[glibmm] Gio::ActionMap: add_action_radio_*(): Use better Slot types.
- From: Murray Cumming <murrayc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glibmm] Gio::ActionMap: add_action_radio_*(): Use better Slot types.
- Date: Wed, 7 Aug 2013 10:05:17 +0000 (UTC)
commit 1fa165f7584d45edf00653cd3d2561ccd215b3af
Author: Murray Cumming <murrayc murrayc com>
Date: Wed Aug 7 12:03:06 2013 +0200
Gio::ActionMap: add_action_radio_*(): Use better Slot types.
* gio/src/actionmap.[hg|ccg]: add_action_radio_string(): Take
a Slot that provides a string, rather than a VariantBase.
add_action_radio_int(): Take a Slot that provides an int, rather
than a VariantBase.
Hopefully passing a Slot via sigc::bind() is a good idea.
The various slot types would be less confusing if we moved
some of this to a derived class.
gio/src/actionmap.ccg | 39 +++++++++++++++++++++++++++++++++++----
gio/src/actionmap.hg | 21 +++++++++++++++++++--
2 files changed, 54 insertions(+), 6 deletions(-)
---
diff --git a/gio/src/actionmap.ccg b/gio/src/actionmap.ccg
index 306cf3d..432b65f 100644
--- a/gio/src/actionmap.ccg
+++ b/gio/src/actionmap.ccg
@@ -70,13 +70,43 @@ 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
ActivateWithParameterSlot& slot, const Glib::ustring& state)
+
+namespace {
+
+//Handle the normal activate signal, calling instead a slot that takes the specific type:
+static void on_action_radio_string(const Glib::VariantBase& parameter, const
Gio::ActionMap::ActivateWithStringParameterSlot& slot)
+{
+ //TODO: This syntax is odd:
+ const Glib::Variant<Glib::ustring> variantDerived =
+ parameter.cast_dynamic< Glib::Variant<Glib::ustring> >(parameter);
+ const Glib::ustring str = variantDerived.get();
+ slot(str);
+}
+
+} //anonymous namespace
+
+Glib::RefPtr<SimpleAction> ActionMap::add_action_radio_string(const Glib::ustring& name, const
ActivateWithStringParameterSlot& slot, const Glib::ustring& state)
{
Glib::RefPtr<SimpleAction> action = add_action_radio_string(name, state);
- action->signal_activate().connect(slot);
+ action->signal_activate().connect(
+ sigc::bind(sigc::ptr_fun(&on_action_radio_string), slot));
return action;
}
+namespace {
+
+//Handle the normal activate signal, calling instead a slot that takes the specific type:
+static void on_action_radio_int(const Glib::VariantBase& parameter, const
Gio::ActionMap::ActivateWithIntParameterSlot& slot)
+{
+ //TODO: This syntax is odd:
+ const Glib::Variant<int> variantDerived =
+ parameter.cast_dynamic< Glib::Variant<int> >(parameter);
+ const int str = variantDerived.get();
+ slot(str);
+}
+
+} //anonymous namespace
+
//TODO: Use a slot that takes an integer?
Glib::RefPtr<SimpleAction> ActionMap::add_action_radio_integer(const Glib::ustring& name, gint32 state)
{
@@ -85,10 +115,11 @@ 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
ActivateWithParameterSlot& slot, gint32 state)
+Glib::RefPtr<SimpleAction> ActionMap::add_action_radio_integer(const Glib::ustring& name, const
ActivateWithIntParameterSlot& slot, gint32 state)
{
Glib::RefPtr<SimpleAction> action = add_action_radio_integer(name, state);
- action->signal_activate().connect(slot);
+ action->signal_activate().connect(
+ sigc::bind(sigc::ptr_fun(&on_action_radio_int), slot));
return action;
}
diff --git a/gio/src/actionmap.hg b/gio/src/actionmap.hg
index fd58f7d..6c8d1c5 100644
--- a/gio/src/actionmap.hg
+++ b/gio/src/actionmap.hg
@@ -123,6 +123,7 @@ public:
*/
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.
@@ -133,6 +134,14 @@ public:
*/
Glib::RefPtr<SimpleAction> add_action_radio_string(const Glib::ustring& name, const Glib::ustring& state);
+ /** A Slot to be called when an action has been activated.
+ * See add_action_radio_string().
+ *
+ * For instance,
+ * void on_slot_activated(const Glib::VariantBase& parameter);
+ */
+ typedef sigc::slot< void, const Glib::ustring& > ActivateWithStringParameterSlot;
+
//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.
@@ -142,7 +151,7 @@ public:
* @param state The initial state.
* @return The Action.
*/
- Glib::RefPtr<SimpleAction> add_action_radio_string(const Glib::ustring& name, const
ActivateWithParameterSlot& slot, const Glib::ustring& state);
+ Glib::RefPtr<SimpleAction> add_action_radio_string(const Glib::ustring& name, const
ActivateWithStringParameterSlot& 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
@@ -154,6 +163,14 @@ public:
*/
Glib::RefPtr<SimpleAction> add_action_radio_integer(const Glib::ustring& name, gint32 state);
+ /** A Slot to be called when an action has been activated.
+ * See add_action_radio_int().
+ *
+ * For instance,
+ * void on_slot_activated(const Glib::VariantBase& parameter);
+ */
+ typedef sigc::slot< void, int > ActivateWithIntParameterSlot;
+
//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.
@@ -163,7 +180,7 @@ public:
* @param state The initial state.
* @return The Action.
*/
- Glib::RefPtr<SimpleAction> add_action_radio_integer(const Glib::ustring& name, const
ActivateWithParameterSlot& slot, gint32 state);
+ Glib::RefPtr<SimpleAction> add_action_radio_integer(const Glib::ustring& name, const
ActivateWithIntParameterSlot& 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]