mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-31 20:52:13 +01:00
Move isModified()
from SketchController to Sketch
Also, update any code that uses it, removing the dependency on SketchController entirely if possible.
This commit is contained in:
parent
629953e20d
commit
dd5c1787fd
@ -542,8 +542,8 @@ public class Base {
|
|||||||
Collections.reverse(reversedEditors);
|
Collections.reverse(reversedEditors);
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (Editor editor : reversedEditors) {
|
for (Editor editor : reversedEditors) {
|
||||||
SketchController sketch = editor.getSketchController();
|
Sketch sketch = editor.getSketch();
|
||||||
String path = sketch.getSketch().getMainFilePath();
|
String path = sketch.getMainFilePath();
|
||||||
// Skip untitled sketches if they do not contains changes.
|
// Skip untitled sketches if they do not contains changes.
|
||||||
if (path.startsWith(untitledPath) && !sketch.isModified()) {
|
if (path.startsWith(untitledPath) && !sketch.isModified()) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -85,11 +85,17 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
private ArrayList<EditorTab> tabs = new ArrayList<>();
|
private ArrayList<EditorTab> tabs = new ArrayList<>();
|
||||||
private int currentTabIndex = -1;
|
private int currentTabIndex = -1;
|
||||||
|
|
||||||
private static class ShouldSaveIfModified implements Predicate<SketchController> {
|
private static class ShouldSaveIfModified
|
||||||
|
implements Predicate<SketchController> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean test(SketchController sketch) {
|
public boolean test(SketchController controller) {
|
||||||
return PreferencesData.getBoolean("editor.save_on_verify") && sketch.isModified() && !sketch.isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath());
|
return PreferencesData.getBoolean("editor.save_on_verify")
|
||||||
|
&& controller.getSketch().isModified()
|
||||||
|
&& !controller.isReadOnly(
|
||||||
|
BaseNoGui.librariesIndexer
|
||||||
|
.getInstalledLibraries(),
|
||||||
|
BaseNoGui.getExamplesPath());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1838,7 +1844,8 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
* @return false if canceling the close/quit operation
|
* @return false if canceling the close/quit operation
|
||||||
*/
|
*/
|
||||||
protected boolean checkModified() {
|
protected boolean checkModified() {
|
||||||
if (!sketchController.isModified()) return true;
|
if (!sketch.isModified())
|
||||||
|
return true;
|
||||||
|
|
||||||
// As of Processing 1.0.10, this always happens immediately.
|
// As of Processing 1.0.10, this always happens immediately.
|
||||||
// http://dev.processing.org/bugs/show_bug.cgi?id=1456
|
// http://dev.processing.org/bugs/show_bug.cgi?id=1456
|
||||||
@ -2169,7 +2176,11 @@ public class Editor extends JFrame implements RunnerListener {
|
|||||||
*/
|
*/
|
||||||
synchronized public void handleExport(final boolean usingProgrammer) {
|
synchronized public void handleExport(final boolean usingProgrammer) {
|
||||||
if (PreferencesData.getBoolean("editor.save_on_verify")) {
|
if (PreferencesData.getBoolean("editor.save_on_verify")) {
|
||||||
if (sketchController.isModified() && !sketchController.isReadOnly(BaseNoGui.librariesIndexer.getInstalledLibraries(), BaseNoGui.getExamplesPath())) {
|
if (sketch.isModified()
|
||||||
|
&& !sketchController.isReadOnly(
|
||||||
|
BaseNoGui.librariesIndexer
|
||||||
|
.getInstalledLibraries(),
|
||||||
|
BaseNoGui.getExamplesPath())) {
|
||||||
handleSave(true);
|
handleSave(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -456,21 +456,13 @@ public class SketchController {
|
|||||||
|
|
||||||
if (OSUtils.isMacOS()) {
|
if (OSUtils.isMacOS()) {
|
||||||
// http://developer.apple.com/qa/qa2001/qa1146.html
|
// http://developer.apple.com/qa/qa2001/qa1146.html
|
||||||
Object modifiedParam = isModified() ? Boolean.TRUE : Boolean.FALSE;
|
Object modifiedParam = sketch.isModified() ? Boolean.TRUE : Boolean.FALSE;
|
||||||
editor.getRootPane().putClientProperty("windowModified", modifiedParam);
|
editor.getRootPane().putClientProperty("windowModified", modifiedParam);
|
||||||
editor.getRootPane().putClientProperty("Window.documentModified", modifiedParam);
|
editor.getRootPane().putClientProperty("Window.documentModified", modifiedParam);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public boolean isModified() {
|
|
||||||
for (SketchCode code : sketch.getCodes()) {
|
|
||||||
if (code.isModified())
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Save all code in the current sketch.
|
* Save all code in the current sketch.
|
||||||
@ -896,7 +888,7 @@ public class SketchController {
|
|||||||
|
|
||||||
boolean deleteTemp = false;
|
boolean deleteTemp = false;
|
||||||
String pathToSketch = sketch.getMainFilePath();
|
String pathToSketch = sketch.getMainFilePath();
|
||||||
if (isModified()) {
|
if (sketch.isModified()) {
|
||||||
// If any files are modified, make a copy of the sketch with the changes
|
// If any files are modified, make a copy of the sketch with the changes
|
||||||
// saved, so arduino-builder will see the modifications.
|
// saved, so arduino-builder will see the modifications.
|
||||||
pathToSketch = saveSketchInTempFolder();
|
pathToSketch = saveSketchInTempFolder();
|
||||||
|
@ -49,7 +49,7 @@ public class FixEncoding implements Tool {
|
|||||||
|
|
||||||
|
|
||||||
public void run() {
|
public void run() {
|
||||||
SketchController sketch = editor.getSketchController();
|
Sketch sketch = editor.getSketch();
|
||||||
//SketchCode code = sketch.current;
|
//SketchCode code = sketch.current;
|
||||||
|
|
||||||
if (sketch.isModified()) {
|
if (sketch.isModified()) {
|
||||||
@ -65,8 +65,8 @@ public class FixEncoding implements Tool {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
for (int i = 0; i < sketch.getSketch().getCodeCount(); i++) {
|
for (int i = 0; i < sketch.getCodeCount(); i++) {
|
||||||
SketchCode code = sketch.getSketch().getCode(i);
|
SketchCode code = sketch.getCode(i);
|
||||||
editor.findTab(code).setText(loadWithLocalEncoding(code.getFile()));
|
editor.findTab(code).setText(loadWithLocalEncoding(code.getFile()));
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
@ -214,4 +214,15 @@ public class Sketch {
|
|||||||
public File getDataFolder() {
|
public File getDataFolder() {
|
||||||
return dataFolder;
|
return dataFolder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Is any of the files in this sketch modified?
|
||||||
|
*/
|
||||||
|
public boolean isModified() {
|
||||||
|
for (SketchCode code : codes) {
|
||||||
|
if (code.isModified())
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user