Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Webster2013-07-31 17:51:38 +0000
committerGerrit Code Review @ Eclipse.org2013-08-14 15:20:12 +0000
commit08785cd6edaeb6b8b2d19751f4e13dba1acb1726 (patch)
treec428f933fa988ca647484daea32e521d865b2a8a
parent527912417061e3e8a74c37a796f9cffb31852d3f (diff)
downloadeclipse.platform.ui-08785cd6edaeb6b8b2d19751f4e13dba1acb1726.tar.gz
eclipse.platform.ui-08785cd6edaeb6b8b2d19751f4e13dba1acb1726.tar.xz
eclipse.platform.ui-08785cd6edaeb6b8b2d19751f4e13dba1acb1726.zip
Bug 411602 - CTRL+Q keyboard shortcut in any dialog closes the workbench
without option to save Scrub a workbench based model that has the left-over e4 commands in it. Change-Id: Ib24401ad49205b689f834b7d8f1e60adbe59e505
-rw-r--r--bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ModelMigrationProcessor.java108
-rw-r--r--bundles/org.eclipse.ui.workbench/plugin.xml4
2 files changed, 112 insertions, 0 deletions
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ModelMigrationProcessor.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ModelMigrationProcessor.java
new file mode 100644
index 00000000000..05bfcd37252
--- /dev/null
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/ModelMigrationProcessor.java
@@ -0,0 +1,108 @@
+/*******************************************************************************
+ * Copyright (c) 2013 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ ******************************************************************************/
+package org.eclipse.ui.internal;
+
+import java.util.HashSet;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+import org.eclipse.e4.core.contexts.IEclipseContext;
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.ui.model.application.MApplication;
+import org.eclipse.e4.ui.model.application.commands.MBindingContext;
+import org.eclipse.e4.ui.model.application.commands.MBindingTable;
+import org.eclipse.e4.ui.model.application.commands.MCommand;
+import org.eclipse.e4.ui.model.application.commands.MHandler;
+import org.eclipse.e4.ui.model.application.commands.MKeyBinding;
+
+public class ModelMigrationProcessor {
+ // remove e4 commands from existing IDE models
+ // Bug 411602 - CTRL+Q keyboard shortcut in any dialog closes the workbench
+ // without option to save
+ private static final String MIGRATION_001 = "ModelMigrationProcessor.001"; //$NON-NLS-1$
+
+ @Execute
+ public void process(MApplication application, IEclipseContext context) {
+ if (!application.getTags().contains(MIGRATION_001)) {
+ application.getTags().add(MIGRATION_001);
+ removeE4CommandsFromIDE(application);
+ }
+ }
+
+ /**
+ * @param application
+ */
+ private void removeE4CommandsFromIDE(MApplication application) {
+ List<MCommand> commands = application.getCommands();
+ Set<MCommand> toBeRemoved = new HashSet<MCommand>();
+ for (MCommand command : commands) {
+ final String elementId = command.getElementId();
+ if ("e4.exit".equals(elementId)) { //$NON-NLS-1$
+ toBeRemoved.add(command);
+ } else if ("e4.show.view".equals(elementId)) { //$NON-NLS-1$
+ toBeRemoved.add(command);
+ } else if ("org.eclipse.e4.ui.saveCommands".equals(elementId)) { //$NON-NLS-1$
+ toBeRemoved.add(command);
+ } else if ("org.eclipse.e4.ui.saveAllCommands".equals(elementId)) { //$NON-NLS-1$
+ toBeRemoved.add(command);
+ }
+ if (toBeRemoved.size() > 3) {
+ break;
+ }
+ }
+ if (toBeRemoved.size() == 0) {
+ return;
+ }
+ List<MHandler> handlers = application.getHandlers();
+ Iterator<MHandler> i = handlers.iterator();
+ int removed = 0;
+ while (i.hasNext() && removed < 4) {
+ MHandler handler = i.next();
+ if (toBeRemoved.contains(handler.getCommand())) {
+ i.remove();
+ removed++;
+ }
+ }
+ List<MBindingContext> bindingContexts = application.getBindingContexts();
+ MBindingContext dialogAndWindow = null;
+ for (MBindingContext c : bindingContexts) {
+ if ("org.eclipse.ui.contexts.dialogAndWindow".equals(c.getElementId())) { //$NON-NLS-1$
+ dialogAndWindow = c;
+ break;
+ }
+ }
+
+ if (dialogAndWindow != null) {
+ List<MBindingTable> bindingTables = application.getBindingTables();
+ MBindingTable dAWTable = null;
+ for (MBindingTable table : bindingTables) {
+ if (dialogAndWindow.equals(table.getBindingContext())) {
+ dAWTable = table;
+ break;
+ }
+ }
+ if (dAWTable != null) {
+ List<MKeyBinding> bindings = dAWTable.getBindings();
+ Iterator<MKeyBinding> j = bindings.iterator();
+ removed = 0;
+ while (j.hasNext() && removed < 3) {
+ MKeyBinding binding = j.next();
+ if (toBeRemoved.contains(binding.getCommand())) {
+ j.remove();
+ removed++;
+ }
+ }
+ }
+ }
+ commands.removeAll(toBeRemoved);
+ }
+
+}
diff --git a/bundles/org.eclipse.ui.workbench/plugin.xml b/bundles/org.eclipse.ui.workbench/plugin.xml
index 5e5e6c2d4c6..e02b96cc313 100644
--- a/bundles/org.eclipse.ui.workbench/plugin.xml
+++ b/bundles/org.eclipse.ui.workbench/plugin.xml
@@ -22,6 +22,10 @@
beforefragment="true"
class="org.eclipse.ui.internal.BindingToModelProcessor">
</processor>
+ <processor
+ beforefragment="true"
+ class="org.eclipse.ui.internal.ModelMigrationProcessor">
+ </processor>
</extension>
<extension
point="org.eclipse.e4.ui.css.core.propertyHandler">

Back to the top