Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / stable / src / gtkmm / instance.cpp
index a70d474..971e69b 100644 (file)
@@ -1,20 +1,23 @@
-/* === S I N F G =========================================================== */
-/*!    \file instance.cpp
+/* === S Y N F I G ========================================================= */
+/*!    \file gtkmm/instance.cpp
 **     \brief writeme
 **
-**     $Id: instance.cpp,v 1.2 2005/01/13 18:37:30 darco Exp $
+**     $Id$
 **
 **     \legal
-**     Copyright (c) 2002 Robert B. Quattlebaum Jr.
+**     Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
+**     Copyright (c) 2007, 2008 Chris Moore
+**  Copyright (c) 2008 Carlos López
 **
-**     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
 */
 /* ========================================================================= */
 #include <sigc++/adaptors/hide.h>
 #include "toolbox.h"
 #include "onemoment.h"
+#include <synfig/savecanvas.h>
 
 #include "autorecover.h"
 #include <sigc++/retype_return.h>
 #include <sigc++/retype.h>
 //#include <sigc++/hide.h>
-#include <sinfg/valuenode_composite.h>
+#include <synfig/valuenode_composite.h>
+#include <synfig/valuenode_duplicate.h>
 #include "widget_waypointmodel.h"
 #include <gtkmm/actiongroup.h>
-#include "iconcontroler.h"
+#include "iconcontroller.h"
+#include "workarea.h"
+#include <sys/stat.h>
+#include <errno.h>
+#include <ETL/stringf>
+
+#include "general.h"
 
 #endif
 
 using namespace std;
 using namespace etl;
-using namespace sinfg;
+using namespace synfig;
 using namespace studio;
-using namespace SigC;
+using namespace sigc;
 
 /* === M A C R O S ========================================================= */
 
@@ -68,8 +79,8 @@ int studio::Instance::instance_count_=0;
 
 /* === M E T H O D S ======================================================= */
 
-Instance::Instance(Canvas::Handle canvas):
-       sinfgapp::Instance              (canvas),
+Instance::Instance(synfig::Canvas::Handle canvas):
+       synfigapp::Instance             (canvas),
 //     canvas_tree_store_              (Gtk::TreeStore::create(CanvasTreeModel())),
 //     canvas_tree_store_              (Gtk::TreeStore::create()),
        history_tree_store_             (HistoryTreeStore::create(this)),
@@ -80,7 +91,7 @@ Instance::Instance(Canvas::Handle canvas):
        canvas_tree_store_=Gtk::TreeStore::create(model);
 
        id_=instance_count_++;
-       
+
        // Connect up all the signals
        signal_filename_changed().connect(sigc::mem_fun(*this,&studio::Instance::update_all_titles));
        signal_unsaved_status_changed().connect(sigc::hide(sigc::mem_fun(*this,&studio::Instance::update_all_titles)));
@@ -94,9 +105,9 @@ Instance::Instance(Canvas::Handle canvas):
                        )
                )
        );
-       
+
        canvas_tree_store_=Gtk::TreeStore::create(canvas_tree_model);
-       
+
        refresh_canvas_tree();
 }
 
@@ -116,31 +127,31 @@ Instance::get_visible_canvases()const
 }
 
 handle<Instance>
-Instance::create(Canvas::Handle canvas)
+Instance::create(synfig::Canvas::Handle canvas)
 {
        // Construct a new instance
        handle<Instance> instance(new Instance(canvas));
 
        // Add the new instance to the application's instance list
        App::instance_list.push_back(instance);
-       
+
        // Set up the instance with the default UI manager
-       instance->sinfgapp::Instance::set_ui_interface(App::get_ui_interface());
-       
+       instance->synfigapp::Instance::set_ui_interface(App::get_ui_interface());
+
        // Signal the new instance
        App::signal_instance_created()(instance);
-       
+
        // And then make sure that is has been selected
        App::set_selected_instance(instance);
-       
+
        // Create the initial window for the root canvas
        instance->focus(canvas);
-       
-       return instance;        
+
+       return instance;
 }
 
 handle<CanvasView>
-Instance::find_canvas_view(Canvas::Handle canvas)
+Instance::find_canvas_view(etl::handle<synfig::Canvas> canvas)
 {
        if(!canvas)
                return 0;
@@ -149,16 +160,16 @@ Instance::find_canvas_view(Canvas::Handle canvas)
                canvas=canvas->parent();
 
        CanvasViewList::iterator iter;
-       
+
        for(iter=canvas_view_list().begin();iter!=canvas_view_list().end();iter++)
                if((*iter)->get_canvas()==canvas)
                        return *iter;
-       
+
        return CanvasView::create(this,canvas);
 }
 
 void
-Instance::focus(Canvas::Handle canvas)
+Instance::focus(etl::handle<synfig::Canvas> canvas)
 {
        handle<CanvasView> canvas_view=find_canvas_view(canvas);
        assert(canvas_view);
@@ -182,104 +193,153 @@ Instance::set_redo_status(bool x)
 }
 
 bool
-studio::Instance::save_as(const sinfg::String &file_name)const
+studio::Instance::save_as(const synfig::String &file_name)
 {
-       if(sinfgapp::Instance::save_as(file_name))
+       if(synfigapp::Instance::save_as(file_name))
        {
-               App::add_recent_file(file_name);
+               // after changing the filename, update the render settings with the new filename
+               list<handle<CanvasView> >::iterator iter;
+               for(iter=canvas_view_list().begin();iter!=canvas_view_list().end();iter++)
+                       (*iter)->render_settings.set_entry_filename();
+               App::add_recent_file(etl::handle<Instance>(this));
                return true;
        }
        return false;
 }
 
-bool
-studio::Instance::save_as(const sinfg::String &file_name)
+void
+studio::Instance::open()
 {
-       if(sinfgapp::Instance::save_as(file_name))
-       {
-               App::add_recent_file(file_name);
-               return true;
-       }
-       return false;
+       App::dialog_open(get_file_name());
 }
 
