changeset 16635:25e418d23a4b

fix running files from file browser's context menu * main-window.cc(run_file_in_terminal): new slot for run_file_signal (run_file_callback): callback for running files after checking the path * main-window.h: new functions run_file_in_terminal und run_file_callback) * files-dock-widget.cc(constructor): connect signal to slot for running files (contextmenu_run): emit run_file_signal with QFileInfo as parameter * files-dock-widget.h: run_file_signal has QFileInfo as parameter * file-editor-tab.cc: removed function run_file_callback (run_file): get file info of current file and emit run_file_signal (file_in_path): moved to octave_qt_link allowiung access from other widgets, updated calls to this functions * file-editor-tab.h: new run_file_signal with QFileInfo, removed functions run_file_callback and file_in_path * file-editor.cc(add_file_editor_tab): connect signal to slot for running files * octave-qt-link.cc/h(file_in_path): moved from file-editor-tab and made static
author Torsten <ttl@justmail.de>
date Fri, 10 May 2013 21:01:02 +0200
parents 2510fffc05e1
children d788ee8b8a99
files libgui/src/files-dock-widget.cc libgui/src/files-dock-widget.h 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/main-window.cc libgui/src/main-window.h libgui/src/octave-qt-link.cc libgui/src/octave-qt-link.h
diffstat 9 files changed, 104 insertions(+), 120 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/files-dock-widget.cc	Fri May 10 01:02:58 2013 +0100
+++ b/libgui/src/files-dock-widget.cc	Fri May 10 21:01:02 2013 +0200
@@ -194,8 +194,8 @@
   connect (_current_directory, SIGNAL (activated (const QString &)),
            this, SLOT (set_current_directory (const QString &)));
 
-  connect (this, SIGNAL (run_file_signal (const QString&)),
-           parent (), SLOT (execute_command_in_terminal (const QString&)));
+  connect (this, SIGNAL (run_file_signal (const QFileInfo&)),
+           parent (), SLOT (run_file_in_terminal (const QFileInfo&)));
 
   QCompleter *completer = new QCompleter (_file_system_model, this);
   _current_directory->setCompleter (completer);
@@ -452,12 +452,7 @@
       QModelIndex index = rows[0];
 
       QFileInfo info = _file_system_model->fileInfo(index);
-
-      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));
+      emit run_file_signal (info);
     }
 }
 
@@ -667,4 +662,3 @@
 {
   emit displayed_directory_changed (dir);
 }
-
--- a/libgui/src/files-dock-widget.h	Fri May 10 01:02:58 2013 +0100
+++ b/libgui/src/files-dock-widget.h	Fri May 10 21:01:02 2013 +0200
@@ -112,7 +112,7 @@
   void load_file_signal (const QString& fileName);
 
   /** Emitted, whenever the user requested to run a file. */
-  void run_file_signal (const QString& fileName);
+  void run_file_signal (const QFileInfo& info);
 
 private:
   void process_new_file(const QString &parent_name);
--- a/libgui/src/m-editor/file-editor-tab.cc	Fri May 10 01:02:58 2013 +0100
+++ b/libgui/src/m-editor/file-editor-tab.cc	Fri May 10 21:01:02 2013 +0200
@@ -48,14 +48,8 @@
 #include "file-editor-tab.h"
 #include "file-editor.h"
 
-#include "cmd-edit.h"
-
-#include "builtin-defun-decls.h"
 #include "debug.h"
-#include "load-path.h"
-#include "octave-link.h"
-#include "oct-env.h"
-#include "utils.h"
+#include "octave-qt-link.h"
 
 // Make parent null for the file editor tab so that warning
 // WindowModal messages don't affect grandparents.
@@ -355,25 +349,6 @@
   delete printer;
 }
 
-
-void
-file_editor_tab::run_file_callback (const bp_info& info)
-{
-  if (file_in_path (info.file, info.dir))
-    {
-      std::string pending_input = command_editor::get_current_line ();
-
-      command_editor::set_initial_input (pending_input);
-
-      command_editor::replace_line (info.function_name);
-      command_editor::redisplay ();
-
-      // We are executing inside the command editor event loop.  Force
-      // the current line to be returned for processing.
-      command_editor::interrupt ();
-    }
-}
-
 void
 file_editor_tab::run_file (const QWidget *ID)
 {
@@ -383,14 +358,8 @@
   if (_edit_area->isModified ())
     save_file (_file_name);
 
-  QFileInfo file_info (_file_name);
-  QString dir = file_info.absolutePath ();
-  QString function_name = file_info.fileName ();
-  function_name.chop (file_info.suffix ().length () + 1);
-
-  bp_info info (_file_name, dir, function_name, 1);
-
-  octave_link::post_event (this, &file_editor_tab::run_file_callback, info);
+  QFileInfo info (_file_name);
+  emit run_file_signal (info);
 }
 
 void
