[glibmm] Gio: SimpleAction, ActionMap: Reorder some parameters



commit 9172df2fd393fae9eef3ca15000640684312c239
Author: Murray Cumming <murrayc murrayc com>
Date:   Tue Jul 30 21:17:43 2013 +0200

    Gio: SimpleAction, ActionMap: Reorder some parameters
    
    Put the initial state at the end so we can have a default value
    where that would make sense.

 gio/src/actionmap.ccg    |   18 +++++++++---------
 gio/src/actionmap.hg     |   24 +++++++++++++++++-------
 gio/src/simpleaction.ccg |    9 +++++----
 gio/src/simpleaction.hg  |    9 ++++++---
 4 files changed, 37 insertions(+), 23 deletions(-)
---
diff --git a/gio/src/actionmap.ccg b/gio/src/actionmap.ccg
index c05b009..38a4ccf 100644
--- a/gio/src/actionmap.ccg
+++ b/gio/src/actionmap.ccg
@@ -44,37 +44,37 @@ Glib::RefPtr<SimpleAction> ActionMap::add_action_bool(const Glib::ustring& name,
   return action;
 }
 
-Glib::RefPtr<SimpleAction> ActionMap::add_action_bool(const Glib::ustring& name,  bool state, const 
ActivateSlot& slot)
+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);
   return action;
 }
 
-Glib::RefPtr<SimpleAction> ActionMap::add_action_radio_string(const Glib::ustring& name)
+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);
+  Glib::RefPtr<SimpleAction> action = SimpleAction::create_radio_string(name, state);
   add_action(action);
   return action;
 }
 
-Glib::RefPtr<SimpleAction> ActionMap::add_action_radio_string(const Glib::ustring& name, const ActivateSlot& 
slot)
+Glib::RefPtr<SimpleAction> ActionMap::add_action_radio_string(const Glib::ustring& name, const ActivateSlot& 
slot, const Glib::ustring& state)
 {
-  Glib::RefPtr<SimpleAction> action = add_action_radio_string(name);
+  Glib::RefPtr<SimpleAction> action = add_action_radio_string(name, state);
   action->signal_activate().connect(slot);
   return action;
 }
 
-Glib::RefPtr<SimpleAction> ActionMap::add_action_radio_integer(const Glib::ustring& name)
+Glib::RefPtr<SimpleAction> ActionMap::add_action_radio_integer(const Glib::ustring& name, gint32 state)
 {
-  Glib::RefPtr<SimpleAction> action = SimpleAction::create_radio_integer(name);
+  Glib::RefPtr<SimpleAction> action = SimpleAction::create_radio_integer(name, state);
   add_action(action);
   return action;
 }
 
-Glib::RefPtr<SimpleAction> ActionMap::add_action_radio_integer(const Glib::ustring& name, const 
ActivateSlot& slot)
+Glib::RefPtr<SimpleAction> ActionMap::add_action_radio_integer(const Glib::ustring& name, const 
ActivateSlot& slot, gint32 state)
 {
-  Glib::RefPtr<SimpleAction> action = add_action_radio_integer(name);
+  Glib::RefPtr<SimpleAction> action = add_action_radio_integer(name, state);
   action->signal_activate().connect(slot);
   return action;
 }
diff --git a/gio/src/actionmap.hg b/gio/src/actionmap.hg
index 54926dc..294d974 100644
--- a/gio/src/actionmap.hg
+++ b/gio/src/actionmap.hg
@@ -88,53 +88,63 @@ public:
    * 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.
+   * @param state The initial state.
    * @return The Action.
    */
-  Glib::RefPtr<SimpleAction> add_action_bool(const Glib::ustring& name, bool state);
+  Glib::RefPtr<SimpleAction> add_action_bool(const Glib::ustring& name, bool state = false);
 
+//TODO: Docs: Refer to this as a toggle action?
   /** A convenience method for creating a boolean-stateful 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.
+   * @param state The initial state.
    * @return The Action.
    */
-  Glib::RefPtr<SimpleAction> add_action_bool(const Glib::ustring& name, bool state, const ActivateSlot& 
slot);
+  Glib::RefPtr<SimpleAction> add_action_bool(const Glib::ustring& name, const ActivateSlot& slot, bool state 
= false);
 
+//TODO: Docs: Add hints about how to specify the various possible states in the GtkBuilder XML.
   /** A convenience method for creating a string-based radio SimpleAction instance
    * and adding it to the ActionMap.
    *
    * @param name The name of the Action.
+   * @param state The initial state.
    * @return The Action.
    */
