mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 317707 convert resource configs context menu to handlers to allow hiding via capabilities
This commit is contained in:
parent
11f1f3bb47
commit
ef6d28343d
7 changed files with 592 additions and 37 deletions
|
@ -2,7 +2,7 @@ Manifest-Version: 1.0
|
|||
Bundle-ManifestVersion: 2
|
||||
Bundle-Name: %pluginName
|
||||
Bundle-SymbolicName: org.eclipse.cdt.ui; singleton:=true
|
||||
Bundle-Version: 5.2.100.qualifier
|
||||
Bundle-Version: 5.3.0.qualifier
|
||||
Bundle-Activator: org.eclipse.cdt.ui.CUIPlugin
|
||||
Bundle-Vendor: %providerName
|
||||
Bundle-Localization: plugin
|
||||
|
|
|
@ -574,3 +574,6 @@ ShiftLeftAction.label= S&hift Left
|
|||
excluded-file.name = C/C++ Files Excluded from Build
|
||||
|
||||
templatesViewName= Templates
|
||||
|
||||
deleteConfigsCommand.name = Reset to Default
|
||||
excludeCommand.name = Exclude from Build
|
|
@ -1055,42 +1055,6 @@
|
|||
<groupMarker name="build"/>
|
||||
</menu>
|
||||
</objectContribution>
|
||||
<objectContribution
|
||||
adaptable="true"
|
||||
id="org.eclipse.cdt.ui.buildConfigContributionM"
|
||||
objectClass="org.eclipse.core.resources.IResource">
|
||||
<visibility>
|
||||
<and>
|
||||
<objectState
|
||||
name="projectNature"
|
||||
value="org.eclipse.cdt.core.cnature"/>
|
||||
<or>
|
||||
<objectClass name="org.eclipse.core.resources.IFolder"/>
|
||||
<objectClass name="org.eclipse.core.resources.IFile"/>
|
||||
</or>
|
||||
</and>
|
||||
</visibility>
|
||||
<action
|
||||
class="org.eclipse.cdt.ui.actions.DeleteResConfigsAction"
|
||||
enablesFor="+"
|
||||
id="org.eclipse.cdt.ui.deleteConfigsAction0"
|
||||
label="%DeleteRcConfigAction.label"
|
||||
menubarPath="org.eclipse.cdt.ui.rescfgmenu/gm1"
|
||||
/>
|
||||
<action
|
||||
class="org.eclipse.cdt.ui.actions.ExcludeFromBuildAction"
|
||||
enablesFor="+"
|
||||
id="org.eclipse.cdt.ui.excludeAction0"
|
||||
label="%ExcludeAction.label"
|
||||
menubarPath="org.eclipse.cdt.ui.rescfgmenu/gm1"
|
||||
/>
|
||||
<menu
|
||||
id="org.eclipse.cdt.ui.rescfgmenu"
|
||||
label="%ResourceConfigurations.menu"
|
||||
path="buildGroup">
|
||||
<groupMarker name="gm1"/>
|
||||
</menu>
|
||||
</objectContribution>
|
||||
</extension>
|
||||
|
||||
<extension
|
||||
|
@ -3548,4 +3512,89 @@
|
|||
</enablement>
|
||||
</decorator>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.commands">
|
||||
<command
|
||||
id="org.eclipse.cdt.ui.deleteConfigsCommand"
|
||||
name="%deleteConfigsCommand.name">
|
||||
</command>
|
||||
<command
|
||||
id="org.eclipse.cdt.ui.excludeCommand"
|
||||
name="%excludeCommand.name">
|
||||
</command>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.handlers">
|
||||
<handler
|
||||
class="org.eclipse.cdt.ui.actions.DeleteResConfigsHandler"
|
||||
commandId="org.eclipse.cdt.ui.deleteConfigsCommand">
|
||||
</handler>
|
||||
<handler
|
||||
class="org.eclipse.cdt.ui.actions.ExcludeFromBuildHandler"
|
||||
commandId="org.eclipse.cdt.ui.excludeCommand">
|
||||
</handler>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.menus">
|
||||
<menuContribution
|
||||
locationURI="popup:org.eclipse.ui.popup.any?endof=buildGroup">
|
||||
<menu
|
||||
id="org.eclipse.cdt.ui.buildConfigContributionM"
|
||||
label="%ResourceConfigurations.menu">
|
||||
<visibleWhen
|
||||
checkEnabled="false">
|
||||
<with variable="activeMenuSelection">
|
||||
<iterate ifEmpty="false">
|
||||
<or>
|
||||
<adapt type="org.eclipse.core.resources.IFile">
|
||||
<test
|
||||
property="org.eclipse.core.resources.projectNature"
|
||||
value="org.eclipse.cdt.core.cnature"/>
|
||||
</adapt>
|
||||
<adapt type="org.eclipse.core.resources.IFolder">
|
||||
<test
|
||||
property="org.eclipse.core.resources.projectNature"
|
||||
value="org.eclipse.cdt.core.cnature"/>
|
||||
</adapt>
|
||||
</or>
|
||||
</iterate>
|
||||
</with>
|
||||
</visibleWhen>
|
||||
</menu>
|
||||
</menuContribution>
|
||||
<menuContribution
|
||||
locationURI="popup:org.eclipse.ui.popup.any?after=additions">
|
||||
<menu
|
||||
id="org.eclipse.cdt.ui.buildConfigContributionM"
|
||||
label="%ResourceConfigurations.menu">
|
||||
<visibleWhen
|
||||
checkEnabled="false">
|
||||
<with variable="activeMenuEditorInput">
|
||||
<iterate ifEmpty="false">
|
||||
<adapt type="org.eclipse.core.resources.IFile">
|
||||
<test
|
||||
property="org.eclipse.core.resources.projectNature"
|
||||
value="org.eclipse.cdt.core.cnature"/>
|
||||
</adapt>
|
||||
</iterate>
|
||||
</with>
|
||||
</visibleWhen>
|
||||
</menu>
|
||||
</menuContribution>
|
||||
<menuContribution
|
||||
locationURI="popup:org.eclipse.cdt.ui.buildConfigContributionM">
|
||||
<command
|
||||
commandId="org.eclipse.cdt.ui.excludeCommand"
|
||||
id="org.eclipse.cdt.ui.excludeCommand.menu"
|
||||
label="%ExcludeAction.label"
|
||||
style="push">
|
||||
</command>
|
||||
<command
|
||||
commandId="org.eclipse.cdt.ui.deleteConfigsCommand"
|
||||
id="org.eclipse.cdt.ui.deleteConfigsCommand.menu"
|
||||
label="%DeleteRcConfigAction.label"
|
||||
style="push">
|
||||
</command>
|
||||
</menuContribution>
|
||||
</extension>
|
||||
</plugin>
|
||||
|
|
|
@ -48,7 +48,9 @@ import org.eclipse.cdt.internal.ui.actions.ActionMessages;
|
|||
/**
|
||||
* Action which deletes resource description. (If resource description is missing
|
||||
* one from parent is normally used)
|
||||
* @deprecated as of CDT 8.0 now using {@link DeleteResConfigsHandler}
|
||||
*/
|
||||
@Deprecated
|
||||
public class DeleteResConfigsAction
|
||||
implements IWorkbenchWindowPulldownDelegate2, IObjectActionDelegate {
|
||||
|
||||
|
|
|
@ -0,0 +1,237 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007, 2010 Intel Corporation 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:
|
||||
* Intel Corporation - initial API and implementation
|
||||
* Nokia - converted from action to handler
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.actions;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.jface.text.ITextSelection;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.IStructuredContentProvider;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
import org.eclipse.jface.window.Window;
|
||||
import org.eclipse.ui.IEditorInput;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.ISources;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.dialogs.ListSelectionDialog;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
|
||||
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.ITranslationUnit;
|
||||
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICResourceDescription;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.newui.AbstractPage;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.actions.ActionMessages;
|
||||
|
||||
|
||||
/**
|
||||
* Handler for command that deletes resource description. (If resource description is missing
|
||||
* one from parent is normally used)
|
||||
* @since 5.3
|
||||
*/
|
||||
public class DeleteResConfigsHandler extends AbstractHandler {
|
||||
|
||||
protected ArrayList<IResource> objects;
|
||||
private ArrayList<ResCfgData> outData;
|
||||
|
||||
@Override
|
||||
public void setEnabled(Object context) {
|
||||
ISelection selection = getSelection(context);
|
||||
setEnabledFromSelection(selection);
|
||||
}
|
||||
|
||||
protected ISelection getSelection(Object context) {
|
||||
Object s = HandlerUtil.getVariable(context, ISources.ACTIVE_MENU_SELECTION_NAME);
|
||||
if (s instanceof ISelection) {
|
||||
return (ISelection) s;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setEnabledFromSelection(ISelection selection) {
|
||||
objects = null;
|
||||
|
||||
if (!selection.isEmpty()) {
|
||||
// case for context menu
|
||||
Object[] obs = null;
|
||||
if (selection instanceof IStructuredSelection) {
|
||||
obs = ((IStructuredSelection)selection).toArray();
|
||||
}
|
||||
else if (selection instanceof ITextSelection) {
|
||||
IFile file = getFileFromActiveEditor();
|
||||
if (file != null)
|
||||
obs = Collections.singletonList(file).toArray();
|
||||
}
|
||||
if (obs != null && obs.length > 0) {
|
||||
for (int i=0; i<obs.length; i++) {
|
||||
IResource res = null;
|
||||
// only folders and files may be affected by this action
|
||||
if (obs[i] instanceof ICContainer || obs[i] instanceof ITranslationUnit)
|
||||
res = ((ICElement)obs[i]).getResource();
|
||||
// project's configuration cannot be deleted
|
||||
else if (obs[i] instanceof IResource && !(obs[i] instanceof IProject))
|
||||
res = (IResource)obs[i];
|
||||
if (res != null) {
|
||||
IProject p = res.getProject();
|
||||
if (!p.isOpen()) continue;
|
||||
|
||||
if (!CoreModel.getDefault().isNewStyleProject(p))
|
||||
continue;
|
||||
|
||||
IPath path = res.getProjectRelativePath();
|
||||
// getting description in read-only mode
|
||||
ICProjectDescription prjd = CoreModel.getDefault().getProjectDescription(p, false);
|
||||
if (prjd == null) continue;
|
||||
ICConfigurationDescription[] cfgds = prjd.getConfigurations();
|
||||
if (cfgds == null || cfgds.length == 0) continue;
|
||||
for (ICConfigurationDescription cfgd : cfgds) {
|
||||
ICResourceDescription rd = cfgd.getResourceDescription(path, true);
|
||||
if (rd != null) {
|
||||
if (objects == null) objects = new ArrayList<IResource>();
|
||||
objects.add(res);
|
||||
break; // stop configurations scanning
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
setBaseEnabled(objects != null);
|
||||
}
|
||||
|
||||
private IFile getFileFromActiveEditor() {
|
||||
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
|
||||
if (window != null) {
|
||||
IWorkbenchPage page = window.getActivePage();
|
||||
if (page != null) {
|
||||
IEditorPart editor = page.getActiveEditor();
|
||||
if (editor != null) {
|
||||
IEditorInput input = editor.getEditorInput();
|
||||
if (input != null)
|
||||
return (IFile) input.getAdapter(IFile.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
openDialog();
|
||||
return null;
|
||||
}
|
||||
|
||||
private void openDialog() {
|
||||
if (objects == null || objects.size() == 0) return;
|
||||
// create list of configurations to delete
|
||||
|
||||
ListSelectionDialog dialog = new ListSelectionDialog(
|
||||
CUIPlugin.getActiveWorkbenchShell(),
|
||||
objects,
|
||||
createSelectionDialogContentProvider(),
|
||||
new LabelProvider() {}, ActionMessages.DeleteResConfigsAction_0);
|
||||
dialog.setTitle(ActionMessages.DeleteResConfigsAction_1);
|
||||
if (dialog.open() == Window.OK) {
|
||||
Object[] selected = dialog.getResult();
|
||||
if (selected != null && selected.length > 0) {
|
||||
for (Object element : selected) {
|
||||
((ResCfgData)element).delete();
|
||||
AbstractPage.updateViews(((ResCfgData)element).res);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Stores data for resource description with its "parents".
|
||||
class ResCfgData {
|
||||
IResource res;
|
||||
ICProjectDescription prjd;
|
||||
ICConfigurationDescription cfgd;
|
||||
ICResourceDescription rdesc;
|
||||
|
||||
public ResCfgData(IResource res2, ICProjectDescription prjd2,
|
||||
ICConfigurationDescription cfgd2, ICResourceDescription rdesc2) {
|
||||
res = res2; prjd = prjd2; cfgd = cfgd2; rdesc = rdesc2;
|
||||
}
|
||||
|
||||
// performs deletion
|
||||
public void delete() {
|
||||
try {
|
||||
cfgd.removeResourceDescription(rdesc);
|
||||
CoreModel.getDefault().setProjectDescription(res.getProject(), prjd);
|
||||
} catch (CoreException e) {}
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[" + cfgd.getName() + "] for " + res.getName(); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private IStructuredContentProvider createSelectionDialogContentProvider() {
|
||||
outData = null;
|
||||
|
||||
return new IStructuredContentProvider() {
|
||||
|
||||
public Object[] getElements(Object inputElement) {
|
||||
if (outData != null) return outData.toArray();
|
||||
|
||||
outData = new ArrayList<ResCfgData>();
|
||||
List<?> ls = (List<?>)inputElement;
|
||||
Iterator<?> it = ls.iterator();
|
||||
IProject proj = null;
|
||||
ICProjectDescription prjd = null;
|
||||
ICConfigurationDescription[] cfgds = null;
|
||||
|
||||
// creating list of all res descs for all objects
|
||||
while (it.hasNext()) {
|
||||
IResource res = (IResource)it.next();
|
||||
IPath path = res.getProjectRelativePath();
|
||||
if (res.getProject() != proj) {
|
||||
proj = res.getProject();
|
||||
prjd = CoreModel.getDefault().getProjectDescription(proj);
|
||||
cfgds = prjd.getConfigurations();
|
||||
}
|
||||
if (cfgds != null) {
|
||||
for (ICConfigurationDescription cfgd : cfgds) {
|
||||
ICResourceDescription rd = cfgd.getResourceDescription(path, true);
|
||||
if (rd != null)
|
||||
outData.add(new ResCfgData(res, prjd, cfgd, rd));
|
||||
}
|
||||
}
|
||||
}
|
||||
return outData.toArray();
|
||||
}
|
||||
public void dispose() {}
|
||||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
|
@ -50,7 +50,9 @@ import org.eclipse.cdt.internal.ui.actions.ActionMessages;
|
|||
|
||||
/**
|
||||
* Action which excludes resources from build.
|
||||
* @deprecated as of CDT 8.0 now using {@link ExcludeFromBuildHandler}
|
||||
*/
|
||||
@Deprecated
|
||||
public class ExcludeFromBuildAction
|
||||
implements IWorkbenchWindowPulldownDelegate2, IObjectActionDelegate {
|
||||
|
||||
|
|
|
@ -0,0 +1,262 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2007, 2010 Intel Corporation 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:
|
||||
* Intel Corporation - initial API and implementation
|
||||
* Nokia - converted from action to handler
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.actions;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Iterator;
|
||||
|
||||
import org.eclipse.core.commands.AbstractHandler;
|
||||
import org.eclipse.core.commands.ExecutionEvent;
|
||||
import org.eclipse.core.commands.ExecutionException;
|
||||
import org.eclipse.core.resources.IFile;
|
||||
import org.eclipse.core.resources.IFolder;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.IResource;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.core.runtime.IPath;
|
||||
import org.eclipse.jface.text.ITextSelection;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.jface.viewers.IStructuredContentProvider;
|
||||
import org.eclipse.jface.viewers.IStructuredSelection;
|
||||
import org.eclipse.jface.viewers.LabelProvider;
|
||||
import org.eclipse.jface.viewers.Viewer;
|
||||
import org.eclipse.jface.window.Window;
|
||||
import org.eclipse.ui.IEditorInput;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.ISources;
|
||||
import org.eclipse.ui.IWorkbenchPage;
|
||||
import org.eclipse.ui.IWorkbenchWindow;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.dialogs.ListSelectionDialog;
|
||||
import org.eclipse.ui.handlers.HandlerUtil;
|
||||
|
||||
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.core.settings.model.ICConfigurationDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICProjectDescription;
|
||||
import org.eclipse.cdt.core.settings.model.ICSourceEntry;
|
||||
import org.eclipse.cdt.core.settings.model.util.CDataUtil;
|
||||
import org.eclipse.cdt.ui.CUIPlugin;
|
||||
import org.eclipse.cdt.ui.newui.AbstractPage;
|
||||
import org.eclipse.cdt.ui.newui.UIMessages;
|
||||
|
||||
import org.eclipse.cdt.internal.ui.actions.ActionMessages;
|
||||
|
||||
/**
|
||||
* Handler for command that excludes resources from build.
|
||||
* @since 5.3
|
||||
*/
|
||||
public class ExcludeFromBuildHandler extends AbstractHandler {
|
||||
|
||||
protected ArrayList<IResource> objects;
|
||||
protected ArrayList<String> cfgNames;
|
||||
|
||||
@Override
|
||||
public void setEnabled(Object context) {
|
||||
ISelection selection = getSelection(context);
|
||||
setEnabledFromSelection(selection);
|
||||
}
|
||||
|
||||
protected ISelection getSelection(Object context) {
|
||||
Object s = HandlerUtil.getVariable(context, ISources.ACTIVE_MENU_SELECTION_NAME);
|
||||
if (s instanceof ISelection) {
|
||||
return (ISelection) s;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void setEnabledFromSelection(ISelection selection) {
|
||||
objects = null;
|
||||
cfgNames = null;
|
||||
boolean cfgsOK = true;
|
||||
|
||||
if (!selection.isEmpty()) {
|
||||
// case for context menu
|
||||
Object[] obs = null;
|
||||
if (selection instanceof IStructuredSelection) {
|
||||
obs = ((IStructuredSelection)selection).toArray();
|
||||
}
|
||||
else if (selection instanceof ITextSelection) {
|
||||
IFile file = getFileFromActiveEditor();
|
||||
if (file != null)
|
||||
obs = Collections.singletonList(file).toArray();
|
||||
}
|
||||
if (obs != null && obs.length > 0) {
|
||||
for (int i=0; i<obs.length && cfgsOK; i++) {
|
||||
// if project selected, don't do anything
|
||||
if ((obs[i] instanceof IProject) || (obs[i] instanceof ICProject)) {
|
||||
cfgsOK=false;
|
||||
break;
|
||||
}
|
||||
IResource res = null;
|
||||
// only folders and files may be affected by this action
|
||||
if (obs[i] instanceof ICContainer || obs[i] instanceof ITranslationUnit) {
|
||||
res = ((ICElement) obs[i]).getResource();
|
||||
} else if (obs[i] instanceof IResource) {
|
||||
// project's configuration cannot be deleted
|
||||
res = (IResource) obs[i];
|
||||
}
|
||||
if (res != null) {
|
||||
ICConfigurationDescription[] cfgds = getCfgsRead(res);
|
||||
if (cfgds == null || cfgds.length == 0) continue;
|
||||
|
||||
if (objects == null) objects = new ArrayList<IResource>();
|
||||
objects.add(res);
|
||||
if (cfgNames == null) {
|
||||
cfgNames = new ArrayList<String>(cfgds.length);
|
||||
for (int j=0; j<cfgds.length; j++) {
|
||||
if (!canExclude(res, cfgds[j])) {
|
||||
cfgNames = null;
|
||||
cfgsOK = false;
|
||||
break;
|
||||
}
|
||||
cfgNames.add(cfgds[j].getName());
|
||||
}
|
||||
} else {
|
||||
if (cfgNames.size() != cfgds.length) {
|
||||
cfgsOK = false;
|
||||
} else {
|
||||
for (int j=0; j<cfgds.length; j++) {
|
||||
if (! canExclude(res, cfgds[j]) ||
|
||||
! cfgNames.contains(cfgds[j].getName())) {
|
||||
cfgsOK = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
setBaseEnabled(cfgsOK && objects != null );
|
||||
}
|
||||
|
||||
private IFile getFileFromActiveEditor() {
|
||||
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
|
||||
if (window != null) {
|
||||
IWorkbenchPage page = window.getActivePage();
|
||||
if (page != null) {
|
||||
IEditorPart editor = page.getActiveEditor();
|
||||
if (editor != null) {
|
||||
IEditorInput input = editor.getEditorInput();
|
||||
if (input != null)
|
||||
return (IFile) input.getAdapter(IFile.class);
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean canExclude(IResource res, ICConfigurationDescription cfg) {
|
||||
IPath p = res.getFullPath();
|
||||
ICSourceEntry[] ent = cfg.getSourceEntries();
|
||||
boolean state = CDataUtil.isExcluded(p, ent);
|
||||
return CDataUtil.canExclude(p, (res instanceof IFolder), !state, ent);
|
||||
}
|
||||
|
||||
private void setExclude(IResource res, ICConfigurationDescription cfg, boolean exclude) {
|
||||
try {
|
||||
ICSourceEntry[] newEntries = CDataUtil.setExcluded(res.getFullPath(), (res instanceof IFolder), exclude, cfg.getSourceEntries());
|
||||
cfg.setSourceEntries(newEntries);
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.log(e);
|
||||
}
|
||||
}
|
||||
|
||||
public Object execute(ExecutionEvent event) throws ExecutionException {
|
||||
openDialog();
|
||||
return null;
|
||||
}
|
||||
|
||||
private ICConfigurationDescription[] getCfgsRead(IResource res) {
|
||||
IProject p = res.getProject();
|
||||
if (!p.isOpen()) return null;
|
||||
if (!CoreModel.getDefault().isNewStyleProject(p)) return null;
|
||||
ICProjectDescription prjd = CoreModel.getDefault().getProjectDescription(p, false);
|
||||
if (prjd == null) return null;
|
||||
return prjd.getConfigurations();
|
||||
}
|
||||
|
||||
private void openDialog() {
|
||||
if (objects == null || objects.size() == 0) return;
|
||||
// create list of configurations to delete
|
||||
|
||||
ListSelectionDialog dialog = new ListSelectionDialog(
|
||||
CUIPlugin.getActiveWorkbenchShell(),
|
||||
cfgNames,
|
||||
createSelectionDialogContentProvider(),
|
||||
new LabelProvider() {},
|
||||
ActionMessages.ExcludeFromBuildAction_0);
|
||||
dialog.setTitle(ActionMessages.ExcludeFromBuildAction_1);
|
||||
|
||||
boolean[] status = new boolean[cfgNames.size()];
|
||||
Iterator<IResource> it = objects.iterator();
|
||||
while (it.hasNext()) {
|
||||
IResource res = it.next();
|
||||
ICConfigurationDescription[] cfgds = getCfgsRead(res);
|
||||
IPath p = res.getFullPath();
|
||||
for (int i=0; i<cfgds.length; i++) {
|
||||
boolean b = CDataUtil.isExcluded(p, cfgds[i].getSourceEntries());
|
||||
if (b) status[i] = true;
|
||||
}
|
||||
}
|
||||
ArrayList<String> lst = new ArrayList<String>();
|
||||
for (int i=0; i<status.length; i++)
|
||||
if (status[i]) lst.add(cfgNames.get(i));
|
||||
if (lst.size() > 0)
|
||||
dialog.setInitialElementSelections(lst);
|
||||
|
||||
if (dialog.open() == Window.OK) {
|
||||
Object[] selected = dialog.getResult(); // may be empty
|
||||
Iterator<IResource> it2 = objects.iterator();
|
||||
while (it2.hasNext()) {
|
||||
IResource res = it2.next();
|
||||
IProject p = res.getProject();
|
||||
if (!p.isOpen()) continue;
|
||||
// get writable description
|
||||
ICProjectDescription prjd = CoreModel.getDefault().getProjectDescription(p, true);
|
||||
if (prjd == null) continue;
|
||||
ICConfigurationDescription[] cfgds = prjd.getConfigurations();
|
||||
for (int i=0; i<cfgds.length; i++) {
|
||||
boolean exclude = false;
|
||||
for (int j=0; j<selected.length; j++) {
|
||||
if (cfgds[i].getName().equals(selected[j])) {
|
||||
exclude = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
setExclude(res, cfgds[i], exclude);
|
||||
}
|
||||
try {
|
||||
CoreModel.getDefault().setProjectDescription(p, prjd);
|
||||
} catch (CoreException e) {
|
||||
CUIPlugin.getDefault().logErrorMessage(UIMessages.getString("AbstractPage.11") + e.getLocalizedMessage()); //$NON-NLS-1$
|
||||
}
|
||||
AbstractPage.updateViews(res);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private IStructuredContentProvider createSelectionDialogContentProvider() {
|
||||
return new IStructuredContentProvider() {
|
||||
public Object[] getElements(Object inputElement) { return cfgNames.toArray(); }
|
||||
public void dispose() {}
|
||||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue