Added copyright lines for files I've edited this year.
[synfig.git] / synfig-studio / trunk / src / synfigapp / actions / valuedescconnect.cpp
index 599d686..7c2dfb2 100644 (file)
@@ -2,19 +2,21 @@
 /*!    \file valuedescconnect.cpp
 **     \brief Template File
 **
-**     $Id: valuedescconnect.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
+**     $Id$
 **
 **     \legal
-**     Copyright (c) 2002 Robert B. Quattlebaum Jr.
+**     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+**     Copyright (c) 2008 Chris Moore
 **
-**     This software and associated documentation
-**     are CONFIDENTIAL and PROPRIETARY property of
-**     the above-mentioned copyright holder.
+**     This package is free software; you can redistribute it and/or
+**     modify it under the terms of the GNU General Public License as
+**     published by the Free Software Foundation; either version 2 of
+**     the License, or (at your option) any later version.
 **
-**     You may not copy, print, publish, or in any
-**     other way distribute this software without
-**     a prior written agreement with
-**     the copyright holder.
+**     This package is distributed in the hope that it will be useful,
+**     but WITHOUT ANY WARRANTY; without even the implied warranty of
+**     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+**     General Public License for more details.
 **     \endlegal
 */
 /* ========================================================================= */
@@ -35,6 +37,8 @@
 #include "valuedescconnect.h"
 #include <synfigapp/canvasinterface.h>
 
+#include <synfigapp/general.h>
+
 #endif
 
 using namespace std;
@@ -45,14 +49,14 @@ using namespace Action;
 
 /* === M A C R O S ========================================================= */
 
-ACTION_INIT(Action::ValueDescConnect);
+ACTION_INIT_NO_GET_LOCAL_NAME(Action::ValueDescConnect);
 ACTION_SET_NAME(Action::ValueDescConnect,"value_desc_connect");
-ACTION_SET_LOCAL_NAME(Action::ValueDescConnect,"Connect");
+ACTION_SET_LOCAL_NAME(Action::ValueDescConnect,N_("Connect"));
 ACTION_SET_TASK(Action::ValueDescConnect,"connect");
 ACTION_SET_CATEGORY(Action::ValueDescConnect,Action::CATEGORY_VALUEDESC|Action::CATEGORY_VALUENODE);
 ACTION_SET_PRIORITY(Action::ValueDescConnect,0);
 ACTION_SET_VERSION(Action::ValueDescConnect,"0.0");
-ACTION_SET_CVS_ID(Action::ValueDescConnect,"$Id: valuedescconnect.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $");
+ACTION_SET_CVS_ID(Action::ValueDescConnect,"$Id$");
 
 /* === G L O B A L S ======================================================= */
 
@@ -64,11 +68,20 @@ Action::ValueDescConnect::ValueDescConnect()
 {
 }
 
+synfig::String
+Action::ValueDescConnect::get_local_name()const
+{
+       // TRANSLATORS: This is used in the 'history' dialog when a connection is made.
+       return strprintf(_("Connect '%s' to '%s'"),
+                                        value_desc.get_description(false).c_str(),
+                                        value_node->get_id().c_str());
+}
+
 Action::ParamVocab
 Action::ValueDescConnect::get_param_vocab()
 {
        ParamVocab ret(Action::CanvasSpecific::get_param_vocab());
-       
+
        ret.push_back(ParamDesc("dest",Param::TYPE_VALUEDESC)
                .set_local_name(_("Destination ValueDesc"))
        );
@@ -83,20 +96,31 @@ Action::ValueDescConnect::get_param_vocab()
                .set_mutual_exclusion("src")
                .set_user_supplied()
        );
-       
+
        return ret;
 }
 
 bool
