@@ -2131,68 +2131,72 @@ protected boolean handleOpenInternal(File sketchFile) {
21312131
21322132 File file = SketchData .checkSketchFile (sketchFile );
21332133
2134- if ((file == null ) && !fileName .endsWith (".ino" ) && !fileName .endsWith (".pde" )) {
2135- Base .showWarning (_ ("Bad file selected" ),
2136- _ ("Arduino can only open its own sketches\n " +
2137- "and other files ending in .ino or .pde" ), null );
2138- return false ;
2134+ if (file == null )
2135+ {
2136+ if (!fileName .endsWith (".ino" ) && !fileName .endsWith (".pde" )) {
21392137
2140- } else {
2141- String properParent =
2142- fileName .substring (0 , fileName .length () - 4 );
2138+ Base .showWarning (_ ("Bad file selected" ),
2139+ _ ("Arduino can only open its own sketches\n " +
2140+ "and other files ending in .ino or .pde" ), null );
2141+ return false ;
2142+
2143+ } else {
2144+ String properParent =
2145+ fileName .substring (0 , fileName .length () - 4 );
21432146
2144- Object [] options = { _ ("OK" ), _ ("Cancel" ) };
2145- String prompt = I18n .format (_ ("The file \" {0}\" needs to be inside\n " +
2147+ Object [] options = { _ ("OK" ), _ ("Cancel" ) };
2148+ String prompt = I18n .format (_ ("The file \" {0}\" needs to be inside\n " +
21462149 "a sketch folder named \" {1}\" .\n " +
21472150 "Create this folder, move the file, and continue?" ),
21482151 fileName ,
21492152 properParent );
21502153
2151- int result = JOptionPane .showOptionDialog (this ,
2152- prompt ,
2153- _ ("Moving" ),
2154- JOptionPane .YES_NO_OPTION ,
2155- JOptionPane .QUESTION_MESSAGE ,
2156- null ,
2157- options ,
2158- options [0 ]);
2159-
2160- if (result == JOptionPane .YES_OPTION ) {
2161- // create properly named folder
2162- File properFolder = new File (file .getParent (), properParent );
2163- if (properFolder .exists ()) {
2164- Base .showWarning (_ ("Error" ),
2165- I18n .format (
2166- _ ("A folder named \" {0}\" already exists. " +
2167- "Can't open sketch." ),
2168- properParent
2169- ),
2154+ int result = JOptionPane .showOptionDialog (this ,
2155+ prompt ,
2156+ _ ("Moving" ),
2157+ JOptionPane .YES_NO_OPTION ,
2158+ JOptionPane .QUESTION_MESSAGE ,
2159+ null ,
2160+ options ,
2161+ options [0 ]);
2162+
2163+ if (result == JOptionPane .YES_OPTION ) {
2164+ // create properly named folder
2165+ File properFolder = new File (sketchFile .getParent (), properParent );
2166+ if (properFolder .exists ()) {
2167+ Base .showWarning (_ ("Error" ),
2168+ I18n .format (
2169+ _ ("A folder named \" {0}\" already exists. " +
2170+ "Can't open sketch." ),
2171+ properParent
2172+ ),
21702173 null );
2171- return false ;
2172- }
2173- if (!properFolder .mkdirs ()) {
2174- //throw new IOException("Couldn't create sketch folder");
2175- Base .showWarning (_ ("Error" ),
2176- _ ("Could not create the sketch folder." ), null );
2177- return false ;
2178- }
2179- // copy the sketch inside
2180- File properPdeFile = new File (properFolder , file .getName ());
2181- try {
2182- Base .copyFile (file , properPdeFile );
2183- } catch (IOException e ) {
2184- Base .showWarning (_ ("Error" ), _ ("Could not copy to a proper location." ), e );
2185- return false ;
2186- }
2174+ return false ;
2175+ }
2176+ if (!properFolder .mkdirs ()) {
2177+ //throw new IOException("Couldn't create sketch folder");
2178+ Base .showWarning (_ ("Error" ),
2179+ _ ("Could not create the sketch folder." ), null );
2180+ return false ;
2181+ }
2182+ // copy the sketch inside
2183+ File properPdeFile = new File (properFolder , sketchFile .getName ());
2184+ try {
2185+ Base .copyFile (file , properPdeFile );
2186+ } catch (IOException e ) {
2187+ Base .showWarning (_ ("Error" ), _ ("Could not copy to a proper location." ), e );
2188+ return false ;
2189+ }
21872190
2188- // remove the original file, so user doesn't get confused
2189- file .delete ();
2191+ // remove the original file, so user doesn't get confused
2192+ sketchFile .delete ();
21902193
2191- // update with the new path
2192- file = properPdeFile ;
2194+ // update with the new path
2195+ file = properPdeFile ;
21932196
2194- } else if (result == JOptionPane .NO_OPTION ) {
2195- return false ;
2197+ } else if (result == JOptionPane .NO_OPTION ) {
2198+ return false ;
2199+ }
21962200 }
21972201 }
21982202
0 commit comments