diff --git a/plugin/plugin.xml b/plugin/plugin.xml
index 380a752..81314c5 100644
--- a/plugin/plugin.xml
+++ b/plugin/plugin.xml
@@ -120,74 +120,15 @@
-
-
-
-
-
-
-
+ locationURI="popup:org.eclipse.ui.popup.any?after=group.open">
+ class="de.anbos.eclipse.easyshell.plugin.commands.DefineCommandsForResourceNavigator"
+ locationURI="popup:org.eclipse.ui.popup.any">
.
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information regarding copyright ownership.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-
-package de.anbos.eclipse.easyshell.plugin;
-
-import org.eclipse.core.expressions.PropertyTester;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.ui.IWorkbenchPart;
-
-import de.anbos.eclipse.easyshell.plugin.actions.ActionDelegate;
-import de.anbos.eclipse.easyshell.plugin.types.ResourceType;
-
-public class EditorPropertyTester extends PropertyTester {
-
- public EditorPropertyTester() {
- super();
- }
-
- public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
- if("hasResourceSelection".equals(property) && receiver instanceof IWorkbenchPart){
- if (args.length > 0 && args[0].equals("resourceType")) {
- return getActionCommonResourceType((IWorkbenchPart)receiver, ResourceType.getFromEnum((String)expectedValue)) != null;
- }
- }
- return false;
- }
-
- static public ActionDelegate getActionCommonResourceType(IWorkbenchPart part, ResourceType resType) {
- ISelection selection = ResourceUtils.getResourceSelection(part);
- if (selection != null) {
- ActionDelegate action = new ActionDelegate();
- action.selectionChanged(null, selection);
- if (action.isEnabled(ResourceType.resourceTypeFileOrDirectory) && resType == action.getCommonResourceType()) {
- return action;
- }
- }
- return null;
- }
-
- static public ActionDelegate getActionExactResourceType(IWorkbenchPart part, ResourceType resType) {
- ISelection selection = ResourceUtils.getResourceSelection(part);
- if (selection != null) {
- ActionDelegate action = new ActionDelegate();
- action.selectionChanged(null, selection);
- if (action.isEnabled(resType)) {
- return action;
- }
- }
- return null;
- }
-
-}
diff --git a/plugin/src/de/anbos/eclipse/easyshell/plugin/Resource.java b/plugin/src/de/anbos/eclipse/easyshell/plugin/Resource.java
index 0769664..7a52721 100644
--- a/plugin/src/de/anbos/eclipse/easyshell/plugin/Resource.java
+++ b/plugin/src/de/anbos/eclipse/easyshell/plugin/Resource.java
@@ -40,10 +40,6 @@ public class Resource {
// resolved
private String projectName = Activator.getResourceString("easyshell.plugin.name");
- //Activator.logDebug("full_path : >" + fullPath + "<");
- //Activator.logDebug("parent_path: >" + parentPath + "<");
- //Activator.logDebug("file_name : >" + fileName + "<");
-
public Resource(Resource myRes) {
this.file = myRes.getFile();
this.resource = myRes.getResource();
diff --git a/plugin/src/de/anbos/eclipse/easyshell/plugin/ResourceUtils.java b/plugin/src/de/anbos/eclipse/easyshell/plugin/ResourceUtils.java
index 61643b3..8c5e4ca 100644
--- a/plugin/src/de/anbos/eclipse/easyshell/plugin/ResourceUtils.java
+++ b/plugin/src/de/anbos/eclipse/easyshell/plugin/ResourceUtils.java
@@ -31,6 +31,10 @@
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.ide.FileStoreEditorInput;
import org.osgi.framework.Bundle;
+
+import de.anbos.eclipse.easyshell.plugin.actions.ActionDelegate;
+import de.anbos.eclipse.easyshell.plugin.types.ResourceType;
+
import org.eclipse.cdt.internal.core.model.ExternalTranslationUnit;
import org.eclipse.cdt.internal.core.model.IncludeReference;
import org.eclipse.cdt.internal.ui.cview.IncludeReferenceProxy;
@@ -167,4 +171,40 @@ static private File getJarFile(IAdaptable adaptable) {
return file;
}
+ static public ActionDelegate getActionCommonResourceType(IWorkbenchPart part, ResourceType resType) {
+ ISelection selection = getResourceSelection(part);
+ if (selection != null) {
+ ActionDelegate action = new ActionDelegate();
+ action.selectionChanged(null, selection);
+ if (action.isEnabled(ResourceType.resourceTypeFileOrDirectory) && resType == action.getCommonResourceType()) {
+ return action;
+ }
+ }
+ return null;
+ }
+
+ static public ActionDelegate getActionExactResourceType(IWorkbenchPart part, ResourceType resType) {
+ ISelection selection = getResourceSelection(part);
+ if (selection != null) {
+ ActionDelegate action = new ActionDelegate();
+ action.selectionChanged(null, selection);
+ if (action.isEnabled(resType)) {
+ return action;
+ }
+ }
+ return null;
+ }
+
+ static public ResourceType getCommonResourceType(IWorkbenchPart part) {
+ ISelection selection = getResourceSelection(part);
+ if (selection != null) {
+ ActionDelegate action = new ActionDelegate();
+ action.selectionChanged(null, selection);
+ if (action.isEnabled(ResourceType.resourceTypeFileOrDirectory)) {
+ return action.getCommonResourceType();
+ }
+ }
+ return null;
+ }
+
}
diff --git a/plugin/src/de/anbos/eclipse/easyshell/plugin/commands/DefineCommands.java b/plugin/src/de/anbos/eclipse/easyshell/plugin/commands/DefineCommands.java
index 1b5bd00..cbbc2d5 100644
--- a/plugin/src/de/anbos/eclipse/easyshell/plugin/commands/DefineCommands.java
+++ b/plugin/src/de/anbos/eclipse/easyshell/plugin/commands/DefineCommands.java
@@ -15,19 +15,24 @@
import java.util.Map;
+import org.eclipse.jface.action.IContributionManager;
+import org.eclipse.jface.action.MenuManager;
import org.eclipse.swt.SWT;
+import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.menus.CommandContributionItem;
import org.eclipse.ui.menus.CommandContributionItemParameter;
import org.eclipse.ui.menus.ExtensionContributionFactory;
import org.eclipse.ui.menus.IContributionRoot;
import org.eclipse.ui.services.IServiceLocator;
-
import de.anbos.eclipse.easyshell.plugin.Activator;
+import de.anbos.eclipse.easyshell.plugin.ResourceUtils;
+import de.anbos.eclipse.easyshell.plugin.Constants;
import de.anbos.eclipse.easyshell.plugin.exceptions.UnknownCommandID;
import de.anbos.eclipse.easyshell.plugin.misc.Utils;
import de.anbos.eclipse.easyshell.plugin.preferences.MenuData;
import de.anbos.eclipse.easyshell.plugin.preferences.MenuDataList;
import de.anbos.eclipse.easyshell.plugin.preferences.MenuDataStore;
+
import de.anbos.eclipse.easyshell.plugin.types.ResourceType;
public class DefineCommands extends ExtensionContributionFactory {
@@ -35,21 +40,33 @@ public class DefineCommands extends ExtensionContributionFactory {
public DefineCommands() {
}
- public ResourceType getWantedResourceType() {
- return ResourceType.resourceTypeFileOrDirectory;
- }
-
@Override
public void createContributionItems(IServiceLocator serviceLocator, IContributionRoot additions) {
+ IWorkbenchPart activePart = serviceLocator.getService(IWorkbenchPart.class);
+ boolean isResourceNavigator = false;
+ isResourceNavigator = activePart instanceof org.eclipse.ui.views.navigator.ResourceNavigator;
+ if ((isResourceNavigator == isForResourceNavigator())) {
+ ResourceType resType = ResourceUtils.getCommonResourceType(activePart);
+ if (resType != null) {
+ createContributionItemsForResType(resType, serviceLocator, additions);
+ }
+ }
+ }
+
+ public boolean isForResourceNavigator() {
+ return false;
+ }
+
+ private void createContributionItemsForResType(ResourceType resType, IServiceLocator serviceLocator, IContributionRoot additions) {
+ MenuManager submenu = new MenuManager("EasyShell", Activator.getImageDescriptor(Constants.IMAGE_EASYSHELL), "de.anbos.eclipse.easyshell.plugin.menu");
MenuDataList items = MenuDataStore.instance().getEnabledCommandMenuDataList();
for (MenuData item : items) {
- ResourceType resTypeWanted = getWantedResourceType();
ResourceType resTypeSupported;
try {
resTypeSupported = item.getCommandData().getResourceType();
if ((resTypeSupported == ResourceType.resourceTypeFileOrDirectory)
- || (resTypeSupported == resTypeWanted)) {
- addItem(serviceLocator, additions, item.getNameExpanded(), item.getCommand(),
+ || (resTypeSupported == resType)) {
+ addItem(serviceLocator, submenu, item.getNameExpanded(), item.getCommand(),
"de.anbos.eclipse.easyshell.plugin.commands.execute",
Utils.getParameterMapFromMenuData(item), item.getImageId(),
true);
@@ -58,9 +75,10 @@ public void createContributionItems(IServiceLocator serviceLocator, IContributio
e.logInternalError();
}
}
+ additions.addContributionItem(submenu, null);
}
- private void addItem(IServiceLocator serviceLocator, IContributionRoot additions, String commandLabel, String commandToolTip,
+ private void addItem(IServiceLocator serviceLocator, IContributionManager submenu, String commandLabel, String commandToolTip,
String commandId, Map commandParamametersMap, String commandImageId, boolean visible) {
CommandContributionItemParameter param = new CommandContributionItemParameter(serviceLocator, "", commandId,
SWT.PUSH);
@@ -70,6 +88,7 @@ private void addItem(IServiceLocator serviceLocator, IContributionRoot additions
param.parameters = commandParamametersMap;
CommandContributionItem item = new CommandContributionItem(param);
item.setVisible(visible);
- additions.addContributionItem(item, null);
+ submenu.add(item);
}
+
}
diff --git a/plugin/src/de/anbos/eclipse/easyshell/plugin/commands/DefineCommandsForDirectory.java b/plugin/src/de/anbos/eclipse/easyshell/plugin/commands/DefineCommandsForDirectory.java
deleted file mode 100644
index 71ac54e..0000000
--- a/plugin/src/de/anbos/eclipse/easyshell/plugin/commands/DefineCommandsForDirectory.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/**
- * Copyright (c) 2014-2020 Andre Bossert .
- *
- * See the NOTICE file(s) distributed with this work for additional
- * information regarding copyright ownership.
- *
- * This program and the accompanying materials are made available under the
- * terms of the Eclipse Public License 2.0 which is available at
- * http://www.eclipse.org/legal/epl-2.0
- *
- * SPDX-License-Identifier: EPL-2.0
- */
-
-package de.anbos.eclipse.easyshell.plugin.commands;
-
-import de.anbos.eclipse.easyshell.plugin.types.ResourceType;
-
-public class DefineCommandsForDirectory extends DefineCommands {
-
- public ResourceType getWantedResourceType() {
- return ResourceType.resourceTypeDirectory;
- }
-
-}
diff --git a/plugin/src/de/anbos/eclipse/easyshell/plugin/commands/DefineCommandsForFile.java b/plugin/src/de/anbos/eclipse/easyshell/plugin/commands/DefineCommandsForResourceNavigator.java
similarity index 68%
rename from plugin/src/de/anbos/eclipse/easyshell/plugin/commands/DefineCommandsForFile.java
rename to plugin/src/de/anbos/eclipse/easyshell/plugin/commands/DefineCommandsForResourceNavigator.java
index 6f4acac..bef500b 100644
--- a/plugin/src/de/anbos/eclipse/easyshell/plugin/commands/DefineCommandsForFile.java
+++ b/plugin/src/de/anbos/eclipse/easyshell/plugin/commands/DefineCommandsForResourceNavigator.java
@@ -13,12 +13,9 @@
package de.anbos.eclipse.easyshell.plugin.commands;
-import de.anbos.eclipse.easyshell.plugin.types.ResourceType;
+public class DefineCommandsForResourceNavigator extends DefineCommands {
-public class DefineCommandsForFile extends DefineCommands {
-
- public ResourceType getWantedResourceType() {
- return ResourceType.resourceTypeFile;
+ public boolean isForResourceNavigator() {
+ return true;
}
-
}
diff --git a/plugin/src/de/anbos/eclipse/easyshell/plugin/handlers/All.java b/plugin/src/de/anbos/eclipse/easyshell/plugin/handlers/All.java
index 723f9b0..2f67724 100644
--- a/plugin/src/de/anbos/eclipse/easyshell/plugin/handlers/All.java
+++ b/plugin/src/de/anbos/eclipse/easyshell/plugin/handlers/All.java
@@ -22,7 +22,7 @@
import org.eclipse.ui.handlers.HandlerUtil;
import de.anbos.eclipse.easyshell.plugin.Activator;
-import de.anbos.eclipse.easyshell.plugin.EditorPropertyTester;
+import de.anbos.eclipse.easyshell.plugin.ResourceUtils;
import de.anbos.eclipse.easyshell.plugin.actions.ActionDelegate;
import de.anbos.eclipse.easyshell.plugin.commands.ExecuteCommandPopup;
import de.anbos.eclipse.easyshell.plugin.exceptions.UnknownCommandID;
@@ -44,7 +44,7 @@ public class All extends AbstractHandler {
public Object execute(ExecutionEvent event) throws ExecutionException {
// get resource type
IWorkbenchPart activePart = HandlerUtil.getActivePart(event);
- ActionDelegate action = EditorPropertyTester.getActionExactResourceType(activePart,
+ ActionDelegate action = ResourceUtils.getActionExactResourceType(activePart,
ResourceType.resourceTypeFileOrDirectory);
if (action != null) {
// load the preferences
diff --git a/plugin/src/de/anbos/eclipse/easyshell/plugin/handlers/Execute.java b/plugin/src/de/anbos/eclipse/easyshell/plugin/handlers/Execute.java
index 3b5a7c8..af7cbfc 100644
--- a/plugin/src/de/anbos/eclipse/easyshell/plugin/handlers/Execute.java
+++ b/plugin/src/de/anbos/eclipse/easyshell/plugin/handlers/Execute.java
@@ -21,7 +21,7 @@
import org.eclipse.ui.handlers.HandlerUtil;
import de.anbos.eclipse.easyshell.plugin.Activator;
-import de.anbos.eclipse.easyshell.plugin.EditorPropertyTester;
+import de.anbos.eclipse.easyshell.plugin.ResourceUtils;
import de.anbos.eclipse.easyshell.plugin.actions.Action;
import de.anbos.eclipse.easyshell.plugin.actions.ActionDelegate;
import de.anbos.eclipse.easyshell.plugin.types.CommandType;
@@ -39,7 +39,7 @@ public Object execute(ExecutionEvent event) throws ExecutionException {
String commandValue = event.getParameter("de.anbos.eclipse.easyshell.plugin.commands.parameter.value");
String commandWorkingDir = event.getParameter("de.anbos.eclipse.easyshell.plugin.commands.parameter.workingdir");
CommandTokenizer commandTokenizer = CommandTokenizer.getFromEnum(event.getParameter("de.anbos.eclipse.easyshell.plugin.commands.parameter.tokenizer"));
- ActionDelegate action = EditorPropertyTester.getActionExactResourceType(activePart, resourceType);
+ ActionDelegate action = ResourceUtils.getActionExactResourceType(activePart, resourceType);
if (action != null) {
action.setResourceType(resourceType);
action.setCommandType(commandType);