diff --git a/core/org.eclipse.cdt.ui/plugin.properties b/core/org.eclipse.cdt.ui/plugin.properties
index 088089d64fb..99fce247cc5 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 e37b22f1f1c..0a9648d636d 100644
--- a/core/org.eclipse.cdt.ui/plugin.xml
+++ b/core/org.eclipse.cdt.ui/plugin.xml
@@ -4453,6 +4453,146 @@
parent="org.eclipse.cdt.internal.ui.language.settings.providers.LanguageSettingsProvidersPage"
tooltip="%AllLanguageSettingEntries.tooltip"/>
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
tuSelection= new ArrayList();
- 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 65fdc01a89c..c01f45a3c99 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 44e4f33a4e5..60cc631ac0c 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 f09481bea07..43ca7b818f4 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 fProblems= new ArrayList();
@@ -142,15 +152,11 @@ public class CreateParserLogAction implements IObjectActionDelegate {
fSite= targetPart.getSite();
}
- @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 workingCopies = new ArrayList();
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 tuSelection= new ArrayList();
- 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 00000000000..ebe905777b3
--- /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 00000000000..568275f83da
--- /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 00000000000..e6cb1d2736f
--- /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 07814660f0d..502e470530c 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 tuSelection= new ArrayList();
+ 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 00000000000..88e6e980afc
--- /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 00000000000..8b3f5a42cfe
--- /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 94b1982453e..4051e4b7369 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 00000000000..96995e9d7d6
--- /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 00000000000..6d9115acb90
--- /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 e6c6f2ce55d..929c5b2cedd 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 projects= new ArrayList();
- 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 projects = new ArrayList();
+ 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 c7cf66c6107..d55ab6e0bc2 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,
+ * null
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 95efd6c3994..6ec57270bdf 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 null
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;
+ }
}