-Action::ValueDescConnect::is_canidate(const ParamList &x)
+Action::ValueDescConnect::is_candidate(const ParamList &x)
 {
-       if(canidate_check(get_param_vocab(),x))
+       if(candidate_check(get_param_vocab(),x))
        {
+               // don't show the option of connecting to an existing Index parameter of the Duplicate layer
+               if(x.count("dest"))
+               {
+                       ValueDesc value_desc=x.find("dest")->second.get_value_desc();
+
+                       if (value_desc.parent_is_layer_param() &&
+                               value_desc.get_layer()->get_name() == "duplicate" &&
+                               value_desc.get_param_name() == "index")
+                               return false;
+               }
+
                if(x.count("src"))
                {
                        ValueDesc value_desc=x.find("dest")->second.get_value_desc();
                        ValueNode::Handle value_node=x.find("src")->second.get_value_node();
-                       if(value_desc.get_value_type()==value_node->get_type()) 
+                       if(value_desc.get_value_type()==value_node->get_type())
                                return true;
                }
                return true;
@@ -110,14 +134,14 @@ Action::ValueDescConnect::set_param(const synfig::String& name, const Action::Pa
        if(name=="dest" && param.get_type()==Param::TYPE_VALUEDESC)
        {
                value_desc=param.get_value_desc();
-               
+
                return true;
        }
 
        if(name=="src" && param.get_type()==Param::TYPE_VALUENODE)
        {
                value_node=param.get_value_node();
-               
+
                return true;
        }
 
@@ -125,21 +149,21 @@ Action::ValueDescConnect::set_param(const synfig::String& name, const Action::Pa
        {
                value_node=param.get_canvas()->find_value_node(value_node_name);
        }
-       
+
        if(name=="src_name" && param.get_type()==Param::TYPE_STRING)
        {
                value_node_name=param.get_string();
-               
+
                if(get_canvas())
                {
                        value_node=get_canvas()->find_value_node(value_node_name);
                        if(!value_node)
                                return false;
                }
-               
+
                return true;
        }
-       
+
        return Action::CanvasSpecific::set_param(name,param);
 }
 
@@ -157,60 +181,60 @@ Action::ValueDescConnect::prepare()
        clear();
 
        if(value_desc.parent_is_canvas())
-       {                               
+       {
                ValueNode::Handle dest_value_node;
                dest_value_node=value_desc.get_value_node();
 
                Action::Handle action(ValueNodeReplace::create());
-               
+
                action->set_param("canvas",get_canvas());
                action->set_param("canvas_interface",get_canvas_interface());
                action->set_param("src",value_node);
                action->set_param("dest",value_desc.get_value_node());
-       
+
                assert(action->is_ready());
                if(!action->is_ready())
                        throw Error(Error::TYPE_NOTREADY);
-       
+
                add_action_front(action);
-               return;         
+               return;
        }
        else
        if(value_desc.parent_is_linkable_value_node())
        {
                Action::Handle action(ValueNodeLinkConnect::create());
-               
+
                action->set_param("canvas",get_canvas());
                action->set_param("canvas_interface",get_canvas_interface());
                action->set_param("parent_value_node",value_desc.get_parent_value_node());
                action->set_param("value_node", value_node);
                action->set_param("index",value_desc.get_index());
-       
+
                assert(action->is_ready());
                if(!action->is_ready())
                        throw Error(Error::TYPE_NOTREADY);
-       
+
                add_action_front(action);
-               return;         
+               return;
        }
        else
        if(value_desc.parent_is_layer_param())
        {
                Action::Handle action(LayerParamConnect::create());
-               
+
                action->set_param("canvas",get_canvas());
                action->set_param("canvas_interface",get_canvas_interface());
                action->set_param("layer",value_desc.get_layer());
                action->set_param("param",value_desc.get_param_name());
                action->set_param("value_node",value_node);
-       
-               assert(action->is_ready());             
+
+               assert(action->is_ready());
                if(!action->is_ready())
                        throw Error(Error::TYPE_NOTREADY);
-       
+
                add_action_front(action);
-               return;         
+               return;
        }
-       
-       throw Error(_("ValueDesc is not recognised or supported."));    
+
+       throw Error(_("ValueDesc is not recognized or supported."));
 }