[gnote] Set focus on current page when popover is closed



commit 238d6616bf015d9d5b2f7e202f6087a9adeb2c03
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sat Aug 20 21:51:12 2022 +0300

    Set focus on current page when popover is closed

 src/recentchanges.cpp | 16 ++++++++++++++++
 src/recentchanges.hpp |  1 +
 2 files changed, 17 insertions(+)
---
diff --git a/src/recentchanges.cpp b/src/recentchanges.cpp
index 073a9ed7..37ff7dc4 100644
--- a/src/recentchanges.cpp
+++ b/src/recentchanges.cpp
@@ -1000,9 +1000,25 @@ namespace gnote {
     menu->set_relative_to(*button);
     menu->set_modal(true);
     menu->set_position(Gtk::POS_BOTTOM);
+
+    menu->signal_closed().connect(sigc::mem_fun(*this, &NoteRecentChanges::on_window_menu_closed));
     return menu;
   }
 
+  void NoteRecentChanges::on_window_menu_closed()
+  {
+    auto idx = m_embed_book.get_current_page();
+    if(idx < 0) {
+      return;
+    }
+    auto current_page = dynamic_cast<EmbeddableWidget*>(m_embed_book.get_nth_page(idx));
+    if(current_page == nullptr) {
+      return;
+    }
+
+    current_page->set_initial_focus();
+  }
+
   void NoteRecentChanges::on_popover_widgets_changed()
   {
     if(m_window_menu_embedded) {
diff --git a/src/recentchanges.hpp b/src/recentchanges.hpp
index 48f53272..9e7458f8 100644
--- a/src/recentchanges.hpp
+++ b/src/recentchanges.hpp
@@ -96,6 +96,7 @@ private:
   void on_find_next_button_clicked();
   void on_find_prev_button_clicked();
   Gtk::PopoverMenu *make_window_menu(Gtk::Button *button, std::vector<PopoverWidget> && items);
+  void on_window_menu_closed();
   bool on_notes_widget_key_press(GdkEventKey*);
   void on_close_window(const Glib::VariantBase&);
   void add_action(const MainWindowAction::Ptr & action);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]