-bool
+Instance::Status
 studio::Instance::save()
 {
-       if(basename(get_file_name()).find("untitled")==0)
+       // if we don't have a real filename yet then we need to ask where to save it
+       if (!has_real_filename())
        {
-               dialog_save_as();
-               return true;
+               if (dialog_save_as())
+                       return STATUS_OK;
+               else
+                       return STATUS_CANCEL;
        }
 
-       return sinfgapp::Instance::save();
-       
+       if (synfigapp::Instance::save())
+       {
+               App::add_recent_file(etl::handle<Instance>(this));
+               return STATUS_OK;
+       }
+       string msg(strprintf(_("Unable to save to '%s'"), get_file_name().c_str()));
+       App::dialog_error_blocking(_("Save - Error"), msg.c_str());
+       return STATUS_ERROR;
 }
 
-void
+// the filename will be set to "Synfig Animation 1" or some such when first created
+// and will be changed to an absolute path once it has been saved
+// so if it still begins with "Synfig Animation " then we don't have a real filename yet
+bool
+studio::Instance::has_real_filename()
+{
+       return get_file_name().find(App::custom_filename_prefix.c_str()) != 0;
+}
+
+bool
 studio::Instance::dialog_save_as()
 {
-       string filename="*.sif";
-       
+       string filename = get_file_name();
        Canvas::Handle canvas(get_canvas());
-       
+
        {
                OneMoment one_moment;
                std::set<Node*>::iterator iter;
                for(iter=canvas->parent_set.begin();iter!=canvas->parent_set.end();++iter)
                {
-                       sinfg::Node* node(*iter);
+                       synfig::Node* node(*iter);
                        for(;!node->parent_set.empty();node=*node->parent_set.begin())
                        {
                                Layer::Handle parent_layer(dynamic_cast<Layer*>(node));
                                if(parent_layer && parent_layer->get_canvas()->get_root()!=get_canvas())
                                {
-                                       App::dialog_error_blocking("SaveAs - Error",
-                                               "There is currently a bug when using \"SaveAs\"\n"
+                                       string msg(strprintf(_("There is currently a bug when using \"SaveAs\"\n"
                                                "on a composition that is being referenced by other\n"
                                                "files that are currently open. Close these\n"
-                                               "other files first before trying to use \"SaveAs\"."
-                                       );
-                                       
-                                       return;
+                                               "other files first before trying to use \"SaveAs\".")));
+                                       App::dialog_error_blocking(_("SaveAs - Error"), msg.c_str());
+
+                                       return false;
                                }
                                if(parent_layer)
                                        break;
                        }
                }
        }
-       
-       while(App::dialog_saveas_file("SaveAs", filename))
+
+       if (has_real_filename())
+               filename = absolute_path(filename);
+
+       // show the canvas' name if it has one, else its ID
+       while (App::dialog_save_file((_("Choose a Filename to Save As") +
+                                                                 String(" (") +
+                                                                 (canvas->get_name().empty() ? canvas->get_id() : canvas->get_name()) +
+                                                                 ") ..."),
+                                                                filename, ANIMATION_DIR_PREFERENCE))
        {
                // If the filename still has wildcards, then we should
                // continue looking for the file we want
-               if(find(filename.begin(),filename.end(),'*')!=filename.end())
+               string base_filename = basename(filename);
+               if (find(base_filename.begin(),base_filename.end(),'*')!=base_filename.end())
                        continue;
 
-               if(find(filename.begin(),filename.end(),'.')==filename.end())
-                       filename+=".sif";
+               if (filename_extension(filename) == "")
+                       filename+=".sifz";
 
                try
                {
-                       String ext(String(filename.begin()+filename.find_last_of('.')+1,filename.end()));
-                       if(ext!="sif" && ext!="sifz" && !App::dialog_yes_no(_("Unknown extension"),
-                               _("You have given the file name an extension\nwhich I do not recognise. Are you sure this is what you want?")))
-                       {
+                       String ext(filename_extension(filename));
+                       if(ext!=".sif" && ext!=".sifz" && !App::dialog_yes_no(_("Unknown extension"),
+                               _("You have given the file name an extension\nwhich I do not recognize. Are you sure this is what you want?")))
                                continue;
-                       }
                }
                catch(...)
                {
                        continue;
                }
-                       
+
+               {
+                       struct stat     s;
+                       int stat_return = stat(filename.c_str(), &s);
+
+                       // if stat() fails with something other than 'file doesn't exist', there's been a real
+                       // error of some kind.  let's give up now and ask for a new path.
+                       if (stat_return == -1 && errno != ENOENT)
+                       {
+                               perror(filename.c_str());
+                               string msg(strprintf(_("Unable to check whether '%s' exists."), filename.c_str()));
+                               App::dialog_error_blocking(_("SaveAs - Error"),msg.c_str());
+                               continue;
+                       }
+
+                       // if the file exists and the user doesn't want to overwrite it, keep prompting for a filename
+                       string msg(strprintf(_("A file named '%s' already exists.\n\n"
+                                                                       "Do you want to replace it with the file you are saving?"), filename.c_str()));
+                       if ((stat_return == 0) &&
+                               !App::dialog_yes_no(_("File exists"),msg.c_str()))
+                               continue;
+               }
+
                if(save_as(filename))
-                       break;
-               
-               App::dialog_error_blocking("SaveAs - Error","Unable to save file");
+               {
+                       synfig::set_file_version(ReleaseVersion(RELEASE_VERSION_END-1));
+                       return true;
+               }
+               string msg(strprintf(_("Unable to save to '%s'"), filename.c_str()));
+               App::dialog_error_blocking(_("SaveAs - Error"),msg.c_str());
        }
+
+       return false;
 }
-       
+
 void
 Instance::update_all_titles()
 {
@@ -318,6 +378,9 @@ Instance::close()
        for(std::list<etl::handle<CanvasView> >::iterator iter=canvas_view_list().begin();iter!=canvas_view_list().end();iter++)
                (*iter)->hide();
 
+       // Consume pending events before deleting the canvas views
+       while(studio::App::events_pending())studio::App::iteration(false);
+
        // Delete all of the canvas views
        canvas_view_list().clear();
 
@@ -329,20 +392,16 @@ Instance::close()
                studio::App::set_selected_instance(0);
        }
        else
