mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-08-07 16:26:11 +02:00
Enable change config and build actions if the selection is in a source file.
This commit is contained in:
parent
caa5ad7df2
commit
6a7ab9f69b
1 changed files with 70 additions and 35 deletions
|
@ -18,16 +18,22 @@ import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.core.resources.IResource;
|
import org.eclipse.core.resources.IResource;
|
||||||
import org.eclipse.jface.action.ActionContributionItem;
|
import org.eclipse.jface.action.ActionContributionItem;
|
||||||
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.ISelection;
|
||||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||||
import org.eclipse.swt.widgets.Menu;
|
import org.eclipse.swt.widgets.Menu;
|
||||||
import org.eclipse.swt.widgets.MenuItem;
|
import org.eclipse.swt.widgets.MenuItem;
|
||||||
|
import org.eclipse.ui.IEditorPart;
|
||||||
|
import org.eclipse.ui.IWorkbenchPage;
|
||||||
|
import org.eclipse.ui.IWorkbenchPart;
|
||||||
|
import org.eclipse.ui.IWorkbenchWindow;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
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.settings.model.ICConfigurationDescription;
|
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||||
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
|
||||||
import org.eclipse.cdt.internal.ui.cview.IncludeRefContainer;
|
import org.eclipse.cdt.internal.ui.cview.IncludeRefContainer;
|
||||||
import org.eclipse.cdt.internal.ui.cview.IncludeReferenceProxy;
|
import org.eclipse.cdt.internal.ui.cview.IncludeReferenceProxy;
|
||||||
|
@ -150,10 +156,11 @@ public class ChangeBuildConfigActionBase {
|
||||||
protected void onSelectionChanged(IAction action, ISelection selection) {
|
protected void onSelectionChanged(IAction action, ISelection selection) {
|
||||||
fProjects.clear();
|
fProjects.clear();
|
||||||
|
|
||||||
if (!action.isEnabled()) return;
|
|
||||||
|
|
||||||
boolean badObject = false;
|
boolean badObject = false;
|
||||||
if (selection != null && selection instanceof IStructuredSelection) {
|
|
||||||
|
if (selection != null )
|
||||||
|
{
|
||||||
|
if (selection instanceof IStructuredSelection) {
|
||||||
Iterator iter = ((IStructuredSelection)selection).iterator();
|
Iterator iter = ((IStructuredSelection)selection).iterator();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
Object selItem = iter.next();
|
Object selItem = iter.next();
|
||||||
|
@ -193,6 +200,34 @@ public class ChangeBuildConfigActionBase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
if (selection instanceof ITextSelection) {
|
||||||
|
// If a text selection check the selected part to see if we can find
|
||||||
|
// an editor part that we can adapt to a resource and then
|
||||||
|
// back to a project.
|
||||||
|
IWorkbenchWindow window = CUIPlugin.getActiveWorkbenchWindow();
|
||||||
|
if (window != null) {
|
||||||
|
if (window != null) {
|
||||||
|
IWorkbenchPage page = window.getActivePage();
|
||||||
|
if (page != null) {
|
||||||
|
IWorkbenchPart part = page.getActivePart();
|
||||||
|
if (part instanceof IEditorPart) {
|
||||||
|
IEditorPart epart = (IEditorPart) part;
|
||||||
|
IResource resource = (IResource) epart.getEditorInput().getAdapter(IResource.class);
|
||||||
|
IProject project = resource.getProject();
|
||||||
|
badObject = !(project != null && CoreModel.getDefault().isNewStyleProject(project));
|
||||||
|
|
||||||
|
if (!badObject) {
|
||||||
|
fProjects.add(project);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
boolean enable = false;
|
boolean enable = false;
|
||||||
if (!badObject && !fProjects.isEmpty()) {
|
if (!badObject && !fProjects.isEmpty()) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue