changeset 17635:7945344506ae

Add possibility to run selected text of the editor in the terminal * octave-qscintilla.cc(contextMenuEvent): new context menu for running selection (context_run): function for run selection action in editor file menu; (contextmenu_run): new slot for context menu run selection; * octave-qscintilla.h: new functions context_run, contextmenu_run * file-editor-tab.cc(context_run): new slot for run menu action * file-editor-tab.h: new slot context_run * file-editor.cc(request_context_run): new slot for run menu entry; (construct): new entry in run menu for running the selection in editor (add_file_editor_tab): connect new signal fetab_context_run to the new slot context_run in file_editor_tab; (set_shortcuts): enable/disable new shortcut when editor focus changes (check_actions): enable/disable new action depending on existing tabs * file-editor.h: new signal fetab_context_run, new slot request_context_edit, new run action
author Torsten <ttl@justmail.de>
date Fri, 11 Oct 2013 22:46:32 +0200
parents bdbf91c0a1a4
children 230ffaf80ac9
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 libgui/src/m-editor/octave-qscintilla.h
diffstat 6 files changed, 58 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc	Fri Oct 11 13:58:23 2013 -0400
+++ b/libgui/src/m-editor/file-editor-tab.cc	Fri Oct 11 22:46:32 2013 +0200
@@ -484,6 +484,15 @@
 }
 
 void
+file_editor_tab::context_run (const QWidget *ID)
+{
+  if (ID != this)
+    return;
+
+  _edit_area->context_run ();
+}
+
+void
 file_editor_tab::toggle_bookmark (const QWidget *ID)
 {
   if (ID != this)
--- a/libgui/src/m-editor/file-editor-tab.h	Fri Oct 11 13:58:23 2013 -0400
+++ b/libgui/src/m-editor/file-editor-tab.h	Fri Oct 11 22:46:32 2013 +0200
@@ -78,6 +78,7 @@
   void save_file_as (const QWidget *ID);
   void print_file (const QWidget *ID);
   void run_file (const QWidget *ID);
+  void context_run (const QWidget *ID);
   void toggle_bookmark (const QWidget *ID);
   void next_bookmark (const QWidget *ID);
   void previous_bookmark (const QWidget *ID);
--- a/libgui/src/m-editor/file-editor.cc	Fri Oct 11 13:58:23 2013 -0400
+++ b/libgui/src/m-editor/file-editor.cc	Fri Oct 11 22:46:32 2013 +0200
@@ -509,6 +509,12 @@
 }
 
 void
