Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrian de Alwis2012-11-23 13:27:46 +0000
committerBrian de Alwis2012-11-23 13:27:46 +0000
commitdc11b8233957e74d3956af62a614c6622957d58d (patch)
tree530378d424abf4e851cfe0ba952467329e975d45
parent341fb23e55e112e5adfd2ce25e4134df72c4db7f (diff)
downloadorg.eclipse.e4.tools-dc11b8233957e74d3956af62a614c6622957d58d.tar.gz
org.eclipse.e4.tools-dc11b8233957e74d3956af62a614c6622957d58d.tar.xz
org.eclipse.e4.tools-dc11b8233957e74d3956af62a614c6622957d58d.zip
Bug 394948 - Change CSS Spy & Scratchpad keybindings away from F4I20121126-0630
Replace existing bindings if they were the system-provided bindings, but don't replace user-provided or user-deleted bindings.
-rw-r--r--bundles/org.eclipse.e4.tools.css.spy/META-INF/MANIFEST.MF4
-rw-r--r--bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/SpyInstaller.java51
2 files changed, 47 insertions, 8 deletions
diff --git a/bundles/org.eclipse.e4.tools.css.spy/META-INF/MANIFEST.MF b/bundles/org.eclipse.e4.tools.css.spy/META-INF/MANIFEST.MF
index f747b15e..92c3363f 100644
--- a/bundles/org.eclipse.e4.tools.css.spy/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.e4.tools.css.spy/META-INF/MANIFEST.MF
@@ -15,9 +15,11 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.6.0",
org.eclipse.e4.ui.widgets;bundle-version="0.11.0"
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Bundle-ActivationPolicy: lazy
-Import-Package: javax.inject;version="1.0.0",
+Import-Package: javax.inject,
org.eclipse.e4.core.contexts,
org.eclipse.e4.core.di.annotations,
+ org.eclipse.e4.core.services.log,
org.eclipse.e4.core.services.statusreporter,
+ org.eclipse.e4.ui.bindings,
org.eclipse.e4.ui.services,
org.w3c.css.sac;version="1.3.0"
diff --git a/bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/SpyInstaller.java b/bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/SpyInstaller.java
index 04ca2854..99ac910b 100644
--- a/bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/SpyInstaller.java
+++ b/bundles/org.eclipse.e4.tools.css.spy/src/org/eclipse/e4/tools/css/spy/SpyInstaller.java
@@ -13,6 +13,9 @@ package org.eclipse.e4.tools.css.spy;
import javax.inject.Inject;
import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.core.di.annotations.Optional;
+import org.eclipse.e4.core.services.log.Logger;
+import org.eclipse.e4.ui.bindings.EBindingService;
import org.eclipse.e4.ui.model.application.MApplication;
import org.eclipse.e4.ui.model.application.commands.MBindingTable;
import org.eclipse.e4.ui.model.application.commands.MCommand;
@@ -39,6 +42,10 @@ public class SpyInstaller {
@Inject
protected MApplication app;
+
+ @Inject
+ @Optional
+ protected Logger logger;
@Execute
public void execute() {
@@ -54,13 +61,13 @@ public class SpyInstaller {
// M3 = Alt
// M4 = Control on MacOS X, Command on others
installBinding("org.eclipse.ui.contexts.dialogAndWindow",
- openSpyCommand, "M2+M3+F5"); // Alt-Shift-F5
+ openSpyCommand, "M2+M3+F5");
MCommand openScratchpadCommand = installCommand("Open CSS Scratchpad",
OPEN_SCRATCHPAD_COMMAND_ID);
installHandler(openScratchpadCommand, SCRATCHPAD_HANDLER_ID, SCRATCHPAD_HANDLER_URI);
installBinding("org.eclipse.ui.contexts.dialogAndWindow",
- openScratchpadCommand, "M2+M3+F6"); // Alt-Shift-F5
+ openScratchpadCommand, "M2+M3+F6");
}
private void removeBindingTable(String tableId) {
@@ -111,9 +118,25 @@ public class SpyInstaller {
// guaranteed an element id.
MBindingTable bindingTable = null;
for(MBindingTable table : app.getBindingTables()) {
- for(MKeyBinding binding : table.getBindings()) {
- if(binding.getCommand() == cmd) {
- return;
+ // check if the binding was a user-defined binding, otherwise remove
+ for (MKeyBinding binding : table.getBindings()) {
+ if (binding.getCommand() == cmd) {
+ // if explicitly set or unbound by the user...
+ if (binding.getTags().contains(
+ EBindingService.TYPE_ATTR_TAG + ":user")) {
+ logInfo("Found user-remapped binding for {0} to {1}: not rebinding",
+ cmd.getElementId(), binding.getKeySequence());
+ return;
+ } else if (binding.getTags().contains(
+ EBindingService.DELETED_BINDING_TAG)) {
+ logInfo("User deleted binding for {0}: not rebinding",
+ cmd.getElementId());
+ return;
+ }
+ logInfo("Removing existing binding for {0} to {1}",
+ cmd.getElementId(), binding.getKeySequence());
+ table.getBindings().remove(binding);
+ break;
}
}
if (table.getBindingContext() != null
@@ -124,8 +147,8 @@ public class SpyInstaller {
}
if(bindingTable == null) {
- System.err.println("Cannot find table for binding context: "
- + bindingContextId);
+ logError("Cannot find table for binding context: {0}",
+ bindingContextId);
return;
}
@@ -137,4 +160,18 @@ public class SpyInstaller {
bindingTable.getBindings().add(binding);
}
+ private void logInfo(String message, Object... args) {
+ if (logger == null) {
+ return;
+ }
+ logger.info(message, args);
+ }
+
+ private void logError(String message, Object... args) {
+ if (logger == null) {
+ return;
+ }
+ logger.error(message, args);
+ }
+
}

Back to the top