From 8da4a46d5566d0454ab754cd5ac0046565ecfbf2 Mon Sep 17 00:00:00 2001 From: eidheim Date: Fri, 3 Jun 2016 21:33:48 +0200 Subject: [PATCH] Notebook focus and page change cleanup --- src/notebook.cc | 31 ++++++++++++++++--------------- src/notebook.h | 6 ++++-- 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/src/notebook.cc b/src/notebook.cc index 0c81a70..3f6dc8d 100644 --- a/src/notebook.cc +++ b/src/notebook.cc @@ -57,11 +57,11 @@ Notebook::Notebook() : Gtk::HPaned(), notebooks(2) { notebook.set_scrollable(); notebook.set_group_name("source_notebooks"); notebook.signal_switch_page().connect([this](Gtk::Widget *widget, guint) { - //Sometimes focus is lost when tabs are reordered auto hbox=dynamic_cast(widget); for(size_t c=0;csignal_focus_in_event().connect([this, source_view](GdkEventFocus *) { - current_view_pre_focused=nullptr; - if(source_view!=current_view_focused) { - current_view_focused=source_view; - if(on_change_page) - on_change_page(source_view); - } - else - current_view_focused=source_view; + set_current_view(source_view); return false; }); @@ -432,9 +426,7 @@ Source::View *Notebook::get_view(size_t notebook_index, int page) { } void Notebook::focus_view(Source::View *view) { - if(!view) - return; - current_view_pre_focused=view; + intermediate_view=view; view->grab_focus(); } @@ -449,6 +441,15 @@ std::pair Notebook::get_notebook_page(size_t index) { return {-1, -1}; } +void Notebook::set_current_view(Source::View *view) { + intermediate_view=nullptr; + if(current_view!=view) { + current_view=view; + if(on_change_page) + on_change_page(view); + } +} + bool Notebook::save_modified_dialog(size_t index) { Gtk::MessageDialog dialog(*static_cast(get_toplevel()), "Save file!", false, Gtk::MESSAGE_QUESTION, Gtk::BUTTONS_YES_NO); dialog.set_default_response(Gtk::RESPONSE_YES); diff --git a/src/notebook.h b/src/notebook.h index 014d04d..87676d5 100644 --- a/src/notebook.h +++ b/src/notebook.h @@ -64,8 +64,10 @@ private: bool split=false; size_t last_index=-1; - Source::View* current_view_pre_focused=nullptr; - Source::View* current_view_focused=nullptr; + + void set_current_view(Source::View *view); + Source::View* current_view=nullptr; + Source::View* intermediate_view=nullptr; bool save_modified_dialog(size_t index); };