Improved the formatting of ValueNode descriptions for use in the History dialog.
authordooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Tue, 15 Jan 2008 14:47:39 +0000 (14:47 +0000)
committerdooglus <dooglus@1f10aa63-cdf2-0310-b900-c93c546f37ac>
Tue, 15 Jan 2008 14:47:39 +0000 (14:47 +0000)
git-svn-id: http://svn.voria.com/code@1369 1f10aa63-cdf2-0310-b900-c93c546f37ac

synfig-core/trunk/src/synfig/valuenode.cpp
synfig-core/trunk/src/synfig/valuenode.h

index 3c537d3..d264d91 100644 (file)
@@ -37,6 +37,7 @@
 #include "valuenode.h"
 #include "general.h"
 #include "canvas.h"
+#include "paramdesc.h"
 
 #include "valuenode_const.h"
 #include "valuenode_linear.h"
@@ -310,6 +311,15 @@ ValueNode::set_id(const String &x)
        }
 }
 
+String
+ValueNode::get_description(bool show_exported_name)const
+{
+       if (dynamic_cast<const LinkableValueNode*>(this))
+               return (dynamic_cast<const LinkableValueNode*>(this))->get_description(-1, show_exported_name);
+
+       return "ValueNode";
+}
+
 ValueNodeList::ValueNodeList():
        placeholder_count_(0)
 {
@@ -555,3 +565,63 @@ void LinkableValueNode::get_times_vfunc(Node::time_set &set) const
                }
        }
 }
+
+String
+LinkableValueNode::get_description(int index, bool show_exported_name)const
+{
+       String description;
+
+       if (show_exported_name && !is_exported())
+               show_exported_name = false;
+
+       if (index != -1)
+               description = String(":") + link_local_name(index);
+
+       const synfig::Node* node = this;
+       LinkableValueNode::ConstHandle parent_linkable_vn = 0;
+
+       // walk up through the valuenodes trying to find the layer at the top
+       while (!node->parent_set.empty() && !dynamic_cast<const Layer*>(node))
+       {
+               LinkableValueNode::ConstHandle linkable_value_node(dynamic_cast<const LinkableValueNode*>(node));
+               if (linkable_value_node)
+               {
+                       String link;
+                       int cnt = linkable_value_node->link_count();
+                       for (int i = 0; i < cnt; i++)
+                               if (linkable_value_node->get_link(i) == parent_linkable_vn)
+                               {
+                                       link = String(":") + linkable_value_node->link_local_name(i);
+                                       break;
+                               }
+
+                       description = linkable_value_node->get_local_name() + link + (parent_linkable_vn?">":"") + description;
+               }
+               node = *node->parent_set.begin();
+               parent_linkable_vn = linkable_value_node;
+       }
+
+       Layer::ConstHandle parent_layer(dynamic_cast<const Layer*>(node));
+       if(parent_layer)
+       {
+               String param;
+               const Layer::DynamicParamList &dynamic_param_list(parent_layer->dynamic_param_list());
+               // loop to find the parameter in the dynamic parameter list - this gives us its name
+               for (Layer::DynamicParamList::const_iterator iter = dynamic_param_list.begin(); iter != dynamic_param_list.end(); iter++)
+                       if (iter->second == parent_linkable_vn)
+                       {
+                               String param_local_name(parent_layer->get_param_local_name(iter->first));
+                               if (!param_local_name.empty())
+                                       param = String(":(nu)") + param_local_name;
+                       }
+               description = strprintf("(%s)%s>%s",
+                                                               parent_layer->get_non_empty_description().c_str(),
+                                                               param.c_str(),
+                                                               description.c_str());
+       }
+
+       if (show_exported_name)
+               description += strprintf(" (%s)", get_id().c_str());
+
+       return description;
+}
index 4d2c778..62940c3 100644 (file)
@@ -212,6 +212,9 @@ public:
        //! Returns the localized name of the ValueNode type
        virtual String get_local_name()const=0;
 
+       //! Return a full description of the ValueNode and its parentage
+       virtual String get_description(bool show_exported_name = true)const;
+
 
        //! \writeme
        virtual ValueNode* clone(const GUID& deriv_guid=GUID())const=0;
@@ -346,6 +349,9 @@ public:
        ValueNode::LooseHandle get_link(int i)const;
        ValueNode::LooseHandle get_link(const String &name)const { return get_link(get_link_index_from_name(name)); }
 
+       String
+       get_description(int index, bool show_exported_name = true)const;
+
 protected:
        //! Sets the type of the ValueNode
        void set_type(ValueBase::Type t) { ValueNode::set_type(t); }