[gnote] Make window actions per window



commit 36182fd77e84ea4b9702f86bf8ac7679462ee5bf
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Sun Dec 6 20:27:38 2015 +0200

    Make window actions per window

 src/actionmanager.cpp  |   32 +++++++-------------------------
 src/actionmanager.hpp  |    8 +++-----
 src/iactionmanager.hpp |    6 ++----
 src/recentchanges.cpp  |   25 +++++++++++++++++++++----
 src/recentchanges.hpp  |    3 +++
 5 files changed, 36 insertions(+), 38 deletions(-)
---
diff --git a/src/actionmanager.cpp b/src/actionmanager.cpp
index 6f33599..98e6dfc 100644
--- a/src/actionmanager.cpp
+++ b/src/actionmanager.cpp
@@ -73,9 +73,9 @@ namespace gnote {
     make_app_actions();
     make_app_menu_items();
 
-    register_main_window_action("close-window");
-    register_main_window_action("delete-note");
-    register_main_window_action(MainWindowAction::create("important-note", false));
+    register_main_window_action("close-window", NULL);
+    register_main_window_action("delete-note", NULL);
+    register_main_window_action("important-note", &Glib::Variant<bool>::variant_type());
   }
 
 
@@ -220,34 +220,16 @@ namespace gnote {
     return section;
   }
 
-  void ActionManager::register_main_window_action(const MainWindowAction::Ptr & action)
+  void ActionManager::register_main_window_action(const Glib::ustring & action, const Glib::VariantType 
*state_type)
   {
-    if(find_main_window_action(action->get_name()) == 0) {
-      m_main_window_actions2.push_back(action);
+    if(m_main_window_actions2.find(action) == m_main_window_actions2.end()) {
+      m_main_window_actions2[action] = state_type;
     }
   }
 
-  void ActionManager::register_main_window_action(const Glib::ustring & action)
-  {
-    if(find_main_window_action(action) == 0) {
-      m_main_window_actions2.push_back(MainWindowAction::create(action));
-    }
-  }
-
-  std::vector<MainWindowAction::Ptr> ActionManager::get_main_window_actions() const
+  std::map<Glib::ustring, const Glib::VariantType*> ActionManager::get_main_window_actions() const
   {
     return m_main_window_actions2;
   }
 
-  MainWindowAction::Ptr ActionManager::find_main_window_action(const Glib::ustring & name) const
-  {
-    FOREACH(MainWindowAction::Ptr a, m_main_window_actions2) {
-      if(a->get_name() == name) {
-        return a;
-      }
-    }
-
-    return MainWindowAction::Ptr();
-  }
-
 }
diff --git a/src/actionmanager.hpp b/src/actionmanager.hpp
index 451cfa9..0caab13 100644
--- a/src/actionmanager.hpp
+++ b/src/actionmanager.hpp
@@ -57,10 +57,8 @@ public:
   virtual void add_app_menu_item(int section, int order, const std::string & label,
                                  const std::string & action_def) override;
   Glib::RefPtr<Gio::Menu> get_app_menu() const;
-  virtual void register_main_window_action(const MainWindowAction::Ptr & action);
-  virtual void register_main_window_action(const Glib::ustring & action) override;
-  virtual std::vector<MainWindowAction::Ptr> get_main_window_actions() const override;
-  virtual MainWindowAction::Ptr find_main_window_action(const Glib::ustring & name) const override;
+  virtual void register_main_window_action(const Glib::ustring & action, const Glib::VariantType 
*state_type) override;
+  virtual std::map<Glib::ustring, const Glib::VariantType*> get_main_window_actions() const override;
 private:
   void make_app_actions();
   void make_app_menu_items();
@@ -92,7 +90,7 @@ private:
   };
   typedef std::multimap<int, AppMenuItem> AppMenuItemMultiMap;
   AppMenuItemMultiMap m_app_menu_items;
-  std::vector<MainWindowAction::Ptr> m_main_window_actions2;
+  std::map<Glib::ustring, const Glib::VariantType*> m_main_window_actions2;
 };
 
 
diff --git a/src/iactionmanager.hpp b/src/iactionmanager.hpp
index 3017778..2c9575b 100644
--- a/src/iactionmanager.hpp
+++ b/src/iactionmanager.hpp
@@ -26,7 +26,6 @@
 #include <gtkmm/uimanager.h>
 
 #include "base/singleton.hpp"
