remove show in explorer/command prompt from editor context menu
authordadubrow
Wed, 30 Jun 2010 15:34:24 -0500
changeset 1564 1c3ed56966df
parent 1559 cc9cfb62406b
child 1567 ad3475a0684e
child 1569 6615e5b1e083
remove show in explorer/command prompt from editor context menu
core/com.nokia.carbide.win32.utils/META-INF/MANIFEST.MF
core/com.nokia.carbide.win32.utils/plugin.xml
core/com.nokia.carbide.win32.utils/src/com/nokia/carbide/internal/win32/utils/actions/OpenInCmdPromptHandler.java
core/com.nokia.carbide.win32.utils/src/com/nokia/carbide/internal/win32/utils/actions/OpenInExplorerHandler.java
core/com.nokia.carbide.win32.utils/src/com/nokia/carbide/internal/win32/utils/actions/WindowsOpenFileUtils.java
--- a/core/com.nokia.carbide.win32.utils/META-INF/MANIFEST.MF	Wed Jun 30 14:00:29 2010 -0500
+++ b/core/com.nokia.carbide.win32.utils/META-INF/MANIFEST.MF	Wed Jun 30 15:34:24 2010 -0500
@@ -9,5 +9,6 @@
  org.eclipse.core.runtime,
  org.eclipse.core.resources,
  org.eclipse.cdt.core,
- org.eclipse.cdt.ui
+ org.eclipse.cdt.ui,
+ org.eclipse.core.expressions;bundle-version="3.4.100"
 Bundle-ActivationPolicy: lazy
--- a/core/com.nokia.carbide.win32.utils/plugin.xml	Wed Jun 30 14:00:29 2010 -0500
+++ b/core/com.nokia.carbide.win32.utils/plugin.xml	Wed Jun 30 15:34:24 2010 -0500
@@ -1,23 +1,58 @@
 <?xml version="1.0" encoding="UTF-8"?>
 <?eclipse version="3.0"?>
 <plugin>
