[glibmm] Gio::SimpleAction: add_action() now takes a slot with no parameter.



commit 76221ac3195ca4d654b3515dcf40a0fa4477de47
Author: Murray Cumming <murrayc murrayc com>
Date:   Wed Aug 7 10:40:42 2013 +0200

    Gio::SimpleAction: add_action() now takes a slot with no parameter.
    
    * gio/src/actionmap.[hg|ccg]: Change ActionSlot to take no parameter,
      hiding it via sigc::hide(), because in most cases the parameter
      is useless and annoying.
      Add add_action_with_parameter() which takes a slot with the
      parameter. We cannot just have an add_action() method overload
      because the compiler considers that ambiguous.

 gio/src/actionmap.ccg |   21 +++++++++++++++++----
 gio/src/actionmap.hg  |   29 ++++++++++++++++++++++++-----
 2 files changed, 41 insertions(+), 9 deletions(-)
---
diff --git a/gio/src/actionmap.ccg b/gio/src/actionmap.ccg
index 38a4ccf..306cf3d 100644
--- a/gio/src/actionmap.ccg
+++ b/gio/src/actionmap.ccg
@@ -30,13 +30,22 @@ Glib::RefPtr<SimpleAction> ActionMap::add_action(const Glib::ustring& name)
   return action;
 }
 
-Glib::RefPtr<SimpleAction> ActionMap::add_action(const Glib::ustring& name, const ActivateSlot& slot)
+Glib::RefPtr<SimpleAction> ActionMap::add_action_with_parameter(const Glib::ustring& name, const 
ActivateWithParameterSlot& slot)
 {
   Glib::RefPtr<SimpleAction> action = add_action(name);
   action->signal_activate().connect(slot);
   return action;
 }
 
