1
0
mirror of https://github.com/arduino/Arduino.git synced 2025-02-26 20:54:22 +01:00

MacOSX: faster startup, fixed double clicking on a .ino file. Fixes #4057

This commit is contained in:
Federico Fissore 2015-11-20 11:02:52 +01:00
parent 80fec38a25
commit 7e9f19c43b
2 changed files with 73 additions and 86 deletions

View File

@ -2171,18 +2171,15 @@ public class Editor extends JFrame implements RunnerListener {
File file = SketchData.checkSketchFile(sketchFile); File file = SketchData.checkSketchFile(sketchFile);
if (file == null) if (file == null) {
{
if (!fileName.endsWith(".ino") && !fileName.endsWith(".pde")) { if (!fileName.endsWith(".ino") && !fileName.endsWith(".pde")) {
Base.showWarning(tr("Bad file selected"), Base.showWarning(tr("Bad file selected"), tr("Arduino can only open its own sketches\n" +
tr("Arduino can only open its own sketches\n" +
"and other files ending in .ino or .pde"), null); "and other files ending in .ino or .pde"), null);
return false; return false;
} else { } else {
String properParent = String properParent = fileName.substring(0, fileName.length() - 4);
fileName.substring(0, fileName.length() - 4);
Object[] options = {tr("OK"), tr("Cancel")}; Object[] options = {tr("OK"), tr("Cancel")};
String prompt = I18n.format(tr("The file \"{0}\" needs to be inside\n" + String prompt = I18n.format(tr("The file \"{0}\" needs to be inside\n" +
@ -2191,32 +2188,22 @@ public class Editor extends JFrame implements RunnerListener {
fileName, fileName,
properParent); properParent);
int result = JOptionPane.showOptionDialog(this, int result = JOptionPane.showOptionDialog(this, prompt, tr("Moving"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
prompt,
tr("Moving"), if (result != JOptionPane.YES_OPTION) {
JOptionPane.YES_NO_OPTION, return false;
JOptionPane.QUESTION_MESSAGE, }
null,
options,
options[0]);
if (result == JOptionPane.YES_OPTION) {
// create properly named folder // create properly named folder
File properFolder = new File(sketchFile.getParent(), properParent); File properFolder = new File(sketchFile.getParent(), properParent);
if (properFolder.exists()) { if (properFolder.exists()) {
Base.showWarning(tr("Error"), Base.showWarning(tr("Error"), I18n.format(tr("A folder named \"{0}\" already exists. " +
I18n.format( "Can't open sketch."), properParent), null);
tr("A folder named \"{0}\" already exists. " +
"Can't open sketch."),
properParent
),
null);
return false; return false;
} }
if (!properFolder.mkdirs()) { if (!properFolder.mkdirs()) {
//throw new IOException("Couldn't create sketch folder"); //throw new IOException("Couldn't create sketch folder");
Base.showWarning(tr("Error"), Base.showWarning(tr("Error"), tr("Could not create the sketch folder."), null);
tr("Could not create the sketch folder."), null);
return false; return false;
} }
// copy the sketch inside // copy the sketch inside
@ -2234,9 +2221,6 @@ public class Editor extends JFrame implements RunnerListener {
// update with the new path // update with the new path
file = properPdeFile; file = properPdeFile;
} else if (result == JOptionPane.NO_OPTION) {
return false;
}
} }
} }
@ -2253,12 +2237,6 @@ public class Editor extends JFrame implements RunnerListener {
// opening was successful // opening was successful
return true; return true;
// } catch (Exception e) {
// e.printStackTrace();
// statusError(e);
// return false;
// }
} }
private void updateTitle() { private void updateTitle() {

View File

@ -33,39 +33,45 @@ import java.util.List;
/** /**
* Deal with issues related to thinking different. This handles the basic * Deal with issues related to thinking different. This handles the basic
* Mac OS X menu commands (and apple events) for open, about, prefs, etc. * Mac OS X menu commands (and apple events) for open, about, prefs, etc.
* <p/> * <p>
* Based on OSXAdapter.java from Apple DTS. * Based on OSXAdapter.java from Apple DTS.
* <p/> * </p>
* As of 0140, this code need not be built on platforms other than OS X, * As of 0140, this code need not be built on platforms other than OS X,
* because of the new platform structure which isolates through reflection. * because of the new platform structure which isolates through reflection.
*/ */
public class ThinkDifferent { public class ThinkDifferent {
private static final int MAX_WAIT_FOR_BASE = 10000; private static final int MAX_WAIT_FOR_BASE = 30000;
static public void init() { static public void init() {
Application application = Application.getApplication(); Application application = Application.getApplication();
application.setAboutHandler(new AboutHandler() { application.setAboutHandler(new AboutHandler() {
@Override @Override
public void handleAbout(AppEvent.AboutEvent aboutEvent) { public void handleAbout(AppEvent.AboutEvent aboutEvent) {
new Thread(() -> {
if (waitForBase()) { if (waitForBase()) {
Base.INSTANCE.handleAbout(); Base.INSTANCE.handleAbout();
} }
}).start();
} }
}); });
application.setPreferencesHandler(new PreferencesHandler() { application.setPreferencesHandler(new PreferencesHandler() {
@Override @Override
public void handlePreferences(AppEvent.PreferencesEvent preferencesEvent) { public void handlePreferences(AppEvent.PreferencesEvent preferencesEvent) {
new Thread(() -> {
if (waitForBase()) { if (waitForBase()) {
Base.INSTANCE.handlePrefs(); Base.INSTANCE.handlePrefs();
} }
}).start();
} }
}); });
application.setOpenFileHandler(new OpenFilesHandler() { application.setOpenFileHandler(new OpenFilesHandler() {
@Override @Override
public void openFiles(final AppEvent.OpenFilesEvent openFilesEvent) { public void openFiles(final AppEvent.OpenFilesEvent openFilesEvent) {
new Thread(() -> {
if (waitForBase()) { if (waitForBase()) {
for (File file : openFilesEvent.getFiles()) { for (File file : openFilesEvent.getFiles()) {
System.out.println(file);
try { try {
Base.INSTANCE.handleOpen(file); Base.INSTANCE.handleOpen(file);
List<Editor> editors = Base.INSTANCE.getEditors(); List<Editor> editors = Base.INSTANCE.getEditors();
@ -77,11 +83,13 @@ public class ThinkDifferent {
} }
} }
} }
}).start();
} }
}); });
application.setQuitHandler(new QuitHandler() { application.setQuitHandler(new QuitHandler() {
@Override @Override
public void handleQuitRequestWith(AppEvent.QuitEvent quitEvent, QuitResponse quitResponse) { public void handleQuitRequestWith(AppEvent.QuitEvent quitEvent, QuitResponse quitResponse) {
new Thread(() -> {
if (waitForBase()) { if (waitForBase()) {
if (Base.INSTANCE.handleQuit()) { if (Base.INSTANCE.handleQuit()) {
quitResponse.performQuit(); quitResponse.performQuit();
@ -89,6 +97,7 @@ public class ThinkDifferent {
quitResponse.cancelQuit(); quitResponse.cancelQuit();
} }
} }
}).start();
} }
}); });
} }