Mercurial > hg > octave-lojdl
changeset 14827:6b90737f69cc gui
Very basic breakpoint setting and removing in the editor works.
* file-editor-tab: Instead of toggling breakpoints directly, now sends events.
* octave-event: Created new events to add and remove breakpoints.
author | Jacob Dawid <jacob.dawid@googlemail.com> |
---|---|
date | Mon, 02 Jul 2012 12:35:08 +0200 |
parents | ed0f820c7ce0 |
children | e97be88fc478 |
files | gui/src/m-editor/file-editor-tab.cc gui/src/m-editor/file-editor-tab.h gui/src/octave-adapter/octave-event.h |
diffstat | 3 files changed, 185 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/gui/src/m-editor/file-editor-tab.cc +++ b/gui/src/m-editor/file-editor-tab.cc @@ -107,6 +107,28 @@ { // File was run successfully. } + + if (octave_add_breakpoint_event *abe + = dynamic_cast<octave_add_breakpoint_event*> (e)) + { + // TODO: Check file. + _edit_area->markerAdd (abe->get_line (), breakpoint); + } + + if (octave_remove_breakpoint_event *rbe + = dynamic_cast<octave_remove_breakpoint_event*> (e)) + { + // TODO: Check file. + _edit_area->markerDelete (rbe->get_line (), breakpoint); + } + + if (octave_remove_all_breakpoints_event *rabe + = dynamic_cast<octave_remove_all_breakpoints_event*> (e)) + { + Q_UNUSED (rabe); + _edit_area->markerDeleteAll (breakpoint); + } + delete e; } @@ -168,14 +190,52 @@ else { if (mask && (1 << breakpoint)) - _edit_area->markerDelete(line,breakpoint); + { + request_remove_breakpoint (line); + } else - _edit_area->markerAdd(line,breakpoint); + { + request_add_breakpoint (line); + } } } } void +file_editor_tab::request_add_breakpoint (int line) +{ + QFileInfo file_info (_file_name); + QString path = file_info.absolutePath (); + QString function_name = file_info.fileName (); + + // We have to cut off the suffix, because octave appends it. + function_name.chop (file_info.suffix ().length () + 1); + + octave_link::instance ()->post_event + (new octave_add_breakpoint_event (*this, + path.toStdString (), + function_name.toStdString (), + line)); +} + +void +file_editor_tab::request_remove_breakpoint (int line) +{ + QFileInfo file_info (_file_name); + QString path = file_info.absolutePath (); + QString function_name = file_info.fileName (); + + // We have to cut off the suffix, because octave appends it. + function_name.chop (file_info.suffix ().length () + 1); + + octave_link::instance ()->post_event + (new octave_remove_breakpoint_event (*this, + path.toStdString (), + function_name.toStdString (), + line)); +} + +void file_editor_tab::comment_selected_text () { do_comment_selected_text (true); @@ -332,11 +392,11 @@ file_editor_tab::toggle_breakpoint () { int line, cur; - _edit_area->getCursorPosition (&line,&cur); + _edit_area->getCursorPosition (&line, &cur); if ( _edit_area->markersAtLine (line) && (1 << breakpoint) ) - _edit_area->markerDelete (line, breakpoint); + request_remove_breakpoint (line); else - _edit_area->markerAdd (line, breakpoint); + request_add_breakpoint (line); } void
--- a/gui/src/m-editor/file-editor-tab.h +++ b/gui/src/m-editor/file-editor-tab.h @@ -79,6 +79,9 @@ void set_file_name (QString fileName); private: + void request_add_breakpoint (int line); + void request_remove_breakpoint (int line); + void update_tracked_file (); int check_file_modified (QString msg, int cancelButton); void do_comment_selected_text (bool comment);
--- a/gui/src/octave-adapter/octave-event.h +++ b/gui/src/octave-adapter/octave-event.h @@ -250,6 +250,123 @@ } }; +class octave_add_breakpoint_event : public octave_event +{ + public: + octave_add_breakpoint_event (octave_event_observer& o, + std::string path, + std::string function_name, + int line) + : octave_event (o) + { + _path = path; + _function_name = function_name; + _line = line; + } + + bool perform () + { + bp_table::intmap intmap; + intmap[0] = _line; + + // TODO: Check success. + std::string previous_directory = octave_env::get_current_directory (); + octave_env::chdir (_path); + bp_table::add_breakpoint (_function_name, intmap); + octave_env::chdir (previous_directory); + return true; + } + + std::string get_path () + { + return _path; + } + + std::string get_function_name () + { + return _function_name; + } + + int get_line () + { + return _line; + } + + private: + std::string _path; + std::string _function_name; + int _line; +}; + +class octave_remove_breakpoint_event : public octave_event +{ + public: + octave_remove_breakpoint_event (octave_event_observer& o, + std::string path, + std::string function_name, + int line) + : octave_event (o) + { + _path = path; + _function_name = function_name; + _line = line; + } + + bool perform () + { + bp_table::intmap intmap; + intmap[0] = _line; + + // TODO: Check success. + std::string previous_directory = octave_env::get_current_directory (); + octave_env::chdir (_path); + bp_table::remove_breakpoint (_function_name, intmap); + octave_env::chdir (previous_directory); + return true; + } + + std::string get_path () + { + return _path; + } + + std::string get_function_name () + { + return _function_name; + } + + int get_line () + { + return _line; + } + + private: + std::string _path; + std::string _function_name; + int _line; +}; + +class octave_remove_all_breakpoints_event : public octave_event +{ + public: + octave_remove_all_breakpoints_event (octave_event_observer& o, + std::string file) + : octave_event (o) + { + _file = file; + } + + bool perform () + { + // TODO: Check success. + bp_table::remove_all_breakpoints_in_file (_file, true); + return true; + } + + private: + std::string _file; +}; + class octave_debug_step_into_event : public octave_event { public: