summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaroline Rieder2013-05-24 09:47:18 (EDT)
committer Anton Leherbauer2013-05-24 09:54:20 (EDT)
commitecb373f340957bc9c382bea6f1868af11d70a96b (patch)
tree514ff97c3c99f5ab10c4affd00abfd9fb60476ed
parent2a84dfb7e3420b2bd406ab4833276bf133022646 (diff)
downloadorg.eclipse.cdt-ecb373f340957bc9c382bea6f1868af11d70a96b.zip
org.eclipse.cdt-ecb373f340957bc9c382bea6f1868af11d70a96b.tar.gz
org.eclipse.cdt-ecb373f340957bc9c382bea6f1868af11d70a96b.tar.bz2
V.3 - Bug 405239 - Index actions are only available within context menurefs/changes/23/13123/3
The provided patch contributes the Index actions to the global Project menu using the command/handler extension points. Project related actions are enabled when: - When an ICProject, an ICContainer or an ITranslationUnit is selected in the Project Explorer and the Project Explorer has the focus - When a file of an ICProject is open in the Editor and the Editor has the focus File related action is enabled when: - When an ITranslationUnit is selected in the Project Explorer and the Project Explorer has the focus - When an ITranslationUnit is open in the Editor and the Editor has the focus Change-Id: I11f05e2b2f0c8f1652b0ee7e655aacacd03c7fde Signed-off-by: Caroline Rieder <caroline.rieder@windriver.com> Reviewed-on: https://git.eclipse.org/r/13123 Reviewed-by: Anton Leherbauer <anton.leherbauer@windriver.com> IP-Clean: Anton Leherbauer <anton.leherbauer@windriver.com> Tested-by: Anton Leherbauer <anton.leherbauer@windriver.com>
-rw-r--r--core/org.eclipse.cdt.ui/plugin.xml61
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/AbstractUpdateIndexAction.java105
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/AbstractUpdateIndexHandler.java47
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/CreateParserLogAction.java94
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/CreateParserLogHandler.java11
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/FreshenAllFilesHandler.java17
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/IndexActionsEnabledTester.java118
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/RebuildIndexAction.java102
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/RebuildIndexHandler.java17
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/UpdateIndexWithModifiedFilesHandler.java17
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/UpdateUnresolvedIncludesHandler.java19
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindUnresolvedIncludesHandler.java21
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindUnresolvedIncludesProjectAction.java88
13 files changed, 198 insertions, 519 deletions
diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml
index 3f93008..59e45e7 100644
--- a/core/org.eclipse.cdt.ui/plugin.xml
+++ b/core/org.eclipse.cdt.ui/plugin.xml
@@ -1407,16 +1407,19 @@
</visibility>
<action
class="org.eclipse.cdt.internal.ui.actions.UpdateUnresolvedIncludesAction"
+ definitionId="org.eclipse.cdt.ui.menu.updateUnresolvedIncludes"
id="org.eclipse.cdt.ui.updateUnresolvedIncludesAction"
label="%UpdateUnresolvedIncludes.name"
menubarPath="org.eclipse.cdt.ui.indexmenu/update"/>
<action
class="org.eclipse.cdt.internal.ui.actions.UpdateIndexWithModifiedFilesAction"
+ definitionId="org.eclipse.cdt.ui.menu.updateWithModifiedFiles"
id="org.eclipse.cdt.ui.syncIndexWithDiskAction"
label="%SyncIndex.name"
menubarPath="org.eclipse.cdt.ui.indexmenu/update"/>
<action
class="org.eclipse.cdt.internal.ui.actions.FreshenIndexAction"
+ definitionId="org.eclipse.cdt.ui.menu.freshenAllFiles"
id="org.eclipse.cdt.ui.updateIndexAction"
label="%FreshenIndex.name"
menubarPath="org.eclipse.cdt.ui.indexmenu/update"/>
@@ -1438,6 +1441,7 @@
</visibility>
<action
class="org.eclipse.cdt.internal.ui.actions.CreateParserLogAction"
+ definitionId="org.eclipse.cdt.ui.menu.createParserLog"
id="org.eclipse.cdt.ui.parserLogAction"
label="%CreateParserLog.name"
menubarPath="org.eclipse.cdt.ui.indexmenu/log"/>
@@ -1456,11 +1460,13 @@
objectClass="org.eclipse.cdt.core.model.ICProject">
<action
class="org.eclipse.cdt.internal.ui.actions.RebuildIndexAction"
+ definitionId="org.eclipse.cdt.ui.menu.rebuildIndex"
id="org.eclipse.cdt.ui.rebuildIndexAction"
label="%RebuildIndex.name"
menubarPath="org.eclipse.cdt.ui.indexmenu/rebuild"/>
<action
class="org.eclipse.cdt.internal.ui.search.actions.FindUnresolvedIncludesProjectAction"
+ definitionId="org.eclipse.cdt.ui.menu.findUnresolvedIncludes"
id="org.eclipse.cdt.ui.searchUnresolvedIncludes"
label="%SearchUnresolvedIncludes.name"
menubarPath="org.eclipse.cdt.ui.indexmenu/search"/>
@@ -1485,26 +1491,31 @@
</visibility>
<action
class="org.eclipse.cdt.internal.ui.actions.UpdateUnresolvedIncludesAction"
+ definitionId="org.eclipse.cdt.ui.menu.updateUnresolvedIncludes"
id="org.eclipse.cdt.ui.updateUnresolvedIncludesAction"
label="%UpdateUnresolvedIncludes.name"
menubarPath="org.eclipse.cdt.ui.indexmenu/update"/>
<action
class="org.eclipse.cdt.internal.ui.actions.UpdateIndexWithModifiedFilesAction"
+ definitionId="org.eclipse.cdt.ui.menu.updateWithModifiedFiles"
id="org.eclipse.cdt.ui.syncIndexWithDiskAction"
label="%SyncIndex.name"
menubarPath="org.eclipse.cdt.ui.indexmenu/update"/>
<action
class="org.eclipse.cdt.internal.ui.actions.FreshenIndexAction"
+ definitionId="org.eclipse.cdt.ui.menu.freshenAllFiles"
id="org.eclipse.cdt.ui.updateIndexAction"
label="%FreshenIndex.name"
menubarPath="org.eclipse.cdt.ui.indexmenu/update"/>
<action
class="org.eclipse.cdt.internal.ui.actions.RebuildIndexAction"
+ definitionId="org.eclipse.cdt.ui.menu.rebuildIndex"
id="org.eclipse.cdt.ui.rebuildIndexAction"
label="%RebuildIndex.name"
menubarPath="org.eclipse.cdt.ui.indexmenu/rebuild"/>
<action
class="org.eclipse.cdt.internal.ui.search.actions.FindUnresolvedIncludesProjectAction"
+ definitionId="org.eclipse.cdt.ui.menu.findUnresolvedIncludes"
id="org.eclipse.cdt.ui.searchUnresolvedIncludes"
label="%SearchUnresolvedIncludes.name"
menubarPath="org.eclipse.cdt.ui.indexmenu/search"/>
@@ -4491,44 +4502,26 @@
<handler
class="org.eclipse.cdt.internal.ui.actions.RebuildIndexHandler"
commandId="org.eclipse.cdt.ui.menu.rebuildIndex">
- <enabledWhen>
- <test property="org.eclipse.cdt.internal.ui.index.rebuild" value="enabled"/>
- </enabledWhen>
</handler>
<handler
class="org.eclipse.cdt.internal.ui.actions.FreshenAllFilesHandler"
commandId="org.eclipse.cdt.ui.menu.freshenAllFiles">
- <enabledWhen>
- <test property="org.eclipse.cdt.internal.ui.index.freshen" value="enabled"/>
- </enabledWhen>
</handler>
<handler
class="org.eclipse.cdt.internal.ui.actions.UpdateIndexWithModifiedFilesHandler"
commandId="org.eclipse.cdt.ui.menu.updateWithModifiedFiles">
- <enabledWhen>
- <test property="org.eclipse.cdt.internal.ui.index.udpateWithModifiedFiles" value="enabled"/>
- </enabledWhen>
</handler>
<handler
class="org.eclipse.cdt.internal.ui.actions.UpdateUnresolvedIncludesHandler"
commandId="org.eclipse.cdt.ui.menu.updateUnresolvedIncludes">
- <enabledWhen>
- <test property="org.eclipse.cdt.internal.ui.index.updateUnresolvedIncludes" value="enabled"/>
- </enabledWhen>
</handler>
<handler
class="org.eclipse.cdt.internal.ui.search.actions.FindUnresolvedIncludesHandler"
commandId="org.eclipse.cdt.ui.menu.findUnresolvedIncludes">
- <enabledWhen>
- <test property="org.eclipse.cdt.internal.ui.index.findUnresolvedIncludes" value="enabled"/>
- </enabledWhen>
</handler>
<handler
class="org.eclipse.cdt.internal.ui.actions.CreateParserLogHandler"
commandId="org.eclipse.cdt.ui.menu.createParserLog">
- <enabledWhen>
- <test property="org.eclipse.cdt.internal.ui.index.log" value="enabled"/>
- </enabledWhen>
</handler>
</extension>
<extension
@@ -4538,7 +4531,27 @@
<menu
label="%C.Cpp.Index.menu">
<visibleWhen>
- <test property="org.eclipse.cdt.internal.ui.index.enabled" value="enabled"/>
+ <or>
+ <with variable="selection">
+ <iterate operator="and" ifEmpty="false">
+ <adapt type="org.eclipse.core.resources.IResource">
+ <test
+ property="org.eclipse.core.resources.projectNature"
+ value="org.eclipse.cdt.core.cnature"/>
+ </adapt>
+ </iterate>
+ </with>
+ <with variable="activeEditorInput">
+ <or>
+ <adapt type="org.eclipse.core.resources.IFile">
+ <test
+ property="org.eclipse.core.resources.projectNature"
+ value="org.eclipse.cdt.core.cnature"/>
+ </adapt>
+ <instanceof value="org.eclipse.cdt.internal.ui.util.ExternalEditorInput"/>
+ </or>
+ </with>
+ </or>
</visibleWhen>
<separator
name="rebuild"
@@ -4584,16 +4597,6 @@
</menuContribution>
</extension>
<extension
- point="org.eclipse.core.expressions.propertyTesters">
- <propertyTester
- class="org.eclipse.cdt.internal.ui.actions.IndexActionsEnabledTester"
- id="org.eclipse.cdt.internal.ui.actions.IndexActionsEnabledTester"
- namespace="org.eclipse.cdt.internal.ui.index"
- properties="enabled,rebuild,freshen,udpateWithModifiedFiles,updateUnresolvedIncludes,findUnresolvedIncludes,log"
- type="java.lang.Object">
- </propertyTester>
- </extension>
- <extension
point="org.eclipse.ui.commands">
<command
id="org.eclipse.cdt.ui.deleteConfigsCommand"
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/AbstractUpdateIndexAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/AbstractUpdateIndexAction.java
index 67ed241..763ffb3 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/AbstractUpdateIndexAction.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/AbstractUpdateIndexAction.java
@@ -15,32 +15,25 @@ import java.util.ArrayList;
import java.util.Iterator;
import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.index.IIndexManager;
-import org.eclipse.cdt.core.model.CoreModel;
-import org.eclipse.cdt.core.model.ICContainer;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
-import org.eclipse.cdt.core.model.ITranslationUnit;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.cdt.internal.ui.util.EditorUtility;
-import org.eclipse.cdt.internal.ui.util.SelectionUtil;
-public abstract class AbstractUpdateIndexAction implements IObjectActionDelegate, IWorkbenchWindowActionDelegate {
+public abstract class AbstractUpdateIndexAction implements IObjectActionDelegate {
private ISelection fSelection;
- private boolean isEnabled;
@Override
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
@@ -51,28 +44,13 @@ public abstract class AbstractUpdateIndexAction implements IObjectActionDelegate
if(!(fSelection instanceof IStructuredSelection) && !(fSelection instanceof ITextSelection)) {
return;
}
-
- ArrayList<ICElement> tuSelection= new ArrayList<ICElement>();
- if(fSelection instanceof IStructuredSelection) {
- IStructuredSelection cElements= SelectionConverter.convertSelectionToCElements(fSelection);
- for (Iterator<?> i= cElements.iterator(); i.hasNext();) {
- Object o= i.next();
- if (o instanceof ICProject || o instanceof ICContainer || o instanceof ITranslationUnit) {
- tuSelection.add((ICElement) o);
- }
- }
- } else if(fSelection instanceof ITextSelection) {
- IProject project = EditorUtility.getProjectForActiveEditor();
- if(project != null) {
- ICProject cproject = CCorePlugin.getDefault().getCoreModel().create(project);
- if(cproject != null) {
- tuSelection.add(cproject);
- }
- }
- }
- ICElement[] tuArray= tuSelection.toArray(new ICElement[tuSelection.size()]);
+ ICProject[] projects = getSelectedCProjects();
+ doRun(projects);
+ }
+
+ protected void doRun(ICProject[] projects) {
try {
- CCorePlugin.getIndexManager().update(tuArray, getUpdateOptions());
+ CCorePlugin.getIndexManager().update(projects, getUpdateOptions());
} catch (CoreException e) {
CUIPlugin.log(e);
}
@@ -84,47 +62,40 @@ public abstract class AbstractUpdateIndexAction implements IObjectActionDelegate
* @since 4.0
*/
abstract protected int getUpdateOptions();
-
- /**
- * @see IActionDelegate#selectionChanged(IAction, ISelection)
- */
- public void selectionChanged(ISelection selection) {
- fSelection= selection;
- isEnabled = false;
-
- if(selection == null || selection instanceof ITextSelection) {
- IProject project = EditorUtility.getProjectForActiveEditor();
- if(project != null) {
- isEnabled = CoreModel.hasCNature(project);
- }
- } else if(selection instanceof IStructuredSelection) {
- Object selectedElement = ((IStructuredSelection)selection).getFirstElement();
- if(selectedElement instanceof IProject) {
- isEnabled = CoreModel.hasCNature((IProject)selectedElement) && ((IProject)selectedElement).isOpen();
- } else if(selectedElement instanceof ITranslationUnit) {
- isEnabled = true;
- }
- }
- }
@Override
- public void init(IWorkbenchWindow window) {
+ public void selectionChanged(IAction action, ISelection selection) {
+ fSelection = selection;
}
- @Override
- public void dispose() {
- }
-
- /**
- * @return {@code true} if the action is enabled or {@code false} otherwise.
- */
- public boolean isEnabled() {
- selectionChanged(SelectionUtil.getActiveSelection());
- return isEnabled;
+ public boolean isEnabledFor(ISelection selection) {
+ selectionChanged(null, selection);
+ ICProject[] project = getSelectedCProjects();
+ return project.length > 0;
}
-
- @Override
- public void selectionChanged(IAction action, ISelection selection) {
- selectionChanged(selection);
+
+ protected ICProject[] getSelectedCProjects() {
+ ArrayList<ICProject> tuSelection= new ArrayList<ICProject>();
+ if(fSelection instanceof IStructuredSelection) {
+ IStructuredSelection resources = SelectionConverter.convertSelectionToResources(fSelection);
+ for (Iterator<?> i= resources.iterator(); i.hasNext();) {
+ Object o= i.next();
+ if(o instanceof IResource) {
+ ICProject cproject= CCorePlugin.getDefault().getCoreModel().create(((IResource)o).getProject());
+ if(cproject != null) {
+ tuSelection.add(cproject);
+ }
+ }
+ }
+ } else if(fSelection == null || fSelection instanceof ITextSelection) {
+ IProject project = EditorUtility.getProjectForActiveEditor();
+ if(project != null) {
+ ICProject cproject= CCorePlugin.getDefault().getCoreModel().create(project);
+ if(cproject != null) {
+ tuSelection.add(cproject);
+ }
+ }
+ }
+ return tuSelection.toArray(new ICProject[tuSelection.size()]);
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/AbstractUpdateIndexHandler.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/AbstractUpdateIndexHandler.java
new file mode 100644
index 0000000..c0e16c9
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/AbstractUpdateIndexHandler.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Wind River Systems, Inc. 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:
+ * Wind River Systems - Initial API and implementation
+ *******************************************************************************/
+package org.eclipse.cdt.internal.ui.actions;
+
+import org.eclipse.core.commands.AbstractHandler;
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+import org.eclipse.cdt.internal.ui.util.SelectionUtil;
+
+/**
+ * Abstract handler for {@link org.eclipse.cdt.internal.ui.actions.AbstractUpdateIndexAction}
+ */
+public abstract class AbstractUpdateIndexHandler extends AbstractHandler {
+
+ abstract protected AbstractUpdateIndexAction getAction();
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ IWorkbenchPart part = HandlerUtil.getActivePart(event);
+ getAction().setActivePart(null, part);
+ getAction().selectionChanged(null, selection);
+ getAction().run(null);
+ return null;
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.commands.AbstractHandler#setEnabled(java.lang.Object)
+ */
+ @Override
+ public void setEnabled(Object evaluationContext) {
+ ISelection selection = SelectionUtil.getActiveSelection();
+ setBaseEnabled(getAction().isEnabledFor(selection));
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/CreateParserLogAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/CreateParserLogAction.java
index 43ca7b8..aaba569 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/CreateParserLogAction.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/CreateParserLogAction.java
@@ -42,7 +42,6 @@ import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.osgi.util.NLS;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.FileDialog;
-import org.eclipse.ui.IActionDelegate;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorReference;
@@ -51,7 +50,6 @@ import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchPartSite;
import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.IWorkbenchWindowActionDelegate;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.ide.IDE;
@@ -95,12 +93,10 @@ import org.eclipse.cdt.internal.core.pdom.indexer.ProjectIndexerInputAdapter;
import org.eclipse.cdt.internal.ui.editor.ASTProvider;
import org.eclipse.cdt.internal.ui.editor.CEditor;
-import org.eclipse.cdt.internal.ui.util.SelectionUtil;
@SuppressWarnings("nls")
-public class CreateParserLogAction implements IObjectActionDelegate, IWorkbenchWindowActionDelegate {
+public class CreateParserLogAction implements IObjectActionDelegate {
private static final String INDENT = " ";
- private boolean isEnabled;
private static final class MyVisitor extends ASTVisitor {
List<IASTProblem> fProblems= new ArrayList<IASTProblem>();
@@ -168,29 +164,20 @@ public class CreateParserLogAction implements IObjectActionDelegate, IWorkbenchW
workingCopies.add((IWorkingCopy) inputElement);
}
}
- ArrayList<ITranslationUnit> tuSelection= new ArrayList<ITranslationUnit>();
- String title = ActionMessages.CreateParserLogAction_title;
- if(fSelection instanceof IStructuredSelection) {
- IStructuredSelection cElements= SelectionConverter.convertSelectionToCElements(fSelection);
- Iterator<?> i= cElements.iterator();
- while (i.hasNext()) {
- Object o= i.next();
- if (o instanceof ITranslationUnit) {
- tuSelection.add(convertToWorkingCopy((ITranslationUnit) o, workingCopies));
- }
- }
- } else if(fSelection instanceof ITextSelection) {
- IWorkingCopy tu = getTranslationUnitForSelectedEditorInput();
- if(tu != null) {
- tuSelection.add(tu);
+
+ ArrayList<ITranslationUnit> tuSelection = getSelectedTranslationUnits();
+ for(int i = 0; i < tuSelection.size(); i++) {
+ if(!(tuSelection.get(i) instanceof IWorkingCopy)) {
+ tuSelection.set(i, convertToWorkingCopy(tuSelection.get(i), workingCopies));
}
}
-
+
ITranslationUnit[] tuArray= tuSelection.toArray(new ITranslationUnit[tuSelection.size()]);
if (tuArray.length == 0) {
return;
}
FileDialog dlg= new FileDialog(fSite.getShell(), SWT.SAVE);
+ String title = ActionMessages.CreateParserLogAction_title;
dlg.setText(title);
dlg.setFilterExtensions(new String[]{"*.log"});
String path= null;
@@ -496,27 +483,13 @@ public class CreateParserLogAction implements IObjectActionDelegate, IWorkbenchW
out.println();
}
}
-
- /**
- * @see IActionDelegate#selectionChanged(IAction, ISelection)
- */
- public void selectionChanged(ISelection selection) {
- fSelection= selection;
- isEnabled = false;
-
- if(selection == null || selection instanceof ITextSelection) {
- IWorkingCopy tu = getTranslationUnitForSelectedEditorInput();
- if(tu != null) {
- isEnabled = true;
- }
- } else if(selection instanceof IStructuredSelection) {
- if(((IStructuredSelection)selection).getFirstElement() instanceof ITranslationUnit) {
- isEnabled = true;
- }
- }
- }
- private IWorkingCopy getTranslationUnitForSelectedEditorInput() {
+ @Override
+ public void selectionChanged(IAction action, ISelection selection) {
+ fSelection = selection;
+ }
+
+ public IWorkingCopy getTranslationUnitForSelectedEditorInput() {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if(window != null) {
IWorkbenchPart workbenchPart = window.getPartService().getActivePart();
@@ -531,24 +504,29 @@ public class CreateParserLogAction implements IObjectActionDelegate, IWorkbenchW
return null;
}
- @Override
- public void init(IWorkbenchWindow window) {
- }
-
- @Override
- public void dispose() {
+ public boolean isEnabledFor(ISelection selection) {
+ selectionChanged(null, selection);
+ ArrayList<ITranslationUnit> tus = getSelectedTranslationUnits();
+ return tus.size() > 0;
}
- /**
- * @return {@code true} if the action is enabled or {@code false} otherwise.
- */
- public boolean isEnabled() {
- selectionChanged(SelectionUtil.getActiveSelection());
- return isEnabled;
- }
-
- @Override
- public void selectionChanged(IAction action, ISelection selection) {
- selectionChanged(selection);
+ private ArrayList<ITranslationUnit> getSelectedTranslationUnits() {
+ ArrayList<ITranslationUnit> tuSelection= new ArrayList<ITranslationUnit>();
+ if(fSelection instanceof IStructuredSelection) {
+ IStructuredSelection cElements= SelectionConverter.convertSelectionToCElements(fSelection);
+ Iterator<?> i= cElements.iterator();
+ while (i.hasNext()) {
+ Object o= i.next();
+ if (o instanceof ITranslationUnit) {
+ tuSelection.add((ITranslationUnit)o);
+ }
+ }
+ } else if(fSelection == null || fSelection instanceof ITextSelection) {
+ IWorkingCopy tu = getTranslationUnitForSelectedEditorInput();
+ if(tu != null) {
+ tuSelection.add(tu);
+ }
+ }
+ return tuSelection;
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/CreateParserLogHandler.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/CreateParserLogHandler.java
index ebe9057..e718bf8 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/CreateParserLogHandler.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/CreateParserLogHandler.java
@@ -17,6 +17,8 @@ import org.eclipse.jface.viewers.ISelection;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.cdt.internal.ui.util.SelectionUtil;
+
/**
* Handler for {@link org.eclipse.cdt.internal.ui.actions.CreateParserLogAction}
*
@@ -36,4 +38,13 @@ public class CreateParserLogHandler extends AbstractHandler {
createParserLogAction.run(null);
return null;
}
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.commands.AbstractHandler#setEnabled(java.lang.Object)
+ */
+ @Override
+ public void setEnabled(Object evaluationContext) {
+ ISelection selection = SelectionUtil.getActiveSelection();
+ setBaseEnabled(createParserLogAction.isEnabledFor(selection));
+ }
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/FreshenAllFilesHandler.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/FreshenAllFilesHandler.java
index 568275f..45de61d 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/FreshenAllFilesHandler.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/FreshenAllFilesHandler.java
@@ -10,12 +10,6 @@
*******************************************************************************/
package org.eclipse.cdt.internal.ui.actions;
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.handlers.HandlerUtil;
/**
* Handler for {@link org.eclipse.cdt.internal.ui.actions.FreshenIndexAction}
@@ -23,17 +17,12 @@ import org.eclipse.ui.handlers.HandlerUtil;
* @noextend This class is not intended to be subclassed by clients.
* @noinstantiate This class is not intended to be instantiated by clients.
*/
-public class FreshenAllFilesHandler extends AbstractHandler {
+public class FreshenAllFilesHandler extends AbstractUpdateIndexHandler {
private final FreshenIndexAction freshenIndexAction = new FreshenIndexAction();
@Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
- ISelection selection = HandlerUtil.getCurrentSelection(event);
- IWorkbenchPart part = HandlerUtil.getActivePart(event);
- freshenIndexAction.setActivePart(null, part);
- freshenIndexAction.selectionChanged(null, selection);
- freshenIndexAction.run(null);
- return null;
+ public AbstractUpdateIndexAction getAction() {
+ return freshenIndexAction;
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/IndexActionsEnabledTester.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/IndexActionsEnabledTester.java
deleted file mode 100644
index e6cb1d2..0000000
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/IndexActionsEnabledTester.java
+++ /dev/null
@@ -1,118 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2013 Wind River Systems, Inc. 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:
- * Wind River Systems - Initial API and implementation
- *******************************************************************************/
-package org.eclipse.cdt.internal.ui.actions;
-
-import org.eclipse.core.expressions.PropertyTester;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.jface.viewers.StructuredSelection;
-import org.eclipse.ui.IEditorPart;
-import org.eclipse.ui.ISelectionListener;
-import org.eclipse.ui.ISelectionService;
-import org.eclipse.ui.IWindowListener;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.ide.ResourceUtil;
-
-import org.eclipse.cdt.internal.ui.search.actions.FindUnresolvedIncludesProjectAction;
-
-public class IndexActionsEnabledTester extends PropertyTester implements ISelectionListener, IWindowListener {
-
- private static RebuildIndexAction fRebuildIndexAction = new RebuildIndexAction();
- private static CreateParserLogAction fCreateParserLogAction = new CreateParserLogAction();
- private static FreshenIndexAction fFreshenAllFiles = new FreshenIndexAction();
- private static UpdateUnresolvedIncludesAction fUpdateUnresolvedIncludes = new UpdateUnresolvedIncludesAction();
- private static UpdateIndexWithModifiedFilesAction fUpdateWithModifiedFiles = new UpdateIndexWithModifiedFilesAction();
- private static FindUnresolvedIncludesProjectAction fFindUnresolvedIncludes = new FindUnresolvedIncludesProjectAction();
-
- /* (non-Javadoc)
- * @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
- */
- @Override
- public boolean test(Object receiver, String property, Object[] args, Object expectedValue)
- {
- if(property.equals("enabled")) { //$NON-NLS-1$
- return fRebuildIndexAction.isEnabled()
- || fCreateParserLogAction.isEnabled()
- || fFreshenAllFiles.isEnabled()
- || fUpdateUnresolvedIncludes.isEnabled()
- || fUpdateWithModifiedFiles.isEnabled()
- || fFindUnresolvedIncludes.isEnabled();
- } else if(property.equals("rebuild")) { //$NON-NLS-1$
- return fRebuildIndexAction.isEnabled();
- } else if(property.equals("log")) { //$NON-NLS-1$
- return fCreateParserLogAction.isEnabled();
- } else if(property.equals("freshen")) { //$NON-NLS-1$
- return fFreshenAllFiles.isEnabled();
- } else if(property.equals("updateUnresolvedIncludes")) { //$NON-NLS-1$
- return fUpdateUnresolvedIncludes.isEnabled();
- } else if(property.equals("udpateWithModifiedFiles")) { //$NON-NLS-1$
- return fUpdateWithModifiedFiles.isEnabled();
- } else if(property.equals("findUnresolvedIncludes")) { //$NON-NLS-1$
- return fFindUnresolvedIncludes.isEnabled();
- }
- return false;
- }
-
- private IStructuredSelection getSelectedItem(Object part, Object selection) {
- if((selection != null) && (selection instanceof IStructuredSelection)) {
- return (IStructuredSelection)selection;
- }
- if((part != null) && (part instanceof IEditorPart)) {
- Object selItem = null;
- selItem = ResourceUtil.getResource(((IEditorPart)part).getEditorInput());
- if(selItem != null) {
- return new StructuredSelection(selItem);
- }
- }
- return StructuredSelection.EMPTY;
- }
-
- @Override
- public void selectionChanged(IWorkbenchPart part, ISelection selection) {
- IStructuredSelection sel = getSelectedItem(part, selection);
- fRebuildIndexAction.selectionChanged(sel);
- fCreateParserLogAction.selectionChanged(sel);
- fFreshenAllFiles.selectionChanged(sel);
- fUpdateUnresolvedIncludes.selectionChanged(sel);
- fUpdateWithModifiedFiles.selectionChanged(sel);
- fFindUnresolvedIncludes.selectionChanged(sel);
- }
-
- @Override
- public void windowActivated(IWorkbenchWindow window) {
- ISelectionService selectionService = window.getSelectionService();
- if (selectionService != null) {
- ISelection sel = selectionService.getSelection();
- selectionChanged(null, sel);
- }
- }
-
- @Override
- public void windowDeactivated(IWorkbenchWindow window) {
- }
-
- @Override
- public void windowClosed(IWorkbenchWindow window) {
- ISelectionService selectionService = window.getSelectionService();
- if (selectionService != null) {
- selectionService.removeSelectionListener(this);
- }
- }
-
- @Override
- public void windowOpened(IWorkbenchWindow window) {
- ISelectionService selectionService = window.getSelectionService();
- if (selectionService != null) {
- selectionService.addSelectionListener(this);
- }
- }
-}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/RebuildIndexAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/RebuildIndexAction.java
index 502e470..a21c823 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/RebuildIndexAction.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/RebuildIndexAction.java
@@ -10,108 +10,22 @@
*******************************************************************************/
package org.eclipse.cdt.internal.ui.actions;
-import java.util.ArrayList;
-import java.util.Iterator;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.text.ITextSelection;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
-import org.eclipse.ui.IActionDelegate;
-import org.eclipse.ui.IObjectActionDelegate;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.IWorkbenchWindowActionDelegate;
-
import org.eclipse.cdt.core.CCorePlugin;
-import org.eclipse.cdt.core.model.CoreModel;
-import org.eclipse.cdt.core.model.ICContainer;
-import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject;
-import org.eclipse.cdt.core.model.ITranslationUnit;
-
-import org.eclipse.cdt.internal.ui.util.EditorUtility;
-import org.eclipse.cdt.internal.ui.util.SelectionUtil;
-
-public class RebuildIndexAction implements IObjectActionDelegate, IWorkbenchWindowActionDelegate {
- private ISelection fSelection;
- private boolean isEnabled;
-
- @Override
- public void setActivePart(IAction action, IWorkbenchPart targetPart) {
- }
+public class RebuildIndexAction extends AbstractUpdateIndexAction {
+
@Override
- public void run(IAction action) {
- if(!(fSelection instanceof IStructuredSelection) && !(fSelection instanceof ITextSelection)) {
- return;
- }
- ArrayList<ICElement> tuSelection= new ArrayList<ICElement>();
- if(fSelection instanceof IStructuredSelection) {
- IStructuredSelection cElements= SelectionConverter.convertSelectionToCElements(fSelection);
- for (Iterator<?> i= cElements.iterator(); i.hasNext();) {
- Object o= i.next();
- if (o instanceof ICProject || o instanceof ICContainer || o instanceof ITranslationUnit) {
- tuSelection.add((ICElement) o);
- }
- }
- } else if(fSelection instanceof ITextSelection) {
- IProject project = EditorUtility.getProjectForActiveEditor();
- if(project != null) {
- ICProject cproject= CCorePlugin.getDefault().getCoreModel().create(project);
- if(cproject != null) {
- tuSelection.add(cproject);
- }
+ protected void doRun(ICProject[] projects) {
+ for (ICProject proj : projects) {
+ if(proj != null) {
+ CCorePlugin.getIndexManager().reindex(proj);
}
}
- ICElement[] tuArray= tuSelection.toArray(new ICElement[tuSelection.size()]);
- for (ICElement elem : tuArray) {
- if(elem instanceof ICProject) {
- CCorePlugin.getIndexManager().reindex((ICProject) elem);
- }
- }
- }
-
- /**
- * @see IActionDelegate#selectionChanged(IAction, ISelection)
- */
- public void selectionChanged(ISelection selection) {
- fSelection= selection;
- isEnabled = false;
- if(selection == null || selection instanceof ITextSelection) {
- IProject project = EditorUtility.getProjectForActiveEditor();
- if(project != null) {
- isEnabled = CoreModel.hasCNature(project);
- }
- } else if(selection instanceof IStructuredSelection) {
- Object selectedElement = ((IStructuredSelection)selection).getFirstElement();
- if(selectedElement instanceof IProject) {
- isEnabled = CoreModel.hasCNature((IProject)selectedElement) && ((IProject)selectedElement).isOpen();
- } else if(selectedElement instanceof ITranslationUnit) {
- isEnabled = true;
- }
- }
- }
-
- @Override
- public void init(IWorkbenchWindow window) {
- }
-
- @Override
- public void dispose() {
- }
-
- /**
- * @return {@code true} if the action is enabled or {@code false} otherwise.
- */
- public boolean isEnabled() {
- selectionChanged(SelectionUtil.getActiveSelection());
- return isEnabled;
}
@Override
- public void selectionChanged(IAction action, ISelection selection) {
- selectionChanged(selection);
+ protected int getUpdateOptions() {
+ return 0;
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/RebuildIndexHandler.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/RebuildIndexHandler.java
index 88e6e98..f0ec4f0 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/RebuildIndexHandler.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/RebuildIndexHandler.java
@@ -10,12 +10,6 @@
*******************************************************************************/
package org.eclipse.cdt.internal.ui.actions;
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.handlers.HandlerUtil;
/**
* Handler for {@link org.eclipse.cdt.internal.ui.actions.RebuildIndexAction}
@@ -23,17 +17,12 @@ import org.eclipse.ui.handlers.HandlerUtil;
* @noextend This class is not intended to be subclassed by clients.
* @noinstantiate This class is not intended to be instantiated by clients.
*/
-public class RebuildIndexHandler extends AbstractHandler {
+public class RebuildIndexHandler extends AbstractUpdateIndexHandler {
private final RebuildIndexAction rebuildIndexAction = new RebuildIndexAction();
@Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
- ISelection selection = HandlerUtil.getCurrentSelection(event);
- IWorkbenchPart part = HandlerUtil.getActivePart(event);
- rebuildIndexAction.setActivePart(null, part);
- rebuildIndexAction.selectionChanged(null, selection);
- rebuildIndexAction.run(null);
- return null;
+ public AbstractUpdateIndexAction getAction() {
+ return rebuildIndexAction;
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/UpdateIndexWithModifiedFilesHandler.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/UpdateIndexWithModifiedFilesHandler.java
index 8b3f5a4..76cc151 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/UpdateIndexWithModifiedFilesHandler.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/UpdateIndexWithModifiedFilesHandler.java
@@ -10,12 +10,6 @@
*******************************************************************************/
package org.eclipse.cdt.internal.ui.actions;
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.handlers.HandlerUtil;
/**
* Handler for {@link org.eclipse.cdt.internal.ui.actions.UpdateIndexWithModifiedFilesAction}
@@ -23,17 +17,12 @@ import org.eclipse.ui.handlers.HandlerUtil;
* @noextend This class is not intended to be subclassed by clients.
* @noinstantiate This class is not intended to be instantiated by clients.
*/
-public class UpdateIndexWithModifiedFilesHandler extends AbstractHandler {
+public class UpdateIndexWithModifiedFilesHandler extends AbstractUpdateIndexHandler {
private final UpdateIndexWithModifiedFilesAction updateAction = new UpdateIndexWithModifiedFilesAction();
@Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
- ISelection selection = HandlerUtil.getCurrentSelection(event);
- IWorkbenchPart part = HandlerUtil.getActivePart(event);
- updateAction.setActivePart(null, part);
- updateAction.selectionChanged(null, selection);
- updateAction.run(null);
- return null;
+ public AbstractUpdateIndexAction getAction() {
+ return updateAction;
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/UpdateUnresolvedIncludesHandler.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/UpdateUnresolvedIncludesHandler.java
index 96995e9d..fcbad2e 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/UpdateUnresolvedIncludesHandler.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/UpdateUnresolvedIncludesHandler.java
@@ -10,12 +10,6 @@
*******************************************************************************/
package org.eclipse.cdt.internal.ui.actions;
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.handlers.HandlerUtil;
/**
* Handler for {@link org.eclipse.cdt.internal.ui.actions.UpdateIndexWithModifiedFilesAction}
@@ -23,17 +17,12 @@ import org.eclipse.ui.handlers.HandlerUtil;
* @noextend This class is not intended to be subclassed by clients.
* @noinstantiate This class is not intended to be instantiated by clients.
*/
-public class UpdateUnresolvedIncludesHandler extends AbstractHandler {
+public class UpdateUnresolvedIncludesHandler extends AbstractUpdateIndexHandler {
- private final UpdateUnresolvedIncludesAction udpateAction = new UpdateUnresolvedIncludesAction();
+ private final UpdateUnresolvedIncludesAction updateAction = new UpdateUnresolvedIncludesAction();
@Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
- ISelection selection = HandlerUtil.getCurrentSelection(event);
- IWorkbenchPart part = HandlerUtil.getActivePart(event);
- udpateAction.setActivePart(null, part);
- udpateAction.selectionChanged(null, selection);
- udpateAction.run(null);
- return null;
+ public AbstractUpdateIndexAction getAction() {
+ return updateAction;
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindUnresolvedIncludesHandler.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindUnresolvedIncludesHandler.java
index 6d9115a..b8b47ac 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindUnresolvedIncludesHandler.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindUnresolvedIncludesHandler.java
@@ -10,12 +10,8 @@
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search.actions;
-import org.eclipse.core.commands.AbstractHandler;
-import org.eclipse.core.commands.ExecutionEvent;
-import org.eclipse.core.commands.ExecutionException;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.ui.IWorkbenchPart;
-import org.eclipse.ui.handlers.HandlerUtil;
+import org.eclipse.cdt.internal.ui.actions.AbstractUpdateIndexAction;
+import org.eclipse.cdt.internal.ui.actions.AbstractUpdateIndexHandler;
/**
* Handler for {@link org.eclipse.cdt.internal.ui.search.actions.FindUnresolvedIncludesProjectAction}
@@ -23,17 +19,12 @@ import org.eclipse.ui.handlers.HandlerUtil;
* @noextend This class is not intended to be subclassed by clients.
* @noinstantiate This class is not intended to be instantiated by clients.
*/
-public class FindUnresolvedIncludesHandler extends AbstractHandler {
+public class FindUnresolvedIncludesHandler extends AbstractUpdateIndexHandler {
- private final FindUnresolvedIncludesProjectAction rebuildIndexAction= new FindUnresolvedIncludesProjectAction();
+ private final FindUnresolvedIncludesProjectAction findUnresolvedIncludesAction = new FindUnresolvedIncludesProjectAction();
@Override
- public Object execute(ExecutionEvent event) throws ExecutionException {
- ISelection selection = HandlerUtil.getCurrentSelection(event);
- IWorkbenchPart part = HandlerUtil.getActivePart(event);
- rebuildIndexAction.setActivePart(null, part);
- rebuildIndexAction.selectionChanged(null, selection);
- rebuildIndexAction.run(null);
- return null;
+ public AbstractUpdateIndexAction getAction() {
+ return findUnresolvedIncludesAction;
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindUnresolvedIncludesProjectAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindUnresolvedIncludesProjectAction.java
index 929c5b2..45fd549 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindUnresolvedIncludesProjectAction.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindUnresolvedIncludesProjectAction.java
@@ -10,74 +10,37 @@
*******************************************************************************/
package org.eclipse.cdt.internal.ui.search.actions;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.eclipse.core.resources.IProject;
import org.eclipse.jface.action.IAction;
-import org.eclipse.jface.text.ITextSelection;
-import org.eclipse.jface.viewers.ISelection;
-import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.search.ui.ISearchQuery;
import org.eclipse.search.ui.NewSearchUI;
-import org.eclipse.ui.IActionDelegate;
-import org.eclipse.ui.IObjectActionDelegate;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchSite;
-import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.IWorkbenchWindowActionDelegate;
-import org.eclipse.cdt.core.CCorePlugin;
-import org.eclipse.cdt.core.model.CoreModel;
import org.eclipse.cdt.core.model.ICProject;
-import org.eclipse.cdt.core.model.ITranslationUnit;
-import org.eclipse.cdt.internal.ui.actions.SelectionConverter;
+import org.eclipse.cdt.internal.ui.actions.AbstractUpdateIndexAction;
import org.eclipse.cdt.internal.ui.search.CSearchMessages;
import org.eclipse.cdt.internal.ui.search.CSearchUnresolvedIncludesQuery;
-import org.eclipse.cdt.internal.ui.util.EditorUtility;
-import org.eclipse.cdt.internal.ui.util.SelectionUtil;
import org.eclipse.cdt.internal.ui.util.StatusLineHandler;
/**
* Searches projects for unresolved includes.
* Could be extended to work on resource selections.
*/
-public class FindUnresolvedIncludesProjectAction implements IObjectActionDelegate, IWorkbenchWindowActionDelegate {
- private ISelection fSelection;
+public class FindUnresolvedIncludesProjectAction extends AbstractUpdateIndexAction {
private IWorkbenchSite fSite;
- private boolean isEnabled;
public FindUnresolvedIncludesProjectAction() {
}
@Override
- public void run(IAction action) {
- List<ICProject> projects = new ArrayList<ICProject>();
- if(fSelection instanceof IStructuredSelection) {
- IStructuredSelection cElements = SelectionConverter.convertSelectionToCElements(fSelection);
- for (Iterator<?> i = cElements.iterator(); i.hasNext();) {
- Object o= i.next();
- if (o instanceof ICProject) {
- projects.add((ICProject) o);
- }
- }
- } else if(fSelection instanceof ITextSelection) {
- IProject project = EditorUtility.getProjectForActiveEditor();
- if(project != null) {
- ICProject cproject = CCorePlugin.getDefault().getCoreModel().create(project);
- if(cproject != null) {
- projects.add(cproject);
- }
- }
- }
- if (projects.isEmpty()) {
+ protected void doRun(ICProject[] projects) {
+ if (projects.length == 0) {
StatusLineHandler.showStatusLineMessage(fSite, CSearchMessages.CSearchOperation_operationUnavailable_message);
return;
}
- ISearchQuery searchJob= new CSearchUnresolvedIncludesQuery(projects.toArray(new ICProject[projects.size()]));
+ ISearchQuery searchJob= new CSearchUnresolvedIncludesQuery(projects);
StatusLineHandler.clearStatusLine(fSite);
NewSearchUI.activateSearchResultView();
@@ -89,45 +52,8 @@ public class FindUnresolvedIncludesProjectAction implements IObjectActionDelegat
fSite= targetPart.getSite();
}
- /**
- * @see IActionDelegate#selectionChanged(IAction, ISelection)
- */
- public void selectionChanged(ISelection selection) {
- fSelection= selection;
- isEnabled = false;
- if(selection == null || selection instanceof ITextSelection) {
- IProject project = EditorUtility.getProjectForActiveEditor();
- if(project != null) {
- isEnabled = CoreModel.hasCNature(project);
- }
- } else if(selection instanceof IStructuredSelection) {
- Object selectedElement = ((IStructuredSelection)selection).getFirstElement();
- if(selectedElement instanceof IProject) {
- isEnabled = CoreModel.hasCNature((IProject)selectedElement) && ((IProject)selectedElement).isOpen();
- } else if(selectedElement instanceof ITranslationUnit) {
- isEnabled = true;
- }
- }
- }
-
- @Override
- public void init(IWorkbenchWindow window) {
- }
-
- @Override
- public void dispose() {
- }
-
- /**
- * @return {@code true} if the action is enabled or {@code false} otherwise.
- */
- public boolean isEnabled() {
- selectionChanged(SelectionUtil.getActiveSelection());
- return isEnabled;
- }
-
@Override
- public void selectionChanged(IAction action, ISelection selection) {
- selectionChanged(selection);
+ protected int getUpdateOptions() {
+ return 0;
}
}