diff --git a/core/org.eclipse.cdt.ui/icons/obj16/config.gif b/core/org.eclipse.cdt.ui/icons/obj16/config.gif
new file mode 100644
index 00000000000..c984fba7039
Binary files /dev/null and b/core/org.eclipse.cdt.ui/icons/obj16/config.gif differ
diff --git a/core/org.eclipse.cdt.ui/plugin.properties b/core/org.eclipse.cdt.ui/plugin.properties
index f7561adcaba..1d4804fb00b 100644
--- a/core/org.eclipse.cdt.ui/plugin.properties
+++ b/core/org.eclipse.cdt.ui/plugin.properties
@@ -500,3 +500,4 @@ cEditorHyperlinkTarget= C/C++ Editor
cElementHyperlinkDetector= C/C++ Elements
keybinding.MSVS= Microsoft Visual Studio
+wsselection= Configs for Working set
diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml
index cd41b1a9982..75211f6f31f 100644
--- a/core/org.eclipse.cdt.ui/plugin.xml
+++ b/core/org.eclipse.cdt.ui/plugin.xml
@@ -1298,6 +1298,12 @@
+
+
+
+
+
+
+
+
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java
index abf87f00284..0dae6e87673 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginImages.java
@@ -91,6 +91,7 @@ public class CPluginImages {
public static final String IMG_OBJS_TUNIT_RESOURCE_A= NAME_PREFIX + "asm_resource_obj.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_SOURCE_ROOT= NAME_PREFIX + "sroot_obj.gif"; // $NON-NLS-1$ //$NON-NLS-1$
public static final String IMG_OBJS_CFOLDER= NAME_PREFIX + "cfolder_obj.gif"; // $NON-NLS-1$ //$NON-NLS-1$
+ public static final String IMG_OBJS_CONFIG = NAME_PREFIX + "config.gif"; // $NON-NLS-1$ //$NON-NLS-1$
public static final String IMG_OBJS_ARCHIVE= NAME_PREFIX + "ar_obj.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_BINARY= NAME_PREFIX + "bin_obj.gif"; //$NON-NLS-1$
public static final String IMG_OBJS_SHLIB= NAME_PREFIX + "shlib_obj.gif"; //$NON-NLS-1$
@@ -172,6 +173,7 @@ public class CPluginImages {
public static final ImageDescriptor DESC_OBJS_TUNIT_RESOURCE_A= createManaged(T_OBJ, IMG_OBJS_TUNIT_RESOURCE_A);
public static final ImageDescriptor DESC_OBJS_SOURCE_ROOT= createManaged(T_OBJ, IMG_OBJS_SOURCE_ROOT);
public static final ImageDescriptor DESC_OBJS_CFOLDER= createManaged(T_OBJ, IMG_OBJS_CFOLDER);
+ public static final ImageDescriptor DESC_OBJS_CONFIG = createManaged(T_OBJ, IMG_OBJS_CONFIG);
public static final ImageDescriptor DESC_OBJS_ARCHIVE= createManaged(T_OBJ, IMG_OBJS_ARCHIVE);
public static final ImageDescriptor DESC_OBJS_ARCHIVE_WSRC= createManaged(T_OBJ, IMG_OBJS_ARCHIVE);
public static final ImageDescriptor DESC_OBJS_BINARY= createManaged(T_OBJ, IMG_OBJS_BINARY);
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/WorkingSetConfigAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/WorkingSetConfigAction.java
new file mode 100644
index 00000000000..8547e6bf369
--- /dev/null
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/actions/WorkingSetConfigAction.java
@@ -0,0 +1,552 @@
+/**
+ *
+ */
+package org.eclipse.cdt.ui.actions;
+
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.Map;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IAdaptable;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.dialogs.IDialogConstants;
+import org.eclipse.jface.dialogs.IInputValidator;
+import org.eclipse.jface.dialogs.InputDialog;
+import org.eclipse.jface.dialogs.TrayDialog;
+import org.eclipse.jface.util.IPropertyChangeListener;
+import org.eclipse.jface.util.PropertyChangeEvent;
+import org.eclipse.jface.viewers.ISelection;
+import org.eclipse.jface.window.Window;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.accessibility.AccessibleAdapter;
+import org.eclipse.swt.accessibility.AccessibleEvent;
+import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.events.SelectionAdapter;
+import org.eclipse.swt.events.SelectionEvent;
+import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.events.TreeEvent;
+import org.eclipse.swt.events.TreeListener;
+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.List;
+import org.eclipse.swt.widgets.MessageBox;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.IWorkbenchWindowActionDelegate;
+import org.eclipse.ui.IWorkingSet;
+import org.eclipse.ui.IWorkingSetManager;
+import org.eclipse.ui.PlatformUI;
+
+import org.eclipse.cdt.core.model.CoreModel;
+import org.eclipse.cdt.core.settings.model.ICConfigurationDescription;
+import org.eclipse.cdt.core.settings.model.ICProjectDescription;
+import org.eclipse.cdt.ui.CUIPlugin;
+import org.eclipse.cdt.ui.newui.CDTHelpContextIds;
+import org.eclipse.cdt.ui.newui.CDTPrefUtil;
+import org.eclipse.cdt.ui.newui.UIMessages;
+
+import org.eclipse.cdt.internal.ui.CPluginImages;
+
+/**
+ */
+public class WorkingSetConfigAction implements IWorkbenchWindowActionDelegate, IPropertyChangeListener {
+ private static final String DELIMITER = " "; //$NON-NLS-1$
+ private static final String EMPTY_STR = ""; //$NON-NLS-1$
+ private static final String CURRENT = UIMessages.getString("WorkingSetConfigAction.10"); //$NON-NLS-1$
+ public static final Image IMG_PROJ = CPluginImages.get(CPluginImages.IMG_OBJS_CFOLDER);
+ public static final Image IMG_CONF = CPluginImages.get(CPluginImages.IMG_OBJS_CONFIG);
+ private static final Shell sh = CUIPlugin.getDefault().getShell();
+ private static final IWorkingSetManager wsm = CUIPlugin.getDefault().getWorkbench().getWorkingSetManager();
+ private LinkedHashMap workingSetsMap;
+ private LinkedHashMap configSetMap;
+ private boolean enabled = true;
+
+ public void run(IAction action) {
+ LocalDialog dlg = new LocalDialog(sh);
+ dlg.open();
+ }
+
+ public void selectionChanged(IAction action, ISelection selection) {
+ if (action.isEnabled() != enabled)
+ action.setEnabled(enabled);
+ }
+ public void dispose() {
+ wsm.removePropertyChangeListener(this);
+
+ }
+ public void init(IWorkbenchWindow window) {
+ wsm.addPropertyChangeListener(this);
+ checkWS();
+ }
+
+ private IWorkingSet[] checkWS() {
+ IWorkingSet[] w = wsm.getWorkingSets();
+ if (w == null)
+ w = new IWorkingSet[0];
+ enabled = w.length > 0;
+ return w;
+ }
+
+ private String[] getWSnames() {
+ IWorkingSet[] w = checkWS();
+ workingSetsMap = new LinkedHashMap(w.length);
+ for (IWorkingSet ws : w)
+ workingSetsMap.put(ws.getLabel(), ws);
+ return workingSetsMap.keySet().toArray(new String[w.length]);
+ }
+
+ public void propertyChange(PropertyChangeEvent event) {
+ checkWS();
+ }
+
+ private class LocalDialog extends TrayDialog {
+ private List wsets;
+ private List csets;
+ private Tree tree;
+ private Button b1, b2, b3, b4;
+
+ LocalDialog(Shell parentShell) {
+ super(parentShell);
+ setHelpAvailable(false);
+ setShellStyle(getShellStyle()|SWT.RESIZE);
+ }
+ @Override
+ protected void buttonPressed(int buttonId) {
+ if (buttonId == IDialogConstants.OK_ID) {
+ saveConfigSets();
+ saveActiveConfigs();
+ } else {}
+ super.buttonPressed(buttonId);
+ }
+
+ private void saveConfigSets() {
+ ArrayList out = new ArrayList(configSetMap.size());
+ for (ConfigSet cs : configSetMap.values())
+ if (cs.isValid() && !cs.name.equals(CURRENT))
+ out.add(cs.toString());
+ CDTPrefUtil.saveConfigSets(out);
+ }
+
+ private void saveActiveConfigs() {
+ for (TreeItem ti : tree.getItems()) {
+ ICProjectDescription pd = (ICProjectDescription)ti.getData();
+ for (TreeItem ti1: ti.getItems()) {
+ if (!ti1.getChecked())
+ continue;
+ ((ICConfigurationDescription)ti1.getData()).setActive();
+ break;
+ }
+ try {
+ CoreModel.getDefault().setProjectDescription(pd.getProject(), pd);
+ } catch (CoreException e) {
+ e.printStackTrace();
+ CUIPlugin.log(e);
+ }
+ }
+ }
+
+ @Override
+ protected void configureShell(Shell shell) {
+ super.configureShell(shell);
+ shell.setText(UIMessages.getString("WorkingSetConfigAction.1")); //$NON-NLS-1$
+ }
+
+ @Override
+ protected Control createDialogArea(Composite parent) {
+ PlatformUI.getWorkbench().getHelpSystem().setHelp( getShell(), CDTHelpContextIds.MAN_PROJ_BUILD_PROP);
+
+ Composite comp = new Composite(parent, SWT.NULL);
+ comp.setFont(parent.getFont());
+ comp.setLayout(new GridLayout(2, false));
+ comp.setLayoutData(new GridData(GridData.FILL_BOTH));
+
+ // Create the sash form
+ SashForm sashForm = new SashForm(comp, SWT.NONE);
+ sashForm.setOrientation(SWT.VERTICAL);
+ GridData gd = new GridData(GridData.FILL_VERTICAL);
+ gd.verticalSpan = 3;
+ sashForm.setLayoutData(gd);
+
+ Composite ws = new Composite(sashForm, SWT.NULL);
+ ws.setLayoutData(new GridData(GridData.FILL_BOTH));
+ ws.setLayout(new GridLayout(1, false));
+ Label l1 = new Label(ws, SWT.NONE);
+ l1.setText(UIMessages.getString("WorkingSetConfigAction.2")); //$NON-NLS-1$
+ l1.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
+ wsets = new List(ws, SWT.SINGLE | SWT.BORDER);
+ wsets.setLayoutData(new GridData(GridData.FILL_BOTH));
+ wsets.setItems(getWSnames());
+
+ wsets.addSelectionListener(new SelectionListener() {
+ public void widgetDefaultSelected(SelectionEvent e) {
+ workingSetChanged();
+ }
+ public void widgetSelected(SelectionEvent e) {
+ workingSetChanged();
+ }});
+
+ if (wsets.getItemCount() == 0) {
+ wsets.add(UIMessages.getString("WorkingSetConfigAction.3")); //$NON-NLS-1$
+ wsets.setEnabled(false);
+ } else {
+ IWorkingSet[] w = wsm.getRecentWorkingSets();
+ if (w == null || w.length == 0)
+ wsets.setSelection(0);
+ else {
+ String s = w[0].getLabel();
+ String[] ss = wsets.getItems();
+ for (int i=0; i 0) {
+ String oldS = csets.getItem(n);
+ String newS = getString(UIMessages.getString("WorkingSetConfigAction.19"), oldS); //$NON-NLS-1$
+ if (newS == null)
+ return;
+ if (oldS.equals(newS)) // nothing to do
+ return;
+ String key = wsets.getSelection()[0] + DELIMITER + newS;
+ if (configSetMap.containsKey(key)) {
+ ExistsMessage(newS);
+ return;
+ }
+ ConfigSet cs = configSetMap.get(wsets.getSelection()[0] + DELIMITER + oldS);
+ configSetMap.remove(cs);
+ cs.name = newS;
+ configSetMap.put(key, cs);
+ csets.setItem(n, newS);
+ }
+ }});
+
+ b4 = new Button(c, SWT.PUSH);
+ b4.setText(UIMessages.getString("WorkingSetConfigAction.9")); //$NON-NLS-1$
+ b4.setLayoutData(new GridData(GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL));
+ b4.addSelectionListener(new SelectionAdapter() {
+ @Override
+ public void widgetSelected(SelectionEvent e) {
+ String[] ss = csets.getSelection();
+ if (ss != null && ss.length > 0) {
+ configSetMap.remove(wsets.getSelection()[0] + DELIMITER + ss[0]);
+ csets.remove(ss[0]);
+ csets.setSelection(0);
+ updateButtons();
+ }
+ }});
+
+ initData();
+ return comp;
+ }
+
+ private void initData() {
+ configSetMap = new LinkedHashMap();
+ for (String s : CDTPrefUtil.readConfigSets()) {
+ ConfigSet cs = new ConfigSet(s);
+ if (cs.isValid())
+ configSetMap.put(cs.workingSetLabel + DELIMITER + cs.name, cs);
+ }
+ workingSetChanged();
+ }
+
+ private void updateButtons() {
+ Button ok = this.getButton(IDialogConstants.OK_ID);
+ boolean en = csets.getSelectionIndex() > 0;
+ if (! wsets.getEnabled()) {
+ b2.setEnabled(false); // new
+ if (ok != null)
+ ok.setEnabled(false); // OK
+ en = false;
+ }
+ b1.setEnabled(en); // update
+ b3.setEnabled(en); // rename
+ b4.setEnabled(en); // delete
+ }
+ private void workingSetChanged() {
+// tree.setRedraw(false);
+ tree.removeAll();
+ String[] ss = wsets.getSelection();
+ if (ss == null || ss.length == 0)
+ return;
+ IWorkingSet ws = workingSetsMap.get(ss[0]);
+ fillTree(ws);
+ tree.setRedraw(true);
+// csets.setRedraw(false);
+ csets.removeAll();
+ csets.add(CURRENT);
+ csets.setSelection(0);
+
+ configSetMap.remove(CURRENT); // previous default object, if any
+ for (Map.Entry me : configSetMap.entrySet()) {
+ if (me.getValue().workingSetLabel.equals(ws.getLabel()))
+ csets.add(me.getValue().name);
+ }
+ configSetMap.put(CURRENT, new ConfigSet(CURRENT, ws.getLabel(), tree));
+ csets.setRedraw(true);
+ updateButtons();
+
+ // calls from FillTree does not work...
+ for (TreeItem ti : tree.getItems())
+ ti.setExpanded(true);
+ }
+
+ /**
+ * Update projects tree for selected working set.
+ * @param ws - working set selected.
+ */
+ private void fillTree(IWorkingSet ws) {
+ if (ws == null)
+ return;
+ for (IAdaptable ad : ws.getElements()) {
+ IProject p = (IProject)ad.getAdapter(IProject.class);
+ if (p == null)
+ continue;
+ ICProjectDescription prjd = CoreModel.getDefault().getProjectDescription(p, true);
+ if (prjd == null)
+ continue;
+ ICConfigurationDescription[] cfgs = prjd.getConfigurations();
+ if (cfgs == null || cfgs.length == 0)
+ continue;
+ TreeItem ti = new TreeItem(tree, SWT.NONE);
+ ti.setText(prjd.getName());
+ ti.setImage(IMG_PROJ);
+ ti.setData(prjd);
+ for (ICConfigurationDescription c : cfgs) {
+ TreeItem ti1 = new TreeItem(ti, SWT.NONE);
+ ti1.setText(c.getName());
+ ti1.setImage(IMG_CONF);
+ ti1.setChecked(c.isActive());
+ ti1.setData(c);
+ }
+ }
+ }
+
+ private void configSetChanged() {
+ int i = csets.getSelectionIndex();
+ if (i >= 0) {
+ String key = (i == 0) ? CURRENT : wsets.getSelection()[0] + DELIMITER + csets.getItem(i);
+ ConfigSet cs = configSetMap.get(key);
+ if (cs != null && cs.isValid()) {
+ for (TreeItem ti : tree.getItems()) {
+ ICProjectDescription prjd = (ICProjectDescription)ti.getData();
+ String cid = cs.data.get(prjd.getName());
+ if (cid == null)
+ continue; // the project not in the list
+ for (TreeItem ti1 : ti.getItems()) {
+ ICConfigurationDescription cfg = (ICConfigurationDescription)ti1.getData();
+ ti1.setChecked(cid.equals(cfg.getId()));
+ }
+ }
+ }
+ }
+ updateButtons();
+ }
+
+ private String getString(String title, String value) {
+ InputDialog d = new InputDialog(sh, title,
+ UIMessages.getString("WorkingSetConfigAction.11"), //$NON-NLS-1$
+ value, new IInputValidator() {
+ public String isValid(String newText) {
+ if (newText.indexOf(CDTPrefUtil.CONFSETDEL) >= 0)
+ return UIMessages.getString("WorkingSetConfigAction.0") + CDTPrefUtil.CONFSETDEL + UIMessages.getString("WorkingSetConfigAction.14"); //$NON-NLS-1$ //$NON-NLS-2$
+ if (configSetMap.containsKey(wsets.getSelection()[0] + DELIMITER + newText))
+ return UIMessages.getString("WorkingSetConfigAction.15") + newText + UIMessages.getString("WorkingSetConfigAction.16"); //$NON-NLS-1$ //$NON-NLS-2$
+ return null;
+ }});
+ if (d.open() == Window.OK)
+ return d.getValue().replace(' ', '_'); // space is delimiter.
+ return null;
+ }
+
+ private void ExistsMessage(String s) {
+ MessageBox box = new MessageBox(sh, SWT.ICON_ERROR);
+ box.setMessage(UIMessages.getString("WorkingSetConfigAction.12") + s); //$NON-NLS-1$
+ box.open();
+ }
+ }
+
+ private static class ConfigSet {
+ String name;
+ String workingSetLabel;
+ LinkedHashMap data;
+
+ private ConfigSet(String s) {
+ data = new LinkedHashMap();
+ String[] ss = s.split(DELIMITER);
+ if (ss == null || ss.length < 4 || ss.length %2 == 1) {
+ CUIPlugin.getDefault().logErrorMessage(UIMessages.getString("WorkingSetConfigAction.13") + s); //$NON-NLS-1$
+ return; // not valid
+ }
+ name = ss[0];
+ workingSetLabel = ss[1];
+ int n = (ss.length - 2) / 2;
+ for (int i=0; i();
+ name = n;
+ workingSetLabel = w;
+ for (TreeItem ti : t.getItems()) {
+ ICProjectDescription prjd = (ICProjectDescription)ti.getData();
+ for (TreeItem ti1 : ti.getItems()) {
+ if (ti1.getChecked()) {
+ ICConfigurationDescription cfg = (ICConfigurationDescription)ti1.getData();
+ data.put(prjd.getName(), cfg.getId());
+ break;
+ }
+ }
+ }
+
+ }
+
+ private boolean isValid() {
+ return data.size() > 0;
+ }
+
+ @Override
+ public String toString() {
+ if (!isValid())
+ return EMPTY_STR;
+ StringBuilder b = new StringBuilder();
+ b.append(name);
+ b.append(DELIMITER);
+ b.append(workingSetLabel);
+ b.append(DELIMITER);
+ for (Map.Entry me : data.entrySet()) {
+ b.append(me.getKey());
+ b.append(DELIMITER);
+ b.append(me.getValue());
+ b.append(DELIMITER);
+ }
+ return b.toString().trim();
+ }
+ }
+}
diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/CDTPrefUtil.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/CDTPrefUtil.java
index fd3ee29949b..9aaae33faa2 100644
--- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/CDTPrefUtil.java
+++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/newui/CDTPrefUtil.java
@@ -33,6 +33,7 @@ public class CDTPrefUtil {
public static final String KEY_EXPORT = "properties.export.page.enable"; //$NON-NLS-1$
// string keys
public static final String KEY_PREFTC = "wizard.preferred.toolchains"; //$NON-NLS-1$
+ public static final String KEY_CONFSET = "workingsets.selected.configs"; //$NON-NLS-1$
// integer keys
public static final String KEY_POSSAVE = "properties.save.position"; //$NON-NLS-1$
public static final int POSITION_SAVE_SIZE = 0;
@@ -57,6 +58,7 @@ public class CDTPrefUtil {
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$
+ public static final String CONFSETDEL = "\f"; //$NON-NLS-1$
private static LinkedList preferredTCs = null;
public static final Object[] EMPTY_ARRAY = new Object[0];
@@ -92,7 +94,7 @@ public class CDTPrefUtil {
public static void savePreferredTCs() {
if (preferredTCs == null) return;
Iterator it = preferredTCs.iterator();
- StringBuffer b = new StringBuffer();
+ StringBuilder b = new StringBuilder();
while (it.hasNext()) {
String s = it.next();
if (s == null) continue;
@@ -176,22 +178,6 @@ public class CDTPrefUtil {
if (s1 == null ||
s1.length == 0)
return EMPTY_ARRAY;
-/*
- if (mode == DMODE_EMPTY) {
- Arrays.sort(s1, cmp);
- for (int i=1; i lst = new ArrayList