Skip to content

Commit d93ab26

Browse files
authored
Merge pull request #817 from Sloeber/issue/#806
Ui implementation for #806
2 parents 2aece75 + 54aeca6 commit d93ab26

File tree

10 files changed

+113
-50
lines changed

10 files changed

+113
-50
lines changed

io.sloeber.core/src/io/sloeber/core/api/BoardsManager.java

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,7 @@ private static TreeMap<String, IPath> getExamplesFromFolder(String prefix, IPath
297297
return examples;
298298
}
299299

300-
public static void setAutoImportLibraries(boolean booleanValue) {
301-
InstancePreferences.setAutomaticallyImportLibraries(booleanValue);
302300

303-
}
304301

305302
public static String[] getBoardNames(String boardFile) {
306303
TxtFile theBoardsFile = new TxtFile(new File(boardFile));
@@ -357,15 +354,7 @@ private static String[] getHardwarePaths() {
357354
+ ConfigurationPreferences.getInstallationPathPackages()).split(File.pathSeparator);
358355
}
359356

360-
public static void setPrivateHardwarePaths(String[] hardWarePaths) {
361-
InstancePreferences.setPrivateHardwarePaths(hardWarePaths);
362-
363-
}
364-
365-
public static void setPrivateLibraryPaths(String[] libraryPaths) {
366-
InstancePreferences.setPrivateLibraryPaths(libraryPaths);
367357

368-
}
369358