-  <extension 
-		point="org.eclipse.ui.popupMenus">
-		<objectContribution
-        	adaptable="true"
-        	id="com.nokia.carbide.win32.utils.contribution1"
-        	nameFilter="*"
-        	objectClass="org.eclipse.core.resources.IResource">
-     		<action
-           		class="com.nokia.carbide.internal.win32.utils.actions.WindowsOpenFileUtils"
-           		enablesFor="1"
-           		id="openInWindowsExplorer"
-           		label="Show in Explorer"/>
-     		<action
-           		class="com.nokia.carbide.internal.win32.utils.actions.WindowsOpenFileUtils"
-           		enablesFor="1"
-           		id="openInCmdPrompt"
-           		label="Open Command Window"/>
- 			</objectContribution>
+  <extension
+        point="org.eclipse.ui.commands">
+     <command
+           id="com.nokia.carbide.win32.utils.openInWindowsExplorer"
+           name="Show in Explorer">
+     </command>
+     <command
+           id="com.nokia.carbide.win32.utils.openInCmdPrompt"
+           name="Open Command Window">
+     </command>
+  </extension>
+  <extension
+        point="org.eclipse.ui.handlers">
+     <handler
+           class="com.nokia.carbide.internal.win32.utils.actions.OpenInExplorerHandler"
+           commandId="com.nokia.carbide.win32.utils.openInWindowsExplorer">
+     </handler>
+     <handler
+           class="com.nokia.carbide.internal.win32.utils.actions.OpenInCmdPromptHandler"
+           commandId="com.nokia.carbide.win32.utils.openInCmdPrompt">
+     </handler>
+  </extension>
+  <extension point="org.eclipse.core.expressions.definitions">
+      <definition id="com.nokia.carbide.win32.utils.singleResource">
+          <with variable="activeMenuSelection">
+             <count value="1"/>
+             <iterate ifEmpty="false">
+	            <adapt type="org.eclipse.core.resources.IResource"/>
+	         </iterate>
+          </with>
+      </definition>
+  </extension>
+  <extension
+        point="org.eclipse.ui.menus">
+     <menuContribution
+           locationURI="popup:org.eclipse.ui.popup.any?after=additions">
+        <command
+              commandId="com.nokia.carbide.win32.utils.openInWindowsExplorer"
+              style="push">
+           <visibleWhen
+                 checkEnabled="false">
+    			<reference definitionId="com.nokia.carbide.win32.utils.singleResource"/>
+           </visibleWhen>
+        </command>
+        <command
+              commandId="com.nokia.carbide.win32.utils.openInCmdPrompt"
+              style="push">
+           <visibleWhen
+                 checkEnabled="false">
+    			<reference definitionId="com.nokia.carbide.win32.utils.singleResource"/>
+           </visibleWhen>
+        </command>
+     </menuContribution>
   </extension>
 </plugin>
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/com.nokia.carbide.win32.utils/src/com/nokia/carbide/internal/win32/utils/actions/OpenInCmdPromptHandler.java	Wed Jun 30 15:34:24 2010 -0500
@@ -0,0 +1,43 @@
+/*
+* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of the License "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description: 
+*
+*/
+package com.nokia.carbide.internal.win32.utils.actions;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+public class OpenInCmdPromptHandler extends AbstractHandler {
+
+	public Object execute(ExecutionEvent event) throws ExecutionException {
+		ISelection s = HandlerUtil.getActiveMenuSelection(event);
+		if (s != null && s instanceof IStructuredSelection) {
+			Object o = ((IStructuredSelection) s).getFirstElement();
+			if (o instanceof IAdaptable) {
+				IResource r = (IResource) ((IAdaptable) o).getAdapter(IResource.class);
+				if (r != null)
+					WindowsOpenFileUtils.executeAction(WindowsOpenFileUtils.OPEN_IN_COMMAND_PROMPT, r);
+			}
+		}
+		return null;
+	}
+
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/core/com.nokia.carbide.win32.utils/src/com/nokia/carbide/internal/win32/utils/actions/OpenInExplorerHandler.java	Wed Jun 30 15:34:24 2010 -0500
@@ -0,0 +1,43 @@
+/*
+* Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of the License "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description: 
+*
+*/
+package com.nokia.carbide.internal.win32.utils.actions;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+public class OpenInExplorerHandler extends AbstractHandler {
+
+	public Object execute(ExecutionEvent event) throws ExecutionException {
+		ISelection s = HandlerUtil.getActiveMenuSelection(event);
+		if (s != null && s instanceof IStructuredSelection) {
+			Object o = ((IStructuredSelection) s).getFirstElement();
+			if (o instanceof IAdaptable) {
+				IResource r = (IResource) ((IAdaptable) o).getAdapter(IResource.class);
+				if (r != null)
+					WindowsOpenFileUtils.executeAction(WindowsOpenFileUtils.OPEN_IN_EXPLORER, r);
+			}
+		}
+		return null;
+	}
+
+}
--- a/core/com.nokia.carbide.win32.utils/src/com/nokia/carbide/internal/win32/utils/actions/WindowsOpenFileUtils.java	Wed Jun 30 14:00:29 2010 -0500
+++ b/core/com.nokia.carbide.win32.utils/src/com/nokia/carbide/internal/win32/utils/actions/WindowsOpenFileUtils.java	Wed Jun 30 15:34:24 2010 -0500
@@ -22,13 +22,15 @@
 import org.eclipse.core.runtime.CoreException;
 import org.eclipse.jface.action.IAction;
 import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.swt.widgets.Shell;
 import org.eclipse.ui.IActionDelegate;
 import org.eclipse.ui.IViewActionDelegate;
 import org.eclipse.ui.IViewPart;
 
 public class WindowsOpenFileUtils extends ActionResourceAction implements IViewActionDelegate  {
 
+	public final static int OPEN_IN_EXPLORER = 1;
+	public final static int OPEN_IN_COMMAND_PROMPT = 2;
+
 	/**
 	 * ProcessResourceTree default constructor.
 	 */
@@ -50,14 +52,22 @@
 		
 		// First get the folder name for the selected workspace resource.
 		// Then our simple operations will work on the folder where the resource lives.
-		Shell shell = new Shell();
-		
 		IResource res = (IResource) selection.getFirstElement();
 		String pathList = ""; //$NON-NLS-1$
 		pathList = pathList.concat(Messages.getString("WindowsOpenFileUtils.2") + res + "\n"); //$NON-NLS-1$ //$NON-NLS-2$
 
 		traceEnabled = false;
 		
+		int actionType = 0;
+		if (action.getId().equals("openInWindowsExplorer"))
+			actionType = OPEN_IN_EXPLORER;
+		else if (action.getId().equals("openInCmdPrompt"))
+			actionType = OPEN_IN_COMMAND_PROMPT;
+		
+		executeAction(actionType, res);
+	}
+
+	public static void executeAction(int actionType, IResource res) {
 		String folderFullPath = ""; //$NON-NLS-1$
 		if (res instanceof IFolder || res instanceof IProject){
 			folderFullPath = res.getLocation().toOSString();
@@ -66,7 +76,7 @@
 		}
 		
 		//  figure out what action logic to run based on xml id
-		if (action.getId().equals("openInWindowsExplorer")) //$NON-NLS-1$
+		if (actionType == OPEN_IN_EXPLORER)
 		{
 			String exeCmd = "explorer.exe "; //$NON-NLS-1$
 			exeCmd += "\""; //$NON-NLS-1$
@@ -80,12 +90,12 @@
 			catch (CoreException e)
 			{
 				MessageDialog.openInformation(
-						shell,
+						null,
 						Messages.getString("WindowsOpenFileUtils.10"), //$NON-NLS-1$
 						""); //$NON-NLS-1$
 			}
 		}
-		else if (action.getId().equals("openInCmdPrompt")) //$NON-NLS-1$
+		else if (actionType == OPEN_IN_COMMAND_PROMPT)
 		{	
 			String exeCmd = "cmd.exe /c start cd /d "; //$NON-NLS-1$
 			exeCmd += folderFullPath;
@@ -96,7 +106,7 @@
 			catch (CoreException e)
 			{
 				MessageDialog.openInformation(
-						shell,
+						null,
 						Messages.getString("WindowsOpenFileUtils.14"), //$NON-NLS-1$
 						""); //$NON-NLS-1$
 			}