diff --git a/META-INF/MANIFEST.MF b/META-INF/MANIFEST.MF index efe6c4b..2499ed3 100644 --- a/META-INF/MANIFEST.MF +++ b/META-INF/MANIFEST.MF @@ -9,7 +9,6 @@ Bundle-Localization: plugin Require-Bundle: org.eclipse.ui, org.eclipse.core.runtime, org.eclipse.core.resources, - org.eclipse.jdt.core, org.eclipse.jface.text Bundle-RequiredExecutionEnvironment: J2SE-1.5 Bundle-ActivationPolicy: lazy diff --git a/plugin.xml b/plugin.xml index 6915489..e8bfe56 100644 --- a/plugin.xml +++ b/plugin.xml @@ -23,13 +23,19 @@ objectClass="org.eclipse.core.runtime.IAdaptable" id="OpenExplorer.popupMenuContribution"> + + Samson Wu * @version 1.4.0 */ -public abstract class AbstractOpenExplorerAction implements IActionDelegate, - IPropertyChangeListener { - protected IWorkbenchWindow window = PlatformUI.getWorkbench() - .getActiveWorkbenchWindow(); +public abstract class AbstractOpenExplorerAction implements IActionDelegate, IPropertyChangeListener { + protected IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); protected Shell shell; protected ISelection currentSelection; @@ -62,8 +59,7 @@ public abstract class AbstractOpenExplorerAction implements IActionDelegate, public AbstractOpenExplorerAction() { this.systemBrowser = OperatingSystem.INSTANCE.getSystemBrowser(); - Activator.getDefault().getPreferenceStore() - .addPropertyChangeListener(this); + Activator.getDefault().getPreferenceStore().addPropertyChangeListener(this); } /* @@ -80,6 +76,7 @@ public void propertyChange(PropertyChangeEvent event) { } public void run(IAction action) { + if (this.currentSelection == null || this.currentSelection.isEmpty()) { return; } @@ -94,35 +91,29 @@ public void run(IAction action) { 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(); + location = ((IFile) resource).getParent().getLocation().toOSString(); if (OperatingSystem.INSTANCE.isWindows()) { browser = this.systemBrowser + " /select,"; - location = ((IFile) resource).getLocation() - .toOSString(); + location = ((IFile) resource).getLocation().toOSString(); } } openInBrowser(browser, location); } } else if (this.currentSelection instanceof ITextSelection - || this.currentSelection instanceof IStructuredSelection) { + || 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); + IFile current_editing_file = (IFile) editor.getEditorInput().getAdapter(IFile.class); String browser = this.systemBrowser; - String location = current_editing_file.getParent() - .getLocation().toOSString(); + String location = current_editing_file.getParent().getLocation().toOSString(); if (OperatingSystem.INSTANCE.isWindows()) { browser = this.systemBrowser + " /select,"; location = current_editing_file.getLocation().toOSString(); @@ -140,8 +131,7 @@ protected void openInBrowser(String browser, String location) { Runtime.getRuntime().exec(new String[] { browser, location }); } } catch (IOException e) { - MessageDialog.openError(shell, Messages.OpenExploer_Error, - Messages.Cant_Open + " \"" + location + "\""); + MessageDialog.openError(shell, Messages.OpenExploer_Error, Messages.Cant_Open + " \"" + location + "\""); e.printStackTrace(); } } diff --git a/src/openexplorer/actions/DosHere.java b/src/openexplorer/actions/DosHere.java new file mode 100644 index 0000000..d8e1e87 --- /dev/null +++ b/src/openexplorer/actions/DosHere.java @@ -0,0 +1,115 @@ +package openexplorer.actions; +/** + * Copyright (c) 2011 zhiyanan + * 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.IOException; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IResource; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.dialogs.MessageDialog; +import org.eclipse.jface.text.ITextSelection; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.jface.viewers.ITreeSelection; +import org.eclipse.jface.viewers.TreePath; +import org.eclipse.ui.IActionDelegate; +import org.eclipse.ui.IEditorPart; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PlatformUI; + +import openexplorer.util.Messages; +import openexplorer.util.OperatingSystem; + +public class DosHere implements IActionDelegate { + + protected ISelection currentSelection; + protected IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + + public DosHere() { + // TODO Auto-generated constructor stub + } + + + public void run(IAction action) { + + + if (this.currentSelection == null || this.currentSelection.isEmpty()) { + return; + } + if (this.currentSelection instanceof ITreeSelection) { + ITreeSelection treeSelection = (ITreeSelection) this.currentSelection; + + 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; + + if (resource == null) { + continue; + } + String location = resource.getLocation().toOSString(); + if ((resource instanceof IFile)) { + location = ((IFile) resource).getParent().getLocation().toOSString(); + } + openInTerminal( location); + return ; + } + } else if (this.currentSelection instanceof ITextSelection + || this.currentSelection instanceof IStructuredSelection) { + IEditorPart editor = window.getActivePage().getActiveEditor(); + if (editor != null) { + IFile current_editing_file = (IFile) editor.getEditorInput().getAdapter(IFile.class); + String location = current_editing_file.getParent().getLocation().toOSString(); + + openInTerminal( location); + return ; + } + } + + MessageDialog.openError(window.getShell(), Messages.OpenExploer_Error, Messages.Cant_Open + " Unsupport selection:" + this.currentSelection); + + } + + protected void openInTerminal(String location) { + try { + if (OperatingSystem.INSTANCE.isWindows()) { + Runtime.getRuntime().exec("cmd /c start cmd /k cd /d " + " \"" + location + "\""); + } else { + MessageDialog.openError(window.getShell(), Messages.OpenExploer_Error, Messages.Cant_Open + " Only support windows now"); + } + } catch (IOException e) { + MessageDialog.openError(window.getShell(), Messages.OpenExploer_Error, Messages.Cant_Open + " \"" + location + "\""); + e.printStackTrace(); + } + } + + public void selectionChanged(IAction action, ISelection selection) { + this.currentSelection = selection; + + } + +}