mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-30 19:52:13 +01:00
Merge branch 'save-on-close'
This commit is contained in:
commit
c3d2bbdb86
@ -327,7 +327,7 @@ public class Base {
|
||||
boolean showEditor = parser.isGuiMode();
|
||||
if (!parser.isForceSavePrefs())
|
||||
PreferencesData.setDoSave(showEditor);
|
||||
if (handleOpen(file, nextEditorLocation(), showEditor, false) == null) {
|
||||
if (handleOpen(file, retrieveSketchLocation(".default"), showEditor, false) == null) {
|
||||
String mess = I18n.format(tr("Failed to open sketch: \"{0}\""), path);
|
||||
// Open failure is fatal in upload/verify mode
|
||||
if (parser.isVerifyOrUploadMode())
|
||||
@ -489,32 +489,6 @@ public class Base {
|
||||
* @throws Exception
|
||||
*/
|
||||
protected boolean restoreSketches() throws Exception {
|
||||
// figure out window placement
|
||||
|
||||
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
boolean windowPositionValid = true;
|
||||
|
||||
if (PreferencesData.get("last.screen.height") != null) {
|
||||
// if screen size has changed, the window coordinates no longer
|
||||
// make sense, so don't use them unless they're identical
|
||||
int screenW = PreferencesData.getInteger("last.screen.width");
|
||||
int screenH = PreferencesData.getInteger("last.screen.height");
|
||||
|
||||
if ((screen.width != screenW) || (screen.height != screenH)) {
|
||||
windowPositionValid = false;
|
||||
}
|
||||
/*
|
||||
int windowX = Preferences.getInteger("last.window.x");
|
||||
int windowY = Preferences.getInteger("last.window.y");
|
||||
if ((windowX < 0) || (windowY < 0) ||
|
||||
(windowX > screenW) || (windowY > screenH)) {
|
||||
windowPositionValid = false;
|
||||
}
|
||||
*/
|
||||
} else {
|
||||
windowPositionValid = false;
|
||||
}
|
||||
|
||||
// Iterate through all sketches that were open last time p5 was running.
|
||||
// If !windowPositionValid, then ignore the coordinates found for each.
|
||||
|
||||
@ -534,13 +508,7 @@ public class Base {
|
||||
// path unchanged.
|
||||
}
|
||||
}
|
||||
int[] location;
|
||||
if (windowPositionValid) {
|
||||
String locationStr = PreferencesData.get("last.sketch" + i + ".location");
|
||||
location = PApplet.parseInt(PApplet.split(locationStr, ','));
|
||||
} else {
|
||||
location = nextEditorLocation();
|
||||
}
|
||||
int[] location = retrieveSketchLocation("" + i);
|
||||
// If file did not exist, null will be returned for the Editor
|
||||
if (handleOpen(new File(path), location, nextEditorLocation(), true, false, false) != null) {
|
||||
opened++;
|
||||
@ -560,29 +528,56 @@ public class Base {
|
||||
PreferencesData.setInteger("last.screen.width", screen.width);
|
||||
PreferencesData.setInteger("last.screen.height", screen.height);
|
||||
|
||||
String untitledPath = untitledFolder.getAbsolutePath();
|
||||
// If there is only one sketch opened save his position as default
|
||||
if (editors.size() == 1) {
|
||||
storeSketchLocation(editors.get(0), ".default");
|
||||
}
|
||||
|
||||
// Save the sketch path and window placement for each open sketch
|
||||
LinkedList<Editor> reverseEditors = new LinkedList<Editor>(editors);
|
||||
Collections.reverse(reverseEditors);
|
||||
String untitledPath = untitledFolder.getAbsolutePath();
|
||||
List<Editor> reversedEditors = new LinkedList<>(editors);
|
||||
Collections.reverse(reversedEditors);
|
||||
int index = 0;
|
||||
for (Editor editor : reverseEditors) {
|
||||
String path = editor.getSketch().getMainFilePath();
|
||||
// In case of a crash, save untitled sketches if they contain changes.
|
||||
// (Added this for release 0158, may not be a good idea.)
|
||||
if (path.startsWith(untitledPath) && !editor.getSketch().isModified()) {
|
||||
for (Editor editor : reversedEditors) {
|
||||
Sketch sketch = editor.getSketch();
|
||||
String path = sketch.getMainFilePath();
|
||||
// Skip untitled sketches if they do not contains changes.
|
||||
if (path.startsWith(untitledPath) && !sketch.isModified()) {
|
||||
continue;
|
||||
}
|
||||
PreferencesData.set("last.sketch" + index + ".path", path);
|
||||
|
||||
int[] location = editor.getPlacement();
|
||||
String locationStr = PApplet.join(PApplet.str(location), ",");
|
||||
PreferencesData.set("last.sketch" + index + ".location", locationStr);
|
||||
storeSketchLocation(editor, "" + index);
|
||||
index++;
|
||||
}
|
||||
PreferencesData.setInteger("last.sketch.count", index);
|
||||
}
|
||||
|
||||
private void storeSketchLocation(Editor editor, String index) {
|
||||
String path = editor.getSketch().getMainFilePath();
|
||||
String loc = StringUtils.join(editor.getPlacement(), ',');
|
||||
PreferencesData.set("last.sketch" + index + ".path", path);
|
||||
PreferencesData.set("last.sketch" + index + ".location", loc);
|
||||
}
|
||||
|
||||
private int[] retrieveSketchLocation(String index) {
|
||||
if (PreferencesData.get("last.screen.height") == null)
|
||||
return defaultEditorLocation();
|
||||
|
||||
// if screen size has changed, the window coordinates no longer
|
||||
// make sense, so don't use them unless they're identical
|
||||
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
int screenW = PreferencesData.getInteger("last.screen.width");
|
||||
int screenH = PreferencesData.getInteger("last.screen.height");
|
||||
|
||||
if ((screen.width != screenW) || (screen.height != screenH))
|
||||
return defaultEditorLocation();
|
||||
|
||||
String locationStr = PreferencesData
|
||||
.get("last.sketch" + index + ".location");
|
||||
if (locationStr == null)
|
||||
return defaultEditorLocation();
|
||||
return PApplet.parseInt(PApplet.split(locationStr, ','));
|
||||
}
|
||||
|
||||
protected void storeRecentSketches(Sketch sketch) {
|
||||
if (sketch.isUntitled()) {
|
||||
return;
|
||||
@ -624,51 +619,48 @@ public class Base {
|
||||
EditorConsole.setCurrentEditorConsole(activeEditor.console);
|
||||
}
|
||||
|
||||
|
||||
protected int[] nextEditorLocation() {
|
||||
protected int[] defaultEditorLocation() {
|
||||
int defaultWidth = PreferencesData.getInteger("editor.window.width.default");
|
||||
int defaultHeight = PreferencesData.getInteger("editor.window.height.default");
|
||||
|
||||
if (activeEditor == null) {
|
||||
Rectangle screen = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getBounds();
|
||||
// If no current active editor, use default placement
|
||||
return new int[]{
|
||||
(screen.width - defaultWidth) / 2,
|
||||
(screen.height - defaultHeight) / 2,
|
||||
defaultWidth, defaultHeight, 0
|
||||
};
|
||||
}
|
||||
|
||||
protected int[] nextEditorLocation() {
|
||||
if (activeEditor == null) {
|
||||
// If no current active editor, use default placement
|
||||
return defaultEditorLocation();
|
||||
}
|
||||
|
||||
} else {
|
||||
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
|
||||
// With a currently active editor, open the new window
|
||||
// using the same dimensions, but offset slightly.
|
||||
synchronized (editors) {
|
||||
final int OVER = 50;
|
||||
// In release 0160, don't
|
||||
//location = activeEditor.getPlacement();
|
||||
Editor lastOpened = activeEditor;
|
||||
int[] location = lastOpened.getPlacement();
|
||||
int[] location = activeEditor.getPlacement();
|
||||
|
||||
// Just in case the bounds for that window are bad
|
||||
final int OVER = 50;
|
||||
location[0] += OVER;
|
||||
location[1] += OVER;
|
||||
|
||||
if (location[0] == OVER ||
|
||||
location[2] == OVER ||
|
||||
location[0] + location[2] > screen.width ||
|
||||
location[1] + location[3] > screen.height) {
|
||||
if (location[0] == OVER || location[2] == OVER
|
||||
|| location[0] + location[2] > screen.width
|
||||
|| location[1] + location[3] > screen.height) {
|
||||
// Warp the next window to a randomish location on screen.
|
||||
return new int[]{
|
||||
(int) (Math.random() * (screen.width - defaultWidth)),
|
||||
(int) (Math.random() * (screen.height - defaultHeight)),
|
||||
defaultWidth, defaultHeight, 0
|
||||
};
|
||||
int[] l = defaultEditorLocation();
|
||||
l[0] *= Math.random() * 2;
|
||||
l[1] *= Math.random() * 2;
|
||||
return l;
|
||||
}
|
||||
|
||||
return location;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// .................................................................
|
||||
@ -896,12 +888,7 @@ public class Base {
|
||||
// now that we're ready, show the window
|
||||
// (don't do earlier, cuz we might move it based on a window being closed)
|
||||
if (showEditor) {
|
||||
SwingUtilities.invokeLater(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
editor.setVisible(true);
|
||||
}
|
||||
});
|
||||
SwingUtilities.invokeLater(() -> editor.setVisible(true));
|
||||
}
|
||||
|
||||
return editor;
|
||||
@ -961,6 +948,8 @@ public class Base {
|
||||
editor.internalCloseRunner();
|
||||
|
||||
if (editors.size() == 1) {
|
||||
storeSketches();
|
||||
|
||||
// This will store the sketch count as zero
|
||||
editors.remove(editor);
|
||||
try {
|
||||
@ -968,7 +957,6 @@ public class Base {
|
||||
} catch (Exception e) {
|
||||
//ignore
|
||||
}
|
||||
storeSketches();
|
||||
rebuildRecentSketchesMenuItems();
|
||||
|
||||
// Save out the current prefs state
|
||||
|
@ -1,6 +1,7 @@
|
||||
ARDUINO 1.6.8
|
||||
|
||||
[ide]
|
||||
* Editor position is saved when closing with Alt+F4 or clicking on the "X" button. Thanks @willie68
|
||||
* Fixed a NullPointerException when dealing with some rare combination of package_*.json files
|
||||
* Fixed incorrect key bindings handling for changing tab. Thanks @matthijskooijman
|
||||
* MacOSX: Fixed handling of add indent/remove indent shortcuts (CMD+[ and CMD+])
|
||||
|
Loading…
x
Reference in New Issue
Block a user