comparison scripts/miscellaneous/edit.m @ 18700:95a1ee1cbdf1

edit.m: add file extension .m to newly created files (bug #41522). * edit.m: add file extension .m to newly created files. If the gui is running then also open a file dialog where users can change the new name.
author Stefan Miereis <stefan.miereis@gmx.de>
date Thu, 20 Mar 2014 13:57:56 +0100
parents 832ecfda1d3c
children 0728f7b6b1a2
comparison
equal deleted inserted replaced
18695:7c78430535db 18700:95a1ee1cbdf1
328 endif 328 endif
329 endif 329 endif
330 330
331 ## If editing a new file, prompt for creation if gui is running 331 ## If editing a new file, prompt for creation if gui is running
332 if (isguirunning ()) 332 if (isguirunning ())
333 if (! __octave_link_edit_file__ (file,"prompt")); 333 if (! __octave_link_edit_file__ (file, "prompt"));
334 return; 334 return;
335 endif 335 endif
336 endif 336 endif
337 337
338 ## If editing a new file that is neither an m-file nor an oct-file, 338 ## If editing a new file that is neither an m-file nor an oct-file,
342 idx = rindex (file, "."); 342 idx = rindex (file, ".");
343 name = file(1:idx-1); 343 name = file(1:idx-1);
344 ext = file(idx+1:end); 344 ext = file(idx+1:end);
345 if (! any (strcmp (ext, {"cc", "m"}))) 345 if (! any (strcmp (ext, {"cc", "m"})))
346 ## Some unknown file. Create and open it or just open it. 346 ## Some unknown file. Create and open it or just open it.
347 ## Add .m file extension per default
348 fileandpath = [fileandpath ".m"];
347 if (isguirunning ()) 349 if (isguirunning ())
348 ## Write the initial file (if there is anything to write) 350 ## Write the initial file (if there is anything to write)
351 ## Give user the opportunity to change the file extension
352 fileandpath = uiputfile (fileandpath);
349 fid = fopen (fileandpath, "wt"); 353 fid = fopen (fileandpath, "wt");
350 if (fid < 0) 354 if (fid < 0)
351 error ("edit: could not create %s", fileandpath); 355 error ("edit: could not create %s", fileandpath);
352 endif 356 endif
353 fclose (fid); 357 fclose (fid);