[gnote] Add concept of non-modifying actions



commit b8228627c843f655d8fedb368631fcb476d09507
Author: Aurimas Černius <aurisc4 gmail com>
Date:   Fri Jan 8 23:41:12 2016 +0200

    Add concept of non-modifying actions

 src/actionmanager.cpp    |   12 ++++++++++--
 src/actionmanager.hpp    |    7 +++++--
 src/addininfo.cpp        |    9 ++++++++-
 src/addininfo.hpp        |    7 ++++++-
 src/addinmanager.cpp     |    6 ++++--
 src/iactionmanager.hpp   |    6 ++++--
 src/mainwindowaction.cpp |    6 +++++-
 src/mainwindowaction.hpp |   12 +++++++++++-
 src/recentchanges.cpp    |   14 +++++++++-----
 9 files changed, 62 insertions(+), 17 deletions(-)
---
diff --git a/src/actionmanager.cpp b/src/actionmanager.cpp
index bd26d2a..c5f1565 100644
--- a/src/actionmanager.cpp
+++ b/src/actionmanager.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2011-2015 Aurimas Cernius
+ * Copyright (C) 2011-2016 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -223,10 +223,13 @@ namespace gnote {
     return section;
   }
 
-  void ActionManager::register_main_window_action(const Glib::ustring & action, const Glib::VariantType 
*state_type)
+  void ActionManager::register_main_window_action(const Glib::ustring & action, const Glib::VariantType 
*state_type, bool modifying)
   {
     if(m_main_window_actions2.find(action) == m_main_window_actions2.end()) {
       m_main_window_actions2[action] = state_type;
+      if(!modifying) {
+        m_non_modifying_actions.push_back(action);
+      }
     }
     else {
       if(m_main_window_actions2[action] != state_type) {
@@ -240,6 +243,11 @@ namespace gnote {
     return m_main_window_actions2;
   }
 
+  bool ActionManager::is_modifying_main_window_action(const Glib::ustring & action) const
+  {
+    return std::find(m_non_modifying_actions.begin(), m_non_modifying_actions.end(), action) == 
m_non_modifying_actions.end();
+  }
+
   void ActionManager::register_main_window_search_callback(const std::string & id, const Glib::ustring & 
action,
                                                     sigc::slot<void, const Glib::VariantBase&> callback)
   {
diff --git a/src/actionmanager.hpp b/src/actionmanager.hpp
index cfcffdf..5a39b61 100644
--- a/src/actionmanager.hpp
+++ b/src/actionmanager.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2012-2013,2015 Aurimas Cernius
+ * Copyright (C) 2012-2013,2015-2016 Aurimas Cernius
  * Copyright (C) 2009 Hubert Figuiere
  *
  * This program is free software: you can redistribute it and/or modify
@@ -57,8 +57,10 @@ 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 Glib::ustring & action, const Glib::VariantType 
*state_type) override;
+  virtual void register_main_window_action(const Glib::ustring & action, const Glib::VariantType *state_type,
+    bool modifying = true) override;
   virtual std::map<Glib::ustring, const Glib::VariantType*> get_main_window_actions() const override;
+  virtual bool is_modifying_main_window_action(const Glib::ustring & action) const override;
 
   virtual void register_main_window_search_callback(const std::string & id, const Glib::ustring & action,
                                                     sigc::slot<void, const Glib::VariantBase&> callback) 
override;
@@ -96,6 +98,7 @@ private:
   typedef std::multimap<int, AppMenuItem> AppMenuItemMultiMap;
   AppMenuItemMultiMap m_app_menu_items;
   std::map<Glib::ustring, const Glib::VariantType*> m_main_window_actions2;
+  std::vector<Glib::ustring> m_non_modifying_actions;
   std::map<std::string, std::pair<Glib::ustring, sigc::slot<void, const Glib::VariantBase&>>> 
m_main_window_search_actions;
 };
 
diff --git a/src/addininfo.cpp b/src/addininfo.cpp
index 59c2844..f419199 100644
--- a/src/addininfo.cpp
+++ b/src/addininfo.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2013-2015 Aurimas Cernius
+ * Copyright (C) 2013-2016 Aurimas Cernius
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -105,6 +105,13 @@ void AddinInfo::load_from_file(const std::string & info_file)
       load_actions(addin_info, "actions_bool", &Glib::Variant<bool>::variant_type());
       load_actions(addin_info, "actions_int", &Glib::Variant<gint32>::variant_type());
       load_actions(addin_info, "actions_string", &Glib::Variant<Glib::ustring>::variant_type());
+      if(addin_info.has_key(ADDIN_ACTIONS, "non_modifying_actions")) {
+        std::vector<std::string> actions;
+        sharp::string_split(actions, addin_info.get_string(ADDIN_ACTIONS, "non_modifying_actions"), ",");
+        for(auto action : actions) {
+          m_non_modifying_actions.push_back(action);
+        }
+      }
     }
   }
   catch(Glib::Error & e) {
diff --git a/src/addininfo.hpp b/src/addininfo.hpp
index 958235a..30935e5 100644
--- a/src/addininfo.hpp
+++ b/src/addininfo.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2013-2015 Aurimas Cernius
+ * Copyright (C) 2013-2016 Aurimas Cernius
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -93,6 +93,10 @@ public:
     {
       return m_actions;
     }
+  const std::vector<Glib::ustring> & non_modifying_actions() const
+    {
+      return m_non_modifying_actions;
+    }
   Glib::ustring get_attribute(const Glib::ustring & att);
   bool validate(const Glib::ustring & release, const Glib::ustring & version_info) const;
 private:
@@ -110,6 +114,7 @@ private:
 
   std::map<Glib::ustring, Glib::ustring> m_attributes;
   std::map<Glib::ustring, const Glib::VariantType*> m_actions;
+  std::vector<Glib::ustring> m_non_modifying_actions;
 
   bool validate_compatibility(const Glib::ustring & release, const Glib::ustring & version_info) const;
   void load_actions(Glib::KeyFile & addin_info, const Glib::ustring & key, const Glib::VariantType *type);
diff --git a/src/addinmanager.cpp b/src/addinmanager.cpp
index 129ee99..2ec5f9b 100644
--- a/src/addinmanager.cpp
+++ b/src/addinmanager.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010-2015 Aurimas Cernius
+ * Copyright (C) 2010-2016 Aurimas Cernius
  * Copyright (C) 2009, 2010 Debarshi Ray
  * Copyright (C) 2009 Hubert Figuiere
  *
@@ -583,8 +583,10 @@ namespace {
   {
     auto & manager(IActionManager::obj());
     for(auto & info : m_addin_infos) {
+      auto & non_modifying = info.second.non_modifying_actions();
       for(auto & action : info.second.actions()) {
-        manager.register_main_window_action(action.first, action.second);
+        manager.register_main_window_action(action.first, action.second,
+          std::find(non_modifying.begin(), non_modifying.end(), action.first) == non_modifying.end());
       }
     }
   }
diff --git a/src/iactionmanager.hpp b/src/iactionmanager.hpp
index dff9f5a..6504d6b 100644
--- a/src/iactionmanager.hpp
+++ b/src/iactionmanager.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2013,2015 Aurimas Cernius
+ * Copyright (C) 2013,2015-2016 Aurimas Cernius
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -58,8 +58,10 @@ 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, const Glib::VariantType 
*state_type) = 0;
+  virtual void register_main_window_action(const Glib::ustring & action, const Glib::VariantType *state_type,
+    bool modifying = true) = 0;
   virtual std::map<Glib::ustring, const Glib::VariantType*> get_main_window_actions() const = 0;
+  virtual bool is_modifying_main_window_action(const Glib::ustring & action) const = 0;
 
   virtual void register_main_window_search_callback(const std::string & id, const Glib::ustring & action,
                                                     sigc::slot<void, const Glib::VariantBase&> callback) = 0;
diff --git a/src/mainwindowaction.cpp b/src/mainwindowaction.cpp
index cdec6f8..a395a0b 100644
--- a/src/mainwindowaction.cpp
+++ b/src/mainwindowaction.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2015 Aurimas Cernius
+ * Copyright (C) 2015-2016 Aurimas Cernius
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -43,21 +43,25 @@ MainWindowAction::Ptr MainWindowAction::create(const Glib::ustring & name, const
 
 MainWindowAction::MainWindowAction(const Glib::ustring & name)
   : Gio::SimpleAction(name)
+  , m_modifying(true)
 {
 }
 
 MainWindowAction::MainWindowAction(const Glib::ustring & name, bool state)
   : Gio::SimpleAction(name, Glib::Variant<bool>::create(state))
+  , m_modifying(true)
 {
 }
 
 MainWindowAction::MainWindowAction(const Glib::ustring & name, int state)
   : Gio::SimpleAction(name, Glib::VARIANT_TYPE_INT32, Glib::Variant<gint32>::create(state))
+  , m_modifying(true)
 {
 }
 
 MainWindowAction::MainWindowAction(const Glib::ustring & name, const Glib::ustring & state)
   : Gio::SimpleAction(name, Glib::VARIANT_TYPE_STRING, Glib::Variant<Glib::ustring>::create(state))
+  , m_modifying(true)
 {
 }
 
diff --git a/src/mainwindowaction.hpp b/src/mainwindowaction.hpp
index bdb7f10..7a89724 100644
--- a/src/mainwindowaction.hpp
+++ b/src/mainwindowaction.hpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2015 Aurimas Cernius
+ * Copyright (C) 2015-2016 Aurimas Cernius
  *
  * This program is free software: you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -42,11 +42,21 @@ public:
     {
       Gio::SimpleAction::set_state(value);
     }
+  void is_modifying(bool modifying)
+    {
+      m_modifying = modifying;
+    }
+  bool is_modifying() const
+    {
+      return m_modifying;
+    }
 protected:
   MainWindowAction(const Glib::ustring & name);
   MainWindowAction(const Glib::ustring & name, bool state);
   MainWindowAction(const Glib::ustring & name, int state);
   MainWindowAction(const Glib::ustring & name, const Glib::ustring & state);
+private:
+  bool m_modifying;
 };
 
 }
