@@ -85,18 +85,18 @@ public class Editor extends JFrame implements RunnerListener {
85
85
private ArrayList <EditorTab > tabs = new ArrayList <>();
86
86
private int currentTabIndex = -1 ;
87
87
88
- private static class ShouldSaveIfModified implements Predicate <Sketch > {
88
+ private static class ShouldSaveIfModified implements Predicate <SketchController > {
89
89
90
90
@ Override
91
- public boolean test (Sketch sketch ) {
91
+ public boolean test (SketchController sketch ) {
92
92
return PreferencesData .getBoolean ("editor.save_on_verify" ) && sketch .isModified () && !sketch .isReadOnly (BaseNoGui .librariesIndexer .getInstalledLibraries (), BaseNoGui .getExamplesPath ());
93
93
}
94
94
}
95
95
96
- private static class ShouldSaveReadOnly implements Predicate <Sketch > {
96
+ private static class ShouldSaveReadOnly implements Predicate <SketchController > {
97
97
98
98
@ Override
99
- public boolean test (Sketch sketch ) {
99
+ public boolean test (SketchController sketch ) {
100
100
return sketch .isReadOnly (BaseNoGui .librariesIndexer .getInstalledLibraries (), BaseNoGui .getExamplesPath ());
101
101
}
102
102
}
@@ -158,6 +158,7 @@ public boolean test(Sketch sketch) {
158
158
private JSplitPane splitPane ;
159
159
160
160
// currently opened program
161
+ SketchController sketchController ;
161
162
Sketch sketch ;
162
163
163
164
EditorLineStatus lineStatus ;
@@ -332,7 +333,7 @@ public void windowDeactivated(WindowEvent e) {
332
333
333
334
// Open the document that was passed in
334
335
boolean loaded = handleOpenInternal (file );
335
- if (!loaded ) sketch = null ;
336
+ if (!loaded ) sketchController = null ;
336
337
}
337
338
338
339
@@ -358,7 +359,7 @@ public boolean importData(JComponent src, Transferable transferable) {
358
359
List <File > list = (List <File >)
359
360
transferable .getTransferData (DataFlavor .javaFileListFlavor );
360
361
for (File file : list ) {
361
- if (sketch .addFile (file )) {
362
+ if (sketchController .addFile (file )) {
362
363
successful ++;
363
364
}
364
365
}
@@ -376,7 +377,7 @@ public boolean importData(JComponent src, Transferable transferable) {
376
377
} else if (piece .startsWith ("file:/" )) {
377
378
path = piece .substring (5 );
378
379
}
379
- if (sketch .addFile (new File (path ))) {
380
+ if (sketchController .addFile (new File (path ))) {
380
381
successful ++;
381
382
}
382
383
}
@@ -675,7 +676,7 @@ public void actionPerformed(ActionEvent e) {
675
676
item = newJMenuItemAlt (tr ("Export compiled Binary" ), 'S' );
676
677
item .addActionListener (new ActionListener () {
677
678
public void actionPerformed (ActionEvent e ) {
678
- if (new ShouldSaveReadOnly ().test (sketch ) && !handleSave (true )) {
679
+ if (new ShouldSaveReadOnly ().test (sketchController ) && !handleSave (true )) {
679
680
System .out .println (tr ("Export canceled, changes must first be saved." ));
680
681
return ;
681
682
}
@@ -713,7 +714,7 @@ public void actionPerformed(ActionEvent e) {
713
714
item = new JMenuItem (tr ("Add File..." ));
714
715
item .addActionListener (new ActionListener () {
715
716
public void actionPerformed (ActionEvent e ) {
716
- sketch .handleAddFile ();
717
+ sketchController .handleAddFile ();
717
718
}
718
719
});
719
720
sketchMenu .add (item );
@@ -1562,7 +1563,14 @@ private void resetHandlers() {
1562
1563
1563
1564
1564
1565
/**
1565
- * Gets the current sketch object.
1566
+ * Gets the current sketch controller.
1567
+ */
1568
+ public SketchController getSketchController () {
1569
+ return sketchController ;
1570
+ }
1571
+
1572
+ /**
1573
+ * Gets the current sketch.
1566
1574
*/
1567
1575
public Sketch getSketch () {
1568
1576
return sketch ;
@@ -1719,9 +1727,9 @@ public void handleRun(final boolean verbose, Runnable verboseHandler, Runnable n
1719
1727
handleRun (verbose , new ShouldSaveIfModified (), verboseHandler , nonVerboseHandler );
1720
1728
}
1721
1729
1722
- private void handleRun (final boolean verbose , Predicate <Sketch > shouldSavePredicate , Runnable verboseHandler , Runnable nonVerboseHandler ) {
1730
+ private void handleRun (final boolean verbose , Predicate <SketchController > shouldSavePredicate , Runnable verboseHandler , Runnable nonVerboseHandler ) {
1723
1731
internalCloseRunner ();
1724
- if (shouldSavePredicate .test (sketch )) {
1732
+ if (shouldSavePredicate .test (sketchController )) {
1725
1733
handleSave (true );
1726
1734
}
1727
1735
toolbar .activateRun ();
@@ -1762,7 +1770,7 @@ public BuildHandler(boolean verbose, boolean saveHex) {
1762
1770
public void run () {
1763
1771
try {
1764
1772
removeAllLineHighlights ();
1765
- sketch .build (verbose , saveHex );
1773
+ sketchController .build (verbose , saveHex );
1766
1774
statusNotice (tr ("Done compiling." ));
1767
1775
} catch (PreferencesMapException e ) {
1768
1776
statusError (I18n .format (
@@ -1830,14 +1838,15 @@ public void internalCloseRunner() {
1830
1838
* @return false if canceling the close/quit operation
1831
1839
*/
1832
1840
protected boolean checkModified () {
1833
- if (!sketch .isModified ()) return true ;
1841
+ if (!sketchController .isModified ()) return true ;
1834
1842
1835
1843
// As of Processing 1.0.10, this always happens immediately.
1836
1844
// http://dev.processing.org/bugs/show_bug.cgi?id=1456
1837
1845
1838
1846
toFront ();
1839
1847
1840
- String prompt = I18n .format (tr ("Save changes to \" {0}\" ? " ), sketch .getName ());
1848
+ String prompt = I18n .format (tr ("Save changes to \" {0}\" ? " ),
1849
+ sketch .getName ());
1841
1850
1842
1851
if (!OSUtils .isMacOS ()) {
1843
1852
int result =
@@ -1924,7 +1933,7 @@ protected boolean handleOpenInternal(File sketchFile) {
1924
1933
// in a folder of the same name
1925
1934
String fileName = sketchFile .getName ();
1926
1935
1927
- File file = SketchData .checkSketchFile (sketchFile );
1936
+ File file = Sketch .checkSketchFile (sketchFile );
1928
1937
1929
1938
if (file == null ) {
1930
1939
if (!fileName .endsWith (".ino" ) && !fileName .endsWith (".pde" )) {
@@ -1980,11 +1989,12 @@ protected boolean handleOpenInternal(File sketchFile) {
1980
1989
}
1981
1990
1982
1991
try {
1983
- sketch = new Sketch (this , file );
1992
+ sketch = new Sketch (file );
1984
1993
} catch (IOException e ) {
1985
1994
Base .showWarning (tr ("Error" ), tr ("Could not create the sketch." ), e );
1986
1995
return false ;
1987
1996
}
1997
+ sketchController = new SketchController (this , sketch );
1988
1998
createTabs ();
1989
1999
1990
2000
// Disable untitled setting from previous document, if any
@@ -1995,12 +2005,13 @@ protected boolean handleOpenInternal(File sketchFile) {
1995
2005
}
1996
2006
1997
2007
private void updateTitle () {
1998
- if (sketch == null ) {
2008
+ if (sketchController == null ) {
1999
2009
return ;
2000
2010
}
2001
2011
SketchCode current = getCurrentTab ().getSketchCode ();
2002
2012
if (sketch .getName ().equals (current .getPrettyName ())) {
2003
- setTitle (I18n .format (tr ("{0} | Arduino {1}" ), sketch .getName (), BaseNoGui .VERSION_NAME_LONG ));
2013
+ setTitle (I18n .format (tr ("{0} | Arduino {1}" ), sketch .getName (),
2014
+ BaseNoGui .VERSION_NAME_LONG ));
2004
2015
} else {
2005
2016
setTitle (I18n .format (tr ("{0} - {1} | Arduino {2}" ), sketch .getName (),
2006
2017
current .getFileName (), BaseNoGui .VERSION_NAME_LONG ));
@@ -2045,15 +2056,15 @@ private boolean handleSave2() {
2045
2056
statusNotice (tr ("Saving..." ));
2046
2057
boolean saved = false ;
2047
2058
try {
2048
- boolean wasReadOnly = sketch .isReadOnly (BaseNoGui .librariesIndexer .getInstalledLibraries (), BaseNoGui .getExamplesPath ());
2059
+ boolean wasReadOnly = sketchController .isReadOnly (BaseNoGui .librariesIndexer .getInstalledLibraries (), BaseNoGui .getExamplesPath ());
2049
2060
String previousMainFilePath = sketch .getMainFilePath ();
2050
- saved = sketch .save ();
2061
+ saved = sketchController .save ();
2051
2062
if (saved ) {
2052
2063
statusNotice (tr ("Done Saving." ));
2053
2064
if (wasReadOnly ) {
2054
2065
base .removeRecentSketchPath (previousMainFilePath );
2055
2066
}
2056
- base .storeRecentSketches (sketch );
2067
+ base .storeRecentSketches (sketchController );
2057
2068
base .rebuildRecentSketchesMenuItems ();
2058
2069
} else {
2059
2070
statusEmpty ();
@@ -2090,8 +2101,8 @@ public boolean handleSaveAs() {
2090
2101
//public void run() {
2091
2102
statusNotice (tr ("Saving..." ));
2092
2103
try {
2093
- if (sketch .saveAs ()) {
2094
- base .storeRecentSketches (sketch );
2104
+ if (sketchController .saveAs ()) {
2105
+ base .storeRecentSketches (sketchController );
2095
2106
base .rebuildRecentSketchesMenuItems ();
2096
2107
statusNotice (tr ("Done Saving." ));
2097
2108
// Disabling this for 0125, instead rebuild the menu inside
@@ -2158,7 +2169,7 @@ private boolean serialPrompt() {
2158
2169
*/
2159
2170
synchronized public void handleExport (final boolean usingProgrammer ) {
2160
2171
if (PreferencesData .getBoolean ("editor.save_on_verify" )) {
2161
- if (sketch .isModified () && !sketch .isReadOnly (BaseNoGui .librariesIndexer .getInstalledLibraries (), BaseNoGui .getExamplesPath ())) {
2172
+ if (sketchController .isModified () && !sketchController .isReadOnly (BaseNoGui .librariesIndexer .getInstalledLibraries (), BaseNoGui .getExamplesPath ())) {
2162
2173
handleSave (true );
2163
2174
}
2164
2175
}
@@ -2185,7 +2196,7 @@ public void run() {
2185
2196
2186
2197
uploading = true ;
2187
2198
2188
- boolean success = sketch .exportApplet (false );
2199
+ boolean success = sketchController .exportApplet (false );
2189
2200
if (success ) {
2190
2201
statusNotice (tr ("Done uploading." ));
2191
2202
}
@@ -2282,7 +2293,7 @@ public void run() {
2282
2293
2283
2294
uploading = true ;
2284
2295
2285
- boolean success = sketch .exportApplet (true );
2296
+ boolean success = sketchController .exportApplet (true );
2286
2297
if (success ) {
2287
2298
statusNotice (tr ("Done uploading." ));
2288
2299
}
0 commit comments