Skip to content

Commit 1b09894

Browse files
committed
Fixed regressions
1 parent adf88f6 commit 1b09894

File tree

6 files changed

+162
-20
lines changed

6 files changed

+162
-20
lines changed

.idea/misc.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

java/preprocessor/build.gradle.kts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,8 @@ repositories{
1717
sourceSets{
1818
main{
1919
java{
20-
srcDirs("../src/", "../generated")
21-
include("processing/mode/java/preproc/**/*")
20+
srcDirs("src/main/java", "../src/", "../generated")
21+
include("processing/mode/java/preproc/**/*", "processing/app/**/*")
2222
}
2323
}
2424
}
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package processing.app;
2+
3+
import java.io.File;
4+
5+
public class Base {
6+
static private final int REVISION = 1294;
7+
8+
static private File settingsOverride;
9+
/**
10+
* @return the current revision number, safe to be used for update checks
11+
*/
12+
static public int getRevision() {
13+
return REVISION;
14+
}
15+
/**
16+
* Get the directory that can store settings. (Library on OS X, App Data or
17+
* something similar on Windows, a dot folder on Linux.) Removed this as a
18+
* preference for 3.0a3 because we need this to be stable, but adding back
19+
* for 4.0 beta 4 so that folks can do 'portable' versions again.
20+
*/
21+
static public File getSettingsFolder() {
22+
File settingsFolder = null;
23+
24+
try {
25+
settingsFolder = Platform.getSettingsFolder();
26+
27+
// create the folder if it doesn't exist already
28+
if (!settingsFolder.exists()) {
29+
if (!settingsFolder.mkdirs()) {
30+
System.err.println("Could not create the folder " + settingsFolder);
31+
32+
}
33+
}
34+
} catch (Exception e) {
35+
System.err.println("Could not get the settings folder");
36+
}
37+
return settingsFolder;
38+
}
39+
40+
41+
42+
static public File getSettingsOverride() {
43+
return settingsOverride;
44+
}
45+
46+
/**
47+
* Convenience method to get a File object for the specified filename inside
48+
* the settings folder. Used to get preferences and recent sketch files.
49+
* @param filename A file inside the settings folder.
50+
* @return filename wrapped as a File object inside the settings folder
51+
*/
52+
static public File getSettingsFile(String filename) {
53+
return new File(getSettingsFolder(), filename);
54+
}
55+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package processing.app;
2+
3+
import java.io.File;
4+
5+
public class Platform {
6+
static public File getSettingsFolder() {
7+
File settingsFolder = null;
8+
String os = System.getProperty("os.name").toLowerCase();
9+
if (os.contains("mac")) {
10+
settingsFolder = new File(System.getProperty("user.home") + "/Library/Processing");
11+
} else if (os.contains("windows")) {
12+
String appData = System.getenv("APPDATA");
13+
if (appData == null) {
14+
appData = System.getProperty("user.home");
15+
}
16+
settingsFolder = new File(appData + "\\Processing");
17+
} else {
18+
settingsFolder = new File(System.getProperty("user.home") + "/.processing");
19+
}
20+
return settingsFolder;
21+
}
22+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2+
3+
/*
4+
Part of the Processing project - http://processing.org
5+
6+
Copyright (c) 2014-19 The Processing Foundation
7+
8+
This program is free software; you can redistribute it and/or modify
9+
it under the terms of the GNU General Public License version 2
10+
as published by the Free Software Foundation.
11+
12+
This program is distributed in the hope that it will be useful,
13+
but WITHOUT ANY WARRANTY; without even the implied warranty of
14+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15+
GNU General Public License for more details.
16+
17+
You should have received a copy of the GNU General Public License
18+
along with this program; if not, write to the Free Software Foundation,
19+
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20+
*/
21+
22+
package processing.app;
23+
24+
import java.io.BufferedReader;
25+
import java.io.File;
26+
import java.io.FileReader;
27+
import java.util.Properties;
28+
29+
/**
30+
* Storage class for user preferences and environment settings.
31+
* <P>
32+
* This class does not use the Properties class because .properties files use
33+
* ISO 8859-1 encoding, which is highly likely to be a problem when trying to
34+
* save sketch folders and locations. Like the rest of Processing, we use UTF8.
35+
* <p>
36+
* We don't use the Java Preferences API because it would entail writing to
37+
* the registry (on Windows), or an obscure file location (on Mac OS X) and
38+
* make it far more difficult (impossible) to remove the preferences.txt to
39+
* reset them (when they become corrupt), or to find the the file to make
40+
* edits for numerous obscure preferences that are not part of the preferences
41+
* window. If we added a generic editor (e.g. about:config in Mozilla) for
42+
* such things, we could start using the Java Preferences API. But wow, that
43+
* sounds like a lot of work. Not unlike writing this paragraph.
44+
*/
45+
public class Preferences {
46+
static public String get(String attribute /*, String defaultValue */) {
47+
try {
48+
var settingsFile = Base.getSettingsFile("preferences.txt");
49+
var reader = new BufferedReader(new FileReader(settingsFile));
50+
51+
var settings = new Properties();
52+
settings.load(reader);
53+
reader.close();
54+
55+
return settings.getProperty(attribute);
56+
}catch (Exception e) {
57+
return null;
58+
}
59+
}
60+
static public boolean getBoolean(String attribute) {
61+
String value = get(attribute); //, null);
62+
return Boolean.parseBoolean(value);
63+
}
64+
}

java/src/processing/mode/java/preproc/PdeParseTreeListener.java

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@
3030

3131
import org.antlr.v4.runtime.tree.ParseTree;
3232

33+
import processing.app.Base;
34+
import processing.app.Preferences;
3335
import processing.core.PApplet;
3436
import processing.mode.java.preproc.PdePreprocessor.Mode;
3537

@@ -1057,7 +1059,7 @@ protected void writePreprocessorComment(PrintWriterWithEditGen headerWriter,
10571059

10581060
String newCode = String.format(
10591061
"/* autogenerated by Processing revision %04d on %s */",
1060-
1234,
1062+
Base.getRevision(),
10611063
dateStr
10621064
);
10631065

@@ -1232,22 +1234,21 @@ protected void writeMain(PrintWriterWithEditGen footerWriter,
12321234
{ // assemble line with applet args
12331235
StringJoiner argsJoiner = new StringJoiner(", ");
12341236

1235-
// TODO: Add support for fullscreen. Not through settings.
1236-
// boolean shouldFullScreen = Preferences.getBoolean("export.application.present");
1237-
// shouldFullScreen = shouldFullScreen || Preferences.getBoolean("export.application.fullscreen");
1238-
// if (shouldFullScreen) {
1239-
// argsJoiner.add("\"" + PApplet.ARGS_FULL_SCREEN + "\"");
1240-
//
1241-
// String bgColor = Preferences.get("run.present.bgcolor");
1242-
// argsJoiner.add("\"" + PApplet.ARGS_BGCOLOR + "=" + bgColor + "\"");
1243-
//
1244-
// if (Preferences.getBoolean("export.application.stop")) {
1245-
// String stopColor = Preferences.get("run.present.stop.color");
1246-
// argsJoiner.add("\"" + PApplet.ARGS_STOP_COLOR + "=" + stopColor + "\"");
1247-
// } else {
1248-
// argsJoiner.add("\"" + PApplet.ARGS_HIDE_STOP + "\"");
1249-
// }
1250-
// }
1237+
boolean shouldFullScreen = Preferences.getBoolean("export.application.present");
1238+
shouldFullScreen = shouldFullScreen || Preferences.getBoolean("export.application.fullscreen");
1239+
if (shouldFullScreen) {
1240+
argsJoiner.add("\"" + PApplet.ARGS_FULL_SCREEN + "\"");
1241+
1242+
String bgColor = Preferences.get("run.present.bgcolor");
1243+
argsJoiner.add("\"" + PApplet.ARGS_BGCOLOR + "=" + bgColor + "\"");
1244+
1245+
if (Preferences.getBoolean("export.application.stop")) {
1246+
String stopColor = Preferences.get("run.present.stop.color");
1247+
argsJoiner.add("\"" + PApplet.ARGS_STOP_COLOR + "=" + stopColor + "\"");
1248+
} else {
1249+
argsJoiner.add("\"" + PApplet.ARGS_HIDE_STOP + "\"");
1250+
}
1251+
}
12511252

12521253
argsJoiner.add("\"" + sketchName + "\"");
12531254
footerWriter.addCode(argsJoiner.toString());

0 commit comments

Comments
 (0)