From 6c2e6ea058399e40f5fe2c4a506f6fb20b36f348 Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Fri, 3 Dec 2004 02:36:36 +0000 Subject: [PATCH] Previous commit was incorrect. --- .../cdt/ui/dialogs/MachOBinaryParserPage.java | 185 +++++++++++++++++- 1 file changed, 181 insertions(+), 4 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/MachOBinaryParserPage.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/MachOBinaryParserPage.java index 40e4386b682..020f941d9b7 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/MachOBinaryParserPage.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/ui/dialogs/MachOBinaryParserPage.java @@ -11,16 +11,193 @@ package org.eclipse.cdt.ui.dialogs; +import java.io.File; + +import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.ICDescriptor; +import org.eclipse.cdt.core.ICExtensionReference; +import org.eclipse.cdt.internal.ui.CUIMessages; +import org.eclipse.cdt.ui.CUIPlugin; +import org.eclipse.cdt.utils.ui.controls.ControlFactory; +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtensionPoint; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.Preferences; +import org.eclipse.swt.SWT; +import org.eclipse.swt.events.ModifyEvent; +import org.eclipse.swt.events.ModifyListener; +import org.eclipse.swt.events.SelectionAdapter; +import org.eclipse.swt.events.SelectionEvent; +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.FileDialog; +import org.eclipse.swt.widgets.Group; +import org.eclipse.swt.widgets.Label; +import org.eclipse.swt.widgets.Text; /** */ -public class MachOBinaryParserPage extends AbstractGNUBinaryParserPage { +public class MachOBinaryParserPage extends AbstractCOptionPage { - /* (non-Javadoc) - * @see org.eclipse.cdt.ui.dialogs.AbstractGNUBinaryParserPage#getRealBinaryParserPage() + public final static String PREF_CPPFILT_PATH = CUIPlugin.PLUGIN_ID + ".cppfilt"; //$NON-NLS-1$ + + protected Text fCPPFiltCommandText; + + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performApply(org.eclipse.core.runtime.IProgressMonitor) */ - protected AbstractGNUBinaryParserPage getRealBinaryParserPage() { + public void performApply(IProgressMonitor monitor) throws CoreException { + if (monitor == null) { + monitor = new NullProgressMonitor(); + } + + String cppfilt = fCPPFiltCommandText.getText().trim(); + + monitor.beginTask(CUIMessages.getString("BinaryParserPage.task.savingAttributes"), 1); //$NON-NLS-1$ + IProject proj = getContainer().getProject(); + if (proj != null) { + String parserID = ""; //$NON-NLS-1$ + ICDescriptor cdesc = CCorePlugin.getDefault().getCProjectDescription(proj); + ICExtensionReference[] cext = cdesc.get(CCorePlugin.BINARY_PARSER_UNIQ_ID); + if (cext.length > 0) { + IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(CUIPlugin.PLUGIN_ID, "BinaryParserPage"); //$NON-NLS-1$ + IConfigurationElement[] infos = point.getConfigurationElements(); + for (int i = 0; i < infos.length; i++) { + String id = infos[i].getAttribute("parserID"); //$NON-NLS-1$ + String clazz = infos[i].getAttribute("class"); //$NON-NLS-1$ + String ego = getRealBinaryParserPage().getClass().getName(); + if (clazz != null && clazz.equals(ego)) { + parserID = id; + break; + } + } + for (int i = 0; i < cext.length; i++) { + if (cext[i].getID().equals(parserID)) { + + String orig = cext[i].getExtensionData("c++filt"); //$NON-NLS-1$ + if (orig == null || !orig.equals(cppfilt)) { + cext[i].setExtensionData("c++filt", cppfilt); //$NON-NLS-1$ + } + } + } + } + } else { + Preferences store = getContainer().getPreferences(); + if (store != null) { + store.setValue(PREF_CPPFILT_PATH, cppfilt); + } + } + } + + /** + * If this class is inherited from then this method MUST be implemented + * in the derived class. + */ + protected Object getRealBinaryParserPage() { return this; } + /* + * (non-Javadoc) + * + * @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performDefaults() + */ + public void performDefaults() { + String addr2line = null; + String cppfilt = null; + IProject proj = getContainer().getProject(); + Preferences store = getContainer().getPreferences(); + if (store != null) { + if (proj != null) { + cppfilt = store.getString(PREF_CPPFILT_PATH); + } else { + cppfilt = store.getDefaultString(PREF_CPPFILT_PATH); + } + fCPPFiltCommandText.setText((cppfilt == null || cppfilt.length() == 0) ? "c++filt" : cppfilt); //$NON-NLS-1$ + } + } + + /* + * (non-Javadoc) + * + * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) + */ + public void createControl(Composite parent) { + Group comp = new Group(parent, SWT.SHADOW_ETCHED_IN); + comp.setText(CUIMessages.getString("BinaryParserBlock.binaryParserOptions")); //$NON-NLS-1$ + comp.setLayout(new GridLayout(2, true)); + comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); + ((GridLayout) comp.getLayout()).makeColumnsEqualWidth = false; + + Label label = ControlFactory.createLabel(comp, CUIMessages.getString("BinaryParserPage.label.cppfiltCommand")); //$NON-NLS-1$ + GridData gd = new GridData(); + gd.horizontalSpan = 2; + label.setLayoutData(gd); + + fCPPFiltCommandText = ControlFactory.createTextField(comp, SWT.SINGLE | SWT.BORDER); + gd = new GridData(GridData.FILL_HORIZONTAL); + fCPPFiltCommandText.setLayoutData(gd); + fCPPFiltCommandText.addModifyListener(new ModifyListener() { + + public void modifyText(ModifyEvent evt) { + //updateLaunchConfigurationDialog(); + } + }); + Button button = ControlFactory.createPushButton(comp, CUIMessages.getString("BinaryParserPage.label.browse")); //$NON-NLS-1$ + button.addSelectionListener(new SelectionAdapter() { + + public void widgetSelected(SelectionEvent evt) { + handleCPPFiltButtonSelected(); + //updateLaunchConfigurationDialog(); + } + + private void handleCPPFiltButtonSelected() { + FileDialog dialog = new FileDialog(getShell(), SWT.NONE); + dialog.setText(CUIMessages.getString("BinaryParserPage.label.cppfiltCommand")); //$NON-NLS-1$ + String command = fCPPFiltCommandText.getText().trim(); + int lastSeparatorIndex = command.lastIndexOf(File.separator); + if (lastSeparatorIndex != -1) { + dialog.setFilterPath(command.substring(0, lastSeparatorIndex)); + } + String res = dialog.open(); + if (res == null) { + return; + } + fCPPFiltCommandText.setText(res); + } + }); + + setControl(comp); + initialziedValues(); + } + + private void initialziedValues() { + 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) { + cppfilt = cext[0].getExtensionData("c++filt"); //$NON-NLS-1$ + } + } catch (CoreException e) { + } + } else { + Preferences store = getContainer().getPreferences(); + if (store != null) { + cppfilt = store.getString(PREF_CPPFILT_PATH); + } + } + fCPPFiltCommandText.setText((cppfilt == null || cppfilt.length() == 0) ? "c++filt" : cppfilt); //$NON-NLS-1$ + } + }