1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-11-29 10:24:12 +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,52 +2171,39 @@ public class Editor extends JFrame implements RunnerListener {
File file = SketchData.checkSketchFile(sketchFile);
if (file == null)
{
if (file == null) {
if (!fileName.endsWith(".ino") && !fileName.endsWith(".pde")) {
Base.showWarning(tr("Bad file selected"),
tr("Arduino can only open its own sketches\n" +
Base.showWarning(tr("Bad file selected"), tr("Arduino can only open its own sketches\n" +
"and other files ending in .ino or .pde"), null);
return false;
} else {
String properParent =
fileName.substring(0, fileName.length() - 4);
String properParent = 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" +
"a sketch folder named \"{1}\".\n" +
"Create this folder, move the file, and continue?"),
fileName,
properParent);
int result = JOptionPane.showOptionDialog(this,
prompt,
tr("Moving"),
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null,
options,
options[0]);
int result = JOptionPane.showOptionDialog(this, prompt, tr("Moving"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE, null, options, options[0]);
if (result != JOptionPane.YES_OPTION) {
return false;
}
if (result == JOptionPane.YES_OPTION) {
// create properly named folder
File properFolder = new File(sketchFile.getParent(), properParent);
if (properFolder.exists()) {
Base.showWarning(tr("Error"),
I18n.format(
tr("A folder named \"{0}\" already exists. " +
"Can't open sketch."),
properParent
),
null);
Base.showWarning(tr("Error"), I18n.format(tr("A folder named \"{0}\" already exists. " +
"Can't open sketch."), properParent), null);
return false;
}
if (!properFolder.mkdirs()) {
//throw new IOException("Couldn't create sketch folder");
Base.showWarning(tr("Error"),
tr("Could not create the sketch folder."), null);
Base.showWarning(tr("Error"), tr("Could not create the sketch folder."), null);
return false;
}
// copy the sketch inside
@ -2234,9 +2221,6 @@ public class Editor extends JFrame implements RunnerListener {
// update with the new path
file = properPdeFile;
} else if (result == JOptionPane.NO_OPTION) {
return false;
}
}
}
@ -2253,12 +2237,6 @@ public class Editor extends JFrame implements RunnerListener {
// opening was successful
return true;
// } catch (Exception e) {
// e.printStackTrace();
// statusError(e);
// return false;
// }
}
private void updateTitle() {

View File

@ -33,39 +33,45 @@ import java.util.List;
/**
* Deal with issues related to thinking different. This handles the basic
* Mac OS X menu commands (and apple events) for open, about, prefs, etc.
* <p/>
* <p>
* Based on OSXAdapter.java from Apple DTS.
* <p/>
* </p>
* 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.
*/
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() {
Application application = Application.getApplication();
application.setAboutHandler(new AboutHandler() {
@Override
public void handleAbout(AppEvent.AboutEvent aboutEvent) {
new Thread(() -> {
if (waitForBase()) {
Base.INSTANCE.handleAbout();
}
}).start();
}
});
application.setPreferencesHandler(new PreferencesHandler() {
@Override
public void handlePreferences(AppEvent.PreferencesEvent preferencesEvent) {
new Thread(() -> {
if (waitForBase()) {
Base.INSTANCE.handlePrefs();
}
}).start();
}
});
application.setOpenFileHandler(new OpenFilesHandler() {
@Override
public void openFiles(final AppEvent.OpenFilesEvent openFilesEvent) {
new Thread(() -> {
if (waitForBase()) {
for (File file : openFilesEvent.getFiles()) {
System.out.println(file);
try {
Base.INSTANCE.handleOpen(file);
List<Editor> editors = Base.INSTANCE.getEditors();
@ -77,11 +83,13 @@ public class ThinkDifferent {
}
}
}
}).start();
}
});
application.setQuitHandler(new QuitHandler() {
@Override
public void handleQuitRequestWith(AppEvent.QuitEvent quitEvent, QuitResponse quitResponse) {
new Thread(() -> {
if (waitForBase()) {
if (Base.INSTANCE.handleQuit()) {
quitResponse.performQuit();
@ -89,6 +97,7 @@ public class ThinkDifferent {
quitResponse.cancelQuit();
}
}
}).start();
}
});
}