Mercurial > hg > octave-lyh
comparison 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 |
comparison
equal
deleted
inserted
replaced
16634:2510fffc05e1 | 16635:25e418d23a4b |
---|---|
27 #endif | 27 #endif |
28 | 28 |
29 #include <QStringList> | 29 #include <QStringList> |
30 | 30 |
31 #include "str-vec.h" | 31 #include "str-vec.h" |
32 | |
33 #include "dialog.h" | 32 #include "dialog.h" |
34 #include "error.h" | 33 #include "error.h" |
35 #include "workspace-element.h" | 34 #include "workspace-element.h" |
35 #include "builtin-defun-decls.h" | |
36 #include "load-path.h" | |
37 #include "oct-env.h" | |
38 #include "utils.h" | |
36 | 39 |
37 #include "octave-qt-link.h" | 40 #include "octave-qt-link.h" |
38 | 41 |
39 octave_qt_link::octave_qt_link (octave_main_thread *mt) | 42 octave_qt_link::octave_qt_link (octave_main_thread *mt) |
40 : octave_link (), main_thread (mt) | 43 : octave_link (), main_thread (mt) |
421 void | 424 void |
422 octave_qt_link::do_delete_debugger_pointer (const std::string& file, int line) | 425 octave_qt_link::do_delete_debugger_pointer (const std::string& file, int line) |
423 { | 426 { |
424 emit delete_debugger_pointer_signal (QString::fromStdString (file), line); | 427 emit delete_debugger_pointer_signal (QString::fromStdString (file), line); |
425 } | 428 } |
429 | |
430 | |
431 bool | |
432 octave_qt_link::file_in_path (const std::string& file, const std::string& dir) | |
433 { | |
434 | |
435 bool ok = false; | |
436 bool addpath_option = true; | |
437 | |
438 std::string curr_dir = octave_env::get_current_directory (); | |
439 | |
440 if (same_file (curr_dir, dir)) | |
441 ok = true; | |
442 else | |
443 { | |
444 bool dir_in_load_path = load_path::contains_canonical (dir); | |
445 | |
446 std::string base_file = octave_env::base_pathname (file); | |
447 std::string lp_file = load_path::find_file (base_file); | |
448 | |
449 if (dir_in_load_path) | |
450 { | |
451 if (same_file (lp_file, file)) | |
452 ok = true; | |
453 } | |
454 else | |
455 { | |
456 // File directory is not in path. Is the file in the path in | |
457 // the current directory? If so, then changing the current | |
458 // directory will be needed. Adding directory to path is | |
459 // not enough because the file in the current directory would | |
460 // still be found. | |
461 | |
462 if (same_file (lp_file, base_file)) | |
463 { | |
464 if (same_file (curr_dir, dir)) | |
465 ok = true; | |
466 else | |
467 addpath_option = false; | |
468 } | |
469 } | |
470 } | |
471 | |
472 if (! ok) | |
473 { | |
474 int action = debug_cd_or_addpath_error (file, dir, addpath_option); | |
475 switch (action) | |
476 { | |
477 case 1: | |
478 Fcd (ovl (dir)); | |
479 ok = true; | |
480 break; | |
481 | |
482 case 2: | |
483 load_path::prepend (dir); | |
484 ok = true; | |
485 break; | |
486 | |
487 default: | |
488 break; | |
489 } | |
490 } | |
491 | |
492 return ok; | |
493 } |