Skip to content

Commit 5350b0a

Browse files
committed
activate the welcome screens
1 parent ff56026 commit 5350b0a

File tree

9 files changed

+229
-77
lines changed

9 files changed

+229
-77
lines changed

app/src/processing/app/Base.java

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
import processing.app.ui.EditorState;
4949
import processing.app.ui.PreferencesFrame;
5050
import processing.app.ui.Recent;
51+
import processing.app.ui.Welcome;
5152
import processing.core.*;
5253
import processing.data.StringDict;
5354
import processing.data.StringList;
@@ -193,23 +194,39 @@ static private void createAndShowGUI(String[] args) {
193194
// run static initialization that grabs all the prefs
194195
Preferences.init();
195196

196-
// Get the sketchbook path, and make sure it's set properly
197-
locateSketchbookFolder();
198-
199-
// String filename = args.length > 1 ? args[0] : null;
200197
if (!SingleInstance.alreadyRunning(args)) {
201-
// SingleInstance.startServer(platform);
202-
203198
// Set the look and feel before opening the window
204199
try {
205200
platform.setLookAndFeel();
206201
} catch (Exception e) {
207-
// String mess = e.getMessage();
208-
// if (!mess.contains("ch.randelshofer.quaqua.QuaquaLookAndFeel")) {
209202
loge("Could not set the Look & Feel", e); //$NON-NLS-1$
210-
// }
211203
}
212204

205+
boolean sketchbookPrompt = false;
206+
if (Preferences.getBoolean("welcome.show")) {
207+
if (!Preferences.getBoolean("welcome.seen")) {
208+
// Check if there's a 2.0 sketchbook present
209+
String oldPath = Preferences.getOldSketchbookPath();
210+
if (oldPath != null) {
211+
String newPath = Preferences.getSketchbookPath();
212+
// If newPath is null, this is the first run of any 3.x version
213+
if (newPath == null) {
214+
sketchbookPrompt = true;
215+
216+
} else if (oldPath.equals(newPath)) {
217+
// If both exist and are identical, then the user has been using
218+
// alpha releases of 3.x and needs to be warned about the larger
219+
// changes in this release.
220+
sketchbookPrompt = true;
221+
}
222+
}
223+
}
224+
}
225+
226+
// Get the sketchbook path, and make sure it's set properly
227+
locateSketchbookFolder();
228+
229+
213230
// Create a location for untitled sketches
214231
try {
215232
untitledFolder = Base.createTempFolder("untitled", "sketches", null);
@@ -222,10 +239,21 @@ static private void createAndShowGUI(String[] args) {
222239

223240
log("about to create base..."); //$NON-NLS-1$
224241
try {
225-
Base base = new Base(args);
242+
final Base base = new Base(args);
226243
// Prevent more than one copy of the PDE from running.
227244
SingleInstance.startServer(base);
228245

246+
// Needs to be shown after the first editor window opens, so that it
247+
// shows up on top, and doesn't prevent an editor window from opening.
248+
if (Preferences.getBoolean("welcome.show")) {
249+
final boolean prompt = sketchbookPrompt;
250+
EventQueue.invokeLater(new Runnable() {
251+
public void run() {
252+
new Welcome(base, prompt);
253+
}
254+
});
255+
}
256+
229257
} catch (Throwable t) {
230258
// Catch-all to pick up badness during startup.
231259
if (t.getCause() != null) {

app/src/processing/app/Preferences.java

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -52,11 +52,13 @@ public class Preferences {
5252
static final String DEFAULTS_FILE = "defaults.txt"; //$NON-NLS-1$
5353
static final String PREFS_FILE = "preferences.txt"; //$NON-NLS-1$
5454

55-
static HashMap<String, String> defaults;
56-
static HashMap<String, String> table = new HashMap<String, String>();
55+
static Map<String, String> defaults;
56+
static Map<String, String> table = new HashMap<String, String>();
5757
static File preferencesFile;
5858

5959

60+
// /** @return true if the sketchbook file did not exist */
61+
// static public boolean init() {
6062
static public void init() {
6163
// start by loading the defaults, in case something
6264
// important was deleted from the user prefs
@@ -101,7 +103,8 @@ static public void init() {
101103

102104
// next load user preferences file
103105
preferencesFile = Base.getSettingsFile(PREFS_FILE);
104-
if (preferencesFile.exists()) {
106+
boolean firstRun = !preferencesFile.exists();
107+
if (!firstRun) {
105108
try {
106109
load(new FileInputStream(preferencesFile));
107110

@@ -114,7 +117,8 @@ static public void init() {
114117
}
115118
}
116119

117-
if (checkSketchbookPref() || !preferencesFile.exists()) {
120+
if (checkSketchbookPref() || firstRun) {
121+
// if (firstRun) {
118122
// create a new preferences file if none exists
119123
// saves the defaults out to the file
120124
save();
@@ -135,30 +139,6 @@ static public void init() {
135139
handleProxy("http", "http.proxyHost", "http.proxyPort");
136140
handleProxy("https", "https.proxyHost", "https.proxyPort");
137141
handleProxy("socks", "socksProxyHost", "socksProxyPort");
138-
139-
/*
140-
String httpProxyHost = get("proxy.http.host");
141-
String httpProxyPort = get("proxy.http.port");
142-
if (httpProxyHost != null && httpProxyHost.length() != 0 &&
143-
httpProxyPort != null && httpProxyPort.length() != 0) {
144-
System.setProperty("http.proxyHost", httpProxyHost);
145-
System.setProperty("http.proxyPort", httpProxyPort);
146-
}
147-
String httpsProxyHost = get("proxy.https.host");
148-
String httpsProxyPort = get("proxy.https.port");
149-
if (httpsProxyHost != null && httpsProxyHost.length() != 0 &&
150-
httpsProxyPort != null && httpsProxyPort.length() != 0) {
151-
System.setProperty("https.proxyHost", httpsProxyHost);
152-
System.setProperty("https.proxyPort", httpsProxyPort);
153-
}
154-
String socksProxyHost = get("proxy.socks.host");
155-
String socksProxyPort = get("proxy.socks.port");
156-
if (socksProxyHost != null && socksProxyHost.length() != 0 &&
157-
socksProxyPort != null && socksProxyPort.length() != 0) {
158-
System.setProperty("socksProxyHost", socksProxyHost);
159-
System.setProperty("socksProxyPort", socksProxyPort);
160-
}
161-
*/
162142
}
163143

164144

@@ -434,6 +414,11 @@ static protected boolean checkSketchbookPref() {
434414
}
435415

436416

417+
static public String getOldSketchbookPath() {
418+
return get("sketchbook.path");
419+
}
420+
421+
437422
static public String getSketchbookPath() {
438423
return get("sketchbook.path.three"); //$NON-NLS-1$
439424
}

app/src/processing/app/ui/Welcome.java

Lines changed: 78 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -25,50 +25,94 @@
2525
import java.io.File;
2626

2727
import processing.app.Base;
28+
import processing.app.Language;
29+
import processing.app.Preferences;
30+
import processing.core.PApplet;
2831
import processing.data.StringDict;
2932

3033

31-
public class Welcome {
34+
public class Welcome extends WebFrame {
35+
Base base;
3236

33-
public Welcome() {
34-
EventQueue.invokeLater(new Runnable() {
35-
public void run() {
36-
// eventually this will be correct
37-
//File indexFile = Base.getLibFile("welcome/index.html");
38-
// version when running from command line for editing
39-
File indexFile = new File("../build/shared/lib/welcome/index.html");
40-
if (!indexFile.exists()) {
41-
// System.out.println("user dir is " + System.getProperty("user.dir"));
42-
// System.out.println(new File("").getAbsolutePath());
43-
// processing/build/macosx/work/Processing.app/Contents/Java
44-
// version for Scott to use for OS X debugging
45-
indexFile = Base.getContentFile("../../../../../shared/lib/welcome/index.html");
46-
// try {
47-
// System.out.println(indexFile.getCanonicalPath());
48-
// } catch (IOException e) {
49-
// e.printStackTrace();
50-
// }
51-
}
52-
53-
WebFrame frame = new WebFrame(indexFile, 400) {
54-
public void handleSubmit(StringDict dict) {
55-
dict.print();
56-
handleClose();
57-
}
5837

59-
public void handleClose() {
60-
//System.exit(0);
61-
dispose();
62-
}
63-
};
64-
frame.setVisible(true);
38+
public Welcome(Base base, boolean sketchbook) {
39+
super(getIndexFile(sketchbook), 400);
40+
this.base = base;
41+
//addStyle("#new_sketchbook { background-color: rgb(0, 255, 0); }");
42+
setVisible(true);
43+
}
44+
45+
46+
public void handleSubmit(StringDict dict) {
47+
// sketchbook = "create_new" or "use_existing"
48+
// show_each_time = "on" or <not param>
49+
//dict.print();
50+
51+
String sketchbookAction = dict.get("sketchbook", null);
52+
if ("create_new".equals(sketchbookAction)) {
53+
// open file dialog
54+
// on affirmative selection, update sketchbook folder
55+
// String path = Preferences.getSketchbookPath() + "3";
56+
// File folder = new File(path);
57+
// folder.mkdirs();
58+
File folder = new File(Preferences.getSketchbookPath()).getParentFile();
59+
PApplet.selectFolder(Language.text("preferences.sketchbook_location.popup"),
60+
"sketchbookCallback", folder,
61+
this, this);
62+
}
63+
64+
boolean keepShowing = "on".equals(dict.get("show_each_time", null));
65+
Preferences.setBoolean("welcome.show", keepShowing);
66+
Preferences.save();
67+
68+
handleClose();
69+
}
70+
71+
72+
/** Callback for the folder selector. */
73+
public void sketchbookCallback(File folder) {
74+
if (folder != null) {
75+
if (base != null) {
76+
base.setSketchbookFolder(folder);
77+
} else {
78+
System.out.println("user selected " + folder);
6579
}
66-
});
80+
}
81+
}
82+
83+
84+
public void handleClose() {
85+
dispose();
86+
}
87+
88+
89+
static private File getIndexFile(boolean sketchbook) {
90+
String filename =
91+
"welcome/" + (sketchbook ? "sketchbook.html" : "generic.html");
92+
// eventually this will be correct
93+
//File indexFile = Base.getLibFile(filename);
94+
// version when running from command line for editing
95+
File htmlFile = new File("../build/shared/lib/" + filename);
96+
if (!htmlFile.exists()) {
97+
// processing/build/macosx/work/Processing.app/Contents/Java
98+
// version for Scott to use for OS X debugging
99+
htmlFile = Base.getContentFile("../../../../../shared/lib/" + filename);
100+
}
101+
return htmlFile;
67102
}
68103

69104

70105
static public void main(String[] args) {
71106
Base.initPlatform();
72-
new Welcome();
107+
108+
EventQueue.invokeLater(new Runnable() {
109+
public void run() {
110+
new Welcome(null, true) {
111+
public void handleClose() {
112+
System.exit(0);
113+
}
114+
};
115+
}
116+
});
73117
}
74118
}

build/shared/lib/defaults.txt

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,16 @@
4646
# Note that this path must exist already otherwise it won't see
4747
# the sketchbook folder, and will instead assume the sketchbook
4848
# has gone missing, and that it should instead use the default.
49-
#sketchbook.path=
49+
# In 3.0, the location has changed.
50+
#sketchbook.path.three=
5051

51-
# By default, no sketches currently open
52-
last.sketch.count=0
52+
welcome.show = true
53+
welcome.seen = false
5354

55+
# By default, no sketches currently open
56+
last.sketch.count = 0
5457
# true if you want sketches to re-open when you next run processing
55-
last.sketch.restore=true
58+
last.sketch.restore = true
5659

5760
# by default, contributions are moved to backup folders when
5861
# they are removed or replaced. The locations of the backup
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<html>
2+
<head>
3+
<title> Welcome to Processing 3 </title>
4+
<style type="text/css">
5+
6+
* {
7+
margin: 0;
8+
padding: 0;
9+
}
10+
11+
body {
12+
padding: 20px;
13+
/* Use the Processing font */
14+
font-family: "Source Sans Pro";
15+
}
16+
17+
h1 {
18+
margin-bottom: 0;
19+
font-size: 16px;
20+
}
21+
22+
p {
23+
margin-bottom: 0;
24+
font-size: 11px;
25+
line-height: 12px;
26+
}
27+
28+
table {
29+
margin-top: 10px;
30+
margin-bottom: 0;
31+
}
32+
33+
p.inset, table.inset {
34+
padding: 10px;
35+
background-color: rgb(224, 253, 251);
36+
}
37+
38+
a {
39+
color: #2c7bb5;
40+
text-decoration: none;
41+
}
42+
43+
#startButton {
44+
margin-left: 50px;
45+
}
46+
47+
</style>
48+
</head>
49+
<body>
50+
51+
<!-- action needs to exist (even though blank), otherwise causes NPE -->
52+
<form action="">
53+
54+
<h1>Welcome to Processing 3</h1>
55+
56+
<p>
57+
<a href="https://github.com/processing/processing/wiki/Changes-in-3.0">Read about what&rsquo;s new in 3.0 &rarr;</a>
58+
</p>
59+
60+
<p>
61+
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris convallis porta dui, eget iaculis velit ornare at.
62+
</p>
63+
64+
<p class="inset">
65+
Quisque eu ultrices erat. Curabitur vel vulputate turpis. Morbi efficitur feugiat augue eget euismod. Fusce vehicula velit libero. Praesent urna dolor, tincidunt ut massa a, rhoncus blandit justo.
66+
</p>
67+
68+
<p>
69+
Curabitur laoreet vestibulum nibh, egestas semper eros viverra nec. Praesent luctus enim commodo mauris ultricies, non efficitur justo vestibulum.
70+
</p>
71+
72+
<table>
73+
<tr>
74+
<td>
75+
<input type="checkbox" name="show_each_time" checked />
76+
</td>
77+
<td>
78+
Show this welcome<br/>message each time
79+
</td>
80+
<td>
81+
<input id="startButton" type="submit" value="Get Started" />
82+
</td>
83+
</tr>
84+
</table>
85+
86+
</form>
87+
88+
</body>
89+
</html>

0 commit comments

Comments
 (0)