Browse files

Github issue #19 - make custom commands work in Juno

  • Loading branch information...
1 parent 950a49f commit e26b16bfc9d7f4262a9d89b930e6ab967d2cc739 @basti1302 basti1302 committed Aug 17, 2012
View
17 misc/es-definitions/es-cygwin-bash.txt.bak
@@ -0,0 +1,17 @@
+Windows/Cygwin Bash
+Shell Open: cmd.exe /C start "{4}" /D"{1}" bash.exe
+Shell Run: cmd.exe /C start "{4}" /D"{1}" bash.exe -c "./{3}"
+Explor: explorer.exe /select,"{2}"
+Copy path: {2}{5}
+
+Start Shell: cmd.exe /c start /d ${resource_path} powershell.exe
+WD: None
+Start Default Application: cmd.exe /c start /d ${resource_parent} powershell.exe -command ${resource_path}
+WD: None
+
+0: Drive Letter
+1: Parent Path
+2: Full Path
+3: File Name
+4: Project Name
+5: Line Separator
View
5 misc/es-definitions/es-windows-powershell.txt.bak
@@ -0,0 +1,5 @@
+Windows/Powershell
+Shell Open: cmd.exe /C start "{4}" /D"{1}" powershell.exe
+Shell Run: cmd.exe /C start "{4}" /D"{1}" powershell.exe -command "./{3}"
+Explor: explorer.exe /select,"{2}"
+Copy path: {2}{5}
View
5 misc/es-definitions/es-windows-standard.txt.bak
@@ -0,0 +1,5 @@
+Windows Standard
+cmd.exe /C start "{4}" /D"{1}" cmd.exe /K
+cmd.exe /C start "{4}" /D"{1}" "{3}"
+explorer.exe /select,"{2}"
+{2}{5}
View
20 ...rc-test/de/bastiankrol/startexplorer/customcommands/AbstractCustomCommandFactoryTest.java
@@ -5,12 +5,14 @@
import static org.mockito.Mockito.*;
import org.eclipse.core.commands.Command;
+import org.eclipse.core.commands.IHandler;
import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.handlers.IHandlerActivation;
+import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.menus.CommandContributionItem;
import org.eclipse.ui.menus.CommandContributionItemParameter;
import org.eclipse.ui.services.IServiceLocator;
import org.junit.Before;
-import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
@@ -41,9 +43,15 @@
Command commandMock;
@Mock
+ IHandlerService handlerServiceMock;
+
+ @Mock
CustomCommandForEditorHandler handlerMock;
@Mock
+ IHandlerActivation handlerActivationMock;
+
+ @Mock
CommandContributionItem commandContributionItemMock;
@Before
@@ -56,6 +64,9 @@ public void before() throws Exception
this.commandMock = PowerMockito.mock(Command.class);
when(this.commandServiceMock.getCommand(anyString())).thenReturn(
this.commandMock);
+ when(
+ this.handlerServiceMock.activateHandler(anyString(),
+ (IHandler) anyObject())).thenReturn(this.handlerActivationMock);
initFactory(this.customCommandFactory);
}
@@ -67,19 +78,22 @@ private void initFactory(AbstractCustomCommandFactory customCommandFactory)
.getServiceLocator();
doReturn(this.commandServiceMock).when(customCommandFactory)
.getCommandService(this.serviceLocatorMock);
+ doReturn(this.handlerServiceMock).when(customCommandFactory)
+ .getHandlerService(this.serviceLocatorMock);
doReturn(this.handlerMock).when(customCommandFactory)
.createHandlerForCustomCommand((CommandConfig) anyObject());
doReturn(this.commandContributionItemMock).when(customCommandFactory)
.createContributionItem((CommandContributionItemParameter) anyObject());
}
- @Test
- public void testCleanUp() throws Exception
+ void commonTestCleanUp()
{
when(this.preferenceModelMock.getCommandConfigList()).thenReturn(
oneForBoth());
this.customCommandFactory.getContributionItems();
this.customCommandFactory.doCleanup();
verify(this.commandMock).undefine();
+ verify(this.handlerServiceMock).deactivateHandler(handlerActivationMock);
}
+
}
View
6 .../src-test/de/bastiankrol/startexplorer/customcommands/CustomCommandEditorFactoryTest.java
@@ -69,4 +69,10 @@ public void twoCommandsForEditorOneResourceViewCommandToBeIgnored()
assertEquals("command/editor",
this.parameterCaptor.getAllValues().get(1).label);
}
+
+ @Test
+ public void testCleanUp() throws Exception
+ {
+ commonTestCleanUp();
+ }
}
View
7 ...est/de/bastiankrol/startexplorer/customcommands/CustomCommandResourceViewFactoryTest.java
@@ -68,4 +68,11 @@ public void twoCommandsForResourceViewOneEditorCommandToBeIgnored()
assertEquals("command/resource",
this.parameterCaptor.getAllValues().get(1).label);
}
+
+ @Test
+ public void testCleanUp() throws Exception
+ {
+ commonTestCleanUp();
+ }
+
}
View
89 plugin/src/de/bastiankrol/startexplorer/customcommands/AbstractCustomCommandFactory.java
@@ -15,6 +15,8 @@
import org.eclipse.swt.SWTException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.commands.ICommandService;
+import org.eclipse.ui.handlers.IHandlerActivation;
+import org.eclipse.ui.handlers.IHandlerService;
import org.eclipse.ui.menus.CommandContributionItem;
import org.eclipse.ui.menus.CommandContributionItemParameter;
import org.eclipse.ui.services.IServiceLocator;
@@ -43,14 +45,11 @@ private static synchronized int getNextCustomCommandIdNumber()
IContributionItem[] getContributionItems()
{
- getLogFacility()
- .logDebug("getContributionItems() start");
+ getLogFacility().logDebug("getContributionItems() start");
this.doCleanup();
- getLogFacility().logDebug(
- "getContributionItems() cleanup done");
+ getLogFacility().logDebug("getContributionItems() cleanup done");
- getLogFacility().logDebug(
- "fetching command configs from preferences");
+ getLogFacility().logDebug("fetching command configs from preferences");
this.commandConfigList = getPreferenceModel().getCommandConfigList();
this.customCommandsFromSharedFileHaveBeenAdded = getPreferenceModel()
.customCommandsFromSharedFileHaveBeenAdded();
@@ -64,8 +63,7 @@ private static synchronized int getNextCustomCommandIdNumber()
private IContributionItem[] createContributionItems()
{
- getLogFacility().logDebug(
- "createContributionItems() start");
+ getLogFacility().logDebug("createContributionItems() start");
List<IContributionItem> contributionItemList = new ArrayList<IContributionItem>();
for (CommandConfig commandConfig : this.commandConfigList)
@@ -84,8 +82,7 @@ private static synchronized int getNextCustomCommandIdNumber()
Command command = this.getCommandFromCommandConfig(commandConfig);
getLogFacility().logDebug(
"got command for " + commandConfig.getCommand() + ": " + command);
- getLogFacility().logDebug(
- "command.isDefined(): " + command.isDefined());
+ getLogFacility().logDebug("command.isDefined(): " + command.isDefined());
CommandContributionItemParameter commandContributionItemParameter = new CommandContributionItemParameter( //
this.getServiceLocator(), // IServiceLocator serviceLocator,
@@ -97,15 +94,13 @@ private static synchronized int getNextCustomCommandIdNumber()
.getNameFromCommandConfig(commandConfig);
contributionItemList.add(this
.createContributionItem(commandContributionItemParameter));
- getLogFacility().logDebug(
- "contribution item added to list");
+ getLogFacility().logDebug("contribution item added to list");
}
this.addComeBackLaterDummyCommand(contributionItemList);
CommandContributionItem[] contributionItems = contributionItemList
.toArray(new CommandContributionItem[contributionItemList.size()]);
- getLogFacility().logDebug(
- "createContributionItems() done");
+ getLogFacility().logDebug("createContributionItems() done");
return contributionItems;
}
@@ -172,6 +167,12 @@ CommandContributionItem createContributionItem(
*/
abstract String getNameFromCommandConfig(CommandConfig commandConfig);
+ abstract IHandlerActivation getHandlerActivationFromCommandConfig(
+ CommandConfig commandConfig);
+
+ abstract void setHandlerActivationInCommandConfig(
+ CommandConfig commandConfig, IHandlerActivation handlerActivation);
+
/**
* Callback method for CommandConfig; in case the command object is not yet
* initialized when {@link CommandConfig#getEclipseCommandForResourceView} or
@@ -186,26 +187,34 @@ Command createCommand(CommandConfig commandConfig)
{
getLogFacility().logDebug(
"createCommand(" + commandConfig.getCommand() + ") start");
- ICommandService commandService = this
- .getCommandService(getServiceLocator());
String commandNumberString = Util
.intToString(getNextCustomCommandIdNumber());
String commandId = "de.bastiankrol.startexplorer.customCommand"
+ commandNumberString;
+ ICommandService commandService = this
+ .getCommandService(getServiceLocator());
Command command = commandService.getCommand(commandId);
String commandName = "StartExplorer Custom Command " + commandNumberString;
getLogFacility().logDebug(
"defining command for " + commandConfig.getCommand() + " as "
+ commandName);
command.define(commandName, this.getNameFromCommandConfig(commandConfig),
this.getLazyInitCategory(commandService));
- IHandler handler = this.createHandlerForCustomCommand(commandConfig);
- command.setHandler(handler);
+ this.activateHandler(commandConfig, commandId);
getLogFacility().logDebug(
"createCommand(" + commandConfig.getCommand() + ") done");
return command;
}
+ private void activateHandler(CommandConfig commandConfig, String commandId)
+ {
+ IHandlerService handlerService = (IHandlerService) getHandlerService(getServiceLocator());
+ IHandler handler = this.createHandlerForCustomCommand(commandConfig);
+ IHandlerActivation handlerActivation = handlerService.activateHandler(
+ commandId, handler);
+ this.setHandlerActivationInCommandConfig(commandConfig, handlerActivation);
+ }
+
/**
* Returns {@code true} if and only if the command is enabled for this view
* (resource view or editor).
@@ -245,8 +254,7 @@ private Category getLazyInitCategory(ICommandService commandService)
*/
public void doCleanupAtPluginStop()
{
- getLogFacility().logDebug(
- "doCleanupAtPluginStop() start");
+ getLogFacility().logDebug("doCleanupAtPluginStop() start");
this.doCleanup(true);
if (this.customCommandCategory != null)
{
@@ -258,8 +266,7 @@ public void doCleanupAtPluginStop()
this.dummyCommandComeBackLater.undefine();
this.dummyCommandComeBackLater = null;
}
- getLogFacility()
- .logDebug("doCleanupAtPluginStop() done");
+ getLogFacility().logDebug("doCleanupAtPluginStop() done");
}
/**
@@ -271,12 +278,11 @@ void doCleanup()
}
/**
- * Undefines all created commands.
+ * Undefines all created commands and deactivates all handlers.
*/
private void doCleanup(boolean atPluginStop)
{
- getLogFacility().logDebug(
- "doCleanup(" + atPluginStop + ") start");
+ getLogFacility().logDebug("doCleanup(" + atPluginStop + ") start");
if (this.commandConfigList != null)
{
for (CommandConfig commandConfig : this.commandConfigList)
@@ -285,16 +291,21 @@ private void doCleanup(boolean atPluginStop)
.getEclipseCommandForResourceViewNoInit();
this.disposeCommand(eclipseCommandForResourceViewNoInit, atPluginStop);
commandConfig.deleteEclipseCommandForResourceView();
+ deactivateHandler(commandConfig.getHandlerActivationForResourceView(),
+ commandConfig.getNameForResourcesMenu());
+ commandConfig.setHandlerActivationForResourceView(null);
Command eclipseCommandForEditorNoInit = commandConfig
.getEclipseCommandForEditorNoInit();
this.disposeCommand(eclipseCommandForEditorNoInit, atPluginStop);
commandConfig.deleteEclipseCommandForEditor();
+ deactivateHandler(commandConfig.getHandlerActivationForEditor(),
+ commandConfig.getNameForTextSelectionMenu());
+ commandConfig.setHandlerActivationForEditor(null);
}
this.commandConfigList = null;
}
- getLogFacility().logDebug(
- "doCleanup(" + atPluginStop + ") done");
+ getLogFacility().logDebug("doCleanup(" + atPluginStop + ") done");
}
private void disposeCommand(Command command, boolean atPluginStop)
@@ -303,8 +314,7 @@ private void disposeCommand(Command command, boolean atPluginStop)
{
try
{
- getLogFacility().logDebug(
- "undefining command: " + command);
+ getLogFacility().logDebug("undefining command: " + command);
command.undefine();
getLogFacility().logDebug("command undefined");
}
@@ -324,6 +334,22 @@ private void disposeCommand(Command command, boolean atPluginStop)
}
}
+ private void deactivateHandler(IHandlerActivation handlerActivation,
+ String name)
+ {
+ if (handlerActivation != null)
+ {
+ IHandlerService handlerService = this.getHandlerService(this
+ .getServiceLocator());
+ if (handlerService != null)
+ {
+ getLogFacility().logDebug("deactivating handler for: " + name);
+ handlerService.deactivateHandler(handlerActivation);
+ getLogFacility().logDebug("handler " + name + " deactivated.");
+ }
+ }
+ }
+
PreferenceModel getPreferenceModel()
{
return getPluginContext().getPreferenceModel();
@@ -338,4 +364,9 @@ ICommandService getCommandService(IServiceLocator serviceLocator)
{
return (ICommandService) serviceLocator.getService(ICommandService.class);
}
+
+ IHandlerService getHandlerService(IServiceLocator serviceLocator)
+ {
+ return (IHandlerService) serviceLocator.getService(IHandlerService.class);
+ }
}
View
57 plugin/src/de/bastiankrol/startexplorer/customcommands/CommandConfig.java
@@ -3,6 +3,7 @@
import static de.bastiankrol.startexplorer.Activator.*;
import org.eclipse.core.commands.Command;
+import org.eclipse.ui.handlers.IHandlerActivation;
import de.bastiankrol.startexplorer.ResourceType;
@@ -33,11 +34,23 @@
private Command eclipseCommandForResourceView;
/**
+ * Stores the handler activation token for the resource view, to be able to
+ * deactivate it againe
+ */
+ private IHandlerActivation handlerActivationForResourceView;
+
+ /**
* Stores the Eclipse command object for the editor, once it has been created.
*/
private Command eclipseCommandForEditor;
/**
+ * Stores the handler activation token for the editor, to be able to
+ * deactivate it againe
+ */
+ private IHandlerActivation handlerActivationForEditor;
+
+ /**
* Creates an empty CommandConfig.
*/
public CommandConfig()
@@ -272,6 +285,28 @@ else if (eclipseCommandForResourceView == null)
}
/**
+ * Returns the handler activation token for the resource view or {@code null}
+ * if it has not been set yet.
+ *
+ * @return the handler activation token or {@code null}
+ */
+ IHandlerActivation getHandlerActivationForResourceView()
+ {
+ return this.handlerActivationForResourceView;
+ }
+
+ /**
+ * Sets the handler activation token for the resource view.
+ *
+ * @param handlerActivation the handler activation token or {@code null} (to
+ * remove an existing reference)
+ */
+ void setHandlerActivationForResourceView(IHandlerActivation handlerActivation)
+ {
+ this.handlerActivationForResourceView = handlerActivation;
+ }
+
+ /**
* Returns the Eclipse command object for the editor; if it has not been
* created yet, it will be created on demand.
*
@@ -293,6 +328,28 @@ else if (this.eclipseCommandForEditor == null)
}
/**
+ * Returns the handler activation token for the editor or {@code null} if it
+ * has not been set yet.
+ *
+ * @return the handler activation token or {@code null}
+ */
+ IHandlerActivation getHandlerActivationForEditor()
+ {
+ return this.handlerActivationForEditor;
+ }
+
+ /**
+ * Sets the handler activation token for the editor.
+ *
+ * @param handlerActivation the handler activation token or {@code null} (to
+ * remove an existing reference)
+ */
+ void setHandlerActivationForEditor(IHandlerActivation handlerActivation)
+ {
+ this.handlerActivationForEditor = handlerActivation;
+ }
+
+ /**
* Simply returns the command without creating it on demand.
*
* @return eclipseCommandForResourceView or {@code null} if not yet
View
15 plugin/src/de/bastiankrol/startexplorer/customcommands/CustomCommandEditorFactory.java
@@ -2,6 +2,7 @@
import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.IHandler;
+import org.eclipse.ui.handlers.IHandlerActivation;
import de.bastiankrol.startexplorer.handlers.CustomCommandForEditorHandler;
@@ -35,6 +36,20 @@ Command getCommandFromCommandConfig(CommandConfig commandConfig)
return commandConfig.getEclipseCommandForEditor(this);
}
+ @Override
+ IHandlerActivation getHandlerActivationFromCommandConfig(
+ CommandConfig commandConfig)
+ {
+ return commandConfig.getHandlerActivationForEditor();
+ }
+
+ @Override
+ void setHandlerActivationInCommandConfig(CommandConfig commandConfig,
+ IHandlerActivation handlerActivation)
+ {
+ commandConfig.setHandlerActivationForEditor(handlerActivation);
+ }
+
/**
* {@inheritDoc}
*
View
15 plugin/src/de/bastiankrol/startexplorer/customcommands/CustomCommandResourceViewFactory.java
@@ -2,6 +2,7 @@
import org.eclipse.core.commands.Command;
import org.eclipse.core.commands.IHandler;
+import org.eclipse.ui.handlers.IHandlerActivation;
import de.bastiankrol.startexplorer.handlers.CustomCommandForResourceHandler;
@@ -36,6 +37,20 @@ Command getCommandFromCommandConfig(CommandConfig commandConfig)
return commandConfig.getEclipseCommandForResourceView(this);
}
+ @Override
+ IHandlerActivation getHandlerActivationFromCommandConfig(
+ CommandConfig commandConfig)
+ {
+ return commandConfig.getHandlerActivationForResourceView();
+ }
+
+ @Override
+ void setHandlerActivationInCommandConfig(CommandConfig commandConfig,
+ IHandlerActivation handlerActivation)
+ {
+ commandConfig.setHandlerActivationForResourceView(handlerActivation);
+ }
+
/**
* {@inheritDoc}
*
View
21 todo.txt.bak
@@ -0,0 +1,21 @@
+* Test folder scanning with large workspace
+
+* Advertise in company skype chat
+
+* Test path with spaces on linux. If problematic, maybe find a different workaround than quoting it.
+
+* Copy resource path to clipboard in editor never uses the selection, always the file opened in the editor
+
+* Put something in the GitHub-wiki. Examples/ideas:
+ - custom commands:
+ - Open WinSCP for folder & direct upload of a file with WinSCP
+ - Open jar file with WinZip/7Zip
+ - execute groovy script on file/folder
+ - Start BeyondCompare on two folders / files
+
+* Screenshots for README.markdown and project page
+
+* Remove duplication
+ - help
+ + plugin/de.bastiankrol.startexplorer/help
+ + /startexplorer-gh-pages/help

0 comments on commit e26b16b

Please sign in to comment.