-       {
-               studio::App::set_selected_canvas_view(studio::App::instance_list.front()->canvas_view_list().front());
-               //studio::App::set_selected_instance(studio::App::instance_list.front());
-       }
+               studio::App::instance_list.front()->canvas_view_list().front()->present();
 }
 
-       
 void
-Instance::insert_canvas(Gtk::TreeRow row,Canvas::Handle canvas)
+Instance::insert_canvas(Gtk::TreeRow row, synfig::Canvas::Handle canvas)
 {
        CanvasTreeModel canvas_tree_model;
        assert(canvas);
 
-       row[canvas_tree_model.icon] = Gtk::Button().render_icon(Gtk::StockID("sinfg-canvas"),Gtk::ICON_SIZE_SMALL_TOOLBAR);     
+       row[canvas_tree_model.icon] = Gtk::Button().render_icon(Gtk::StockID("synfig-canvas"),Gtk::ICON_SIZE_SMALL_TOOLBAR);
        row[canvas_tree_model.id] = canvas->get_id();
        row[canvas_tree_model.name] = canvas->get_name();
        if(canvas->is_root())
@@ -352,18 +411,18 @@ Instance::insert_canvas(Gtk::TreeRow row,Canvas::Handle canvas)
                row[canvas_tree_model.label] = canvas->get_id();
        else
        if(!canvas->get_name().empty())
-               row[canvas_tree_model.label] = canvas->get_name();              
+               row[canvas_tree_model.label] = canvas->get_name();
        else
-               row[canvas_tree_model.label] = _("[Unnamed]");          
-               
+               row[canvas_tree_model.label] = _("[Unnamed]");
+
        row[canvas_tree_model.canvas] = canvas;
        row[canvas_tree_model.is_canvas] = true;
        row[canvas_tree_model.is_value_node] = false;
 
        {
-               sinfg::Canvas::Children::iterator iter;
-               sinfg::Canvas::Children &children(canvas->children());
-       
+               synfig::Canvas::Children::iterator iter;
+               synfig::Canvas::Children &children(canvas->children());
+
                for(iter=children.begin();iter!=children.end();iter++)
                        insert_canvas(*(canvas_tree_store()->append(row.children())),*iter);
        }
@@ -378,8 +437,8 @@ Instance::insert_canvas(Gtk::TreeRow row,Canvas::Handle canvas)
                valuenode_row[canvas_tree_model.is_canvas] = false;
                valuenode_row[canvas_tree_model.is_value_node] = false;
 
-               sinfg::ValueNodeList::iterator iter;
-               sinfg::ValueNodeList &value_node_list(canvas->value_node_list());
+               synfig::ValueNodeList::iterator iter;
+               synfig::ValueNodeList &value_node_list(canvas->value_node_list());
 
                for(iter=value_node_list.begin();iter!=value_node_list.end();iter++)
                        insert_value_node(*(canvas_tree_store()->append(valuenode_row.children())),canvas,*iter);
@@ -387,10 +446,9 @@ Instance::insert_canvas(Gtk::TreeRow row,Canvas::Handle canvas)
        */
 }
 
