[gnote/tabbed: 18/19] Handle main window actions in recent changes itself




commit a6ecfdbf330194dd8d08341c9b62f97a9b1d8937
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Tue Nov 2 14:15:17 2021 +0200

    Handle main window actions in recent changes itself

 src/recentchanges.cpp | 31 +++++++++++++++++++++++++++++++
 src/recentchanges.hpp |  4 ++++
 2 files changed, 35 insertions(+)
---
diff --git a/src/recentchanges.cpp b/src/recentchanges.cpp
index 94f91a5f..30aa1584 100644
--- a/src/recentchanges.cpp
+++ b/src/recentchanges.cpp
@@ -203,6 +203,37 @@ namespace gnote {
     }
     find_action("close-window")->signal_activate()
       .connect(sigc::mem_fun(*this, &NoteRecentChanges::on_close_window));
+    am.signal_main_window_search_actions_changed
+      .connect(sigc::mem_fun(*this, &NoteRecentChanges::callbacks_changed));
+
+    register_callbacks();
+  }
+
+  void NoteRecentChanges::callbacks_changed()
+  {
+    unregister_callbacks();
+    register_callbacks();
+    m_window_menu_default = nullptr;
+  }
+
+  void NoteRecentChanges::register_callbacks()
+  {
+    auto & manager(m_gnote.action_manager());
+    auto cbacks = manager.get_main_window_search_callbacks();
+    for(auto & cback : cbacks) {
+      auto action = find_action(cback.first);
+      if(action) {
+        m_action_cids.push_back(action->signal_activate().connect(cback.second));
+      }
+    }
+  }
+
+  void NoteRecentChanges::unregister_callbacks()
+  {
+    for(auto & cid : m_action_cids) {
+      cid.disconnect();
+    }
+    m_action_cids.clear();
   }
 
   void NoteRecentChanges::make_header_bar()
diff --git a/src/recentchanges.hpp b/src/recentchanges.hpp
index 8f1daf10..a2eacfc6 100644
--- a/src/recentchanges.hpp
+++ b/src/recentchanges.hpp
@@ -102,6 +102,9 @@ private:
   void on_popover_widgets_changed();
   bool present_active(const Note::Ptr & note);
   void register_actions();
+  void callbacks_changed();
+  void register_callbacks();
+  void unregister_callbacks();
 
   IGnote             &m_gnote;
   NoteManagerBase    &m_note_manager;
@@ -128,6 +131,7 @@ private:
   Glib::RefPtr<Gtk::AccelGroup> m_accel_group;
   utils::GlobalKeybinder m_keybinder;
   std::map<Glib::ustring, MainWindowAction::Ptr> m_actions;
+  std::vector<sigc::connection> m_action_cids;
 };
 
 


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