mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-06 17:26:01 +02:00
Bug 230185 Add Clean All / selected configurations to project pop-up
This commit is contained in:
parent
c7f45478a9
commit
868b8f9a8a
7 changed files with 419 additions and 204 deletions
|
@ -4595,12 +4595,56 @@ public class ManagedBuildManager extends AbstractCExtension {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void buildConfigurations(IConfiguration[] configs, IBuilder builder, IProgressMonitor monitor, boolean allBuilders) throws CoreException{
|
public static void buildConfigurations(IConfiguration[] configs, IBuilder builder, IProgressMonitor monitor, boolean allBuilders) throws CoreException{
|
||||||
|
buildOrCleanConfigurations(configs, builder, monitor, allBuilders, IncrementalProjectBuilder.FULL_BUILD);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean the specified build configurations
|
||||||
|
* @param configs
|
||||||
|
* @param monitor
|
||||||
|
* @throws CoreException
|
||||||
|
* @since 7.0
|
||||||
|
*/
|
||||||
|
public static void cleanConfigurations(IConfiguration[] configs, IProgressMonitor monitor) throws CoreException{
|
||||||
|
cleanConfigurations(configs, null, monitor);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean the specified build configurations using the given builder
|
||||||
|
* @param configs
|
||||||
|
* @param builder
|
||||||
|
* @param monitor
|
||||||
|
* @throws CoreException
|
||||||
|
* @since 7.0
|
||||||
|
*/
|
||||||
|
public static void cleanConfigurations(IConfiguration[] configs, IBuilder builder, IProgressMonitor monitor) throws CoreException{
|
||||||
|
cleanConfigurations(configs, builder, monitor, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Clean the specified configurations
|
||||||
|
* @param configs
|
||||||
|
* @param builder
|
||||||
|
* @param monitor
|
||||||
|
* @param allBuilders
|
||||||
|
* @throws CoreException
|
||||||
|
* @since 7.0
|
||||||
|
*/
|
||||||
|
public static void cleanConfigurations(IConfiguration[] configs, IBuilder builder, IProgressMonitor monitor, boolean allBuilders) throws CoreException{
|
||||||
|
buildOrCleanConfigurations(configs, builder, monitor, allBuilders, IncrementalProjectBuilder.CLEAN_BUILD);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void buildOrCleanConfigurations(IConfiguration[] configs, IBuilder builder, IProgressMonitor monitor, boolean allBuilders, int buildKind) throws CoreException{
|
||||||
Map map = sortConfigs(configs);
|
Map map = sortConfigs(configs);
|
||||||
for(Iterator iter = map.entrySet().iterator(); iter.hasNext();){
|
for(Iterator iter = map.entrySet().iterator(); iter.hasNext();){
|
||||||
Map.Entry entry = (Map.Entry)iter.next();
|
Map.Entry entry = (Map.Entry)iter.next();
|
||||||
IProject proj = (IProject)entry.getKey();
|
IProject proj = (IProject)entry.getKey();
|
||||||
IConfiguration[] cfgs = (IConfiguration[])entry.getValue();
|
IConfiguration[] cfgs = (IConfiguration[])entry.getValue();
|
||||||
buildConfigurations(proj, cfgs, builder, monitor, allBuilders);
|
if(buildKind == IncrementalProjectBuilder.CLEAN_BUILD) {
|
||||||
|
cleanConfigurations(proj, cfgs, builder, monitor, allBuilders);
|
||||||
|
} else {
|
||||||
|
buildConfigurations(proj, cfgs, builder, monitor, allBuilders);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4668,6 +4712,46 @@ public class ManagedBuildManager extends AbstractCExtension {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void cleanConfigurations(final IProject project, final IConfiguration[] configs, IBuilder builder, final IProgressMonitor monitor, boolean allBuilders) throws CoreException{
|
||||||
|
final boolean runAllBuidlers = allBuilders;
|
||||||
|
final IManagedBuildInfo buildInfo = ManagedBuildManager.getBuildInfo(project);
|
||||||
|
IConfiguration savedCfg = buildInfo.getDefaultConfiguration();
|
||||||
|
IWorkspaceRunnable op = new IWorkspaceRunnable() {
|
||||||
|
|
||||||
|
/*
|
||||||
|
* (non-Javadoc)
|
||||||
|
*
|
||||||
|
* @see org.eclipse.core.resources.IWorkspaceRunnable#run(org.eclipse.core.runtime.IProgressMonitor)
|
||||||
|
*/
|
||||||
|
public void run(IProgressMonitor monitor) throws CoreException {
|
||||||
|
ICommand[] commands = project.getDescription().getBuildSpec();
|
||||||
|
int totalWork = (runAllBuidlers) ? commands.length * configs.length : configs.length;
|
||||||
|
|
||||||
|
// iterate through all configurations and clean them
|
||||||
|
monitor.beginTask("", totalWork); //$NON-NLS-1$
|
||||||
|
for (IConfiguration config : configs) {
|
||||||
|
buildInfo.setDefaultConfiguration(config);
|
||||||
|
if (runAllBuidlers) {
|
||||||
|
for (int i = 0; i < commands.length; i++) {
|
||||||
|
// currently the platform doesn't accept arguments for a builder to clean a project, thus arguments are null
|
||||||
|
project.build(IncrementalProjectBuilder.CLEAN_BUILD, commands[i].getBuilderName(), null, new SubProgressMonitor(monitor, 1));
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
project.build(IncrementalProjectBuilder.CLEAN_BUILD, CommonBuilder.BUILDER_ID, null, new SubProgressMonitor(monitor, 1));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
ResourcesPlugin.getWorkspace().run(op, monitor);
|
||||||
|
} finally {
|
||||||
|
// complete the progress monitor and restore default configuration
|
||||||
|
monitor.done();
|
||||||
|
buildInfo.setDefaultConfiguration(savedCfg);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
public static IBuilder getInternalBuilder(){
|
public static IBuilder getInternalBuilder(){
|
||||||
return getExtensionBuilder(INTERNAL_BUILDER_ID);
|
return getExtensionBuilder(INTERNAL_BUILDER_ID);
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,6 +54,7 @@ Environment=Environment
|
||||||
|
|
||||||
BuildCfgMenu.label=Build configurations
|
BuildCfgMenu.label=Build configurations
|
||||||
BuildMenu.label=Build
|
BuildMenu.label=Build
|
||||||
|
CleanMenu.label=Clean
|
||||||
|
|
||||||
Build.System.Wizard=Build System Wizard
|
Build.System.Wizard=Build System Wizard
|
||||||
Make.Project.Wizard=Make Project Wizard
|
Make.Project.Wizard=Make Project Wizard
|
||||||
|
|
|
@ -95,6 +95,13 @@
|
||||||
objectClass="org.eclipse.core.resources.IProject"
|
objectClass="org.eclipse.core.resources.IProject"
|
||||||
adaptable="true"
|
adaptable="true"
|
||||||
id="org.eclipse.cdt.managedbuilder.ui.popupMenu.BuildAll">
|
id="org.eclipse.cdt.managedbuilder.ui.popupMenu.BuildAll">
|
||||||
|
<action
|
||||||
|
class="org.eclipse.cdt.managedbuilder.internal.ui.actions.CleanAllAction"
|
||||||
|
enablesFor="+"
|
||||||
|
id="org.eclipse.cdt.managedbuilder.ui.cleanAllAction"
|
||||||
|
label="%CleanMenu.label"
|
||||||
|
menubarPath="org.eclipse.cdt.ui.cfgmenu/gm1"
|
||||||
|
style="pulldown"/>
|
||||||
<action
|
<action
|
||||||
class="org.eclipse.cdt.managedbuilder.ui.actions.BuildAllAction"
|
class="org.eclipse.cdt.managedbuilder.ui.actions.BuildAllAction"
|
||||||
enablesFor="+"
|
enablesFor="+"
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* 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
|
||||||
|
* LSI Corporation - added symmetric project clean action
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.managedbuilder.internal.ui.actions;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
|
||||||
|
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
|
||||||
|
import org.eclipse.cdt.managedbuilder.ui.properties.Messages;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Action which changes active build configuration of the current project to
|
||||||
|
* the given one.
|
||||||
|
*
|
||||||
|
* @noextend This class is not intended to be subclassed by clients.
|
||||||
|
* @noinstantiate This class is not intended to be instantiated by clients.
|
||||||
|
* @since 7.0
|
||||||
|
*/
|
||||||
|
public class CleanAllAction extends CommonBuildCleanAllAction {
|
||||||
|
@Override
|
||||||
|
protected String getTIP_ALL() { return Messages.getString("CleanAllAction.0");}//$NON-NLS-1$
|
||||||
|
@Override
|
||||||
|
protected String getLBL_ALL() { return Messages.getString("CleanAllAction.1");}//$NON-NLS-1$
|
||||||
|
@Override
|
||||||
|
protected String getJOB_MSG() { return Messages.getString("CleanAllAction.2");}//$NON-NLS-1$
|
||||||
|
@Override
|
||||||
|
protected String getERR_MSG() { return Messages.getString("CleanAllAction.3");}//$NON-NLS-1$
|
||||||
|
@Override
|
||||||
|
protected String getLBL_SEL() { return Messages.getString("CleanAllAction.4");}//$NON-NLS-1$
|
||||||
|
@Override
|
||||||
|
protected String getTIP_SEL() { return Messages.getString("CleanAllAction.5");}//$NON-NLS-1$
|
||||||
|
@Override
|
||||||
|
protected String getDLG_TEXT(){ return Messages.getString("CleanAllAction.6"); }//$NON-NLS-1$
|
||||||
|
@Override
|
||||||
|
protected String getDLG_TITLE(){ return Messages.getString("CleanAllAction.7");}//$NON-NLS-1$
|
||||||
|
@Override
|
||||||
|
protected void performAction(IConfiguration[] configs,
|
||||||
|
IProgressMonitor monitor) throws CoreException {
|
||||||
|
ManagedBuildManager.cleanConfigurations(configs, monitor);
|
||||||
|
}
|
||||||
|
}
|
|
@ -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
|
||||||
|
* LSI Corporation - added symmetric project clean action
|
||||||
|
*******************************************************************************/
|
||||||
|
package org.eclipse.cdt.managedbuilder.internal.ui.actions;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import org.eclipse.cdt.core.model.CoreModel;
|
||||||
|
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.managedbuilder.core.IConfiguration;
|
||||||
|
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
|
||||||
|
import org.eclipse.cdt.ui.CUIPlugin;
|
||||||
|
import org.eclipse.core.resources.IProject;
|
||||||
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
|
import org.eclipse.core.runtime.CoreException;
|
||||||
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
|
import org.eclipse.core.runtime.IStatus;
|
||||||
|
import org.eclipse.core.runtime.Status;
|
||||||
|
import org.eclipse.core.runtime.jobs.Job;
|
||||||
|
import org.eclipse.jface.action.Action;
|
||||||
|
import org.eclipse.jface.action.ActionContributionItem;
|
||||||
|
import org.eclipse.jface.action.IAction;
|
||||||
|
import org.eclipse.jface.action.IMenuCreator;
|
||||||
|
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.actions.ActionDelegate;
|
||||||
|
import org.eclipse.ui.dialogs.ListSelectionDialog;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Abstract action which builds or cleans the build configurations of the current project.
|
||||||
|
*
|
||||||
|
* @noextend This class is not intended to be subclassed by clients.
|
||||||
|
* @since 7.0
|
||||||
|
*/
|
||||||
|
public abstract class CommonBuildCleanAllAction extends ActionDelegate implements
|
||||||
|
IWorkbenchWindowPulldownDelegate2, IObjectActionDelegate, IMenuCreator {
|
||||||
|
|
||||||
|
protected ArrayList<IProject> projects = null;
|
||||||
|
private ActionContributionItem it_all = null;
|
||||||
|
private ActionContributionItem it_sel = null;
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Get message strings
|
||||||
|
*/
|
||||||
|
protected abstract String getTIP_ALL();
|
||||||
|
protected abstract String getLBL_ALL();
|
||||||
|
protected abstract String getJOB_MSG();
|
||||||
|
protected abstract String getERR_MSG();
|
||||||
|
protected abstract String getLBL_SEL();
|
||||||
|
protected abstract String getTIP_SEL();
|
||||||
|
protected abstract String getDLG_TEXT();
|
||||||
|
protected abstract String getDLG_TITLE();
|
||||||
|
/**
|
||||||
|
* Perform the requested build
|
||||||
|
* @param configs
|
||||||
|
* @param monitor
|
||||||
|
* @throws CoreException
|
||||||
|
*/
|
||||||
|
protected abstract void performAction(IConfiguration[] configs, IProgressMonitor monitor) throws CoreException;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void selectionChanged(IAction action, ISelection selection) {
|
||||||
|
projects = null;
|
||||||
|
|
||||||
|
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; i++) {
|
||||||
|
IProject prj = null;
|
||||||
|
if (obs[i] instanceof IProject)
|
||||||
|
prj = (IProject)obs[i];
|
||||||
|
else if (obs[i] instanceof ICProject)
|
||||||
|
prj = ((ICProject)obs[i]).getProject();
|
||||||
|
if (prj != null) {
|
||||||
|
if (!CoreModel.getDefault().isNewStyleProject(prj)) continue;
|
||||||
|
ICProjectDescription prjd = CoreModel.getDefault().getProjectDescription(prj, false);
|
||||||
|
if (prjd == null) continue;
|
||||||
|
ICConfigurationDescription[] cfgds = prjd.getConfigurations();
|
||||||
|
if (cfgds != null && cfgds.length > 0) {
|
||||||
|
if (projects == null) projects = new ArrayList<IProject>();
|
||||||
|
projects.add(prj);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
action.setEnabled(projects != null);
|
||||||
|
if (projects != null && it_sel != null)
|
||||||
|
it_sel.getAction().setEnabled(projects.size() == 1);
|
||||||
|
action.setMenuCreator(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run(IAction action) {} // do nothing - show menus only
|
||||||
|
public void setActivePart(IAction action, IWorkbenchPart targetPart) {}
|
||||||
|
|
||||||
|
// doing nothing
|
||||||
|
public void init(IWorkbenchWindow window) { }
|
||||||
|
|
||||||
|
private final class BuildCleanFilesJob extends Job {
|
||||||
|
Object[] cfs;
|
||||||
|
|
||||||
|
BuildCleanFilesJob(Object[] _cfs) {
|
||||||
|
super(getJOB_MSG() + ((ICConfigurationDescription)_cfs[0]).getProjectDescription().getName());
|
||||||
|
cfs = _cfs;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
protected IStatus run(IProgressMonitor monitor) {
|
||||||
|
IConfiguration[] cf = new IConfiguration[cfs.length];
|
||||||
|
for (int i=0; i<cfs.length; i++)
|
||||||
|
cf[i] = ManagedBuildManager.getConfigurationForDescription((ICConfigurationDescription)cfs[i]);
|
||||||
|
try {
|
||||||
|
performAction(cf, monitor);
|
||||||
|
} catch (CoreException e) {
|
||||||
|
return new Status(IStatus.ERROR, getERR_MSG(), e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
if (monitor.isCanceled()) {
|
||||||
|
return Status.CANCEL_STATUS;
|
||||||
|
}
|
||||||
|
monitor.done();
|
||||||
|
return Status.OK_STATUS;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* (non-Javadoc)
|
||||||
|
* @see org.eclipse.core.runtime.jobs.Job#belongsTo(java.lang.Object)
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public boolean belongsTo(Object family) {
|
||||||
|
return ResourcesPlugin.FAMILY_MANUAL_BUILD == family;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public Menu getMenu(Control parent) {
|
||||||
|
return fillMenu(new Menu(parent));
|
||||||
|
}
|
||||||
|
|
||||||
|
public Menu getMenu(Menu parent) {
|
||||||
|
return fillMenu(new Menu(parent));
|
||||||
|
}
|
||||||
|
protected Menu fillMenu(Menu menu) {
|
||||||
|
it_all = new ActionContributionItem(new LocalAction(true));
|
||||||
|
it_sel = new ActionContributionItem(new LocalAction(false));
|
||||||
|
if (projects != null)
|
||||||
|
it_sel.getAction().setEnabled(projects.size() == 1);
|
||||||
|
|
||||||
|
it_all.fill(menu, -1);
|
||||||
|
it_sel.fill(menu, -1);
|
||||||
|
|
||||||
|
return menu;
|
||||||
|
}
|
||||||
|
|
||||||
|
private class LocalAction extends Action {
|
||||||
|
boolean forAll;
|
||||||
|
LocalAction(boolean mode) {
|
||||||
|
super();
|
||||||
|
forAll = mode;
|
||||||
|
setText(forAll ? getLBL_ALL() : getLBL_SEL());
|
||||||
|
setToolTipText(forAll ? getTIP_ALL() : getTIP_SEL());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
if (projects == null || projects.isEmpty())
|
||||||
|
return;
|
||||||
|
Iterator<IProject> it = projects.iterator();
|
||||||
|
if (forAll) {
|
||||||
|
while(it.hasNext())
|
||||||
|
processProject(it.next());
|
||||||
|
} else {
|
||||||
|
if (it.hasNext())
|
||||||
|
processProject(it.next());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void processProject(IProject prj) {
|
||||||
|
ICProjectDescription prjd = CoreModel.getDefault().getProjectDescription(prj, false);
|
||||||
|
if (prjd == null) return;
|
||||||
|
Object[] cfgds = prjd.getConfigurations();
|
||||||
|
if (!forAll) cfgds = openDialog(cfgds);
|
||||||
|
if (cfgds == null || cfgds.length == 0) return;
|
||||||
|
Job buildCleanFilesJob = new BuildCleanFilesJob(cfgds);
|
||||||
|
buildCleanFilesJob.schedule();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Object[] openDialog(Object[] cfgds) {
|
||||||
|
if (cfgds == null || cfgds.length == 0) return null;
|
||||||
|
ListSelectionDialog dialog = new ListSelectionDialog(
|
||||||
|
CUIPlugin.getActiveWorkbenchShell(),
|
||||||
|
cfgds,
|
||||||
|
new IStructuredContentProvider() {
|
||||||
|
public Object[] getElements(Object inputElement) { return (Object[])inputElement; }
|
||||||
|
public void dispose() {}
|
||||||
|
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
|
||||||
|
},
|
||||||
|
new LabelProvider() {
|
||||||
|
@Override
|
||||||
|
public String getText(Object element) {
|
||||||
|
if (element == null || !(element instanceof ICConfigurationDescription)) return null;
|
||||||
|
return ((ICConfigurationDescription)element).getName();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
getDLG_TEXT());
|
||||||
|
dialog.setTitle(getDLG_TITLE());
|
||||||
|
dialog.setInitialSelections(cfgds);
|
||||||
|
return (dialog.open() == Window.OK) ? dialog.getResult() : null;
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,226 +7,54 @@
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Intel Corporation - initial API and implementation
|
* Intel Corporation - initial API and implementation
|
||||||
|
* LSI Corporation - added symmetric project clean action
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.managedbuilder.ui.actions;
|
package org.eclipse.cdt.managedbuilder.ui.actions;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.CoreModel;
|
|
||||||
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.managedbuilder.core.IConfiguration;
|
import org.eclipse.cdt.managedbuilder.core.IConfiguration;
|
||||||
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
|
import org.eclipse.cdt.managedbuilder.core.ManagedBuildManager;
|
||||||
|
import org.eclipse.cdt.managedbuilder.internal.ui.actions.CommonBuildCleanAllAction;
|
||||||
import org.eclipse.cdt.managedbuilder.ui.properties.Messages;
|
import org.eclipse.cdt.managedbuilder.ui.properties.Messages;
|
||||||
import org.eclipse.cdt.ui.CUIPlugin;
|
|
||||||
import org.eclipse.core.resources.IProject;
|
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
import org.eclipse.core.runtime.IProgressMonitor;
|
||||||
import org.eclipse.core.runtime.IStatus;
|
|
||||||
import org.eclipse.core.runtime.Status;
|
|
||||||
import org.eclipse.core.runtime.jobs.Job;
|
|
||||||
import org.eclipse.jface.action.Action;
|
|
||||||
import org.eclipse.jface.action.ActionContributionItem;
|
|
||||||
import org.eclipse.jface.action.IAction;
|
|
||||||
import org.eclipse.jface.action.IMenuCreator;
|
|
||||||
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.actions.ActionDelegate;
|
|
||||||
import org.eclipse.ui.dialogs.ListSelectionDialog;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
*
|
*
|
||||||
* @noextend This class is not intended to be subclassed by clients.
|
* @noextend This class is not intended to be subclassed by clients.
|
||||||
* @noinstantiate This class is not intended to be instantiated by clients.
|
* @noinstantiate This class is not intended to be instantiated by clients.
|
||||||
*/
|
*/
|
||||||
public class BuildAllAction extends ActionDelegate
|
public class BuildAllAction extends CommonBuildCleanAllAction {
|
||||||
implements IWorkbenchWindowPulldownDelegate2, IObjectActionDelegate, IMenuCreator {
|
/** @since 7.0 */
|
||||||
|
|
||||||
private static final String TIP_ALL = Messages.getString("BuildAllAction.0");//$NON-NLS-1$
|
|
||||||
private static final String LBL_ALL = Messages.getString("BuildAllAction.1");//$NON-NLS-1$
|
|
||||||
private static final String JOB_MSG = Messages.getString("BuildAllAction.2");//$NON-NLS-1$
|
|
||||||
private static final String ERR_MSG = Messages.getString("BuildAllAction.3");//$NON-NLS-1$
|
|
||||||
private static final String LBL_SEL = Messages.getString("BuildAllAction.4");//$NON-NLS-1$
|
|
||||||
private static final String TIP_SEL = Messages.getString("BuildAllAction.5");//$NON-NLS-1$
|
|
||||||
private static final String DLG_TEXT = Messages.getString("BuildAllAction.6");//$NON-NLS-1$
|
|
||||||
private static final String DLG_TITLE = Messages.getString("BuildAllAction.7");//$NON-NLS-1$
|
|
||||||
|
|
||||||
protected ArrayList<IProject> projects = null;
|
|
||||||
private ActionContributionItem it_all = null;
|
|
||||||
private ActionContributionItem it_sel = null;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void selectionChanged(IAction action, ISelection selection) {
|
protected String getTIP_ALL() { return Messages.getString("BuildAllAction.0");}//$NON-NLS-1$
|
||||||
projects = null;
|
/** @since 7.0 */
|
||||||
|
|
||||||
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; i++) {
|
|
||||||
IProject prj = null;
|
|
||||||
if (obs[i] instanceof IProject)
|
|
||||||
prj = (IProject)obs[i];
|
|
||||||
else if (obs[i] instanceof ICProject)
|
|
||||||
prj = ((ICProject)obs[i]).getProject();
|
|
||||||
if (prj != null) {
|
|
||||||
if (!CoreModel.getDefault().isNewStyleProject(prj)) continue;
|
|
||||||
ICProjectDescription prjd = CoreModel.getDefault().getProjectDescription(prj, false);
|
|
||||||
if (prjd == null) continue;
|
|
||||||
ICConfigurationDescription[] cfgds = prjd.getConfigurations();
|
|
||||||
if (cfgds != null && cfgds.length > 0) {
|
|
||||||
if (projects == null) projects = new ArrayList<IProject>();
|
|
||||||
projects.add(prj);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
action.setEnabled(projects != null);
|
|
||||||
if (projects != null && it_sel != null)
|
|
||||||
it_sel.getAction().setEnabled(projects.size() == 1);
|
|
||||||
action.setMenuCreator(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run(IAction action) {} // do nothing - show menus only
|
protected String getLBL_ALL() { return Messages.getString("BuildAllAction.1");}//$NON-NLS-1$
|
||||||
public void setActivePart(IAction action, IWorkbenchPart targetPart) {}
|
/** @since 7.0 */
|
||||||
|
|
||||||
// doing nothing
|
|
||||||
@Override
|
@Override
|
||||||
public void dispose() { }
|
protected String getJOB_MSG() { return Messages.getString("BuildAllAction.2");}//$NON-NLS-1$
|
||||||
public void init(IWorkbenchWindow window) { }
|
/** @since 7.0 */
|
||||||
|
@Override
|
||||||
private static final class BuildFilesJob extends Job {
|
protected String getERR_MSG() { return Messages.getString("BuildAllAction.3");}//$NON-NLS-1$
|
||||||
Object[] cfs;
|
/** @since 7.0 */
|
||||||
|
@Override
|
||||||
BuildFilesJob(Object[] _cfs) {
|
protected String getLBL_SEL() { return Messages.getString("BuildAllAction.4");}//$NON-NLS-1$
|
||||||
super(JOB_MSG + ((ICConfigurationDescription)_cfs[0]).getProjectDescription().getName());
|
/** @since 7.0 */
|
||||||
cfs = _cfs;
|
@Override
|
||||||
}
|
protected String getTIP_SEL() { return Messages.getString("BuildAllAction.5");}//$NON-NLS-1$
|
||||||
|
/** @since 7.0 */
|
||||||
/* (non-Javadoc)
|
@Override
|
||||||
* @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
|
protected String getDLG_TEXT(){ return Messages.getString("BuildAllAction.6"); }//$NON-NLS-1$
|
||||||
*/
|
/** @since 7.0 */
|
||||||
@Override
|
@Override
|
||||||
protected IStatus run(IProgressMonitor monitor) {
|
protected String getDLG_TITLE(){ return Messages.getString("BuildAllAction.7");}//$NON-NLS-1$
|
||||||
IConfiguration[] cf = new IConfiguration[cfs.length];
|
/** @since 7.0 */
|
||||||
for (int i=0; i<cfs.length; i++)
|
@Override
|
||||||
cf[i] = ManagedBuildManager.getConfigurationForDescription((ICConfigurationDescription)cfs[i]);
|
protected void performAction(IConfiguration[] configs,
|
||||||
try {
|
IProgressMonitor monitor) throws CoreException {
|
||||||
ManagedBuildManager.buildConfigurations(cf, monitor);
|
ManagedBuildManager.buildConfigurations(configs, monitor);
|
||||||
} catch (CoreException e) {
|
|
||||||
return new Status(IStatus.ERROR, ERR_MSG, e.getLocalizedMessage());
|
|
||||||
}
|
|
||||||
if (monitor.isCanceled()) {
|
|
||||||
return Status.CANCEL_STATUS;
|
|
||||||
}
|
|
||||||
monitor.done();
|
|
||||||
return Status.OK_STATUS;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* (non-Javadoc)
|
|
||||||
* @see org.eclipse.core.runtime.jobs.Job#belongsTo(java.lang.Object)
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public boolean belongsTo(Object family) {
|
|
||||||
return ResourcesPlugin.FAMILY_MANUAL_BUILD == family;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public Menu getMenu(Control parent) {
|
|
||||||
return fillMenu(new Menu(parent));
|
|
||||||
}
|
|
||||||
|
|
||||||
public Menu getMenu(Menu parent) {
|
|
||||||
return fillMenu(new Menu(parent));
|
|
||||||
}
|
|
||||||
protected Menu fillMenu(Menu menu) {
|
|
||||||
it_all = new ActionContributionItem(new LocalAction(true));
|
|
||||||
it_sel = new ActionContributionItem(new LocalAction(false));
|
|
||||||
|
|
||||||
if (projects != null)
|
|
||||||
it_sel.getAction().setEnabled(projects.size() == 1);
|
|
||||||
|
|
||||||
it_all.fill(menu, -1);
|
|
||||||
it_sel.fill(menu, -1);
|
|
||||||
|
|
||||||
return menu;
|
|
||||||
}
|
|
||||||
|
|
||||||
private class LocalAction extends Action {
|
|
||||||
boolean forAll;
|
|
||||||
LocalAction(boolean mode) {
|
|
||||||
super();
|
|
||||||
forAll = mode;
|
|
||||||
setText(forAll ? LBL_ALL : LBL_SEL);
|
|
||||||
setToolTipText(forAll ? TIP_ALL : TIP_SEL);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void run() {
|
|
||||||
if (projects == null || projects.isEmpty())
|
|
||||||
return;
|
|
||||||
Iterator<IProject> it = projects.iterator();
|
|
||||||
if (forAll) {
|
|
||||||
while(it.hasNext())
|
|
||||||
processProject(it.next());
|
|
||||||
} else {
|
|
||||||
if (it.hasNext())
|
|
||||||
processProject(it.next());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void processProject(IProject prj) {
|
|
||||||
ICProjectDescription prjd = CoreModel.getDefault().getProjectDescription(prj, false);
|
|
||||||
if (prjd == null) return;
|
|
||||||
Object[] cfgds = prjd.getConfigurations();
|
|
||||||
if (!forAll) cfgds = openDialog(cfgds);
|
|
||||||
if (cfgds == null || cfgds.length == 0) return;
|
|
||||||
Job buildFilesJob = new BuildFilesJob(cfgds);
|
|
||||||
buildFilesJob.schedule();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Object[] openDialog(Object[] cfgds) {
|
|
||||||
if (cfgds == null || cfgds.length == 0) return null;
|
|
||||||
ListSelectionDialog dialog = new ListSelectionDialog(
|
|
||||||
CUIPlugin.getActiveWorkbenchShell(),
|
|
||||||
cfgds,
|
|
||||||
new IStructuredContentProvider() {
|
|
||||||
public Object[] getElements(Object inputElement) { return (Object[])inputElement; }
|
|
||||||
public void dispose() {}
|
|
||||||
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
|
|
||||||
},
|
|
||||||
new LabelProvider() {
|
|
||||||
@Override
|
|
||||||
public String getText(Object element) {
|
|
||||||
if (element == null || !(element instanceof ICConfigurationDescription)) return null;
|
|
||||||
return ((ICConfigurationDescription)element).getName();
|
|
||||||
}
|
|
||||||
},
|
|
||||||
DLG_TEXT);
|
|
||||||
dialog.setTitle(DLG_TITLE);
|
|
||||||
dialog.setInitialSelections(cfgds);
|
|
||||||
return (dialog.open() == Window.OK) ? dialog.getResult() : null;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -100,6 +100,14 @@ BuildAllAction.4=Select...
|
||||||
BuildAllAction.5=Build selected configurations in parallel
|
BuildAllAction.5=Build selected configurations in parallel
|
||||||
BuildAllAction.6=Select configurations to build
|
BuildAllAction.6=Select configurations to build
|
||||||
BuildAllAction.7=Build configurations
|
BuildAllAction.7=Build configurations
|
||||||
|
CleanAllAction.0=Clean all project configurations in parallel
|
||||||
|
CleanAllAction.1=All
|
||||||
|
CleanAllAction.2=Cleaning project
|
||||||
|
CleanAllAction.3=Clean error
|
||||||
|
CleanAllAction.4=Select...
|
||||||
|
CleanAllAction.5=Clean selected configurations in parallel
|
||||||
|
CleanAllAction.6=Select configurations to clean
|
||||||
|
CleanAllAction.7=Clean configurations
|
||||||
PrefPage_NewCDTWizard.0=Settings will be applied to CDT new project wizard during project creation process
|
PrefPage_NewCDTWizard.0=Settings will be applied to CDT new project wizard during project creation process
|
||||||
WizardDefaultsTab.0=Show only supported toolchains, by default
|
WizardDefaultsTab.0=Show only supported toolchains, by default
|
||||||
WizardDefaultsTab.1=Group old-style toolchains to <Others> folder
|
WizardDefaultsTab.1=Group old-style toolchains to <Others> folder
|
||||||
|
|
Loading…
Add table
Reference in a new issue