diff --git a/src/recentchanges.cpp b/src/recentchanges.cpp
index 2b1a512..87ac2c9 100644
--- a/src/recentchanges.cpp
+++ b/src/recentchanges.cpp
@@ -1,7 +1,7 @@
 /*
  * gnote
  *
- * Copyright (C) 2010-2015 Aurimas Cernius
+ * Copyright (C) 2010-2016 Aurimas Cernius
  * Copyright (C) 2010 Debarshi Ray
  * Copyright (C) 2009 Hubert Figuiere
  *
@@ -103,17 +103,21 @@ namespace gnote {
     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) {
+      MainWindowAction::Ptr action;
       if(iter->second == NULL) {
-        add_action(MainWindowAction::create(iter->first));
+        add_action(action = MainWindowAction::create(iter->first));
       }
       else if(iter->second == &Glib::Variant<bool>::variant_type()) {
-        add_action(MainWindowAction::create(iter->first, false));
+        add_action(action = MainWindowAction::create(iter->first, false));
       }
       else if(iter->second == &Glib::Variant<gint32>::variant_type()) {
-        add_action(MainWindowAction::create(iter->first, 0));
+        add_action(action = MainWindowAction::create(iter->first, 0));
       }
       else if(iter->second == &Glib::Variant<Glib::ustring>::variant_type()) {
-        add_action(MainWindowAction::create(iter->first, Glib::ustring("")));
+        add_action(action = MainWindowAction::create(iter->first, Glib::ustring("")));
+      }
+      if(action) {
+        action->is_modifying(IActionManager::obj().is_modifying_main_window_action(iter->first));
       }
     }
     find_action("close-window")->signal_activate()


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