mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 06:32:10 +02:00
V.3 - Bug 405239 - Index actions are only available within context menu
The provided patch contributes the Index actions to the global Project menu using the command/handler extension points. Project related actions are enabled when: - When an ICProject, an ICContainer or an ITranslationUnit is selected in the Project Explorer and the Project Explorer has the focus - When a file of an ICProject is open in the Editor and the Editor has the focus File related action is enabled when: - When an ITranslationUnit is selected in the Project Explorer and the Project Explorer has the focus - When an ITranslationUnit is open in the Editor and the Editor has the focus Change-Id: I11f05e2b2f0c8f1652b0ee7e655aacacd03c7fde Signed-off-by: Caroline Rieder <caroline.rieder@windriver.com> Reviewed-on: https://git.eclipse.org/r/13123 Reviewed-by: Anton Leherbauer <anton.leherbauer@windriver.com> IP-Clean: Anton Leherbauer <anton.leherbauer@windriver.com> Tested-by: Anton Leherbauer <anton.leherbauer@windriver.com>
This commit is contained in:
parent
2a84dfb7e3
commit
ecb373f340
13 changed files with 201 additions and 522 deletions
|
@ -1407,16 +1407,19 @@
|
|||
</visibility>
|
||||
<action
|
||||
class="org.eclipse.cdt.internal.ui.actions.UpdateUnresolvedIncludesAction"
|
||||
definitionId="org.eclipse.cdt.ui.menu.updateUnresolvedIncludes"
|
||||
id="org.eclipse.cdt.ui.updateUnresolvedIncludesAction"
|
||||
label="%UpdateUnresolvedIncludes.name"
|
||||
menubarPath="org.eclipse.cdt.ui.indexmenu/update"/>
|
||||
<action
|
||||
class="org.eclipse.cdt.internal.ui.actions.UpdateIndexWithModifiedFilesAction"
|
||||
definitionId="org.eclipse.cdt.ui.menu.updateWithModifiedFiles"
|
||||
id="org.eclipse.cdt.ui.syncIndexWithDiskAction"
|
||||
label="%SyncIndex.name"
|
||||
menubarPath="org.eclipse.cdt.ui.indexmenu/update"/>
|
||||
<action
|
||||
class="org.eclipse.cdt.internal.ui.actions.FreshenIndexAction"
|
||||
definitionId="org.eclipse.cdt.ui.menu.freshenAllFiles"
|
||||
id="org.eclipse.cdt.ui.updateIndexAction"
|
||||
label="%FreshenIndex.name"
|
||||
menubarPath="org.eclipse.cdt.ui.indexmenu/update"/>
|
||||
|
@ -1438,6 +1441,7 @@
|
|||
</visibility>
|
||||
<action
|
||||
class="org.eclipse.cdt.internal.ui.actions.CreateParserLogAction"
|
||||
definitionId="org.eclipse.cdt.ui.menu.createParserLog"
|
||||
id="org.eclipse.cdt.ui.parserLogAction"
|
||||
label="%CreateParserLog.name"
|
||||
menubarPath="org.eclipse.cdt.ui.indexmenu/log"/>
|
||||
|
@ -1456,11 +1460,13 @@
|
|||
objectClass="org.eclipse.cdt.core.model.ICProject">
|
||||
<action
|
||||
class="org.eclipse.cdt.internal.ui.actions.RebuildIndexAction"
|
||||
definitionId="org.eclipse.cdt.ui.menu.rebuildIndex"
|
||||
id="org.eclipse.cdt.ui.rebuildIndexAction"
|
||||
label="%RebuildIndex.name"
|
||||
menubarPath="org.eclipse.cdt.ui.indexmenu/rebuild"/>
|
||||
<action
|
||||
class="org.eclipse.cdt.internal.ui.search.actions.FindUnresolvedIncludesProjectAction"
|
||||
definitionId="org.eclipse.cdt.ui.menu.findUnresolvedIncludes"
|
||||
id="org.eclipse.cdt.ui.searchUnresolvedIncludes"
|
||||
label="%SearchUnresolvedIncludes.name"
|
||||
menubarPath="org.eclipse.cdt.ui.indexmenu/search"/>
|
||||
|
@ -1485,26 +1491,31 @@
|
|||
</visibility>
|
||||
<action
|
||||
class="org.eclipse.cdt.internal.ui.actions.UpdateUnresolvedIncludesAction"
|
||||
definitionId="org.eclipse.cdt.ui.menu.updateUnresolvedIncludes"
|
||||
id="org.eclipse.cdt.ui.updateUnresolvedIncludesAction"
|
||||
label="%UpdateUnresolvedIncludes.name"
|
||||
menubarPath="org.eclipse.cdt.ui.indexmenu/update"/>
|
||||
<action
|
||||
class="org.eclipse.cdt.internal.ui.actions.UpdateIndexWithModifiedFilesAction"
|
||||
definitionId="org.eclipse.cdt.ui.menu.updateWithModifiedFiles"
|
||||
id="org.eclipse.cdt.ui.syncIndexWithDiskAction"
|
||||
label="%SyncIndex.name"
|
||||
menubarPath="org.eclipse.cdt.ui.indexmenu/update"/>
|
||||
<action
|
||||
class="org.eclipse.cdt.internal.ui.actions.FreshenIndexAction"
|
||||
definitionId="org.eclipse.cdt.ui.menu.freshenAllFiles"
|
||||
id="org.eclipse.cdt.ui.updateIndexAction"
|
||||
label="%FreshenIndex.name"
|
||||
menubarPath="org.eclipse.cdt.ui.indexmenu/update"/>
|
||||
<action
|
||||
class="org.eclipse.cdt.internal.ui.actions.RebuildIndexAction"
|
||||
definitionId="org.eclipse.cdt.ui.menu.rebuildIndex"
|
||||
id="org.eclipse.cdt.ui.rebuildIndexAction"
|
||||
label="%RebuildIndex.name"
|
||||
menubarPath="org.eclipse.cdt.ui.indexmenu/rebuild"/>
|
||||
<action
|
||||
class="org.eclipse.cdt.internal.ui.search.actions.FindUnresolvedIncludesProjectAction"
|
||||
definitionId="org.eclipse.cdt.ui.menu.findUnresolvedIncludes"
|
||||
id="org.eclipse.cdt.ui.searchUnresolvedIncludes"
|
||||
label="%SearchUnresolvedIncludes.name"
|
||||
menubarPath="org.eclipse.cdt.ui.indexmenu/search"/>
|
||||
|
@ -4491,44 +4502,26 @@
|
|||
<handler
|
||||
class="org.eclipse.cdt.internal.ui.actions.RebuildIndexHandler"
|
||||
commandId="org.eclipse.cdt.ui.menu.rebuildIndex">
|
||||
<enabledWhen>
|
||||
<test property="org.eclipse.cdt.internal.ui.index.rebuild" value="enabled"/>
|
||||
</enabledWhen>
|
||||
</handler>
|
||||
<handler
|
||||
class="org.eclipse.cdt.internal.ui.actions.FreshenAllFilesHandler"
|
||||
commandId="org.eclipse.cdt.ui.menu.freshenAllFiles">
|
||||
<enabledWhen>
|
||||
<test property="org.eclipse.cdt.internal.ui.index.freshen" value="enabled"/>
|
||||
</enabledWhen>
|
||||
</handler>
|
||||
<handler
|
||||
class="org.eclipse.cdt.internal.ui.actions.UpdateIndexWithModifiedFilesHandler"
|
||||
commandId="org.eclipse.cdt.ui.menu.updateWithModifiedFiles">
|
||||
<enabledWhen>
|
||||
<test property="org.eclipse.cdt.internal.ui.index.udpateWithModifiedFiles" value="enabled"/>
|
||||
</enabledWhen>
|
||||
</handler>
|
||||
<handler
|
||||
class="org.eclipse.cdt.internal.ui.actions.UpdateUnresolvedIncludesHandler"
|
||||
commandId="org.eclipse.cdt.ui.menu.updateUnresolvedIncludes">
|
||||
<enabledWhen>
|
||||
<test property="org.eclipse.cdt.internal.ui.index.updateUnresolvedIncludes" value="enabled"/>
|
||||
</enabledWhen>
|
||||
</handler>
|
||||
<handler
|
||||
class="org.eclipse.cdt.internal.ui.search.actions.FindUnresolvedIncludesHandler"
|
||||
commandId="org.eclipse.cdt.ui.menu.findUnresolvedIncludes">
|
||||
<enabledWhen>
|
||||
<test property="org.eclipse.cdt.internal.ui.index.findUnresolvedIncludes" value="enabled"/>
|
||||
</enabledWhen>
|
||||
</handler>
|
||||
<handler
|
||||
class="org.eclipse.cdt.internal.ui.actions.CreateParserLogHandler"
|
||||
commandId="org.eclipse.cdt.ui.menu.createParserLog">
|
||||
<enabledWhen>
|
||||
<test property="org.eclipse.cdt.internal.ui.index.log" value="enabled"/>
|
||||
</enabledWhen>
|
||||
</handler>
|
||||
</extension>
|
||||
<extension
|
||||
|
@ -4538,7 +4531,27 @@
|
|||
<menu
|
||||
label="%C.Cpp.Index.menu">
|
||||
<visibleWhen>
|
||||
<test property="org.eclipse.cdt.internal.ui.index.enabled" value="enabled"/>
|
||||
<or>
|
||||
<with variable="selection">
|
||||
<iterate operator="and" ifEmpty="false">
|
||||
<adapt type="org.eclipse.core.resources.IResource">
|
||||
<test
|
||||
property="org.eclipse.core.resources.projectNature"
|
||||
value="org.eclipse.cdt.core.cnature"/>
|
||||
</adapt>
|
||||
</iterate>
|
||||
</with>
|
||||
<with variable="activeEditorInput">
|
||||
<or>
|
||||
<adapt type="org.eclipse.core.resources.IFile">
|
||||
<test
|
||||
property="org.eclipse.core.resources.projectNature"
|
||||
value="org.eclipse.cdt.core.cnature"/>
|
||||
</adapt>
|
||||
<instanceof value="org.eclipse.cdt.internal.ui.util.ExternalEditorInput"/>
|
||||
</or>
|
||||
</with>
|
||||
</or>
|
||||
</visibleWhen>
|
||||
<separator
|
||||
name="rebuild"
|
||||
|
@ -4583,16 +4596,6 @@
|
|||
</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
|
||||
|
|
|
@ -15,32 +15,25 @@ import java.util.ArrayList;
|
|||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.jface.text.ITextSelection;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.ui.IActionDelegate;
|
||||
import org.eclipse.ui.IObjectActionDelegate;
|
||||
import org.eclipse.ui.IWorkbenchPart;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.index.IIndexManager;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICContainer;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
||||
import org.eclipse.cdt.internal.ui.util.SelectionUtil;
|
||||
|
||||
public abstract class AbstractUpdateIndexAction implements IObjectActionDelegate, IWorkbenchWindowActionDelegate {
|
||||
public abstract class AbstractUpdateIndexAction implements IObjectActionDelegate {
|
||||
private ISelection fSelection;
|
||||
private boolean isEnabled;
|
||||
|
||||
@Override
|
||||
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
|
||||
|
@ -51,28 +44,13 @@ public abstract class AbstractUpdateIndexAction implements IObjectActionDelegate
|
|||
if(!(fSelection instanceof IStructuredSelection) && !(fSelection instanceof ITextSelection)) {
|
||||
return;
|
||||
}
|
||||
|
||||
ArrayList<ICElement> tuSelection= new ArrayList<ICElement>();
|
||||
if(fSelection instanceof IStructuredSelection) {
|
||||
IStructuredSelection cElements= SelectionConverter.convertSelectionToCElements(fSelection);
|
||||
for (Iterator<?> i= cElements.iterator(); i.hasNext();) {
|
||||
Object o= i.next();
|
||||
if (o instanceof ICProject || o instanceof ICContainer || o instanceof ITranslationUnit) {
|
||||
tuSelection.add((ICElement) o);
|
||||
}
|
||||
}
|
||||
} else if(fSelection instanceof ITextSelection) {
|
||||
IProject project = EditorUtility.getProjectForActiveEditor();
|
||||
if(project != null) {
|
||||
ICProject cproject = CCorePlugin.getDefault().getCoreModel().create(project);
|
||||
if(cproject != null) {
|
||||
tuSelection.add(cproject);
|
||||
}
|
||||
}
|
||||
}
|
||||
ICElement[] tuArray= tuSelection.toArray(new ICElement[tuSelection.size()]);
|
||||
ICProject[] projects = getSelectedCProjects();
|
||||
doRun(projects);
|
||||
}
|
||||
|
||||
protected void doRun(ICProject[] projects) {
|
||||
try {
|
||||
CCorePlugin.getIndexManager().update(tuArray, getUpdateOptions());
|
||||
CCorePlugin.getIndexManager().update(projects, getUpdateOptions());
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.log(e);
|
||||
}
|
||||
|
@ -84,47 +62,40 @@ public abstract class AbstractUpdateIndexAction implements IObjectActionDelegate
|
|||
* @since 4.0
|
||||
*/
|
||||
abstract protected int getUpdateOptions();
|
||||
|
||||
/**
|
||||
* @see IActionDelegate#selectionChanged(IAction, ISelection)
|
||||
*/
|
||||
public void selectionChanged(ISelection selection) {
|
||||
fSelection= selection;
|
||||
isEnabled = false;
|
||||
|
||||
if(selection == null || selection instanceof ITextSelection) {
|
||||
IProject project = EditorUtility.getProjectForActiveEditor();
|
||||
if(project != null) {
|
||||
isEnabled = CoreModel.hasCNature(project);
|
||||
}
|
||||
} else if(selection instanceof IStructuredSelection) {
|
||||
Object selectedElement = ((IStructuredSelection)selection).getFirstElement();
|
||||
if(selectedElement instanceof IProject) {
|
||||
isEnabled = CoreModel.hasCNature((IProject)selectedElement) && ((IProject)selectedElement).isOpen();
|
||||
} else if(selectedElement instanceof ITranslationUnit) {
|
||||
isEnabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(IWorkbenchWindow window) {
|
||||
}
|
||||
|
||||
@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);
|
||||
fSelection = selection;
|
||||
}
|
||||
|
||||
public boolean isEnabledFor(ISelection selection) {
|
||||
selectionChanged(null, selection);
|
||||
ICProject[] project = getSelectedCProjects();
|
||||
return project.length > 0;
|
||||
}
|
||||
|
||||
protected ICProject[] getSelectedCProjects() {
|
||||
ArrayList<ICProject> tuSelection= new ArrayList<ICProject>();
|
||||
if(fSelection instanceof IStructuredSelection) {
|
||||
IStructuredSelection resources = SelectionConverter.convertSelectionToResources(fSelection);
|
||||
for (Iterator<?> i= resources.iterator(); i.hasNext();) {
|
||||
Object o= i.next();
|
||||
if(o instanceof IResource) {
|
||||
ICProject cproject= CCorePlugin.getDefault().getCoreModel().create(((IResource)o).getProject());
|
||||
if(cproject != null) {
|
||||
tuSelection.add(cproject);
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if(fSelection == null || fSelection instanceof ITextSelection) {
|
||||
IProject project = EditorUtility.getProjectForActiveEditor();
|
||||
if(project != null) {
|
||||
ICProject cproject= CCorePlugin.getDefault().getCoreModel().create(project);
|
||||
if(cproject != null) {
|
||||
tuSelection.add(cproject);
|
||||
}
|
||||
}
|
||||
}
|
||||
return tuSelection.toArray(new ICProject[tuSelection.size()]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Wind River Systems - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.actions;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.ui.IWorkbenchPart;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.util.SelectionUtil;
|
||||
|
||||
/**
|
||||
* Abstract handler for {@link org.eclipse.cdt.internal.ui.actions.AbstractUpdateIndexAction}
|
||||
*/
|
||||
public abstract class AbstractUpdateIndexHandler extends AbstractHandler {
|
||||
|
||||
abstract protected AbstractUpdateIndexAction getAction();
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
ISelection selection = HandlerUtil.getCurrentSelection(event);
|
||||
IWorkbenchPart part = HandlerUtil.getActivePart(event);
|
||||
getAction().setActivePart(null, part);
|
||||
getAction().selectionChanged(null, selection);
|
||||
getAction().run(null);
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.core.commands.AbstractHandler#setEnabled(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public void setEnabled(Object evaluationContext) {
|
||||
ISelection selection = SelectionUtil.getActiveSelection();
|
||||
setBaseEnabled(getAction().isEnabledFor(selection));
|
||||
}
|
||||
}
|
|
@ -42,7 +42,6 @@ import org.eclipse.jface.viewers.IStructuredSelection;
|
|||
import org.eclipse.osgi.util.NLS;
|
||||
import org.eclipse.swt.SWT;
|
||||
import org.eclipse.swt.widgets.FileDialog;
|
||||
import org.eclipse.ui.IActionDelegate;
|
||||
import org.eclipse.ui.IEditorInput;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.IEditorReference;
|
||||
|
@ -51,7 +50,6 @@ import org.eclipse.ui.IWorkbenchPage;
|
|||
import org.eclipse.ui.IWorkbenchPart;
|
||||
import org.eclipse.ui.IWorkbenchPartSite;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.ide.IDE;
|
||||
|
||||
|
@ -95,12 +93,10 @@ import org.eclipse.cdt.internal.core.pdom.indexer.ProjectIndexerInputAdapter;
|
|||
|
||||
import org.eclipse.cdt.internal.ui.editor.ASTProvider;
|
||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||
import org.eclipse.cdt.internal.ui.util.SelectionUtil;
|
||||
|
||||
@SuppressWarnings("nls")
|
||||
public class CreateParserLogAction implements IObjectActionDelegate, IWorkbenchWindowActionDelegate {
|
||||
public class CreateParserLogAction implements IObjectActionDelegate {
|
||||
private static final String INDENT = " ";
|
||||
private boolean isEnabled;
|
||||
|
||||
private static final class MyVisitor extends ASTVisitor {
|
||||
List<IASTProblem> fProblems= new ArrayList<IASTProblem>();
|
||||
|
@ -168,29 +164,20 @@ public class CreateParserLogAction implements IObjectActionDelegate, IWorkbenchW
|
|||
workingCopies.add((IWorkingCopy) inputElement);
|
||||
}
|
||||
}
|
||||
ArrayList<ITranslationUnit> tuSelection= new ArrayList<ITranslationUnit>();
|
||||
String title = ActionMessages.CreateParserLogAction_title;
|
||||
if(fSelection instanceof IStructuredSelection) {
|
||||
IStructuredSelection cElements= SelectionConverter.convertSelectionToCElements(fSelection);
|
||||
Iterator<?> i= cElements.iterator();
|
||||
while (i.hasNext()) {
|
||||
Object o= i.next();
|
||||
if (o instanceof ITranslationUnit) {
|
||||
tuSelection.add(convertToWorkingCopy((ITranslationUnit) o, workingCopies));
|
||||
}
|
||||
}
|
||||
} else if(fSelection instanceof ITextSelection) {
|
||||
IWorkingCopy tu = getTranslationUnitForSelectedEditorInput();
|
||||
if(tu != null) {
|
||||
tuSelection.add(tu);
|
||||
|
||||
ArrayList<ITranslationUnit> tuSelection = getSelectedTranslationUnits();
|
||||
for(int i = 0; i < tuSelection.size(); i++) {
|
||||
if(!(tuSelection.get(i) instanceof IWorkingCopy)) {
|
||||
tuSelection.set(i, convertToWorkingCopy(tuSelection.get(i), workingCopies));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
ITranslationUnit[] tuArray= tuSelection.toArray(new ITranslationUnit[tuSelection.size()]);
|
||||
if (tuArray.length == 0) {
|
||||
return;
|
||||
}
|
||||
FileDialog dlg= new FileDialog(fSite.getShell(), SWT.SAVE);
|
||||
String title = ActionMessages.CreateParserLogAction_title;
|
||||
dlg.setText(title);
|
||||
dlg.setFilterExtensions(new String[]{"*.log"});
|
||||
String path= null;
|
||||
|
@ -496,27 +483,13 @@ public class CreateParserLogAction implements IObjectActionDelegate, IWorkbenchW
|
|||
out.println();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IActionDelegate#selectionChanged(IAction, ISelection)
|
||||
*/
|
||||
public void selectionChanged(ISelection selection) {
|
||||
fSelection= selection;
|
||||
isEnabled = false;
|
||||
|
||||
if(selection == null || selection instanceof ITextSelection) {
|
||||
IWorkingCopy tu = getTranslationUnitForSelectedEditorInput();
|
||||
if(tu != null) {
|
||||
isEnabled = true;
|
||||
}
|
||||
} else if(selection instanceof IStructuredSelection) {
|
||||
if(((IStructuredSelection)selection).getFirstElement() instanceof ITranslationUnit) {
|
||||
isEnabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IWorkingCopy getTranslationUnitForSelectedEditorInput() {
|
||||
@Override
|
||||
public void selectionChanged(IAction action, ISelection selection) {
|
||||
fSelection = selection;
|
||||
}
|
||||
|
||||
public IWorkingCopy getTranslationUnitForSelectedEditorInput() {
|
||||
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
|
||||
if(window != null) {
|
||||
IWorkbenchPart workbenchPart = window.getPartService().getActivePart();
|
||||
|
@ -531,24 +504,29 @@ public class CreateParserLogAction implements IObjectActionDelegate, IWorkbenchW
|
|||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(IWorkbenchWindow window) {
|
||||
public boolean isEnabledFor(ISelection selection) {
|
||||
selectionChanged(null, selection);
|
||||
ArrayList<ITranslationUnit> tus = getSelectedTranslationUnits();
|
||||
return tus.size() > 0;
|
||||
}
|
||||
|
||||
@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);
|
||||
private ArrayList<ITranslationUnit> getSelectedTranslationUnits() {
|
||||
ArrayList<ITranslationUnit> tuSelection= new ArrayList<ITranslationUnit>();
|
||||
if(fSelection instanceof IStructuredSelection) {
|
||||
IStructuredSelection cElements= SelectionConverter.convertSelectionToCElements(fSelection);
|
||||
Iterator<?> i= cElements.iterator();
|
||||
while (i.hasNext()) {
|
||||
Object o= i.next();
|
||||
if (o instanceof ITranslationUnit) {
|
||||
tuSelection.add((ITranslationUnit)o);
|
||||
}
|
||||
}
|
||||
} else if(fSelection == null || fSelection instanceof ITextSelection) {
|
||||
IWorkingCopy tu = getTranslationUnitForSelectedEditorInput();
|
||||
if(tu != null) {
|
||||
tuSelection.add(tu);
|
||||
}
|
||||
}
|
||||
return tuSelection;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,6 +17,8 @@ import org.eclipse.jface.viewers.ISelection;
|
|||
import org.eclipse.ui.IWorkbenchPart;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.util.SelectionUtil;
|
||||
|
||||
/**
|
||||
* Handler for {@link org.eclipse.cdt.internal.ui.actions.CreateParserLogAction}
|
||||
*
|
||||
|
@ -36,4 +38,13 @@ public class CreateParserLogHandler extends AbstractHandler {
|
|||
createParserLogAction.run(null);
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.core.commands.AbstractHandler#setEnabled(java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public void setEnabled(Object evaluationContext) {
|
||||
ISelection selection = SelectionUtil.getActiveSelection();
|
||||
setBaseEnabled(createParserLogAction.isEnabledFor(selection));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,12 +10,6 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.actions;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.ui.IWorkbenchPart;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
|
||||
/**
|
||||
* Handler for {@link org.eclipse.cdt.internal.ui.actions.FreshenIndexAction}
|
||||
|
@ -23,17 +17,12 @@ import org.eclipse.ui.handlers.HandlerUtil;
|
|||
* @noextend This class is not intended to be subclassed by clients.
|
||||
* @noinstantiate This class is not intended to be instantiated by clients.
|
||||
*/
|
||||
public class FreshenAllFilesHandler extends AbstractHandler {
|
||||
public class FreshenAllFilesHandler extends AbstractUpdateIndexHandler {
|
||||
|
||||
private final FreshenIndexAction freshenIndexAction = new FreshenIndexAction();
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
ISelection selection = HandlerUtil.getCurrentSelection(event);
|
||||
IWorkbenchPart part = HandlerUtil.getActivePart(event);
|
||||
freshenIndexAction.setActivePart(null, part);
|
||||
freshenIndexAction.selectionChanged(null, selection);
|
||||
freshenIndexAction.run(null);
|
||||
return null;
|
||||
public AbstractUpdateIndexAction getAction() {
|
||||
return freshenIndexAction;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,118 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2013 Wind River Systems, Inc. and others.
|
||||
* All rights reserved. This program and the accompanying materials
|
||||
* are made available under the terms of the Eclipse Public License v1.0
|
||||
* which accompanies this distribution, and is available at
|
||||
* http://www.eclipse.org/legal/epl-v10.html
|
||||
*
|
||||
* Contributors:
|
||||
* Wind River Systems - Initial API and implementation
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.actions;
|
||||
|
||||
import org.eclipse.core.expressions.PropertyTester;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.StructuredSelection;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.ISelectionListener;
|
||||
import org.eclipse.ui.ISelectionService;
|
||||
import org.eclipse.ui.IWindowListener;
|
||||
import org.eclipse.ui.IWorkbenchPart;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.ide.ResourceUtil;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.search.actions.FindUnresolvedIncludesProjectAction;
|
||||
|
||||
public class IndexActionsEnabledTester extends PropertyTester implements ISelectionListener, IWindowListener {
|
||||
|
||||
private static RebuildIndexAction fRebuildIndexAction = new RebuildIndexAction();
|
||||
private static CreateParserLogAction fCreateParserLogAction = new CreateParserLogAction();
|
||||
private static FreshenIndexAction fFreshenAllFiles = new FreshenIndexAction();
|
||||
private static UpdateUnresolvedIncludesAction fUpdateUnresolvedIncludes = new UpdateUnresolvedIncludesAction();
|
||||
private static UpdateIndexWithModifiedFilesAction fUpdateWithModifiedFiles = new UpdateIndexWithModifiedFilesAction();
|
||||
private static FindUnresolvedIncludesProjectAction fFindUnresolvedIncludes = new FindUnresolvedIncludesProjectAction();
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
|
||||
*/
|
||||
@Override
|
||||
public boolean test(Object receiver, String property, Object[] args, Object expectedValue)
|
||||
{
|
||||
if(property.equals("enabled")) { //$NON-NLS-1$
|
||||
return fRebuildIndexAction.isEnabled()
|
||||
|| fCreateParserLogAction.isEnabled()
|
||||
|| fFreshenAllFiles.isEnabled()
|
||||
|| fUpdateUnresolvedIncludes.isEnabled()
|
||||
|| fUpdateWithModifiedFiles.isEnabled()
|
||||
|| fFindUnresolvedIncludes.isEnabled();
|
||||
} else if(property.equals("rebuild")) { //$NON-NLS-1$
|
||||
return fRebuildIndexAction.isEnabled();
|
||||
} else if(property.equals("log")) { //$NON-NLS-1$
|
||||
return fCreateParserLogAction.isEnabled();
|
||||
} else if(property.equals("freshen")) { //$NON-NLS-1$
|
||||
return fFreshenAllFiles.isEnabled();
|
||||
} else if(property.equals("updateUnresolvedIncludes")) { //$NON-NLS-1$
|
||||
return fUpdateUnresolvedIncludes.isEnabled();
|
||||
} else if(property.equals("udpateWithModifiedFiles")) { //$NON-NLS-1$
|
||||
return fUpdateWithModifiedFiles.isEnabled();
|
||||
} else if(property.equals("findUnresolvedIncludes")) { //$NON-NLS-1$
|
||||
return fFindUnresolvedIncludes.isEnabled();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private IStructuredSelection getSelectedItem(Object part, Object selection) {
|
||||
if((selection != null) && (selection instanceof IStructuredSelection)) {
|
||||
return (IStructuredSelection)selection;
|
||||
}
|
||||
if((part != null) && (part instanceof IEditorPart)) {
|
||||
Object selItem = null;
|
||||
selItem = ResourceUtil.getResource(((IEditorPart)part).getEditorInput());
|
||||
if(selItem != null) {
|
||||
return new StructuredSelection(selItem);
|
||||
}
|
||||
}
|
||||
return StructuredSelection.EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
|
||||
IStructuredSelection sel = getSelectedItem(part, selection);
|
||||
fRebuildIndexAction.selectionChanged(sel);
|
||||
fCreateParserLogAction.selectionChanged(sel);
|
||||
fFreshenAllFiles.selectionChanged(sel);
|
||||
fUpdateUnresolvedIncludes.selectionChanged(sel);
|
||||
fUpdateWithModifiedFiles.selectionChanged(sel);
|
||||
fFindUnresolvedIncludes.selectionChanged(sel);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowActivated(IWorkbenchWindow window) {
|
||||
ISelectionService selectionService = window.getSelectionService();
|
||||
if (selectionService != null) {
|
||||
ISelection sel = selectionService.getSelection();
|
||||
selectionChanged(null, sel);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowDeactivated(IWorkbenchWindow window) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowClosed(IWorkbenchWindow window) {
|
||||
ISelectionService selectionService = window.getSelectionService();
|
||||
if (selectionService != null) {
|
||||
selectionService.removeSelectionListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void windowOpened(IWorkbenchWindow window) {
|
||||
ISelectionService selectionService = window.getSelectionService();
|
||||
if (selectionService != null) {
|
||||
selectionService.addSelectionListener(this);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -10,108 +10,22 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.actions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.jface.text.ITextSelection;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.ui.IActionDelegate;
|
||||
import org.eclipse.ui.IObjectActionDelegate;
|
||||
import org.eclipse.ui.IWorkbenchPart;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICContainer;
|
||||
import org.eclipse.cdt.core.model.ICElement;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
||||
import org.eclipse.cdt.internal.ui.util.SelectionUtil;
|
||||
|
||||
public class RebuildIndexAction implements IObjectActionDelegate, IWorkbenchWindowActionDelegate {
|
||||
private ISelection fSelection;
|
||||
private boolean isEnabled;
|
||||
|
||||
@Override
|
||||
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(IAction action) {
|
||||
if(!(fSelection instanceof IStructuredSelection) && !(fSelection instanceof ITextSelection)) {
|
||||
return;
|
||||
}
|
||||
ArrayList<ICElement> tuSelection= new ArrayList<ICElement>();
|
||||
if(fSelection instanceof IStructuredSelection) {
|
||||
IStructuredSelection cElements= SelectionConverter.convertSelectionToCElements(fSelection);
|
||||
for (Iterator<?> i= cElements.iterator(); i.hasNext();) {
|
||||
Object o= i.next();
|
||||
if (o instanceof ICProject || o instanceof ICContainer || o instanceof ITranslationUnit) {
|
||||
tuSelection.add((ICElement) o);
|
||||
}
|
||||
}
|
||||
} else if(fSelection instanceof ITextSelection) {
|
||||
IProject project = EditorUtility.getProjectForActiveEditor();
|
||||
if(project != null) {
|
||||
ICProject cproject= CCorePlugin.getDefault().getCoreModel().create(project);
|
||||
if(cproject != null) {
|
||||
tuSelection.add(cproject);
|
||||
}
|
||||
}
|
||||
}
|
||||
ICElement[] tuArray= tuSelection.toArray(new ICElement[tuSelection.size()]);
|
||||
for (ICElement elem : tuArray) {
|
||||
if(elem instanceof ICProject) {
|
||||
CCorePlugin.getIndexManager().reindex((ICProject) elem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IActionDelegate#selectionChanged(IAction, ISelection)
|
||||
*/
|
||||
public void selectionChanged(ISelection selection) {
|
||||
fSelection= selection;
|
||||
isEnabled = false;
|
||||
if(selection == null || selection instanceof ITextSelection) {
|
||||
IProject project = EditorUtility.getProjectForActiveEditor();
|
||||
if(project != null) {
|
||||
isEnabled = CoreModel.hasCNature(project);
|
||||
}
|
||||
} else if(selection instanceof IStructuredSelection) {
|
||||
Object selectedElement = ((IStructuredSelection)selection).getFirstElement();
|
||||
if(selectedElement instanceof IProject) {
|
||||
isEnabled = CoreModel.hasCNature((IProject)selectedElement) && ((IProject)selectedElement).isOpen();
|
||||
} else if(selectedElement instanceof ITranslationUnit) {
|
||||
isEnabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(IWorkbenchWindow window) {
|
||||
}
|
||||
public class RebuildIndexAction extends AbstractUpdateIndexAction {
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} if the action is enabled or {@code false} otherwise.
|
||||
*/
|
||||
public boolean isEnabled() {
|
||||
selectionChanged(SelectionUtil.getActiveSelection());
|
||||
return isEnabled;
|
||||
protected void doRun(ICProject[] projects) {
|
||||
for (ICProject proj : projects) {
|
||||
if(proj != null) {
|
||||
CCorePlugin.getIndexManager().reindex(proj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectionChanged(IAction action, ISelection selection) {
|
||||
selectionChanged(selection);
|
||||
protected int getUpdateOptions() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,12 +10,6 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.actions;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.ui.IWorkbenchPart;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
|
||||
/**
|
||||
* Handler for {@link org.eclipse.cdt.internal.ui.actions.RebuildIndexAction}
|
||||
|
@ -23,17 +17,12 @@ import org.eclipse.ui.handlers.HandlerUtil;
|
|||
* @noextend This class is not intended to be subclassed by clients.
|
||||
* @noinstantiate This class is not intended to be instantiated by clients.
|
||||
*/
|
||||
public class RebuildIndexHandler extends AbstractHandler {
|
||||
public class RebuildIndexHandler extends AbstractUpdateIndexHandler {
|
||||
|
||||
private final RebuildIndexAction rebuildIndexAction = new RebuildIndexAction();
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
ISelection selection = HandlerUtil.getCurrentSelection(event);
|
||||
IWorkbenchPart part = HandlerUtil.getActivePart(event);
|
||||
rebuildIndexAction.setActivePart(null, part);
|
||||
rebuildIndexAction.selectionChanged(null, selection);
|
||||
rebuildIndexAction.run(null);
|
||||
return null;
|
||||
public AbstractUpdateIndexAction getAction() {
|
||||
return rebuildIndexAction;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,12 +10,6 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.actions;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.ui.IWorkbenchPart;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
|
||||
/**
|
||||
* Handler for {@link org.eclipse.cdt.internal.ui.actions.UpdateIndexWithModifiedFilesAction}
|
||||
|
@ -23,17 +17,12 @@ import org.eclipse.ui.handlers.HandlerUtil;
|
|||
* @noextend This class is not intended to be subclassed by clients.
|
||||
* @noinstantiate This class is not intended to be instantiated by clients.
|
||||
*/
|
||||
public class UpdateIndexWithModifiedFilesHandler extends AbstractHandler {
|
||||
public class UpdateIndexWithModifiedFilesHandler extends AbstractUpdateIndexHandler {
|
||||
|
||||
private final UpdateIndexWithModifiedFilesAction updateAction = new UpdateIndexWithModifiedFilesAction();
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
ISelection selection = HandlerUtil.getCurrentSelection(event);
|
||||
IWorkbenchPart part = HandlerUtil.getActivePart(event);
|
||||
updateAction.setActivePart(null, part);
|
||||
updateAction.selectionChanged(null, selection);
|
||||
updateAction.run(null);
|
||||
return null;
|
||||
public AbstractUpdateIndexAction getAction() {
|
||||
return updateAction;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,12 +10,6 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.actions;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.ui.IWorkbenchPart;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
|
||||
/**
|
||||
* Handler for {@link org.eclipse.cdt.internal.ui.actions.UpdateIndexWithModifiedFilesAction}
|
||||
|
@ -23,17 +17,12 @@ import org.eclipse.ui.handlers.HandlerUtil;
|
|||
* @noextend This class is not intended to be subclassed by clients.
|
||||
* @noinstantiate This class is not intended to be instantiated by clients.
|
||||
*/
|
||||
public class UpdateUnresolvedIncludesHandler extends AbstractHandler {
|
||||
public class UpdateUnresolvedIncludesHandler extends AbstractUpdateIndexHandler {
|
||||
|
||||
private final UpdateUnresolvedIncludesAction udpateAction = new UpdateUnresolvedIncludesAction();
|
||||
private final UpdateUnresolvedIncludesAction updateAction = new UpdateUnresolvedIncludesAction();
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
ISelection selection = HandlerUtil.getCurrentSelection(event);
|
||||
IWorkbenchPart part = HandlerUtil.getActivePart(event);
|
||||
udpateAction.setActivePart(null, part);
|
||||
udpateAction.selectionChanged(null, selection);
|
||||
udpateAction.run(null);
|
||||
return null;
|
||||
public AbstractUpdateIndexAction getAction() {
|
||||
return updateAction;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,12 +10,8 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.search.actions;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.ui.IWorkbenchPart;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
import org.eclipse.cdt.internal.ui.actions.AbstractUpdateIndexAction;
|
||||
import org.eclipse.cdt.internal.ui.actions.AbstractUpdateIndexHandler;
|
||||
|
||||
/**
|
||||
* Handler for {@link org.eclipse.cdt.internal.ui.search.actions.FindUnresolvedIncludesProjectAction}
|
||||
|
@ -23,17 +19,12 @@ import org.eclipse.ui.handlers.HandlerUtil;
|
|||
* @noextend This class is not intended to be subclassed by clients.
|
||||
* @noinstantiate This class is not intended to be instantiated by clients.
|
||||
*/
|
||||
public class FindUnresolvedIncludesHandler extends AbstractHandler {
|
||||
public class FindUnresolvedIncludesHandler extends AbstractUpdateIndexHandler {
|
||||
|
||||
private final FindUnresolvedIncludesProjectAction rebuildIndexAction= new FindUnresolvedIncludesProjectAction();
|
||||
private final FindUnresolvedIncludesProjectAction findUnresolvedIncludesAction = new FindUnresolvedIncludesProjectAction();
|
||||
|
||||
@Override
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
ISelection selection = HandlerUtil.getCurrentSelection(event);
|
||||
IWorkbenchPart part = HandlerUtil.getActivePart(event);
|
||||
rebuildIndexAction.setActivePart(null, part);
|
||||
rebuildIndexAction.selectionChanged(null, selection);
|
||||
rebuildIndexAction.run(null);
|
||||
return null;
|
||||
public AbstractUpdateIndexAction getAction() {
|
||||
return findUnresolvedIncludesAction;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,74 +10,37 @@
|
|||
*******************************************************************************/
|
||||
package org.eclipse.cdt.internal.ui.search.actions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.jface.action.IAction;
|
||||
import org.eclipse.jface.text.ITextSelection;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.search.ui.ISearchQuery;
|
||||
import org.eclipse.search.ui.NewSearchUI;
|
||||
import org.eclipse.ui.IActionDelegate;
|
||||
import org.eclipse.ui.IObjectActionDelegate;
|
||||
import org.eclipse.ui.IWorkbenchPart;
|
||||
import org.eclipse.ui.IWorkbenchSite;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
|
||||
|
||||
import org.eclipse.cdt.core.CCorePlugin;
|
||||
import org.eclipse.cdt.core.model.CoreModel;
|
||||
import org.eclipse.cdt.core.model.ICProject;
|
||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.actions.SelectionConverter;
|
||||
import org.eclipse.cdt.internal.ui.actions.AbstractUpdateIndexAction;
|
||||
import org.eclipse.cdt.internal.ui.search.CSearchMessages;
|
||||
import org.eclipse.cdt.internal.ui.search.CSearchUnresolvedIncludesQuery;
|
||||
import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
||||
import org.eclipse.cdt.internal.ui.util.SelectionUtil;
|
||||
import org.eclipse.cdt.internal.ui.util.StatusLineHandler;
|
||||
|
||||
/**
|
||||
* Searches projects for unresolved includes.
|
||||
* Could be extended to work on resource selections.
|
||||
*/
|
||||
public class FindUnresolvedIncludesProjectAction implements IObjectActionDelegate, IWorkbenchWindowActionDelegate {
|
||||
private ISelection fSelection;
|
||||
public class FindUnresolvedIncludesProjectAction extends AbstractUpdateIndexAction {
|
||||
private IWorkbenchSite fSite;
|
||||
private boolean isEnabled;
|
||||
|
||||
public FindUnresolvedIncludesProjectAction() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void run(IAction action) {
|
||||
List<ICProject> projects = new ArrayList<ICProject>();
|
||||
if(fSelection instanceof IStructuredSelection) {
|
||||
IStructuredSelection cElements = SelectionConverter.convertSelectionToCElements(fSelection);
|
||||
for (Iterator<?> i = cElements.iterator(); i.hasNext();) {
|
||||
Object o= i.next();
|
||||
if (o instanceof ICProject) {
|
||||
projects.add((ICProject) o);
|
||||
}
|
||||
}
|
||||
} else if(fSelection instanceof ITextSelection) {
|
||||
IProject project = EditorUtility.getProjectForActiveEditor();
|
||||
if(project != null) {
|
||||
ICProject cproject = CCorePlugin.getDefault().getCoreModel().create(project);
|
||||
if(cproject != null) {
|
||||
projects.add(cproject);
|
||||
}
|
||||
}
|
||||
}
|
||||
if (projects.isEmpty()) {
|
||||
protected void doRun(ICProject[] projects) {
|
||||
if (projects.length == 0) {
|
||||
StatusLineHandler.showStatusLineMessage(fSite, CSearchMessages.CSearchOperation_operationUnavailable_message);
|
||||
return;
|
||||
}
|
||||
|
||||
ISearchQuery searchJob= new CSearchUnresolvedIncludesQuery(projects.toArray(new ICProject[projects.size()]));
|
||||
ISearchQuery searchJob= new CSearchUnresolvedIncludesQuery(projects);
|
||||
|
||||
StatusLineHandler.clearStatusLine(fSite);
|
||||
NewSearchUI.activateSearchResultView();
|
||||
|
@ -89,45 +52,8 @@ public class FindUnresolvedIncludesProjectAction implements IObjectActionDelegat
|
|||
fSite= targetPart.getSite();
|
||||
}
|
||||
|
||||
/**
|
||||
* @see IActionDelegate#selectionChanged(IAction, ISelection)
|
||||
*/
|
||||
public void selectionChanged(ISelection selection) {
|
||||
fSelection= selection;
|
||||
isEnabled = false;
|
||||
if(selection == null || selection instanceof ITextSelection) {
|
||||
IProject project = EditorUtility.getProjectForActiveEditor();
|
||||
if(project != null) {
|
||||
isEnabled = CoreModel.hasCNature(project);
|
||||
}
|
||||
} else if(selection instanceof IStructuredSelection) {
|
||||
Object selectedElement = ((IStructuredSelection)selection).getFirstElement();
|
||||
if(selectedElement instanceof IProject) {
|
||||
isEnabled = CoreModel.hasCNature((IProject)selectedElement) && ((IProject)selectedElement).isOpen();
|
||||
} else if(selectedElement instanceof ITranslationUnit) {
|
||||
isEnabled = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(IWorkbenchWindow window) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @return {@code true} if the action is enabled or {@code false} otherwise.
|
||||
*/
|
||||
public boolean isEnabled() {
|
||||
selectionChanged(SelectionUtil.getActiveSelection());
|
||||
return isEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void selectionChanged(IAction action, ISelection selection) {
|
||||
selectionChanged(selection);
|
||||
protected int getUpdateOptions() {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue