Mercurial > hg > octave-lyh
diff libgui/src/octave-qt-link.cc @ 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 | fa4a035e0cf4 |
children | b04413e5a811 |
line wrap: on
line diff
--- a/libgui/src/octave-qt-link.cc +++ b/libgui/src/octave-qt-link.cc @@ -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; +}