1 /* === S Y N F I G ========================================================= */
2 /*! \file layertreestore.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2008 Chris Moore
11 ** This package is free software; you can redistribute it and/or
12 ** modify it under the terms of the GNU General Public License as
13 ** published by the Free Software Foundation; either version 2 of
14 ** the License, or (at your option) any later version.
16 ** This package is distributed in the hope that it will be useful,
17 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19 ** General Public License for more details.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include "layertreestore.h"
34 #include "iconcontroller.h"
35 #include <gtkmm/button.h>
36 #include <synfig/paramdesc.h>
37 #include <synfigapp/action.h>
38 #include <synfigapp/instance.h>
41 #include <synfig/layer_pastecanvas.h>
42 #include <synfigapp/action_system.h>
44 #include <gtk/gtkversion.h>
50 /* === U S I N G =========================================================== */
54 using namespace synfig;
55 using namespace studio;
57 /* === M A C R O S ========================================================= */
59 /* === G L O B A L S ======================================================= */
61 /* === P R O C E D U R E S ================================================= */
63 /* === M E T H O D S ======================================================= */
65 static LayerTreeStore::Model& ModelHack()
67 static LayerTreeStore::Model* model(0);
68 if(!model)model=new LayerTreeStore::Model;
72 LayerTreeStore::LayerTreeStore(etl::loose_handle<synfigapp::CanvasInterface> canvas_interface_):
73 Gtk::TreeStore (ModelHack()),
75 canvas_interface_ (canvas_interface_)
77 layer_icon=Gtk::Button().render_icon(Gtk::StockID("synfig-layer"),Gtk::ICON_SIZE_SMALL_TOOLBAR);
79 // Connect Signals to Terminals
80 canvas_interface()->signal_layer_status_changed().connect(sigc::mem_fun(*this,&studio::LayerTreeStore::on_layer_status_changed));
81 canvas_interface()->signal_layer_lowered().connect(sigc::mem_fun(*this,&studio::LayerTreeStore::on_layer_lowered));
82 canvas_interface()->signal_layer_raised().connect(sigc::mem_fun(*this,&studio::LayerTreeStore::on_layer_raised));
83 canvas_interface()->signal_layer_removed().connect(sigc::mem_fun(*this,&studio::LayerTreeStore::on_layer_removed));
84 canvas_interface()->signal_layer_inserted().connect(sigc::mem_fun(*this,&studio::LayerTreeStore::on_layer_inserted));
85 canvas_interface()->signal_layer_moved().connect(sigc::mem_fun(*this,&studio::LayerTreeStore::on_layer_moved));
86 //canvas_interface()->signal_layer_param_changed().connect(sigc::mem_fun(*this,&studio::LayerTreeStore::on_layer_param_changed));
87 canvas_interface()->signal_layer_new_description().connect(sigc::mem_fun(*this,&studio::LayerTreeStore::on_layer_new_description));
89 canvas_interface()->signal_time_changed().connect(sigc::mem_fun(*this,&studio::LayerTreeStore::refresh));
91 //canvas_interface()->signal_value_node_changed().connect(sigc::mem_fun(*this,&studio::LayerTreeStore::on_value_node_changed));
92 //canvas_interface()->signal_value_node_added().connect(sigc::mem_fun(*this,&studio::LayerTreeStore::on_value_node_added));
93 //canvas_interface()->signal_value_node_deleted().connect(sigc::mem_fun(*this,&studio::LayerTreeStore::on_value_node_deleted));
94 //canvas_interface()->signal_value_node_replaced().connect(sigc::mem_fun(*this,&studio::LayerTreeStore::on_value_node_replaced));
96 set_default_sort_func(sigc::ptr_fun(index_sorter));
101 LayerTreeStore::~LayerTreeStore()
103 if (getenv("SYNFIG_DEBUG_DESTRUCTORS"))
104 synfig::info("LayerTreeStore::~LayerTreeStore(): Deleted");
108 LayerTreeStore::z_sorter(const Gtk::TreeModel::iterator &rhs,const Gtk::TreeModel::iterator &lhs)
112 float diff((float)(*rhs)[model.z_depth]-(float)(*lhs)[model.z_depth]);
122 LayerTreeStore::index_sorter(const Gtk::TreeModel::iterator &rhs,const Gtk::TreeModel::iterator &lhs)
126 return ((int)(*rhs)[model.index]-(int)(*lhs)[model.index]);
130 LayerTreeStore::search_func(const Glib::RefPtr<TreeModel>&,int,const Glib::ustring& x,const TreeModel::iterator& iter)
134 Glib::ustring substr(x.uppercase());
135 Glib::ustring label((*iter)[model.label]);
136 label=label.uppercase();
138 return label.find(substr)==Glib::ustring::npos;
142 Glib::RefPtr<LayerTreeStore>
143 LayerTreeStore::create(etl::loose_handle<synfigapp::CanvasInterface> canvas_interface_)
145 return Glib::RefPtr<LayerTreeStore>(new LayerTreeStore(canvas_interface_));
149 LayerTreeStore::get_value_vfunc (const Gtk::TreeModel::iterator& iter, int column, Glib::ValueBase& value)const
151 if(column==model.index.index())
153 synfig::Layer::Handle layer((*iter)[model.layer]);
158 g_value_init(x.gobj(),x.value_type());
160 x.set(layer->get_depth());
162 g_value_init(value.gobj(),x.value_type());
163 g_value_copy(x.gobj(),value.gobj());
165 else if(column==model.z_depth.index())
167 synfig::Layer::Handle layer((*iter)[model.layer]);
171 Glib::Value<float> x;
172 g_value_init(x.gobj(),x.value_type());
174 x.set(layer->get_z_depth(canvas_interface()->get_time())*1.0001+layer->get_depth());
176 g_value_init(value.gobj(),x.value_type());
177 g_value_copy(x.gobj(),value.gobj());
179 else if(column==model.children_lock.index())
181 synfig::Layer::Handle layer((*iter)[model.layer]);
186 g_value_init(x.gobj(),x.value_type());
189 ValueBase v(layer->get_param("children_lock"));
190 if(v.same_type_as(bool()))
191 x.set(v.get(bool()));
193 g_value_init(value.gobj(),x.value_type());
194 g_value_copy(x.gobj(),value.gobj());
196 else if(column==model.label.index())
198 synfig::Layer::Handle layer((*iter)[model.layer]);
202 Glib::Value<Glib::ustring> x;
203 g_value_init(x.gobj(),x.value_type());
205 x.set(layer->get_non_empty_description());
207 g_value_init(value.gobj(),x.value_type());
208 //g_value_copy(x.gobj(),value.gobj());
211 else if(column==model.tooltip.index())
213 synfig::Layer::Handle layer((*iter)[model.layer]);
217 Glib::Value<Glib::ustring> x;
218 g_value_init(x.gobj(),x.value_type());
221 x.set(layer->get_local_name());
223 g_value_init(value.gobj(),x.value_type());
224 //g_value_copy(x.gobj(),value.gobj());
227 else if(column==model.canvas.index())
229 synfig::Layer::Handle layer((*iter)[model.layer]);
233 Glib::Value<Canvas::Handle> x;
234 g_value_init(x.gobj(),x.value_type());
237 x.set(layer->get_canvas());
239 g_value_init(value.gobj(),x.value_type());
240 //g_value_copy(x.gobj(),value.gobj());
243 else if(column==model.active.index())
245 synfig::Layer::Handle layer((*iter)[model.layer]);
250 g_value_init(x.gobj(),x.value_type());
252 x.set(layer->active());
254 g_value_init(value.gobj(),x.value_type());
255 g_value_copy(x.gobj(),value.gobj());
257 else if(column==model.icon.index())
259 synfig::Layer::Handle layer((*iter)[model.layer]);
262 Glib::Value<Glib::RefPtr<Gdk::Pixbuf> > x;
263 g_value_init(x.gobj(),x.value_type());
266 x.set(get_tree_pixbuf_layer(layer->get_name()));
268 g_value_init(value.gobj(),x.value_type());
269 g_value_copy(x.gobj(),value.gobj());
272 Gtk::TreeStore::get_value_vfunc(iter,column,value);
276 LayerTreeStore::set_value_impl(const Gtk::TreeModel::iterator& iter, int column, const Glib::ValueBase& value)
278 //if(!iterator_sane(row))
281 if(column>=get_n_columns_vfunc())
283 g_warning("LayerTreeStore::set_value_impl: Bad column (%d)",column);
287 if(!g_value_type_compatible(G_VALUE_TYPE(value.gobj()),get_column_type_vfunc(column)))
289 g_warning("LayerTreeStore::set_value_impl: Bad value type");
295 if(column==model.label.index())
297 Glib::Value<Glib::ustring> x;
298 g_value_init(x.gobj(),model.label.type());
299 g_value_copy(value.gobj(),x.gobj());
301 synfig::Layer::Handle layer((*iter)[model.layer]);
304 synfig::String new_desc(x.get());
306 if(new_desc==layer->get_local_name())
307 new_desc=synfig::String();
309 if(new_desc==layer->get_description())
312 synfigapp::Action::Handle action(synfigapp::Action::create("LayerSetDesc"));
317 action->set_param("canvas",canvas_interface()->get_canvas());
318 action->set_param("canvas_interface",canvas_interface());
319 action->set_param("layer",layer);
320 action->set_param("new_description",synfig::String(x.get()));
322 canvas_interface()->get_instance()->perform_action(action);
325 else if(column==model.active.index())
327 synfig::Layer::Handle layer((*iter)[model.layer]);
332 g_value_init(x.gobj(),model.active.type());
333 g_value_copy(value.gobj(),x.gobj());
335 synfigapp::Action::Handle action(synfigapp::Action::create("LayerActivate"));
340 action->set_param("canvas",canvas_interface()->get_canvas());
341 action->set_param("canvas_interface",canvas_interface());
342 action->set_param("layer",layer);
343 action->set_param("new_status",bool(x.get()));
345 canvas_interface()->get_instance()->perform_action(action);
349 Gtk::TreeStore::set_value_impl(iter,column, value);
352 catch(std::exception x)
354 g_warning("%s", x.what());
362 LayerTreeStore::row_draggable_vfunc (const TreeModel::Path& /*path*/)const
364 //if(!get_iter(path)) return false;
365 // Gtk::TreeModel::Row row(*get_iter(path));
368 // return (bool)true;
372 LayerTreeStore::drag_data_get_vfunc (const TreeModel::Path& path, Gtk::SelectionData& selection_data)const
374 if(!const_cast<LayerTreeStore*>(this)->get_iter(path)) return false;
375 //synfig::info("Dragged data of type \"%s\"",selection_data.get_data_type());
376 //synfig::info("Dragged data of target \"%s\"",gdk_atom_name(selection_data->target));
377 //synfig::info("Dragged selection=\"%s\"",gdk_atom_name(selection_data->selection));
379 Gtk::TreeModel::Row row(*const_cast<LayerTreeStore*>(this)->get_iter(path));
383 Layer* layer(((Layer::Handle)row[model.layer]).get());
385 bool included(false);
387 //gtk_selection_data_set (selection_data, gdk_atom_intern("LAYER",false), 8, reinterpret_cast<const guchar*>(&layer), sizeof(layer));
389 std::vector<Layer*> layers;
390 // The following is a hack for multiple row DND
392 synfigapp::SelectionManager::LayerList bleh(get_canvas_interface()->get_selection_manager()->get_selected_layers());
395 selection_data.set("LAYER", 8, reinterpret_cast<const guchar*>(&layer), sizeof(layer));
400 if(bleh.back().get()==layer)
402 layers.push_back(bleh.back().get());
407 layers.push_back(layer);
408 selection_data.set("LAYER", 8, reinterpret_cast<const guchar*>(&layers.front()), sizeof(void*)*layers.size());
416 LayerTreeStore::drag_data_delete_vfunc (const TreeModel::Path& /*path*/)
422 LayerTreeStore::row_drop_possible_vfunc (const TreeModel::Path& dest, const Gtk::SelectionData& selection_data)const
424 //if(!const_cast<LayerTreeStore*>(this)->get_iter(dest)) return false;
426 //synfig::info("possible_drop -- data of type \"%s\"",selection_data.get_data_type());
427 //synfig::info("possible_drop -- data of target \"%s\"",gdk_atom_name(selection_data->target));
428 //synfig::info("possible_drop -- selection=\"%s\"",gdk_atom_name(selection_data->selection));
430 //Gtk::TreeModel::Row row(*get_iter(dest));
432 if(synfig::String(selection_data.get_data_type())=="LAYER" && (bool)true)
434 //Layer::Handle src(reinterpret_cast<Layer**>(const_cast<guint8*>(selection_data.get_data()))[i]);
438 TreeModel::Path dest_parent(dest);
439 if(!dest_parent.up() || dest.get_depth()==1)
441 //row=(*get_iter(dest));
442 //dest_canvas=(Canvas::Handle)(row[model.canvas]);
445 else if((bool)const_cast<LayerTreeStore*>(this)->get_iter(dest_parent))
446 return (bool)(Canvas::Handle)(*const_cast<LayerTreeStore*>(this)->get_iter(dest_parent))[model.contained_canvas];
452 LayerTreeStore::drag_data_received_vfunc (const TreeModel::Path& dest, const Gtk::SelectionData& selection_data)
455 //if(!dest_parent.up() || !get_iter(dest)) return false;
461 //synfig::info("Dropped data of type \"%s\"",selection_data.get_data_type());
462 //synfig::info("Dropped data of target \"%s\"",gdk_atom_name(selection_data->target));
463 //synfig::info("Dropped selection=\"%s\"",gdk_atom_name(selection_data->selection));
464 synfigapp::Action::PassiveGrouper passive_grouper(canvas_interface()->get_instance().get(),_("Move Layers"));
466 // Save the selection data
467 synfigapp::SelectionManager::LayerList selected_layer_list=canvas_interface()->get_selection_manager()->get_selected_layers();
469 if ((selection_data.get_length() >= 0) && (selection_data.get_format() == 8))
471 Gtk::TreeModel::Row row;
472 Canvas::Handle dest_canvas;
474 int dest_layer_depth=dest.back();
476 TreeModel::Path dest_parent(dest);
477 if(!dest_parent.up() || !get_iter(dest_parent))
479 TreeModel::Path dest_(dest);
487 row=(*get_iter(dest_));
488 dest_canvas=(Canvas::Handle)(row[model.canvas]);
493 row=(*get_iter(dest_parent));
494 dest_canvas=row[model.contained_canvas];
499 Layer::Handle dest_layer(row[model.layer]);
501 if(synfig::String(selection_data.get_data_type())=="LAYER")for(unsigned int i=0;i<selection_data.get_length()/sizeof(void*);i++)
503 //synfig::info("dest_layer_depth=%d",dest_layer_depth);
505 Layer::Handle src(reinterpret_cast<Layer**>(const_cast<guint8*>(selection_data.get_data()))[i]);
510 if(dest_canvas==src->get_canvas() && src->get_depth()<dest_layer_depth)
513 // In this case, we are just moving.
514 // if(dest_canvas==src->get_canvas())
516 //if(dest_canvas==src->get_canvas() && dest_layer_depth && dest_layer_depth>src->get_depth())
517 // dest_layer_depth--;
518 if(dest_canvas==src->get_canvas() && dest_layer_depth==src->get_depth())
521 synfigapp::Action::Handle action(synfigapp::Action::create("LayerMove"));
522 action->set_param("canvas",dest_canvas);
523 action->set_param("canvas_interface",canvas_interface());
524 action->set_param("layer",src);
525 action->set_param("new_index",dest_layer_depth);
526 action->set_param("dest_canvas",dest_canvas);
527 if(canvas_interface()->get_instance()->perform_action(action))
531 passive_grouper.cancel();
536 /*else // In this case we need to remove and then add
539 synfigapp::Action::Handle action;
540 action=synfigapp::Action::create("LayerRemove");
541 action->set_param("canvas",Canvas::Handle(src->get_canvas()));
542 if(!action->set_param("canvas_interface",App::get_instance(src->get_canvas())->find_canvas_interface(src->get_canvas())))
543 action->set_param("canvas_interface",canvas_interface());
544 action->set_param("layer",src);
545 if(!canvas_interface()->get_instance()->perform_action(action))
547 passive_grouper.cancel();
552 action=synfigapp::Action::create("LayerAdd");
553 action->set_param("canvas",dest_canvas);
554 action->set_param("canvas_interface",canvas_interface());
555 action->set_param("new",src);
556 if(!canvas_interface()->get_instance()->perform_action(action))
558 passive_grouper.cancel();
563 if(dest_layer_depth!=0)
565 action=synfigapp::Action::create("LayerMove");
566 action->set_param("canvas",dest_canvas);
567 action->set_param("canvas_interface",canvas_interface());
568 action->set_param("layer",src);
569 action->set_param("new_index",dest_layer_depth);
570 if(!canvas_interface()->get_instance()->perform_action(action))
572 passive_grouper.cancel();
582 synfig::info("I supposedly moved %d layers",i);
584 // Reselect the previously selected layers
585 canvas_interface()->get_selection_manager()->set_selected_layers(selected_layer_list);
591 LayerTreeStore::queue_rebuild()
595 queue_connection.disconnect();
596 queue_connection=Glib::signal_timeout().connect(
598 sigc::mem_fun(*this,&LayerTreeStore::rebuild),
605 LayerTreeStore::rebuild()
607 if (queued) queued = false;
609 // disconnect any subcanvas_changed connections
610 std::map<synfig::Layer::Handle, sigc::connection>::iterator iter;
611 for (iter = subcanvas_changed_connections.begin(); iter != subcanvas_changed_connections.end(); iter++)
612 iter->second.disconnect();
613 subcanvas_changed_connections.clear();
615 //etl::clock timer;timer.reset();
617 //synfig::warning("---------rebuilding layer table---------");
618 // Save the selection data
619 synfigapp::SelectionManager::LayerList layer_list=canvas_interface()->get_selection_manager()->get_selected_layers();
621 // Clear out the current list
624 // Go ahead and add all the layers
626 canvas_interface()->get_canvas()->rbegin(), canvas_interface()->get_canvas()->rend(),
627 sigc::mem_fun(*this, &studio::LayerTreeStore::on_layer_added)
630 // Reselect the previously selected layers
631 if(!layer_list.empty())
632 canvas_interface()->get_selection_manager()->set_selected_layers(layer_list);
634 //synfig::info("LayerTreeStore::rebuild() took %f seconds",float(timer()));
638 LayerTreeStore::refresh()
640 etl::clock timer;timer.reset();
642 Gtk::TreeModel::Children children_(children());
644 Gtk::TreeModel::Children::iterator iter;
646 if(!children_.empty())
647 for(iter = children_.begin(); iter && iter != children_.end(); ++iter)
649 Gtk::TreeRow row=*iter;
652 //synfig::info("LayerTreeStore::refresh() took %f seconds",float(timer()));
656 LayerTreeStore::refresh_row(Gtk::TreeModel::Row &row)
658 Layer::Handle layer=row[model.layer];
661 row[model.name] = layer->get_local_name();
662 if(layer->get_description().empty())
664 row[model.label] = layer->get_local_name();
665 row[model.tooltip] = Glib::ustring("Layer");
669 row[model.label] = layer->get_description();
670 row[model.tooltip] = layer->get_local_name();
675 if(layer->dynamic_param_list().count("z_depth"))
676 row[model.z_depth]=Time::begin();
677 // row_changed(get_path(row),row);
679 Gtk::TreeModel::Children children = row.children();
680 Gtk::TreeModel::Children::iterator iter;
682 if(!children.empty())
683 for(iter = children.begin(); iter && iter != children.end(); ++iter)
685 Gtk::TreeRow row=*iter;
692 LayerTreeStore::set_row_layer(Gtk::TreeRow &row,synfig::Layer::Handle &handle)
694 //row[model.id] = handle->get_name();
695 //row[model.name] = handle->get_local_name();
696 /*if(handle->get_description().empty())
698 //row[model.label] = handle->get_local_name();
699 row[model.tooltip] = Glib::ustring("Layer");
703 //row[model.label] = handle->get_description();
704 row[model.tooltip] = handle->get_local_name();
707 //row[model.active] = handle->active();
708 row[model.layer] = handle;
709 //row[model.canvas] = handle->get_canvas();
710 //row[model.icon] = layer_icon;
712 synfig::Layer::ParamList paramlist=handle->get_param_list();
714 synfig::Layer::Vocab vocab=handle->get_param_vocab();
715 synfig::Layer::Vocab::iterator iter;
717 for(iter=vocab.begin();iter!=vocab.end();++iter)
719 if(iter->get_hidden())
721 if(handle->get_param(iter->get_name()).get_type()!=ValueBase::TYPE_CANVAS)
725 Canvas::Handle canvas;
726 canvas=handle->get_param(iter->get_name()).get(canvas);
730 Canvas::reverse_iterator iter;
731 row[model.contained_canvas]=canvas;
733 for(iter=canvas->rbegin();iter!=canvas->rend();++iter)
735 Gtk::TreeRow row_(*(prepend(row.children())));
736 set_row_layer(row_,*iter);
742 etl::handle<ValueNode> value_node;
743 if(handle.constant()->dynamic_param_list().count(iter->get_name()))
744 value_node=handle->dynamic_param_list()[iter->get_name()];
746 Gtk::TreeRow child_row = *(append(row.children()));
751 iter->get_local_name(),
752 paramlist[iter->get_name()],
761 LayerTreeStore::on_layer_added(synfig::Layer::Handle layer)
763 if (etl::handle<Layer_PasteCanvas>::cast_dynamic(layer))
764 subcanvas_changed_connections[layer] =
765 (etl::handle<Layer_PasteCanvas>::cast_dynamic(layer))->signal_subcanvas_changed().connect(
766 sigc::mem_fun(*this,&studio::LayerTreeStore::queue_rebuild)
771 if(canvas_interface()->get_canvas()==layer->get_canvas())
777 Gtk::TreeModel::Children::iterator iter;
778 if(!find_canvas_row(layer->get_canvas(),iter))
783 row=*(prepend(iter->children()));
785 set_row_layer(row,layer);
789 LayerTreeStore::on_layer_removed(synfig::Layer::Handle handle)
791 if (etl::handle<Layer_PasteCanvas>::cast_dynamic(handle))
793 subcanvas_changed_connections[handle].disconnect();
794 subcanvas_changed_connections.erase(handle);
796 Gtk::TreeModel::Children::iterator iter;
797 if(find_layer_row(handle,iter))
801 synfig::error("LayerTreeStore::on_layer_removed():Unable to find layer to be removed, forced to rebuild...");
807 LayerTreeStore::on_layer_inserted(synfig::Layer::Handle handle,int depth)
811 on_layer_added(handle);
815 Gtk::TreeModel::Children children_(children());
816 if(canvas_interface()->get_canvas()!=handle->get_canvas())
818 Gtk::TreeModel::Children::iterator iter;
819 if(!find_canvas_row(handle->get_canvas(),iter))
821 synfig::error("LayerTreeStore::on_layer_inserted():Unable to find canvas row, forced to rebuild...");
825 children_=iter->children();
828 Gtk::TreeModel::Children::iterator iter(children_.begin());
829 while(depth-- && iter)
832 if(!iter || iter==children_.end())
834 synfig::error("LayerTreeStore::on_layer_inserted():Unable to achieve desired depth, forced to rebuild...");
840 Gtk::TreeModel::Row row(*insert(iter));
841 set_row_layer(row,handle);
845 LayerTreeStore::on_layer_status_changed(synfig::Layer::Handle handle,bool /*x*/)
847 Gtk::TreeModel::Children::iterator iter;
848 if(find_layer_row(handle,iter))
849 (*iter)[model.layer]=handle;
852 synfig::warning("Couldn't find layer to be activated in layer list. Rebuilding index...");
858 LayerTreeStore::on_layer_lowered(synfig::Layer::Handle layer)
860 Gtk::TreeModel::Children::iterator iter, iter2;
861 if(find_layer_row(layer,iter))
863 // Save the selection data
864 //synfigapp::SelectionManager::LayerList layer_list=canvas_interface()->get_selection_manager()->get_selected_layers();
873 //Gtk::TreeModel::Row row(*iter);
874 Gtk::TreeModel::Row row2 = *iter2;
875 synfig::Layer::Handle layer2=row2[model.layer];
879 set_row_layer(row2,layer2);
887 LayerTreeStore::on_layer_raised(synfig::Layer::Handle layer)
889 Gtk::TreeModel::Children::iterator iter, iter2;
891 Gtk::TreeModel::Children children_(children());
893 if(find_layer_row_(layer, canvas_interface()->get_canvas(), children_, iter,iter2))
897 //Gtk::TreeModel::Row row = *iter;
898 Gtk::TreeModel::Row row2 = *iter2;
899 synfig::Layer::Handle layer2=row2[model.layer];
904 set_row_layer(row2,layer2);
914 LayerTreeStore::on_layer_moved(synfig::Layer::Handle layer,int depth, synfig::Canvas::Handle /*canvas*/)
916 on_layer_removed(layer);
917 on_layer_inserted(layer,depth);
921 LayerTreeStore::on_layer_param_changed(synfig::Layer::Handle handle,synfig::String param_name)
923 if(param_name=="z_depth")
925 Gtk::TreeModel::Children::iterator iter;
926 if(find_layer_row(handle,iter))
928 (*iter)[model.z_depth]=Time::begin();
933 Gtk::TreeModel::Children::iterator iter;
934 if(find_layer_row(handle,iter))
936 Gtk::TreeModel::Children children(iter->children());
938 for(iter = children.begin(); iter && iter != children.end(); ++iter)
940 if((Glib::ustring)(*iter)[model.param_name]==param_name)
942 Gtk::TreeRow row=*iter;
953 LayerTreeStore::on_layer_new_description(synfig::Layer::Handle handle,synfig::String desc)
955 Gtk::TreeModel::Children::iterator iter;
956 if(find_layer_row(handle,iter))
958 Gtk::TreeRow row(*iter);
960 Layer::Handle layer(row[model.layer]);
964 //row[model.label]=layer->get_local_name();
965 row[model.tooltip]=Glib::ustring(_("Layer"));
968 //row[model.label]=layer->get_description();
969 row[model.tooltip]=layer->get_local_name();
978 LayerTreeStore::find_canvas_row_(synfig::Canvas::Handle canvas, synfig::Canvas::Handle parent, Gtk::TreeModel::Children layers, Gtk::TreeModel::Children::iterator &iter)
984 for(iter=layers.begin(); iter && iter != layers.end(); ++iter)
986 Gtk::TreeModel::Row row = *iter;
987 if(canvas==(synfig::Canvas::Handle)row[model.contained_canvas])
991 iter=children().end();
995 Gtk::TreeModel::Children::iterator iter2;
996 //Gtk::TreeModel::Children::iterator iter3;
998 for(iter2 = layers.begin(); iter2 && iter2 != layers.end(); ++iter2)
1000 Gtk::TreeModel::Row row = *iter2;
1003 if(row.children().empty())
1006 Canvas::Handle sub_canvas((*row.children().begin())[model.canvas]);
1010 if(find_canvas_row_(canvas,sub_canvas,iter2->children(),iter))
1014 iter=children().end();
1019 LayerTreeStore::find_canvas_row(synfig::Canvas::Handle canvas, Gtk::TreeModel::Children::iterator &iter)
1021 return find_canvas_row_(canvas,canvas_interface()->get_canvas(),children(),iter);
1026 LayerTreeStore::find_layer_row_(const synfig::Layer::Handle &layer, synfig::Canvas::Handle /*canvas*/, Gtk::TreeModel::Children layers, Gtk::TreeModel::Children::iterator &iter, Gtk::TreeModel::Children::iterator &prev)
1030 //if(layer->get_canvas()==canvas)
1032 for(iter=prev=layers.begin(); iter && iter != layers.end(); prev=iter++)
1034 Gtk::TreeModel::Row row = *iter;
1035 if(layer==(synfig::Layer::Handle)row[model.layer])
1039 iter=children().end();
1043 Gtk::TreeModel::Children::iterator iter2;
1045 for(iter2 = layers.begin(); iter2 && iter2 != layers.end(); ++iter2)
1047 Gtk::TreeModel::Row row = *iter2;
1050 if(row.children().empty())
1053 Canvas::Handle canvas((*row.children().begin())[model.canvas]);
1057 if(find_layer_row_(layer,canvas,iter2->children(),iter,prev))
1061 iter=children().end();
1066 LayerTreeStore::find_layer_row(const synfig::Layer::Handle &layer, Gtk::TreeModel::Children::iterator &iter)
1068 Gtk::TreeModel::Children::iterator prev;
1069 return find_layer_row_(layer,canvas_interface()->get_canvas(),children(),iter,prev);
1073 LayerTreeStore::find_prev_layer_row(const synfig::Layer::Handle &layer, Gtk::TreeModel::Children::iterator &prev)
1075 Gtk::TreeModel::Children::iterator iter;
1076 if(!find_layer_row_(layer,canvas_interface()->get_canvas(),children(),iter,prev))
1078 if(iter==children().begin())