mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-06-08 18:26:01 +02:00
Patch from Oleg Smetanin: easy active build configuration selection
This commit is contained in:
parent
2f2ef46adc
commit
779174d197
6 changed files with 492 additions and 2 deletions
|
@ -1,5 +1,5 @@
|
|||
###############################################################################
|
||||
# Copyright (c) 2003, 2005 IBM Corporation and others.
|
||||
# Copyright (c) 2003, 2006 IBM 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
|
||||
|
@ -29,3 +29,10 @@ MngResourceProp.name=C/C++ Build
|
|||
|
||||
#The Project Converter page
|
||||
ConvertTargetAction.label=Convert To...
|
||||
|
||||
# Build configuration actions
|
||||
BuildConfigActionSet.label=Build Configuration
|
||||
BuildConfigToolbarAction.label=Active Build Configuration
|
||||
BuildConfigMenuAction.label=Active Buil&d Configuration
|
||||
BuildConfigContextAction.label=Active Bui&ld Configuration
|
||||
BuildConfigAction.tooltip=Change active build configuration for the current project
|
||||
|
|
|
@ -120,5 +120,57 @@
|
|||
value="org.eclipse.cdt.managedbuilder.core.managedBuildNature">
|
||||
</filter>
|
||||
</objectContribution>
|
||||
</extension>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.actionSets">
|
||||
<actionSet
|
||||
description="Build configuration for the current project"
|
||||
id="org.eclipse.cdt.managedbuilder.ui.buildConfigActionSet"
|
||||
label="%BuildConfigActionSet.label"
|
||||
visible="false">
|
||||
<action
|
||||
class="org.eclipse.cdt.managedbuilder.ui.actions.ChangeBuildConfigMenuAction"
|
||||
disabledIcon="icons/dlcl16/config-tool.gif"
|
||||
enablesFor="+"
|
||||
icon="icons/elcl16/config-tool.gif"
|
||||
id="org.eclipse.cdt.managedbuilder.ui.buildConfigToolbarAction"
|
||||
label="%BuildConfigToolbarAction.label"
|
||||
style="pulldown"
|
||||
toolbarPath="buildConfig"
|
||||
tooltip="%BuildConfigAction.tooltip"/>
|
||||
<action
|
||||
class="org.eclipse.cdt.managedbuilder.ui.actions.ChangeBuildConfigMenuAction"
|
||||
enablesFor="+"
|
||||
id="org.eclipse.cdt.managedbuilder.ui.buildConfigMenuAction"
|
||||
label="%BuildConfigMenuAction.label"
|
||||
menubarPath="project/build"
|
||||
style="pulldown"
|
||||
tooltip="%BuildConfigAction.tooltip"/>
|
||||
</actionSet>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.popupMenus">
|
||||
<objectContribution
|
||||
adaptable="true"
|
||||
id="org.eclipse.cdt.managedbuilder.ui.buildConfigContribution"
|
||||
objectClass="org.eclipse.core.resources.IResource">
|
||||
<action
|
||||
class="org.eclipse.cdt.managedbuilder.ui.actions.ChangeBuildConfigContextAction"
|
||||
enablesFor="+"
|
||||
id="org.eclipse.cdt.managedbuilder.ui.buildConfigPulldownAction"
|
||||
label="%BuildConfigContextAction.label"
|
||||
menubarPath="buildGroup"
|
||||
style="pulldown"
|
||||
tooltip="%BuildConfigAction.tooltip"/>
|
||||
<filter
|
||||
name="projectNature"
|
||||
value="org.eclipse.cdt.managedbuilder.core.managedBuildNature"/>
|
||||
</objectContribution>
|
||||
</extension>
|
||||
<extension
|
||||
point="org.eclipse.ui.perspectiveExtensions">
|
||||
<perspectiveExtension targetID="org.eclipse.cdt.ui.CPerspective">
|
||||
<actionSet id="org.eclipse.cdt.managedbuilder.ui.buildConfigActionSet"/>
|
||||
</perspectiveExtension>
|
||||
</extension>
|
||||
</plugin>
|
||||
|
|
|
@ -0,0 +1,62 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 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.managedbuilder.ui.actions;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.eclipse.cdt.managedbuilder.core.*;
|
||||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.jface.action.Action;
|
||||
|
||||
/**
|
||||
* Action which changes active build configuration of the current project to
|
||||
* the given one.
|
||||
*/
|
||||
public class BuildConfigAction extends Action {
|
||||
|
||||
private String fConfigName = null;
|
||||
private HashSet fProjects = null;
|
||||
|
||||
/**
|
||||
* Constructs the action.
|
||||
* @param projects List of selected managed-built projects
|
||||
* @param configName Build configuration name
|
||||
* @param accel Number to be used as accelerator
|
||||
*/
|
||||
public BuildConfigAction(HashSet projects, String configName, String displayName, int accel) {
|
||||
super("&" + accel + " " + displayName); //$NON-NLS-1$ //$NON-NLS-2$
|
||||
fProjects = projects;
|
||||
fConfigName = configName;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jface.action.IAction#run()
|
||||
*/
|
||||
public void run() {
|
||||
Iterator iter = fProjects.iterator();
|
||||
while (iter.hasNext()) {
|
||||
IManagedBuildInfo info = ManagedBuildManager.getBuildInfo((IProject)iter.next());
|
||||
IConfiguration[] configs = info.getManagedProject().getConfigurations();
|
||||
int i = 0;
|
||||
for (; i < configs.length; i++) {
|
||||
if (configs[i].getName().equals(fConfigName)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i != configs.length) {
|
||||
info.setDefaultConfiguration(configs[i]);
|
||||
info.setSelectedConfiguration(configs[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,212 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 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.managedbuilder.ui.actions;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
import org.eclipse.cdt.core.model.*;
|
||||
import org.eclipse.cdt.managedbuilder.core.*;
|
||||
import org.eclipse.core.resources.*;
|
||||
import org.eclipse.core.runtime.CoreException;
|
||||
import org.eclipse.jface.action.*;
|
||||
import org.eclipse.jface.viewers.*;
|
||||
import org.eclipse.swt.widgets.*;
|
||||
|
||||
/**
|
||||
* Base class for build configuration actions.
|
||||
*/
|
||||
public class ChangeBuildConfigActionBase {
|
||||
|
||||
/**
|
||||
* List of selected managed-built projects
|
||||
*/
|
||||
protected HashSet fProjects = new HashSet();
|
||||
|
||||
/**
|
||||
* Fills the menu with build configurations which are common for all selected projects
|
||||
* @param menu The menu to fill
|
||||
*/
|
||||
protected void fillMenu(Menu menu) {
|
||||
if (menu == null) {
|
||||
// This should not happen
|
||||
return;
|
||||
}
|
||||
|
||||
MenuItem[] items = menu.getItems();
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
items[i].dispose();
|
||||
}
|
||||
|
||||
TreeSet configNames = new TreeSet();
|
||||
Iterator projIter = fProjects.iterator();
|
||||
String sCurrentConfig = null;
|
||||
boolean bCurrentConfig = true;
|
||||
while (projIter.hasNext()) {
|
||||
IManagedBuildInfo info = ManagedBuildManager.getBuildInfo((IProject)projIter.next());
|
||||
if (bCurrentConfig) {
|
||||
String sNewConfig = info.getDefaultConfiguration().getName();
|
||||
if (sCurrentConfig == null) {
|
||||
sCurrentConfig = sNewConfig;
|
||||
}
|
||||
else {
|
||||
if (!sCurrentConfig.equals(sNewConfig)) {
|
||||
bCurrentConfig = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (info != null) {
|
||||
IConfiguration[] configs = info.getManagedProject().getConfigurations();
|
||||
for (int i = 0; i < configs.length; i++) {
|
||||
configNames.add(configs[i].getName());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Iterator confIter = configNames.iterator();
|
||||
int accel = 0;
|
||||
while (confIter.hasNext()) {
|
||||
String sName = (String)confIter.next();
|
||||
String sDesc = null;
|
||||
projIter = fProjects.iterator();
|
||||
boolean commonName = true;
|
||||
boolean commonDesc = true;
|
||||
boolean firstProj = true;
|
||||
while (projIter.hasNext()) {
|
||||
IManagedBuildInfo info = ManagedBuildManager.getBuildInfo((IProject)projIter.next());
|
||||
if (info != null) {
|
||||
IConfiguration[] configs = info.getManagedProject().getConfigurations();
|
||||
int i = 0;
|
||||
for (; i < configs.length; i++) {
|
||||
if (configs[i].getName().equals(sName)) {
|
||||
String sNewDesc = configs[i].getDescription();
|
||||
if (sNewDesc.equals("")) { //$NON-NLS-1$
|
||||
sNewDesc = null;
|
||||
}
|
||||
if (commonDesc) {
|
||||
if (firstProj) {
|
||||
sDesc = sNewDesc;
|
||||
firstProj = false;
|
||||
} else if (sNewDesc == null && sDesc != null || sNewDesc != null && !sNewDesc.equals(sDesc)) {
|
||||
commonDesc = false;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == configs.length) {
|
||||
commonName = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (commonName) {
|
||||
StringBuilder builder = new StringBuilder(sName);
|
||||
if (commonDesc) {
|
||||
if (sDesc != null) {
|
||||
builder.append(" ("); //$NON-NLS-1$
|
||||
builder.append(sDesc);
|
||||
builder.append(")"); //$NON-NLS-1$
|
||||
}
|
||||
} else {
|
||||
builder.append(" (...)"); //$NON-NLS-1$
|
||||
}
|
||||
|
||||
IAction action = new BuildConfigAction(fProjects, sName, builder.toString(), accel + 1);
|
||||
if (bCurrentConfig && sCurrentConfig.equals(sName)) {
|
||||
action.setChecked(true);
|
||||
}
|
||||
ActionContributionItem item = new ActionContributionItem(action);
|
||||
item.fill(menu, -1);
|
||||
accel++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* selectionChanged() event handler. Fills the list of managed-built projects
|
||||
* based on the selection. If some non-managed-built projects are selected,
|
||||
* disables the action.
|
||||
* @param action The action
|
||||
* @param selection The selection
|
||||
*/
|
||||
protected void onSelectionChanged(IAction action, ISelection selection) {
|
||||
fProjects.clear();
|
||||
|
||||
if (!action.isEnabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
boolean found = 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();
|
||||
}
|
||||
if (project != null) {
|
||||
try {
|
||||
if (project != null && !project.hasNature(ManagedCProjectNature.MNG_NATURE_ID)) {
|
||||
project = null;
|
||||
}
|
||||
}
|
||||
catch (CoreException xE) {
|
||||
// do nothing
|
||||
}
|
||||
}
|
||||
if (project != null) {
|
||||
fProjects.add(project);
|
||||
} else {
|
||||
found = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean enable = false;
|
||||
if (!found && !fProjects.isEmpty()) {
|
||||
Iterator iter = fProjects.iterator();
|
||||
IProject first = (IProject)iter.next();
|
||||
IConfiguration[] firstConfigs = ManagedBuildManager.getBuildInfo(first).getManagedProject().getConfigurations();
|
||||
for (int i = 0; i < firstConfigs.length; i++)
|
||||
{
|
||||
boolean common = true;
|
||||
iter = fProjects.iterator();
|
||||
while (iter.hasNext()) {
|
||||
IProject current = (IProject)iter.next();
|
||||
IConfiguration[] currentConfigs = ManagedBuildManager.getBuildInfo(current).getManagedProject().getConfigurations();
|
||||
int j = 0;
|
||||
for (; j < currentConfigs.length; j++) {
|
||||
if (firstConfigs[i].getName().equals(currentConfigs[j].getName())) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j == currentConfigs.length) {
|
||||
common = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (common) {
|
||||
enable = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
action.setEnabled(enable);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,74 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 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.managedbuilder.ui.actions;
|
||||
|
||||
import org.eclipse.jface.action.*;
|
||||
import org.eclipse.jface.viewers.ISelection;
|
||||
import org.eclipse.swt.events.*;
|
||||
import org.eclipse.swt.widgets.*;
|
||||
import org.eclipse.ui.*;
|
||||
|
||||
/**
|
||||
* This context menu action is used to change active build configuration for the project
|
||||
*/
|
||||
public class ChangeBuildConfigContextAction extends ChangeBuildConfigActionBase implements
|
||||
IMenuCreator, IObjectActionDelegate {
|
||||
|
||||
/**
|
||||
* @see org.eclipse.ui.IObjectActionDelegate#setActivePart(org.eclipse.jface.action.IAction, org.eclipse.ui.IWorkbenchPart)
|
||||
*/
|
||||
public void setActivePart(IAction action, IWorkbenchPart targetPart) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
|
||||
*/
|
||||
public void run(IAction action) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
|
||||
*/
|
||||
public void selectionChanged(IAction action, ISelection selection) {
|
||||
onSelectionChanged(action, selection);
|
||||
action.setMenuCreator(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jface.action.IMenuCreator#dispose()
|
||||
*/
|
||||
public void dispose() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jface.action.IMenuCreator#getMenu(org.eclipse.swt.widgets.Control)
|
||||
*/
|
||||
public Menu getMenu(Control parent) {
|
||||
// this method is never called
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.jface.action.IMenuCreator#getMenu(org.eclipse.swt.widgets.Menu)
|
||||
*/
|
||||
public Menu getMenu(Menu parent) {
|
||||
Menu menu = new Menu(parent);
|
||||
menu.addMenuListener(new MenuAdapter() {
|
||||
public void menuShown(MenuEvent e) {
|
||||
fillMenu((Menu)e.widget);
|
||||
}
|
||||
});
|
||||
return menu;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,83 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2006 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.managedbuilder.ui.actions;
|
||||
|
||||
import org.eclipse.jface.action.*;
|
||||
import org.eclipse.jface.viewers.*;
|
||||
import org.eclipse.core.resources.*;
|
||||
import org.eclipse.swt.events.*;
|
||||
import org.eclipse.swt.widgets.*;
|
||||
import org.eclipse.ui.*;
|
||||
|
||||
/**
|
||||
* Action which changes active build configuration of the current project
|
||||
*/
|
||||
public class ChangeBuildConfigMenuAction extends ChangeBuildConfigActionBase implements
|
||||
IWorkbenchWindowPulldownDelegate2 {
|
||||
|
||||
/**
|
||||
* @see org.eclipse.ui.IWorkbenchWindowPulldownDelegate2#getMenu(org.eclipse.swt.widgets.Menu)
|
||||
*/
|
||||
public Menu getMenu(Menu parent) {
|
||||
Menu menu = new Menu(parent);
|
||||
addMenuListener(menu);
|
||||
return menu;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.ui.IWorkbenchWindowPulldownDelegate#getMenu(org.eclipse.swt.widgets.Control)
|
||||
*/
|
||||
public Menu getMenu(Control parent) {
|
||||
Menu menu = new Menu(parent);
|
||||
addMenuListener(menu);
|
||||
return menu;
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.ui.IWorkbenchWindowActionDelegate#dispose()
|
||||
*/
|
||||
public void dispose() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.ui.IWorkbenchWindowActionDelegate#init(org.eclipse.ui.IWorkbenchWindow)
|
||||
*/
|
||||
public void init(IWorkbenchWindow window) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
|
||||
*/
|
||||
public void run(IAction action) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.eclipse.ui.IActionDelegate#selectionChanged(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
|
||||
*/
|
||||
public void selectionChanged(IAction action, ISelection selection) {
|
||||
onSelectionChanged(action, selection);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a listener to the given menu to repopulate it each time is is shown
|
||||
* @param menu The menu to add listener to
|
||||
*/
|
||||
private void addMenuListener(Menu menu) {
|
||||
menu.addMenuListener(new MenuAdapter() {
|
||||
public void menuShown(MenuEvent e) {
|
||||
fillMenu((Menu)e.widget);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue