Added
Link Here
|
1 |
/******************************************************************************* |
2 |
* Copyright (c) 2003, 2004 IBM Corporation and others. |
3 |
* All rights reserved. This program and the accompanying materials |
4 |
* are made available under the terms of the Common Public License v1.0 |
5 |
* which accompanies this distribution, and is available at |
6 |
* http://www.eclipse.org/legal/cpl-v10.html |
7 |
* |
8 |
* Contributors: |
9 |
* QNX Software Systems - Initial API and implementation |
10 |
*******************************************************************************/ |
11 |
|
12 |
package org.eclipse.cdt.ui.dialogs; |
13 |
|
14 |
import java.io.File; |
15 |
|
16 |
import org.eclipse.cdt.core.CCorePlugin; |
17 |
import org.eclipse.cdt.core.ICDescriptor; |
18 |
import org.eclipse.cdt.core.ICExtensionReference; |
19 |
import org.eclipse.cdt.internal.ui.CUIMessages; |
20 |
import org.eclipse.cdt.ui.CUIPlugin; |
21 |
import org.eclipse.cdt.utils.ui.controls.ControlFactory; |
22 |
import org.eclipse.core.resources.IProject; |
23 |
import org.eclipse.core.runtime.CoreException; |
24 |
import org.eclipse.core.runtime.IConfigurationElement; |
25 |
import org.eclipse.core.runtime.IExtensionPoint; |
26 |
import org.eclipse.core.runtime.IProgressMonitor; |
27 |
import org.eclipse.core.runtime.NullProgressMonitor; |
28 |
import org.eclipse.core.runtime.Platform; |
29 |
import org.eclipse.core.runtime.Preferences; |
30 |
import org.eclipse.swt.SWT; |
31 |
import org.eclipse.swt.events.ModifyEvent; |
32 |
import org.eclipse.swt.events.ModifyListener; |
33 |
import org.eclipse.swt.events.SelectionAdapter; |
34 |
import org.eclipse.swt.events.SelectionEvent; |
35 |
import org.eclipse.swt.layout.GridData; |
36 |
import org.eclipse.swt.layout.GridLayout; |
37 |
import org.eclipse.swt.widgets.Button; |
38 |
import org.eclipse.swt.widgets.Composite; |
39 |
import org.eclipse.swt.widgets.FileDialog; |
40 |
import org.eclipse.swt.widgets.Group; |
41 |
import org.eclipse.swt.widgets.Label; |
42 |
import org.eclipse.swt.widgets.Text; |
43 |
|
44 |
/** |
45 |
*/ |
46 |
public class MachOBinaryParserPage extends AbstractCOptionPage { |
47 |
|
48 |
public final static String PREF_CPPFILT_PATH = CUIPlugin.PLUGIN_ID + ".cppfilt"; //$NON-NLS-1$ |
49 |
|
50 |
protected Text fCPPFiltCommandText; |
51 |
|
52 |
/* |
53 |
* (non-Javadoc) |
54 |
* |
55 |
* @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performApply(org.eclipse.core.runtime.IProgressMonitor) |
56 |
*/ |
57 |
public void performApply(IProgressMonitor monitor) throws CoreException { |
58 |
if (monitor == null) { |
59 |
monitor = new NullProgressMonitor(); |
60 |
} |
61 |
|
62 |
String cppfilt = fCPPFiltCommandText.getText().trim(); |
63 |
|
64 |
monitor.beginTask(CUIMessages.getString("BinaryParserPage.task.savingAttributes"), 1); //$NON-NLS-1$ |
65 |
IProject proj = getContainer().getProject(); |
66 |
if (proj != null) { |
67 |
String parserID = ""; //$NON-NLS-1$ |
68 |
ICDescriptor cdesc = CCorePlugin.getDefault().getCProjectDescription(proj); |
69 |
ICExtensionReference[] cext = cdesc.get(CCorePlugin.BINARY_PARSER_UNIQ_ID); |
70 |
if (cext.length > 0) { |
71 |
IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(CUIPlugin.PLUGIN_ID, "BinaryParserPage"); //$NON-NLS-1$ |
72 |
IConfigurationElement[] infos = point.getConfigurationElements(); |
73 |
for (int i = 0; i < infos.length; i++) { |
74 |
String id = infos[i].getAttribute("parserID"); //$NON-NLS-1$ |
75 |
String clazz = infos[i].getAttribute("class"); //$NON-NLS-1$ |
76 |
String ego = getRealBinaryParserPage().getClass().getName(); |
77 |
if (clazz != null && clazz.equals(ego)) { |
78 |
parserID = id; |
79 |
break; |
80 |
} |
81 |
} |
82 |
for (int i = 0; i < cext.length; i++) { |
83 |
if (cext[i].getID().equals(parserID)) { |
84 |
|
85 |
String orig = cext[i].getExtensionData("c++filt"); //$NON-NLS-1$ |
86 |
if (orig == null || !orig.equals(cppfilt)) { |
87 |
cext[i].setExtensionData("c++filt", cppfilt); //$NON-NLS-1$ |
88 |
} |
89 |
} |
90 |
} |
91 |
} |
92 |
} else { |
93 |
Preferences store = getContainer().getPreferences(); |
94 |
if (store != null) { |
95 |
store.setValue(PREF_CPPFILT_PATH, cppfilt); |
96 |
} |
97 |
} |
98 |
} |
99 |
|
100 |
/** |
101 |
* If this class is inherited from then this method MUST be implemented |
102 |
* in the derived class. |
103 |
*/ |
104 |
protected Object getRealBinaryParserPage() { |
105 |
return this; |
106 |
} |
107 |
|
108 |
/* |
109 |
* (non-Javadoc) |
110 |
* |
111 |
* @see org.eclipse.cdt.ui.dialogs.ICOptionPage#performDefaults() |
112 |
*/ |
113 |
public void performDefaults() { |
114 |
String addr2line = null; |
115 |
String cppfilt = null; |
116 |
IProject proj = getContainer().getProject(); |
117 |
Preferences store = getContainer().getPreferences(); |
118 |
if (store != null) { |
119 |
if (proj != null) { |
120 |
cppfilt = store.getString(PREF_CPPFILT_PATH); |
121 |
} else { |
122 |
cppfilt = store.getDefaultString(PREF_CPPFILT_PATH); |
123 |
} |
124 |
fCPPFiltCommandText.setText((cppfilt == null || cppfilt.length() == 0) ? "c++filt" : cppfilt); //$NON-NLS-1$ |
125 |
} |
126 |
} |
127 |
|
128 |
/* |
129 |
* (non-Javadoc) |
130 |
* |
131 |
* @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite) |
132 |
*/ |
133 |
public void createControl(Composite parent) { |
134 |
Group comp = new Group(parent, SWT.SHADOW_ETCHED_IN); |
135 |
comp.setText(CUIMessages.getString("BinaryParserBlock.binaryParserOptions")); //$NON-NLS-1$ |
136 |
comp.setLayout(new GridLayout(2, true)); |
137 |
comp.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); |
138 |
((GridLayout) comp.getLayout()).makeColumnsEqualWidth = false; |
139 |
|
140 |
Label label = ControlFactory.createLabel(comp, CUIMessages.getString("BinaryParserPage.label.addr2lineCommand")); //$NON-NLS-1$ |
141 |
GridData gd = new GridData(); |
142 |
gd.horizontalSpan = 2; |
143 |
label.setLayoutData(gd); |
144 |
|
145 |
Button button = ControlFactory.createPushButton(comp, CUIMessages.getString("BinaryParserPage.label.browse")); //$NON-NLS-1$ |
146 |
button.addSelectionListener(new SelectionAdapter() { |
147 |
|
148 |
public void widgetSelected(SelectionEvent evt) { |
149 |
//updateLaunchConfigurationDialog(); |
150 |
} |
151 |
|
152 |
}); |
153 |
|
154 |
label = ControlFactory.createLabel(comp, CUIMessages.getString("BinaryParserPage.label.cppfiltCommand")); //$NON-NLS-1$ |
155 |
gd = new GridData(); |
156 |
gd.horizontalSpan = 2; |
157 |
label.setLayoutData(gd); |
158 |
|
159 |
fCPPFiltCommandText = ControlFactory.createTextField(comp, SWT.SINGLE | SWT.BORDER); |
160 |
gd = new GridData(GridData.FILL_HORIZONTAL); |
161 |
fCPPFiltCommandText.setLayoutData(gd); |
162 |
fCPPFiltCommandText.addModifyListener(new ModifyListener() { |
163 |
|
164 |
public void modifyText(ModifyEvent evt) { |
165 |
//updateLaunchConfigurationDialog(); |
166 |
} |
167 |
}); |
168 |
button = ControlFactory.createPushButton(comp, CUIMessages.getString("BinaryParserPage.label.browse")); //$NON-NLS-1$ |
169 |
button.addSelectionListener(new SelectionAdapter() { |
170 |
|
171 |
public void widgetSelected(SelectionEvent evt) { |
172 |
handleCPPFiltButtonSelected(); |
173 |
//updateLaunchConfigurationDialog(); |
174 |
} |
175 |
|
176 |
private void handleCPPFiltButtonSelected() { |
177 |
FileDialog dialog = new FileDialog(getShell(), SWT.NONE); |
178 |
dialog.setText(CUIMessages.getString("BinaryParserPage.label.cppfiltCommand")); //$NON-NLS-1$ |
179 |
String command = fCPPFiltCommandText.getText().trim(); |
180 |
int lastSeparatorIndex = command.lastIndexOf(File.separator); |
181 |
if (lastSeparatorIndex != -1) { |
182 |
dialog.setFilterPath(command.substring(0, lastSeparatorIndex)); |
183 |
} |
184 |
String res = dialog.open(); |
185 |
if (res == null) { |
186 |
return; |
187 |
} |
188 |
fCPPFiltCommandText.setText(res); |
189 |
} |
190 |
}); |
191 |
|
192 |
setControl(comp); |
193 |
initialziedValues(); |
194 |
} |
195 |
|
196 |
private void initialziedValues() { |
197 |
String cppfilt = null; |
198 |
IProject proj = getContainer().getProject(); |
199 |
if (proj != null) { |
200 |
try { |
201 |
ICDescriptor cdesc = CCorePlugin.getDefault().getCProjectDescription(proj); |
202 |
ICExtensionReference[] cext = cdesc.get(CCorePlugin.BINARY_PARSER_UNIQ_ID); |
203 |
if (cext.length > 0) { |
204 |
cppfilt = cext[0].getExtensionData("c++filt"); //$NON-NLS-1$ |
205 |
} |
206 |
} catch (CoreException e) { |
207 |
} |
208 |
} else { |
209 |
Preferences store = getContainer().getPreferences(); |
210 |
if (store != null) { |
211 |
cppfilt = store.getString(PREF_CPPFILT_PATH); |
212 |
} |
213 |
} |
214 |
fCPPFiltCommandText.setText((cppfilt == null || cppfilt.length() == 0) ? "c++filt" : cppfilt); //$NON-NLS-1$ |
215 |
} |
216 |
|
217 |
} |