Skip to content

Commit afe12e9

Browse files
committed
cleaning up settings path and language pref handling
1 parent d3d2f0d commit afe12e9

File tree

6 files changed

+82
-53
lines changed

6 files changed

+82
-53
lines changed

app/src/processing/app/Base.java

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1784,24 +1784,29 @@ static public boolean isLinux() {
17841784
}
17851785

17861786

1787-
// .................................................................
1787+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
17881788

17891789

1790+
/**
1791+
* Get the directory that can store settings. (Library on OS X, App Data or
1792+
* something similar on Windows, a dot folder on Linux.) Removed this as a
1793+
* preference for 3.0a3 because we need this to be stable.
1794+
*/
17901795
static public File getSettingsFolder() {
17911796
File settingsFolder = null;
17921797

1793-
String preferencesPath = Preferences.get("settings.path"); //$NON-NLS-1$
1794-
if (preferencesPath != null) {
1795-
settingsFolder = new File(preferencesPath);
1796-
1797-
} else {
1798-
try {
1799-
settingsFolder = platform.getSettingsFolder();
1800-
} catch (Exception e) {
1801-
showError("Problem getting data folder",
1802-
"Error getting the Processing data folder.", e);
1803-
}
1798+
// String preferencesPath = Preferences.get("settings.path"); //$NON-NLS-1$
1799+
// if (preferencesPath != null) {
1800+
// settingsFolder = new File(preferencesPath);
1801+
//
1802+
// } else {
1803+
try {
1804+
settingsFolder = platform.getSettingsFolder();
1805+
} catch (Exception e) {
1806+
showError("Problem getting the settings folder",
1807+
"Error getting the Processing the settings folder.", e);
18041808
}
1809+
// }
18051810

18061811
// create the folder if it doesn't exist already
18071812
if (!settingsFolder.exists()) {

app/src/processing/app/Language.java

Lines changed: 58 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@
3535
*/
3636
public class Language {
3737
static private final String FILE = "processing.app.languages.PDE";
38-
static private final String LISTING = "processing/app/languages/languages.txt";
39-
static protected final String PREF = "language";
38+
//static private final String LISTING = "processing/app/languages/languages.txt";
39+
40+
// Store the language information in a file separate from the preferences,
41+
// because preferences need the language on load time.
42+
static protected final String PREF_FILE = "language.txt";
43+
static protected final File prefFile = Base.getSettingsFile(PREF_FILE);
4044

4145
/** Single instance of this Language class */
4246
static private Language instance = null;
@@ -52,7 +56,7 @@ public class Language {
5256

5357
private Language() {
5458
String systemLanguage = Locale.getDefault().getLanguage();
55-
String language = Preferences.get(PREF);
59+
language = loadLanguage();
5660
boolean writePrefs = false;
5761

5862
if (language == null) {
@@ -72,44 +76,31 @@ private Language() {
7276
writePrefs = true;
7377
}
7478

75-
// // Get saved language
76-
// try {
77-
// File file = Base.getSettingsFile("language.txt");
78-
// if (file.exists()) {
79-
// String language = PApplet.loadStrings(file)[0];
80-
// language = language.trim().toLowerCase();
81-
// if (!language.equals("")) {
82-
// this.language = language;
83-
// } else {
84-
// Base.saveFile(this.language, file);
85-
// }
86-
// }
87-
// } catch (Exception e) {
88-
// e.printStackTrace();
89-
// }
90-
9179
if (writePrefs) {
92-
Preferences.save();
80+
saveLanguage(language);
9381
}
9482

9583
// Get bundle with translations (processing.app.language.PDE)
9684
bundle = ResourceBundle.getBundle(Language.FILE, new Locale(this.language), new UTF8Control());
9785
}
9886

9987

100-
String[] listSupported() {
101-
// // Old list of languages in alphabetical order.
102-
// final String[] SUPPORTED = {
103-
// "de", // de, German, Deutsch
104-
// "en", // en, English, English
105-
// "el", // el, Greek
106-
// "es", // es, Spanish
107-
// "fr", // fr, French, Français, Langue française
108-
// "ja", // ja, Japanese
109-
// "nl", // nl, Dutch, Nederlands
110-
// "pt", // pt, Portuguese
111-
// };
112-
88+
static private String[] listSupported() {
89+
// List of languages in alphabetical order.
90+
final String[] SUPPORTED = {
91+
"de", // de, German, Deutsch
92+
"en", // en, English, English
93+
"el", // el, Greek
94+
"es", // es, Spanish
95+
"fr", // fr, French, Français, Langue française
96+
"ja", // ja, Japanese
97+
"nl", // nl, Dutch, Nederlands
98+
"pt", // pt, Portuguese
99+
};
100+
return SUPPORTED;
101+
102+
/*
103+
// come back to this when bundles are placed outside the JAR
113104
InputStream input = getClass().getResourceAsStream(LISTING);
114105
String[] lines = PApplet.loadStrings(input);
115106
ArrayList<String> list = new ArrayList<String>();
@@ -122,9 +113,40 @@ String[] listSupported() {
122113
list.add(line);
123114
}
124115
return list.toArray(new String[0]);
116+
*/
125117
}
126118

127119

120+
/** Read the saved language */
121+
static private String loadLanguage() {
122+
try {
123+
if (prefFile.exists()) {
124+
String language = PApplet.loadStrings(prefFile)[0];
125+
language = language.trim().toLowerCase();
126+
if (!language.equals("")) {
127+
return language;
128+
}
129+
}
130+
} catch (Exception e) {
131+
e.printStackTrace();
132+
}
133+
return null;
134+
}
135+
136+
137+
/**
138+
* Save the language directly to a settings file. This is 'save' and not
139+
* 'set' because a language change requires a restart of Processing.
140+
*/
141+
static public void saveLanguage(String language) {
142+
try {
143+
Base.saveFile(language, prefFile);
144+
} catch (Exception e) {
145+
e.printStackTrace();
146+
}
147+
}
148+
149+
128150
/** Singleton constructor */
129151
static public synchronized Language init() {
130152
if (instance == null) {
@@ -152,8 +174,10 @@ static public String getLanguage() {
152174
}
153175

154176

155-
// /** Set new language */
177+
// /** Set new language (called by Preferences) */
156178
// static public void setLanguage(String language) {
179+
// this.language = language;
180+
//
157181
// try {
158182
// File file = Base.getContentFile("lib/language.txt");
159183
// Base.saveFile(language, file);

app/src/processing/app/Platform.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ public void init(Base base) {
8080
}
8181

8282

83+
/**
84+
* This function should throw an exception or return a value.
85+
* Do not return null.
86+
*/
8387
public File getSettingsFolder() throws Exception {
8488
// otherwise make a .processing directory int the user's home dir
8589
File home = new File(System.getProperty("user.home"));

app/src/processing/app/Preferences.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -816,8 +816,7 @@ protected void applyFrame() {
816816
}
817817
}
818818
if (!language.equals(Language.getLanguage()) && !language.equals("")) {
819-
//Language.setLanguage(language);
820-
set(Language.PREF, language);
819+
Language.saveLanguage(language);
821820
}
822821

823822
int oldDisplayIndex = getInteger("run.display"); //$NON-NLS-1$

app/src/processing/app/platform/WindowsPlatform.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
package processing.app.platform;
2424

2525
import java.io.File;
26+
import java.io.IOException;
2627
import java.io.UnsupportedEncodingException;
2728

2829
import com.sun.jna.Library;
@@ -261,7 +262,7 @@ public File getSettingsFolder() throws Exception {
261262
if (appData != null) {
262263
return new File(appData, APP_NAME);
263264
}
264-
return null;
265+
throw new IOException("Could not get the Application Data folder");
265266
}
266267

267268

build/shared/lib/defaults.txt

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,6 @@
4848
# has gone missing, and that it should instead use the default.
4949
#sketchbook.path=
5050

51-
# if you don't want settings to go into "application data" on windows
52-
# and "library" on macosx, set this to the alternate location.
53-
#settings.path=data
54-
5551
# By default, no sketches currently open
5652
last.sketch.count=0
5753

0 commit comments

Comments
 (0)