allow to copy processor state (drag processor on another of same type)
[ardour.git] / gtk2_ardour / gui_object.cc
index 2b516d04dac97e64b16bf0230cd6f14d329cec6f..3128e61f3ab44c2ab0a8e7c4c80435bf7d91c0f3 100644 (file)
@@ -34,10 +34,11 @@ GUIObjectState::GUIObjectState ()
 }
 
 XMLNode *
-GUIObjectState::find_node (const string& id) const
+GUIObjectState::get_node (const XMLNode* parent, const string& id)
 {
-       XMLNodeList const & children = _state.children ();
+       XMLNodeList const & children = parent->children ();
        for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
+
                if ((*i)->name() != X_("Object")) {
                        continue;
                }
@@ -51,6 +52,35 @@ GUIObjectState::find_node (const string& id) const
        return 0;
 }
 
+XMLNode *
+GUIObjectState::get_or_add_node (XMLNode* parent, const string& id)
+{
+       XMLNode* child = get_node (parent, id);
+       if (!child) {
+               child = new XMLNode (X_("Object"));
+               child->add_property (X_("id"), id);
+               parent->add_child_nocopy (*child);
+       }
+
+       return child;
+}
+
+XMLNode *
+GUIObjectState::get_or_add_node (const string& id)
+{
+       return get_or_add_node (&_state, id);
+}
+
+/** Remove node with provided id.
+ *  @param id property of Object node to look for.
+ */
+
+void
+GUIObjectState::remove_node (const std::string& id)
+{
+       _state.remove_nodes_and_delete(X_("id"), id );
+}
+
 /** Get a string from our state.
  *  @param id property of Object node to look for.
  *  @param prop_name name of the Object property to return.
@@ -58,10 +88,11 @@ GUIObjectState::find_node (const string& id) const
  *  @return value of property `prop_name', or empty.
  */
 
-string 
+string
 GUIObjectState::get_string (const string& id, const string& prop_name, bool* empty)
 {
-       XMLNode* child = find_node (id);
+       XMLNode* child = get_node (&_state, id);
+
        if (!child) {
                if (empty) {
                        *empty = true;
@@ -107,13 +138,6 @@ GUIObjectState::load (const XMLNode& node)
        (void) set_state (node);
 }
 
-GUIObjectState&
-GUIObjectState::operator= (const GUIObjectState& other)
-{
-       _state = other._state;
-       return *this;
-}
-
 std::list<string>
 GUIObjectState::all_ids () const
 {
@@ -133,4 +157,4 @@ GUIObjectState::all_ids () const
        return ids;
 }
 
-       
+