-  Glib::RefPtr<SimpleAction> add_action_radio_string(const Glib::ustring& name);
+  Glib::RefPtr<SimpleAction> add_action_radio_string(const Glib::ustring& name, 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 a string-based radio 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.
+   * @param state The initial state.
    * @return The Action.
    */
-  Glib::RefPtr<SimpleAction> add_action_radio_string(const Glib::ustring& name, const ActivateSlot& slot);
+  Glib::RefPtr<SimpleAction> add_action_radio_string(const Glib::ustring& name, const ActivateSlot& 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
    * and adding it to the ActionMap.
    *
    * @param name The name of the Action.
+   * @param state The initial state.
    * @return The Action.
    */
-  Glib::RefPtr<SimpleAction> add_action_radio_integer(const Glib::ustring& name);
+  Glib::RefPtr<SimpleAction> add_action_radio_integer(const Glib::ustring& name, gint32 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
    * 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.
+   * @param state The initial state.
    * @return The Action.
    */
-  Glib::RefPtr<SimpleAction> add_action_radio_integer(const Glib::ustring& name, const ActivateSlot& slot);
+  Glib::RefPtr<SimpleAction> add_action_radio_integer(const Glib::ustring& name, const ActivateSlot& slot, 
gint32 state);
 
 
   _WRAP_METHOD(void add_action(const Glib::RefPtr<Action>& action), g_action_map_add_action)
diff --git a/gio/src/simpleaction.ccg b/gio/src/simpleaction.ccg
index ae90453..2b91ecf 100644
--- a/gio/src/simpleaction.ccg
+++ b/gio/src/simpleaction.ccg
@@ -34,20 +34,21 @@ SimpleAction::SimpleAction(const Glib::ustring& name, const Glib::VariantBase& s
 
 Glib::RefPtr<SimpleAction> SimpleAction::create_bool(const Glib::ustring& name, bool state)
 {
+  //We must provide some initial state, as a way to specify the type of the state.
   return create(name, Glib::Variant<bool>::create(state));
 }
 
 
-Glib::RefPtr<SimpleAction> SimpleAction::create_radio_string(const Glib::ustring& name)
+Glib::RefPtr<SimpleAction> SimpleAction::create_radio_string(const Glib::ustring& name, const Glib::ustring& 
initial_state)
 {
   //See https://developer.gnome.org/glib/stable/gvariant-format-strings.html#gvariant-format-strings-strings
-  return create(name, Glib::VariantType("s"));
+  return create(name, Glib::VARIANT_TYPE_STRING, Glib::Variant<Glib::ustring>::create(initial_state));
 }
 
-Glib::RefPtr<SimpleAction> SimpleAction::create_radio_integer(const Glib::ustring& name)
+Glib::RefPtr<SimpleAction> SimpleAction::create_radio_integer(const Glib::ustring& name, gint32 
initial_state)
 {
   //See 
https://developer.gnome.org/glib/stable/gvariant-format-strings.html#gvariant-format-strings-numeric-types
-  return create(name, Glib::VariantType("i"));
+  return create(name, Glib::VARIANT_TYPE_INT32, Glib::Variant<gint32>::create(initial_state));
 }
 
 } // namespace Gio
diff --git a/gio/src/simpleaction.hg b/gio/src/simpleaction.hg
index 744d8dd..3746d86 100644
--- a/gio/src/simpleaction.hg
+++ b/gio/src/simpleaction.hg
@@ -63,9 +63,11 @@ public:
   _WRAP_METHOD_DOCS_ONLY(g_simple_action_new)
   _WRAP_CREATE(const Glib::ustring& name, const Glib::VariantType& parameter_type)
 
+  //TODO: Add a templated version of this to avoid the need fo Gio::Variant by the caller.
   _WRAP_METHOD_DOCS_ONLY(g_simple_action_new_stateful)
   _WRAP_CREATE(const Glib::ustring& name, const Glib::VariantType& parameter_type, const Glib::VariantBase& 
state)
 
+  //TODO: Add a templated version of this to avoid the need fo Gio::Variant by the caller.
   /** Creates a new stateful action.
    * 
    * @a state is the initial state of the action.  All future state values
@@ -80,6 +82,7 @@ public:
 
   //TODO: Use similar C API if they ever add it. Doing this manually is tedious.
   //TODO: Create a derived SimpleToggleAction class for this?
+  //TODO: Document how the app must handle signal_activate() to call change_state().
   /** Creates a new boolean stateful action.
    * 
    * @a state is the initial state of the action.  All future state values
@@ -90,7 +93,7 @@ public:
    * @param state The initial state of the action.
    * @return A new SimpleAction.
    */
-  static Glib::RefPtr<SimpleAction> create_bool(const Glib::ustring&name, bool state);
+  static Glib::RefPtr<SimpleAction> create_bool(const Glib::ustring&name, bool state = false);
 
   //TODO: Use similar C API if they ever add it. Doing this manually is tedious.
   //TODO: Create a derived SimpleToggleAction class for this?
@@ -101,7 +104,7 @@ public:
    * @param name The name of the action.
    * @return A new SimpleAction.
    */
-  static Glib::RefPtr<SimpleAction> create_radio_string(const Glib::ustring& name);
+  static Glib::RefPtr<SimpleAction> create_radio_string(const Glib::ustring& name, const Glib::ustring& 
initial_state);
 
   //TODO: Use similar C API if they ever add it. Doing this manually is tedious.
   //TODO: Create a derived SimpleToggleAction class for this?
@@ -112,7 +115,7 @@ public:
    * @param name The name of the action.
    * @return A new SimpleAction.
    */
-  static Glib::RefPtr<SimpleAction> create_radio_integer(const Glib::ustring& name);
+  static Glib::RefPtr<SimpleAction> create_radio_integer(const Glib::ustring& name, gint32 inital_state);
 
   _WRAP_METHOD(void set_enabled(bool enabled = true), g_simple_action_set_enabled)
   _WRAP_METHOD(void set_state(const Glib::VariantBase& value), g_simple_action_set_state)


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