-
 /*
 void
-Instance::insert_value_node(Gtk::TreeRow row,Canvas::Handle canvas,etl::handle<sinfg::ValueNode> value_node)
+Instance::insert_value_node(Gtk::TreeRow row,Canvas::Handle canvas,etl::handle<synfig::ValueNode> value_node)
 {
        CanvasTreeModel canvas_tree_model;
        assert(value_node);
@@ -428,7 +486,7 @@ Instance::dialog_cvs_commit()
        {
                string message;
 
-               if(sinfgapp::Instance::get_action_count())
+               if(synfigapp::Instance::get_action_count())
                {
                        if(!App::dialog_yes_no(_("CVS Commit"), _("This will save any changes you have made. Are you sure?")))
                                return;
@@ -443,13 +501,13 @@ Instance::dialog_cvs_commit()
 
                if(!App::dialog_entry(_("CVS Commit"),_("Enter a log message describing the changes you have made"), message))
                        return;
-               
+
                OneMoment one_moment;
                cvs_commit(message);
        }
        catch(...)
        {
-               App::dialog_error_blocking(_("Error"),_("An error has occured when trying to COMMIT"));
+               App::dialog_error_blocking(_("Error"),_("An error has occurred when trying to COMMIT"));
        }
        update_all_titles();
 }
@@ -466,7 +524,7 @@ Instance::dialog_cvs_add()
        try
        {
                string message;
-               
+
                //if(!App::dialog_entry(_("CVS Add"),_("Enter a log message describing the file"), message))
                //      return;
                OneMoment one_moment;
@@ -474,7 +532,7 @@ Instance::dialog_cvs_add()
        }
        catch(...)
        {
-               App::dialog_error_blocking(_("Error"),_("An error has occured when trying to ADD"));
+               App::dialog_error_blocking(_("Error"),_("An error has occurred when trying to ADD"));
        }
        update_all_titles();
 }
@@ -493,11 +551,11 @@ Instance::dialog_cvs_update()
                App::dialog_error_blocking(_("Info"),_("This file is up-to-date"));
                return;
        }
-       
+
        try
        {
                String filename(get_file_name());
-               if(sinfgapp::Instance::get_action_count())
+               if(synfigapp::Instance::get_action_count())
                {
                        if(!App::dialog_yes_no(_("CVS Update"), _("This will save any changes you have made. Are you sure?")))
                                return;
@@ -506,7 +564,7 @@ Instance::dialog_cvs_update()
                OneMoment one_moment;
                time_t oldtime=get_original_timestamp();
                cvs_update();
-               calc_repository_info();         
+               calc_repository_info();
                // If something has been updated...
                if(oldtime!=get_original_timestamp())
                {
@@ -515,7 +573,7 @@ Instance::dialog_cvs_update()
        }
        catch(...)
        {
-               App::dialog_error_blocking(_("Error"),_("An error has occured when trying to UPDATE"));
+               App::dialog_error_blocking(_("Error"),_("An error has occurred when trying to UPDATE"));
        }
        //update_all_titles();
 }
@@ -551,7 +609,7 @@ Instance::dialog_cvs_revert()
        }
        catch(...)
        {
-               App::dialog_error_blocking(_("Error"),_("An error has occured when trying to UPDATE"));
+               App::dialog_error_blocking(_("Error"),_("An error has occurred when trying to UPDATE"));
        }
        //update_all_titles();
 }
@@ -564,17 +622,17 @@ Instance::_revert(Instance *instance)
        String filename(instance->get_file_name());
 
        Canvas::Handle canvas(instance->get_canvas());
-       
+
        instance->close();
 
        if(canvas->count()!=1)
        {
                one_moment.hide();
-               App::dialog_error_blocking(_("Error: Revert Failed"),_("The revert operation has failed. This can be due to it being\nreferenced by another composition that is already open, or\nbecause of an internal error in SINFG Studio. Try closing any\ncompositions that might reference this composition and try\nagain, or restart SINFG studio."));
+               App::dialog_error_blocking(_("Error: Revert Failed"),_("The revert operation has failed. This can be due to it being\nreferenced by another composition that is already open, or\nbecause of an internal error in Synfig Studio. Try closing any\ncompositions that might reference this composition and try\nagain, or restart Synfig Studio."));
                one_moment.show();
        }
        canvas=0;
-       
+
        App::open(filename);
 }
 
@@ -597,8 +655,8 @@ Instance::revert()
 bool
 Instance::safe_revert()
 {
-       if(sinfgapp::Instance::get_action_count())
-               if(!App::dialog_yes_no(_("Revert to saved"), _("You will loose any changes you have made since your last save.\nAre you sure?")))
+       if(synfigapp::Instance::get_action_count())
+               if(!App::dialog_yes_no(_("Revert to saved"), _("You will lose any changes you have made since your last save.\nAre you sure?")))
                        return false;
        revert();
        return true;
@@ -607,56 +665,68 @@ Instance::safe_revert()
 bool
 Instance::safe_close()
 {
-       handle<sinfgapp::UIInterface> uim;
-       uim=find_canvas_view(get_canvas())->get_ui_interface();
+       handle<CanvasView> canvas_view = find_canvas_view(get_canvas());
+       handle<synfigapp::UIInterface> uim=canvas_view->get_ui_interface();
 
-       if(get_action_count())
+       // if the animation is currently playing, closing the window will cause a crash,
+       // so don't allow it
+       if (canvas_view->is_playing())
        {
-               string str=strprintf(_("Would you like to save your changes to %s?"),basename(get_file_name()).c_str() );
-               int answer=uim->yes_no_cancel(get_canvas()->get_name(),str,sinfgapp::UIInterface::RESPONSE_YES);
-               if(answer==sinfgapp::UIInterface::RESPONSE_YES)
-                       save();
-               if(answer==sinfgapp::UIInterface::RESPONSE_CANCEL)
-                       return false;
+               canvas_view->present();
+               App::dialog_error_blocking("Close Error", "The animation is currently playing so the window cannot be closed.");
+               return false;
        }
+       if(get_action_count())
+               do
+               {
+                       string str=strprintf(_("Would you like to save your changes to %s?"),basename(get_file_name()).c_str() );
+                       int answer=uim->yes_no_cancel(get_canvas()->get_name(),str,synfigapp::UIInterface::RESPONSE_YES);
+                       if(answer==synfigapp::UIInterface::RESPONSE_YES)
+                       {
+                               enum Status status = save();
+                               if (status == STATUS_OK) break;
+                               else if (status == STATUS_CANCEL) return false;
+                       }
+                       if(answer==synfigapp::UIInterface::RESPONSE_NO)
+                               break;
+                       if(answer==synfigapp::UIInterface::RESPONSE_CANCEL)
+                               return false;
+               } while (true);
 
        if(is_modified())
        {
                string str=strprintf(_("%s has changes not yet on the CVS repository.\nWould you like to commit these changes?"),basename(get_file_name()).c_str());
-               int answer=uim->yes_no_cancel(get_canvas()->get_name(),str,sinfgapp::UIInterface::RESPONSE_YES);
+               int answer=uim->yes_no_cancel(get_canvas()->get_name(),str,synfigapp::UIInterface::RESPONSE_YES);
 
-               if(answer==sinfgapp::UIInterface::RESPONSE_YES)
+               if(answer==synfigapp::UIInterface::RESPONSE_YES)
                        dialog_cvs_commit();
-               if(answer==sinfgapp::UIInterface::RESPONSE_CANCEL)
+               if(answer==synfigapp::UIInterface::RESPONSE_CANCEL)
                        return false;
        }
-       
-       close();
 
-       while(studio::App::events_pending())studio::App::iteration(false);
+       close();
 
        return true;
 }
 
-
 void
-Instance::add_actions_to_group(const Glib::RefPtr<Gtk::ActionGroup>& action_group, sinfg::String& ui_info,   const sinfgapp::Action::ParamList &param_list, sinfgapp::Action::Category category)const
+Instance::add_actions_to_group(const Glib::RefPtr<Gtk::ActionGroup>& action_group, synfig::String& ui_info,   const synfigapp::Action::ParamList &param_list, synfigapp::Action::Category category)const
 {
-       sinfgapp::Action::CanidateList canidate_list;
-       sinfgapp::Action::CanidateList::iterator iter;
-       
-       canidate_list=compile_canidate_list(param_list,category);
-       
-       canidate_list.sort();
-
-       if(canidate_list.empty())
-               sinfg::warning("Action CanidateList is empty!");
-       
-       for(iter=canidate_list.begin();iter!=canidate_list.end();++iter)
+       synfigapp::Action::CandidateList candidate_list;
+       synfigapp::Action::CandidateList::iterator iter;
+
+       candidate_list=compile_candidate_list(param_list,category);
+
+       candidate_list.sort();
+
+       // if(candidate_list.empty())
+       //      synfig::warning("%s:%d Action CandidateList is empty!", __FILE__, __LINE__);
+
+       for(iter=candidate_list.begin();iter!=candidate_list.end();++iter)
        {
                Gtk::StockID stock_id(get_action_stock_id(*iter));
-               
-               if(!(iter->category&sinfgapp::Action::CATEGORY_HIDDEN))
+
+               if(!(iter->category&synfigapp::Action::CATEGORY_HIDDEN))
                {
                        action_group->add(Gtk::Action::create(
                                "action-"+iter->name,
@@ -680,25 +750,25 @@ Instance::add_actions_to_group(const Glib::RefPtr<Gtk::ActionGroup>& action_grou
 }
 
 void
-Instance::add_actions_to_menu(Gtk::Menu *menu, const sinfgapp::Action::ParamList &param_list,sinfgapp::Action::Category category)const
+Instance::add_actions_to_menu(Gtk::Menu *menu, const synfigapp::Action::ParamList &param_list,synfigapp::Action::Category category)const
 {
-       sinfgapp::Action::CanidateList canidate_list;
-       sinfgapp::Action::CanidateList::iterator iter;
-       
-       canidate_list=compile_canidate_list(param_list,category);
-       
-       canidate_list.sort();
-
-       if(canidate_list.empty())
-               sinfg::warning("Action CanidateList is empty!");
-       
-       for(iter=canidate_list.begin();iter!=canidate_list.end();++iter)
+       synfigapp::Action::CandidateList candidate_list;
+       synfigapp::Action::CandidateList::iterator iter;
+
+       candidate_list=compile_candidate_list(param_list,category);
+
+       candidate_list.sort();
+
+       if(candidate_list.empty())
+               synfig::warning("%s:%d Action CandidateList is empty!", __FILE__, __LINE__);
+
+       for(iter=candidate_list.begin();iter!=candidate_list.end();++iter)
        {
-               if(!(iter->category&sinfgapp::Action::CATEGORY_HIDDEN))
+               if(!(iter->category&synfigapp::Action::CATEGORY_HIDDEN))
                {
                        Gtk::Image* image(manage(new Gtk::Image()));
                        Gtk::Stock::lookup(get_action_stock_id(*iter),Gtk::ICON_SIZE_MENU,*image);
-                       
+
                        /*
                        if(iter->task=="raise")
                                Gtk::Stock::lookup(Gtk::Stock::GO_UP,Gtk::ICON_SIZE_MENU,*image);
@@ -720,9 +790,9 @@ Instance::add_actions_to_menu(Gtk::Menu *menu, const sinfgapp::Action::ParamList
                                Gtk::Stock::lookup(Gtk::Stock::DELETE,Gtk::ICON_SIZE_MENU,*image);
                        else
                        {
-                               Gtk::Stock::lookup(Gtk::StockID("sinfg-"+iter->name),Gtk::ICON_SIZE_MENU,*image) ||
+                               Gtk::Stock::lookup(Gtk::StockID("synfig-"+iter->name),Gtk::ICON_SIZE_MENU,*image) ||
                                Gtk::Stock::lookup(Gtk::StockID("gtk-"+iter->task),Gtk::ICON_SIZE_MENU,*image) ||
-                               Gtk::Stock::lookup(Gtk::StockID("sinfg-"+iter->task),Gtk::ICON_SIZE_MENU,*image);
+                               Gtk::Stock::lookup(Gtk::StockID("synfig-"+iter->task),Gtk::ICON_SIZE_MENU,*image);
                        }
                        */
                        menu->items().push_back(
@@ -746,34 +816,34 @@ Instance::add_actions_to_menu(Gtk::Menu *menu, const sinfgapp::Action::ParamList
 }
 
 void
-Instance::add_actions_to_menu(Gtk::Menu *menu, const sinfgapp::Action::ParamList &param_list,const sinfgapp::Action::ParamList &param_list2,sinfgapp::Action::Category category)const
+Instance::add_actions_to_menu(Gtk::Menu *menu, const synfigapp::Action::ParamList &param_list,const synfigapp::Action::ParamList &param_list2,synfigapp::Action::Category category)const
 {
-       sinfgapp::Action::CanidateList canidate_list;
-       sinfgapp::Action::CanidateList canidate_list2;
-       
-       sinfgapp::Action::CanidateList::iterator iter;
-       
-       canidate_list=compile_canidate_list(param_list,category);
-       canidate_list2=compile_canidate_list(param_list2,category);
-       
-       canidate_list.sort();
-
-       if(canidate_list.empty())
-               sinfg::warning("Action CanidateList is empty!");
-       if(canidate_list2.empty())
-               sinfg::warning("Action CanidateList2 is empty!");
-
-       // Seperate out the canidate lists so that there are no conflicts
-       for(iter=canidate_list.begin();iter!=canidate_list.end();++iter)
+       synfigapp::Action::CandidateList candidate_list;
+       synfigapp::Action::CandidateList candidate_list2;
+
+       synfigapp::Action::CandidateList::iterator iter;
+
+       candidate_list=compile_candidate_list(param_list,category);
+       candidate_list2=compile_candidate_list(param_list2,category);
+
+       candidate_list.sort();
+
+       if(candidate_list.empty())
+               synfig::warning("%s:%d Action CandidateList is empty!", __FILE__, __LINE__);
+       if(candidate_list2.empty())
+               synfig::warning("%s:%d Action CandidateList2 is empty!", __FILE__, __LINE__);
+
+       // Separate out the candidate lists so that there are no conflicts
+       for(iter=candidate_list.begin();iter!=candidate_list.end();++iter)
        {
-               sinfgapp::Action::CanidateList::iterator iter2(canidate_list2.find(iter->name));
-               if(iter2!=canidate_list2.end())
-                       canidate_list2.erase(iter2);
+               synfigapp::Action::CandidateList::iterator iter2(candidate_list2.find(iter->name));
+               if(iter2!=candidate_list2.end())
+                       candidate_list2.erase(iter2);
        }
-               
-       for(iter=canidate_list2.begin();iter!=canidate_list2.end();++iter)
+
+       for(iter=candidate_list2.begin();iter!=candidate_list2.end();++iter)
        {
-               if(!(iter->category&sinfgapp::Action::CATEGORY_HIDDEN))
+               if(!(iter->category&synfigapp::Action::CATEGORY_HIDDEN))
                {
                        Gtk::Image* image(manage(new Gtk::Image()));
                        Gtk::Stock::lookup(get_action_stock_id(*iter),Gtk::ICON_SIZE_MENU,*image);
@@ -798,9 +868,9 @@ Instance::add_actions_to_menu(Gtk::Menu *menu, const sinfgapp::Action::ParamList
                                Gtk::Stock::lookup(Gtk::Stock::DELETE,Gtk::ICON_SIZE_MENU,*image);
                        else
                        {
-                               Gtk::Stock::lookup(Gtk::StockID("sinfg-"+iter->name),Gtk::ICON_SIZE_MENU,*image) ||
+                               Gtk::Stock::lookup(Gtk::StockID("synfig-"+iter->name),Gtk::ICON_SIZE_MENU,*image) ||
                                Gtk::Stock::lookup(Gtk::StockID("gtk-"+iter->task),Gtk::ICON_SIZE_MENU,*image) ||
-                               Gtk::Stock::lookup(Gtk::StockID("sinfg-"+iter->task),Gtk::ICON_SIZE_MENU,*image);
+                               Gtk::Stock::lookup(Gtk::StockID("synfig-"+iter->task),Gtk::ICON_SIZE_MENU,*image);
                        }
 */
                        menu->items().push_back(
@@ -822,9 +892,9 @@ Instance::add_actions_to_menu(Gtk::Menu *menu, const sinfgapp::Action::ParamList
                }
        }
 
-       for(iter=canidate_list.begin();iter!=canidate_list.end();++iter)
+       for(iter=candidate_list.begin();iter!=candidate_list.end();++iter)
        {
-               if(!(iter->category&sinfgapp::Action::CATEGORY_HIDDEN))
+               if(!(iter->category&synfigapp::Action::CATEGORY_HIDDEN))
                {
                        Gtk::Image* image(manage(new Gtk::Image()));
                        Gtk::Stock::lookup(get_action_stock_id(*iter),Gtk::ICON_SIZE_MENU,*image);
@@ -848,9 +918,9 @@ Instance::add_actions_to_menu(Gtk::Menu *menu, const sinfgapp::Action::ParamList
                                Gtk::Stock::lookup(Gtk::Stock::DELETE,Gtk::ICON_SIZE_MENU,*image);
                        else
                        {
-                               Gtk::Stock::lookup(Gtk::StockID("sinfg-"+iter->name),Gtk::ICON_SIZE_MENU,*image) ||
+                               Gtk::Stock::lookup(Gtk::StockID("synfig-"+iter->name),Gtk::ICON_SIZE_MENU,*image) ||
                                Gtk::Stock::lookup(Gtk::StockID("gtk-"+iter->task),Gtk::ICON_SIZE_MENU,*image) ||
-                               Gtk::Stock::lookup(Gtk::StockID("sinfg-"+iter->task),Gtk::ICON_SIZE_MENU,*image);
+                               Gtk::Stock::lookup(Gtk::StockID("synfig-"+iter->task),Gtk::ICON_SIZE_MENU,*image);
                        }
 */
                        menu->items().push_back(
@@ -874,25 +944,25 @@ Instance::add_actions_to_menu(Gtk::Menu *menu, const sinfgapp::Action::ParamList
 }
 
 void
-Instance::process_action(String name, sinfgapp::Action::ParamList param_list)
+Instance::process_action(synfig::String name, synfigapp::Action::ParamList param_list)
 {
-       assert(sinfgapp::Action::book().count(name));
+       assert(synfigapp::Action::book().count(name));
+
+       synfigapp::Action::BookEntry entry(synfigapp::Action::book().find(name)->second);
 
-       sinfgapp::Action::BookEntry entry(sinfgapp::Action::book().find(name)->second);
-       
-       sinfgapp::Action::Handle action(entry.factory());
+       synfigapp::Action::Handle action(entry.factory());
 
        if(!action)
        {
-               sinfg::error("Bad Action");
+               synfig::error("Bad Action");
                return;
        }
-       
+
        action->set_param_list(param_list);
 
-       sinfgapp::Action::ParamVocab param_vocab(entry.get_param_vocab());
-       sinfgapp::Action::ParamVocab::const_iterator iter;
-       
+       synfigapp::Action::ParamVocab param_vocab(entry.get_param_vocab());
+       synfigapp::Action::ParamVocab::const_iterator iter;
+
        for(iter=param_vocab.begin();iter!=param_vocab.end();++iter)
        {
                if(!iter->get_mutual_exclusion().empty() && param_list.count(iter->get_mutual_exclusion()))
@@ -906,7 +976,7 @@ Instance::process_action(String name, sinfgapp::Action::ParamList param_list)
                {
                        switch(iter->get_type())
                        {
-                       case sinfgapp::Action::Param::TYPE_STRING:
+                       case synfigapp::Action::Param::TYPE_STRING:
                        {
                                String str;
                                if(!studio::App::dialog_entry(entry.local_name, iter->get_local_name()+":"+iter->get_desc(),str))
@@ -915,16 +985,16 @@ Instance::process_action(String name, sinfgapp::Action::ParamList param_list)
                                break;
                        }
                        default:
-                               sinfg::error("Unsupported user-supplied action parameter");
+                               synfig::error("Unsupported user-supplied action parameter");
                                return;
                                break;
                        }
                }
        }
-               
+
        if(!action->is_ready())
        {
-               sinfg::error("Action not ready");
+               synfig::error("Action not ready");
                return;
        }
 
@@ -932,23 +1002,23 @@ Instance::process_action(String name, sinfgapp::Action::ParamList param_list)
 }
 
 void
-Instance::make_param_menu(Gtk::Menu *menu,sinfg::Canvas::Handle canvas, sinfgapp::ValueDesc value_desc, float location)
+Instance::make_param_menu(Gtk::Menu *menu,synfig::Canvas::Handle canvas, synfigapp::ValueDesc value_desc, float location, bool bezier)
 {
        Gtk::Menu& parammenu(*menu);
-       
-       etl::handle<sinfgapp::CanvasInterface> canvas_interface(find_canvas_interface(canvas));
-       
+
+       etl::handle<synfigapp::CanvasInterface> canvas_interface(find_canvas_interface(canvas));
+
        if(!canvas_interface)
                return;
-       
-       sinfgapp::Action::ParamList param_list,param_list2;
+
+       synfigapp::Action::ParamList param_list,param_list2;
        param_list=canvas_interface->generate_param_list(value_desc);
        param_list.add("origin",location);
 
        if(value_desc.get_value_type()==ValueBase::TYPE_BLINEPOINT && value_desc.is_value_node() && ValueNode_Composite::Handle::cast_dynamic(value_desc.get_value_node()))
        {
                param_list2=canvas_interface->generate_param_list(
-                       sinfgapp::ValueDesc(
+                       synfigapp::ValueDesc(
                                ValueNode_Composite::Handle::cast_dynamic(value_desc.get_value_node())
                                ,0
                        )
@@ -956,10 +1026,21 @@ Instance::make_param_menu(Gtk::Menu *menu,sinfg::Canvas::Handle canvas, sinfgapp
                param_list2.add("origin",location);
        }
 
-       
        // Populate the convert menu by looping through
        // the ValueNode book and find the ones that are
        // relevant.
+
+       // show the 'Convert' sub-menu if this valuedesc is anything other than either:
+       //   the 'Index' parameter of a Duplicate layer
+       // or
+       //   a Duplicate ValueNode whose parent is not a (layer or ValueNode)
+       if (!((value_desc.parent_is_layer_param() &&
+                  value_desc.get_layer()->get_name() == "duplicate" &&
+                  value_desc.get_param_name() == "index") ||
+                 (value_desc.is_value_node() &&
+                  ValueNode_Duplicate::Handle::cast_dynamic(value_desc.get_value_node()) &&
+                  !(value_desc.parent_is_layer_param() ||
+                        value_desc.parent_is_value_node()))))
        {
                Gtk::Menu *convert_menu=manage(new Gtk::Menu());
                LinkableValueNode::Book::const_iterator iter;
@@ -971,7 +1052,7 @@ Instance::make_param_menu(Gtk::Menu *menu,sinfg::Canvas::Handle canvas, sinfgapp
                                        sigc::hide_return(
                                                sigc::bind(
                                                        sigc::bind(
-                                                               sigc::mem_fun(*canvas_interface.get(),&sinfgapp::CanvasInterface::convert),
+                                                               sigc::mem_fun(*canvas_interface.get(),&synfigapp::CanvasInterface::convert),
                                                                iter->first
                                                        ),
                                                        value_desc
@@ -981,34 +1062,53 @@ Instance::make_param_menu(Gtk::Menu *menu,sinfg::Canvas::Handle canvas, sinfgapp
                        }
                }
 
-               parammenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::Stock::CONVERT,*convert_menu));                       
+               parammenu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::Stock::CONVERT,*convert_menu));
+       }
+
+       synfigapp::Action::Category categories = synfigapp::Action::CATEGORY_VALUEDESC|synfigapp::Action::CATEGORY_VALUENODE;
+       if (bezier)
+       {
+               categories = categories|synfigapp::Action::CATEGORY_BEZIER;
+
+               const DuckList selected_ducks(find_canvas_view(canvas)->get_work_area()->get_selected_ducks());
+               for(DuckList::const_iterator iter=selected_ducks.begin();iter!=selected_ducks.end();++iter)
+               {
+                       synfigapp::ValueDesc value_desc((*iter)->get_value_desc());
+                       if(value_desc.is_valid())
+                               param_list.add("selected_value_desc",value_desc);
+               }
        }
 
        if(param_list2.empty())
-               add_actions_to_menu(&parammenu, param_list,sinfgapp::Action::CATEGORY_VALUEDESC|sinfgapp::Action::CATEGORY_VALUENODE);
+               add_actions_to_menu(&parammenu, param_list,categories);
        else
-               add_actions_to_menu(&parammenu, param_list2,param_list,sinfgapp::Action::CATEGORY_VALUEDESC|sinfgapp::Action::CATEGORY_VALUENODE);
+               add_actions_to_menu(&parammenu, param_list2,param_list,categories);
 
        if(value_desc.get_value_type()==ValueBase::TYPE_BLINEPOINT && value_desc.is_value_node() && ValueNode_Composite::Handle::cast_dynamic(value_desc.get_value_node()))
        {
-               value_desc=sinfgapp::ValueDesc(ValueNode_Composite::Handle::cast_dynamic(value_desc.get_value_node()),0);
+               value_desc=synfigapp::ValueDesc(ValueNode_Composite::Handle::cast_dynamic(value_desc.get_value_node()),0);
        }
 
        if(value_desc.is_value_node() && ValueNode_Animated::Handle::cast_dynamic(value_desc.get_value_node()))
        {
                ValueNode_Animated::Handle value_node(ValueNode_Animated::Handle::cast_dynamic(value_desc.get_value_node()));
-               
+
                try
                {
+                       // try to find a waypoint at the current time - if we
+                       // can't, we don't want the menu entry - an exception is thrown
                        WaypointList::iterator iter(value_node->find(canvas->get_time()));
+                       std::set<synfig::Waypoint, std::less<UniqueID> > waypoint_set;
+                       waypoint_set.insert(*iter);
+
                        parammenu.items().push_back(Gtk::Menu_Helpers::MenuElem(_("Edit Waypoint"),
                                sigc::bind(
                                        sigc::bind(
                                                sigc::bind(
-                                                       sigc::mem_fun(*find_canvas_view(canvas),&studio::CanvasView::on_waypoint_clicked),
+                                                       sigc::mem_fun(*find_canvas_view(canvas),&studio::CanvasView::on_waypoint_clicked_canvasview),
                                                        -1
                                                ),
-                                               *iter
+                                               waypoint_set
                                        ),
                                        value_desc
                                )
@@ -1021,9 +1121,9 @@ Instance::make_param_menu(Gtk::Menu *menu,sinfg::Canvas::Handle canvas, sinfgapp
 }
 
 void
-edit_several_waypoints(etl::handle<CanvasView> canvas_view, std::list<sinfgapp::ValueDesc> value_desc_list)
+edit_several_waypoints(etl::handle<CanvasView> canvas_view, std::list<synfigapp::ValueDesc> value_desc_list)
 {
-       etl::handle<sinfgapp::CanvasInterface> canvas_interface(canvas_view->canvas_interface());
+       etl::handle<synfigapp::CanvasInterface> canvas_interface(canvas_view->canvas_interface());
 
        Gtk::Dialog dialog(
                "Edit Multiple Waypoints",              // Title
@@ -1035,28 +1135,25 @@ edit_several_waypoints(etl::handle<CanvasView> canvas_view, std::list<sinfgapp::
        widget_waypoint_model.show();
 
        dialog.get_vbox()->pack_start(widget_waypoint_model);
-       
-       
+
        dialog.add_button(Gtk::StockID("gtk-apply"),1);
        dialog.add_button(Gtk::StockID("gtk-cancel"),0);
        dialog.show();
-       
-       DEBUGPOINT();
+
        if(dialog.run()==0 || widget_waypoint_model.get_waypoint_model().is_trivial())
                return;
-       DEBUGPOINT();
-       sinfgapp::Action::PassiveGrouper group(canvas_interface->get_instance().get(),_("Set Waypoints"));
+       synfigapp::Action::PassiveGrouper group(canvas_interface->get_instance().get(),_("Set Waypoints"));
 
-       std::list<sinfgapp::ValueDesc>::iterator iter;
+       std::list<synfigapp::ValueDesc>::iterator iter;
        for(iter=value_desc_list.begin();iter!=value_desc_list.end();++iter)
        {
-               sinfgapp::ValueDesc value_desc(*iter);
-               
+               synfigapp::ValueDesc value_desc(*iter);
+
                if(!value_desc.is_valid())
                        continue;
 
                ValueNode_Animated::Handle value_node;
-               
+
                // If this value isn't a ValueNode_Animated, but
                // it is somewhat constant, then go ahead and convert
                // it to a ValueNode_Animated.
@@ -1067,28 +1164,27 @@ edit_several_waypoints(etl::handle<CanvasView> canvas_view, std::list<sinfgapp::
                                value=ValueNode_Const::Handle::cast_dynamic(value_desc.get_value_node())->get_value();
                        else
                                value=value_desc.get_value();
-                       
+
                        value_node=ValueNode_Animated::create(value,canvas_interface->get_time());
-                       
-                       sinfgapp::Action::Handle action;
-                       
+
+                       synfigapp::Action::Handle action;
+
                        if(!value_desc.is_value_node())
                        {
-                               action=sinfgapp::Action::create("value_desc_connect");
+                               action=synfigapp::Action::create("value_desc_connect");
                                action->set_param("dest",value_desc);
                                action->set_param("src",ValueNode::Handle(value_node));
                        }
                        else
                        {
-                               action=sinfgapp::Action::create("value_node_replace");
+                               action=synfigapp::Action::create("value_node_replace");
                                action->set_param("dest",value_desc.get_value_node());
                                action->set_param("src",ValueNode::Handle(value_node));
                        }
-                       
+
                        action->set_param("canvas",canvas_view->get_canvas());
                        action->set_param("canvas_interface",canvas_interface);
-                       
-       
+
                        if(!canvas_interface->get_instance()->perform_action(action))
                        {
                                canvas_view->get_ui_interface()->error(_("Unable to convert to animated waypoint"));
@@ -1101,12 +1197,10 @@ edit_several_waypoints(etl::handle<CanvasView> canvas_view, std::list<sinfgapp::
                        if(value_desc.is_value_node())
                                value_node=ValueNode_Animated::Handle::cast_dynamic(value_desc.get_value_node());
                }
-               
-               
+
                if(value_node)
                {
-                       
-                       sinfgapp::Action::Handle action(sinfgapp::Action::create("waypoint_set_smart"));
+                       synfigapp::Action::Handle action(synfigapp::Action::create("waypoint_set_smart"));
 
                        if(!action)
                        {
@@ -1114,14 +1208,13 @@ edit_several_waypoints(etl::handle<CanvasView> canvas_view, std::list<sinfgapp::
                                group.cancel();
                                return;
                        }
-                               
 
                        action->set_param("canvas",canvas_view->get_canvas());
-                       action->set_param("canvas_interface",canvas_interface);                 
-                       action->set_param("value_node",ValueNode::Handle(value_node));                  
-                       action->set_param("time",canvas_interface->get_time());                                         
+                       action->set_param("canvas_interface",canvas_interface);
+                       action->set_param("value_node",ValueNode::Handle(value_node));
+                       action->set_param("time",canvas_interface->get_time());
                        action->set_param("model",widget_waypoint_model.get_waypoint_model());
-               
+
                        if(!canvas_interface->get_instance()->perform_action(action))
                        {
                                canvas_view->get_ui_interface()->error(_("Unable to set a specific waypoint"));
@@ -1135,19 +1228,19 @@ edit_several_waypoints(etl::handle<CanvasView> canvas_view, std::list<sinfgapp::
                        //group.cancel();
                        //return;
                }
-                       
+
        }
 }
 
 void
-Instance::make_param_menu(Gtk::Menu *menu,sinfg::Canvas::Handle canvas,const std::list<sinfgapp::ValueDesc>& value_desc_list)
+Instance::make_param_menu(Gtk::Menu *menu,synfig::Canvas::Handle canvas,const std::list<synfigapp::ValueDesc>& value_desc_list)
 {
-       etl::handle<sinfgapp::CanvasInterface> canvas_interface(find_canvas_interface(canvas));
+       etl::handle<synfigapp::CanvasInterface> canvas_interface(find_canvas_interface(canvas));
 
-       sinfgapp::Action::ParamList param_list;
+       synfigapp::Action::ParamList param_list;
        param_list=canvas_interface->generate_param_list(value_desc_list);
 
-       add_actions_to_menu(menu, param_list,sinfgapp::Action::CATEGORY_VALUEDESC|sinfgapp::Action::CATEGORY_VALUENODE);
+       add_actions_to_menu(menu, param_list,synfigapp::Action::CATEGORY_VALUEDESC|synfigapp::Action::CATEGORY_VALUENODE);
 
        // Add the edit waypoints option if that might be useful
        if(canvas->rend_desc().get_time_end()-Time::epsilon()>canvas->rend_desc().get_time_start())