diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF
index 5fc0910..efe6c4b 100644
--- a/META-INF/MANIFEST.MF
+++ b/META-INF/MANIFEST.MF
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: OpenExplorer
Bundle-SymbolicName: OpenExplorer;singleton:=true
-Bundle-Version: 1.4.0.qualifier
+Bundle-Version: 1.5.0.qualifier
Bundle-Activator: openexplorer.Activator
Bundle-Vendor: Samson Wu
Bundle-Localization: plugin
diff --git a/build.properties b/build.properties
index 6c480f3..5df0f2c 100644
--- a/build.properties
+++ b/build.properties
@@ -3,4 +3,5 @@ output.. = bin/
bin.includes = META-INF/,\
.,\
plugin.xml,\
- icons/
+ icons/,\
+ LICENSE
diff --git a/plugin.xml b/plugin.xml
index a1f6407..6915489 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -32,5 +32,24 @@
-
+
+
+
+
+
+
+
+
+
+
diff --git a/src/openexplorer/Activator.java b/src/openexplorer/Activator.java
index 7c0dd02..439f199 100644
--- a/src/openexplorer/Activator.java
+++ b/src/openexplorer/Activator.java
@@ -37,6 +37,9 @@ public class Activator extends AbstractUIPlugin {
// The plug-in ID
public static final String PLUGIN_ID = "OpenExplorer"; //$NON-NLS-1$
+ // The plugin version
+ public static final String VERSION = "1.5.0";
+
// The shared instance
private static Activator plugin;
diff --git a/src/openexplorer/actions/AbstractOpenExplorerAction.java b/src/openexplorer/actions/AbstractOpenExplorerAction.java
index 80a95a5..4222bac 100644
--- a/src/openexplorer/actions/AbstractOpenExplorerAction.java
+++ b/src/openexplorer/actions/AbstractOpenExplorerAction.java
@@ -25,7 +25,9 @@
import java.io.IOException;
-import openexplorer.util.IOUtils;
+import openexplorer.Activator;
+import openexplorer.util.Messages;
+import openexplorer.util.OperatingSystem;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
@@ -33,6 +35,8 @@
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.text.ITextSelection;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.ITreeSelection;
@@ -47,141 +51,102 @@
* @author Samson Wu
* @version 1.4.0
*/
-public abstract class AbstractOpenExplorerAction implements IActionDelegate {
- protected IWorkbenchWindow window = PlatformUI.getWorkbench()
- .getActiveWorkbenchWindow();
- protected Shell shell;
- protected ISelection currentSelection;
+public abstract class AbstractOpenExplorerAction implements IActionDelegate,
+ IPropertyChangeListener {
+ protected IWorkbenchWindow window = PlatformUI.getWorkbench()
+ .getActiveWorkbenchWindow();
+ protected Shell shell;
+ protected ISelection currentSelection;
- protected String os;
- public static final String WINDOWS = "win32";
- public static final String LINUX = "linux";
- public static final String MACOSX = "macosx";
+ protected String systemBrowser;
- protected String systemBrowser = "explorer";
-
- public AbstractOpenExplorerAction() {
- this.os = System.getProperty("osgi.os");
- if (WINDOWS.equalsIgnoreCase(this.os)) {
- this.systemBrowser = "explorer";
- } else if (LINUX.equalsIgnoreCase(this.os)) {
- this.systemBrowser = detachLinuxBrowser();
- } else if (MACOSX.equalsIgnoreCase(this.os)) {
- this.systemBrowser = "open";
- }
- }
-
- /**
- * Use {@code which} command to found the modern file manager, if not found use the xdg-open.
- * @return the file manager
- */
- protected String detachLinuxBrowser() {
- String result = executeCommand("which dolphin");
- if (result == null || result.trim().equals("")) {
- result = executeCommand("which nautilus");
- }
- if (result == null || result.trim().equals("")) {
- result = executeCommand("which thunar");
- }
- if (result == null || result.trim().equals("")) {
- result = executeCommand("which pcmanfm");
- }
- if (result == null || result.trim().equals("")) {
- result = executeCommand("which rox");
- }
- if (result == null || result.trim().equals("")) {
- result = "xdg-open";
- }
- return result;
- }
+ public AbstractOpenExplorerAction() {
+ this.systemBrowser = OperatingSystem.INSTANCE.getSystemBrowser();
+ Activator.getDefault().getPreferenceStore()
+ .addPropertyChangeListener(this);
+ }
- /**
- * execute the command and return the result.
- * @param command
- * @return
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse
+ * .jface.util.PropertyChangeEvent)
*/
- private String executeCommand(String command) {
- String stdout = null;
- try {
- Process process = Runtime.getRuntime().exec(command);
- stdout = IOUtils.toString(process.getInputStream());
- stdout = stdout.trim();
- stdout = stdout.replace("\n", "");
- stdout = stdout.replace("\r", "");
- } catch (IOException e) {
- e.printStackTrace();
+ public void propertyChange(PropertyChangeEvent event) {
+ if (OperatingSystem.INSTANCE.isLinux()) {
+ this.systemBrowser = OperatingSystem.INSTANCE.getSystemBrowser();
}
- return stdout;
}
public void run(IAction action) {
- if (this.currentSelection == null || this.currentSelection.isEmpty()) {
- return;
- }
- if (this.currentSelection instanceof ITreeSelection) {
- ITreeSelection treeSelection = (ITreeSelection) this.currentSelection;
+ if (this.currentSelection == null || this.currentSelection.isEmpty()) {
+ return;
+ }
+ if (this.currentSelection instanceof ITreeSelection) {
+ ITreeSelection treeSelection = (ITreeSelection) this.currentSelection;
- TreePath[] paths = treeSelection.getPaths();
+ TreePath[] paths = treeSelection.getPaths();
- for (int i = 0; i < paths.length; i++) {
- TreePath path = paths[i];
- IResource resource = null;
- Object segment = path.getLastSegment();
- if ((segment instanceof IResource))
- resource = (IResource) segment;
- else if ((segment instanceof IJavaElement)) {
- resource = ((IJavaElement) segment).getResource();
- }
- if (resource == null) {
- continue;
- }
- String browser = this.systemBrowser;
- String location = resource.getLocation().toOSString();
- if ((resource instanceof IFile)) {
- location = ((IFile) resource).getParent().getLocation()
- .toOSString();
- if (WINDOWS.equalsIgnoreCase(this.os)) {
- browser = this.systemBrowser + " /select,";
- location = ((IFile) resource).getLocation()
- .toOSString();
- }
- }
- openInBrowser(browser, location);
- }
- } else if (this.currentSelection instanceof ITextSelection
- || this.currentSelection instanceof IStructuredSelection) {
- // open current editing file
- IEditorPart editor = window.getActivePage().getActiveEditor();
- if (editor != null) {
- IFile current_editing_file = (IFile) editor.getEditorInput()
- .getAdapter(IFile.class);
- String browser = this.systemBrowser;
- String location = current_editing_file.getParent()
- .getLocation().toOSString();
- if (WINDOWS.equalsIgnoreCase(this.os)) {
- browser = this.systemBrowser + " /select,";
- location = current_editing_file.getLocation().toOSString();
- }
- openInBrowser(browser, location);
- }
- }
- }
+ for (int i = 0; i < paths.length; i++) {
+ TreePath path = paths[i];
+ IResource resource = null;
+ Object segment = path.getLastSegment();
+ if ((segment instanceof IResource))
+ resource = (IResource) segment;
+ else if ((segment instanceof IJavaElement)) {
+ resource = ((IJavaElement) segment).getResource();
+ }
+ if (resource == null) {
+ continue;
+ }
+ String browser = this.systemBrowser;
+ String location = resource.getLocation().toOSString();
+ if ((resource instanceof IFile)) {
+ location = ((IFile) resource).getParent().getLocation()
+ .toOSString();
+ if (OperatingSystem.INSTANCE.isWindows()) {
+ browser = this.systemBrowser + " /select,";
+ location = ((IFile) resource).getLocation()
+ .toOSString();
+ }
+ }
+ openInBrowser(browser, location);
+ }
+ } else if (this.currentSelection instanceof ITextSelection
+ || this.currentSelection instanceof IStructuredSelection) {
+ // open current editing file
+ IEditorPart editor = window.getActivePage().getActiveEditor();
+ if (editor != null) {
+ IFile current_editing_file = (IFile) editor.getEditorInput()
+ .getAdapter(IFile.class);
+ String browser = this.systemBrowser;
+ String location = current_editing_file.getParent()
+ .getLocation().toOSString();
+ if (OperatingSystem.INSTANCE.isWindows()) {
+ browser = this.systemBrowser + " /select,";
+ location = current_editing_file.getLocation().toOSString();
+ }
+ openInBrowser(browser, location);
+ }
+ }
+ }
- protected void openInBrowser(String browser, String location) {
- try {
- if (WINDOWS.equalsIgnoreCase(this.os)) {
- Runtime.getRuntime().exec(browser + " \"" + location + "\"");
- } else {
- Runtime.getRuntime().exec(new String[] { browser, location });
- }
- } catch (IOException e) {
- MessageDialog.openError(shell, "OpenExploer Error", "Can't open \""
- + location + "\"");
- e.printStackTrace();
- }
- }
+ protected void openInBrowser(String browser, String location) {
+ try {
+ if (OperatingSystem.INSTANCE.isWindows()) {
+ Runtime.getRuntime().exec(browser + " \"" + location + "\"");
+ } else {
+ Runtime.getRuntime().exec(new String[] { browser, location });
+ }
+ } catch (IOException e) {
+ MessageDialog.openError(shell, Messages.OpenExploer_Error,
+ Messages.Cant_Open + " \"" + location + "\"");
+ e.printStackTrace();
+ }
+ }
- public void selectionChanged(IAction action, ISelection selection) {
- this.currentSelection = selection;
- }
+ public void selectionChanged(IAction action, ISelection selection) {
+ this.currentSelection = selection;
+ }
}
diff --git a/src/openexplorer/preferences/FMPreferencePage.java b/src/openexplorer/preferences/FMPreferencePage.java
new file mode 100644
index 0000000..0d32d7d
--- /dev/null
+++ b/src/openexplorer/preferences/FMPreferencePage.java
@@ -0,0 +1,358 @@
+package openexplorer.preferences;
+
+/**
+ * Copyright (c) 2011 Samson Wu
+ * Permission is hereby granted, free of charge, to any person obtaining
+ * a copy of this software and associated documentation files (the
+ * "Software"), to deal in the Software without restriction, including
+ * without limitation the rights to use, copy, modify, merge, publish,
+ * distribute, sublicense, and/or sell copies of the Software, and to
+ * permit persons to whom the Software is furnished to do so, subject to
+ * the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be
+ * included in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+import java.io.File;
+import java.util.ArrayList;
+
+import openexplorer.Activator;
+import openexplorer.util.IFileManagerExecutables;
+import openexplorer.util.Messages;
+
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.jface.preference.PreferencePage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.DisposeEvent;
+import org.eclipse.swt.events.DisposeListener;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Button;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.FileDialog;
+import org.eclipse.swt.widgets.Group;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPreferencePage;
+
+/**
+ * @author Samson Wu
+ * @version 1.4.0
+ */
+public class FMPreferencePage extends PreferencePage implements
+ IWorkbenchPreferencePage {
+
+ private ArrayList