From f594128873a990e8611d5e96bd10da7e7d7e3f06 Mon Sep 17 00:00:00 2001 From: David Inglis Date: Fri, 2 Apr 2004 19:07:41 +0000 Subject: [PATCH] support multiple binary parsers --- core/org.eclipse.cdt.ui/ChangeLog | 12 + core/org.eclipse.cdt.ui/plugin.xml | 3 - .../cdt/internal/ui/CUIMessages.properties | 2 + .../ui/dialogs/AbstractBinaryParserPage.java | 176 ++++----- .../cdt/ui/dialogs/AbstractCOptionPage.java | 6 +- .../cdt/ui/dialogs/BinaryParserBlock.java | 346 +++++++++++++----- .../ui/dialogs/CygwinPEBinaryParserPage.java | 69 ++-- .../ui/dialogs/GNUElfBinaryParserPage.java | 58 ++- 8 files changed, 438 insertions(+), 234 deletions(-) diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index 43327c4a27e..8e0402f4a8d 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -1,3 +1,15 @@ +2004-04-02 David Inglis + + Support selection of multiple binary parsers. + + * plugin.xml + * src/org/eclipse/cdt/internal/ui/CUIMessages.properties + * src/org/eclipse/cdt/ui/dialogs/AbstractBinaryParserPage.java + * src/org/eclipse/cdt/ui/dialogs/AbstractCOptionPage.java + * src/org/eclipse/cdt/ui/dialogs/BinaryParserBlock.java + * src/org/eclipse/cdt/ui/dialogs/CygwinPEBinaryParserPage.java + * src/org/eclipse/cdt/ui/dialogs/GNUElfBinaryParserPage.java + 2004-04-02 Alain Magloire Add new filter to hide/show non C Projects. diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index 6f16ece3923..07ac2e36030 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -556,9 +556,6 @@ class="org.eclipse.cdt.ui.dialogs.GNUElfBinaryParserPage" id="ElfBinaryParserPage"> - - 0) { - IExtension ext = point.getExtension(ref[0].getID()); - if (ext != null) { - initial = ext.getLabel(); + initialSelected = new ArrayList(ref.length); + for (int i = 0; i < ref.length; i++) { + if (configMap.get(ref[i].getID()) != null) { + initialSelected.add(configMap.get(ref[i].getID())); + elements.add(configMap.get(ref[i].getID())); } } - } catch (CoreException e) { } - } - if (initial == null) { - String id = fPrefs.getString(CCorePlugin.PREF_BINARY_PARSER); - if (id == null || id.length() == 0) { - initial = point.getExtension(CCorePlugin.DEFAULT_BINARY_PARSER_UNIQ_ID).getLabel(); - } else { - IExtension ext = point.getExtension(id); - if (ext != null) { - initial = ext.getLabel(); + Iterator iter = configMap.entrySet().iterator(); + while (iter.hasNext()) { + Entry entry = (Entry) iter.next(); + if (!elements.contains(entry.getValue())) { + elements.add(entry.getValue()); } - } + binaryList.setElements(elements); + if (initialSelected != null) + binaryList.setCheckedElements(initialSelected); } + if (initialSelected == null) { + Preferences store = getContainer().getPreferences(); + String id = null; + if (store != null) { + id = store.getString(CCorePlugin.PREF_BINARY_PARSER); + } + if (id != null && id.length() > 0) { + String[] ids = parseStringToArray(id); + initialSelected = new ArrayList(ids.length); + for (int i = 0; i < ids.length; i++) { + if (configMap.get(ids[i]) != null) { + initialSelected.add(configMap.get(ids[i])); + elements.add(configMap.get(ids[i])); + } + } + } + Iterator iter = configMap.entrySet().iterator(); + while (iter.hasNext()) { + Entry entry = (Entry) iter.next(); + if (!elements.contains(entry.getValue())) { + elements.add(entry.getValue()); + } + } + binaryList.setElements(elements); + if (initialSelected != null) + binaryList.setCheckedElements(initialSelected); + // reset this since we only want to prevent applying non-changed selections on the project + // and project creation we always want to apply selection. + initialSelected = null; + } + } + private String arrayToString(Object[] array) { + StringBuffer buf = new StringBuffer(); + for (int i = 0; i < array.length; i++) { + buf.append(array[i].toString()).append(';'); + } + return buf.toString(); + } + + private String[] parseStringToArray(String syms) { + if (syms != null && syms.length() > 0) { + StringTokenizer tok = new StringTokenizer(syms, ";"); //$NON-NLS-1$ + ArrayList list = new ArrayList(tok.countTokens()); + while (tok.hasMoreElements()) { + list.add(tok.nextToken()); + } + return (String[]) list.toArray(new String[list.size()]); + } + return new String[0]; } public void performDefaults() { - IExtensionPoint point = CCorePlugin.getDefault().getDescriptor().getExtensionPoint(CCorePlugin.BINARY_PARSER_SIMPLE_ID); - String id; - if (getContainer().getProject() != null) { - id = fPrefs.getString(CCorePlugin.PREF_BINARY_PARSER); - } else { - id = fPrefs.getDefaultString(CCorePlugin.PREF_BINARY_PARSER); + String id = null; + + // default current pages. + List selected = binaryList.getCheckedElements(); + for (int i = 0; i < selected.size(); i++) { + ICOptionPage page = getBinaryParserPage(((BinaryParserConfiguration) selected.get(i)).getID()); + if (page != null) { + page.performDefaults(); + } } - String selected; - if (id == null || id.length() == 0) { - selected = point.getExtension(CCorePlugin.DEFAULT_BINARY_PARSER_UNIQ_ID).getLabel(); - } else { - selected = point.getExtension(id).getLabel(); + Preferences store = getContainer().getPreferences(); + if (store != null) { + if (getContainer().getProject() != null) { + id = store.getString(CCorePlugin.PREF_BINARY_PARSER); + } else { + id = store.getDefaultString(CCorePlugin.PREF_BINARY_PARSER); + } } - comboBox.setText(selected); + //default selection + selected.clear(); + if (id != null) { + String[] ids = parseStringToArray(id); + for (int i = 0; i < ids.length; i++) { + if (configMap.get(ids[i]) != null) { + selected.add(configMap.get(ids[i])); + } + } + } + binaryList.setCheckedElements(selected); // Give a change to the UI contributors to react. // But do it last after the comboBox is set. handleBinaryParserChanged(); - super.performDefaults(); getContainer().updateContainer(); } protected String getCurrentBinaryParserID() { - String selected = comboBox.getText(); - return (String) idMap.get(selected); + List list = binaryList.getSelectedElements(); + if (list.size() > 0) { + BinaryParserConfiguration selected = (BinaryParserConfiguration) list.get(0); + if (binaryList.isChecked(selected)) { + return selected.getID(); + } + } + return null; } + protected String[] getBinaryParserIDs() { + return (String[]) configMap.keySet().toArray(new String[configMap.keySet().size()]); + } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/CygwinPEBinaryParserPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/CygwinPEBinaryParserPage.java index bfa6e55ec26..9d5e81f9a98 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/CygwinPEBinaryParserPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/CygwinPEBinaryParserPage.java @@ -87,17 +87,17 @@ public class CygwinPEBinaryParserPage extends AbstractCOptionPage { } for (int i = 0; i < cext.length; i++) { if (cext[i].getID().equals(parserID)) { - String orig = cext[0].getExtensionData("addr2line"); //$NON-NLS-1$ + String orig = cext[i].getExtensionData("addr2line"); //$NON-NLS-1$ if (orig == null || !orig.equals(addr2line)) { - cext[0].setExtensionData("addr2line", addr2line); //$NON-NLS-1$ + cext[i].setExtensionData("addr2line", addr2line); //$NON-NLS-1$ } - orig = cext[0].getExtensionData("c++filt"); //$NON-NLS-1$ + orig = cext[i].getExtensionData("c++filt"); //$NON-NLS-1$ if (orig == null || !orig.equals(cppfilt)) { - cext[0].setExtensionData("c++filt", cppfilt); //$NON-NLS-1$ + cext[i].setExtensionData("c++filt", cppfilt); //$NON-NLS-1$ } - orig = cext[0].getExtensionData("cygpath"); //$NON-NLS-1$ + orig = cext[i].getExtensionData("cygpath"); //$NON-NLS-1$ if (orig == null || !orig.equals(cygpath)) { - cext[0].setExtensionData("cygpath", cygpath); //$NON-NLS-1$ + cext[i].setExtensionData("cygpath", cygpath); //$NON-NLS-1$ } } } @@ -122,28 +122,21 @@ public class CygwinPEBinaryParserPage extends AbstractCOptionPage { String cppfilt = null; String cygpath = null; IProject proj = getContainer().getProject(); - if (proj != null) { - try { - ICDescriptor cdesc = CCorePlugin.getDefault().getCProjectDescription(proj); - ICExtensionReference[] cext = cdesc.get(CCorePlugin.BINARY_PARSER_UNIQ_ID); - if (cext.length > 0) { - addr2line = cext[0].getExtensionData("addr2line"); //$NON-NLS-1$; - cppfilt = cext[0].getExtensionData("c++filt"); //$NON-NLS-1$; - cygpath = cext[0].getExtensionData("cygpath"); //$NON-NLS-1$; - } - } catch (CoreException e) { - } - } else { - Preferences store = getContainer().getPreferences(); - if (store != null) { + Preferences store = getContainer().getPreferences(); + if (store != null) { + if (proj != null) { addr2line = store.getString(PREF_ADDR2LINE_PATH); cppfilt = store.getString(PREF_CPPFILT_PATH); cygpath = store.getString(PREF_CYGPATH_PATH); + } else { + addr2line = store.getDefaultString(PREF_ADDR2LINE_PATH); + cppfilt = store.getDefaultString(PREF_CPPFILT_PATH); + cygpath = store.getDefaultString(PREF_CYGPATH_PATH); } + fAddr2LineCommandText.setText((addr2line == null || addr2line.length() == 0) ? "addr2line" : addr2line); //$NON-NLS-1$; + fCPPFiltCommandText.setText((cppfilt == null || cppfilt.length() == 0) ? "c++filt" : cppfilt); //$NON-NLS-1$; + fCygPathCommandText.setText((cygpath == null || cygpath.length() == 0) ? "cygpath" : cygpath); //$NON-NLS-1$; } - fAddr2LineCommandText.setText((addr2line == null || addr2line.length() == 0) ? "addr2line" : addr2line); //$NON-NLS-1$; - fCPPFiltCommandText.setText((cppfilt == null || cppfilt.length() == 0) ? "c++filt" : cppfilt); //$NON-NLS-1$; - fCygPathCommandText.setText((cygpath == null || cygpath.length() == 0) ? "cygpath" : cygpath); //$NON-NLS-1$; } /* @@ -269,7 +262,35 @@ public class CygwinPEBinaryParserPage extends AbstractCOptionPage { }); setControl(comp); - performDefaults(); + initializeValues(); } + private void initializeValues() { + String addr2line = null; + String cppfilt = null; + String cygpath = null; + IProject proj = getContainer().getProject(); + if (proj != null) { + try { + ICDescriptor cdesc = CCorePlugin.getDefault().getCProjectDescription(proj); + ICExtensionReference[] cext = cdesc.get(CCorePlugin.BINARY_PARSER_UNIQ_ID); + if (cext.length > 0) { + addr2line = cext[0].getExtensionData("addr2line"); //$NON-NLS-1$; + cppfilt = cext[0].getExtensionData("c++filt"); //$NON-NLS-1$; + cygpath = cext[0].getExtensionData("cygpath"); //$NON-NLS-1$; + } + } catch (CoreException e) { + } + } else { + Preferences store = getContainer().getPreferences(); + if (store != null) { + addr2line = store.getString(PREF_ADDR2LINE_PATH); + cppfilt = store.getString(PREF_CPPFILT_PATH); + cygpath = store.getString(PREF_CYGPATH_PATH); + } + } + fAddr2LineCommandText.setText((addr2line == null || addr2line.length() == 0) ? "addr2line" : addr2line); //$NON-NLS-1$; + fCPPFiltCommandText.setText((cppfilt == null || cppfilt.length() == 0) ? "c++filt" : cppfilt); //$NON-NLS-1$; + fCygPathCommandText.setText((cygpath == null || cygpath.length() == 0) ? "cygpath" : cygpath); //$NON-NLS-1$; + } } \ No newline at end of file diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/GNUElfBinaryParserPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/GNUElfBinaryParserPage.java index a8124535323..c98ff83b404 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/GNUElfBinaryParserPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/GNUElfBinaryParserPage.java @@ -85,13 +85,13 @@ public class GNUElfBinaryParserPage extends AbstractCOptionPage { for (int i = 0; i < cext.length; i++) { if (cext[i].getID().equals(parserID)) { - String orig = cext[0].getExtensionData("addr2line"); //$NON-NLS-1$ + String orig = cext[i].getExtensionData("addr2line"); //$NON-NLS-1$ if (orig == null || !orig.equals(addr2line)) { - cext[0].setExtensionData("addr2line", addr2line); //$NON-NLS-1$ + cext[i].setExtensionData("addr2line", addr2line); //$NON-NLS-1$ } - orig = cext[0].getExtensionData("c++filt"); //$NON-NLS-1$ + orig = cext[i].getExtensionData("c++filt"); //$NON-NLS-1$ if (orig == null || !orig.equals(cppfilt)) { - cext[0].setExtensionData("c++filt", cppfilt); //$NON-NLS-1$ + cext[i].setExtensionData("c++filt", cppfilt); //$NON-NLS-1$ } } } @@ -114,25 +114,18 @@ public class GNUElfBinaryParserPage extends AbstractCOptionPage { String addr2line = null; String cppfilt = null; IProject proj = getContainer().getProject(); - if (proj != null) { - try { - ICDescriptor cdesc = CCorePlugin.getDefault().getCProjectDescription(proj); - ICExtensionReference[] cext = cdesc.get(CCorePlugin.BINARY_PARSER_UNIQ_ID); - if (cext.length > 0) { - addr2line = cext[0].getExtensionData("addr2line"); //$NON-NLS-1$ - cppfilt = cext[0].getExtensionData("c++filt"); //$NON-NLS-1$ - } - } catch (CoreException e) { - } - } else { - Preferences store = getContainer().getPreferences(); - if (store != null) { + Preferences store = getContainer().getPreferences(); + if (store != null) { + if (proj != null) { addr2line = store.getString(PREF_ADDR2LINE_PATH); cppfilt = store.getString(PREF_CPPFILT_PATH); + } else { + addr2line = store.getDefaultString(PREF_ADDR2LINE_PATH); + cppfilt = store.getDefaultString(PREF_CPPFILT_PATH); } + fAddr2LineCommandText.setText((addr2line == null || addr2line.length() == 0) ? "addr2line" : addr2line); //$NON-NLS-1$ + fCPPFiltCommandText.setText((cppfilt == null || cppfilt.length() == 0) ? "c++filt" : cppfilt); //$NON-NLS-1$ } - fAddr2LineCommandText.setText((addr2line == null || addr2line.length() == 0) ? "addr2line" : addr2line); //$NON-NLS-1$ - fCPPFiltCommandText.setText((cppfilt == null || cppfilt.length() == 0) ? "c++filt" : cppfilt); //$NON-NLS-1$ } /* @@ -220,7 +213,32 @@ public class GNUElfBinaryParserPage extends AbstractCOptionPage { }); setControl(comp); - performDefaults(); + initialziedValues(); + } + + private void initialziedValues() { + String addr2line = null; + String cppfilt = null; + IProject proj = getContainer().getProject(); + if (proj != null) { + try { + ICDescriptor cdesc = CCorePlugin.getDefault().getCProjectDescription(proj); + ICExtensionReference[] cext = cdesc.get(CCorePlugin.BINARY_PARSER_UNIQ_ID); + if (cext.length > 0) { + addr2line = cext[0].getExtensionData("addr2line"); //$NON-NLS-1$ + cppfilt = cext[0].getExtensionData("c++filt"); //$NON-NLS-1$ + } + } catch (CoreException e) { + } + } else { + Preferences store = getContainer().getPreferences(); + if (store != null) { + addr2line = store.getString(PREF_ADDR2LINE_PATH); + cppfilt = store.getString(PREF_CPPFILT_PATH); + } + } + fAddr2LineCommandText.setText((addr2line == null || addr2line.length() == 0) ? "addr2line" : addr2line); //$NON-NLS-1$ + fCPPFiltCommandText.setText((cppfilt == null || cppfilt.length() == 0) ? "c++filt" : cppfilt); //$NON-NLS-1$ } } \ No newline at end of file