@@ -2171,72 +2171,56 @@ protected boolean handleOpenInternal(File sketchFile) {
21712171
21722172 File file = SketchData .checkSketchFile (sketchFile );
21732173
2174- if (file == null )
2175- {
2174+ if (file == null ) {
21762175 if (!fileName .endsWith (".ino" ) && !fileName .endsWith (".pde" )) {
21772176
2178- Base .showWarning (tr ("Bad file selected" ),
2179- tr ("Arduino can only open its own sketches\n " +
2180- "and other files ending in .ino or .pde" ), null );
2177+ Base .showWarning (tr ("Bad file selected" ), tr ("Arduino can only open its own sketches\n " +
2178+ "and other files ending in .ino or .pde" ), null );
21812179 return false ;
21822180
21832181 } else {
2184- String properParent =
2185- fileName .substring (0 , fileName .length () - 4 );
2182+ String properParent = fileName .substring (0 , fileName .length () - 4 );
21862183
2187- Object [] options = { tr ("OK" ), tr ("Cancel" ) };
2184+ Object [] options = {tr ("OK" ), tr ("Cancel" )};
21882185 String prompt = I18n .format (tr ("The file \" {0}\" needs to be inside\n " +
2189- "a sketch folder named \" {1}\" .\n " +
2190- "Create this folder, move the file, and continue?" ),
2191- fileName ,
2192- properParent );
2193-
2194- int result = JOptionPane .showOptionDialog (this ,
2195- prompt ,
2196- tr ("Moving" ),
2197- JOptionPane .YES_NO_OPTION ,
2198- JOptionPane .QUESTION_MESSAGE ,
2199- null ,
2200- options ,
2201- options [0 ]);
2202-
2203- if (result == JOptionPane .YES_OPTION ) {
2204- // create properly named folder
2205- File properFolder = new File (sketchFile .getParent (), properParent );
2206- if (properFolder .exists ()) {
2207- Base .showWarning (tr ("Error" ),
2208- I18n .format (
2209- tr ("A folder named \" {0}\" already exists. " +
2210- "Can't open sketch." ),
2211- properParent
2212- ),
2213- null );
2214- return false ;
2215- }
2216- if (!properFolder .mkdirs ()) {
2217- //throw new IOException("Couldn't create sketch folder");
2218- Base .showWarning (tr ("Error" ),
2219- tr ("Could not create the sketch folder." ), null );
2220- return false ;
2221- }
2222- // copy the sketch inside
2223- File properPdeFile = new File (properFolder , sketchFile .getName ());
2224- try {
2225- Base .copyFile (sketchFile , properPdeFile );
2226- } catch (IOException e ) {
2227- Base .showWarning (tr ("Error" ), tr ("Could not copy to a proper location." ), e );
2228- return false ;
2229- }
2186+ "a sketch folder named \" {1}\" .\n " +
2187+ "Create this folder, move the file, and continue?" ),
2188+ fileName ,
2189+ properParent );
22302190
2231- // remove the original file, so user doesn't get confused
2232- sketchFile .delete ();
2191+ int result = JOptionPane .showOptionDialog (this , prompt , tr ("Moving" ), JOptionPane .YES_NO_OPTION , JOptionPane .QUESTION_MESSAGE , null , options , options [0 ]);
22332192
2234- // update with the new path
2235- file = properPdeFile ;
2193+ if (result != JOptionPane .YES_OPTION ) {
2194+ return false ;
2195+ }
22362196
2237- } else if (result == JOptionPane .NO_OPTION ) {
2197+ // create properly named folder
2198+ File properFolder = new File (sketchFile .getParent (), properParent );
2199+ if (properFolder .exists ()) {
2200+ Base .showWarning (tr ("Error" ), I18n .format (tr ("A folder named \" {0}\" already exists. " +
2201+ "Can't open sketch." ), properParent ), null );
2202+ return false ;
2203+ }
2204+ if (!properFolder .mkdirs ()) {
2205+ //throw new IOException("Couldn't create sketch folder");
2206+ Base .showWarning (tr ("Error" ), tr ("Could not create the sketch folder." ), null );
22382207 return false ;
22392208 }
2209+ // copy the sketch inside
2210+ File properPdeFile = new File (properFolder , sketchFile .getName ());
2211+ try {
2212+ Base .copyFile (sketchFile , properPdeFile );
2213+ } catch (IOException e ) {
2214+ Base .showWarning (tr ("Error" ), tr ("Could not copy to a proper location." ), e );
2215+ return false ;
2216+ }
2217+
2218+ // remove the original file, so user doesn't get confused
2219+ sketchFile .delete ();
2220+
2221+ // update with the new path
2222+ file = properPdeFile ;
2223+
22402224 }
22412225 }
22422226
@@ -2253,12 +2237,6 @@ protected boolean handleOpenInternal(File sketchFile) {
22532237
22542238 // opening was successful
22552239 return true ;
2256-
2257- // } catch (Exception e) {
2258- // e.printStackTrace();
2259- // statusError(e);
2260- // return false;
2261- // }
22622240 }
22632241
22642242 private void updateTitle () {
0 commit comments