@@ -451,77 +420,13 @@
   _edit_area->markerDeleteAll (bookmark);
 }
 
-bool
-file_editor_tab::file_in_path (const std::string& file, const std::string& dir)
-{
-  bool ok = false;
-  bool addpath_option = true;
-
-  std::string curr_dir = octave_env::get_current_directory ();
-
-  if (same_file (curr_dir, dir))
-    ok = true;
-  else
-    {
-      bool dir_in_load_path = load_path::contains_canonical (dir);
-
-      std::string base_file = octave_env::base_pathname (file);
-      std::string lp_file = load_path::find_file (base_file);
-
-      if (dir_in_load_path)
-        {
-          if (same_file (lp_file, file))
-            ok = true;
-        }
-      else
-        {
-          // File directory is not in path.  Is the file in the path in
-          // the current directory?  If so, then changing the current
-          // directory will be needed.  Adding directory to path is
-          // not enough because the file in the current directory would
-          // still be found.
-
-          if (same_file (lp_file, base_file))
-            {
-              if (same_file (curr_dir, dir))
-                ok = true;
-              else
-                addpath_option = false;
-            }
-        }
-    }
-
-  if (! ok)
-    {
-      int action
-        = octave_link::debug_cd_or_addpath_error (file, dir, addpath_option);
-      switch (action)
-        {
-        case 1:
-          Fcd (ovl (dir));
-          ok = true;
-          break;
-
-        case 2:
-          load_path::prepend (dir);
-          ok = true;
-          break;
-
-        default:
-          break;
-        }
-    }
-
-  return ok;
-}
-
 void
 file_editor_tab::add_breakpoint_callback (const bp_info& info)
 {
   bp_table::intmap line_info;
   line_info[0] = info.line;
 
-  if (file_in_path (info.file, info.dir))
+  if (octave_qt_link::file_in_path (info.file, info.dir))
     bp_table::add_breakpoint (info.function_name, line_info);
 }
 
@@ -531,14 +436,14 @@
   bp_table::intmap line_info;
   line_info[0] = info.line;
 
-  if (file_in_path (info.file, info.dir))
+  if (octave_qt_link::file_in_path (info.file, info.dir))
     bp_table::remove_breakpoint (info.function_name, line_info);
 }
 
 void
 file_editor_tab::remove_all_breakpoints_callback (const bp_info& info)
 {
-  if (file_in_path (info.file, info.dir))
+  if (octave_qt_link::file_in_path (info.file, info.dir))
     bp_table::remove_all_breakpoints_in_file (info.function_name, true);
 }
 
--- a/libgui/src/m-editor/file-editor-tab.h	Fri May 10 01:02:58 2013 +0100
+++ b/libgui/src/m-editor/file-editor-tab.h	Fri May 10 21:01:02 2013 +0200
@@ -27,7 +27,7 @@
 #include <QCloseEvent>
 #include <QFileSystemWatcher>
 #include <QSettings>
-
+#include <QFileInfo>
 #include <Qsci/qsciscintilla.h>
 
 #include "find-dialog.h"
@@ -111,7 +111,7 @@
   void mru_add_file (const QString& file_name);
   void editor_check_conflict_save (const QString& saveFileName,
                                    bool remove_on_success);
-  void process_octave_code (const QString& command);
+  void run_file_signal (const QFileInfo& info);
 
 protected:
 
@@ -170,10 +170,6 @@
   int check_file_modified ();
   void do_comment_selected_text (bool comment);
 
-  void run_file_callback (const bp_info& info);
-
-  bool file_in_path (const std::string& file, const std::string& dir);
-
   void add_breakpoint_callback (const bp_info& info);
   void remove_breakpoint_callback (const bp_info& info);
   void remove_all_breakpoints_callback (const bp_info& info);
--- a/libgui/src/m-editor/file-editor.cc	Fri May 10 01:02:58 2013 +0100
+++ b/libgui/src/m-editor/file-editor.cc	Fri May 10 21:01:02 2013 +0200
@@ -1079,8 +1079,8 @@
   connect (f, SIGNAL (mru_add_file (const QString&)),
            this, SLOT (handle_mru_add_file (const QString&)));
 
