@@ -84,18 +84,18 @@ public class Editor extends JFrame implements RunnerListener {
84
84
private ArrayList <EditorTab > tabs = new ArrayList <>();
85
85
private int currentTabIndex = -1 ;
86
86
87
- private static class ShouldSaveIfModified implements Predicate <Sketch > {
87
+ private static class ShouldSaveIfModified implements Predicate <SketchController > {
88
88
89
89
@ Override
90
- public boolean test (Sketch sketch ) {
90
+ public boolean test (SketchController sketch ) {
91
91
return PreferencesData .getBoolean ("editor.save_on_verify" ) && sketch .isModified () && !sketch .isReadOnly (BaseNoGui .librariesIndexer .getInstalledLibraries (), BaseNoGui .getExamplesPath ());
92
92
}
93
93
}
94
94
95
- private static class ShouldSaveReadOnly implements Predicate <Sketch > {
95
+ private static class ShouldSaveReadOnly implements Predicate <SketchController > {
96
96
97
97
@ Override
98
- public boolean test (Sketch sketch ) {
98
+ public boolean test (SketchController sketch ) {
99
99
return sketch .isReadOnly (BaseNoGui .librariesIndexer .getInstalledLibraries (), BaseNoGui .getExamplesPath ());
100
100
}
101
101
}
@@ -155,6 +155,7 @@ public boolean test(Sketch sketch) {
155
155
private JSplitPane splitPane ;
156
156
157
157
// currently opened program
158
+ SketchController sketchController ;
158
159
Sketch sketch ;
159
160
160
161
EditorLineStatus lineStatus ;
@@ -341,7 +342,7 @@ public void windowDeactivated(WindowEvent e) {
341
342
342
343
// Open the document that was passed in
343
344
boolean loaded = handleOpenInternal (file );
344
- if (!loaded ) sketch = null ;
345
+ if (!loaded ) sketchController = null ;
345
346
346
347
// System.out.println("t5");
347
348
@@ -372,7 +373,7 @@ public boolean importData(JComponent src, Transferable transferable) {
372
373
List <File > list = (List <File >)
373
374
transferable .getTransferData (DataFlavor .javaFileListFlavor );
374
375
for (File file : list ) {
375
- if (sketch .addFile (file )) {
376
+ if (sketchController .addFile (file )) {
376
377
successful ++;
377
378
}
378
379
}
@@ -390,7 +391,7 @@ public boolean importData(JComponent src, Transferable transferable) {
390
391
} else if (piece .startsWith ("file:/" )) {
391
392
path = piece .substring (5 );
392
393
}
393
- if (sketch .addFile (new File (path ))) {
394
+ if (sketchController .addFile (new File (path ))) {
394
395
successful ++;
395
396
}
396
397
}
@@ -701,7 +702,7 @@ public void actionPerformed(ActionEvent e) {
701
702
item = newJMenuItemAlt (tr ("Export compiled Binary" ), 'S' );
702
703
item .addActionListener (new ActionListener () {
703
704
public void actionPerformed (ActionEvent e ) {
704
- if (new ShouldSaveReadOnly ().test (sketch ) && !handleSave (true )) {
705
+ if (new ShouldSaveReadOnly ().test (sketchController ) && !handleSave (true )) {
705
706
System .out .println (tr ("Export canceled, changes must first be saved." ));
706
707
return ;
707
708
}
@@ -739,7 +740,7 @@ public void actionPerformed(ActionEvent e) {
739
740
item = new JMenuItem (tr ("Add File..." ));
740
741
item .addActionListener (new ActionListener () {
741
742
public void actionPerformed (ActionEvent e ) {
742
- sketch .handleAddFile ();
743
+ sketchController .handleAddFile ();
743
744
}
744
745
});
745
746
sketchMenu .add (item );
@@ -1571,7 +1572,14 @@ private void resetHandlers() {
1571
1572
1572
1573
1573
1574
/**
1574
- * Gets the current sketch object.
1575
+ * Gets the current sketch controller.
1576
+ */
1577
+ public SketchController getSketchController () {
1578
+ return sketchController ;
1579
+ }
1580
+
1581
+ /**
1582
+ * Gets the current sketch.
1575
1583
*/
1576
1584
public Sketch getSketch () {
1577
1585
return sketch ;
@@ -1728,9 +1736,9 @@ public void handleRun(final boolean verbose, Runnable verboseHandler, Runnable n
1728
1736
handleRun (verbose , new ShouldSaveIfModified (), verboseHandler , nonVerboseHandler );
1729
1737
}
1730
1738
1731
- private void handleRun (final boolean verbose , Predicate <Sketch > shouldSavePredicate , Runnable verboseHandler , Runnable nonVerboseHandler ) {
1739
+ private void handleRun (final boolean verbose , Predicate <SketchController > shouldSavePredicate , Runnable verboseHandler , Runnable nonVerboseHandler ) {
1732
1740
internalCloseRunner ();
1733
- if (shouldSavePredicate .test (sketch )) {
1741
+ if (shouldSavePredicate .test (sketchController )) {
1734
1742
handleSave (true );
1735
1743
}
1736
1744
toolbar .activateRun ();
@@ -1771,7 +1779,7 @@ public BuildHandler(boolean verbose, boolean saveHex) {
1771
1779
public void run () {
1772
1780
try {
1773
1781
removeAllLineHighlights ();
1774
- sketch .build (verbose , saveHex );
1782
+ sketchController .build (verbose , saveHex );
1775
1783
statusNotice (tr ("Done compiling." ));
1776
1784
} catch (PreferencesMapException e ) {
1777
1785
statusError (I18n .format (
@@ -1838,14 +1846,15 @@ public void internalCloseRunner() {
1838
1846
* @return false if canceling the close/quit operation
1839
1847
*/
1840
1848
protected boolean checkModified () {
1841
- if (!sketch .isModified ()) return true ;
1849
+ if (!sketchController .isModified ()) return true ;
1842
1850
1843
1851
// As of Processing 1.0.10, this always happens immediately.
1844
1852
// http://dev.processing.org/bugs/show_bug.cgi?id=1456
1845
1853
1846
1854
toFront ();
1847
1855
1848
- String prompt = I18n .format (tr ("Save changes to \" {0}\" ? " ), sketch .getName ());
1856
+ String prompt = I18n .format (tr ("Save changes to \" {0}\" ? " ),
1857
+ sketch .getName ());
1849
1858
1850
1859
if (!OSUtils .isMacOS ()) {
1851
1860
int result =
@@ -1932,7 +1941,7 @@ protected boolean handleOpenInternal(File sketchFile) {
1932
1941
// in a folder of the same name
1933
1942
String fileName = sketchFile .getName ();
1934
1943
1935
- File file = SketchData .checkSketchFile (sketchFile );
1944
+ File file = Sketch .checkSketchFile (sketchFile );
1936
1945
1937
1946
if (file == null ) {
1938
1947
if (!fileName .endsWith (".ino" ) && !fileName .endsWith (".pde" )) {
@@ -1988,11 +1997,12 @@ protected boolean handleOpenInternal(File sketchFile) {
1988
1997
}
1989
1998
1990
1999
try {
1991
- sketch = new Sketch (this , file );
2000
+ sketch = new Sketch (file );
1992
2001
} catch (IOException e ) {
1993
2002
Base .showWarning (tr ("Error" ), tr ("Could not create the sketch." ), e );
1994
2003
return false ;
1995
2004
}
2005
+ sketchController = new SketchController (this , sketch );
1996
2006
createTabs ();
1997
2007
1998
2008
// Disable untitled setting from previous document, if any
@@ -2003,12 +2013,13 @@ protected boolean handleOpenInternal(File sketchFile) {
2003
2013
}
2004
2014
2005
2015
private void updateTitle () {
2006
- if (sketch == null ) {
2016
+ if (sketchController == null ) {
2007
2017
return ;
2008
2018
}
2009
2019
SketchCode current = getCurrentTab ().getSketchCode ();
2010
2020
if (sketch .getName ().equals (current .getPrettyName ())) {
2011
- setTitle (I18n .format (tr ("{0} | Arduino {1}" ), sketch .getName (), BaseNoGui .VERSION_NAME_LONG ));
2021
+ setTitle (I18n .format (tr ("{0} | Arduino {1}" ), sketch .getName (),
2022
+ BaseNoGui .VERSION_NAME_LONG ));
2012
2023
} else {
2013
2024
setTitle (I18n .format (tr ("{0} - {1} | Arduino {2}" ), sketch .getName (),
2014
2025
current .getFileName (), BaseNoGui .VERSION_NAME_LONG ));
@@ -2053,15 +2064,15 @@ private boolean handleSave2() {
2053
2064
statusNotice (tr ("Saving..." ));
2054
2065
boolean saved = false ;
2055
2066
try {
2056
- boolean wasReadOnly = sketch .isReadOnly (BaseNoGui .librariesIndexer .getInstalledLibraries (), BaseNoGui .getExamplesPath ());
2067
+ boolean wasReadOnly = sketchController .isReadOnly (BaseNoGui .librariesIndexer .getInstalledLibraries (), BaseNoGui .getExamplesPath ());
2057
2068
String previousMainFilePath = sketch .getMainFilePath ();
2058
- saved = sketch .save ();
2069
+ saved = sketchController .save ();
2059
2070
if (saved ) {
2060
2071
statusNotice (tr ("Done Saving." ));
2061
2072
if (wasReadOnly ) {
2062
2073
base .removeRecentSketchPath (previousMainFilePath );
2063
2074
}
2064
- base .storeRecentSketches (sketch );
2075
+ base .storeRecentSketches (sketchController );
2065
2076
base .rebuildRecentSketchesMenuItems ();
2066
2077
} else {
2067
2078
statusEmpty ();
@@ -2098,8 +2109,8 @@ public boolean handleSaveAs() {
2098
2109
//public void run() {
2099
2110
statusNotice (tr ("Saving..." ));
2100
2111
try {
2101
- if (sketch .saveAs ()) {
2102
- base .storeRecentSketches (sketch );
2112
+ if (sketchController .saveAs ()) {
2113
+ base .storeRecentSketches (sketchController );
2103
2114
base .rebuildRecentSketchesMenuItems ();
2104
2115
statusNotice (tr ("Done Saving." ));
2105
2116
// Disabling this for 0125, instead rebuild the menu inside
@@ -2166,7 +2177,7 @@ private boolean serialPrompt() {
2166
2177
*/
2167
2178
synchronized public void handleExport (final boolean usingProgrammer ) {
2168
2179
if (PreferencesData .getBoolean ("editor.save_on_verify" )) {
2169
- if (sketch .isModified () && !sketch .isReadOnly (BaseNoGui .librariesIndexer .getInstalledLibraries (), BaseNoGui .getExamplesPath ())) {
2180
+ if (sketchController .isModified () && !sketchController .isReadOnly (BaseNoGui .librariesIndexer .getInstalledLibraries (), BaseNoGui .getExamplesPath ())) {
2170
2181
handleSave (true );
2171
2182
}
2172
2183
}
@@ -2192,7 +2203,7 @@ public void run() {
2192
2203
2193
2204
uploading = true ;
2194
2205
2195
- boolean success = sketch .exportApplet (false );
2206
+ boolean success = sketchController .exportApplet (false );
2196
2207
if (success ) {
2197
2208
statusNotice (tr ("Done uploading." ));
2198
2209
}
@@ -2287,7 +2298,7 @@ public void run() {
2287
2298
2288
2299
uploading = true ;
2289
2300
2290
- boolean success = sketch .exportApplet (true );
2301
+ boolean success = sketchController .exportApplet (true );
2291
2302
if (success ) {
2292
2303
statusNotice (tr ("Done uploading." ));
2293
2304
}
0 commit comments