1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-25 01:45:33 +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.jface.action.ActionContributionItem;
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.swt.widgets.Menu;
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.ICElement;
import org.eclipse.cdt.core.model.ICProject;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
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.IncludeReferenceProxy;
@ -150,50 +156,79 @@ public class ChangeBuildConfigActionBase {
protected void onSelectionChanged(IAction action, ISelection selection) {
fProjects.clear();
if (!action.isEnabled()) return;
boolean badObject = false;
if (selection != null && selection instanceof IStructuredSelection) {
Iterator iter = ((IStructuredSelection)selection).iterator();
while (iter.hasNext()) {
Object selItem = iter.next();
IProject project = null;
if (selItem instanceof ICElement) {
ICProject cproject = ((ICElement)selItem).getCProject();
if (cproject != null) project = cproject.getProject();
}
else if (selItem instanceof IResource) {
project = ((IResource)selItem).getProject();
} else if (selItem instanceof IncludeRefContainer) {
ICProject fCProject = ((IncludeRefContainer)selItem).getCProject();
if (fCProject != null)
project = fCProject.getProject();
} else if (selItem instanceof IncludeReferenceProxy) {
IncludeRefContainer irc = ((IncludeReferenceProxy)selItem).getIncludeRefContainer();
if (irc != null) {
ICProject fCProject = irc.getCProject();
if (selection != null )
{
if (selection instanceof IStructuredSelection) {
Iterator iter = ((IStructuredSelection)selection).iterator();
while (iter.hasNext()) {
Object selItem = iter.next();
IProject project = null;
if (selItem instanceof ICElement) {
ICProject cproject = ((ICElement)selItem).getCProject();
if (cproject != null) project = cproject.getProject();
}
else if (selItem instanceof IResource) {
project = ((IResource)selItem).getProject();
} else if (selItem instanceof IncludeRefContainer) {
ICProject fCProject = ((IncludeRefContainer)selItem).getCProject();
if (fCProject != null)
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
if (project != null) {
if (!CoreModel.getDefault().isNewStyleProject(project))
project = null;
else {
ICConfigurationDescription[] tmp = getCfgs(project);
if (tmp == null || tmp.length == 0) project = null;
// Check whether the project is CDT project
if (project != null) {
if (!CoreModel.getDefault().isNewStyleProject(project))
project = null;
else {
ICConfigurationDescription[] tmp = getCfgs(project);
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;
if (!badObject && !fProjects.isEmpty()) {
Iterator iter = fProjects.iterator();