From 9a3da9043c683999178d08c947b62fdb1b6897ba Mon Sep 17 00:00:00 2001 From: Ole Christian Eidheim Date: Wed, 21 Dec 2016 13:34:53 +0100 Subject: [PATCH] Fixed crash when trying to scroll in an already closed SelectionDialog --- src/selectiondialog.cc | 9 ++++----- src/selectiondialog.h | 2 +- src/source.cc | 4 ++-- src/source_clang.cc | 4 ++-- src/source_spellcheck.cc | 2 +- 5 files changed, 10 insertions(+), 11 deletions(-) diff --git a/src/selectiondialog.cc b/src/selectiondialog.cc index 8226a15..86d941d 100644 --- a/src/selectiondialog.cc +++ b/src/selectiondialog.cc @@ -90,7 +90,7 @@ SelectionDialogBase::SelectionDialogBase(Gtk::TextView& text_view, Glib::RefPtr< } void SelectionDialogBase::cursor_changed() { - if(!shown) + if(!is_visible()) return; auto it=list_view_text.get_selection()->get_selected(); std::string row; @@ -112,7 +112,6 @@ void SelectionDialogBase::add_row(const std::string& row) { } void SelectionDialogBase::show() { - shown=true; window.show_all(); text_view.grab_focus(); @@ -124,7 +123,8 @@ void SelectionDialogBase::show() { else if(list_view_text.get_model()->children().begin()!=list_view_text.get_selection()->get_selected()) { while(Gtk::Main::events_pending()) Gtk::Main::iteration(false); - list_view_text.scroll_to_row(list_view_text.get_model()->get_path(list_view_text.get_selection()->get_selected()), 0.5); + if(is_visible()) + list_view_text.scroll_to_row(list_view_text.get_model()->get_path(list_view_text.get_selection()->get_selected()), 0.5); } } } @@ -138,9 +138,8 @@ void SelectionDialogBase::set_cursor_at_last_row() { } void SelectionDialogBase::hide() { - if(!shown) + if(!is_visible()) return; - shown=false; window.hide(); if(on_hide) on_hide(); diff --git a/src/selectiondialog.h b/src/selectiondialog.h index 431e332..74cd014 100644 --- a/src/selectiondialog.h +++ b/src/selectiondialog.h @@ -37,13 +37,13 @@ public: void set_cursor_at_last_row(); void show(); void hide(); + bool is_visible() {return window.is_visible();} std::function on_hide; std::function on_select; std::function on_changed; Glib::RefPtr start_mark; - bool shown=false; protected: void cursor_changed(); diff --git a/src/source.cc b/src/source.cc index 0a32b25..e1b8971 100644 --- a/src/source.cc +++ b/src/source.cc @@ -1244,11 +1244,11 @@ std::string Source::View::get_token(Gtk::TextIter iter) { } bool Source::View::on_key_press_event(GdkEventKey* key) { - if(selection_dialog && selection_dialog->shown) { + if(selection_dialog && selection_dialog->is_visible()) { if(selection_dialog->on_key_press(key)) return true; } - if(autocomplete_dialog && autocomplete_dialog->shown) { + if(autocomplete_dialog && autocomplete_dialog->is_visible()) { if(autocomplete_dialog->on_key_press(key)) return true; } diff --git a/src/source_clang.cc b/src/source_clang.cc index 7dd2924..8409d12 100644 --- a/src/source_clang.cc +++ b/src/source_clang.cc @@ -568,7 +568,7 @@ void Source::ClangViewParse::show_type_tooltips(const Gdk::Rectangle &rectangle) Source::ClangViewAutocomplete::ClangViewAutocomplete(const boost::filesystem::path &file_path, Glib::RefPtr language): Source::ClangViewParse(file_path, language), autocomplete_state(AutocompleteState::IDLE) { get_buffer()->signal_changed().connect([this](){ - if(autocomplete_dialog && autocomplete_dialog->shown) + if(autocomplete_dialog && autocomplete_dialog->is_visible()) delayed_reparse_connection.disconnect(); else { if(!has_focus()) @@ -596,7 +596,7 @@ Source::ClangViewAutocomplete::ClangViewAutocomplete(const boost::filesystem::pa }); signal_key_release_event().connect([this](GdkEventKey* key){ - if(autocomplete_dialog && autocomplete_dialog->shown) { + if(autocomplete_dialog && autocomplete_dialog->is_visible()) { if(autocomplete_dialog->on_key_release(key)) return true; } diff --git a/src/source_spellcheck.cc b/src/source_spellcheck.cc index 867ed7f..7dddf06 100644 --- a/src/source_spellcheck.cc +++ b/src/source_spellcheck.cc @@ -27,7 +27,7 @@ Source::SpellCheckView::SpellCheckView() : Gsv::View() { spellcheck_error_tag->property_underline()=Pango::Underline::UNDERLINE_ERROR; signal_key_press_event().connect([this](GdkEventKey *event) { - if(spellcheck_suggestions_dialog && spellcheck_suggestions_dialog->shown) { + if(spellcheck_suggestions_dialog && spellcheck_suggestions_dialog->is_visible()) { if(spellcheck_suggestions_dialog->on_key_press(event)) return true; }