All Downloads are FREE. Search and download functionalities are using the official Maven repository.

me.dsnet.quickopener.actions.FileSystem Maven / Gradle / Ivy

Go to download

<p>Sometimes while programming in NetBeans you want to explore a particular file that you are editing on the file system browser, or maybe launch a command in a terminal to do something with it.</p> <p>This plugins brings to your NetBeans six action, three of them always available and three of them available when the selected node has a file assiociated with it.<br/> In particular:<p><p><em>When the selection has a valid file</em></p> <ul> <li><strong>Open the default OS shell</strong> on the location of the file (or its folder) selected.</li> <li><strong>Open the file system browser</strong> on the location of the file (or its folder) selected.</li> <li><strong>Copy to the clipboard</strong> the path of the file selected.</li> </ul> <p><em>Always enabled:</em></p> <ul> <li><strong>Launch a shell command</strong> (with parameters, customizable on preferences)</li> <li><strong>FileSystem browser on any location</strong> (favorites, customizable on preferences)</li> <li><strong>Open a shell on any location</strong> (favorites, customizable on preferences)</li> </ul>

The newest version!
package me.dsnet.quickopener.actions;

import com.sessonad.oscommands.commands.Commands;
import me.dsnet.quickopener.QuickMessages;
import java.io.File;
import me.dsnet.quickopener.PathFinder;
import me.dsnet.quickopener.prefs.PrefsUtil;
import me.dsnet.quickopener.prefs.QuickOpenerProperty;
import org.netbeans.api.annotations.common.StaticResource;
import org.openide.DialogDisplayer;
import org.openide.NotifyDescriptor;
import org.openide.awt.ActionID;
import org.openide.awt.ActionRegistration;
import org.openide.filesystems.FileObject;
import org.openide.filesystems.FileUtil;
import org.openide.loaders.DataObject;
import org.openide.nodes.Node;
import org.openide.util.NbBundle.Messages;

/**
 *
 * @author SessonaD
 * @author markiewb (contributor)
 */
@ActionID(
        category = "Tools",
        id = "me.dsnet.quickopener.actions.FileSystem")
@ActionRegistration(
        lazy = false,
        displayName = "#CTL_FileSystem"
)
@Messages("CTL_FileSystem=Open in File Manager")
public final class FileSystem extends AbstractFileContextAwareAction {

    @StaticResource
    private static final String icon = "me/dsnet/quickopener/icons/folder-documents-icon.png";

    @Override
    public String getName() {
        return Bundle.CTL_FileSystem();
    }

    @Override
    protected String iconResource() {
        return icon;
    }

    @Override
    protected void performAction(Node[] activatedNodes) {
        File file = getFile();
        
        try {
            if (file == null) {
                NotifyDescriptor d = new NotifyDescriptor.Message(QuickMessages.NO_FILE_IN_SELECTION, NotifyDescriptor.WARNING_MESSAGE);
                DialogDisplayer.getDefault().notify(d);
                return;
            }
            FileObject fo = FileUtil.toFileObject(FileUtil.normalizeFile(file));
            DataObject dataObj = DataObject.find(fo);
            String path = PathFinder.getActivePath(dataObj, true);
            if (path == null) {
                NotifyDescriptor d = new NotifyDescriptor.Message(QuickMessages.NO_FILE_IN_SELECTION, NotifyDescriptor.WARNING_MESSAGE);
                DialogDisplayer.getDefault().notify(d);
                return;
            }

            //open in os shell or in the custom one if defined
            QuickOpenerProperty customShell = PrefsUtil.load(null, "customFileManager", null);
            if (customShell.getValue() == null) {
                Commands.getPlatform().browseInFileSystemToFileOrDir(file);
            } else {
                Runtime.getRuntime().exec(customShell.getValue(), null, new File(path));
            }

        } catch (Exception ex) {
        }//ex.printStackTrace();}
     
    }
    
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy