Fixed the restore defaults method.
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/commands/KeysPreferencePage.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/commands/KeysPreferencePage.java
index ca81817..46fc394 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/commands/KeysPreferencePage.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/commands/KeysPreferencePage.java
@@ -47,6 +47,7 @@
import org.eclipse.jface.bindings.keys.KeyStroke;
import org.eclipse.jface.dialogs.ErrorDialog;
import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.jface.util.SafeRunnable;
@@ -520,7 +521,7 @@
tabFolder.setSelection(selectedTab);
}
- // TODO Make this actually do something (i.e., define the help context)
+ // TODO Add a help context
// Link a help context to this preference page.
// helpSystem.setHelp(parent,
// IWorkbenchHelpContextIds.KEYS_PREFERENCE_PAGE);
@@ -1269,45 +1270,54 @@
return super.performCancel();
}
- protected void performDefaults() {
- /*
- * TODO String activeKeyConfigurationId = getSchemeId(); List
- * preferenceKeySequenceBindingDefinitions = new ArrayList();
- * KeySequenceBindingNode.getKeySequenceBindingDefinitions(tree,
- * KeySequence.getInstance(), 0,
- * preferenceKeySequenceBindingDefinitions);
- *
- * if (activeKeyConfigurationId != null ||
- * !preferenceKeySequenceBindingDefinitions.isEmpty()) { final String
- * title = Util.translateString(RESOURCE_BUNDLE,
- * "restoreDefaultsMessageBoxText"); //$NON-NLS-1$ final String message =
- * Util.translateString(RESOURCE_BUNDLE,
- * "restoreDefaultsMessageBoxMessage"); //$NON-NLS-1$ final boolean
- * confirmed = MessageDialog.openConfirm(getShell(), title, message);
- *
- * if (confirmed) {
- * setScheme(IWorkbenchConstants.DEFAULT_ACCELERATOR_CONFIGURATION_ID);
- * Iterator iterator = preferenceKeySequenceBindingDefinitions
- * .iterator();
- *
- * while (iterator.hasNext()) { KeySequenceBindingDefinition
- * keySequenceBindingDefinition = (KeySequenceBindingDefinition)
- * iterator .next(); KeySequenceBindingNode.remove(tree,
- * keySequenceBindingDefinition.getKeySequence(),
- * keySequenceBindingDefinition.getContextId(),
- * keySequenceBindingDefinition .getKeyConfigurationId(), 0,
- * keySequenceBindingDefinition.getPlatform(),
- * keySequenceBindingDefinition.getLocale(),
- * keySequenceBindingDefinition.getCommandId()); } } }
- */
+ protected final void performDefaults() {
+ // Ask the user to confirm
+ final String title = Util.translateString(RESOURCE_BUNDLE,
+ "restoreDefaultsMessageBoxText"); //$NON-NLS-1$
+ final String message = Util.translateString(RESOURCE_BUNDLE,
+ "restoreDefaultsMessageBoxMessage"); //$NON-NLS-1$
+ final boolean confirmed = MessageDialog.openConfirm(getShell(), title,
+ message);
+ if (confirmed) {
+ // Fix the scheme in the local changes.
+ final String defaultSchemeId = bindingService.getDefaultSchemeId();
+ final Scheme defaultScheme = localChangeManager
+ .getScheme(defaultSchemeId);
+ try {
+ localChangeManager.setActiveScheme(defaultScheme);
+ } catch (final NotDefinedException e) {
+ // At least we tried....
+ }
+
+ // Fix the bindings in the local changes.
+ final Set currentBindings = localChangeManager.getBindings();
+ final Set trimmedBindings = new HashSet();
+ final Iterator bindingItr = currentBindings.iterator();
+ while (bindingItr.hasNext()) {
+ final Binding binding = (Binding) bindingItr.next();
+ if (binding.getType() != Binding.USER) {
+ trimmedBindings.add(binding);
+ }
+ }
+ localChangeManager.setBindings(trimmedBindings);
+
+ // Apply the changes.
+ try {
+ bindingService.savePreferences(defaultScheme, trimmedBindings);
+ } catch (final IOException e) {
+ logPreferenceStoreException(e);
+ }
+ }
+
+ setScheme(localChangeManager.getActiveScheme()); // update the scheme
update();
+ super.performDefaults();
}
- public boolean performOk() {
+ public final boolean performOk() {
// Save the preferences.
try {
- // TODO This is not working for the active scheme.
bindingService.savePreferences(
localChangeManager.getActiveScheme(), localChangeManager
.getBindings());
@@ -2115,7 +2125,7 @@
* Set the associated image based on the type of binding. Either it
* is a user binding or a system binding.
*
- * TODO Do we need to do more here?
+ * TODO Identify more image types.
*/
if (binding.getType() == Binding.SYSTEM) {
tableItem.setImage(0, IMAGE_BLANK);
@@ -2163,7 +2173,7 @@
* Set the associated image based on the type of binding. Either it
* is a user binding or a system binding.
*
- * TODO Do we need to do more here?
+ * TODO Identify more image types.
*/
if (binding.getType() == Binding.SYSTEM) {
tableItem.setImage(0, IMAGE_BLANK);
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/BindingPersistence.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/BindingPersistence.java
index ee921c1..8313d13 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/BindingPersistence.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/BindingPersistence.java
@@ -35,6 +35,9 @@
* development for Eclipse 3.1. This class -- its existence, its name and its
* methods -- are in flux. Do not use this class yet.
* </p>
+ * <p>
+ * TODO Add methods for reading the extension registry and the preference store.
+ * </p>
*
* @since 3.1
*/
@@ -97,6 +100,20 @@
private static final String WORKBENCH_PREFERENCE_KEY = "org.eclipse.ui.commands"; //$NON-NLS-1$
/**
+ * Returns the default scheme identifier for the currently running
+ * application.
+ *
+ * @return The default scheme identifier (<code>String</code>); never
+ * <code>null</code>, but may be empty or point to an undefined
+ * scheme.
+ */
+ public static final String getDefaultSchemeId() {
+ final IPreferenceStore store = PlatformUI.getPreferenceStore();
+ return store
+ .getDefaultString(IWorkbenchPreferenceConstants.KEY_CONFIGURATION_ID);
+ }
+
+ /**
* Writes the given active scheme and bindings to the preference store. Only
* bindings that are of the <code>Binding.USER</code> type will be
* written; the others will be ignored.
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/BindingService.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/BindingService.java
index a84f89b..01fc040 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/BindingService.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/keys/BindingService.java
@@ -71,6 +71,10 @@
return bindingManager.getBindings();
}
+ public final String getDefaultSchemeId() {
+ return BindingPersistence.getDefaultSchemeId();
+ }
+
public final Collection getDefinedSchemeIds() {
return bindingManager.getDefinedSchemeIds();
}
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/keys/IBindingService.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/keys/IBindingService.java
index 43a0c54..6d6b85e 100644
--- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/keys/IBindingService.java
+++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/keys/IBindingService.java
@@ -64,6 +64,16 @@
public Set getBindings();
/**
+ * Returns the default scheme identifier for the currently running
+ * application.
+ *
+ * @return The default scheme identifier (<code>String</code>); never
+ * <code>null</code>, but may be empty or point to an undefined
+ * scheme.
+ */
+ public String getDefaultSchemeId();
+
+ /**
* Returns the collection of the identifiers for all of the defined schemes
* in the workbench.
*