mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 10:16:03 +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>
|
</visibility>
|
||||||
<action
|
<action
|
||||||
class="org.eclipse.cdt.internal.ui.actions.UpdateUnresolvedIncludesAction"
|
class="org.eclipse.cdt.internal.ui.actions.UpdateUnresolvedIncludesAction"
|
||||||
|
definitionId="org.eclipse.cdt.ui.menu.updateUnresolvedIncludes"
|
||||||
id="org.eclipse.cdt.ui.updateUnresolvedIncludesAction"
|
id="org.eclipse.cdt.ui.updateUnresolvedIncludesAction"
|
||||||
label="%UpdateUnresolvedIncludes.name"
|
label="%UpdateUnresolvedIncludes.name"
|
||||||
menubarPath="org.eclipse.cdt.ui.indexmenu/update"/>
|
menubarPath="org.eclipse.cdt.ui.indexmenu/update"/>
|
||||||
<action
|
<action
|
||||||
class="org.eclipse.cdt.internal.ui.actions.UpdateIndexWithModifiedFilesAction"
|
class="org.eclipse.cdt.internal.ui.actions.UpdateIndexWithModifiedFilesAction"
|
||||||
|
definitionId="org.eclipse.cdt.ui.menu.updateWithModifiedFiles"
|
||||||
id="org.eclipse.cdt.ui.syncIndexWithDiskAction"
|
id="org.eclipse.cdt.ui.syncIndexWithDiskAction"
|
||||||
label="%SyncIndex.name"
|
label="%SyncIndex.name"
|
||||||
menubarPath="org.eclipse.cdt.ui.indexmenu/update"/>
|
menubarPath="org.eclipse.cdt.ui.indexmenu/update"/>
|
||||||
<action
|
<action
|
||||||
class="org.eclipse.cdt.internal.ui.actions.FreshenIndexAction"
|
class="org.eclipse.cdt.internal.ui.actions.FreshenIndexAction"
|
||||||
|
definitionId="org.eclipse.cdt.ui.menu.freshenAllFiles"
|
||||||
id="org.eclipse.cdt.ui.updateIndexAction"
|
id="org.eclipse.cdt.ui.updateIndexAction"
|
||||||
label="%FreshenIndex.name"
|
label="%FreshenIndex.name"
|
||||||
menubarPath="org.eclipse.cdt.ui.indexmenu/update"/>
|
menubarPath="org.eclipse.cdt.ui.indexmenu/update"/>
|
||||||
|
@ -1438,6 +1441,7 @@
|
||||||
</visibility>
|
</visibility>
|
||||||
<action
|
<action
|
||||||
class="org.eclipse.cdt.internal.ui.actions.CreateParserLogAction"
|
class="org.eclipse.cdt.internal.ui.actions.CreateParserLogAction"
|
||||||
|
definitionId="org.eclipse.cdt.ui.menu.createParserLog"
|
||||||
id="org.eclipse.cdt.ui.parserLogAction"
|
id="org.eclipse.cdt.ui.parserLogAction"
|
||||||
label="%CreateParserLog.name"
|
label="%CreateParserLog.name"
|
||||||
menubarPath="org.eclipse.cdt.ui.indexmenu/log"/>
|
menubarPath="org.eclipse.cdt.ui.indexmenu/log"/>
|
||||||
|
@ -1456,11 +1460,13 @@
|
||||||
objectClass="org.eclipse.cdt.core.model.ICProject">
|
objectClass="org.eclipse.cdt.core.model.ICProject">
|
||||||
<action
|
<action
|
||||||
class="org.eclipse.cdt.internal.ui.actions.RebuildIndexAction"
|
class="org.eclipse.cdt.internal.ui.actions.RebuildIndexAction"
|
||||||
|
definitionId="org.eclipse.cdt.ui.menu.rebuildIndex"
|
||||||
id="org.eclipse.cdt.ui.rebuildIndexAction"
|
id="org.eclipse.cdt.ui.rebuildIndexAction"
|
||||||
label="%RebuildIndex.name"
|
label="%RebuildIndex.name"
|
||||||
menubarPath="org.eclipse.cdt.ui.indexmenu/rebuild"/>
|
menubarPath="org.eclipse.cdt.ui.indexmenu/rebuild"/>
|
||||||
<action
|
<action
|
||||||
class="org.eclipse.cdt.internal.ui.search.actions.FindUnresolvedIncludesProjectAction"
|
class="org.eclipse.cdt.internal.ui.search.actions.FindUnresolvedIncludesProjectAction"
|
||||||
|
definitionId="org.eclipse.cdt.ui.menu.findUnresolvedIncludes"
|
||||||
id="org.eclipse.cdt.ui.searchUnresolvedIncludes"
|
id="org.eclipse.cdt.ui.searchUnresolvedIncludes"
|
||||||
label="%SearchUnresolvedIncludes.name"
|
label="%SearchUnresolvedIncludes.name"
|
||||||
menubarPath="org.eclipse.cdt.ui.indexmenu/search"/>
|
menubarPath="org.eclipse.cdt.ui.indexmenu/search"/>
|
||||||
|
@ -1485,26 +1491,31 @@
|
||||||
</visibility>
|
</visibility>
|
||||||
<action
|
<action
|
||||||
class="org.eclipse.cdt.internal.ui.actions.UpdateUnresolvedIncludesAction"
|
class="org.eclipse.cdt.internal.ui.actions.UpdateUnresolvedIncludesAction"
|
||||||
|
definitionId="org.eclipse.cdt.ui.menu.updateUnresolvedIncludes"
|
||||||
id="org.eclipse.cdt.ui.updateUnresolvedIncludesAction"
|
id="org.eclipse.cdt.ui.updateUnresolvedIncludesAction"
|
||||||
label="%UpdateUnresolvedIncludes.name"
|
label="%UpdateUnresolvedIncludes.name"
|
||||||
menubarPath="org.eclipse.cdt.ui.indexmenu/update"/>
|
menubarPath="org.eclipse.cdt.ui.indexmenu/update"/>
|
||||||
<action
|
<action
|
||||||
class="org.eclipse.cdt.internal.ui.actions.UpdateIndexWithModifiedFilesAction"
|
class="org.eclipse.cdt.internal.ui.actions.UpdateIndexWithModifiedFilesAction"
|
||||||
|
definitionId="org.eclipse.cdt.ui.menu.updateWithModifiedFiles"
|
||||||
id="org.eclipse.cdt.ui.syncIndexWithDiskAction"
|
id="org.eclipse.cdt.ui.syncIndexWithDiskAction"
|
||||||
label="%SyncIndex.name"
|
label="%SyncIndex.name"
|
||||||
menubarPath="org.eclipse.cdt.ui.indexmenu/update"/>
|
menubarPath="org.eclipse.cdt.ui.indexmenu/update"/>
|
||||||
<action
|
<action
|
||||||
class="org.eclipse.cdt.internal.ui.actions.FreshenIndexAction"
|
class="org.eclipse.cdt.internal.ui.actions.FreshenIndexAction"
|
||||||
|
definitionId="org.eclipse.cdt.ui.menu.freshenAllFiles"
|
||||||
id="org.eclipse.cdt.ui.updateIndexAction"
|
id="org.eclipse.cdt.ui.updateIndexAction"
|
||||||
label="%FreshenIndex.name"
|
label="%FreshenIndex.name"
|
||||||
menubarPath="org.eclipse.cdt.ui.indexmenu/update"/>
|
menubarPath="org.eclipse.cdt.ui.indexmenu/update"/>
|
||||||
<action
|
<action
|
||||||
class="org.eclipse.cdt.internal.ui.actions.RebuildIndexAction"
|
class="org.eclipse.cdt.internal.ui.actions.RebuildIndexAction"
|
||||||
|
definitionId="org.eclipse.cdt.ui.menu.rebuildIndex"
|
||||||
id="org.eclipse.cdt.ui.rebuildIndexAction"
|
id="org.eclipse.cdt.ui.rebuildIndexAction"
|
||||||
label="%RebuildIndex.name"
|
label="%RebuildIndex.name"
|
||||||
menubarPath="org.eclipse.cdt.ui.indexmenu/rebuild"/>
|
menubarPath="org.eclipse.cdt.ui.indexmenu/rebuild"/>
|
||||||
<action
|
<action
|
||||||
class="org.eclipse.cdt.internal.ui.search.actions.FindUnresolvedIncludesProjectAction"
|
class="org.eclipse.cdt.internal.ui.search.actions.FindUnresolvedIncludesProjectAction"
|
||||||
|
definitionId="org.eclipse.cdt.ui.menu.findUnresolvedIncludes"
|
||||||
id="org.eclipse.cdt.ui.searchUnresolvedIncludes"
|
id="org.eclipse.cdt.ui.searchUnresolvedIncludes"
|
||||||
label="%SearchUnresolvedIncludes.name"
|
label="%SearchUnresolvedIncludes.name"
|
||||||
menubarPath="org.eclipse.cdt.ui.indexmenu/search"/>
|
menubarPath="org.eclipse.cdt.ui.indexmenu/search"/>
|
||||||
|
@ -4491,44 +4502,26 @@
|
||||||
<handler
|
<handler
|
||||||
class="org.eclipse.cdt.internal.ui.actions.RebuildIndexHandler"
|
class="org.eclipse.cdt.internal.ui.actions.RebuildIndexHandler"
|
||||||
commandId="org.eclipse.cdt.ui.menu.rebuildIndex">
|
commandId="org.eclipse.cdt.ui.menu.rebuildIndex">
|
||||||
<enabledWhen>
|
|
||||||
<test property="org.eclipse.cdt.internal.ui.index.rebuild" value="enabled"/>
|
|
||||||
</enabledWhen>
|
|
||||||
</handler>
|
</handler>
|
||||||
<handler
|
<handler
|
||||||
class="org.eclipse.cdt.internal.ui.actions.FreshenAllFilesHandler"
|
class="org.eclipse.cdt.internal.ui.actions.FreshenAllFilesHandler"
|
||||||
commandId="org.eclipse.cdt.ui.menu.freshenAllFiles">
|
commandId="org.eclipse.cdt.ui.menu.freshenAllFiles">
|
||||||
<enabledWhen>
|
|
||||||
<test property="org.eclipse.cdt.internal.ui.index.freshen" value="enabled"/>
|
|
||||||
</enabledWhen>
|
|
||||||
</handler>
|
</handler>
|
||||||
<handler
|
<handler
|
||||||
class="org.eclipse.cdt.internal.ui.actions.UpdateIndexWithModifiedFilesHandler"
|
class="org.eclipse.cdt.internal.ui.actions.UpdateIndexWithModifiedFilesHandler"
|
||||||
commandId="org.eclipse.cdt.ui.menu.updateWithModifiedFiles">
|
commandId="org.eclipse.cdt.ui.menu.updateWithModifiedFiles">
|
||||||
<enabledWhen>
|
|
||||||
<test property="org.eclipse.cdt.internal.ui.index.udpateWithModifiedFiles" value="enabled"/>
|
|
||||||
</enabledWhen>
|
|
||||||
</handler>
|
</handler>
|
||||||
<handler
|
<handler
|
||||||
class="org.eclipse.cdt.internal.ui.actions.UpdateUnresolvedIncludesHandler"
|
class="org.eclipse.cdt.internal.ui.actions.UpdateUnresolvedIncludesHandler"
|
||||||
commandId="org.eclipse.cdt.ui.menu.updateUnresolvedIncludes">
|
commandId="org.eclipse.cdt.ui.menu.updateUnresolvedIncludes">
|
||||||
<enabledWhen>
|
|
||||||
<test property="org.eclipse.cdt.internal.ui.index.updateUnresolvedIncludes" value="enabled"/>
|
|
||||||
</enabledWhen>
|
|
||||||
</handler>
|
</handler>
|
||||||
<handler
|
<handler
|
||||||
class="org.eclipse.cdt.internal.ui.search.actions.FindUnresolvedIncludesHandler"
|
class="org.eclipse.cdt.internal.ui.search.actions.FindUnresolvedIncludesHandler"
|
||||||
commandId="org.eclipse.cdt.ui.menu.findUnresolvedIncludes">
|
commandId="org.eclipse.cdt.ui.menu.findUnresolvedIncludes">
|
||||||
<enabledWhen>
|
|
||||||
<test property="org.eclipse.cdt.internal.ui.index.findUnresolvedIncludes" value="enabled"/>
|
|
||||||
</enabledWhen>
|
|
||||||
</handler>
|
</handler>
|
||||||
<handler
|
<handler
|
||||||
class="org.eclipse.cdt.internal.ui.actions.CreateParserLogHandler"
|
class="org.eclipse.cdt.internal.ui.actions.CreateParserLogHandler"
|
||||||
commandId="org.eclipse.cdt.ui.menu.createParserLog">
|
commandId="org.eclipse.cdt.ui.menu.createParserLog">
|
||||||
<enabledWhen>
|
|
||||||
<test property="org.eclipse.cdt.internal.ui.index.log" value="enabled"/>
|
|
||||||
</enabledWhen>
|
|
||||||
</handler>
|
</handler>
|
||||||
</extension>
|
</extension>
|
||||||
<extension
|
<extension
|
||||||
|
@ -4538,7 +4531,27 @@
|
||||||
<menu
|
<menu
|
||||||
label="%C.Cpp.Index.menu">
|
label="%C.Cpp.Index.menu">
|
||||||
<visibleWhen>
|
<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>
|
</visibleWhen>
|
||||||
<separator
|
<separator
|
||||||
name="rebuild"
|
name="rebuild"
|
||||||
|
@ -4583,16 +4596,6 @@
|
||||||
</menu>
|
</menu>
|
||||||
</menuContribution>
|
</menuContribution>
|
||||||
</extension>
|
</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
|
<extension
|
||||||
point="org.eclipse.ui.commands">
|
point="org.eclipse.ui.commands">
|
||||||
<command
|
<command
|
||||||
|
|
|
@ -15,32 +15,25 @@ import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.jface.action.IAction;
|
import org.eclipse.jface.action.IAction;
|
||||||
import org.eclipse.jface.text.ITextSelection;
|
import org.eclipse.jface.text.ITextSelection;
|
||||||
import org.eclipse.jface.viewers.ISelection;
|
import org.eclipse.jface.viewers.ISelection;
|
||||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||||
import org.eclipse.ui.IActionDelegate;
|
|
||||||
import org.eclipse.ui.IObjectActionDelegate;
|
import org.eclipse.ui.IObjectActionDelegate;
|
||||||
import org.eclipse.ui.IWorkbenchPart;
|
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.CCorePlugin;
|
||||||
import org.eclipse.cdt.core.index.IIndexManager;
|
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.ICElement;
|
||||||
import org.eclipse.cdt.core.model.ICProject;
|
import org.eclipse.cdt.core.model.ICProject;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
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 ISelection fSelection;
|
||||||
private boolean isEnabled;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
|
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
|
||||||
|
@ -51,28 +44,13 @@ public abstract class AbstractUpdateIndexAction implements IObjectActionDelegate
|
||||||
if(!(fSelection instanceof IStructuredSelection) && !(fSelection instanceof ITextSelection)) {
|
if(!(fSelection instanceof IStructuredSelection) && !(fSelection instanceof ITextSelection)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
ICProject[] projects = getSelectedCProjects();
|
||||||
|
doRun(projects);
|
||||||
|
}
|
||||||
|
|
||||||
ArrayList<ICElement> tuSelection= new ArrayList<ICElement>();
|
protected void doRun(ICProject[] projects) {
|
||||||
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 {
|
try {
|
||||||
CCorePlugin.getIndexManager().update(tuArray, getUpdateOptions());
|
CCorePlugin.getIndexManager().update(projects, getUpdateOptions());
|
||||||
} catch (CoreException e) {
|
} catch (CoreException e) {
|
||||||
CUIPlugin.log(e);
|
CUIPlugin.log(e);
|
||||||
}
|
}
|
||||||
|
@ -85,46 +63,39 @@ public abstract class AbstractUpdateIndexAction implements IObjectActionDelegate
|
||||||
*/
|
*/
|
||||||
abstract protected int getUpdateOptions();
|
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
|
@Override
|
||||||
public void selectionChanged(IAction action, ISelection selection) {
|
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.osgi.util.NLS;
|
||||||
import org.eclipse.swt.SWT;
|
import org.eclipse.swt.SWT;
|
||||||
import org.eclipse.swt.widgets.FileDialog;
|
import org.eclipse.swt.widgets.FileDialog;
|
||||||
import org.eclipse.ui.IActionDelegate;
|
|
||||||
import org.eclipse.ui.IEditorInput;
|
import org.eclipse.ui.IEditorInput;
|
||||||
import org.eclipse.ui.IEditorPart;
|
import org.eclipse.ui.IEditorPart;
|
||||||
import org.eclipse.ui.IEditorReference;
|
import org.eclipse.ui.IEditorReference;
|
||||||
|
@ -51,7 +50,6 @@ import org.eclipse.ui.IWorkbenchPage;
|
||||||
import org.eclipse.ui.IWorkbenchPart;
|
import org.eclipse.ui.IWorkbenchPart;
|
||||||
import org.eclipse.ui.IWorkbenchPartSite;
|
import org.eclipse.ui.IWorkbenchPartSite;
|
||||||
import org.eclipse.ui.IWorkbenchWindow;
|
import org.eclipse.ui.IWorkbenchWindow;
|
||||||
import org.eclipse.ui.IWorkbenchWindowActionDelegate;
|
|
||||||
import org.eclipse.ui.PlatformUI;
|
import org.eclipse.ui.PlatformUI;
|
||||||
import org.eclipse.ui.ide.IDE;
|
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.ASTProvider;
|
||||||
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
import org.eclipse.cdt.internal.ui.editor.CEditor;
|
||||||
import org.eclipse.cdt.internal.ui.util.SelectionUtil;
|
|
||||||
|
|
||||||
@SuppressWarnings("nls")
|
@SuppressWarnings("nls")
|
||||||
public class CreateParserLogAction implements IObjectActionDelegate, IWorkbenchWindowActionDelegate {
|
public class CreateParserLogAction implements IObjectActionDelegate {
|
||||||
private static final String INDENT = " ";
|
private static final String INDENT = " ";
|
||||||
private boolean isEnabled;
|
|
||||||
|
|
||||||
private static final class MyVisitor extends ASTVisitor {
|
private static final class MyVisitor extends ASTVisitor {
|
||||||
List<IASTProblem> fProblems= new ArrayList<IASTProblem>();
|
List<IASTProblem> fProblems= new ArrayList<IASTProblem>();
|
||||||
|
@ -168,21 +164,11 @@ public class CreateParserLogAction implements IObjectActionDelegate, IWorkbenchW
|
||||||
workingCopies.add((IWorkingCopy) inputElement);
|
workingCopies.add((IWorkingCopy) inputElement);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ArrayList<ITranslationUnit> tuSelection= new ArrayList<ITranslationUnit>();
|
|
||||||
String title = ActionMessages.CreateParserLogAction_title;
|
ArrayList<ITranslationUnit> tuSelection = getSelectedTranslationUnits();
|
||||||
if(fSelection instanceof IStructuredSelection) {
|
for(int i = 0; i < tuSelection.size(); i++) {
|
||||||
IStructuredSelection cElements= SelectionConverter.convertSelectionToCElements(fSelection);
|
if(!(tuSelection.get(i) instanceof IWorkingCopy)) {
|
||||||
Iterator<?> i= cElements.iterator();
|
tuSelection.set(i, convertToWorkingCopy(tuSelection.get(i), workingCopies));
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,6 +177,7 @@ public class CreateParserLogAction implements IObjectActionDelegate, IWorkbenchW
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
FileDialog dlg= new FileDialog(fSite.getShell(), SWT.SAVE);
|
FileDialog dlg= new FileDialog(fSite.getShell(), SWT.SAVE);
|
||||||
|
String title = ActionMessages.CreateParserLogAction_title;
|
||||||
dlg.setText(title);
|
dlg.setText(title);
|
||||||
dlg.setFilterExtensions(new String[]{"*.log"});
|
dlg.setFilterExtensions(new String[]{"*.log"});
|
||||||
String path= null;
|
String path= null;
|
||||||
|
@ -497,26 +484,12 @@ public class CreateParserLogAction implements IObjectActionDelegate, IWorkbenchW
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
@Override
|
||||||
* @see IActionDelegate#selectionChanged(IAction, ISelection)
|
public void selectionChanged(IAction action, ISelection selection) {
|
||||||
*/
|
fSelection = selection;
|
||||||
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() {
|
public IWorkingCopy getTranslationUnitForSelectedEditorInput() {
|
||||||
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
|
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
|
||||||
if(window != null) {
|
if(window != null) {
|
||||||
IWorkbenchPart workbenchPart = window.getPartService().getActivePart();
|
IWorkbenchPart workbenchPart = window.getPartService().getActivePart();
|
||||||
|
@ -531,24 +504,29 @@ public class CreateParserLogAction implements IObjectActionDelegate, IWorkbenchW
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public boolean isEnabledFor(ISelection selection) {
|
||||||
public void init(IWorkbenchWindow window) {
|
selectionChanged(null, selection);
|
||||||
|
ArrayList<ITranslationUnit> tus = getSelectedTranslationUnits();
|
||||||
|
return tus.size() > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
private ArrayList<ITranslationUnit> getSelectedTranslationUnits() {
|
||||||
public void dispose() {
|
ArrayList<ITranslationUnit> tuSelection= new ArrayList<ITranslationUnit>();
|
||||||
}
|
if(fSelection instanceof IStructuredSelection) {
|
||||||
|
IStructuredSelection cElements= SelectionConverter.convertSelectionToCElements(fSelection);
|
||||||
/**
|
Iterator<?> i= cElements.iterator();
|
||||||
* @return {@code true} if the action is enabled or {@code false} otherwise.
|
while (i.hasNext()) {
|
||||||
*/
|
Object o= i.next();
|
||||||
public boolean isEnabled() {
|
if (o instanceof ITranslationUnit) {
|
||||||
selectionChanged(SelectionUtil.getActiveSelection());
|
tuSelection.add((ITranslationUnit)o);
|
||||||
return isEnabled;
|
}
|
||||||
}
|
}
|
||||||
|
} else if(fSelection == null || fSelection instanceof ITextSelection) {
|
||||||
@Override
|
IWorkingCopy tu = getTranslationUnitForSelectedEditorInput();
|
||||||
public void selectionChanged(IAction action, ISelection selection) {
|
if(tu != null) {
|
||||||
selectionChanged(selection);
|
tuSelection.add(tu);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return tuSelection;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,8 @@ import org.eclipse.jface.viewers.ISelection;
|
||||||
import org.eclipse.ui.IWorkbenchPart;
|
import org.eclipse.ui.IWorkbenchPart;
|
||||||
import org.eclipse.ui.handlers.HandlerUtil;
|
import org.eclipse.ui.handlers.HandlerUtil;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.ui.util.SelectionUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handler for {@link org.eclipse.cdt.internal.ui.actions.CreateParserLogAction}
|
* Handler for {@link org.eclipse.cdt.internal.ui.actions.CreateParserLogAction}
|
||||||
*
|
*
|
||||||
|
@ -36,4 +38,13 @@ public class CreateParserLogHandler extends AbstractHandler {
|
||||||
createParserLogAction.run(null);
|
createParserLogAction.run(null);
|
||||||
return 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;
|
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}
|
* 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.
|
* @noextend This class is not intended to be subclassed by clients.
|
||||||
* @noinstantiate This class is not intended to be instantiated 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();
|
private final FreshenIndexAction freshenIndexAction = new FreshenIndexAction();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
public AbstractUpdateIndexAction getAction() {
|
||||||
ISelection selection = HandlerUtil.getCurrentSelection(event);
|
return freshenIndexAction;
|
||||||
IWorkbenchPart part = HandlerUtil.getActivePart(event);
|
|
||||||
freshenIndexAction.setActivePart(null, part);
|
|
||||||
freshenIndexAction.selectionChanged(null, selection);
|
|
||||||
freshenIndexAction.run(null);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,118 +0,0 @@
|
||||||
/*******************************************************************************
|
|
||||||
* Copyright (c) 2013 Wind River Systems, Inc. and others.
|
|
||||||
* All rights reserved. This program and the accompanying materials
|
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
|
||||||
* which accompanies this distribution, and is available at
|
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
|
||||||
*
|
|
||||||
* Contributors:
|
|
||||||
* Wind River Systems - Initial API and implementation
|
|
||||||
*******************************************************************************/
|
|
||||||
package org.eclipse.cdt.internal.ui.actions;
|
|
||||||
|
|
||||||
import org.eclipse.core.expressions.PropertyTester;
|
|
||||||
import org.eclipse.jface.viewers.ISelection;
|
|
||||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
|
||||||
import org.eclipse.jface.viewers.StructuredSelection;
|
|
||||||
import org.eclipse.ui.IEditorPart;
|
|
||||||
import org.eclipse.ui.ISelectionListener;
|
|
||||||
import org.eclipse.ui.ISelectionService;
|
|
||||||
import org.eclipse.ui.IWindowListener;
|
|
||||||
import org.eclipse.ui.IWorkbenchPart;
|
|
||||||
import org.eclipse.ui.IWorkbenchWindow;
|
|
||||||
import org.eclipse.ui.ide.ResourceUtil;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.search.actions.FindUnresolvedIncludesProjectAction;
|
|
||||||
|
|
||||||
public class IndexActionsEnabledTester extends PropertyTester implements ISelectionListener, IWindowListener {
|
|
||||||
|
|
||||||
private static RebuildIndexAction fRebuildIndexAction = new RebuildIndexAction();
|
|
||||||
private static CreateParserLogAction fCreateParserLogAction = new CreateParserLogAction();
|
|
||||||
private static FreshenIndexAction fFreshenAllFiles = new FreshenIndexAction();
|
|
||||||
private static UpdateUnresolvedIncludesAction fUpdateUnresolvedIncludes = new UpdateUnresolvedIncludesAction();
|
|
||||||
private static UpdateIndexWithModifiedFilesAction fUpdateWithModifiedFiles = new UpdateIndexWithModifiedFilesAction();
|
|
||||||
private static FindUnresolvedIncludesProjectAction fFindUnresolvedIncludes = new FindUnresolvedIncludesProjectAction();
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.core.expressions.IPropertyTester#test(java.lang.Object, java.lang.String, java.lang.Object[], java.lang.Object)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean test(Object receiver, String property, Object[] args, Object expectedValue)
|
|
||||||
{
|
|
||||||
if(property.equals("enabled")) { //$NON-NLS-1$
|
|
||||||
return fRebuildIndexAction.isEnabled()
|
|
||||||
|| fCreateParserLogAction.isEnabled()
|
|
||||||
|| fFreshenAllFiles.isEnabled()
|
|
||||||
|| fUpdateUnresolvedIncludes.isEnabled()
|
|
||||||
|| fUpdateWithModifiedFiles.isEnabled()
|
|
||||||
|| fFindUnresolvedIncludes.isEnabled();
|
|
||||||
} else if(property.equals("rebuild")) { //$NON-NLS-1$
|
|
||||||
return fRebuildIndexAction.isEnabled();
|
|
||||||
} else if(property.equals("log")) { //$NON-NLS-1$
|
|
||||||
return fCreateParserLogAction.isEnabled();
|
|
||||||
} else if(property.equals("freshen")) { //$NON-NLS-1$
|
|
||||||
return fFreshenAllFiles.isEnabled();
|
|
||||||
} else if(property.equals("updateUnresolvedIncludes")) { //$NON-NLS-1$
|
|
||||||
return fUpdateUnresolvedIncludes.isEnabled();
|
|
||||||
} else if(property.equals("udpateWithModifiedFiles")) { //$NON-NLS-1$
|
|
||||||
return fUpdateWithModifiedFiles.isEnabled();
|
|
||||||
} else if(property.equals("findUnresolvedIncludes")) { //$NON-NLS-1$
|
|
||||||
return fFindUnresolvedIncludes.isEnabled();
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private IStructuredSelection getSelectedItem(Object part, Object selection) {
|
|
||||||
if((selection != null) && (selection instanceof IStructuredSelection)) {
|
|
||||||
return (IStructuredSelection)selection;
|
|
||||||
}
|
|
||||||
if((part != null) && (part instanceof IEditorPart)) {
|
|
||||||
Object selItem = null;
|
|
||||||
selItem = ResourceUtil.getResource(((IEditorPart)part).getEditorInput());
|
|
||||||
if(selItem != null) {
|
|
||||||
return new StructuredSelection(selItem);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return StructuredSelection.EMPTY;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void selectionChanged(IWorkbenchPart part, ISelection selection) {
|
|
||||||
IStructuredSelection sel = getSelectedItem(part, selection);
|
|
||||||
fRebuildIndexAction.selectionChanged(sel);
|
|
||||||
fCreateParserLogAction.selectionChanged(sel);
|
|
||||||
fFreshenAllFiles.selectionChanged(sel);
|
|
||||||
fUpdateUnresolvedIncludes.selectionChanged(sel);
|
|
||||||
fUpdateWithModifiedFiles.selectionChanged(sel);
|
|
||||||
fFindUnresolvedIncludes.selectionChanged(sel);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void windowActivated(IWorkbenchWindow window) {
|
|
||||||
ISelectionService selectionService = window.getSelectionService();
|
|
||||||
if (selectionService != null) {
|
|
||||||
ISelection sel = selectionService.getSelection();
|
|
||||||
selectionChanged(null, sel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void windowDeactivated(IWorkbenchWindow window) {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void windowClosed(IWorkbenchWindow window) {
|
|
||||||
ISelectionService selectionService = window.getSelectionService();
|
|
||||||
if (selectionService != null) {
|
|
||||||
selectionService.removeSelectionListener(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void windowOpened(IWorkbenchWindow window) {
|
|
||||||
ISelectionService selectionService = window.getSelectionService();
|
|
||||||
if (selectionService != null) {
|
|
||||||
selectionService.addSelectionListener(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -10,108 +10,22 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.actions;
|
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.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.ICProject;
|
||||||
import org.eclipse.cdt.core.model.ITranslationUnit;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.util.EditorUtility;
|
public class RebuildIndexAction extends AbstractUpdateIndexAction {
|
||||||
import org.eclipse.cdt.internal.ui.util.SelectionUtil;
|
|
||||||
|
|
||||||
public class RebuildIndexAction implements IObjectActionDelegate, IWorkbenchWindowActionDelegate {
|
|
||||||
private ISelection fSelection;
|
|
||||||
private boolean isEnabled;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
|
protected void doRun(ICProject[] projects) {
|
||||||
}
|
for (ICProject proj : projects) {
|
||||||
|
if(proj != null) {
|
||||||
@Override
|
CCorePlugin.getIndexManager().reindex(proj);
|
||||||
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
|
@Override
|
||||||
public void init(IWorkbenchWindow window) {
|
protected int getUpdateOptions() {
|
||||||
}
|
return 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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,12 +10,6 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.actions;
|
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}
|
* 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.
|
* @noextend This class is not intended to be subclassed by clients.
|
||||||
* @noinstantiate This class is not intended to be instantiated 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();
|
private final RebuildIndexAction rebuildIndexAction = new RebuildIndexAction();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
public AbstractUpdateIndexAction getAction() {
|
||||||
ISelection selection = HandlerUtil.getCurrentSelection(event);
|
return rebuildIndexAction;
|
||||||
IWorkbenchPart part = HandlerUtil.getActivePart(event);
|
|
||||||
rebuildIndexAction.setActivePart(null, part);
|
|
||||||
rebuildIndexAction.selectionChanged(null, selection);
|
|
||||||
rebuildIndexAction.run(null);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,12 +10,6 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.actions;
|
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}
|
* 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.
|
* @noextend This class is not intended to be subclassed by clients.
|
||||||
* @noinstantiate This class is not intended to be instantiated 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();
|
private final UpdateIndexWithModifiedFilesAction updateAction = new UpdateIndexWithModifiedFilesAction();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
public AbstractUpdateIndexAction getAction() {
|
||||||
ISelection selection = HandlerUtil.getCurrentSelection(event);
|
return updateAction;
|
||||||
IWorkbenchPart part = HandlerUtil.getActivePart(event);
|
|
||||||
updateAction.setActivePart(null, part);
|
|
||||||
updateAction.selectionChanged(null, selection);
|
|
||||||
updateAction.run(null);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,12 +10,6 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.actions;
|
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}
|
* 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.
|
* @noextend This class is not intended to be subclassed by clients.
|
||||||
* @noinstantiate This class is not intended to be instantiated 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
|
@Override
|
||||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
public AbstractUpdateIndexAction getAction() {
|
||||||
ISelection selection = HandlerUtil.getCurrentSelection(event);
|
return updateAction;
|
||||||
IWorkbenchPart part = HandlerUtil.getActivePart(event);
|
|
||||||
udpateAction.setActivePart(null, part);
|
|
||||||
udpateAction.selectionChanged(null, selection);
|
|
||||||
udpateAction.run(null);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,12 +10,8 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.search.actions;
|
package org.eclipse.cdt.internal.ui.search.actions;
|
||||||
|
|
||||||
import org.eclipse.core.commands.AbstractHandler;
|
import org.eclipse.cdt.internal.ui.actions.AbstractUpdateIndexAction;
|
||||||
import org.eclipse.core.commands.ExecutionEvent;
|
import org.eclipse.cdt.internal.ui.actions.AbstractUpdateIndexHandler;
|
||||||
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}
|
* 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.
|
* @noextend This class is not intended to be subclassed by clients.
|
||||||
* @noinstantiate This class is not intended to be instantiated 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
|
@Override
|
||||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
public AbstractUpdateIndexAction getAction() {
|
||||||
ISelection selection = HandlerUtil.getCurrentSelection(event);
|
return findUnresolvedIncludesAction;
|
||||||
IWorkbenchPart part = HandlerUtil.getActivePart(event);
|
|
||||||
rebuildIndexAction.setActivePart(null, part);
|
|
||||||
rebuildIndexAction.selectionChanged(null, selection);
|
|
||||||
rebuildIndexAction.run(null);
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -10,74 +10,37 @@
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.internal.ui.search.actions;
|
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.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.ISearchQuery;
|
||||||
import org.eclipse.search.ui.NewSearchUI;
|
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.IWorkbenchPart;
|
||||||
import org.eclipse.ui.IWorkbenchSite;
|
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.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.CSearchMessages;
|
||||||
import org.eclipse.cdt.internal.ui.search.CSearchUnresolvedIncludesQuery;
|
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;
|
import org.eclipse.cdt.internal.ui.util.StatusLineHandler;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Searches projects for unresolved includes.
|
* Searches projects for unresolved includes.
|
||||||
* Could be extended to work on resource selections.
|
* Could be extended to work on resource selections.
|
||||||
*/
|
*/
|
||||||
public class FindUnresolvedIncludesProjectAction implements IObjectActionDelegate, IWorkbenchWindowActionDelegate {
|
public class FindUnresolvedIncludesProjectAction extends AbstractUpdateIndexAction {
|
||||||
private ISelection fSelection;
|
|
||||||
private IWorkbenchSite fSite;
|
private IWorkbenchSite fSite;
|
||||||
private boolean isEnabled;
|
|
||||||
|
|
||||||
public FindUnresolvedIncludesProjectAction() {
|
public FindUnresolvedIncludesProjectAction() {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(IAction action) {
|
protected void doRun(ICProject[] projects) {
|
||||||
List<ICProject> projects = new ArrayList<ICProject>();
|
if (projects.length == 0) {
|
||||||
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);
|
StatusLineHandler.showStatusLineMessage(fSite, CSearchMessages.CSearchOperation_operationUnavailable_message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
ISearchQuery searchJob= new CSearchUnresolvedIncludesQuery(projects.toArray(new ICProject[projects.size()]));
|
ISearchQuery searchJob= new CSearchUnresolvedIncludesQuery(projects);
|
||||||
|
|
||||||
StatusLineHandler.clearStatusLine(fSite);
|
StatusLineHandler.clearStatusLine(fSite);
|
||||||
NewSearchUI.activateSearchResultView();
|
NewSearchUI.activateSearchResultView();
|
||||||
|
@ -89,45 +52,8 @@ public class FindUnresolvedIncludesProjectAction implements IObjectActionDelegat
|
||||||
fSite= targetPart.getSite();
|
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
|
@Override
|
||||||
public void init(IWorkbenchWindow window) {
|
protected int getUpdateOptions() {
|
||||||
}
|
return 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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue