diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 061c44705..145cb093e 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -1784,24 +1784,29 @@ public class Base { } - // ................................................................. + // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . + /** + * Get the directory that can store settings. (Library on OS X, App Data or + * something similar on Windows, a dot folder on Linux.) Removed this as a + * preference for 3.0a3 because we need this to be stable. + */ static public File getSettingsFolder() { File settingsFolder = null; - String preferencesPath = Preferences.get("settings.path"); //$NON-NLS-1$ - if (preferencesPath != null) { - settingsFolder = new File(preferencesPath); - - } else { - try { - settingsFolder = platform.getSettingsFolder(); - } catch (Exception e) { - showError("Problem getting data folder", - "Error getting the Processing data folder.", e); - } +// String preferencesPath = Preferences.get("settings.path"); //$NON-NLS-1$ +// if (preferencesPath != null) { +// settingsFolder = new File(preferencesPath); +// +// } else { + try { + settingsFolder = platform.getSettingsFolder(); + } catch (Exception e) { + showError("Problem getting the settings folder", + "Error getting the Processing the settings folder.", e); } +// } // create the folder if it doesn't exist already if (!settingsFolder.exists()) { diff --git a/app/src/processing/app/Language.java b/app/src/processing/app/Language.java index 50b76ff74..daf9a227a 100644 --- a/app/src/processing/app/Language.java +++ b/app/src/processing/app/Language.java @@ -35,8 +35,12 @@ import processing.core.PApplet; */ public class Language { static private final String FILE = "processing.app.languages.PDE"; - static private final String LISTING = "processing/app/languages/languages.txt"; - static protected final String PREF = "language"; + //static private final String LISTING = "processing/app/languages/languages.txt"; + + // Store the language information in a file separate from the preferences, + // because preferences need the language on load time. + static protected final String PREF_FILE = "language.txt"; + static protected final File prefFile = Base.getSettingsFile(PREF_FILE); /** Single instance of this Language class */ static private Language instance = null; @@ -52,7 +56,7 @@ public class Language { private Language() { String systemLanguage = Locale.getDefault().getLanguage(); - String language = Preferences.get(PREF); + language = loadLanguage(); boolean writePrefs = false; if (language == null) { @@ -72,24 +76,8 @@ public class Language { writePrefs = true; } -// // Get saved language -// try { -// File file = Base.getSettingsFile("language.txt"); -// if (file.exists()) { -// String language = PApplet.loadStrings(file)[0]; -// language = language.trim().toLowerCase(); -// if (!language.equals("")) { -// this.language = language; -// } else { -// Base.saveFile(this.language, file); -// } -// } -// } catch (Exception e) { -// e.printStackTrace(); -// } - if (writePrefs) { - Preferences.save(); + saveLanguage(language); } // Get bundle with translations (processing.app.language.PDE) @@ -97,19 +85,22 @@ public class Language { } - String[] listSupported() { -// // Old list of languages in alphabetical order. -// final String[] SUPPORTED = { -// "de", // de, German, Deutsch -// "en", // en, English, English -// "el", // el, Greek -// "es", // es, Spanish -// "fr", // fr, French, Français, Langue française -// "ja", // ja, Japanese -// "nl", // nl, Dutch, Nederlands -// "pt", // pt, Portuguese -// }; + static private String[] listSupported() { + // List of languages in alphabetical order. + final String[] SUPPORTED = { + "de", // de, German, Deutsch + "en", // en, English, English + "el", // el, Greek + "es", // es, Spanish + "fr", // fr, French, Français, Langue française + "ja", // ja, Japanese + "nl", // nl, Dutch, Nederlands + "pt", // pt, Portuguese + }; + return SUPPORTED; + /* + // come back to this when bundles are placed outside the JAR InputStream input = getClass().getResourceAsStream(LISTING); String[] lines = PApplet.loadStrings(input); ArrayList list = new ArrayList(); @@ -122,9 +113,40 @@ public class Language { list.add(line); } return list.toArray(new String[0]); + */ } + /** Read the saved language */ + static private String loadLanguage() { + try { + if (prefFile.exists()) { + String language = PApplet.loadStrings(prefFile)[0]; + language = language.trim().toLowerCase(); + if (!language.equals("")) { + return language; + } + } + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + + + /** + * Save the language directly to a settings file. This is 'save' and not + * 'set' because a language change requires a restart of Processing. + */ + static public void saveLanguage(String language) { + try { + Base.saveFile(language, prefFile); + } catch (Exception e) { + e.printStackTrace(); + } + } + + /** Singleton constructor */ static public synchronized Language init() { if (instance == null) { @@ -152,8 +174,10 @@ public class Language { } -// /** Set new language */ +// /** Set new language (called by Preferences) */ // static public void setLanguage(String language) { +// this.language = language; +// // try { // File file = Base.getContentFile("lib/language.txt"); // Base.saveFile(language, file); diff --git a/app/src/processing/app/Platform.java b/app/src/processing/app/Platform.java index 5b16bd5ff..c5248ec51 100644 --- a/app/src/processing/app/Platform.java +++ b/app/src/processing/app/Platform.java @@ -80,6 +80,10 @@ public class Platform { } + /** + * This function should throw an exception or return a value. + * Do not return null. + */ public File getSettingsFolder() throws Exception { // otherwise make a .processing directory int the user's home dir File home = new File(System.getProperty("user.home")); diff --git a/app/src/processing/app/Preferences.java b/app/src/processing/app/Preferences.java index 9ece2af18..bd8c12204 100644 --- a/app/src/processing/app/Preferences.java +++ b/app/src/processing/app/Preferences.java @@ -816,8 +816,7 @@ public class Preferences { } } if (!language.equals(Language.getLanguage()) && !language.equals("")) { - //Language.setLanguage(language); - set(Language.PREF, language); + Language.saveLanguage(language); } int oldDisplayIndex = getInteger("run.display"); //$NON-NLS-1$ diff --git a/app/src/processing/app/platform/WindowsPlatform.java b/app/src/processing/app/platform/WindowsPlatform.java index 0c14b5ead..47b1d2746 100644 --- a/app/src/processing/app/platform/WindowsPlatform.java +++ b/app/src/processing/app/platform/WindowsPlatform.java @@ -23,6 +23,7 @@ package processing.app.platform; import java.io.File; +import java.io.IOException; import java.io.UnsupportedEncodingException; import com.sun.jna.Library; @@ -261,7 +262,7 @@ public class WindowsPlatform extends Platform { if (appData != null) { return new File(appData, APP_NAME); } - return null; + throw new IOException("Could not get the Application Data folder"); } diff --git a/build/shared/lib/defaults.txt b/build/shared/lib/defaults.txt index a7e5706a8..f8e453211 100644 --- a/build/shared/lib/defaults.txt +++ b/build/shared/lib/defaults.txt @@ -48,10 +48,6 @@ # has gone missing, and that it should instead use the default. #sketchbook.path= -# if you don't want settings to go into "application data" on windows -# and "library" on macosx, set this to the alternate location. -#settings.path=data - # By default, no sketches currently open last.sketch.count=0