mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-25 18:05:33 +02:00
Bug # 161547
This commit is contained in:
parent
fc34a9ccbf
commit
91a194dc33
5 changed files with 237 additions and 4 deletions
|
@ -162,8 +162,9 @@ BuildConfigContextAction.label=Active Bui&ld Configuration
|
||||||
BuildConfigAction.tooltip=Change active build configuration for project(s)
|
BuildConfigAction.tooltip=Change active build configuration for project(s)
|
||||||
BuildConfigAction.tooltip2=Manage configurations for the current project
|
BuildConfigAction.tooltip2=Manage configurations for the current project
|
||||||
|
|
||||||
ManageConfigAction.label=Manage configurations
|
ManageConfigAction.label=Manage configurations...
|
||||||
DeleteRcConfigAction.label=Delete resource configs...
|
DeleteRcConfigAction.label=Delete resource configs...
|
||||||
|
ExcludeAction.label=Exclude from build...
|
||||||
BuildConfigurationActionSet.descr=Build configuration for the current project
|
BuildConfigurationActionSet.descr=Build configuration for the current project
|
||||||
|
|
||||||
# Common Editor ruler actions
|
# Common Editor ruler actions
|
||||||
|
|
|
@ -837,6 +837,13 @@
|
||||||
label="%DeleteRcConfigAction.label"
|
label="%DeleteRcConfigAction.label"
|
||||||
menubarPath="buildGroup"
|
menubarPath="buildGroup"
|
||||||
/>
|
/>
|
||||||
|
<action
|
||||||
|
class="org.eclipse.cdt.ui.actions.ExcludeFromBuildAction"
|
||||||
|
enablesFor="+"
|
||||||
|
id="org.eclipse.cdt.ui.excludeAction0"
|
||||||
|
label="%ExcludeAction.label"
|
||||||
|
menubarPath="buildGroup"
|
||||||
|
/>
|
||||||
</objectContribution>
|
</objectContribution>
|
||||||
</extension>
|
</extension>
|
||||||
|
|
||||||
|
@ -979,6 +986,13 @@
|
||||||
label="%DeleteRcConfigAction.label"
|
label="%DeleteRcConfigAction.label"
|
||||||
menubarPath="project/build"
|
menubarPath="project/build"
|
||||||
/>
|
/>
|
||||||
|
<action
|
||||||
|
class="org.eclipse.cdt.ui.actions.ExcludeFromBuildAction"
|
||||||
|
enablesFor="+"
|
||||||
|
id="org.eclipse.cdt.ui.excludeAction2"
|
||||||
|
label="%ExcludeAction.label"
|
||||||
|
menubarPath="project/build"
|
||||||
|
/>
|
||||||
</actionSet>
|
</actionSet>
|
||||||
<actionSet
|
<actionSet
|
||||||
label="%CElementCreationActionSet.label"
|
label="%CElementCreationActionSet.label"
|
||||||
|
|
|
@ -115,4 +115,10 @@ COutlineInformationControl.viewMenu.move.label=Move outline
|
||||||
COutlineInformationControl.viewMenu.sort.label=Sort
|
COutlineInformationControl.viewMenu.sort.label=Sort
|
||||||
|
|
||||||
ChangeBuildConfigMenuAction.title=Sorry
|
ChangeBuildConfigMenuAction.title=Sorry
|
||||||
ChangeBuildConfigMenuAction.text=Only one project should be selected to manage configurations.
|
ChangeBuildConfigMenuAction.text=Only one project should be selected to manage configurations.
|
||||||
|
|
||||||
|
DeleteResConfigsAction.0=Select configurations to delete
|
||||||
|
DeleteResConfigsAction.1=Delete resource configurations
|
||||||
|
|
||||||
|
ExcludeFromBuildAction.0=Exclude object(s) from build in the following configurations
|
||||||
|
ExcludeFromBuildAction.1=Exclude from build
|
||||||
|
|
|
@ -43,6 +43,8 @@ import org.eclipse.cdt.core.settings.model.ICResourceDescription;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
import org.eclipse.cdt.ui.newui.AbstractPage;
|
import org.eclipse.cdt.ui.newui.AbstractPage;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.internal.ui.actions.ActionMessages;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Action which changes active build configuration of the current project to
|
* Action which changes active build configuration of the current project to
|
||||||
* the given one.
|
* the given one.
|
||||||
|
@ -107,8 +109,8 @@ implements IWorkbenchWindowPulldownDelegate2, IObjectActionDelegate {
|
||||||
CUIPlugin.getActiveWorkbenchShell(),
|
CUIPlugin.getActiveWorkbenchShell(),
|
||||||
objects,
|
objects,
|
||||||
createSelectionDialogContentProvider(),
|
createSelectionDialogContentProvider(),
|
||||||
new LabelProvider() {}, "Select configurations to delete"); //$NON-NLS-1$
|
new LabelProvider() {}, ActionMessages.getString("DeleteResConfigsAction.0")); //$NON-NLS-1$
|
||||||
dialog.setTitle("Delete resource configurations"); //$NON-NLS-1$
|
dialog.setTitle(ActionMessages.getString("DeleteResConfigsAction.1")); //$NON-NLS-1$
|
||||||
if (dialog.open() == Window.OK) {
|
if (dialog.open() == Window.OK) {
|
||||||
Object[] selected = dialog.getResult();
|
Object[] selected = dialog.getResult();
|
||||||
if (selected != null && selected.length > 0) {
|
if (selected != null && selected.length > 0) {
|
||||||
|
|
|
@ -0,0 +1,210 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Copyright (c) 2007 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
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.ui.actions;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
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.action.IAction;
|
||||||
|
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.swt.widgets.Control;
|
||||||
|
import org.eclipse.swt.widgets.Menu;
|
||||||
|
import org.eclipse.ui.IObjectActionDelegate;
|
||||||
|
import org.eclipse.ui.IWorkbenchPart;
|
||||||
|
import org.eclipse.ui.IWorkbenchWindow;
|
||||||
|
import org.eclipse.ui.IWorkbenchWindowPulldownDelegate2;
|
||||||
|
import org.eclipse.ui.dialogs.ListSelectionDialog;
|
||||||
|
|
||||||
|
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.ICFolderDescription;
|
||||||
|
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;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Action which changes active build configuration of the current project to
|
||||||
|
* the given one.
|
||||||
|
*/
|
||||||
|
public class ExcludeFromBuildAction
|
||||||
|
implements IWorkbenchWindowPulldownDelegate2, IObjectActionDelegate {
|
||||||
|
|
||||||
|
protected ArrayList objects = null;
|
||||||
|
protected ArrayList cfgNames = null;
|
||||||
|
|
||||||
|
public void selectionChanged(IAction action, ISelection selection) {
|
||||||
|
objects = null;
|
||||||
|
boolean cfgsOK = true;
|
||||||
|
|
||||||
|
if (!selection.isEmpty()) {
|
||||||
|
// case for context menu
|
||||||
|
if (selection instanceof IStructuredSelection) {
|
||||||
|
Object[] obs = ((IStructuredSelection)selection).toArray();
|
||||||
|
if (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();
|
||||||
|
// project's configuration cannot be deleted
|
||||||
|
else if (obs[i] instanceof IResource)
|
||||||
|
res = (IResource)obs[i];
|
||||||
|
if (res != null) {
|
||||||
|
ICConfigurationDescription[] cfgds = getCfgsRead(res);
|
||||||
|
if (cfgds == null || cfgds.length == 0) continue;
|
||||||
|
if (objects == null) objects = new ArrayList();
|
||||||
|
objects.add(res);
|
||||||
|
if (cfgNames == null) {
|
||||||
|
cfgNames = new ArrayList(cfgds.length);
|
||||||
|
for (int j=0; j<cfgds.length; j++)
|
||||||
|
cfgNames.add(cfgds[j].getName());
|
||||||
|
} else {
|
||||||
|
if (cfgNames.size() != cfgds.length) cfgsOK = false;
|
||||||
|
else for (int j=0; j<cfgds.length; j++) {
|
||||||
|
if (!cfgNames.contains(cfgds[j].getName())) {
|
||||||
|
cfgsOK = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
action.setEnabled(cfgsOK && objects != null );
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run(IAction action) {
|
||||||
|
openDialog();
|
||||||
|
}
|
||||||
|
|
||||||
|
private ICConfigurationDescription[] getCfgsRead(IResource res) {
|
||||||
|
IProject p = res.getProject();
|
||||||
|
if (!p.isOpen()) 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.getString("ExcludeFromBuildAction.0")); //$NON-NLS-1$
|
||||||
|
dialog.setTitle(ActionMessages.getString("ExcludeFromBuildAction.1")); //$NON-NLS-1$
|
||||||
|
|
||||||
|
boolean[] status = new boolean[cfgNames.size()];
|
||||||
|
Iterator it = objects.iterator();
|
||||||
|
while(it.hasNext()) {
|
||||||
|
IResource res = (IResource)it.next();
|
||||||
|
ICConfigurationDescription[] cfgds = getCfgsRead(res);
|
||||||
|
IPath p = res.getProjectRelativePath();
|
||||||
|
for (int i=0; i<cfgds.length; i++) {
|
||||||
|
ICResourceDescription out = cfgds[i].getResourceDescription(p, false);
|
||||||
|
if (!out.isExcluded()) status[i] = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
ArrayList lst = new ArrayList();
|
||||||
|
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();
|
||||||
|
if (selected != null && selected.length > 0) {
|
||||||
|
Iterator it2 = objects.iterator();
|
||||||
|
outer:
|
||||||
|
while(it2.hasNext()) {
|
||||||
|
IResource res = (IResource)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();
|
||||||
|
IPath p2 = res.getProjectRelativePath();
|
||||||
|
for (int i=0; i<cfgds.length; i++) {
|
||||||
|
ICResourceDescription out = cfgds[i].getResourceDescription(p2, false);
|
||||||
|
if (! p2.equals(out.getPath()) ) {
|
||||||
|
try {
|
||||||
|
if (res instanceof IFolder)
|
||||||
|
out = cfgds[i].createFolderDescription(p2, (ICFolderDescription)out);
|
||||||
|
else
|
||||||
|
out = cfgds[i].createFileDescription(p2, out);
|
||||||
|
} catch (CoreException e) { continue outer; }
|
||||||
|
}
|
||||||
|
if (out != null) {
|
||||||
|
boolean exclude = false;
|
||||||
|
for (int j=0; j<selected.length; j++) {
|
||||||
|
if (cfgds[i].getName().equals(selected[j])) {
|
||||||
|
exclude = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
out.setExcluded(exclude);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
CoreModel.getDefault().setProjectDescription(p, prjd);
|
||||||
|
} catch (CoreException e) {}
|
||||||
|
|
||||||
|
}
|
||||||
|
AbstractPage.updateViews();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public void dispose() { objects = null; }
|
||||||
|
|
||||||
|
// doing nothing
|
||||||
|
public void init(IWorkbenchWindow window) { }
|
||||||
|
public Menu getMenu(Menu parent) { return null; }
|
||||||
|
public Menu getMenu(Control parent) { return null; }
|
||||||
|
public void setActivePart(IAction action, IWorkbenchPart targetPart) {}
|
||||||
|
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue