Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Sohn2013-08-15 16:52:55 -0400
committerMatthias Sohn2013-08-23 04:49:06 -0400
commitfdc286a3ccf49037c55919f24c87daae4b516392 (patch)
tree21b13dd5e6224c94651c45f04e53341fa92a1b1e
parent71389064a61d9f19a260b74e0fe94cf20432da64 (diff)
downloadegit-fdc286a3ccf49037c55919f24c87daae4b516392.tar.gz
egit-fdc286a3ccf49037c55919f24c87daae4b516392.tar.xz
egit-fdc286a3ccf49037c55919f24c87daae4b516392.zip
Lookup keybinding used to trigger content assist
EGit hardcoded the keybinding for content assist to "CTRL+Space". Instead it should dynamically lookup the configured keybinding. Bug: 415133 Change-Id: I7ea30a5e162d6e7e63e8d220ed514f3af4366e27 Signed-off-by: Matthias Sohn <matthias.sohn@sap.com> Signed-off-by: Robin Stocker <robin@nibor.org>
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIUtils.java67
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchGerritChangePage.java14
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/gerrit/GerritConfigurationPage.java14
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushToGerritPage.java14
4 files changed, 60 insertions, 49 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIUtils.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIUtils.java
index 3c695c6d4b..642a79e1a8 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIUtils.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIUtils.java
@@ -28,8 +28,9 @@ import org.eclipse.egit.ui.internal.UIIcons;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.internal.components.RefContentProposal;
import org.eclipse.jface.action.MenuManager;
+import org.eclipse.jface.bindings.Trigger;
+import org.eclipse.jface.bindings.TriggerSequence;
import org.eclipse.jface.bindings.keys.KeyStroke;
-import org.eclipse.jface.bindings.keys.ParseException;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.fieldassist.ContentProposalAdapter;
import org.eclipse.jface.fieldassist.ControlDecoration;
@@ -216,8 +217,7 @@ public class UIUtils {
/**
* Adds a "previously used values" content proposal handler to a text field.
* <p>
- * The keyboard shortcut will be "M1+SPACE" and the list will be limited to
- * 10 values.
+ * The list will be limited to 10 values.
*
* @param textField
* the text field
@@ -228,17 +228,16 @@ public class UIUtils {
*/
public static IPreviousValueProposalHandler addPreviousValuesContentProposalToText(
final Text textField, final String preferenceKey) {
- KeyStroke stroke;
- try {
- stroke = KeyStroke.getInstance("M1+SPACE"); //$NON-NLS-1$
- addBulbDecorator(textField, NLS.bind(
- UIText.UIUtils_PressShortcutMessage, stroke.format()));
- } catch (ParseException e1) {
- Activator.handleError(e1.getMessage(), e1, false);
- stroke = null;
+ KeyStroke stroke = UIUtils
+ .getKeystrokeOfBestActiveBindingFor(IWorkbenchCommandConstants.EDIT_CONTENT_ASSIST);
+ if (stroke == null)
addBulbDecorator(textField,
UIText.UIUtils_StartTypingForPreviousValuesMessage);
- }
+ else
+ addBulbDecorator(
+ textField,
+ NLS.bind(UIText.UIUtils_PressShortcutMessage,
+ stroke.format()));
IContentProposalProvider cp = new IContentProposalProvider() {
@@ -375,17 +374,16 @@ public class UIUtils {
*/
public static final void addRefContentProposalToText(final Text textField,
final Repository repository, final IRefListProvider refListProvider) {
- KeyStroke stroke;
- try {
- stroke = KeyStroke.getInstance("M1+SPACE"); //$NON-NLS-1$
- UIUtils.addBulbDecorator(textField, NLS.bind(
- UIText.UIUtils_PressShortcutMessage, stroke.format()));
- } catch (ParseException e1) {
- Activator.handleError(e1.getMessage(), e1, false);
- stroke = null;
- UIUtils.addBulbDecorator(textField,
+ KeyStroke stroke = UIUtils
+ .getKeystrokeOfBestActiveBindingFor(IWorkbenchCommandConstants.EDIT_CONTENT_ASSIST);
+ if (stroke == null)
+ addBulbDecorator(textField,
UIText.UIUtils_StartTypingForPreviousValuesMessage);
- }
+ else
+ addBulbDecorator(
+ textField,
+ NLS.bind(UIText.UIUtils_PressShortcutMessage,
+ stroke.format()));
IContentProposalProvider cp = new IContentProposalProvider() {
public IContentProposal[] getProposals(String contents, int position) {
@@ -709,4 +707,29 @@ public class UIUtils {
return UIText.UIUtils_ShowInMenuLabel;
}
+
+ /**
+ * Look up best active binding's keystroke for the given command
+ *
+ * @param commandId
+ * The identifier of the command for which the best active
+ * binding's keystroke should be retrieved; must not be null.
+ * @return {@code KeyStroke} for the best active binding for the specified
+ * commandId or {@code null} if no binding is defined or if the
+ * binding service returns a {@code TriggerSequence} containing more
+ * than one {@code Trigger}.
+ */
+ public static KeyStroke getKeystrokeOfBestActiveBindingFor(String commandId) {
+ IBindingService bindingService = (IBindingService) PlatformUI
+ .getWorkbench().getAdapter(IBindingService.class);
+ TriggerSequence ts = bindingService.getBestActiveBindingFor(commandId);
+ if (ts == null)
+ return null;
+
+ Trigger[] triggers = ts.getTriggers();
+ if (triggers.length == 1 && triggers[0] instanceof KeyStroke)
+ return (KeyStroke) triggers[0];
+ else
+ return null;
+ }
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchGerritChangePage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchGerritChangePage.java
index 0ccf76a29e..274df9be8b 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchGerritChangePage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/fetch/FetchGerritChangePage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2010 SAP AG.
+ * Copyright (c) 2010, 2013 SAP AG 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
@@ -38,7 +38,6 @@ import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.internal.branch.BranchOperationUI;
import org.eclipse.egit.ui.internal.dialogs.CheckoutConflictDialog;
import org.eclipse.jface.bindings.keys.KeyStroke;
-import org.eclipse.jface.bindings.keys.ParseException;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.fieldassist.ContentProposalAdapter;
@@ -82,6 +81,7 @@ import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IWorkbenchCommandConstants;
import org.eclipse.ui.PlatformUI;
/**
@@ -684,16 +684,12 @@ public class FetchGerritChangePage extends WizardPage {
}
private void addRefContentProposalToText(final Text textField) {
- KeyStroke stroke;
- try {
- stroke = KeyStroke.getInstance("CTRL+SPACE"); //$NON-NLS-1$
+ KeyStroke stroke = UIUtils
+ .getKeystrokeOfBestActiveBindingFor(IWorkbenchCommandConstants.EDIT_CONTENT_ASSIST);
+ if (stroke != null)
UIUtils.addBulbDecorator(textField, NLS.bind(
UIText.FetchGerritChangePage_ContentAssistTooltip,
stroke.format()));
- } catch (ParseException e1) {
- Activator.handleError(e1.getMessage(), e1, false);
- stroke = null;
- }
IContentProposalProvider cp = new IContentProposalProvider() {
public IContentProposal[] getProposals(String contents, int position) {
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/gerrit/GerritConfigurationPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/gerrit/GerritConfigurationPage.java
index 76dd4f0d5a..e31c232d90 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/gerrit/GerritConfigurationPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/gerrit/GerritConfigurationPage.java
@@ -1,6 +1,6 @@
/*******************************************************************************
* Copyright (C) 2011, Stefan Lay <stefan.lay@sap.com>
- * Copyright (C) 2011, Matthias Sohn <matthias.sohn@sap.com>
+ * Copyright (C) 2011, 2013, Matthias Sohn <matthias.sohn@sap.com>
*
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
@@ -25,7 +25,6 @@ import org.eclipse.egit.ui.internal.SWTUtils;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.internal.components.RepositorySelectionPage.Protocol;
import org.eclipse.jface.bindings.keys.KeyStroke;
-import org.eclipse.jface.bindings.keys.ParseException;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.fieldassist.ContentProposalAdapter;
import org.eclipse.jface.fieldassist.IContentProposal;
@@ -49,6 +48,7 @@ import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IWorkbenchCommandConstants;
import org.eclipse.ui.PlatformUI;
/**
@@ -299,16 +299,12 @@ class GerritConfigurationPage extends WizardPage {
}
private void addRefContentProposalToText(final Text textField) {
- KeyStroke stroke;
- try {
- stroke = KeyStroke.getInstance("CTRL+SPACE"); //$NON-NLS-1$
+ KeyStroke stroke = UIUtils
+ .getKeystrokeOfBestActiveBindingFor(IWorkbenchCommandConstants.EDIT_CONTENT_ASSIST);
+ if (stroke != null)
UIUtils.addBulbDecorator(textField, NLS.bind(
UIText.GerritConfigurationPage_BranchTooltipHover,
stroke.format()));
- } catch (ParseException e1) {
- Activator.handleError(e1.getMessage(), e1, false);
- stroke = null;
- }
IContentProposalProvider cp = new IContentProposalProvider() {
public IContentProposal[] getProposals(String contents, int position) {
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushToGerritPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushToGerritPage.java
index 296a069694..3f429c0f8e 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushToGerritPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/push/PushToGerritPage.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 SAP AG.
+ * Copyright (c) 2012, 2013 SAP AG 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
@@ -31,7 +31,6 @@ import org.eclipse.egit.ui.UIUtils;
import org.eclipse.egit.ui.internal.UIText;
import org.eclipse.egit.ui.internal.credentials.EGitCredentialsProvider;
import org.eclipse.jface.bindings.keys.KeyStroke;
-import org.eclipse.jface.bindings.keys.ParseException;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogSettings;
import org.eclipse.jface.fieldassist.ContentProposalAdapter;
@@ -57,6 +56,7 @@ import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.IWorkbenchCommandConstants;
/**
* Push the current HEAD to Gerrit
@@ -245,16 +245,12 @@ class PushToGerritPage extends WizardPage {
}
private void addRefContentProposalToText(final Text textField) {
- KeyStroke stroke;
- try {
- stroke = KeyStroke.getInstance("CTRL+SPACE"); //$NON-NLS-1$
+ KeyStroke stroke = UIUtils
+ .getKeystrokeOfBestActiveBindingFor(IWorkbenchCommandConstants.EDIT_CONTENT_ASSIST);
+ if (stroke != null)
UIUtils.addBulbDecorator(textField, NLS.bind(
UIText.PushToGerritPage_ContentProposalHoverText,
stroke.format()));
- } catch (ParseException e1) {
- Activator.handleError(e1.getMessage(), e1, false);
- stroke = null;
- }
IContentProposalProvider cp = new IContentProposalProvider() {
public IContentProposal[] getProposals(String contents, int position) {

Back to the top