changeset 18801:095fdef3d67c gui-release

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
author Torsten <ttl@justmail.de>
date Fri, 16 May 2014 20:01:27 +0200
parents be569698970c
children a5286fb173cd
files libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/file-editor-tab.h libgui/src/m-editor/file-editor.cc libgui/src/m-editor/file-editor.h libgui/src/m-editor/octave-qscintilla.cc
diffstat 5 files changed, 26 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- 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
--- 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;
 
--- 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 ()));
--- 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);
 
--- 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