Skip to content

Commit 11e6945

Browse files
author
Anton Krug
committed
Implementing the File chooser and variables approach at the same time
1 parent 862adb0 commit 11e6945

File tree

4 files changed

+45
-6
lines changed

4 files changed

+45
-6
lines changed

com.googlecode.cppcheclipse.ui/META-INF/MANIFEST.MF

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ Require-Bundle: org.eclipse.ui;bundle-version="3.4.0",
1212
org.eclipse.cdt.core;bundle-version="5.0.0",
1313
org.eclipse.ui.editors;bundle-version="3.4.0",
1414
org.eclipse.jface.text;bundle-version="3.4.0",
15-
org.eclipse.cdt.make.core;bundle-version="5.0.0"
15+
org.eclipse.cdt.make.core;bundle-version="5.0.0",
16+
org.eclipse.debug.ui
1617
Bundle-RequiredExecutionEnvironment: JavaSE-1.7
1718
Bundle-ActivationPolicy: lazy
1819
Import-Package: org.eclipse.cdt.core.model,

com.googlecode.cppcheclipse.ui/src/com/googlecode/cppcheclipse/ui/Messages.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@ public class Messages extends NLS {
2525
public static String BinaryPathPreferencePage_ButtonSave;
2626
public static String BinaryPathPreferencePage_CheckForUpdate;
2727
public static String BinaryPathPreferencePage_Description;
28+
public static String BinaryPathPreferencePage_FileDialogButton;
29+
public static String BinaryPathPreferencePage_FileDialogTitle;
2830
public static String BinaryPathPreferencePage_NoValidPath;
2931
public static String BinaryPathPreferencePage_PathToBinary;
3032
public static String BinaryPathPreferencePage_UnknownVersion;
3133
public static String BinaryPathPreferencePage_UpdateCheckNever;
3234
public static String BinaryPathPreferencePage_UpdateCheckNotice;
3335
public static String BinaryPathPreferencePage_UpdateInterval;
36+
public static String BinaryPathPreferencePage_VariablesButton;
37+
3438
public static String BinaryPathPreferencePage_VersionTooOld;
3539
public static String BinaryPathPreferencePage_LinkToCppcheck;
3640
public static String Builder_IncrementalBuilderTask;

com.googlecode.cppcheclipse.ui/src/com/googlecode/cppcheclipse/ui/messages.properties

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,16 @@ BinaryPathPreferencePage_ButtonDiscard=Discard
1919
BinaryPathPreferencePage_ButtonSave=Save
2020
BinaryPathPreferencePage_CheckForUpdate=Check for update now...
2121
BinaryPathPreferencePage_Description=Set path to cppcheck binary and update settings.
22+
BinaryPathPreferencePage_FileDialogButton=Browse
23+
BinaryPathPreferencePage_FileDialogTitle=Location of the cppcheck binary
2224
BinaryPathPreferencePage_LinkToCppcheck=You must get this binary separately from <a href="http://sourceforge.net/projects/cppcheck/">http://sourceforge.net/projects/cppcheck/</a>.\nGiven cppcheck has version {0}.
2325
BinaryPathPreferencePage_NoValidPath=No valid path to cppcheck specified!
2426
BinaryPathPreferencePage_PathToBinary=cppcheck binary path
2527
BinaryPathPreferencePage_UnknownVersion=??
2628
BinaryPathPreferencePage_UpdateCheckNever=Never
2729
BinaryPathPreferencePage_UpdateCheckNotice=This update check only checks for updates to cppcheck. Last update check: {0}\nTo automatically check for updates to cppcheclipse click <A>here</A>.
2830
BinaryPathPreferencePage_UpdateInterval=How often should the check be run?
31+
BinaryPathPreferencePage_VariablesButton=Variables
2932
BinaryPathPreferencePage_VersionTooOld=Version of cppcheck is too old. You need at least version {0} but you only have {1}!
3033

3134
SettingsPreferencePage_CheckAll=Check for all known issues (all)

com.googlecode.cppcheclipse.ui/src/com/googlecode/cppcheclipse/ui/preferences/BinaryPathPreferencePage.java

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@
1111
import org.eclipse.jface.dialogs.MessageDialog;
1212
import org.eclipse.jface.preference.BooleanFieldEditor;
1313
import org.eclipse.jface.preference.FieldEditorPreferencePage;
14-
import org.eclipse.jface.preference.StringFieldEditor;
14+
import org.eclipse.jface.preference.StringButtonFieldEditor;
15+
import org.eclipse.debug.ui.StringVariableSelectionDialog;
1516
import org.eclipse.jface.preference.IPreferenceNode;
1617
import org.eclipse.jface.preference.PreferenceDialog;
1718
import org.eclipse.jface.preference.PreferenceManager;
@@ -31,6 +32,7 @@
3132
import org.eclipse.ui.IWorkbench;
3233
import org.eclipse.ui.IWorkbenchPreferencePage;
3334
import org.eclipse.ui.PlatformUI;
35+
import org.eclipse.swt.widgets.FileDialog;
3436
import org.eclipse.ui.dialogs.PreferencesUtil;
3537

3638
import com.googlecode.cppcheclipse.core.CppcheclipsePlugin;
@@ -57,7 +59,7 @@ public class BinaryPathPreferencePage extends FieldEditorPreferencePage
5759
private RadioGroupFieldEditor updateInterval;
5860
private Composite updateIntervalParent;
5961
private BooleanFieldEditor automaticUpdateCheck;
60-
private StringFieldEditor binaryPath;
62+
private StringButtonFieldEditor binaryPath;
6163
private Link updateCheckNotice;
6264
private boolean hasBinaryPathChanged;
6365
private Link link;
@@ -106,9 +108,12 @@ private void setCurrentVersion() {
106108
@Override
107109
protected void createFieldEditors() {
108110
Composite parent = getFieldEditorParent();
109-
binaryPath = new StringFieldEditor(IPreferenceConstants.P_BINARY_PATH,
110-
Messages.BinaryPathPreferencePage_PathToBinary, -1,
111-
StringFieldEditor.VALIDATE_ON_KEY_STROKE, parent) {
111+
112+
final FileDialog fileDialog = new FileDialog(getShell(), SWT.OPEN);
113+
fileDialog.setText(Messages.BinaryPathPreferencePage_FileDialogTitle);
114+
115+
binaryPath = new StringButtonFieldEditor(IPreferenceConstants.P_BINARY_PATH,
116+
Messages.BinaryPathPreferencePage_PathToBinary, parent) {
112117

113118
@Override
114119
protected boolean checkState() {
@@ -151,11 +156,37 @@ protected void fireValueChanged(String property, Object oldValue,
151156
super.fireValueChanged(property, oldValue, newValue);
152157
}
153158

159+
160+
161+
@Override
162+
protected String changePressed() {
163+
// Browse button pressed, after selection finished, it replace the current text
164+
return fileDialog.open();
165+
}
166+
154167
};
168+
binaryPath.setChangeButtonText(Messages.BinaryPathPreferencePage_FileDialogButton);
155169
binaryPath.setEmptyStringAllowed(false);
156170
binaryPath
157171
.setErrorMessage(Messages.BinaryPathPreferencePage_NoValidPath);
158172
addField(binaryPath);
173+
174+
final StringVariableSelectionDialog variablesDialog = new StringVariableSelectionDialog(getShell());
175+
Button variablesButton = new Button(parent, SWT.PUSH | SWT.TRAIL);
176+
variablesButton.setText(Messages.BinaryPathPreferencePage_VariablesButton);
177+
variablesButton.addSelectionListener(new SelectionAdapter() {
178+
public void widgetSelected(SelectionEvent event) {
179+
if (variablesDialog.open() == IDialogConstants.OK_ID) {
180+
final String variable = variablesDialog.getVariableExpression();
181+
if (variable != null) {
182+
// append the selected variable to the end of the path
183+
binaryPath.setStringValue(binaryPath.getStringValue() + variable);
184+
}
185+
}
186+
}
187+
});
188+
189+
afterControlInsertion(variablesButton);
159190

160191
parent = getFieldEditorParent();
161192
beforeControlInsertion(parent);

0 commit comments

Comments
 (0)