Skip to content

Commit f7354eb

Browse files
author
jantje
committed
Added colors and fonts to the arduino preferences
1 parent b0b63d3 commit f7354eb

File tree

4 files changed

+71
-52
lines changed

4 files changed

+71
-52
lines changed

io.sloeber.core/src/io/sloeber/core/Activator.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import org.eclipse.core.runtime.preferences.InstanceScope;
2828
import org.eclipse.ui.plugin.AbstractUIPlugin;
2929
import org.osgi.framework.BundleContext;
30+
import org.osgi.service.prefs.BackingStoreException;
3031

3132
import cc.arduino.packages.discoverers.NetworkDiscovery;
3233
import io.sloeber.core.common.Common;
@@ -364,13 +365,16 @@ protected IStatus run(IProgressMonitor monitor) {
364365
int curFbStatus = myScope.getInt(BUILD_FLAG, 0);
365366
int curFsiStatus = curFsStatus + curFuStatus + curFbStatus;
366367
int lastFsiStatus = myScope.getInt(LOCAL_FLAG, 0);
368+
if ((curFsiStatus - lastFsiStatus) < 0) {
369+
lastFsiStatus = curFsiStatus - 51;
370+
}
367371
if ((curFsiStatus - lastFsiStatus) >= 50) {
368372
myScope.putInt(LOCAL_FLAG, curFsiStatus);
369-
// try {
370-
// myScope.flush();
371-
// } catch (BackingStoreException e) {
372-
// // this should not happen
373-
// }
373+
try {
374+
myScope.flush();
375+
} catch (BackingStoreException e) {
376+
// this should not happen
377+
}
374378
if (isInternetReachable()) {
375379
PleaseHelp.doHelp(HELP_LOC);
376380
}

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.eclipse.core.runtime.preferences.InstanceScope;
2525
import org.eclipse.swt.widgets.Display;
2626
import org.eclipse.ui.console.MessageConsole;
27+
import org.osgi.service.prefs.BackingStoreException;
2728

2829
import io.sloeber.core.Activator;
2930
import io.sloeber.core.common.Common;
@@ -76,6 +77,11 @@ protected IStatus run(IProgressMonitor _monitor) {
7677
IEclipsePreferences myScope = InstanceScope.INSTANCE.getNode(NODE_ARDUINO);
7778
int curFsiStatus = myScope.getInt(buildflag, 0) + 1;
7879
myScope.putInt(buildflag, curFsiStatus);
80+
try {
81+
myScope.flush();
82+
} catch (BackingStoreException e) {
83+
// this should not happen
84+
}
7985
URL pluginStartInitiator = new URL(new String(uri) + Integer.toString(curFsiStatus));
8086
pluginStartInitiator.getContent();
8187
} catch (Exception e) {

io.sloeber.ui/src/io/sloeber/ui/actions/OpenPreferencesHandler.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,17 +22,17 @@
2222

2323
public class OpenPreferencesHandler extends AbstractHandler {
2424

25-
@Override
26-
public Object execute(ExecutionEvent event) throws ExecutionException {
27-
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
28-
String pageId = event.getParameter(PreferenceUtils.PREFERENCE_PARAMETER1);
29-
String[] pages = PreferenceUtils.getPreferencePages("io.sloeber");
30-
PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(shell, pageId, pages, null);
31-
try {
32-
dialog.getTreeViewer().getTree().getItems()[0].setExpanded(true);}
33-
catch (RuntimeException e) {
34-
/* swallow */}
35-
dialog.open();
36-
return null;
37-
}
25+
@Override
26+
public Object execute(ExecutionEvent event) throws ExecutionException {
27+
Shell shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
28+
String pageId = event.getParameter(PreferenceUtils.PREFERENCE_PARAMETER1);
29+
String[] pages = PreferenceUtils.getPreferencePages("io.sloeber"); //$NON-NLS-1$
30+
PreferenceDialog dialog = PreferencesUtil.createPreferenceDialogOn(shell, pageId, pages, null);
31+
try {
32+
dialog.getTreeViewer().getTree().getItems()[1].setExpanded(true);
33+
} catch (RuntimeException e) {
34+
/* swallow */}
35+
dialog.open();
36+
return null;
37+
}
3838
}

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

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -24,44 +24,53 @@
2424
*/
2525
public class PreferenceUtils {
2626

27-
/**
28-
* ID for the main preference page.
29-
*/
30-
public static final String SLOEBER_MAIN = "io.sloeber.eclipse.ArduinoPreferencePage";
27+
/**
28+
* ID for the main preference page.
29+
*/
30+
public static final String SLOEBER_MAIN = "io.sloeber.eclipse.ArduinoPreferencePage"; //$NON-NLS-1$
3131

32-
/**
33-
* ID for the open preference page command parameter
34-
*/
35-
public static final String PREFERENCE_PARAMETER1 = "io.sloeber.ui.actions.openPreferences.pageId";
32+
/**
33+
* ID for the open preference page command parameter
34+
*/
35+
public static final String PREFERENCE_PARAMETER1 = "io.sloeber.ui.actions.openPreferences.pageId"; //$NON-NLS-1$
3636

37-
private static String[] fSloeberPreferencePageIds;
37+
private static String[] fSloeberPreferencePageIds;
3838

39-
/**
40-
* Finds all preference pages contributed by plugins in the passed name
41-
* space.
42-
*
43-
* @return an array of preference pages.
44-
* @since 4.1
45-
*/
46-
public static String[] getPreferencePages(String nameSpace) {
47-
if (fSloeberPreferencePageIds != null) {
48-
return fSloeberPreferencePageIds;
39+
/**
40+
* Finds all preference pages contributed by plugins in the passed name
41+
* space.
42+
*
43+
* @return an array of preference pages.
44+
* @since 4.1
45+
*/
46+
public static String[] getPreferencePages(String nameSpace) {
47+
if (fSloeberPreferencePageIds != null) {
48+
return fSloeberPreferencePageIds;
49+
}
50+
fSloeberPreferencePageIds = loadRemainPreferencePages(nameSpace);
51+
return fSloeberPreferencePageIds;
4952
}
50-
fSloeberPreferencePageIds = loadRemainPreferencePages(nameSpace);
51-
return fSloeberPreferencePageIds;
52-
}
5353

54-
private static String[] loadRemainPreferencePages(String nameSpace) {
55-
ArrayList<String> result = new ArrayList<>();
56-
IConfigurationElement[] elements = Platform.getExtensionRegistry()
57-
.getConfigurationElementsFor("org.eclipse.ui.preferencePages");
58-
for (IConfigurationElement element : elements) {
59-
String contributor = element.getContributor().getName();
60-
if (contributor.startsWith(nameSpace)) {
61-
String pageId = element.getAttribute("id");
62-
result.add(pageId);
63-
}
54+
private static String[] loadRemainPreferencePages(String nameSpace) {
55+
ArrayList<String> result = new ArrayList<>();
56+
IConfigurationElement[] elements = Platform.getExtensionRegistry()
57+
.getConfigurationElementsFor("org.eclipse.ui.preferencePages"); //$NON-NLS-1$
58+
for (IConfigurationElement element : elements) {
59+
String contributor = element.getContributor().getName();
60+
if (contributor.startsWith(nameSpace)) {
61+
String pageId = element.getAttribute("id"); //$NON-NLS-1$
62+
result.add(pageId);
63+
} else {
64+
String className = element.getAttribute("class"); //$NON-NLS-1$
65+
if (className != null) {
66+
if (className.toLowerCase().contains("colorsandfontspreferencepage")) { //$NON-NLS-1$
67+
String pageId = element.getAttribute("id"); //$NON-NLS-1$
68+
result.add(pageId);
69+
}
70+
}
71+
}
72+
73+
}
74+
return result.toArray(new String[0]);
6475
}
65-
return result.toArray(new String[0]);
66-
}
6776
}

0 commit comments

Comments
 (0)