Browse Source

Cleanup of the code around while(g_main_context_pending(NULL)) loops

merge-requests/365/head
eidheim 10 years ago
parent
commit
af62c9a3f7
  1. 2
      src/source_clang.cc
  2. 20
      src/window.cc

2
src/source_clang.cc

@ -1007,7 +1007,7 @@ Source::ClangViewAutocomplete(file_path, project_path, language) {
iter.forward_char(); iter.forward_char();
} }
get_buffer()->place_cursor(iter); get_buffer()->place_cursor(iter);
while(g_main_context_pending(NULL)) while(g_main_context_pending(NULL)) //TODO: minor: might crash if the buffer is saved and closed really fast right after doing auto indent
g_main_context_iteration(NULL, false); g_main_context_iteration(NULL, false);
scroll_to(get_buffer()->get_insert(), 0.0, 1.0, 0.5); scroll_to(get_buffer()->get_insert(), 0.0, 1.0, 0.5);
} }

20
src/window.cc

@ -334,10 +334,12 @@ void Window::set_menu_actions() {
}); });
menu->add_action("source_center_cursor", [this]() { menu->add_action("source_center_cursor", [this]() {
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
auto view=notebook.get_current_view();
while(g_main_context_pending(NULL)) while(g_main_context_pending(NULL))
g_main_context_iteration(NULL, false); g_main_context_iteration(NULL, false);
if(notebook.get_current_page()!=-1) if(notebook.get_current_page()!=-1 && notebook.get_current_view()==view)
notebook.get_current_view()->scroll_to(notebook.get_current_view()->get_buffer()->get_insert(), 0.0, 1.0, 0.5); view->scroll_to(view->get_buffer()->get_insert(), 0.0, 1.0, 0.5);
} }
}); });
@ -408,7 +410,7 @@ void Window::set_menu_actions() {
g_main_context_iteration(NULL, false); g_main_context_iteration(NULL, false);
if(notebook.get_current_page()!=-1 && notebook.get_current_view()==view) { if(notebook.get_current_page()!=-1 && notebook.get_current_view()==view) {
view->get_buffer()->place_cursor(view->get_buffer()->get_iter_at_line_index(line, index)); view->get_buffer()->place_cursor(view->get_buffer()->get_iter_at_line_index(line, index));
notebook.get_current_view()->scroll_to(notebook.get_current_view()->get_buffer()->get_insert(), 0.0, 1.0, 0.5); view->scroll_to(view->get_buffer()->get_insert(), 0.0, 1.0, 0.5);
} }
} }
} }
@ -844,16 +846,18 @@ void Window::goto_line_entry() {
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
entry_box.entries.emplace_back("", [this](const std::string& content){ entry_box.entries.emplace_back("", [this](const std::string& content){
if(notebook.get_current_page()!=-1) { if(notebook.get_current_page()!=-1) {
auto buffer=notebook.get_current_view()->get_buffer(); auto view=notebook.get_current_view();
try { try {
auto line = stoi(content); auto line = stoi(content);
if(line>0 && line<=buffer->get_line_count()) { if(line>0 && line<=view->get_buffer()->get_line_count()) {
line--; line--;
buffer->place_cursor(buffer->get_iter_at_line(line));
while(g_main_context_pending(NULL)) while(g_main_context_pending(NULL))
g_main_context_iteration(NULL, false); g_main_context_iteration(NULL, false);
if(notebook.get_current_page()!=-1) if(notebook.get_current_page()!=-1 && notebook.get_current_view()==view) {
notebook.get_current_view()->scroll_to(buffer->get_insert(), 0.0, 1.0, 0.5); view->get_buffer()->place_cursor(view->get_buffer()->get_iter_at_line(line));
view->scroll_to(view->get_buffer()->get_insert(), 0.0, 1.0, 0.5);
}
} }
} }
catch(const std::exception &e) {} catch(const std::exception &e) {}

Loading…
Cancel
Save