# HG changeset patch # User Torsten # Date 1400263287 -7200 # Node ID 095fdef3d67c18c015d0fa7c72cca1242e19b8f2 # Parent be569698970c47a0bf3eb3ebc8ebfb989e3674d7 use editors run selection action for the context menu * file-editor-tab.cc (constructor): initialize flag for octave file; (update_lexer): set flag for octave file; (set_file_name, handle_copy_available, change_editor_state): editor_state_changed signal uses flag for octave file; * file-editor-tab.h: flag for octave file, also used in editor_state_changed * file-editor.cc (create_context_menu): add action for running selection; (handle_editor_state_changed): gets flag whether file is an octave script, enable run action and run selection action depending on selection and file type; (add_file_editor_tab): connect editor_state_changed to handle_editor_state_changedwith new third parameter; * file-editor.h: handle_editor_state_changed has a new third parameter * octave-qscintilla.cc (contextMenuEvent): run selection is added by the edtior diff -r be569698970c -r 095fdef3d67c libgui/src/m-editor/file-editor-tab.cc --- a/libgui/src/m-editor/file-editor-tab.cc Thu May 15 08:37:02 2014 -0700 +++ b/libgui/src/m-editor/file-editor-tab.cc Fri May 16 20:01:27 2014 +0200 @@ -66,6 +66,7 @@ QString directory = directory_arg; _lexer_apis = 0; _app_closing = false; + _is_octave_file = true; // Make sure there is a slash at the end of the directory name // for identification when saved later. @@ -84,7 +85,7 @@ this, SLOT (execute_command_in_terminal (const QString&))); - connect (_edit_area, + connect (_edit_area, SIGNAL (cursorPositionChanged (int, int)), this, SLOT (handle_cursor_moved (int,int))); @@ -215,9 +216,9 @@ update_lexer (); // update the file editor with current editing directory - emit editor_state_changed (_copy_available, _file_name); + emit editor_state_changed (_copy_available, _file_name, _is_octave_file); + // add the new file to the mru list - emit mru_add_file (_file_name); } @@ -270,6 +271,8 @@ delete lexer; lexer = 0; + _is_octave_file = false; + if (_file_name.endsWith (".m") || _file_name.endsWith ("octaverc")) { @@ -278,6 +281,7 @@ #elif defined (HAVE_LEXER_MATLAB) lexer = new QsciLexerMatlab (); #endif + _is_octave_file = true; } if (! lexer) @@ -311,8 +315,10 @@ // new, no yet named file: let us assume it is octave #if defined (HAVE_LEXER_OCTAVE) lexer = new QsciLexerOctave (); + _is_octave_file = true; #elif defined (HAVE_LEXER_MATLAB) lexer = new QsciLexerMatlab (); + _is_octave_file = true; #else lexer = new QsciLexerBash (); #endif @@ -975,7 +981,8 @@ file_editor_tab::handle_copy_available (bool enableCopy) { _copy_available = enableCopy; - emit editor_state_changed (_copy_available, QDir::cleanPath (_file_name)); + emit editor_state_changed (_copy_available, QDir::cleanPath (_file_name), + _is_octave_file); } // show_dialog: shows a modal or non modal dialog depeding on the closing @@ -1510,7 +1517,8 @@ _find_dialog->show (); } - emit editor_state_changed (_copy_available, QDir::cleanPath (_file_name)); + emit editor_state_changed (_copy_available, QDir::cleanPath (_file_name), + _is_octave_file); } void diff -r be569698970c -r 095fdef3d67c libgui/src/m-editor/file-editor-tab.h --- a/libgui/src/m-editor/file-editor-tab.h Thu May 15 08:37:02 2014 -0700 +++ b/libgui/src/m-editor/file-editor-tab.h Fri May 16 20:01:27 2014 +0200 @@ -123,7 +123,8 @@ signals: void file_name_changed (const QString& fileName, const QString& toolTip); - void editor_state_changed (bool copy_available, const QString& fileName); + void editor_state_changed (bool copy_available, const QString& fileName, + bool is_octave_file); void tab_remove_request (); void add_filename_to_list (const QString&, QWidget *); void mru_add_file (const QString& file_name); @@ -217,6 +218,7 @@ bool _long_title; bool _copy_available; bool _app_closing; + bool _is_octave_file; QFileSystemWatcher _file_system_watcher; diff -r be569698970c -r 095fdef3d67c libgui/src/m-editor/file-editor.cc --- a/libgui/src/m-editor/file-editor.cc Thu May 15 08:37:02 2014 -0700 +++ b/libgui/src/m-editor/file-editor.cc Fri May 16 20:01:27 2014 +0200 @@ -965,6 +965,8 @@ menu->addAction (_paste_action); menu->addSeparator (); menu->addAction (_selectall_action); + menu->addSeparator (); + menu->addAction (_run_selection_action); } void @@ -994,7 +996,8 @@ void file_editor::handle_editor_state_changed (bool copy_available, - const QString& file_name) + const QString& file_name, + bool is_octave_file) { // In case there is some scenario where traffic could be coming from // all the file editor tabs, just process info from the current active tab. @@ -1002,7 +1005,8 @@ { _copy_action->setEnabled (copy_available); _cut_action->setEnabled (copy_available); - _run_selection_action->setEnabled (copy_available); + _run_selection_action->setEnabled (copy_available && is_octave_file); + _run_action->setEnabled (is_octave_file); if (!file_name.isEmpty ()) { @@ -1410,8 +1414,8 @@ this, SLOT (handle_file_name_changed (const QString&, const QString&))); - connect (f, SIGNAL (editor_state_changed (bool, const QString&)), - this, SLOT (handle_editor_state_changed (bool, const QString&))); + connect (f, SIGNAL (editor_state_changed (bool, const QString&, bool)), + this, SLOT (handle_editor_state_changed (bool, const QString&, bool))); connect (f, SIGNAL (tab_remove_request ()), this, SLOT (handle_tab_remove_request ())); diff -r be569698970c -r 095fdef3d67c libgui/src/m-editor/file-editor.h --- a/libgui/src/m-editor/file-editor.h Thu May 15 08:37:02 2014 -0700 +++ b/libgui/src/m-editor/file-editor.h Fri May 16 20:01:27 2014 +0200 @@ -178,7 +178,8 @@ void handle_tab_remove_request (void); void handle_add_filename_to_list (const QString& fileName, QWidget *ID); void active_tab_changed (int index); - void handle_editor_state_changed (bool enableCopy, const QString& fileName); + void handle_editor_state_changed (bool enableCopy, const QString& fileName, + bool is_octave_file); void handle_mru_add_file (const QString& file_name); void check_conflict_save (const QString& fileName, bool remove_on_success); diff -r be569698970c -r 095fdef3d67c libgui/src/m-editor/octave-qscintilla.cc --- a/libgui/src/m-editor/octave-qscintilla.cc Thu May 15 08:37:02 2014 -0700 +++ b/libgui/src/m-editor/octave-qscintilla.cc Fri May 16 20:01:27 2014 +0200 @@ -200,10 +200,6 @@ context_menu->addAction (tr ("Edit") + " " + _word_at_cursor, this, SLOT (contextmenu_edit (bool))); } - context_menu->addSeparator (); // separator before custom entries - if (hasSelectedText ()) - context_menu->addAction (tr ("&Run Selection"), - this, SLOT (contextmenu_run (bool))); } // finaly show the menu