1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 14:42:11 +02:00

Bug #125686 and related changes.

This commit is contained in:
Oleg Krasilnikov 2007-03-15 17:01:29 +00:00
parent 3fa2470a54
commit f720d9d47d
6 changed files with 268 additions and 59 deletions

View file

@ -389,7 +389,7 @@ public class ProblemsLabelDecorator implements ILabelDecorator, ILightweightLabe
ICResourceDescription out = cf[i].getResourceDescription(path, true);
if (out != null) result |= TICK_CONFIGURATION;
out = cf[i].getResourceDescription(path, false);
if (out.isExcluded()) result |= TICK_EXCLUDE;
if (out != null && out.isExcluded()) result |= TICK_EXCLUDE;
}
}
}

View file

@ -31,7 +31,6 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Preferences;
import org.eclipse.core.runtime.QualifiedName;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.dialogs.ProgressMonitorDialog;
import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.preference.IPreferencePageContainer;
@ -53,7 +52,6 @@ import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import org.eclipse.ui.IWorkbenchPropertyPage;
@ -99,28 +97,16 @@ implements
IPreferencePageContainer, // dynamic pages
ICPropertyProvider // utility methods for tabs
{
// Toggle this constant to <false>
// to hide "Manage configurations" button.
// Corresponding menu items and toolbar button
// will not be affected by this change.
private static final boolean ENABLE_MANAGE = true;
// All(Multiple) configuration support is now disabled
private static final boolean ENABLE_MULTI_CFG = false;
private static ArrayList pages = new ArrayList(5);
private static ICResourceDescription resd = null;
private static ICConfigurationDescription[] cfgDescs = null;
private static ICConfigurationDescription[] multiCfgs = null; // selected multi cfg
private static ICProjectDescription prjd = null;
private static int cfgIndex = 0;
private static boolean doneOK = false;
/*
* String constants
*/
private static final String PREFIX = "CLanguagesPropertyPage"; //$NON-NLS-1$
private static final String LABEL = PREFIX + ".label"; //$NON-NLS-1$
private static final String TIP = PREFIX + ".tip"; //$NON-NLS-1$
private static final String CONFIG_LABEL = LABEL + ".Configuration"; //$NON-NLS-1$
private static final String ALL_CONFS = PREFIX + ".selection.configuration.all"; //$NON-NLS-1$
private static final String CONF_TIP = TIP + ".config"; //$NON-NLS-1$
// tabs
private static final String EXTENSION_POINT_ID = "org.eclipse.cdt.ui.cPropertyTab"; //$NON-NLS-1$
public static final String ELEMENT_NAME = "tab"; //$NON-NLS-1$
@ -145,12 +131,11 @@ implements
*/
private boolean noContentOnPage = false;
protected boolean displayedConfig = false;
protected boolean isDirty = false;
protected IResource internalElement = null;
protected boolean isProject = false;
protected boolean isFolder = false;
protected boolean isFile = false;
protected boolean isMulti = false;
// tabs
TabFolder folder;
@ -245,7 +230,8 @@ implements
// Use the form layout inside the group composite
GridLayout ff = new GridLayout(3, false);
configGroup.setLayout(ff);
Label configLabel = ControlFactory.createLabel(configGroup, NewUIMessages.getResourceString(CONFIG_LABEL));
Label configLabel = new Label(configGroup, SWT.NONE);
configLabel.setText(NewUIMessages.getResourceString("AbstractPage.6")); //$NON-NLS-1$
configLabel.setLayoutData(new GridData(GridData.BEGINNING));
configSelector = new Combo(configGroup, SWT.READ_ONLY | SWT.DROP_DOWN);
@ -254,7 +240,6 @@ implements
handleConfigSelection();
}
});
configSelector.setToolTipText(NewUIMessages.getResourceString(CONF_TIP));
gd = new GridData(GridData.FILL);
gd.grabExcessHorizontalSpace = true;
gd.grabExcessVerticalSpace = true;
@ -263,9 +248,9 @@ implements
configSelector.setLayoutData(gd);
if (ENABLE_MANAGE) {
if (CDTPrefUtil.getBool(CDTPrefUtil.KEY_MANAGE)) {
manageButton = new Button(configGroup, SWT.PUSH);
manageButton.setText("Manage configurations"); //$NON-NLS-1$
manageButton.setText(NewUIMessages.getResourceString("AbstractPage.12")); //$NON-NLS-1$
gd = new GridData(GridData.END);
gd.widthHint = 150;
manageButton.setLayoutData(gd);
@ -285,7 +270,7 @@ implements
if (isForFolder() || isForFile()) {
excludeFromBuildCheck = new Button(configGroup, SWT.CHECK);
excludeFromBuildCheck.setText("Exclude resource from build"); //$NON-NLS-1$
excludeFromBuildCheck.setText(NewUIMessages.getResourceString("AbstractPage.7")); //$NON-NLS-1$
gd = new GridData(GridData.FILL_HORIZONTAL);
gd.horizontalSpan = 3;
excludeFromBuildCheck.setLayoutData(gd);
@ -358,43 +343,44 @@ implements
* Event Handlers
*/
private void handleConfigSelection() {
isMulti = false; // no multi config selection by default
// If there is nothing in config selection widget just bail
if (configSelector.getItemCount() == 0) return;
int selectionIndex = configSelector.getSelectionIndex();
if (selectionIndex == -1) return;
// Check if the user has selected the "all" configuration
String configName = configSelector.getItem(selectionIndex);
if (configName.equals(NewUIMessages.getResourceString(ALL_CONFS))) {
// This is the all config
// Check if the user has selected the "all / multiple" configuration
if (selectionIndex >= cfgDescs.length) {
if ((selectionIndex - cfgDescs.length) == 0) // all
multiCfgs = cfgDescs;
else {
ICConfigurationDescription[] mcfgs = ConfigMultiSelectionDialog.select(cfgDescs);
if (mcfgs == null || mcfgs.length == 0) {
// return back to previous selection, but not to multi !
if (cfgIndex >= cfgDescs.length) {
cfgIndex = 0;
configSelector.select(0);
cfgChanged(cfgDescs[0]);
} else {
configSelector.select(cfgIndex);
}
return;
}
multiCfgs = mcfgs;
}
isMulti = true;
// if tab does not support multi cfg,
// it will show 1st cfg, at least.
cfgChanged(multiCfgs[0]);
return;
} else {
ICConfigurationDescription newConfig = cfgDescs[selectionIndex];
if (newConfig != getResDesc()) {
// If the user has changed values, and is now switching configurations, prompt for saving
if (getResDesc() != null) {
if (isDirty) {
Shell shell = CUIPlugin.getActiveWorkbenchShell();
boolean shouldApply = MessageDialog.openQuestion(shell,
NewUIMessages.getResourceString("BuildPropertyPage.changes.save.title"), //$NON-NLS-1$
NewUIMessages.getFormattedString("BuildPropertyPage.changes.save.question", //$NON-NLS-1$
new String[] {getResDesc().getName(), newConfig.getName()}));
if (shouldApply) {
if (performOk()) {
isDirty = false;
} else {
MessageDialog.openWarning(shell,
NewUIMessages.getResourceString("BuildPropertyPage.changes.save.title"), //$NON-NLS-1$
NewUIMessages.getResourceString("BuildPropertyPage.changes.save.error")); //$NON-NLS-1$
}
}
}
}
// Set the new selected configuration
cfgIndex = selectionIndex;
cfgIndex = selectionIndex;
cfgChanged(newConfig);
}
}
return;
}
/**
@ -431,7 +417,7 @@ implements
try {
CoreModel.getDefault().setProjectDescription(getProject(), local_prjd);
} catch (CoreException e) {
System.out.println("setProjectDescription: " + e.getLocalizedMessage()); //$NON-NLS-1$
System.out.println(NewUIMessages.getResourceString("AbstractPage.11") + e.getLocalizedMessage()); //$NON-NLS-1$
}
updateViews(internalElement);
}
@ -441,7 +427,9 @@ implements
new ProgressMonitorDialog(getShell()).run(false, true, op);
} catch (InvocationTargetException e) {
Throwable e1 = e.getTargetException();
CUIPlugin.errorDialog(getShell(), "Cannot apply", "Internal error", e1, true); //$NON-NLS-1$ //$NON-NLS-2$
CUIPlugin.errorDialog(getShell(),
NewUIMessages.getResourceString("AbstractPage.8"), //$NON-NLS-1$
NewUIMessages.getResourceString("AbstractPage.9"), e1, true); //$NON-NLS-1$
} catch (InterruptedException e) {}
}
@ -485,6 +473,13 @@ implements
configSelector.add(cfgDescs[i].getName());
if (cfgDescs[i].isActive()) cfgIndex = i;
}
// Handling of All/Multiple configurations can be disabled
if (ENABLE_MULTI_CFG) {
if (cfgDescs.length > 1) // "All cfgs" - shown if at least 2 cfgs available
configSelector.add(NewUIMessages.getResourceString("AbstractPage.4")); //$NON-NLS-1$
if (cfgDescs.length > 2)// "Multi cfgs" - shown if at least 3 cfgs available
configSelector.add(NewUIMessages.getResourceString("AbstractPage.5")); //$NON-NLS-1$
}
configSelector.select(cfgIndex);
handleConfigSelection();
}
@ -617,7 +612,7 @@ implements
else
out = cf.createFileDescription(p, out);
} catch (CoreException e) {
System.out.println("Cannot create resource configuration for " + //$NON-NLS-1$
System.out.println(NewUIMessages.getResourceString("AbstractPage.10") + //$NON-NLS-1$
p.toOSString() + "\n" + e.getLocalizedMessage()); //$NON-NLS-1$
}
}
@ -696,7 +691,7 @@ implements
if (elements[k].getName().equals(ELEMENT_NAME)) {
if (loadTab(elements[k], parent)) return;
} else {
System.out.println("Cannot load " + elements[k].getName()); //$NON-NLS-1$
System.out.println(NewUIMessages.getResourceString("AbstractPage.13") + elements[k].getName()); //$NON-NLS-1$
}
}
}
@ -719,7 +714,8 @@ implements
try {
page = (ICPropertyTab) element.createExecutableExtension(CLASS_NAME);
} catch (CoreException e) {
System.out.println("Cannot create page: " + e.getLocalizedMessage()); //$NON-NLS-1$
System.out.println(NewUIMessages.getResourceString("AbstractPage.14") + //$NON-NLS-1$
e.getLocalizedMessage());
return false;
}
if (page == null) return false;
@ -783,7 +779,6 @@ implements
case ICPropertyTab.MANAGEDBUILDSTATE:
// generally, single-tabbed pages are not intended to handle this message
if (folder == null) return;
boolean willAdd = false;
TabItem[] ts = folder.getItems();
int x = folder.getSelectionIndex();
@ -847,7 +842,7 @@ implements
// override parent's method to use proper class
public IAdaptable getElement() {
if (internalElement == null && !checkElement())
throw (new NullPointerException("element not initialized !")); //$NON-NLS-1$
throw (new NullPointerException(NewUIMessages.getResourceString("AbstractPage.15"))); //$NON-NLS-1$
return internalElement;
}
@ -856,6 +851,9 @@ implements
public boolean isForFile() { return isFile; }
public boolean isForPrefs() { return false; }
public boolean isMultiCfg() { return isMulti; }
public ICConfigurationDescription[] getMultiCfg() { return (isMulti) ? multiCfgs : null; }
/**
* Checks whether CDT property pages can be open for given object.
* In particular, header files and text files are not allowed.

View file

@ -0,0 +1,72 @@
/*******************************************************************************
* 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.newui;
import java.util.Arrays;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import org.eclipse.cdt.ui.CUIPlugin;
import org.eclipse.jface.preference.IPreferenceStore;
public class CDTPrefUtil {
public static final String KEY_UNSUPP = "wizard.default.show.unsupported"; //$NON-NLS-1$
public static final String KEY_OTHERS = "wizard.default.group.others"; //$NON-NLS-1$
public static final String KEY_PREFTC = "wizard.preferred.toolchains"; //$NON-NLS-1$
public static final String KEY_MANAGE = "properties.manage.config.button"; //$NON-NLS-1$
public static final String NULL = "NULL"; //$NON-NLS-1$
private static final IPreferenceStore pref = CUIPlugin.getDefault().getPreferenceStore();
private static final String DELIMITER = " "; //$NON-NLS-1$
private static LinkedList preferredTCs = null;
// low-level methods
public static boolean getBool(String key) { return pref.getBoolean(key); }
public static void setBool(String key, boolean val) { pref.setValue(key, val); }
public static int getInt(String key) { return pref.getInt(key); }
public static void setInt(String key, int val) { pref.setValue(key, val); }
public static String getStr(String key) { return pref.getString(key); }
public static void setStr(String key, String val) { pref.setValue(key, val); }
// up-level methods
public static void readPreferredTCs() {
preferredTCs = new LinkedList(Arrays.asList(getStr(KEY_PREFTC).split(DELIMITER)));
}
public static List getPreferredTCs() {
if (preferredTCs == null) readPreferredTCs();
return preferredTCs;
}
public static void delPreferredTC(String s) {
if (preferredTCs == null) readPreferredTCs();
preferredTCs.remove(s);
}
public static void addPreferredTC(String s) {
if (preferredTCs == null) readPreferredTCs();
if (!preferredTCs.contains(s)) preferredTCs.add(s);
}
public static void cleanPreferredTCs() {
setStr(KEY_PREFTC, IPreferenceStore.STRING_DEFAULT_DEFAULT);
readPreferredTCs();
}
public static void savePreferredTCs() {
if (preferredTCs == null) return;
Iterator it = preferredTCs.iterator();
StringBuffer b = new StringBuffer();
while (it.hasNext()) {
String s = (String)it.next();
if (s == null) continue;
b.append(s);
b.append(DELIMITER);
}
setStr(KEY_PREFTC, b.toString().trim());
}
}

View file

@ -0,0 +1,126 @@
/*******************************************************************************
* Copyright (c) 2002, 2007 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
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* IBM Rational Software - Initial API and implementation
*******************************************************************************/
package org.eclipse.cdt.ui.newui;
import org.eclipse.jface.dialogs.Dialog;
import org.eclipse.jface.dialogs.IDialogConstants;
import org.eclipse.jface.viewers.CheckStateChangedEvent;
import org.eclipse.jface.viewers.CheckboxTableViewer;
import org.eclipse.jface.viewers.ICheckStateListener;
import org.eclipse.jface.viewers.ILabelProviderListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.ITableLabelProvider;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Table;
import org.eclipse.swt.widgets.TableColumn;
import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
import org.eclipse.cdt.ui.CUIPlugin;
public class ConfigMultiSelectionDialog extends Dialog {
static private ICConfigurationDescription[] cfgds;
private Table table;
private CheckboxTableViewer tv;
private Button b_ok;
private Label message;
public static ICConfigurationDescription[] select(ICConfigurationDescription[] _cfgds) {
cfgds = _cfgds;
ConfigMultiSelectionDialog d = new ConfigMultiSelectionDialog(CUIPlugin.getActiveWorkbenchShell());
if (d.open() == OK)
return (ICConfigurationDescription[])d.tv.getCheckedElements();
return null;
}
public ConfigMultiSelectionDialog(Shell parentShell) { super(parentShell); }
protected void configureShell(Shell shell) {
super.configureShell(shell);
shell.setText(NewUIMessages.getResourceString("ConfigMultiSelectionDialog.0")); //$NON-NLS-1$
}
/**
* Method is overridden to disable "OK" button at start
*/
protected Control createContents(Composite parent) {
Control out = super.createContents(parent);
b_ok = getButton(IDialogConstants.OK_ID);
b_ok.setEnabled(false);
return out;
}
/* (non-Javadoc)
* @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
*/
protected Control createDialogArea(Composite parent) {
Composite composite = new Composite(parent, SWT.NULL);
composite.setFont(parent.getFont());
composite.setLayout(new GridLayout(1, true));
composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
// Create the current config table
table = new Table(composite, SWT.CHECK | SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL | SWT.FULL_SELECTION);
table.setLayoutData(new GridData(GridData.FILL));
table.setHeaderVisible(true);
table.setLinesVisible(true);
message = new Label(composite, SWT.NONE);
message.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
message.setText(NewUIMessages.getResourceString("ConfigMultiSelectionDialog.1")); //$NON-NLS-1$
message.setForeground(composite.getDisplay().getSystemColor(SWT.COLOR_RED));
TableColumn col = new TableColumn(table, SWT.NONE);
col.setText(NewUIMessages.getResourceString("ManageConfigDialog.1")); //$NON-NLS-1$
col.setWidth(100);
col = new TableColumn(table, SWT.NONE);
col.setText(NewUIMessages.getResourceString("ManageConfigDialog.2")); //$NON-NLS-1$
col.setWidth(120);
tv = new CheckboxTableViewer(table);
tv.setContentProvider(new IStructuredContentProvider() {
public Object[] getElements(Object inputElement) { return cfgds; }
public void dispose() {}
public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {}
});
tv.addCheckStateListener(new ICheckStateListener() {
public void checkStateChanged(CheckStateChangedEvent e) {
boolean enabled = (tv.getCheckedElements().length > 1);
if (b_ok != null) b_ok.setEnabled(enabled);
message.setVisible(!enabled);
}});
tv.setLabelProvider(new ITableLabelProvider() {
public Image getColumnImage(Object element, int columnIndex) { return null; }
public void addListener(ILabelProviderListener listener) {}
public void dispose() {}
public boolean isLabelProperty(Object element, String property) { return false;}
public void removeListener(ILabelProviderListener listener) {}
public String getColumnText(Object element, int index) {
ICConfigurationDescription cfg = (ICConfigurationDescription)element;
if (index == 0) return cfg.getName();
if (index == 1) return cfg.getDescription();
return AbstractPage.EMPTY_STR;
}});
tv.setInput(cfgds);
table.setFocus();
return composite;
}
}

View file

@ -63,4 +63,7 @@ public interface ICPropertyProvider extends ICOptionContainer {
// Checks whether a project is new CDT model-style
boolean isCDTProject(IProject p);
boolean isMultiCfg();
ICConfigurationDescription[] getMultiCfg();
}

View file

@ -420,9 +420,19 @@ AbstractCPropertyTab.0=Select build variable
AbstractCPropertyTab.1=Variables...
AbstractPage.0=Unknown element selected
AbstractPage.1=This file has no properties to display
AbstractPage.12=Manage configurations
AbstractPage.11=setProjectDescription:
AbstractPage.10=Cannot create resource configuration for
AbstractPage.13=Cannot load
AbstractPage.14=Cannot create page:
AbstractPage.15=element not initialized \!
AbstractPage.2=This project is not a CDT project
AbstractPage.4=[ All configurations ]
AbstractPage.5=[ Multiple configurations...]
AbstractPage.6=Configuration:
AbstractPage.7=Exclude resource from build
AbstractPage.8=Cannot apply
AbstractPage.9=Internal error
AbstractLangsListTab.0=Show built-in values
AbstractLangsListTab.1=Languages