@@ -180,71 +180,7 @@ static public void main(String args[]) {
180
180
// setup the theme coloring fun
181
181
Theme .init ();
182
182
183
- if (Base .isMacOS ()) {
184
- String properMenuBar = "apple.laf.useScreenMenuBar" ;
185
- String menubar = Preferences .get (properMenuBar );
186
- if (menubar != null ) {
187
- // Get the current menu bar setting and use it
188
- System .setProperty (properMenuBar , menubar );
189
-
190
- } else {
191
- // 10.4 is not affected, 10.5 (and prolly 10.6) are
192
- if (System .getProperty ("os.version" ).startsWith ("10.4" )) {
193
- // Don't bother checking next time
194
- Preferences .set (properMenuBar , "true" );
195
- // Also set the menubar now
196
- System .setProperty (properMenuBar , "true" );
197
-
198
- } else {
199
- // Running 10.5 or 10.6 or whatever, give 'em the business
200
- String warning =
201
- "<html>" +
202
- "<head> <style type=\" text/css\" >" +
203
- "b { font: 13pt \" Lucida Grande\" }" +
204
- "p { font: 11pt \" Lucida Grande\" ; margin-top: 8px }" +
205
- "</style> </head> <body>" +
206
- "<b>Some menus have been disabled.</b>" +
207
- "<p>Due to an Apple bug, the Sketchbook and Example menus " +
208
- "are unusable. <br>" +
209
- "As a workaround, these items will be disabled from the " +
210
- "standard menu bar, <br>" +
211
- "but you can use the Open button on " +
212
- "the toolbar to access the same items. <br>" +
213
- "If this bug makes you sad, " +
214
- "please contact Apple via bugreporter.apple.com.</p>" +
215
- "</body> </html>" ;
216
- Object [] options = { "OK" , "More Info" };
217
- int result = JOptionPane .showOptionDialog (new Frame (),
218
- warning ,
219
- "Menu Bar Problem" ,
220
- JOptionPane .YES_NO_OPTION ,
221
- JOptionPane .WARNING_MESSAGE ,
222
- null ,
223
- options ,
224
- options [0 ]);
225
- if (result == -1 ) {
226
- // They hit ESC or closed the window, so just hide it for now
227
- // But don't bother setting the preference in the file
228
- } else {
229
- // Shut off in the preferences for next time
230
- //Preferences.set(properMenuBar, "false");
231
- // For 1.0.4, we'll stick with the Apple menu bar,
232
- // and just disable the sketchbook and examples sub-menus.
233
- Preferences .set (properMenuBar , "true" );
234
- if (result == 1 ) { // More Info
235
- Base .openURL ("http://dev.processing.org/bugs/show_bug.cgi?id=786" );
236
- }
237
- }
238
- // Whether or not canceled, set to false (right now) if we're on 10.5
239
- //System.setProperty(properMenuBar, "false");
240
- // Changing this behavior for 1.0.4
241
- System .setProperty (properMenuBar , "true" );
242
- }
243
- }
244
- }
245
-
246
183
// Set the look and feel before opening the window
247
- // For 0158, moving it lower so that the apple.laf.useScreenMenuBar stuff works
248
184
try {
249
185
platform .setLookAndFeel ();
250
186
} catch (Exception e ) {
@@ -815,7 +751,8 @@ protected Editor handleOpen(String path, int[] location) {
815
751
*/
816
752
public boolean handleClose (Editor editor ) {
817
753
// Check if modified
818
- if (!editor .checkModified (false )) {
754
+ boolean immediate = editors .size () == 1 ;
755
+ if (!editor .checkModified (immediate )) {
819
756
return false ;
820
757
}
821
758
@@ -993,17 +930,9 @@ public void actionPerformed(ActionEvent e) {
993
930
protected void rebuildSketchbookMenu (JMenu menu ) {
994
931
//System.out.println("rebuilding sketchbook menu");
995
932
//new Exception().printStackTrace();
996
- //boolean nativeButBroken = Base.isMacOS() ?
997
- //Preferences.getBoolean("apple.laf.useScreenMenuBar") : false;
998
- boolean nativeButBroken = false ;
999
-
1000
933
try {
1001
- if (nativeButBroken ) { // osx workaround
1002
- menu .setEnabled (false );
1003
- } else {
1004
934
menu .removeAll ();
1005
935
addSketches (menu , getSketchbookFolder (), false );
1006
- }
1007
936
} catch (IOException e ) {
1008
937
e .printStackTrace ();
1009
938
}
@@ -1045,21 +974,13 @@ public void rebuildImportMenu(JMenu importMenu) {
1045
974
1046
975
public void rebuildExamplesMenu (JMenu menu ) {
1047
976
//System.out.println("rebuilding examples menu");
1048
- //boolean nativeButBroken = Base.isMacOS() ?
1049
- //Preferences.getBoolean("apple.laf.useScreenMenuBar") : false;
1050
- boolean nativeButBroken = false ;
1051
-
1052
977
try {
1053
- if (nativeButBroken ) { // osx workaround
1054
- menu .setEnabled (false );
1055
- } else {
1056
- menu .removeAll ();
1057
- boolean found = addSketches (menu , examplesFolder , false );
1058
- if (found ) menu .addSeparator ();
1059
- found = addSketches (menu , getSketchbookLibrariesFolder (), false );
1060
- if (found ) menu .addSeparator ();
1061
- addSketches (menu , librariesFolder , false );
1062
- }
978
+ menu .removeAll ();
979
+ boolean found = addSketches (menu , examplesFolder , false );
980
+ if (found ) menu .addSeparator ();
981
+ found = addSketches (menu , getSketchbookLibrariesFolder (), false );
982
+ if (found ) menu .addSeparator ();
983
+ addSketches (menu , librariesFolder , false );
1063
984
} catch (IOException e ) {
1064
985
e .printStackTrace ();
1065
986
}
@@ -1965,56 +1886,30 @@ static public void copyFile(File sourceFile,
1965
1886
* Grab the contents of a file as a string.
1966
1887
*/
1967
1888
static public String loadFile (File file ) throws IOException {
1968
- return PApplet .join (PApplet .loadStrings (file ), "\n " );
1969
-
1970
- /*
1971
- // empty code file.. no worries, might be getting filled up later
1972
- if (file.length() == 0) return "";
1973
-
1974
- //FileInputStream fis = new FileInputStream(file);
1975
- //InputStreamReader isr = new InputStreamReader(fis, "UTF-8");
1976
- //BufferedReader reader = new BufferedReader(isr);
1977
- BufferedReader reader = PApplet.createReader(file);
1978
-
1979
- StringBuffer buffer = new StringBuffer();
1980
- String line = null;
1981
- while ((line = reader.readLine()) != null) {
1982
- // char[] cc = line.toCharArray();
1983
- // for (int i = 0; i < cc.length; i++) {
1984
- // char c = cc[i];
1985
- // if (c < 32 || c > 126) System.out.println("found " + c + " " + ((int) c));
1986
- // }
1987
- //
1988
- buffer.append(line);
1989
- buffer.append('\n');
1889
+ String [] contents = PApplet .loadStrings (file );
1890
+ if (contents == null ) return null ;
1891
+ return PApplet .join (contents , "\n " );
1990
1892
}
1991
- reader.close();
1992
- return buffer.toString();
1993
- */
1994
- }
1995
1893
1996
1894
1997
1895
/**
1998
1896
* Spew the contents of a String object out to a file.
1999
1897
*/
2000
1898
static public void saveFile (String str , File file ) throws IOException {
2001
- PApplet . saveStrings (file , new String [] { str } );
2002
- /*
2003
- ByteArrayInputStream bis = new ByteArrayInputStream(str.getBytes ());
2004
- InputStreamReader isr = new InputStreamReader(bis );
2005
- BufferedReader reader = new BufferedReader(isr);
2006
-
2007
- FileOutputStream fos = new FileOutputStream( file);
2008
- OutputStreamWriter osw = new OutputStreamWriter(fos, "UTF-8");
2009
- PrintWriter writer = new PrintWriter(osw);
2010
-
2011
- String line = null;
2012
- while ((line = reader.readLine()) != null) {
2013
- writer.println(line );
1899
+ File temp = File . createTempFile (file . getName (), null , file . getParentFile () );
1900
+ PApplet . saveStrings ( temp , new String [] { str });
1901
+ if ( file . exists ()) {
1902
+ boolean result = file . delete ( );
1903
+ if (! result ) {
1904
+ throw new IOException ( "Could not remove old version of " +
1905
+ file . getAbsolutePath () );
1906
+ }
1907
+ }
1908
+ boolean result = temp . renameTo ( file );
1909
+ if (! result ) {
1910
+ throw new IOException ( "Could not replace " +
1911
+ file . getAbsolutePath () );
2014
1912
}
2015
- writer.flush();
2016
- writer.close();
2017
- */
2018
1913
}
2019
1914
2020
1915
0 commit comments