+file_editor::request_context_run (bool)
+{
+  emit fetab_context_run (_tab_widget->currentWidget ());
+}
+
+void
 file_editor::request_toggle_bookmark (void)
 {
   emit fetab_toggle_bookmark (_tab_widget->currentWidget ());
@@ -945,6 +951,9 @@
 
   QMenu *_run_menu = new QMenu (tr ("&Run"), _menu_bar);
   _run_menu->addAction (_run_action);
+  _context_run_action =
+    _run_menu->addAction (QIcon (), tr ("Run &Selection"),
+                           this, SLOT (request_context_run (bool)));
   _menu_bar->addMenu (_run_menu);
 
   QMenu *_help_menu = new QMenu (tr ("&Help"), _menu_bar);
@@ -1154,6 +1163,9 @@
   connect (this, SIGNAL (fetab_run_file (const QWidget*)),
            f, SLOT (run_file (const QWidget*)));
 
+  connect (this, SIGNAL (fetab_context_run (const QWidget*)),
+           f, SLOT (context_run (const QWidget*)));
+
   connect (this, SIGNAL (fetab_toggle_bookmark (const QWidget*)),
            f, SLOT (toggle_bookmark (const QWidget*)));
 
@@ -1252,6 +1264,7 @@
 
       _print_action->setShortcut (QKeySequence::Print);
       _run_action->setShortcut (Qt::ControlModifier+ Qt::Key_R);
+      _context_run_action->setShortcut (Qt::Key_F9);
 
       _context_edit_action->setShortcut (Qt::ControlModifier + Qt::Key_E);
       _save_action->setShortcut (QKeySequence::Save);
@@ -1282,6 +1295,7 @@
 
       _print_action->setShortcut (no_key);
       _run_action->setShortcut (no_key);
+      _context_run_action->setShortcut (no_key);
 
       _context_edit_action->setShortcut (no_key);
       _save_action->setShortcut (no_key);
@@ -1316,6 +1330,7 @@
 
   _print_action->setEnabled (have_tabs);
   _run_action->setEnabled (have_tabs);
+  _context_run_action->setEnabled (have_tabs);
 
   _context_edit_action->setEnabled (have_tabs);
   _save_action->setEnabled (have_tabs);
--- a/libgui/src/m-editor/file-editor.h	Fri Oct 11 13:58:23 2013 -0400
+++ b/libgui/src/m-editor/file-editor.h	Fri Oct 11 22:46:32 2013 +0200
@@ -80,6 +80,7 @@
   void fetab_save_file_as (const QWidget* ID);
   void fetab_print_file (const QWidget* ID);
   void fetab_run_file (const QWidget* ID);
+  void fetab_context_run (const QWidget* ID);
   void fetab_toggle_bookmark (const QWidget* ID);
   void fetab_next_bookmark (const QWidget* ID);
   void fetab_previous_bookmark (const QWidget* ID);
@@ -122,6 +123,7 @@
   void request_save_file (void);
   void request_save_file_as (void);
   void request_run_file (void);
+  void request_context_run (bool);
   void request_toggle_bookmark (void);
   void request_next_bookmark (void);
   void request_previous_bookmark (void);
@@ -208,6 +210,7 @@
 
   QAction *_print_action;
   QAction *_run_action;
+  QAction *_context_run_action;
 
   QAction *_context_edit_action;
   QAction *_save_action;
--- a/libgui/src/m-editor/octave-qscintilla.cc	Fri Oct 11 13:58:23 2013 -0400
+++ b/libgui/src/m-editor/octave-qscintilla.cc	Fri Oct 11 22:46:32 2013 +0200
@@ -76,10 +76,18 @@
 void
 octave_qscintilla::context_edit ()
 {
-  if (get_actual_word ())
+  if (hasSelectedText ())
     contextmenu_edit (true);
 }
 
+// call edit the function related to the current word
+void
+octave_qscintilla::context_run ()
+{
+  if (hasSelectedText ())
+    contextmenu_run (true);
+}
+
 #ifdef HAVE_QSCI_VERSION_2_6_0
 // context menu requested
 void
@@ -115,12 +123,18 @@
     {
       _word_at_cursor = wordAtPoint (local_pos);
       if (!_word_at_cursor.isEmpty ())
-        context_menu->addAction (tr ("Help on") + " " + _word_at_cursor,
-                                this, SLOT (contextmenu_help (bool)));
-        context_menu->addAction (tr ("Documentation on") + " " + _word_at_cursor,
-                                this, SLOT (contextmenu_doc (bool)));
-        context_menu->addAction (tr ("Edit") + " " + _word_at_cursor,
-                                this, SLOT (contextmenu_edit (bool)));
+        {
+          context_menu->addAction (tr ("Help on") + " " + _word_at_cursor,
+                                  this, SLOT (contextmenu_help (bool)));
+          context_menu->addAction (tr ("Documentation on") + " " + _word_at_cursor,
+                                  this, SLOT (contextmenu_doc (bool)));
+          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
@@ -159,4 +173,11 @@
   emit execute_command_in_terminal_signal (QString("edit ") + _word_at_cursor);
 }
 
+void
+octave_qscintilla::contextmenu_run (bool)
+{
+  QString command = selectedText ();
+  emit execute_command_in_terminal_signal (command);
+}
+
 #endif
--- a/libgui/src/m-editor/octave-qscintilla.h	Fri Oct 11 13:58:23 2013 -0400
+++ b/libgui/src/m-editor/octave-qscintilla.h	Fri Oct 11 22:46:32 2013 +0200
@@ -43,6 +43,7 @@
 #endif
   void context_help_doc (bool);
   void context_edit ();
+  void context_run ();
   void get_global_textcursor_pos (QPoint *global_pos, QPoint *local_pos);
   bool get_actual_word ();
 
@@ -56,6 +57,7 @@
   void contextmenu_doc (bool);
   void contextmenu_help_doc (bool);
   void contextmenu_edit (bool);
+  void contextmenu_run (bool);
 
 private: