[ekiga/ds-gtk-application] Actor: Added method to get ActionPtr by name.
- From: Damien Sandras <dsandras src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ekiga/ds-gtk-application] Actor: Added method to get ActionPtr by name.
- Date: Tue, 16 Sep 2014 19:22:06 +0000 (UTC)
commit 442ebd13f6240d1c39dcbed115a494882669925b
Author: Damien Sandras <dsandras seconix com>
Date: Tue Sep 16 21:19:41 2014 +0200
Actor: Added method to get ActionPtr by name.
Also refactorised code.
lib/engine/action/actor.cpp | 49 +++++++++++++++++++++++++++---------------
lib/engine/action/actor.h | 9 ++++++++
2 files changed, 40 insertions(+), 18 deletions(-)
---
diff --git a/lib/engine/action/actor.cpp b/lib/engine/action/actor.cpp
index 42d1184..de9eab1 100644
--- a/lib/engine/action/actor.cpp
+++ b/lib/engine/action/actor.cpp
@@ -65,40 +65,53 @@ Actor::add_action (const ActionStore & _actions)
bool
Actor::remove_action (const std::string & name)
{
- for (ActionStore::iterator it = actions.begin (); it != actions.end () ; ++it) {
- if ((*it)->get_name () == name) {
- action_removed (name);
- actions.erase (it);
- return true;
- }
- }
- return false;
+ ActionPtr a = get_action (name);
+ if (!a)
+ return false;
+
+ action_removed (name);
+ actions.remove (a);
+
+ return true;
}
bool
Actor::enable_action (const std::string & name)
{
- for (ActionStore::iterator it = actions.begin (); it != actions.end () ; ++it) {
- if ((*it)->get_name () == name) {
- (*it)->enable ();
- return true;
- }
- }
- return false;
+ ActionPtr a = get_action (name);
+ if (!a)
+ return false;
+
+ a->enable ();
+
+ return true;
}
bool
Actor::disable_action (const std::string & name)
{
+ ActionPtr a = get_action (name);
+ if (!a)
+ return false;
+
+ a->disable ();
+
+ return true;
+}
+
+
+ActionPtr
+Actor::get_action (const std::string & name)
+{
for (ActionStore::iterator it = actions.begin (); it != actions.end () ; ++it) {
if ((*it)->get_name () == name) {
- (*it)->disable ();
- return true;
+ return (*it);
}
}
- return false;
+
+ return ActionPtr ();
}
diff --git a/lib/engine/action/actor.h b/lib/engine/action/actor.h
index 1db2c12..afa8f2b 100644
--- a/lib/engine/action/actor.h
+++ b/lib/engine/action/actor.h
@@ -116,6 +116,15 @@ namespace Ekiga {
virtual void remove_actions ();
+ /** Return an action by name.
+ *
+ * @param An Action name.
+ * @return A smart pointer to the Action if it was found. An empty pointer
+ * otherwise.
+ */
+ virtual ActionPtr get_action (const std::string & name);
+
+
/** Iterators (able to iterate through actions)
*/
const_iterator begin () const;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]