Skip to content

Commit e8ec710

Browse files
committed
Issue 408 fix for boolean preferences
This commit fixes issue when boolean preferences set to 'false' value with 'true' being logically default were not saved.
1 parent 3faf68f commit e8ec710

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package it.baeyens.arduino.common;
2+
3+
public class Defaults {
4+
public static final boolean OPEN_SERIAL_WITH_MONITOR = true;
5+
public static final boolean AUTO_IMPORT_LIBRARIES = true;
6+
}

it.baeyens.arduino.common/src/it/baeyens/arduino/common/InstancePreferences.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
public class InstancePreferences extends Const {
2727

2828
public static boolean getOpenSerialWithMonitor() {
29-
return getGlobalBoolean(KEY_OPEN_SERIAL_WITH_MONITOR, true);
29+
return getGlobalBoolean(KEY_OPEN_SERIAL_WITH_MONITOR, Defaults.OPEN_SERIAL_WITH_MONITOR);
3030
}
3131

3232
public static void setOpenSerialWithMonitor(boolean value) {
@@ -39,7 +39,7 @@ public static void setOpenSerialWithMonitor(boolean value) {
3939
* @return true if libraries need to be added else false.
4040
*/
4141
public static boolean getAutomaticallyIncludeLibraries() {
42-
return getGlobalBoolean(KEY_AUTO_IMPORT_LIBRARIES, true);
42+
return getGlobalBoolean(KEY_AUTO_IMPORT_LIBRARIES, Defaults.AUTO_IMPORT_LIBRARIES);
4343
}
4444

4545
public static void setAutomaticallyIncludeLibraries(boolean value) {

it.baeyens.arduino.core/src/it/baeyens/arduino/ui/PreferencePage.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.eclipse.ui.preferences.ScopedPreferenceStore;
1616

1717
import it.baeyens.arduino.common.Const;
18+
import it.baeyens.arduino.common.Defaults;
1819

1920
/**
2021
* ArduinoPreferencePage is the class that is behind the preference page of
@@ -38,7 +39,11 @@ public class PreferencePage extends FieldEditorPreferencePage implements IWorkbe
3839
public PreferencePage() {
3940
super(org.eclipse.jface.preference.FieldEditorPreferencePage.GRID);
4041
setDescription(Messages.ui_workspace_settings);
41-
setPreferenceStore(new ScopedPreferenceStore(InstanceScope.INSTANCE, Const.NODE_ARDUINO));
42+
43+
ScopedPreferenceStore preferences = new ScopedPreferenceStore(InstanceScope.INSTANCE, Const.NODE_ARDUINO);
44+
preferences.setDefault(Const.KEY_OPEN_SERIAL_WITH_MONITOR, Defaults.OPEN_SERIAL_WITH_MONITOR);
45+
preferences.setDefault(Const.KEY_AUTO_IMPORT_LIBRARIES, Defaults.AUTO_IMPORT_LIBRARIES);
46+
setPreferenceStore(preferences);
4247
}
4348

4449
@Override

0 commit comments

Comments
 (0)