-  connect (f, SIGNAL (process_octave_code (const QString&)),
-           parent (), SLOT (execute_command_in_terminal (const QString&)));
+  connect (f, SIGNAL (run_file_signal (const QFileInfo&)),
+           parent (), SLOT (run_file_in_terminal (const QFileInfo&)));
   
   // Signals from the file_editor non-trivial operations
   connect (this, SIGNAL (fetab_settings_changed (const QSettings *)),
--- a/libgui/src/main-window.cc	Fri May 10 01:02:58 2013 +0100
+++ b/libgui/src/main-window.cc	Fri May 10 21:01:02 2013 +0200
@@ -203,6 +203,12 @@
 }
 
 void
+main_window::run_file_in_terminal (const QFileInfo& info)
+{
+  octave_link::post_event (this, &main_window::run_file_callback, info);
+}
+
+void
 main_window::handle_new_figure_request (void)
 {
   octave_link::post_event (this, &main_window::new_figure_callback);
@@ -1459,6 +1465,17 @@
 }
 
 void
+main_window::run_file_callback (const QFileInfo& info)
+{
+  QString dir = info.absolutePath ();
+  QString function_name = info.fileName ();
+  function_name.chop (info.suffix ().length () + 1);
+  if (octave_qt_link::file_in_path (info.absoluteFilePath ().toStdString (),
+                                    dir.toStdString ()))
+    execute_command_callback (function_name.toStdString ());
+}
+
+void
 main_window::new_figure_callback (void)
 {
   Fbuiltin (ovl ("figure"));
@@ -1561,3 +1578,4 @@
 
 }
 
+
--- a/libgui/src/main-window.h	Fri May 10 01:02:58 2013 +0100
+++ b/libgui/src/main-window.h	Fri May 10 21:01:02 2013 +0200
@@ -116,6 +116,7 @@
   void accept_directory_line_edit (void);
 
   void execute_command_in_terminal(const QString& dir);
+  void run_file_in_terminal(const QFileInfo& info);
 
   void handle_new_figure_request (void);
 
@@ -213,6 +214,7 @@
   void clear_history_callback (void);
 
   void execute_command_callback (const std::string& command);
+  void run_file_callback (const QFileInfo& info);
 
   void new_figure_callback (void);
 
--- a/libgui/src/octave-qt-link.cc	Fri May 10 01:02:58 2013 +0100
+++ b/libgui/src/octave-qt-link.cc	Fri May 10 21:01:02 2013 +0200
@@ -29,10 +29,13 @@
 #include <QStringList>
 
 #include "str-vec.h"
-
 #include "dialog.h"
 #include "error.h"
 #include "workspace-element.h"
+#include "builtin-defun-decls.h"
+#include "load-path.h"
+#include "oct-env.h"
+#include "utils.h"
 
 #include "octave-qt-link.h"
 
@@ -423,3 +426,68 @@
 {
   emit delete_debugger_pointer_signal (QString::fromStdString (file), line);
 }
+
+
+bool
+octave_qt_link::file_in_path (const std::string& file, const std::string& dir)
+{
+
+  bool ok = false;
+  bool addpath_option = true;
+
+  std::string curr_dir = octave_env::get_current_directory ();
+
+  if (same_file (curr_dir, dir))
+    ok = true;
+  else
+    {
+      bool dir_in_load_path = load_path::contains_canonical (dir);
+
+      std::string base_file = octave_env::base_pathname (file);
+      std::string lp_file = load_path::find_file (base_file);
+
+      if (dir_in_load_path)
+        {
+          if (same_file (lp_file, file))
+            ok = true;
+        }
+      else
+        {
+          // File directory is not in path.  Is the file in the path in
+          // the current directory?  If so, then changing the current
+          // directory will be needed.  Adding directory to path is
+          // not enough because the file in the current directory would
+          // still be found.
+
+          if (same_file (lp_file, base_file))
+            {
+              if (same_file (curr_dir, dir))
+                ok = true;
+              else
+                addpath_option = false;
+            }
+        }
+    }
+
+  if (! ok)
+    {
+      int action = debug_cd_or_addpath_error (file, dir, addpath_option);
+      switch (action)
+        {
+        case 1:
+          Fcd (ovl (dir));
+          ok = true;
+          break;
+
+        case 2:
+          load_path::prepend (dir);
+          ok = true;
+          break;
+
+        default:
+          break;
+        }
+    }
+
+  return ok;
+}
--- a/libgui/src/octave-qt-link.h	Fri May 10 01:02:58 2013 +0100
+++ b/libgui/src/octave-qt-link.h	Fri May 10 21:01:02 2013 +0200
@@ -119,6 +119,7 @@
   void do_set_default_prompts (std::string& ps1, std::string& ps2,
                                std::string& ps4);
 
+  static bool file_in_path (const std::string& file, const std::string& dir);
 
 private: