Skip to content

Commit b2966cb

Browse files
committed
make sketch.properties work elsewhere (issue #722), other notes
1 parent 3f52526 commit b2966cb

File tree

5 files changed

+68
-21
lines changed

5 files changed

+68
-21
lines changed

app/src/processing/app/Base.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -533,10 +533,17 @@ protected void changeMode(Mode mode) {
533533

534534
// save a mode file into this sketch folder
535535
File sketchProps = new File(sketch.getFolder(), "sketch.properties");
536-
PrintWriter writer = PApplet.createWriter(sketchProps);
537-
writer.println("mode=" + mode.getTitle());
538-
writer.flush();
539-
writer.close();
536+
try {
537+
Settings props = new Settings(sketchProps);
538+
props.set("mode", mode.getTitle());
539+
props.save();
540+
} catch (IOException e) {
541+
e.printStackTrace();
542+
}
543+
// PrintWriter writer = PApplet.createWriter(sketchProps);
544+
// writer.println("mode=" + mode.getTitle());
545+
// writer.flush();
546+
// writer.close();
540547

541548
// close this sketch
542549
int[] where = activeEditor.getPlacement();

app/src/processing/app/Mode.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,10 @@ public Mode(Base base, File folder) {
6262

6363
try {
6464
theme = new Settings(new File(folder, "theme/theme.txt"));
65+
66+
// other things that have to be set explicitly for the defaults
67+
theme.setColor("run.window.bgcolor", SystemColor.control);
68+
6569
} catch (IOException e) {
6670
Base.showError("Problem loading theme.txt",
6771
"Could not load theme.txt, please re-install Processing", e);

app/src/processing/app/Settings.java

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/*
44
Part of the Processing project - http://processing.org
55
6-
Copyright (c) 2004-10 Ben Fry and Casey Reas
6+
Copyright (c) 2004-11 Ben Fry and Casey Reas
77
Copyright (c) 2001-04 Massachusetts Institute of Technology
88
99
This program is free software; you can redistribute it and/or modify
@@ -37,21 +37,31 @@
3737
* and to make way for future ability to customize.
3838
*/
3939
public class Settings {
40-
/** Copy of the defaults in case the user mangles a preference. */
40+
/**
41+
* Copy of the defaults in case the user mangles a preference.
42+
* It's necessary to keep a copy of the defaults around, because the user may
43+
* have mangled a setting on their own. In the past, we used to load the
44+
* defaults, then replace those with what was in the user's preferences file.
45+
* Problem is, if something like a font entry in the user's file no longer
46+
* parses properly, we need to be able to get back to a clean version of that
47+
* setting so we can recover.
48+
*/
4149
HashMap<String,String> defaults;
42-
/** Table of attributes/values for the theme. */
50+
51+
/** Table of attributes/values. */
4352
HashMap<String,String> table = new HashMap<String,String>();;
53+
4454
/** Associated file for this settings data. */
4555
File file;
4656

4757

4858
public Settings(File file) throws IOException {
4959
this.file = file;
50-
load();
51-
52-
// other things that have to be set explicitly for the defaults
53-
setColor("run.window.bgcolor", SystemColor.control);
54-
60+
61+
if (file.exists()) {
62+
load();
63+
}
64+
5565
// clone the hash table
5666
defaults = (HashMap<String,String>) table.clone();
5767
}
@@ -86,19 +96,23 @@ public void load() {
8696
}
8797

8898

99+
public void save() {
100+
PrintWriter writer = PApplet.createWriter(file);
101+
102+
for (String key : table.keySet()) {
103+
writer.println(key + "=" + table.get(key));
104+
}
105+
106+
writer.flush();
107+
writer.close();
108+
}
109+
110+
89111
public String get(String attribute) {
90112
return table.get(attribute);
91113
}
92114

93115

94-
/**
95-
* It's necessary to keep a copy of the defaults around, because the user may
96-
* have mangled a setting on their own. In the past, we used to load the
97-
* defaults, then replace those with what was in the user's preferences file.
98-
* Problem is, if something like a font entry in the user's file no longer
99-
* parses properly, we need to be able to get back to a clean version of that
100-
* setting so we can recover.
101-
*/
102116
public String getDefault(String attribute) {
103117
return defaults.get(attribute);
104118
}

core/todo.txt

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -441,11 +441,11 @@ _ add docs for screenWidth and screenHeight
441441
_ remove delay() documentation
442442

443443
2.0
444+
_ PNode.getChildren() shouldn't make a new array.. toArray() can do that
444445
_ texts using textMode(SCREEN) not displayed in Processing 1.5.1
445446
_ http://code.google.com/p/processing/issues/detail?id=741
446447
_ thread() causes weird flickering
447448
_ http://code.google.com/p/processing/issues/detail?id=742
448-
449449
_ toArray(), toArray(float[]), toVectorArray(), toVectorArray(PVector[])
450450
_ toColorArray(), toColorArray(float[])...
451451
_ remove blend(), add blendMode()
@@ -524,6 +524,18 @@ _ http://code.google.com/p/processing/issues/detail?id=722
524524
_ add methods to PShape to apply all transformations in the tree
525525
_ need to clean up the hints in the reference/source
526526

527+
gui priorities
528+
+ Label
529+
+ Button
530+
+ Scrollbar/Slider
531+
- Checkbox
532+
- Radio
533+
. List
534+
. Textblock
535+
\ Knob
536+
\ Progress bar
537+
\ Toggle
538+
527539
decisions to make
528540
_ possible addition for 'implementation' variable
529541
_ http://code.google.com/p/processing/issues/detail?id=281
@@ -552,6 +564,8 @@ _ http://code.google.com/p/processing/issues/detail?id=246
552564
_ path for selectXxxxx() functions
553565
_ http://code.google.com/p/processing/issues/detail?id=233
554566
_ provide a way to clear the PGraphics with plain alpha
567+
_ add breakShape to the public API
568+
_ or handle differently in general.. nested beginPath() calls?
555569

556570
_ opengl applet problems
557571
_ http://code.google.com/p/processing/issues/detail?id=196

todo.txt

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ X Resize box on OS X is not present in Examples box
2121
X http://code.google.com/p/processing/issues/detail?id=730
2222
X New/Rename Tab commands inhibited when Console/Message Area is hidden
2323
X http://code.google.com/p/processing/issues/detail?id=745
24+
X make sketch.properties usable elsewhere by loading/reloading
25+
X http://code.google.com/p/processing/issues/detail?id=722
2426

2527
cleanup
2628
X how is autoformat doing? good now
@@ -41,6 +43,12 @@ o prevent people from setting the font size too small in the editor
4143
o how do we figure out what "too small" is?
4244
X -> everyone thinks this is funny
4345

46+
decisions
47+
_ kill external editor (for all its quirks) in favor of command line?
48+
_ use external editor needs to enable/disable across all windows
49+
_ http://code.google.com/p/processing/issues/detail?id=515
50+
_ lots of other things in the google code issues list
51+
4452
required for 0198 release
4553
_ automatically insert the 'import processing.opengl' when P3D used
4654
_ add support for automatically including OpenGL when asking for P3D

0 commit comments

Comments
 (0)