-#include "mainwindowaction.hpp"
 
 namespace gnote {
 
@@ -58,9 +57,8 @@ public:
   virtual Glib::RefPtr<Gio::SimpleAction> add_app_action(const std::string & name) = 0;
   virtual void add_app_menu_item(int section, int order, const std::string & label,
                                  const std::string & action_def) = 0;
-  virtual void register_main_window_action(const Glib::ustring & action) = 0;
-  virtual std::vector<MainWindowAction::Ptr> get_main_window_actions() const = 0;
-  virtual MainWindowAction::Ptr find_main_window_action(const Glib::ustring & name) const = 0;
+  virtual void register_main_window_action(const Glib::ustring & action, const Glib::VariantType 
*state_type) = 0;
+  virtual std::map<Glib::ustring, const Glib::VariantType*> get_main_window_actions() const = 0;
 };
 
 }
diff --git a/src/recentchanges.cpp b/src/recentchanges.cpp
index 7461267..9391658 100644
--- a/src/recentchanges.cpp
+++ b/src/recentchanges.cpp
@@ -100,10 +100,17 @@ namespace gnote {
     m_keybinder.add_accelerator(sigc::mem_fun(*this, &NoteRecentChanges::close_window),
                                 GDK_KEY_Q, Gdk::CONTROL_MASK, (Gtk::AccelFlags)0);
 
-    FOREACH(MainWindowAction::Ptr action, IActionManager::obj().get_main_window_actions()) {
-      add_action(action);
+    std::map<Glib::ustring, const Glib::VariantType*> actions = 
IActionManager::obj().get_main_window_actions();
+    for(std::map<Glib::ustring, const Glib::VariantType*>::iterator iter = actions.begin();
+        iter != actions.end(); ++iter) {
+      if(iter->second == NULL) {
+        add_action(MainWindowAction::create(iter->first));
+      }
+      else if(iter->second == &Glib::Variant<bool>::variant_type()) {
+        add_action(MainWindowAction::create(iter->first, false));
+      }
     }
-    IActionManager::obj().find_main_window_action("close-window")->signal_activate()
+    find_action("close-window")->signal_activate()
       .connect(sigc::mem_fun(*this, &NoteRecentChanges::on_close_window));
 
     m_window_menu_default = make_window_menu(m_window_actions_button, std::vector<Gtk::Widget*>());
@@ -586,9 +593,19 @@ namespace gnote {
     return false;
   }
 
+  void NoteRecentChanges::add_action(const MainWindowAction::Ptr & action)
+  {
+    m_actions[action->get_name()] = action;
+    MainWindow::add_action(action);
+  }
+
   MainWindowAction::Ptr NoteRecentChanges::find_action(const Glib::ustring & name)
   {
-    return IActionManager::obj().find_main_window_action(name);
+    std::map<Glib::ustring, MainWindowAction::Ptr>::iterator iter = m_actions.find(name);
+    if(iter != m_actions.end()) {
+      return iter->second;
+    }
+    return MainWindowAction::Ptr();
   }
 
   EmbeddableWidget *NoteRecentChanges::currently_embedded()
diff --git a/src/recentchanges.hpp b/src/recentchanges.hpp
index e39aa52..659473f 100644
--- a/src/recentchanges.hpp
+++ b/src/recentchanges.hpp
@@ -32,6 +32,7 @@
 #include <gtkmm/grid.h>
 
 #include "base/macros.hpp"
+#include "mainwindowaction.hpp"
 #include "note.hpp"
 #include "searchnoteswidget.hpp"
 #include "utils.hpp"
@@ -91,6 +92,7 @@ private:
   void on_settings_changed(const Glib::ustring & key);
   bool on_notes_widget_key_press(GdkEventKey*);
   void on_close_window(const Glib::VariantBase&);
+  void add_action(const MainWindowAction::Ptr & action);
 
   NoteManager        &m_note_manager;
   Gtk::Widget        *m_header_bar;
@@ -114,6 +116,7 @@ private:
   utils::GlobalKeybinder m_keybinder;
   bool                m_open_notes_in_new_window;
   bool                m_close_note_on_escape;
+  std::map<Glib::ustring, MainWindowAction::Ptr> m_actions;
 };
 
 


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