mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-23 14:42:11 +02:00
Fix problem in configuration selection when MBS project cannot be loaded
This commit is contained in:
parent
70f115ea4d
commit
c63f679228
2 changed files with 279 additions and 274 deletions
|
@ -1,62 +1,64 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2006 Intel Corporation and others.
|
* Copyright (c) 2006 Intel Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Intel Corporation - initial API and implementation
|
* Intel Corporation - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.managedbuilder.ui.actions;
|
package org.eclipse.cdt.managedbuilder.ui.actions;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import org.eclipse.cdt.managedbuilder.core.*;
|
import org.eclipse.cdt.managedbuilder.core.*;
|
||||||
import org.eclipse.core.resources.IProject;
|
import org.eclipse.core.resources.IProject;
|
||||||
import org.eclipse.jface.action.Action;
|
import org.eclipse.jface.action.Action;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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.
|
||||||
*/
|
*/
|
||||||
public class BuildConfigAction extends Action {
|
public class BuildConfigAction extends Action {
|
||||||
|
|
||||||
private String fConfigName = null;
|
private String fConfigName = null;
|
||||||
private HashSet fProjects = null;
|
private HashSet fProjects = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs the action.
|
* Constructs the action.
|
||||||
* @param projects List of selected managed-built projects
|
* @param projects List of selected managed-built projects
|
||||||
* @param configName Build configuration name
|
* @param configName Build configuration name
|
||||||
* @param accel Number to be used as accelerator
|
* @param accel Number to be used as accelerator
|
||||||
*/
|
*/
|
||||||
public BuildConfigAction(HashSet projects, String configName, String displayName, int accel) {
|
public BuildConfigAction(HashSet projects, String configName, String displayName, int accel) {
|
||||||
super("&" + accel + " " + displayName); //$NON-NLS-1$ //$NON-NLS-2$
|
super("&" + accel + " " + displayName); //$NON-NLS-1$ //$NON-NLS-2$
|
||||||
fProjects = projects;
|
fProjects = projects;
|
||||||
fConfigName = configName;
|
fConfigName = configName;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @see org.eclipse.jface.action.IAction#run()
|
* @see org.eclipse.jface.action.IAction#run()
|
||||||
*/
|
*/
|
||||||
public void run() {
|
public void run() {
|
||||||
Iterator iter = fProjects.iterator();
|
Iterator iter = fProjects.iterator();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
IManagedBuildInfo info = ManagedBuildManager.getBuildInfo((IProject)iter.next());
|
IManagedBuildInfo info = ManagedBuildManager.getBuildInfo((IProject)iter.next());
|
||||||
IConfiguration[] configs = info.getManagedProject().getConfigurations();
|
if (info != null && info.isValid()) {
|
||||||
int i = 0;
|
IConfiguration[] configs = info.getManagedProject().getConfigurations();
|
||||||
for (; i < configs.length; i++) {
|
int i = 0;
|
||||||
if (configs[i].getName().equals(fConfigName)) {
|
for (; i < configs.length; i++) {
|
||||||
break;
|
if (configs[i].getName().equals(fConfigName)) {
|
||||||
}
|
break;
|
||||||
}
|
}
|
||||||
if (i != configs.length) {
|
}
|
||||||
info.setDefaultConfiguration(configs[i]);
|
if (i != configs.length) {
|
||||||
info.setSelectedConfiguration(configs[i]);
|
info.setDefaultConfiguration(configs[i]);
|
||||||
}
|
info.setSelectedConfiguration(configs[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -1,212 +1,215 @@
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* Copyright (c) 2006 Intel Corporation and others.
|
* Copyright (c) 2006 Intel Corporation and others.
|
||||||
* All rights reserved. This program and the accompanying materials
|
* All rights reserved. This program and the accompanying materials
|
||||||
* are made available under the terms of the Eclipse Public License v1.0
|
* are made available under the terms of the Eclipse Public License v1.0
|
||||||
* which accompanies this distribution, and is available at
|
* which accompanies this distribution, and is available at
|
||||||
* http://www.eclipse.org/legal/epl-v10.html
|
* http://www.eclipse.org/legal/epl-v10.html
|
||||||
*
|
*
|
||||||
* Contributors:
|
* Contributors:
|
||||||
* Intel Corporation - initial API and implementation
|
* Intel Corporation - initial API and implementation
|
||||||
*******************************************************************************/
|
*******************************************************************************/
|
||||||
package org.eclipse.cdt.managedbuilder.ui.actions;
|
package org.eclipse.cdt.managedbuilder.ui.actions;
|
||||||
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import org.eclipse.cdt.core.model.*;
|
import org.eclipse.cdt.core.model.*;
|
||||||
import org.eclipse.cdt.managedbuilder.core.*;
|
import org.eclipse.cdt.managedbuilder.core.*;
|
||||||
import org.eclipse.core.resources.*;
|
import org.eclipse.core.resources.*;
|
||||||
import org.eclipse.core.runtime.CoreException;
|
import org.eclipse.core.runtime.CoreException;
|
||||||
import org.eclipse.jface.action.*;
|
import org.eclipse.jface.action.*;
|
||||||
import org.eclipse.jface.viewers.*;
|
import org.eclipse.jface.viewers.*;
|
||||||
import org.eclipse.swt.widgets.*;
|
import org.eclipse.swt.widgets.*;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for build configuration actions.
|
* Base class for build configuration actions.
|
||||||
*/
|
*/
|
||||||
public class ChangeBuildConfigActionBase {
|
public class ChangeBuildConfigActionBase {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* List of selected managed-built projects
|
* List of selected managed-built projects
|
||||||
*/
|
*/
|
||||||
protected HashSet fProjects = new HashSet();
|
protected HashSet fProjects = new HashSet();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fills the menu with build configurations which are common for all selected projects
|
* Fills the menu with build configurations which are common for all selected projects
|
||||||
* @param menu The menu to fill
|
* @param menu The menu to fill
|
||||||
*/
|
*/
|
||||||
protected void fillMenu(Menu menu) {
|
protected void fillMenu(Menu menu) {
|
||||||
if (menu == null) {
|
if (menu == null) {
|
||||||
// This should not happen
|
// This should not happen
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
MenuItem[] items = menu.getItems();
|
MenuItem[] items = menu.getItems();
|
||||||
for (int i = 0; i < items.length; i++) {
|
for (int i = 0; i < items.length; i++) {
|
||||||
items[i].dispose();
|
items[i].dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
TreeSet configNames = new TreeSet();
|
TreeSet configNames = new TreeSet();
|
||||||
Iterator projIter = fProjects.iterator();
|
Iterator projIter = fProjects.iterator();
|
||||||
String sCurrentConfig = null;
|
String sCurrentConfig = null;
|
||||||
boolean bCurrentConfig = true;
|
boolean bCurrentConfig = true;
|
||||||
while (projIter.hasNext()) {
|
while (projIter.hasNext()) {
|
||||||
IManagedBuildInfo info = ManagedBuildManager.getBuildInfo((IProject)projIter.next());
|
IManagedBuildInfo info = ManagedBuildManager.getBuildInfo((IProject)projIter.next());
|
||||||
if (bCurrentConfig) {
|
if (info != null && info.isValid()) {
|
||||||
String sNewConfig = info.getDefaultConfiguration().getName();
|
if (bCurrentConfig) {
|
||||||
if (sCurrentConfig == null) {
|
String sNewConfig = info.getDefaultConfiguration().getName();
|
||||||
sCurrentConfig = sNewConfig;
|
if (sCurrentConfig == null) {
|
||||||
}
|
sCurrentConfig = sNewConfig;
|
||||||
else {
|
}
|
||||||
if (!sCurrentConfig.equals(sNewConfig)) {
|
else {
|
||||||
bCurrentConfig = false;
|
if (!sCurrentConfig.equals(sNewConfig)) {
|
||||||
}
|
bCurrentConfig = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (info != null) {
|
}
|
||||||
IConfiguration[] configs = info.getManagedProject().getConfigurations();
|
IConfiguration[] configs = info.getManagedProject().getConfigurations();
|
||||||
for (int i = 0; i < configs.length; i++) {
|
for (int i = 0; i < configs.length; i++) {
|
||||||
configNames.add(configs[i].getName());
|
configNames.add(configs[i].getName());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Iterator confIter = configNames.iterator();
|
Iterator confIter = configNames.iterator();
|
||||||
int accel = 0;
|
int accel = 0;
|
||||||
while (confIter.hasNext()) {
|
while (confIter.hasNext()) {
|
||||||
String sName = (String)confIter.next();
|
String sName = (String)confIter.next();
|
||||||
String sDesc = null;
|
String sDesc = null;
|
||||||
projIter = fProjects.iterator();
|
projIter = fProjects.iterator();
|
||||||
boolean commonName = true;
|
boolean commonName = true;
|
||||||
boolean commonDesc = true;
|
boolean commonDesc = true;
|
||||||
boolean firstProj = true;
|
boolean firstProj = true;
|
||||||
while (projIter.hasNext()) {
|
while (projIter.hasNext()) {
|
||||||
IManagedBuildInfo info = ManagedBuildManager.getBuildInfo((IProject)projIter.next());
|
IManagedBuildInfo info = ManagedBuildManager.getBuildInfo((IProject)projIter.next());
|
||||||
if (info != null) {
|
if (info != null && info.isValid()) {
|
||||||
IConfiguration[] configs = info.getManagedProject().getConfigurations();
|
IConfiguration[] configs = info.getManagedProject().getConfigurations();
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (; i < configs.length; i++) {
|
for (; i < configs.length; i++) {
|
||||||
if (configs[i].getName().equals(sName)) {
|
if (configs[i].getName().equals(sName)) {
|
||||||
String sNewDesc = configs[i].getDescription();
|
String sNewDesc = configs[i].getDescription();
|
||||||
if (sNewDesc.equals("")) { //$NON-NLS-1$
|
if (sNewDesc.equals("")) { //$NON-NLS-1$
|
||||||
sNewDesc = null;
|
sNewDesc = null;
|
||||||
}
|
}
|
||||||
if (commonDesc) {
|
if (commonDesc) {
|
||||||
if (firstProj) {
|
if (firstProj) {
|
||||||
sDesc = sNewDesc;
|
sDesc = sNewDesc;
|
||||||
firstProj = false;
|
firstProj = false;
|
||||||
} else if (sNewDesc == null && sDesc != null || sNewDesc != null && !sNewDesc.equals(sDesc)) {
|
} else if (sNewDesc == null && sDesc != null || sNewDesc != null && !sNewDesc.equals(sDesc)) {
|
||||||
commonDesc = false;
|
commonDesc = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (i == configs.length) {
|
if (i == configs.length) {
|
||||||
commonName = false;
|
commonName = false;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (commonName) {
|
if (commonName) {
|
||||||
StringBuffer builder = new StringBuffer(sName);
|
StringBuffer builder = new StringBuffer(sName);
|
||||||
if (commonDesc) {
|
if (commonDesc) {
|
||||||
if (sDesc != null) {
|
if (sDesc != null) {
|
||||||
builder.append(" ("); //$NON-NLS-1$
|
builder.append(" ("); //$NON-NLS-1$
|
||||||
builder.append(sDesc);
|
builder.append(sDesc);
|
||||||
builder.append(")"); //$NON-NLS-1$
|
builder.append(")"); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
builder.append(" (...)"); //$NON-NLS-1$
|
builder.append(" (...)"); //$NON-NLS-1$
|
||||||
}
|
}
|
||||||
|
|
||||||
IAction action = new BuildConfigAction(fProjects, sName, builder.toString(), accel + 1);
|
IAction action = new BuildConfigAction(fProjects, sName, builder.toString(), accel + 1);
|
||||||
if (bCurrentConfig && sCurrentConfig.equals(sName)) {
|
if (bCurrentConfig && sCurrentConfig.equals(sName)) {
|
||||||
action.setChecked(true);
|
action.setChecked(true);
|
||||||
}
|
}
|
||||||
ActionContributionItem item = new ActionContributionItem(action);
|
ActionContributionItem item = new ActionContributionItem(action);
|
||||||
item.fill(menu, -1);
|
item.fill(menu, -1);
|
||||||
accel++;
|
accel++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* selectionChanged() event handler. Fills the list of managed-built projects
|
* selectionChanged() event handler. Fills the list of managed-built projects
|
||||||
* based on the selection. If some non-managed-built projects are selected,
|
* based on the selection. If some non-managed-built projects are selected,
|
||||||
* disables the action.
|
* disables the action.
|
||||||
* @param action The action
|
* @param action The action
|
||||||
* @param selection The selection
|
* @param selection The selection
|
||||||
*/
|
*/
|
||||||
protected void onSelectionChanged(IAction action, ISelection selection) {
|
protected void onSelectionChanged(IAction action, ISelection selection) {
|
||||||
fProjects.clear();
|
fProjects.clear();
|
||||||
|
|
||||||
if (!action.isEnabled()) {
|
if (!action.isEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
if (selection != null && selection instanceof IStructuredSelection) {
|
if (selection != null && selection instanceof IStructuredSelection) {
|
||||||
Iterator iter = ((IStructuredSelection)selection).iterator();
|
Iterator iter = ((IStructuredSelection)selection).iterator();
|
||||||
while (iter.hasNext()) {
|
while (iter.hasNext()) {
|
||||||
Object selItem = iter.next();
|
Object selItem = iter.next();
|
||||||
IProject project = null;
|
IProject project = null;
|
||||||
if (selItem instanceof ICElement) {
|
if (selItem instanceof ICElement) {
|
||||||
ICProject cproject = ((ICElement)selItem).getCProject();
|
ICProject cproject = ((ICElement)selItem).getCProject();
|
||||||
if (cproject != null) {
|
if (cproject != null) {
|
||||||
project = cproject.getProject();
|
project = cproject.getProject();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (selItem instanceof IResource) {
|
else if (selItem instanceof IResource) {
|
||||||
project = ((IResource)selItem).getProject();
|
project = ((IResource)selItem).getProject();
|
||||||
}
|
}
|
||||||
if (project != null) {
|
if (project != null) {
|
||||||
try {
|
try {
|
||||||
if (project != null && !project.hasNature(ManagedCProjectNature.MNG_NATURE_ID)) {
|
if (project != null && !project.hasNature(ManagedCProjectNature.MNG_NATURE_ID)) {
|
||||||
project = null;
|
project = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (CoreException xE) {
|
catch (CoreException xE) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (project != null) {
|
if (project != null) {
|
||||||
fProjects.add(project);
|
IManagedBuildInfo info = ManagedBuildManager.getBuildInfo(project);
|
||||||
} else {
|
if (info != null && info.isValid()) {
|
||||||
found = true;
|
fProjects.add(project);
|
||||||
break;
|
}
|
||||||
}
|
} else {
|
||||||
}
|
found = true;
|
||||||
}
|
break;
|
||||||
|
}
|
||||||
boolean enable = false;
|
}
|
||||||
if (!found && !fProjects.isEmpty()) {
|
}
|
||||||
Iterator iter = fProjects.iterator();
|
|
||||||
IProject first = (IProject)iter.next();
|
boolean enable = false;
|
||||||
IConfiguration[] firstConfigs = ManagedBuildManager.getBuildInfo(first).getManagedProject().getConfigurations();
|
if (!found && !fProjects.isEmpty()) {
|
||||||
for (int i = 0; i < firstConfigs.length; i++)
|
Iterator iter = fProjects.iterator();
|
||||||
{
|
IProject first = (IProject)iter.next();
|
||||||
boolean common = true;
|
IConfiguration[] firstConfigs = ManagedBuildManager.getBuildInfo(first).getManagedProject().getConfigurations();
|
||||||
iter = fProjects.iterator();
|
for (int i = 0; i < firstConfigs.length; i++)
|
||||||
while (iter.hasNext()) {
|
{
|
||||||
IProject current = (IProject)iter.next();
|
boolean common = true;
|
||||||
IConfiguration[] currentConfigs = ManagedBuildManager.getBuildInfo(current).getManagedProject().getConfigurations();
|
iter = fProjects.iterator();
|
||||||
int j = 0;
|
while (iter.hasNext()) {
|
||||||
for (; j < currentConfigs.length; j++) {
|
IProject current = (IProject)iter.next();
|
||||||
if (firstConfigs[i].getName().equals(currentConfigs[j].getName())) {
|
IConfiguration[] currentConfigs = ManagedBuildManager.getBuildInfo(current).getManagedProject().getConfigurations();
|
||||||
break;
|
int j = 0;
|
||||||
}
|
for (; j < currentConfigs.length; j++) {
|
||||||
}
|
if (firstConfigs[i].getName().equals(currentConfigs[j].getName())) {
|
||||||
if (j == currentConfigs.length) {
|
break;
|
||||||
common = false;
|
}
|
||||||
break;
|
}
|
||||||
}
|
if (j == currentConfigs.length) {
|
||||||
}
|
common = false;
|
||||||
if (common) {
|
break;
|
||||||
enable = true;
|
}
|
||||||
break;
|
}
|
||||||
}
|
if (common) {
|
||||||
}
|
enable = true;
|
||||||
}
|
break;
|
||||||
action.setEnabled(enable);
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
action.setEnabled(enable);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue