1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-08-07 00:05:53 +02:00

Enable change config and build actions if the selection is in a source file.

This commit is contained in:
Ken Ryall 2007-06-09 02:28:47 +00:00
parent caa5ad7df2
commit 6a7ab9f69b

View file

@ -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,50 +156,79 @@ 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) {
Iterator iter = ((IStructuredSelection)selection).iterator(); if (selection != null )
while (iter.hasNext()) { {
Object selItem = iter.next(); if (selection instanceof IStructuredSelection) {
IProject project = null; Iterator iter = ((IStructuredSelection)selection).iterator();
if (selItem instanceof ICElement) { while (iter.hasNext()) {
ICProject cproject = ((ICElement)selItem).getCProject(); Object selItem = iter.next();
if (cproject != null) project = cproject.getProject(); IProject project = null;
} if (selItem instanceof ICElement) {
else if (selItem instanceof IResource) { ICProject cproject = ((ICElement)selItem).getCProject();
project = ((IResource)selItem).getProject(); if (cproject != null) project = cproject.getProject();
} else if (selItem instanceof IncludeRefContainer) { }
ICProject fCProject = ((IncludeRefContainer)selItem).getCProject(); else if (selItem instanceof IResource) {
if (fCProject != null) project = ((IResource)selItem).getProject();
project = fCProject.getProject(); } else if (selItem instanceof IncludeRefContainer) {
} else if (selItem instanceof IncludeReferenceProxy) { ICProject fCProject = ((IncludeRefContainer)selItem).getCProject();
IncludeRefContainer irc = ((IncludeReferenceProxy)selItem).getIncludeRefContainer();
if (irc != null) {
ICProject fCProject = irc.getCProject();
if (fCProject != null) if (fCProject != null)
project = fCProject.getProject(); project = fCProject.getProject();
} else if (selItem instanceof IncludeReferenceProxy) {
IncludeRefContainer irc = ((IncludeReferenceProxy)selItem).getIncludeRefContainer();
if (irc != null) {
ICProject fCProject = irc.getCProject();
if (fCProject != null)
project = fCProject.getProject();
}
} }
} // Check whether the project is CDT project
// Check whether the project is CDT project if (project != null) {
if (project != null) { if (!CoreModel.getDefault().isNewStyleProject(project))
if (!CoreModel.getDefault().isNewStyleProject(project)) project = null;
project = null; else {
else { ICConfigurationDescription[] tmp = getCfgs(project);
ICConfigurationDescription[] tmp = getCfgs(project); if (tmp == null || tmp.length == 0) project = null;
if (tmp == null || tmp.length == 0) project = null; }
}
if (project != null) {
fProjects.add(project);
} else {
badObject = true;
break;
} }
}
if (project != null) {
fProjects.add(project);
} else {
badObject = true;
break;
} }
} }
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()) {
Iterator iter = fProjects.iterator(); Iterator iter = fProjects.iterator();