# HG changeset patch # User Jacob Dawid # Date 1341225308 -7200 # Node ID 6b90737f69cc0f17794ce0aef0e3fb684f6f880a # Parent ed0f820c7ce004b5a8515fc28a86b455026af49a 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. diff -r ed0f820c7ce0 -r 6b90737f69cc gui/src/m-editor/file-editor-tab.cc --- a/gui/src/m-editor/file-editor-tab.cc Mon Jul 02 10:51:47 2012 +0200 +++ b/gui/src/m-editor/file-editor-tab.cc Mon Jul 02 12:35:08 2012 +0200 @@ -107,6 +107,28 @@ { // File was run successfully. } + + if (octave_add_breakpoint_event *abe + = dynamic_cast (e)) + { + // TODO: Check file. + _edit_area->markerAdd (abe->get_line (), breakpoint); + } + + if (octave_remove_breakpoint_event *rbe + = dynamic_cast (e)) + { + // TODO: Check file. + _edit_area->markerDelete (rbe->get_line (), breakpoint); + } + + if (octave_remove_all_breakpoints_event *rabe + = dynamic_cast (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 diff -r ed0f820c7ce0 -r 6b90737f69cc gui/src/m-editor/file-editor-tab.h --- a/gui/src/m-editor/file-editor-tab.h Mon Jul 02 10:51:47 2012 +0200 +++ b/gui/src/m-editor/file-editor-tab.h Mon Jul 02 12:35:08 2012 +0200 @@ -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); diff -r ed0f820c7ce0 -r 6b90737f69cc gui/src/octave-adapter/octave-event.h --- a/gui/src/octave-adapter/octave-event.h Mon Jul 02 10:51:47 2012 +0200 +++ b/gui/src/octave-adapter/octave-event.h Mon Jul 02 12:35:08 2012 +0200 @@ -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: