Skip to content

Commit f4df44d

Browse files
author
jantje
committed
#718 added setUpdateJsonFilesFlag and removed getUpdateJasonFilesKey
Because the UI and core use a different storage location getting the key does not work
1 parent 50b43c5 commit f4df44d

File tree

4 files changed

+84
-72
lines changed

4 files changed

+84
-72
lines changed

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,6 @@ public class BoardsManager {
4747
private static final String CPP = "cpp";//$NON-NLS-1$
4848
private static final String C = "c";//$NON-NLS-1$
4949

50-
public static String getUpdateJasonFilesKey() {
51-
return ConfigurationPreferences.getUpdateJasonFilesKey();
52-
}
53-
5450
/**
5551
* Gets the board descriptor based on the information provided. If
5652
* jsonFileName="local" the board is assumed not to be installed by the
@@ -717,4 +713,9 @@ public static void onlyKeepLatestPlatforms() {
717713

718714
}
719715

716+
public static void setUpdateJsonFilesFlag(boolean flag) {
717+
ConfigurationPreferences.setUpdateJasonFilesFlag(flag);
718+
719+
}
720+
720721
}

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

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,16 @@ private static boolean getBoolean(String key, boolean defaultValue) {
5959
return myScope.getBoolean(key, defaultValue);
6060
}
6161

62+
private static void setBoolean(String key, boolean value) {
63+
IEclipsePreferences myScope = ConfigurationScope.INSTANCE.getNode(NODE_ARDUINO);
64+
myScope.putBoolean(key, value);
65+
try {
66+
myScope.flush();
67+
} catch (BackingStoreException e) {
68+
e.printStackTrace();
69+
}
70+
}
71+
6272
private static void setString(String key, String value) {
6373
IEclipsePreferences myScope = ConfigurationScope.INSTANCE.getNode(NODE_ARDUINO);
6474
myScope.put(key, value);
@@ -165,12 +175,12 @@ public static Path getMakePath() {
165175

166176
}
167177

168-
public static String getUpdateJasonFilesKey() {
169-
return KEY_UPDATE_JASONS;
178+
public static boolean getUpdateJasonFilesFlag() {
179+
return getBoolean(KEY_UPDATE_JASONS, false);
170180
}
171181

172-
public static boolean getUpdateJasonFilesValue() {
173-
return getBoolean(KEY_UPDATE_JASONS, false);
182+
public static void setUpdateJasonFilesFlag(boolean newFlag) {
183+
setBoolean(KEY_UPDATE_JASONS, newFlag);
174184
}
175185

176186
private static String systemHash = null;

io.sloeber.core/src/io/sloeber/core/managers/Manager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public static void addPackageURLs(HashSet<String> packageUrlsToAdd, boolean forc
8888
* @param monitor
8989
*/
9090
public static void startup_Pluging(IProgressMonitor monitor) {
91-
loadIndices(ConfigurationPreferences.getUpdateJasonFilesValue());
91+
loadIndices(ConfigurationPreferences.getUpdateJasonFilesFlag());
9292
List<Board> allBoards = getInstalledBoards();
9393
if (allBoards.isEmpty()) { // If boards are installed do nothing
9494
InstallDefaultLibraries(monitor);

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

Lines changed: 64 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -25,68 +25,69 @@
2525
import io.sloeber.ui.helpers.MyPreferences;
2626

2727
public class ThirdPartyHardwareSelectionPage extends FieldEditorPreferencePage implements IWorkbenchPreferencePage {
28-
29-
private Text urlsText;
30-
BooleanFieldEditor upDateJsons;
31-
32-
public ThirdPartyHardwareSelectionPage() {
33-
super(org.eclipse.jface.preference.FieldEditorPreferencePage.GRID);
34-
setDescription(Messages.json_maintain);
35-
setPreferenceStore(new ScopedPreferenceStore(ConfigurationScope.INSTANCE, MyPreferences.NODE_ARDUINO));
36-
}
37-
38-
@Override
39-
public boolean performOk() {
40-
BoardsManager.setBoardsPackageURL(this.urlsText.getText().split(System.lineSeparator()));
41-
return super.performOk();
42-
}
43-
44-
@Override
45-
protected void performDefaults() {
46-
super.performDefaults();
47-
this.urlsText.setText(BoardsManager.getDefaultBoardsPackageURLs());
48-
}
49-
50-
@Override
51-
protected void createFieldEditors() {
52-
String selectedJsons[] = BoardsManager.getBoardsPackageURLList();
53-
final Composite parent = getFieldEditorParent();
54-
// Composite control = new Composite(parent, SWT.NONE);
55-
Label title = new Label(parent, SWT.UP);
56-
title.setFont(parent.getFont());
57-
58-
title.setText(Messages.ui_url_for_package_index_file);
59-
title.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
60-
61-
this.urlsText = new Text(parent, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER | SWT.WRAP);
62-
GridData gd = new GridData(GridData.FILL_BOTH);
63-
this.urlsText.setLayoutData(gd);
64-
this.urlsText.setText(StringUtil.join(selectedJsons, System.lineSeparator()));
65-
66-
this.upDateJsons = new BooleanFieldEditor(BoardsManager.getUpdateJasonFilesKey(), Messages.json_update,
67-
BooleanFieldEditor.DEFAULT, parent);
68-
addField(this.upDateJsons);
69-
final Hyperlink link = new Hyperlink(parent, SWT.NONE);
70-
link.setText(Messages.json_find);
71-
link.setHref("https://github.com/arduino/Arduino/wiki/Unofficial-list-of-3rd-party-boards-support-urls"); //$NON-NLS-1$
72-
link.setUnderlined(true);
73-
link.addHyperlinkListener(new HyperlinkAdapter() {
74-
@Override
75-
public void linkActivated(HyperlinkEvent he) {
76-
try {
77-
org.eclipse.swt.program.Program.launch(link.getHref().toString());
78-
} catch (IllegalArgumentException e) {
79-
Activator.log(new Status(IStatus.ERROR, Activator.getId(), Messages.json_browser_fail, e));
80-
}
81-
}
82-
});
83-
84-
}
85-
86-
@Override
87-
public void init(IWorkbench arg0) {
88-
// Nothing to do here
89-
90-
}
28+
private static final String KEY_UPDATE_JASONS = "Update jsons files"; //$NON-NLS-1$
29+
private Text urlsText;
30+
BooleanFieldEditor upDateJsons;
31+
32+
public ThirdPartyHardwareSelectionPage() {
33+
super(org.eclipse.jface.preference.FieldEditorPreferencePage.GRID);
34+
setDescription(Messages.json_maintain);
35+
setPreferenceStore(new ScopedPreferenceStore(ConfigurationScope.INSTANCE, MyPreferences.NODE_ARDUINO));
36+
}
37+
38+
@Override
39+
public boolean performOk() {
40+
BoardsManager.setBoardsPackageURL(this.urlsText.getText().split(System.lineSeparator()));
41+
BoardsManager.setUpdateJsonFilesFlag(this.upDateJsons.getBooleanValue());
42+
return super.performOk();
43+
}
44+
45+
@Override
46+
protected void performDefaults() {
47+
super.performDefaults();
48+
this.urlsText.setText(BoardsManager.getDefaultBoardsPackageURLs());
49+
}
50+
51+
@Override
52+
protected void createFieldEditors() {
53+
String selectedJsons[] = BoardsManager.getBoardsPackageURLList();
54+
final Composite parent = getFieldEditorParent();
55+
// Composite control = new Composite(parent, SWT.NONE);
56+
Label title = new Label(parent, SWT.UP);
57+
title.setFont(parent.getFont());
58+
59+
title.setText(Messages.ui_url_for_package_index_file);
60+
title.setLayoutData(new GridData(GridData.VERTICAL_ALIGN_BEGINNING));
61+
62+
this.urlsText = new Text(parent, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER | SWT.WRAP);
63+
GridData gd = new GridData(GridData.FILL_BOTH);
64+
this.urlsText.setLayoutData(gd);
65+
this.urlsText.setText(StringUtil.join(selectedJsons, System.lineSeparator()));
66+
67+
this.upDateJsons = new BooleanFieldEditor(KEY_UPDATE_JASONS, Messages.json_update, BooleanFieldEditor.DEFAULT,
68+
parent);
69+
addField(this.upDateJsons);
70+
final Hyperlink link = new Hyperlink(parent, SWT.NONE);
71+
link.setText(Messages.json_find);
72+
link.setHref("https://github.com/arduino/Arduino/wiki/Unofficial-list-of-3rd-party-boards-support-urls"); //$NON-NLS-1$
73+
link.setUnderlined(true);
74+
link.addHyperlinkListener(new HyperlinkAdapter() {
75+
@Override
76+
public void linkActivated(HyperlinkEvent he) {
77+
try {
78+
org.eclipse.swt.program.Program.launch(link.getHref().toString());
79+
} catch (IllegalArgumentException e) {
80+
Activator.log(new Status(IStatus.ERROR, Activator.getId(), Messages.json_browser_fail, e));
81+
}
82+
}
83+
});
84+
85+
}
86+
87+
@Override
88+
public void init(IWorkbench arg0) {
89+
// Nothing to do here
90+
91+
}
9192

9293
}

0 commit comments

Comments
 (0)