summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMike Kucera2013-04-02 12:19:44 (EDT)
committerChris Recoskie2013-04-02 12:31:38 (EDT)
commit33f8b2f85ace23c87dc83315a734093a78d38325 (patch)
tree5f57f159de4c00c4b550887389b90c42e615e516
parent38f5bc520a55974e4c0a9cf51bb8c8b72081c3de (diff)
downloadorg.eclipse.ptp-33f8b2f85ace23c87dc83315a734093a78d38325.zip
org.eclipse.ptp-33f8b2f85ace23c87dc83315a734093a78d38325.tar.gz
org.eclipse.ptp-33f8b2f85ace23c87dc83315a734093a78d38325.tar.bz2
Bug 404566 - Add tie-breaking to editorInfoProvider extension point.
-rw-r--r--rdt/org.eclipse.ptp.rdt.editor/src/org/eclipse/ptp/rdt/editor/info/IRemoteCEditorInfoProvider.java12
-rw-r--r--rdt/org.eclipse.ptp.rdt.editor/src/org/eclipse/ptp/rdt/editor/info/RemoteCInfoProviderUtilities.java25
-rw-r--r--rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/internal/rdt/ui/editor/RemoteCEditorInfoProvider.java14
3 files changed, 26 insertions, 25 deletions
diff --git a/rdt/org.eclipse.ptp.rdt.editor/src/org/eclipse/ptp/rdt/editor/info/IRemoteCEditorInfoProvider.java b/rdt/org.eclipse.ptp.rdt.editor/src/org/eclipse/ptp/rdt/editor/info/IRemoteCEditorInfoProvider.java
index e448f03..1e2e785 100644
--- a/rdt/org.eclipse.ptp.rdt.editor/src/org/eclipse/ptp/rdt/editor/info/IRemoteCEditorInfoProvider.java
+++ b/rdt/org.eclipse.ptp.rdt.editor/src/org/eclipse/ptp/rdt/editor/info/IRemoteCEditorInfoProvider.java
@@ -31,9 +31,6 @@ import org.eclipse.ui.texteditor.IDocumentProvider;
public interface IRemoteCEditorInfoProvider {
- public static int INPUT_UNKNOWN = 0;
- public static int HANDLES_INPUT = 1;
- public static int INPUT_AMBIGUOUS = 2;
/**
* Called when the editor is initialized to initialize any necessary values in the info provider
@@ -54,9 +51,12 @@ public interface IRemoteCEditorInfoProvider {
public void postDoSetInput(IEditorInput input) throws CoreException;
/**
- * Indicates whether or not the specified editor input is applicable to this info provider
- * @param input the editor input
- * @return one of INPUT_UNKNOWN, HANDLES_INPUT or INPUT_AMBIGUOUS
+ * Indicates whether or not the specified editor input is applicable to this info provider.
+ * Return an integer less than or equal to 0 to indicate that it does not handle the input.
+ * Return an integer between 1 and 100 inclusive to indicate that it does handle the input.
+ * The value will be used to break ties, a greater value wins. If there is still a tie
+ * then the winning provider is indeterminate. Values greater than 100 will be treated
+ * like 100.
*/
public int isApplicableEditorInput(IEditorInput input);
diff --git a/rdt/org.eclipse.ptp.rdt.editor/src/org/eclipse/ptp/rdt/editor/info/RemoteCInfoProviderUtilities.java b/rdt/org.eclipse.ptp.rdt.editor/src/org/eclipse/ptp/rdt/editor/info/RemoteCInfoProviderUtilities.java
index aa62be7..35ed1eb 100644
--- a/rdt/org.eclipse.ptp.rdt.editor/src/org/eclipse/ptp/rdt/editor/info/RemoteCInfoProviderUtilities.java
+++ b/rdt/org.eclipse.ptp.rdt.editor/src/org/eclipse/ptp/rdt/editor/info/RemoteCInfoProviderUtilities.java
@@ -52,23 +52,18 @@ public class RemoteCInfoProviderUtilities {
return editorProviders;
}
- public static IRemoteCEditorInfoProvider getApplicableEditorInfoProvider(List<IRemoteCEditorInfoProvider> infoProviders,
- IEditorInput input) {
- List<IRemoteCEditorInfoProvider> handled = new ArrayList<IRemoteCEditorInfoProvider>();
- List<IRemoteCEditorInfoProvider> ambiguous = new ArrayList<IRemoteCEditorInfoProvider>();
-
+ public static IRemoteCEditorInfoProvider getApplicableEditorInfoProvider(List<IRemoteCEditorInfoProvider> infoProviders, IEditorInput input) {
+ IRemoteCEditorInfoProvider winner = null;
+ int highestVal = 0;
for (IRemoteCEditorInfoProvider provider: infoProviders) {
- if (provider.isApplicableEditorInput(input)==IRemoteCEditorInfoProvider.HANDLES_INPUT)
- handled.add(provider);
- else if (provider.isApplicableEditorInput(input)==IRemoteCEditorInfoProvider.INPUT_AMBIGUOUS)
- ambiguous.add(provider);
- }
- if (handled.size()==1)
- return handled.get(0);
- else {
- //TODO: prompt the user for which context they would prefer for the editor
+ int applicable = Math.min(100, provider.isApplicableEditorInput(input));
+ if(applicable <= 0)
+ continue;
+ if(applicable > highestVal)
+ winner = provider;
}
- return null;
+
+ return winner;
}
}
diff --git a/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/internal/rdt/ui/editor/RemoteCEditorInfoProvider.java b/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/internal/rdt/ui/editor/RemoteCEditorInfoProvider.java
index c229121..c7fcf39 100644
--- a/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/internal/rdt/ui/editor/RemoteCEditorInfoProvider.java
+++ b/rdt/org.eclipse.ptp.rdt.ui/src/org/eclipse/ptp/internal/rdt/ui/editor/RemoteCEditorInfoProvider.java
@@ -78,6 +78,11 @@ public class RemoteCEditorInfoProvider implements IRemoteCEditorInfoProvider {
editor = remoteCEditor;
}
+
+ protected RemoteCEditor getEditor() {
+ return editor;
+ }
+
/* (non-Javadoc)
* @see org.eclipse.ptp.rdt.editor.info.IRemoteCEditorInfoProvider#preDoSetInput(org.eclipse.ui.IEditorInput)
*/
@@ -98,11 +103,11 @@ public class RemoteCEditorInfoProvider implements IRemoteCEditorInfoProvider {
public int isApplicableEditorInput(IEditorInput input) {
ICProject cproject = EditorUtility.getCProject(input);
if (cproject == null)
- return INPUT_UNKNOWN;
+ return 0;
IProject project = cproject.getProject();
if (RemoteNature.hasRemoteNature(project))
- return HANDLES_INPUT;
- return INPUT_UNKNOWN;
+ return 1;
+ return 0;
}
/* (non-Javadoc)
@@ -354,7 +359,7 @@ public class RemoteCEditorInfoProvider implements IRemoteCEditorInfoProvider {
* Returns true if the input element is a C element and it comes from a remote project. Also returns true if the
* editor is opened on an external translation unit that was navigated to from a remote resource.
*/
- private boolean isRemote() {
+ protected boolean isRemote() {
ICElement element = editor.getInputCElement();
if (element == null)
return false;
@@ -410,6 +415,7 @@ public class RemoteCEditorInfoProvider implements IRemoteCEditorInfoProvider {
actionBars.setGlobalActionHandler(CdtActionConstants.EXTRACT_LOCAL_VARIABLE, null);
actionBars.setGlobalActionHandler(CdtActionConstants.EXTRACT_METHOD, null);
actionBars.setGlobalActionHandler(CdtActionConstants.HIDE_METHOD, null);
+ actionBars.setGlobalActionHandler(CdtActionConstants.TOGGLE_FUNCTION, null);
actionBars.setGlobalActionHandler(CdtActionConstants.GETTERS_AND_SETTERS, null);
actionBars.setGlobalActionHandler(CdtActionConstants.IMPLEMENT_METHOD, null);