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