+Glib::RefPtr<SimpleAction> ActionMap::add_action(const Glib::ustring& name, const ActivateSlot& slot)
+{
+  Glib::RefPtr<SimpleAction> action = add_action(name);
+  action->signal_activate().connect(
+    sigc::hide(slot));
+  return action;
+}
+
+
 Glib::RefPtr<SimpleAction> ActionMap::add_action_bool(const Glib::ustring& name, bool state)
 {
   Glib::RefPtr<SimpleAction> action = SimpleAction::create_bool(name, state);
@@ -44,13 +53,16 @@ Glib::RefPtr<SimpleAction> ActionMap::add_action_bool(const Glib::ustring& name,
   return action;
 }
 
+//TODO: Use a slot that takes a bool?
 Glib::RefPtr<SimpleAction> ActionMap::add_action_bool(const Glib::ustring& name, const ActivateSlot& slot, 
bool state)
 {
   Glib::RefPtr<SimpleAction> action = add_action_bool(name, state);
-  action->signal_activate().connect(slot);
+  action->signal_activate().connect(
+    sigc::hide(slot));
   return action;
 }
 
+//TODO: Use a slot that takes a string?
 Glib::RefPtr<SimpleAction> ActionMap::add_action_radio_string(const Glib::ustring& name, const 
Glib::ustring& state)
 {
   Glib::RefPtr<SimpleAction> action = SimpleAction::create_radio_string(name, state);
@@ -58,13 +70,14 @@ Glib::RefPtr<SimpleAction> ActionMap::add_action_radio_string(const Glib::ustrin
   return action;
 }
 
-Glib::RefPtr<SimpleAction> ActionMap::add_action_radio_string(const Glib::ustring& name, const ActivateSlot& 
slot, const Glib::ustring& state)
+Glib::RefPtr<SimpleAction> ActionMap::add_action_radio_string(const Glib::ustring& name, const 
ActivateWithParameterSlot& slot, const Glib::ustring& state)
 {
   Glib::RefPtr<SimpleAction> action = add_action_radio_string(name, state);
   action->signal_activate().connect(slot);
   return action;
 }
 
+//TODO: Use a slot that takes an integer?
 Glib::RefPtr<SimpleAction> ActionMap::add_action_radio_integer(const Glib::ustring& name, gint32 state)
 {
   Glib::RefPtr<SimpleAction> action = SimpleAction::create_radio_integer(name, state);
@@ -72,7 +85,7 @@ Glib::RefPtr<SimpleAction> ActionMap::add_action_radio_integer(const Glib::ustri
   return action;
 }
 
-Glib::RefPtr<SimpleAction> ActionMap::add_action_radio_integer(const Glib::ustring& name, const 
ActivateSlot& slot, gint32 state)
+Glib::RefPtr<SimpleAction> ActionMap::add_action_radio_integer(const Glib::ustring& name, const 
ActivateWithParameterSlot& slot, gint32 state)
 {
   Glib::RefPtr<SimpleAction> action = add_action_radio_integer(name, state);
   action->signal_activate().connect(slot);
diff --git a/gio/src/actionmap.hg b/gio/src/actionmap.hg
index 294d974..fd58f7d 100644
--- a/gio/src/actionmap.hg
+++ b/gio/src/actionmap.hg
@@ -56,12 +56,12 @@ public:
   _WRAP_METHOD(Glib::RefPtr<const Action> lookup_action(const Glib::ustring& action_name) const, 
g_action_map_lookup_action, constversion)
 
   /** A Slot to be called when an action has been activated.
-   * See add_action().
+   * See add_action_with_parameter().
    *
    * For instance,
    * void on_slot_activated(const Glib::VariantBase& parameter);
    */
-  typedef sigc::slot< void,const Glib::VariantBase& > ActivateSlot;
+  typedef sigc::slot< void, const Glib::VariantBase& > ActivateWithParameterSlot;
 
   //This is an equivalent for g_action_map_add_action_entries().
   /** A convenience method for creating a SimpleAction instance
@@ -81,9 +81,28 @@ public:
    * @param slot The callback method to be called when the action is activated.
    * @return The Action.
    */
-  Glib::RefPtr<SimpleAction> add_action(const Glib::ustring& name, const ActivateSlot& slot);
+  Glib::RefPtr<SimpleAction> add_action_with_parameter(const Glib::ustring& name, const 
ActivateWithParameterSlot& slot);
   _IGNORE(g_action_map_add_action_entries)
 
+  /** A Slot to be called when an action has been activated,
+   * without passing a parameter to the slot.
+   * See add_action().
+   *
+   * For instance,
+   * void on_slot_activated();
+   */
+  typedef sigc::slot<void> ActivateSlot;
+
+  /** A convenience method for creating a SimpleAction instance
+   * and adding it to the ActionMap.
+   *
+   * @param name The name of the Action.
+   * @param slot The callback method to be called when the action is activated.
+   * @return The Action.
+   */
+  Glib::RefPtr<SimpleAction> add_action(const Glib::ustring& name, const ActivateSlot& slot);
+
+
   /** A convenience method for creating a boolean-stateful SimpleAction instance
    * and adding it to the ActionMap.
    *
@@ -123,7 +142,7 @@ public:
    * @param state The initial state.
    * @return The Action.
    */
-  Glib::RefPtr<SimpleAction> add_action_radio_string(const Glib::ustring& name, const ActivateSlot& slot, 
const Glib::ustring& state);
+  Glib::RefPtr<SimpleAction> add_action_radio_string(const Glib::ustring& name, const 
ActivateWithParameterSlot& slot, const Glib::ustring& state);
 
 //TODO: Docs: Add hints about how to specify the various possible states in the GtkBuilder XML.
   /** A convenience method for creating an integer-based radio SimpleAction instance
@@ -144,7 +163,7 @@ public:
    * @param state The initial state.
    * @return The Action.
    */
-  Glib::RefPtr<SimpleAction> add_action_radio_integer(const Glib::ustring& name, const ActivateSlot& slot, 
gint32 state);
+  Glib::RefPtr<SimpleAction> add_action_radio_integer(const Glib::ustring& name, const 
ActivateWithParameterSlot& slot, gint32 state);
 
 
   _WRAP_METHOD(void add_action(const Glib::RefPtr<Action>& action), g_action_map_add_action)


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