Mercurial > hg > octave-jordi
changeset 18274:3a26bb54655e gui-release
warn when saving or executing a file with spaces in its name (bug #41136)
* main-window.cc (run_file_in_terminal): check for spaces in the name,
show a warning message and execute 'run file' if desired
* file-editor-tab.cc (save_file_check_spaces): new function that checks for
spaces in a file name and asks if the user wants to chose another file name;
(handle_save_file_as_answer_close): use the new function;
(handle_save_file_as_answer): use the new function;
* file-editor-tab.h: new function save_file_check_spaces
author | Torsten <ttl@justmail.de> |
---|---|
date | Tue, 14 Jan 2014 20:56:57 +0100 |
parents | 8449cc186059 |
children | 8d98ebeceab4 |
files | libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/file-editor-tab.h libgui/src/main-window.cc |
diffstat | 3 files changed, 51 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc +++ b/libgui/src/m-editor/file-editor-tab.cc @@ -1168,6 +1168,26 @@ show_dialog (fileDialog); } +bool +file_editor_tab::save_file_check_spaces (QString file_name) +{ + QFileInfo file = QFileInfo(file_name); + + if (file.suffix () == "m" && file.baseName ().contains (' ')) + { + 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 wnat to chose another name?"), + QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); + + if (ans == QMessageBox::Yes) + return true; + } + + return false; +} + void file_editor_tab::handle_save_file_as_answer (const QString& saveFileName) { @@ -1179,7 +1199,10 @@ else { // Have editor check for conflict, do not delete tab after save. - emit editor_check_conflict_save (saveFileName, false); + if (save_file_check_spaces (saveFileName)) + save_file_as (false); + else + emit editor_check_conflict_save (saveFileName, false); } } @@ -1190,7 +1213,10 @@ // when we close a tab and _file_name is not a valid file name yet // Have editor check for conflict, delete tab after save. - emit editor_check_conflict_save (saveFileName, true); + if (save_file_check_spaces (saveFileName)) + save_file_as (true); + else + emit editor_check_conflict_save (saveFileName, true); } void
--- a/libgui/src/m-editor/file-editor-tab.h +++ b/libgui/src/m-editor/file-editor-tab.h @@ -176,6 +176,7 @@ bool valid_file_name (const QString& file=QString ()); void save_file (const QString& saveFileName, bool remove_on_success = false); void save_file_as (bool remove_on_success = false); + bool save_file_check_spaces (QString file_name); void update_lexer (); void request_add_breakpoint (int line);
--- a/libgui/src/main-window.cc +++ b/libgui/src/main-window.cc @@ -262,6 +262,28 @@ void main_window::run_file_in_terminal (const QFileInfo& info) { + QString file_name = info.canonicalFilePath (); + QString command = "run \""+file_name+"\""; + + QString function_name = info.fileName (); + function_name.chop (info.suffix ().length () + 1); + + if (function_name.contains (' ')) + { + int ans = QMessageBox::question (0, tr ("Octave"), + tr ("The file %1\n" + "contains spaces and can not be executed.\n\n" + "Do you want to execute\n%2\n" + "instead?"). + arg (file_name).arg (command), + QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); + + if (ans == QMessageBox::Yes) + execute_command_in_terminal (command); + + return; + } + octave_link::post_event (this, &main_window::run_file_callback, info); if (focus_console_after_command ()) focus_command_window ();