Mercurial > octave
diff libgui/src/m-editor/file-editor-tab.cc @ 16547:3cd80afc3509
improve debugging with the GUI
* dialog.h, dialog.cc (cd_or_addpath_dialog): New class.
(QUIWidgetCreator::signal_debug_cd_or_addpath): New function.
(QUIWidgetCreator::create_debug_cd_or_addpath_dialog): New signal.
* file-editor-tab.h, file-editor-tab.cc
(file_editor_tab::file_in_path): New function.
(file_editor_tab::add_breakpoint_callback,
file_editor_tab::remove_breakpoint_callback,
file_editor_tab::remove_all_breakpoints_callback): Use file_in_path.
Don't cd to the directory containing the file. Don't add 1 to the
line number.
(file_editor_tab::request_add_breakpoint,
file_editor_tab::request_remove_breakpoint):
Add 1 to the line number.
(file_editor_tab::insert_debugger_pointer,
file_editor_tab::delete_debugger_pointer,
file_editor_tab::do_breakpoint_marker): Subtract 1 from line.
(file_editor_tab::bp_info): Also cache full file name. Change all uses.
* file-editor.h, file-editor.cc (file_editor::request_open_file,
file_editor::handle_delete_debugger_pointer_request):
Don't subtract 1 from line numbers.
* main-window.h, main-window.cc (main_window::connect_uiwidget_links):
Connect uiwidget_creator::create_debug_cd_or_addpath_dialog to
main_window::handle_create_debug_cd_or_addpath_dialog.
(main_window::handle_create_debug_cd_or_addpath_dialog):
New function.
* octave-qt-link.h, octave-qt-link.cc
(octave_qt_link::do_debug_cd_or_addpath_error): New function.
* load-path.h, load-path.cc (load_path::contains_canonical,
load_path::do_contains_canonical): New functions.
* octave-link.h (octave_link::debug_cd_or_addpath_error,
octave_link::do_debug_cd_or_addpath_error): New functions.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 19 Apr 2013 17:36:40 -0400 |
parents | 086b5e81245b |
children | 5fc1ce2947bd |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc Fri Apr 19 09:36:22 2013 -0400 +++ b/libgui/src/m-editor/file-editor-tab.cc Fri Apr 19 17:36:40 2013 -0400 @@ -47,10 +47,13 @@ #include "file-editor-tab.h" #include "file-editor.h" + +#include "builtin-defun-decls.h" +#include "debug.h" +#include "load-path.h" #include "octave-link.h" - -#include "debug.h" #include "oct-env.h" +#include "utils.h" // Make parent null for the file editor tab so that warning // WindowModal messages don't affect grandparents. @@ -195,13 +198,9 @@ else { if (markers_mask && (1 << breakpoint)) - { - request_remove_breakpoint (line); - } + request_remove_breakpoint (line); else - { - request_add_breakpoint (line); - } + request_add_breakpoint (line); } } } @@ -431,42 +430,96 @@ _edit_area->markerDeleteAll (bookmark); } +bool +file_editor_tab::file_in_path (const bp_info& info) +{ + bool ok = false; + bool addpath_option = true; + + std::string curr_dir = octave_env::get_current_directory (); + + if (curr_dir == info.path) + ok = true; + else + { + bool dir_in_load_path = load_path::contains_canonical (info.path); + + std::string base_file = octave_env::base_pathname (info.file); + std::string lp_file = load_path::find_file (base_file); + + if (dir_in_load_path) + { + if (same_file (lp_file, info.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, info.path)) + ok = true; + else + addpath_option = false; + } + } + } + + if (! ok) + { + int action + = octave_link::debug_cd_or_addpath_error (info.file, info.path, + addpath_option); + switch (action) + { + case 1: + Fcd (ovl (info.path)); + ok = true; + break; + + case 2: + load_path::prepend (info.path); + ok = true; + break; + + default: + break; + } + } + + return ok; +} + void file_editor_tab::add_breakpoint_callback (const bp_info& info) { - bp_table::intmap intmap; - intmap[0] = info.line + 1; + bp_table::intmap line_info; + line_info[0] = info.line; - std::string previous_directory = octave_env::get_current_directory (); - octave_env::chdir (info.path); - intmap = bp_table::add_breakpoint (info.function_name, intmap); - octave_env::chdir (previous_directory); - // bp_table::add_breakpoint also sets the marker in the editor + if (file_in_path (info)) + bp_table::add_breakpoint (info.function_name, line_info); } void file_editor_tab::remove_breakpoint_callback (const bp_info& info) { - bp_table::intmap intmap; - intmap[0] = info.line + 1; + bp_table::intmap line_info; + line_info[0] = info.line; - std::string previous_directory = octave_env::get_current_directory (); - octave_env::chdir (info.path); - bp_table::remove_breakpoint (info.function_name, intmap); - octave_env::chdir (previous_directory); + if (file_in_path (info)) + bp_table::remove_breakpoint (info.function_name, line_info); } void file_editor_tab::remove_all_breakpoints_callback (const bp_info& info) { - bp_table::intmap intmap; - std::string previous_directory = octave_env::get_current_directory (); - octave_env::chdir (info.path); - intmap = bp_table::remove_all_breakpoints_in_file (info.function_name, true); - octave_env::chdir (previous_directory); - - if (intmap.size() > 0) - _edit_area->markerDeleteAll (breakpoint); + if (file_in_path (info)) + bp_table::remove_all_breakpoints_in_file (info.function_name, true); } void @@ -479,7 +532,7 @@ // We have to cut off the suffix, because octave appends it. function_name.chop (file_info.suffix ().length () + 1); - bp_info info (path, function_name, line); + bp_info info (_file_name, path, function_name, line+1); octave_link::post_event (this, &file_editor_tab::add_breakpoint_callback, info); @@ -495,7 +548,7 @@ // We have to cut off the suffix, because octave appends it. function_name.chop (file_info.suffix ().length () + 1); - bp_info info (path, function_name, line); + bp_info info (_file_name, path, function_name, line+1); octave_link::post_event (this, &file_editor_tab::remove_breakpoint_callback, info); @@ -556,7 +609,7 @@ // We have to cut off the suffix, because octave appends it. function_name.chop (file_info.suffix ().length () + 1); - bp_info info (path, function_name, 0); + bp_info info (_file_name, path, function_name, 0); octave_link::post_event (this, &file_editor_tab::remove_all_breakpoints_callback, info); @@ -1143,7 +1196,7 @@ if (line > 0) { - _edit_area->markerAdd (line, debugger_position); + _edit_area->markerAdd (line-1, debugger_position); center_current_line (); } } @@ -1155,7 +1208,7 @@ return; if (line > 0) - _edit_area->markerDelete (line, debugger_position); + _edit_area->markerDelete (line-1, debugger_position); } void @@ -1167,9 +1220,9 @@ if (line > 0) { if (insert) - _edit_area->markerAdd (line, breakpoint); + _edit_area->markerAdd (line-1, breakpoint); else - _edit_area->markerDelete (line, breakpoint); + _edit_area->markerDelete (line-1, breakpoint); } }