1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-17 14:05:23 +02:00

Bug 490191 - Allow changing of Arduino Home directory.

Added to Arduino Preferences page.

Change-Id: Ibe3e65f87cb613757d9e22ebb96324d43884a8e5
This commit is contained in:
Doug Schaefer 2016-06-25 21:50:09 -05:00
parent 857afa3a80
commit 47b6fd9200
3 changed files with 59 additions and 3 deletions

View file

@ -39,7 +39,13 @@ public class ArduinoPreferences {
} }
public static void setArduinoHome(Path home) { public static void setArduinoHome(Path home) {
getPrefs().put(ARDUINO_HOME, home.toString()); IEclipsePreferences prefs = getPrefs();
prefs.put(ARDUINO_HOME, home.toString());
try {
prefs.flush();
} catch (BackingStoreException e) {
Activator.log(e);
}
} }
public static String getBoardUrls() { public static String getBoardUrls() {

View file

@ -83,6 +83,7 @@ public class ArduinoManager {
private Properties props; private Properties props;
private Path arduinoHome = ArduinoPreferences.getArduinoHome();
private Map<String, ArduinoPackage> packages; private Map<String, ArduinoPackage> packages;
private Map<String, ArduinoLibrary> installedLibraries; private Map<String, ArduinoLibrary> installedLibraries;
@ -91,6 +92,14 @@ public class ArduinoManager {
} }
private synchronized void init() throws CoreException { private synchronized void init() throws CoreException {
if (!arduinoHome.equals(ArduinoPreferences.getArduinoHome())) {
// Arduino Home changed, reset.
props = null;
packages = null;
installedLibraries = null;
arduinoHome = ArduinoPreferences.getArduinoHome();
}
if (props == null) { if (props == null) {
if (!Files.exists(ArduinoPreferences.getArduinoHome())) { if (!Files.exists(ArduinoPreferences.getArduinoHome())) {
try { try {
@ -293,8 +302,8 @@ public class ArduinoManager {
} }
private synchronized void initPackages() throws CoreException { private synchronized void initPackages() throws CoreException {
init();
if (packages == null) { if (packages == null) {
init();
packages = new HashMap<>(); packages = new HashMap<>();
try { try {
@ -372,7 +381,7 @@ public class ArduinoManager {
return pkg != null ? pkg.getTool(toolName, version) : null; return pkg != null ? pkg.getTool(toolName, version) : null;
} }
public void initInstalledLibraries() throws CoreException { private void initInstalledLibraries() throws CoreException {
init(); init();
if (installedLibraries == null) { if (installedLibraries == null) {
installedLibraries = new HashMap<>(); installedLibraries = new HashMap<>();

View file

@ -10,14 +10,21 @@
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.arduino.ui.internal.preferences; package org.eclipse.cdt.arduino.ui.internal.preferences;
import java.nio.file.Paths;
import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences; import org.eclipse.cdt.arduino.core.internal.ArduinoPreferences;
import org.eclipse.cdt.arduino.ui.internal.Messages; import org.eclipse.cdt.arduino.ui.internal.Messages;
import org.eclipse.jface.preference.PreferencePage; import org.eclipse.jface.preference.PreferencePage;
import org.eclipse.swt.SWT; import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control; import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.DirectoryDialog;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbench;
import org.eclipse.ui.IWorkbenchPreferencePage; import org.eclipse.ui.IWorkbenchPreferencePage;
@ -25,6 +32,7 @@ import org.eclipse.ui.IWorkbenchPreferencePage;
public class ArduinoPreferencePage extends PreferencePage implements IWorkbenchPreferencePage { public class ArduinoPreferencePage extends PreferencePage implements IWorkbenchPreferencePage {
private Text urlsText; private Text urlsText;
private Text homeText;
@Override @Override
public void init(IWorkbench workbench) { public void init(IWorkbench workbench) {
@ -35,6 +43,33 @@ public class ArduinoPreferencePage extends PreferencePage implements IWorkbenchP
Composite control = new Composite(parent, SWT.NONE); Composite control = new Composite(parent, SWT.NONE);
control.setLayout(new GridLayout()); control.setLayout(new GridLayout());
Composite homeComp = new Composite(control, SWT.NONE);
homeComp.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
homeComp.setLayout(new GridLayout(3, false));
Label label = new Label(homeComp, SWT.NONE);
label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false));
label.setText("Arduino home:");
homeText = new Text(homeComp, SWT.BORDER);
homeText.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
homeText.setText(ArduinoPreferences.getArduinoHome().toString());
Button browse = new Button(homeComp, SWT.NONE);
browse.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
browse.setText("Browse...");
browse.addSelectionListener(new SelectionAdapter() {
@Override
public void widgetSelected(SelectionEvent e) {
DirectoryDialog dialog = new DirectoryDialog(getShell());
dialog.setMessage("Select directory for the Arduino SDKs and toolchains.");
String dir = dialog.open();
if (dir != null) {
homeText.setText(dir);
}
}
});
Text desc = new Text(control, SWT.READ_ONLY | SWT.WRAP); Text desc = new Text(control, SWT.READ_ONLY | SWT.WRAP);
GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, false); GridData layoutData = new GridData(SWT.FILL, SWT.FILL, true, false);
layoutData.widthHint = 500; layoutData.widthHint = 500;
@ -52,14 +87,20 @@ public class ArduinoPreferencePage extends PreferencePage implements IWorkbenchP
@Override @Override
public boolean performOk() { public boolean performOk() {
ArduinoPreferences.setBoardUrls(urlsText.getText()); ArduinoPreferences.setBoardUrls(urlsText.getText());
ArduinoPreferences.setArduinoHome(Paths.get(homeText.getText()));
return true; return true;
} }
@Override @Override
protected void performDefaults() { protected void performDefaults() {
String defaultHome = ArduinoPreferences.getDefaultArduinoHome();
homeText.setText(defaultHome);
ArduinoPreferences.setArduinoHome(Paths.get(defaultHome));
String defaultBoardUrl = ArduinoPreferences.getDefaultBoardUrls(); String defaultBoardUrl = ArduinoPreferences.getDefaultBoardUrls();
urlsText.setText(defaultBoardUrl); urlsText.setText(defaultBoardUrl);
ArduinoPreferences.setBoardUrls(defaultBoardUrl); ArduinoPreferences.setBoardUrls(defaultBoardUrl);
super.performDefaults(); super.performDefaults();
} }