370359
public static class PlatformTree {
371360
private TreeMap<String, IndexFile> IndexFiles = new TreeMap<>();
@@ -685,13 +674,9 @@ public static IStatus setPlatformTree(PlatformTree platformTree, IProgressMonito
685674
return status;
686675
}
687676

688-
public static boolean getAutoImportLibraries() {
689-
return InstancePreferences.getAutomaticallyImportLibraries();
690-
}
691677

692-
public static String getPrivateHardwarePathsString() {
693-
return InstancePreferences.getPrivateHardwarePathsString();
694-
}
678+
679+
695680

696681
/**
697682
* returns all the menu names for all installed platforms. The return is
@@ -727,13 +712,11 @@ public static void onlyKeepLatestPlatforms() {
727712

728713
}
729714

730-
public static void setPragmaOnceHeaders(boolean booleanValue) {
731-
InstancePreferences.setPragmaOnceHeaders(booleanValue);
732-
715+
public static void setPrivateHardwarePaths(String[] hardWarePaths) {
716+
InstancePreferences.setPrivateHardwarePaths(hardWarePaths);
733717
}
734-
735-
public static boolean getPragmaOnceHeaders() {
736-
return InstancePreferences.getPragmaOnceHeaders();
718+
public static String getPrivateHardwarePathsString() {
719+
return InstancePreferences.getPrivateHardwarePathsString();
737720
}
738721

739722
}

io.sloeber.core/src/io/sloeber/core/api/Defaults.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,4 +35,8 @@ public static String getPrivateHardwarePath() {
3535
public static String getDefaultUploadProtocol() {
3636
return DEFAULT;
3737
}
38+
39+
public static boolean getUseArduinoToolSelection() {
40+
return true;
41+
}
3842
}

io.sloeber.core/src/io/sloeber/core/api/LibraryManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,10 @@ public static IStatus setLibraryTree(LibraryTree libs, IProgressMonitor monitor,
237237
public static String getPrivateLibraryPathsString() {
238238
return InstancePreferences.getPrivateLibraryPathsString();
239239
}
240+
public static void setPrivateLibraryPaths(String[] libraryPaths) {
241+
InstancePreferences.setPrivateLibraryPaths(libraryPaths);
242+
243+
}
240244

241245
/**
242246
* get all the categories for all libraries (installed or not)
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package io.sloeber.core.api;
2+
3+
import io.sloeber.core.common.InstancePreferences;
4+
5+
/**
6+
* A class to controll the preferences at the workspace level
7+
* @author jan
8+
*
9+
*/
10+
public class Preferences {
11+
public static void setAutoImportLibraries(boolean booleanValue) {
12+
InstancePreferences.setAutomaticallyImportLibraries(booleanValue);
13+
14+
}
15+
16+
public static void setPragmaOnceHeaders(boolean booleanValue) {
17+
InstancePreferences.setPragmaOnceHeaders(booleanValue);
18+
19+
}
20+
21+
public static boolean getPragmaOnceHeaders() {
22+
return InstancePreferences.getPragmaOnceHeaders();
23+
}
24+
25+
public static boolean getAutoImportLibraries() {
26+
return InstancePreferences.getAutomaticallyImportLibraries();
27+
}
28+
29+
public static void setUseArduinoToolSelection(boolean booleanValue) {
30+
InstancePreferences.setUseArduinoToolSelection(booleanValue);
31+
32+
}
33+
34+
public static boolean getUseArduinoToolSelection() {
35+
return InstancePreferences.getUseArduinoToolSelection();
36+
}
37+
38+
39+
}

io.sloeber.core/src/io/sloeber/core/common/InstancePreferences.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ public class InstancePreferences {
2424
private static final String KEY_PRIVATE_HARDWARE_PATHS = "Private hardware Path"; //$NON-NLS-1$
2525
public static final String KEY_AUTO_IMPORT_LIBRARIES = "Automatically import libraries"; //$NON-NLS-1$
2626
private static final String KEY_PRAGMA_ONCE_HEADER = "add pragma once to headers"; //$NON-NLS-1$
27+
private static final String KEY_USE_ARDUINO_TOOLS_SELECTION_ALGORITHM="Use the algoritm to find the toolchain like Arduino IDE"; //$NON-NLS-1$
2728
// preference nodes
2829
public static final String NODE_ARDUINO = Activator.NODE_ARDUINO;
2930

@@ -141,4 +142,13 @@ public static boolean getPragmaOnceHeaders() {
141142
return getGlobalBoolean(KEY_PRAGMA_ONCE_HEADER, true);
142143
}
143144

145+
public static void setUseArduinoToolSelection(boolean booleanValue) {
146+
setGlobalValue(KEY_USE_ARDUINO_TOOLS_SELECTION_ALGORITHM, booleanValue);
147+
148+
}
149+
150+
public static boolean getUseArduinoToolSelection() {
151+
return getGlobalBoolean(KEY_USE_ARDUINO_TOOLS_SELECTION_ALGORITHM, Defaults.getUseArduinoToolSelection());
152+
}
153+
144154
}

io.sloeber.core/src/io/sloeber/core/tools/Helpers.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@
5858
import io.sloeber.core.api.BoardDescriptor;
5959
import io.sloeber.core.api.CompileOptions;
6060
import io.sloeber.core.api.Defaults;
61+
import io.sloeber.core.api.Preferences;
6162
import io.sloeber.core.common.Common;
6263
import io.sloeber.core.common.ConfigurationPreferences;
6364
import io.sloeber.core.common.Const;
@@ -673,7 +674,7 @@ private static void setTheEnvironmentVariablesAddThePlatformInfo(BoardDescriptor
673674
addPlatformFileTools(LatestArduinoPlatform, contribEnv, confDesc, true);
674675
}
675676
// todo implement this jsonBasedPlatformManagement trigger
676-
boolean jsonBasedPlatformManagement = true;
677+
boolean jsonBasedPlatformManagement = !Preferences.getUseArduinoToolSelection();
677678
if (jsonBasedPlatformManagement) {
678679
// add the referenced platform before the real platform
679680
ArduinoPlatform referencedPlatform = Manager.getPlatform(referencedPlatformFile);

io.sloeber.core/src/jUnit/CreateAndCompile.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import io.sloeber.core.api.CodeDescriptor;
2424
import io.sloeber.core.api.CompileOptions;
2525
import io.sloeber.core.api.ConfigurationDescriptor;
26+
import io.sloeber.core.api.Preferences;
2627

2728
@SuppressWarnings("nls")
2829
@RunWith(Parameterized.class)
@@ -144,6 +145,8 @@ public static void installAdditionalBoards() {
144145
BoardsManager.installAllLatestPlatforms();
145146
BoardsManager.onlyKeepLatestPlatforms();
146147
}
148+
//build the Arduino way
149+
Preferences.setUseArduinoToolSelection(false);
147150
Shared.waitForAllJobsToFinish();
148151
}
149152

io.sloeber.ui/src/io/sloeber/ui/Messages.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,8 @@ public class Messages extends NLS {
109109

110110
public static String ui_pragma_once_headers;
111111

112+
public static String ui_use_arduino_toolchain_selection;
113+
112114
static {
113115
// initialize resource bundle
114116
NLS.initializeMessages(BUNDLE_NAME, Messages.class);

io.sloeber.ui/src/io/sloeber/ui/messages.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,3 +78,4 @@ platformSelectionTip=remove or add checkboxes and select OK to update your confi
7878
port_is_not_a_computer_name=The port you have selected is not a computer name.
7979
Set_or_Remove_password=Set or remove password.
8080
ui_pragma_once_headers=Add #pragma once to all headers
81+
ui_use_arduino_toolchain_selection=Select the toolchain like the Arduino IDE.

io.sloeber.ui/src/io/sloeber/ui/preferences/PreferencePage.java

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import io.sloeber.core.api.Defaults;
2121
import io.sloeber.core.api.LibraryManager;
2222
import io.sloeber.core.api.Other;
23+
import io.sloeber.core.api.Preferences;
2324
import io.sloeber.ui.Messages;
2425
import io.sloeber.ui.helpers.MyPreferences;
2526

@@ -42,14 +43,16 @@ public class PreferencePage extends FieldEditorPreferencePage implements IWorkbe
4243
private static final String KEY_PRAGMA_ONCE_HEADERS = "Gui entry for add pragma once"; //$NON-NLS-1$
4344
private static final String KEY_PRIVATE_HARDWARE_PATHS = "Gui entry for private hardware paths"; //$NON-NLS-1$
4445
private static final String KEY_PRIVATE_LIBRARY_PATHS = "Gui entry for private library paths"; //$NON-NLS-1$
46+
private static final String KEY_TOOLCHAIN_SELECTION = "Gui entry for toolchain selection"; //$NON-NLS-1$
4547

46-
private PathEditor arduinoPrivateLibPath;
47-
private PathEditor arduinoPrivateHardwarePath;
48-
private ComboFieldEditor buildBeforeUploadOption;
49-
private BooleanFieldEditor openSerialMonitorOpensSerialsOption;
50-
private BooleanFieldEditor automaticallyImportLibrariesOption;
51-
private BooleanFieldEditor PragmaOnceHeaderOption;
52-
private BooleanFieldEditor cleanSerialMonitorAfterUpload;
48+
private PathEditor arduinoPrivateLibPathPathEditor;
49+
private PathEditor arduinoPrivateHardwarePathPathEditor;
50+
private ComboFieldEditor buildBeforeUploadOptionEditor;
51+
private BooleanFieldEditor openSerialMonitorOpensSerialsOptionEditor;
52+
private BooleanFieldEditor automaticallyImportLibrariesOptionEditor;
53+
private BooleanFieldEditor useArduinoToolchainSelectionEditor;
54+
private BooleanFieldEditor pragmaOnceHeaderOptionEditor;
55+
private BooleanFieldEditor cleanSerialMonitorAfterUploadEditor;
5356

5457
public PreferencePage() {
5558
super(org.eclipse.jface.preference.FieldEditorPreferencePage.GRID);
@@ -63,6 +66,8 @@ public PreferencePage() {
6366
preferences.setDefault(KEY_PRAGMA_ONCE_HEADERS, true);
6467
preferences.setDefault(KEY_PRIVATE_HARDWARE_PATHS, Defaults.getPrivateHardwarePath());
6568
preferences.setDefault(KEY_PRIVATE_LIBRARY_PATHS, Defaults.getPrivateLibraryPath());
69+
preferences.setDefault(KEY_TOOLCHAIN_SELECTION, Defaults.getUseArduinoToolSelection());
70+
6671
setPreferenceStore(preferences);
6772
}
6873

@@ -97,24 +102,29 @@ public boolean performOk() {
97102
boolean ret = super.performOk();
98103
String hardWarePaths[] = getPreferenceStore().getString(KEY_PRIVATE_HARDWARE_PATHS).split(File.pathSeparator);
99104
String libraryPaths[] = getPreferenceStore().getString(KEY_PRIVATE_LIBRARY_PATHS).split(File.pathSeparator);
100-
BoardsManager.setAutoImportLibraries(this.automaticallyImportLibrariesOption.getBooleanValue());
101-
BoardsManager.setPragmaOnceHeaders(this.PragmaOnceHeaderOption.getBooleanValue());
105+
106+
Preferences.setUseArduinoToolSelection(this.useArduinoToolchainSelectionEditor.getBooleanValue());
107+
Preferences.setAutoImportLibraries(this.automaticallyImportLibrariesOptionEditor.getBooleanValue());
108+
Preferences.setPragmaOnceHeaders(this.pragmaOnceHeaderOptionEditor.getBooleanValue());
102109
BoardsManager.setPrivateHardwarePaths(hardWarePaths);
103-
BoardsManager.setPrivateLibraryPaths(libraryPaths);
110+
LibraryManager.setPrivateLibraryPaths(libraryPaths);
104111
return ret;
105112
}
106113

107114
@Override
108115
public void init(IWorkbench workbench) {
109116
String hardWarePaths = BoardsManager.getPrivateHardwarePathsString();
110117
String libraryPaths = LibraryManager.getPrivateLibraryPathsString();
111-
boolean autoImport = BoardsManager.getAutoImportLibraries();
112-
boolean pragmaOnceHeaders = BoardsManager.getPragmaOnceHeaders();
118+
boolean autoImport = Preferences.getAutoImportLibraries();
119+
boolean pragmaOnceHeaders = Preferences.getPragmaOnceHeaders();
120+
boolean useArduinoToolchainSelection =Preferences.getUseArduinoToolSelection();
113121

114122
getPreferenceStore().setValue(KEY_AUTO_IMPORT_LIBRARIES, autoImport);
115123
getPreferenceStore().setValue(KEY_PRAGMA_ONCE_HEADERS, pragmaOnceHeaders);
116124
getPreferenceStore().setValue(KEY_PRIVATE_HARDWARE_PATHS, hardWarePaths);
117125
getPreferenceStore().setValue(KEY_PRIVATE_LIBRARY_PATHS, libraryPaths);
126+
getPreferenceStore().setValue(KEY_TOOLCHAIN_SELECTION, useArduinoToolchainSelection);
127+
118128
}
119129

120130
/**
@@ -126,39 +136,45 @@ public void init(IWorkbench workbench) {
126136
protected void createFieldEditors() {
127137
final Composite parent = getFieldEditorParent();
128138

129-
this.arduinoPrivateLibPath = new PathEditor(KEY_PRIVATE_LIBRARY_PATHS, Messages.ui_private_lib_path,
139+
this.arduinoPrivateLibPathPathEditor = new PathEditor(KEY_PRIVATE_LIBRARY_PATHS, Messages.ui_private_lib_path,
130140
Messages.ui_private_lib_path_help, parent);
131-
addField(this.arduinoPrivateLibPath);
141+
addField(this.arduinoPrivateLibPathPathEditor);
132142

133-
this.arduinoPrivateHardwarePath = new PathEditor(KEY_PRIVATE_HARDWARE_PATHS, Messages.ui_private_hardware_path,
143+
this.arduinoPrivateHardwarePathPathEditor = new PathEditor(KEY_PRIVATE_HARDWARE_PATHS, Messages.ui_private_hardware_path,
134144
Messages.ui_private_hardware_path_help, parent);
135-
addField(this.arduinoPrivateHardwarePath);
145+
addField(this.arduinoPrivateHardwarePathPathEditor);
136146

137147
Dialog.applyDialogFont(parent);
138148
createLine(parent, 4);
139149
String[][] YesNoAskOptions = new String[][] { { Messages.ui_ask_every_upload, "ASK" }, //$NON-NLS-1$
140150
{ "Yes", TRUE }, { "No", FALSE } }; //$NON-NLS-1$ //$NON-NLS-2$
141-
this.buildBeforeUploadOption = new ComboFieldEditor(MyPreferences.KEY_BUILD_BEFORE_UPLOAD_OPTION,
151+
this.buildBeforeUploadOptionEditor = new ComboFieldEditor(MyPreferences.KEY_BUILD_BEFORE_UPLOAD_OPTION,
142152
Messages.ui_build_before_upload, YesNoAskOptions, parent);
143-
addField(this.buildBeforeUploadOption);
153+
addField(this.buildBeforeUploadOptionEditor);
144154
createLine(parent, 4);
145155

146-
this.openSerialMonitorOpensSerialsOption = new BooleanFieldEditor(MyPreferences.KEY_OPEN_SERIAL_WITH_MONITOR,
156+
this.useArduinoToolchainSelectionEditor = new BooleanFieldEditor(KEY_TOOLCHAIN_SELECTION,
157+
Messages.ui_use_arduino_toolchain_selection, BooleanFieldEditor.DEFAULT, parent);
158+
addField(this.useArduinoToolchainSelectionEditor);
159+
160+
createLine(parent, 4);
161+
this.openSerialMonitorOpensSerialsOptionEditor = new BooleanFieldEditor(MyPreferences.KEY_OPEN_SERIAL_WITH_MONITOR,
147162
Messages.ui_open_serial_with_monitor, BooleanFieldEditor.DEFAULT, parent);
148-
addField(this.openSerialMonitorOpensSerialsOption);
163+
addField(this.openSerialMonitorOpensSerialsOptionEditor);
149164
createLine(parent, 4);
150165

151-
this.automaticallyImportLibrariesOption = new BooleanFieldEditor(KEY_AUTO_IMPORT_LIBRARIES,
166+
167+
this.automaticallyImportLibrariesOptionEditor = new BooleanFieldEditor(KEY_AUTO_IMPORT_LIBRARIES,
152168
Messages.ui_auto_import_libraries, BooleanFieldEditor.DEFAULT, parent);
153-
addField(this.automaticallyImportLibrariesOption);
169+
addField(this.automaticallyImportLibrariesOptionEditor);
154170

155-
this.PragmaOnceHeaderOption = new BooleanFieldEditor(KEY_PRAGMA_ONCE_HEADERS, Messages.ui_pragma_once_headers,
171+
this.pragmaOnceHeaderOptionEditor = new BooleanFieldEditor(KEY_PRAGMA_ONCE_HEADERS, Messages.ui_pragma_once_headers,
156172
BooleanFieldEditor.DEFAULT, parent);
157-
addField(this.PragmaOnceHeaderOption);
173+
addField(this.pragmaOnceHeaderOptionEditor);
158174

159-
this.cleanSerialMonitorAfterUpload = new BooleanFieldEditor(MyPreferences.getCleanSerialMonitorAfterUploadKey(),
175+
this.cleanSerialMonitorAfterUploadEditor = new BooleanFieldEditor(MyPreferences.getCleanSerialMonitorAfterUploadKey(),
160176
Messages.ui_Clean_Serial_Monitor_After_Upload, BooleanFieldEditor.DEFAULT, parent);
161-
addField(this.cleanSerialMonitorAfterUpload);
177+
addField(this.cleanSerialMonitorAfterUploadEditor);
162178

163179
createLine(parent, 4);
164180
Label label = new Label(parent, SWT.LEFT);

0 commit comments

Comments
 (0)