Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new options select shell and file manager #86

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,346 changes: 673 additions & 673 deletions QuickOpener/license.txt

Large diffs are not rendered by default.

18 changes: 18 additions & 0 deletions QuickOpener/nb-configuration.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<project-shared-configuration>
<!--
This file contains additional configuration written by modules in the NetBeans IDE.
The configuration is intended to be shared among all the users of project and
therefore it is assumed to be part of version control checkout.
Without this configuration present, some functionality in the IDE may be limited or fail altogether.
-->
<properties xmlns="http://www.netbeans.org/ns/maven-properties-data/1">
<!--
Properties that influence various parts of the IDE, especially code formatting and the like.
You can copy and paste the single properties, into the pom.xml file and the IDE will pick them up.
That way multiple projects can share the same settings (useful for formatting rules for example).
Any value defined here will override the pom.xml file value but is only applicable to the current project.
-->
<netbeans.hint.license>gpl30</netbeans.hint.license>
</properties>
</project-shared-configuration>
396 changes: 198 additions & 198 deletions QuickOpener/pom.xml

Large diffs are not rendered by default.

280 changes: 150 additions & 130 deletions QuickOpener/src/main/java/com/sessonad/oscommands/commands/Commands.java
Original file line number Diff line number Diff line change
@@ -1,130 +1,150 @@
package com.sessonad.oscommands.commands;


import com.sessonad.oscommands.detector.OSDetector;
import com.sessonad.oscommands.detector.OperatingSystem;
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;


/**
*
* @author SessonaD
* @author markiewb
*/
public abstract class Commands {

private static final Logger LOG = Logger.getLogger(Commands.class.getName());

static Commands platform;

@SuppressWarnings("unchecked")
public static <T extends Commands> T getPlatform(){
if (platform == null)initializePlatform();
return (T)platform;
}

static void initializePlatform(){
OperatingSystem os = OSDetector.detectOS();
if (os.equals(OperatingSystem.WINDOWS)) platform = new WindowsCommands();
else if (os.equals(OperatingSystem.MAC_OS)) platform = new MacOSCommands();
else if (os.equals(OperatingSystem.LINUX_GNOME))platform = new LinuxGnomeCommands();
else if (os.equals(OperatingSystem.LINUX_KDE)) platform = new LinuxKdeCommands();
else if (os.equals(OperatingSystem.LINUX_LXDE)) platform = new LinuxLxdeCommands();
else if (os.equals(OperatingSystem.LINUX_XFCE)) platform = new LinuxXfceCommands();
else if (os.equals(OperatingSystem.LINUX_UNKNOWN)) platform = new LinuxUnknownCommands();
else if (os.equals(OperatingSystem.UNKNOWN)) platform = new UnknownOSCommands();
}

public abstract OperatingSystem getOperatingSystem();

public void openInShell(String currentPath) throws Exception {
String fullCommand = "";
if(getOperatingSystem().equals(OperatingSystem.WINDOWS)){
fullCommand = getOperatingSystem().getShellCommand()+"\""+currentPath+"\"";
}else{
fullCommand = getOperatingSystem().getShellCommand() + currentPath;
}
Runtime.getRuntime().exec(fullCommand);
}

/**
* Old function. Only left for backward compatibility.
*
* @param current
* @throws Exception
*/
@Deprecated
public void browseInFileSystem(File current) throws Exception {
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) {
try {
Desktop.getDesktop().open(current);
} catch (IOException e) {
executeFileSystemBrowserCommand(current);
}
} else {
executeFileSystemBrowserCommand(current);
}
}
/**
* Browses to the file or directory (depending on the features of the
* OS/file-browser). If it does work, then
* {@link Desktop#open(java.io.File)} is used.
*
* @param fileOrDir
* @throws Exception
*/
public void browseInFileSystemToFileOrDir(File fileOrDir) throws Exception {
if (null == fileOrDir) {
return;
}

try {
executeFileSystemBrowserCommand(fileOrDir);
} catch (Exception e) {
LOG.log(Level.WARNING, String.format("Could not browse to file %s. Try to fallback to Desktop.getDesktop().open()", fileOrDir), e);

//execution via executeFileSystemBrowserCommand did not work, so fallback to Desktop.open()
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) {
try {
File directory = fileOrDir.isDirectory() ? fileOrDir : fileOrDir.getParentFile();
Desktop.getDesktop().open(directory);
} catch (IOException ioe) {
//NOP, no fallback anymore
}
}
}

}

/**
*
* @param fileOrDir
* @return exit-code from the process (!=0 means error)
* @throws IOException
*/
protected Process executeFileSystemBrowserCommand(File fileOrDir) throws IOException {
final boolean isFile = fileOrDir.isFile();
File directory = isFile ? fileOrDir.getParentFile() : fileOrDir;
String fullCommand = null;
if (isFile) {
if (getOperatingSystem().isFeatured(SupportedFeatures.BROWSE_TO_FILE)) {
fullCommand = getOperatingSystem().getFileSystemBrowserCommandForFile() + fileOrDir.getAbsolutePath();
}
if (getOperatingSystem().isFeatured(SupportedFeatures.BROWSE_TO_DIR)) {
fullCommand = getOperatingSystem().getFileSystemBrowserCommand() + directory.getAbsolutePath();
}
} else {
//exp
fullCommand = getOperatingSystem().getFileSystemBrowserCommand() + directory.getAbsolutePath();
}
if (null == fullCommand) {
return null;
}

return Runtime.getRuntime().exec(fullCommand);
}
}
package com.sessonad.oscommands.commands;


