changeset 16506:8a4960f2c7c3

gui: allow running files from the file browser * files-dock-widget.cc(constructor): connect run_file_signal (contextmenu_requested): add menu to run the selected file (contextmenu_run): new slot for running the selected file (run_file_signal): new signal * files-dock-widget.h: new function contextmenu_run, new signal run_file_signal
author Torsten <ttl@justmail.de>
date Fri, 12 Apr 2013 22:20:39 +0200
parents ff061068a66c
children 8cb12cf9ca32
files libgui/src/files-dock-widget.cc libgui/src/files-dock-widget.h
diffstat 2 files changed, 33 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/files-dock-widget.cc	Fri Apr 12 14:51:51 2013 -0400
+++ b/libgui/src/files-dock-widget.cc	Fri Apr 12 22:20:39 2013 +0200
@@ -160,6 +160,9 @@
   connect (_current_directory, SIGNAL (activated (const QString &)),
            this, SLOT (set_current_directory (const QString &)));
 
+  connect (this, SIGNAL (run_file_signal (const QString&)),
+           parent (), SLOT (handle_command_double_clicked (const QString&)));
+
   QCompleter *completer = new QCompleter (_file_system_model, this);
   _current_directory->setCompleter (completer);
 
@@ -283,6 +286,7 @@
       QFileInfo info = _file_system_model->fileInfo(index);
 
       menu.addAction(tr("Open"), this, SLOT(contextmenu_open(bool)));
+      menu.addAction(QIcon(":/actions/icons/artsbuilderexecute.png"), tr("Run"), this, SLOT(contextmenu_run(bool)));
       menu.addAction(tr("Load Data"), this, SLOT(contextmenu_load(bool)));
       menu.addSeparator();
       menu.addAction(tr("Rename"), this, SLOT(contextmenu_rename(bool)));
@@ -300,7 +304,7 @@
     }
 }
 
-void 
+void
 files_dock_widget::contextmenu_open (bool)
 {
 
@@ -313,7 +317,7 @@
     }
 }
 
-void 
+void
 files_dock_widget::contextmenu_load (bool)
 {
   QItemSelectionModel *m = _file_tree_view->selectionModel ();
@@ -329,6 +333,29 @@
     }
 }
 
+void
+files_dock_widget::contextmenu_run (bool)
+{
+  QItemSelectionModel *m = _file_tree_view->selectionModel ();
+  QModelIndexList rows = m->selectedRows ();
+
+  if (rows.size () > 0)
+    {
+      QModelIndex index = rows[0];
+
+      QFileInfo info = _file_system_model->fileInfo(index);
+
+      if (info.isFile() && info.suffix () == "m")
+        {
+          QString function_name = info.fileName ();
+          // We have to cut off the suffix, because octave appends it.
+          function_name.chop (info.suffix ().length () + 1);
+          emit run_file_signal (QString ("cd \'%1\'\n%2\n")
+                            .arg(info.absolutePath ()).arg (function_name));
+        }
+    }
+}
+
 void 
 files_dock_widget::contextmenu_rename (bool)
 {
--- a/libgui/src/files-dock-widget.h	Fri Apr 12 14:51:51 2013 -0400
+++ b/libgui/src/files-dock-widget.h	Fri Apr 12 22:20:39 2013 +0200
@@ -85,6 +85,7 @@
 
   /* context menu actions */
   void contextmenu_open (bool);
+  void contextmenu_run (bool);
   void contextmenu_load (bool);
   void contextmenu_rename (bool);
   void contextmenu_delete (bool);
@@ -102,6 +103,9 @@
   /** Emitted, whenever the user requested to load a file. */
   void load_file_signal (const QString& fileName);
 
+  /** Emitted, whenever the user requested to run a file. */
+  void run_file_signal (const QString& fileName);
+
 private:
 
   // TODO: Add toolbar with buttons for navigating the path, creating dirs, etc