Browse Source

Improved separation of what is performed in window and project classes

merge-requests/365/head
eidheim 10 years ago
parent
commit
edbd713280
  1. 57
      src/project.cc
  2. 14
      src/project.h
  3. 54
      src/window.cc

57
src/project.cc

@ -469,61 +469,12 @@ void Project::Clang::debug_run_command(const std::string &command) {
}
}
void Project::Clang::toggle_breakpoint() {
if(notebook.get_current_page()!=-1) {
auto view=notebook.get_current_view();
bool debug_is_stopped_or_running=Debug::get().is_stopped() || Debug::get().is_running();
if(Debug::get().is_invalid() || debug_is_stopped_or_running) {
auto line_nr=view->get_buffer()->get_insert()->get_iter().get_line();
if(view->get_source_buffer()->get_source_marks_at_line(line_nr, "debug_breakpoint").size()>0) {
auto start_iter=view->get_buffer()->get_iter_at_line(line_nr);
auto end_iter=start_iter;
while(!end_iter.ends_line() && end_iter.forward_char()) {}
view->get_source_buffer()->remove_source_marks(start_iter, end_iter, "debug_breakpoint");
if(debug_is_stopped_or_running)
Debug::get().remove_breakpoint(view->file_path, line_nr+1, view->get_buffer()->get_line_count()+1);
}
else {
view->get_source_buffer()->create_source_mark("debug_breakpoint", view->get_buffer()->get_insert()->get_iter());
if(debug_is_stopped_or_running)
Debug::get().add_breakpoint(view->file_path, line_nr+1);
}
}
void Project::Clang::debug_add_breakpoint(const boost::filesystem::path &file_path, int line_nr) {
Debug::get().add_breakpoint(file_path, line_nr);
}
}
void Project::Clang::debug_goto_stop() {
if(Project::get().debugging) {
auto &project=Project::get();
project.debug_stop_mutex.lock();
auto debug_stop_copy=project.debug_stop;
project.debug_stop_mutex.unlock();
if(!debug_stop_copy.first.empty()) {
notebook.open(debug_stop_copy.first);
if(notebook.get_current_page()!=-1) {
auto view=notebook.get_current_view();
int line_nr=debug_stop_copy.second.first-1;
int line_index=debug_stop_copy.second.second-1;
if(line_nr<view->get_buffer()->get_line_count()) {
auto iter=view->get_buffer()->get_iter_at_line(line_nr);
auto end_line_iter=iter;
while(!iter.ends_line() && iter.forward_char()) {}
auto line=view->get_buffer()->get_text(iter, end_line_iter);
if(static_cast<size_t>(line_index)>=line.bytes())
line_index=0;
view->get_buffer()->place_cursor(view->get_buffer()->get_iter_at_line_index(line_nr, line_index));
while(g_main_context_pending(NULL))
g_main_context_iteration(NULL, false);
if(notebook.get_current_page()!=-1 && notebook.get_current_view()==view)
view->scroll_to(view->get_buffer()->get_insert(), 0.0, 1.0, 0.5);
}
project.debug_update_stop();
}
}
}
void Project::Clang::debug_remove_breakpoint(const boost::filesystem::path &file_path, int line_nr, int line_count) {
Debug::get().remove_breakpoint(file_path, line_nr, line_count);
}
void Project::Clang::debug_delete() {

14
src/project.h

@ -12,10 +12,7 @@
class Project {
private:
std::pair<boost::filesystem::path, std::pair<int, int> > debug_stop;
std::mutex debug_stop_mutex;
boost::filesystem::path debug_last_stop_file_path;
Glib::Dispatcher debug_update_stop;
std::string debug_status;
std::mutex debug_status_mutex;
Glib::Dispatcher debug_update_status;
@ -29,6 +26,9 @@ public:
}
Gtk::Label debug_status_label;
std::pair<boost::filesystem::path, std::pair<int, int> > debug_stop;
std::mutex debug_stop_mutex;
Glib::Dispatcher debug_update_stop;
std::unordered_map<std::string, std::string> run_arguments;
std::unordered_map<std::string, std::string> debug_run_arguments;
std::atomic<bool> compiling;
@ -57,8 +57,8 @@ public:
virtual void debug_backtrace() {}
virtual void debug_show_variables() {}
virtual void debug_run_command(const std::string &command) {}
virtual void toggle_breakpoint() {}
virtual void debug_goto_stop() {}
virtual void debug_add_breakpoint(const boost::filesystem::path &file_path, int line_nr) {}
virtual void debug_remove_breakpoint(const boost::filesystem::path &file_path, int line_nr, int line_count) {}
virtual void debug_delete() {}
};
@ -85,8 +85,8 @@ public:
void debug_backtrace() override;
void debug_show_variables() override;
void debug_run_command(const std::string &command) override;
void toggle_breakpoint() override;
void debug_goto_stop() override;
void debug_add_breakpoint(const boost::filesystem::path &file_path, int line_nr) override;
void debug_remove_breakpoint(const boost::filesystem::path &file_path, int line_nr, int line_count) override;
void debug_delete() override;
#endif
};

54
src/window.cc

@ -667,14 +667,56 @@ void Window::set_menu_actions() {
entry_box.show();
});
menu.add_action("debug_toggle_breakpoint", [this](){
if(Project::get().debugging)
project_language->toggle_breakpoint();
else
Project::get().get_language()->toggle_breakpoint();
if(notebook.get_current_page()!=-1) {
auto view=notebook.get_current_view();
auto line_nr=view->get_buffer()->get_insert()->get_iter().get_line();
if(view->get_source_buffer()->get_source_marks_at_line(line_nr, "debug_breakpoint").size()>0) {
auto start_iter=view->get_buffer()->get_iter_at_line(line_nr);
auto end_iter=start_iter;
while(!end_iter.ends_line() && end_iter.forward_char()) {}
view->get_source_buffer()->remove_source_marks(start_iter, end_iter, "debug_breakpoint");
if(project_language)
project_language->debug_remove_breakpoint(view->file_path, line_nr+1, view->get_buffer()->get_line_count()+1);
}
else {
view->get_source_buffer()->create_source_mark("debug_breakpoint", view->get_buffer()->get_insert()->get_iter());
if(project_language)
project_language->debug_add_breakpoint(view->file_path, line_nr+1);
}
}
});
menu.add_action("debug_goto_stop", [this](){
if(project_language)
project_language->debug_goto_stop();
if(Project::get().debugging) {
auto &project=Project::get();
project.debug_stop_mutex.lock();
auto debug_stop_copy=project.debug_stop;
project.debug_stop_mutex.unlock();
if(!debug_stop_copy.first.empty()) {
notebook.open(debug_stop_copy.first);
if(notebook.get_current_page()!=-1) {
auto view=notebook.get_current_view();
int line_nr=debug_stop_copy.second.first-1;
int line_index=debug_stop_copy.second.second-1;
if(line_nr<view->get_buffer()->get_line_count()) {
auto iter=view->get_buffer()->get_iter_at_line(line_nr);
auto end_line_iter=iter;
while(!iter.ends_line() && iter.forward_char()) {}
auto line=view->get_buffer()->get_text(iter, end_line_iter);
if(static_cast<size_t>(line_index)>=line.bytes())
line_index=0;
view->get_buffer()->place_cursor(view->get_buffer()->get_iter_at_line_index(line_nr, line_index));
while(g_main_context_pending(NULL))
g_main_context_iteration(NULL, false);
if(notebook.get_current_page()!=-1 && notebook.get_current_view()==view)
view->scroll_to(view->get_buffer()->get_insert(), 0.0, 1.0, 0.5);
}
project.debug_update_stop();
}
}
}
});
#endif

Loading…
Cancel
Save