import com.sessonad.oscommands.detector.OSDetector;
import com.sessonad.oscommands.detector.OperatingSystem;
import java.awt.Desktop;
import java.io.File;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;


/**
*
* @author SessonaD
* @author markiewb
*/
public abstract class Commands {

private static final Logger LOG = Logger.getLogger(Commands.class.getName());

static Commands platform;

@SuppressWarnings("unchecked")
public static <T extends Commands> T getPlatform(){
if (platform == null)initializePlatform();
return (T)platform;
}

static void initializePlatform(){
OperatingSystem os = OSDetector.detectOS();
switch (os) {
case WINDOWS:
platform = new WindowsCommands();
break;
case MAC_OS:
platform = new MacOSCommands();
break;
case LINUX_GNOME:
platform = new LinuxGnomeCommands();
break;
case LINUX_KDE:
platform = new LinuxKdeCommands();
break;
case LINUX_LXDE:
platform = new LinuxLxdeCommands();
break;
case LINUX_XFCE:
platform = new LinuxXfceCommands();
break;
case LINUX_UNKNOWN:
platform = new LinuxUnknownCommands();
break;
case UNKNOWN:
platform = new UnknownOSCommands();
break;
default:
break;
}
}

public abstract OperatingSystem getOperatingSystem();

public void openInShell(String currentPath) throws Exception {
String fullCommand;
if(getOperatingSystem().equals(OperatingSystem.WINDOWS)){
fullCommand = getOperatingSystem().getShellCommand()+"\""+currentPath+"\"";
}else{
fullCommand = getOperatingSystem().getShellCommand() + currentPath;
}
Runtime.getRuntime().exec(fullCommand);
}

/**
* Old function. Only left for backward compatibility.
*
* @param current
* @throws Exception
*/
@Deprecated
public void browseInFileSystem(File current) throws Exception {
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) {
try {
Desktop.getDesktop().open(current);
} catch (IOException e) {
executeFileSystemBrowserCommand(current);
}
} else {
executeFileSystemBrowserCommand(current);
}
}
/**
* Browses to the file or directory (depending on the features of the
* OS/file-browser). If it does work, then
* {@link Desktop#open(java.io.File)} is used.
*
* @param fileOrDir
* @throws Exception
*/
public void browseInFileSystemToFileOrDir(File fileOrDir) throws Exception {
if (null == fileOrDir) {
return;
}

try {
executeFileSystemBrowserCommand(fileOrDir);
} catch (IOException e) {
LOG.log(Level.WARNING, String.format("Could not browse to file %s. Try to fallback to Desktop.getDesktop().open()", fileOrDir), e);

//execution via executeFileSystemBrowserCommand did not work, so fallback to Desktop.open()
if (Desktop.isDesktopSupported() && Desktop.getDesktop().isSupported(Desktop.Action.OPEN)) {
try {
File directory = fileOrDir.isDirectory() ? fileOrDir : fileOrDir.getParentFile();
Desktop.getDesktop().open(directory);
} catch (IOException ioe) {
//NOP, no fallback anymore
}
}
}

}

/**
*
* @param fileOrDir
* @return exit-code from the process (!=0 means error)
* @throws IOException
*/
protected Process executeFileSystemBrowserCommand(File fileOrDir) throws IOException {
final boolean isFile = fileOrDir.isFile();
File directory = isFile ? fileOrDir.getParentFile() : fileOrDir;
String fullCommand = null;
if (isFile) {
if (getOperatingSystem().isFeatured(SupportedFeatures.BROWSE_TO_FILE)) {
fullCommand = getOperatingSystem().getFileSystemBrowserCommandForFile() + fileOrDir.getAbsolutePath();
}
if (getOperatingSystem().isFeatured(SupportedFeatures.BROWSE_TO_DIR)) {
fullCommand = getOperatingSystem().getFileSystemBrowserCommand() + directory.getAbsolutePath();
}
} else {
//exp
fullCommand = getOperatingSystem().getFileSystemBrowserCommand() + directory.getAbsolutePath();
}
if (null == fullCommand) {
return null;
}

return Runtime.getRuntime().exec(fullCommand);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ private static OperatingSystem detectLinuxGUI() {

private static boolean checkProcessNames(String... processNames) throws Exception {
for (String processName : processNames) {
if (executePidOfCommand(processName)) return true;
if (executePidOfCommand(processName)) {
return true;
}
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
/*
* Copyright (C) 2017 Diego Zambelli Sessona (diego.sessona@gmail.com)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.sessonad.oscommands.detector;

import com.sessonad.oscommands.commands.SupportedFeatures;
Expand Down Expand Up @@ -54,4 +70,8 @@ public boolean isFeatured(SupportedFeatures feature){
return features.contains(feature);
}

public boolean isLinux(){
return this.equals(OperatingSystem.LINUX_GNOME)|| this.equals(OperatingSystem.LINUX_KDE)|| this.equals(OperatingSystem.LINUX_LXDE)|| this.equals(OperatingSystem.LINUX_XFCE)|| this.equals(OperatingSystem.LINUX_UNKNOWN);
}

}
Loading