Skip to content

Commit 7e9f19c

Browse files
author
Federico Fissore
committed
MacOSX: faster startup, fixed double clicking on a .ino file. Fixes #4057
1 parent 80fec38 commit 7e9f19c

File tree

2 files changed

+72
-85
lines changed

2 files changed

+72
-85
lines changed

app/src/processing/app/Editor.java

Lines changed: 38 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -2171,72 +2171,56 @@ protected boolean handleOpenInternal(File sketchFile) {
21712171

21722172
File file = SketchData.checkSketchFile(sketchFile);
21732173

2174-
if (file == null)
2175-
{
2174+
if (file == null) {
21762175
if (!fileName.endsWith(".ino") && !fileName.endsWith(".pde")) {
21772176

2178-
Base.showWarning(tr("Bad file selected"),
2179-
tr("Arduino can only open its own sketches\n" +
2180-
"and other files ending in .ino or .pde"), null);
2177+
Base.showWarning(tr("Bad file selected"), tr("Arduino can only open its own sketches\n" +
2178+
"and other files ending in .ino or .pde"), null);
21812179
return false;
21822180

21832181
} else {
2184-
String properParent =
2185-
fileName.substring(0, fileName.length() - 4);
2182+
String properParent = fileName.substring(0, fileName.length() - 4);
21862183

2187-
Object[] options = { tr("OK"), tr("Cancel") };
2184+
Object[] options = {tr("OK"), tr("Cancel")};
21882185
String prompt = I18n.format(tr("The file \"{0}\" needs to be inside\n" +
2189-
"a sketch folder named \"{1}\".\n" +
2190-
"Create this folder, move the file, and continue?"),
2191-
fileName,
2192-
properParent);
2193-
2194-
int result = JOptionPane.showOptionDialog(this,
2195-
prompt,
2196-
tr("Moving"),
2197-
JOptionPane.YES_NO_OPTION,
2198-
JOptionPane.QUESTION_MESSAGE,
2199-
null,
2200-
options,
2201-
options[0]);
2202-
2203-
if (result == JOptionPane.YES_OPTION) {
2204-
// create properly named folder
2205-
File properFolder = new File(sketchFile.getParent(), properParent);
2206-
if (properFolder.exists()) {
2207-
Base.showWarning(tr("Error"),
2208-
I18n.format(
2209-
tr("A folder named \"{0}\" already exists. " +
2210-
"Can't open sketch."),
2211-
properParent
2212-
),
2213-
null);
2214-
return false;
2215-
}
2216-
if (!properFolder.mkdirs()) {
2217-
//throw new IOException("Couldn't create sketch folder");
2218-
Base.showWarning(tr("Error"),
2219-
tr("Could not create the sketch folder."), null);
2220-
return false;
2221-
}
2222-
// copy the sketch inside
2223-
File properPdeFile = new File(properFolder, sketchFile.getName());
2224-
try {
2225-
Base.copyFile(sketchFile, properPdeFile);
2226-
} catch (IOException e) {
2227-
Base.showWarning(tr("Error"), tr("Could not copy to a proper location."), e);
2228-
return false;
2229-
}
2186+
"a sketch folder named \"{1}\".\n" +
2187+
"Create this folder, move the file, and continue?"),
2188+
fileName,
2189+
properParent);
22302190

2231-
// remove the original file, so user doesn't get confused
2232-
sketchFile.delete();
2191+
int result = JOptionPane.showOptionDialog(this, prompt, tr("Moving"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
22332192

2234-
// update with the new path
2235-
file = properPdeFile;
2193+
if (result != JOptionPane.YES_OPTION) {
2194+
return false;
2195+
}
22362196

2237-
} else if (result == JOptionPane.NO_OPTION) {
2197+
// create properly named folder
2198+
File properFolder = new File(sketchFile.getParent(), properParent);
2199+
if (properFolder.exists()) {
2200+
Base.showWarning(tr("Error"), I18n.format(tr("A folder named \"{0}\" already exists. " +
2201+
"Can't open sketch."), properParent), null);
2202+
return false;
2203+
}
2204+
if (!properFolder.mkdirs()) {
2205+
//throw new IOException("Couldn't create sketch folder");
2206+
Base.showWarning(tr("Error"), tr("Could not create the sketch folder."), null);
22382207
return false;
22392208
}
2209+
// copy the sketch inside
2210+
File properPdeFile = new File(properFolder, sketchFile.getName());
2211+
try {
2212+
Base.copyFile(sketchFile, properPdeFile);
2213+
} catch (IOException e) {
2214+
Base.showWarning(tr("Error"), tr("Could not copy to a proper location."), e);
2215+
return false;
2216+
}
2217+
2218+
// remove the original file, so user doesn't get confused
2219+
sketchFile.delete();
2220+
2221+
// update with the new path
2222+
file = properPdeFile;
2223+
22402224
}
22412225
}
22422226

@@ -2253,12 +2237,6 @@ protected boolean handleOpenInternal(File sketchFile) {
22532237

22542238
// opening was successful
22552239
return true;
2256-
2257-
// } catch (Exception e) {
2258-
// e.printStackTrace();
2259-
// statusError(e);
2260-
// return false;
2261-
// }
22622240
}
22632241

22642242
private void updateTitle() {

app/src/processing/app/macosx/ThinkDifferent.java

Lines changed: 34 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -33,62 +33,71 @@
3333
/**
3434
* Deal with issues related to thinking different. This handles the basic
3535
* Mac OS X menu commands (and apple events) for open, about, prefs, etc.
36-
* <p/>
36+
* <p>
3737
* Based on OSXAdapter.java from Apple DTS.
38-
* <p/>
38+
* </p>
3939
* As of 0140, this code need not be built on platforms other than OS X,
4040
* because of the new platform structure which isolates through reflection.
4141
*/
4242
public class ThinkDifferent {
4343

44-
private static final int MAX_WAIT_FOR_BASE = 10000;
44+
private static final int MAX_WAIT_FOR_BASE = 30000;
4545

4646
static public void init() {
4747
Application application = Application.getApplication();
4848
application.setAboutHandler(new AboutHandler() {
4949
@Override
5050
public void handleAbout(AppEvent.AboutEvent aboutEvent) {
51-
if (waitForBase()) {
52-
Base.INSTANCE.handleAbout();
53-
}
51+
new Thread(() -> {
52+
if (waitForBase()) {
53+
Base.INSTANCE.handleAbout();
54+
}
55+
}).start();
5456
}
5557
});
5658
application.setPreferencesHandler(new PreferencesHandler() {
5759
@Override
5860
public void handlePreferences(AppEvent.PreferencesEvent preferencesEvent) {
59-
if (waitForBase()) {
60-
Base.INSTANCE.handlePrefs();
61-
}
61+
new Thread(() -> {
62+
if (waitForBase()) {
63+
Base.INSTANCE.handlePrefs();
64+
}
65+
}).start();
6266
}
6367
});
6468
application.setOpenFileHandler(new OpenFilesHandler() {
6569
@Override
6670
public void openFiles(final AppEvent.OpenFilesEvent openFilesEvent) {
67-
if (waitForBase()) {
68-
for (File file : openFilesEvent.getFiles()) {
69-
try {
70-
Base.INSTANCE.handleOpen(file);
71-
List<Editor> editors = Base.INSTANCE.getEditors();
72-
if (editors.size() == 2 && editors.get(0).getSketch().isUntitled()) {
73-
Base.INSTANCE.handleClose(editors.get(0));
71+
new Thread(() -> {
72+
if (waitForBase()) {
73+
for (File file : openFilesEvent.getFiles()) {
74+
System.out.println(file);
75+
try {
76+
Base.INSTANCE.handleOpen(file);
77+
List<Editor> editors = Base.INSTANCE.getEditors();
78+
if (editors.size() == 2 && editors.get(0).getSketch().isUntitled()) {
79+
Base.INSTANCE.handleClose(editors.get(0));
80+
}
81+
} catch (Exception e) {
82+
throw new RuntimeException(e);
7483
}
75-
} catch (Exception e) {
76-
throw new RuntimeException(e);
7784
}
7885
}
79-
}
86+
}).start();
8087
}
8188
});
8289
application.setQuitHandler(new QuitHandler() {
8390
@Override
8491
public void handleQuitRequestWith(AppEvent.QuitEvent quitEvent, QuitResponse quitResponse) {
85-
if (waitForBase()) {
86-
if (Base.INSTANCE.handleQuit()) {
87-
quitResponse.performQuit();
88-
} else {
89-
quitResponse.cancelQuit();
92+
new Thread(() -> {
93+
if (waitForBase()) {
94+
if (Base.INSTANCE.handleQuit()) {
95+
quitResponse.performQuit();
96+
} else {
97+
quitResponse.cancelQuit();
98+
}
9099
}
91-
}
100+
}).start();
92101
}
93102
});
94103
}

0 commit comments

Comments
 (0)