Mercurial > hg > octave-nkf
diff libgui/src/m-editor/file-editor-tab.cc @ 18360:770c525a1a2b gui-release
Warn when saving/running a script whose name is not a valid identifier.
* file-editor-tab.h: rename save_file_check_spaces
* file-editor-tab.cc (check_valid_identifier): renamed save_file_check_spaces,
check if valid identifier and adapt message;
(handle_save_file_as_answer, handle_save_file_as_answer_close): use this
function
* main-window.cc (run_file_in_terminal): use the function
author | Julien Bect <julien.bect@supelec.fr> |
---|---|
date | Tue, 21 Jan 2014 18:11:50 +0100 |
parents | 6e8188effddf |
children | f01ac1bb8a5d |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc +++ b/libgui/src/m-editor/file-editor-tab.cc @@ -57,6 +57,7 @@ #include "debug.h" #include "octave-qt-link.h" #include "version.h" +#include "utils.h" // Make parent null for the file editor tab so that warning // WindowModal messages don't affect grandparents. @@ -1228,16 +1229,20 @@ } bool -file_editor_tab::save_file_check_spaces (QString file_name) +file_editor_tab::check_valid_identifier (QString file_name) { - QFileInfo file = QFileInfo(file_name); + QFileInfo file = QFileInfo (file_name); + QString base_name = file.baseName (); - if (file.suffix () == "m" && file.baseName ().contains (' ')) + if ((file.suffix () == "m") + && (! valid_identifier (base_name.toStdString ()))) { int ans = QMessageBox::question (0, tr ("Octave Editor"), - tr ("It is not advisable to save an Octave script\n" - "in a file with a name containing spaces.\n\n" - "Do you want to choose another name?"), + tr ("\"%1\"\n" + "is not a valid identifier.\n\n" + "If you keep this file name, you will not be able to\n" + "call your script using its name as an Octave command.\n\n" + "Do you want to choose another name?").arg (base_name), QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); if (ans == QMessageBox::Yes) @@ -1258,7 +1263,7 @@ else { // Have editor check for conflict, do not delete tab after save. - if (save_file_check_spaces (saveFileName)) + if (check_valid_identifier (saveFileName)) save_file_as (false); else emit editor_check_conflict_save (saveFileName, false); @@ -1272,7 +1277,7 @@ // when we close a tab and _file_name is not a valid file name yet // Have editor check for conflict, delete tab after save. - if (save_file_check_spaces (saveFileName)) + if (check_valid_identifier (saveFileName)) save_file_as (true); else emit editor_check_conflict_save (saveFileName, true);