summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCaroline Rieder2013-05-23 06:32:22 (EDT)
committerAnton Leherbauer2013-05-23 10:03:55 (EDT)
commitef7967342a8232124e242f397da79c2d12537812 (patch)
tree17ce4ae78e28c7f0f173c1193827bb736d686af4
parente91740f2eb3b186d8b686c1e66d03bda4573a82b (diff)
downloadorg.eclipse.cdt-ef7967342a8232124e242f397da79c2d12537812.zip
org.eclipse.cdt-ef7967342a8232124e242f397da79c2d12537812.tar.gz
org.eclipse.cdt-ef7967342a8232124e242f397da79c2d12537812.tar.bz2
Bug 405239 - Index actions are only available within context menurefs/changes/73/13073/2
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: Ide0e3e241f1162323c2e17d2d58741eb3db9ae41 Signed-off-by: Caroline Rieder <caroline.rieder@windriver.com> Reviewed-on: https://git.eclipse.org/r/13073 Reviewed-by: Anton Leherbauer <anton.leherbauer@windriver.com> IP-Clean: Anton Leherbauer <anton.leherbauer@windriver.com> Tested-by: Anton Leherbauer <anton.leherbauer@windriver.com>
-rwxr-xr-xcore/org.eclipse.cdt.ui/plugin.properties1
-rw-r--r--core/org.eclipse.cdt.ui/plugin.xml140
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/AbstractUpdateIndexAction.java78
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/ActionMessages.java3
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/ActionMessages.properties4
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/CreateParserLogAction.java101
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/CreateParserLogHandler.java39
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/FreshenAllFilesHandler.java39
-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.java83
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/RebuildIndexHandler.java39
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/UpdateIndexWithModifiedFilesHandler.java39
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/UpdateUnresolvedIncludesAction.java3
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/UpdateUnresolvedIncludesHandler.java39
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindUnresolvedIncludesHandler.java39
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindUnresolvedIncludesProjectAction.java77
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java29
-rw-r--r--core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/SelectionUtil.java28
18 files changed, 848 insertions, 51 deletions
diff --git a/core/org.eclipse.cdt.ui/plugin.properties b/core/org.eclipse.cdt.ui/plugin.properties
index 088089d..99fce24 100755
--- a/core/org.eclipse.cdt.ui/plugin.properties
+++ b/core/org.eclipse.cdt.ui/plugin.properties
@@ -524,6 +524,7 @@ page.c.general=C/C++ General
Configurations.menu=Build Configurations
ResourceConfigurations.menu=Resource Configurations
Index.menu=Index
+C.Cpp.Index.menu=C/C++ &Index
CDTWizard=CDT New Project Wizard
CDTproject=CDT Project
diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml
index e37b22f..0a9648d 100644
--- a/core/org.eclipse.cdt.ui/plugin.xml
+++ b/core/org.eclipse.cdt.ui/plugin.xml
@@ -4455,6 +4455,146 @@
</extension>
<extension
point="org.eclipse.ui.commands">
+ <command
+ name="%RebuildIndex.name"
+ categoryId="org.eclipse.ui.category.project"
+ id="org.eclipse.cdt.ui.menu.rebuildIndex">
+ </command>
+ <command
+ name="%FreshenIndex.name"
+ categoryId="org.eclipse.ui.category.project"
+ id="org.eclipse.cdt.ui.menu.freshenAllFiles">
+ </command>
+ <command
+ name="%SyncIndex.name"
+ categoryId="org.eclipse.ui.category.project"
+ id="org.eclipse.cdt.ui.menu.updateWithModifiedFiles">
+ </command>
+ <command
+ name="%UpdateUnresolvedIncludes.name"
+ categoryId="org.eclipse.ui.category.project"
+ id="org.eclipse.cdt.ui.menu.updateUnresolvedIncludes">
+ </command>
+ <command
+ name="%SearchUnresolvedIncludes.name"
+ categoryId="org.eclipse.ui.category.project"
+ id="org.eclipse.cdt.ui.menu.findUnresolvedIncludes">
+ </command>
+ <command
+ name="%CreateParserLog.name"
+ categoryId="org.eclipse.ui.category.project"
+ id="org.eclipse.cdt.ui.menu.createParserLog">
+ </command>
+ </extension>
+ <extension
+ point="org.eclipse.ui.handlers">
+ <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
+ point="org.eclipse.ui.menus">
+ <menuContribution locationURI="menu:project?after=additions">
+ <separator name="index" visible="true"/>
+ <menu
+ label="%C.Cpp.Index.menu">
+ <visibleWhen>
+ <test property="org.eclipse.cdt.internal.ui.index.enabled" value="enabled"/>
+ </visibleWhen>
+ <separator
+ name="rebuild"
+ visible="true">
+ </separator>
+ <command
+ commandId="org.eclipse.cdt.ui.menu.rebuildIndex"
+ label="%RebuildIndex.name">
+ </command>
+ <separator
+ name="update"
+ visible="true">
+ </separator>
+ <command
+ commandId="org.eclipse.cdt.ui.menu.freshenAllFiles"
+ label="%FreshenIndex.name">
+ </command>
+ <command
+ commandId="org.eclipse.cdt.ui.menu.updateWithModifiedFiles"
+ label="%SyncIndex.name">
+ </command>
+ <command
+ commandId="org.eclipse.cdt.ui.menu.updateUnresolvedIncludes"
+ label="%UpdateUnresolvedIncludes.name">
+ </command>
+ <separator
+ name="search"
+ visible="true">
+ </separator>
+ <command
+ commandId="org.eclipse.cdt.ui.menu.findUnresolvedIncludes"
+ label="%SearchUnresolvedIncludes.name">
+ </command>
+ <separator
+ name="log"
+ visible="true">
+ </separator>
+ <command
+ commandId="org.eclipse.cdt.ui.menu.createParserLog"
+ label="%CreateParserLog.name">
+ </command>
+ </menu>
+ </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"
name="%deleteConfigsCommand.name">
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 a679a82..67ed241 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
+ * Copyright (c) 2007, 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
@@ -14,24 +14,33 @@ package org.eclipse.cdt.internal.ui.actions;
import java.util.ArrayList;
import java.util.Iterator;
+import org.eclipse.core.resources.IProject;
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;
-public abstract class AbstractUpdateIndexAction implements IObjectActionDelegate {
+import org.eclipse.cdt.internal.ui.util.EditorUtility;
+import org.eclipse.cdt.internal.ui.util.SelectionUtil;
+
+public abstract class AbstractUpdateIndexAction implements IObjectActionDelegate, IWorkbenchWindowActionDelegate {
private ISelection fSelection;
+ private boolean isEnabled;
@Override
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
@@ -39,19 +48,29 @@ public abstract class AbstractUpdateIndexAction implements IObjectActionDelegate
@Override
public void run(IAction action) {
- if (!(fSelection instanceof IStructuredSelection))
+ if(!(fSelection instanceof IStructuredSelection) && !(fSelection instanceof ITextSelection)) {
return;
-
- IStructuredSelection cElements= SelectionConverter.convertSelectionToCElements(fSelection);
+ }
+
ArrayList<ICElement> tuSelection= new ArrayList<ICElement>();
- 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);
+ 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()]);
-
try {
CCorePlugin.getIndexManager().update(tuArray, getUpdateOptions());
} catch (CoreException e) {
@@ -65,12 +84,47 @@ 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) {
+ }
+
+ @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) {
- fSelection = selection;
+ selectionChanged(selection);
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/ActionMessages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/ActionMessages.java
index 65fdc01..c01f45a 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/ActionMessages.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/ActionMessages.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2001, 2011 IBM Corporation and others.
+ * Copyright (c) 2001, 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
@@ -68,6 +68,7 @@ public class ActionMessages extends NLS {
public static String ChangeBuildConfigMenuAction_text;
public static String CreateParserLogAction_existingFile;
public static String CreateParserLogAction_readOnlyFile;
+ public static String CreateParserLogAction_title;
public static String DeleteResConfigsAction_0;
public static String DeleteResConfigsAction_1;
public static String ExcludeFromBuildAction_0;
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/ActionMessages.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/ActionMessages.properties
index 44e4f33..60cc631 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/ActionMessages.properties
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/ActionMessages.properties
@@ -1,5 +1,5 @@
###############################################################################
-# Copyright (c) 2000, 2011 IBM Corporation and others.
+# Copyright (c) 2000, 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
@@ -80,6 +80,8 @@ ChangeBuildConfigMenuAction_text=No way to manage configurations for selected ob
CreateParserLogAction_existingFile=''{0}'' already exists.\nDo you want to replace it?
CreateParserLogAction_readOnlyFile=''{0}'' cannot be modified\!
+CreateParserLogAction_title=Create Parser Log File
+
DeleteResConfigsAction_0=Select resource configurations to restore default settings
DeleteResConfigsAction_1=Reset Resource Configurations
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 f09481b..43ca7b8 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008, 2010 Wind River Systems, Inc. and others.
+ * Copyright (c) 2008, 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
@@ -36,17 +36,23 @@ import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelection;
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;
import org.eclipse.ui.IObjectActionDelegate;
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;
import org.eclipse.cdt.core.CCorePlugin;
@@ -77,7 +83,9 @@ import org.eclipse.cdt.core.parser.ISignificantMacros;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
import org.eclipse.cdt.core.settings.model.ICProjectDescriptionManager;
+import org.eclipse.cdt.ui.CDTUITools;
import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.cdt.ui.IWorkingCopyManager;
import org.eclipse.cdt.internal.core.model.ASTCache;
import org.eclipse.cdt.internal.core.model.TranslationUnit;
@@ -87,10 +95,12 @@ 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 {
+public class CreateParserLogAction implements IObjectActionDelegate, IWorkbenchWindowActionDelegate {
private static final String INDENT = " ";
+ private boolean isEnabled;
private static final class MyVisitor extends ASTVisitor {
List<IASTProblem> fProblems= new ArrayList<IASTProblem>();
@@ -143,14 +153,10 @@ public class CreateParserLogAction implements IObjectActionDelegate {
}
@Override
- public void selectionChanged(IAction action, ISelection selection) {
- fSelection = selection;
- }
-
- @Override
public void run(IAction action) {
- if (!(fSelection instanceof IStructuredSelection))
+ if(!(fSelection instanceof IStructuredSelection) && !(fSelection instanceof ITextSelection)) {
return;
+ }
List<IWorkingCopy> workingCopies = new ArrayList<IWorkingCopy>();
final IWorkbenchPage activePage = fSite.getWorkbenchWindow().getActivePage();
@@ -162,16 +168,24 @@ public class CreateParserLogAction implements IObjectActionDelegate {
workingCopies.add((IWorkingCopy) inputElement);
}
}
- final String title= action.getText().replace("&", "");
- IStructuredSelection cElements= SelectionConverter.convertSelectionToCElements(fSelection);
- Iterator<?> i= cElements.iterator();
ArrayList<ITranslationUnit> tuSelection= new ArrayList<ITranslationUnit>();
- while (i.hasNext()) {
- Object o= i.next();
- if (o instanceof ITranslationUnit) {
- tuSelection.add(convertToWorkingCopy((ITranslationUnit) o, workingCopies));
+ 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);
}
}
+
ITranslationUnit[] tuArray= tuSelection.toArray(new ITranslationUnit[tuSelection.size()]);
if (tuArray.length == 0) {
return;
@@ -221,7 +235,7 @@ public class CreateParserLogAction implements IObjectActionDelegate {
} catch (Exception e) {
}
} catch (IOException e) {
- MessageDialog.openError(fSite.getShell(), action.getText(), e.getMessage());
+ MessageDialog.openError(fSite.getShell(), title, e.getMessage());
}
}
@@ -482,4 +496,59 @@ public class CreateParserLogAction implements IObjectActionDelegate {
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() {
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if(window != null) {
+ IWorkbenchPart workbenchPart = window.getPartService().getActivePart();
+ if (workbenchPart instanceof IEditorPart) {
+ IEditorPart editorPart = (IEditorPart) workbenchPart;
+ IEditorInput editorInput = editorPart.getEditorInput();
+ IWorkingCopyManager manager = CDTUITools.getWorkingCopyManager();
+ IWorkingCopy tu = manager.getWorkingCopy(editorInput);
+ return tu;
+ }
+ }
+ return null;
+ }
+
+ @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);
+ }
}
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
new file mode 100644
index 0000000..ebe9057
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/CreateParserLogHandler.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * Handler for {@link org.eclipse.cdt.internal.ui.actions.CreateParserLogAction}
+ *
+ * @noextend This class is not intended to be subclassed by clients.
+ * @noinstantiate This class is not intended to be instantiated by clients.
+ */
+public class CreateParserLogHandler extends AbstractHandler {
+
+ private final CreateParserLogAction createParserLogAction = new CreateParserLogAction();
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ ISelection selection = HandlerUtil.getCurrentSelection(event);
+ IWorkbenchPart part = HandlerUtil.getActivePart(event);
+ createParserLogAction.setActivePart(null, part);
+ createParserLogAction.selectionChanged(null, selection);
+ createParserLogAction.run(null);
+ return null;
+ }
+}
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
new file mode 100644
index 0000000..568275f
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/FreshenAllFilesHandler.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * Handler for {@link org.eclipse.cdt.internal.ui.actions.FreshenIndexAction}
+ *
+ * @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 {
+
+ 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;
+ }
+}
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
new file mode 100644
index 0000000..e6cb1d2
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/IndexActionsEnabledTester.java
@@ -0,0 +1,118 @@
+/*******************************************************************************
+ * 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 0781466..502e470 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2007, 2008 Wind River Systems, Inc. and others.
+ * Copyright (c) 2007, 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
@@ -10,31 +10,64 @@
*******************************************************************************/
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;
-public class RebuildIndexAction implements IObjectActionDelegate {
+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) {
}
@Override
- public void run(IAction action) {
- IStructuredSelection cElements= SelectionConverter.convertSelectionToCElements(fSelection);
- for (Iterator<?> i = cElements.iterator(); i.hasNext();) {
- Object elem = i.next();
- if (elem instanceof ICProject) {
+ 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);
+ }
+ }
+ }
+ ICElement[] tuArray= tuSelection.toArray(new ICElement[tuSelection.size()]);
+ for (ICElement elem : tuArray) {
+ if(elem instanceof ICProject) {
CCorePlugin.getIndexManager().reindex((ICProject) elem);
}
}
@@ -43,8 +76,42 @@ public class RebuildIndexAction implements IObjectActionDelegate {
/**
* @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) {
- fSelection= selection;
+ selectionChanged(selection);
}
}
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
new file mode 100644
index 0000000..88e6e98
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/RebuildIndexHandler.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * Handler for {@link org.eclipse.cdt.internal.ui.actions.RebuildIndexAction}
+ *
+ * @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 {
+
+ 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;
+ }
+}
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
new file mode 100644
index 0000000..8b3f5a4
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/UpdateIndexWithModifiedFilesHandler.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * Handler for {@link org.eclipse.cdt.internal.ui.actions.UpdateIndexWithModifiedFilesAction}
+ *
+ * @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 {
+
+ 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;
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/UpdateUnresolvedIncludesAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/UpdateUnresolvedIncludesAction.java
index 94b1982..4051e4b 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/UpdateUnresolvedIncludesAction.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/UpdateUnresolvedIncludesAction.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2012 Google, Inc and others.
+ * Copyright (c) 2012, 2013 Google, 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
@@ -13,6 +13,7 @@ package org.eclipse.cdt.internal.ui.actions;
import org.eclipse.cdt.core.index.IIndexManager;
public class UpdateUnresolvedIncludesAction extends AbstractUpdateIndexAction {
+
@Override
protected int getUpdateOptions() {
return IIndexManager.UPDATE_UNRESOLVED_INCLUDES;
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
new file mode 100644
index 0000000..96995e9d
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/actions/UpdateUnresolvedIncludesHandler.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * 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;
+
+/**
+ * Handler for {@link org.eclipse.cdt.internal.ui.actions.UpdateIndexWithModifiedFilesAction}
+ *
+ * @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 {
+
+ private final UpdateUnresolvedIncludesAction udpateAction = 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;
+ }
+}
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
new file mode 100644
index 0000000..6d9115a
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/search/actions/FindUnresolvedIncludesHandler.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * 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.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;
+
+/**
+ * Handler for {@link org.eclipse.cdt.internal.ui.search.actions.FindUnresolvedIncludesProjectAction}
+ *
+ * @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 {
+
+ private final FindUnresolvedIncludesProjectAction rebuildIndexAction= 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;
+ }
+}
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 e6c6f2c..929c5b2 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2008 Wind River Systems, Inc. and others.
+ * Copyright (c) 2008, 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
@@ -14,44 +14,64 @@ 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.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 {
+public class FindUnresolvedIncludesProjectAction implements IObjectActionDelegate, IWorkbenchWindowActionDelegate {
private ISelection fSelection;
private IWorkbenchSite fSite;
+ private boolean isEnabled;
public FindUnresolvedIncludesProjectAction() {
}
@Override
public void run(IAction action) {
- List<ICProject> projects= new ArrayList<ICProject>();
- IStructuredSelection cElements= SelectionConverter.convertSelectionToCElements(fSelection);
- for (Iterator<?> i = cElements.iterator(); i.hasNext();) {
- Object elem = i.next();
- if (elem instanceof ICProject) {
- projects.add((ICProject) elem);
+ 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()) {
StatusLineHandler.showStatusLineMessage(fSite, CSearchMessages.CSearchOperation_operationUnavailable_message);
return;
@@ -69,8 +89,45 @@ 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) {
- fSelection= selection;
+ selectionChanged(selection);
}
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java
index c7cf66c..d55ab6e 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2011 QNX Software Systems and others.
+ * Copyright (c) 2000, 2013 QNX Software Systems 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
@@ -1015,4 +1015,31 @@ public class EditorUtility {
return new NullProgressMonitor();
}
+
+
+ /**
+ * Returns the project contains the resource, which is currently open in the active editor.
+ * If the active part is no ITextEditor or if the editorInput is no FileEditorInput,
+ * <code>null</code> is returned.
+ *
+ * @return the project which the selected editor input belongs to or null
+ */
+ public static IProject getProjectForActiveEditor() {
+ IProject project = null;
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if(window != null) {
+ IWorkbenchPage activePage = window.getActivePage();
+ if(activePage != null) {
+ IEditorPart activeEditor = activePage.getActiveEditor();
+ if(activeEditor instanceof ITextEditor) {
+ IEditorInput editorInput = ((ITextEditor)activeEditor).getEditorInput();
+ IFile file = ResourceUtil.getFile(editorInput);
+ if(file != null) {
+ project = file.getProject();
+ }
+ }
+ }
+ }
+ return project;
+ }
}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/SelectionUtil.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/SelectionUtil.java
index 95efd6c..6ec5727 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/SelectionUtil.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/SelectionUtil.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2000, 2010 IBM Corporation and others.
+ * Copyright (c) 2000, 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
@@ -13,6 +13,10 @@ package org.eclipse.cdt.internal.ui.util;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
public class SelectionUtil {
/**
@@ -30,4 +34,26 @@ public class SelectionUtil {
return selection.getFirstElement();
}
+
+
+ /**
+ * Returns the selection in the currently active workbench window part.
+ * If the no selection exists or no selection exists in the active part <code>null</code> is returned.
+ *
+ * @return the current selection in the active workbench window part or null
+ */
+ public static ISelection getActiveSelection() {
+ ISelection selection = null;
+ IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
+ if (window != null) {
+ IWorkbenchPage activePage = window.getActivePage();
+ if (activePage != null) {
+ IWorkbenchPart activePart = activePage.getActivePart();
+ if (activePart != null) {
+ selection = window.getSelectionService().getSelection(activePart.getSite().getId());
+ }
+ }
+ }
+ return selection;
+ }
}