1 /* === S Y N F I G ========================================================= */
2 /*! \file layergrouptreestore.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 "layergrouptreestore.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 <synfigapp/action_system.h>
42 #include "dockmanager.h"
45 #include <gtk/gtkversion.h>
51 /* === U S I N G =========================================================== */
55 using namespace synfig;
56 using namespace studio;
58 /* === M A C R O S ========================================================= */
60 #define GROUP_NEST_CHAR '.'
62 /* === G L O B A L S ======================================================= */
64 /* === P R O C E D U R E S ================================================= */
66 /* === M E T H O D S ======================================================= */
68 static LayerGroupTreeStore::Model& ModelHack()
70 static LayerGroupTreeStore::Model* model(0);
71 if(!model)model=new LayerGroupTreeStore::Model;
75 LayerGroupTreeStore::LayerGroupTreeStore(etl::loose_handle<synfigapp::CanvasInterface> canvas_interface_):
76 Gtk::TreeStore (ModelHack()),
77 canvas_interface_ (canvas_interface_)
79 layer_icon=Gtk::Button().render_icon(Gtk::StockID("synfig-layer"),Gtk::ICON_SIZE_SMALL_TOOLBAR);
80 group_icon=Gtk::Button().render_icon(Gtk::StockID("synfig-group"),Gtk::ICON_SIZE_SMALL_TOOLBAR);
82 // Connect Signals to Terminals
83 canvas_interface()->signal_layer_status_changed().connect(sigc::mem_fun(*this,&studio::LayerGroupTreeStore::on_layer_status_changed));
84 canvas_interface()->signal_layer_new_description().connect(sigc::mem_fun(*this,&studio::LayerGroupTreeStore::on_layer_new_description));
86 canvas_interface()->get_canvas()->signal_group_added().connect(sigc::hide_return(sigc::mem_fun(*this,&studio::LayerGroupTreeStore::on_group_added)));
87 canvas_interface()->get_canvas()->signal_group_removed().connect(sigc::hide_return(sigc::mem_fun(*this,&studio::LayerGroupTreeStore::on_group_removed)));
88 canvas_interface()->get_canvas()->signal_group_changed().connect(sigc::hide_return(sigc::mem_fun(*this,&studio::LayerGroupTreeStore::on_group_changed)));
90 canvas_interface()->get_canvas()->signal_group_pair_added().connect(sigc::hide_return(sigc::mem_fun(*this,&studio::LayerGroupTreeStore::on_group_pair_added)));
91 canvas_interface()->get_canvas()->signal_group_pair_removed().connect(sigc::hide_return(sigc::mem_fun(*this,&studio::LayerGroupTreeStore::on_group_pair_removed)));
96 LayerGroupTreeStore::~LayerGroupTreeStore()
100 if (getenv("SYNFIG_DEBUG_DESTRUCTORS"))
101 synfig::info("LayerGroupTreeStore::~LayerGroupTreeStore(): Deleted");
105 LayerGroupTreeStore::search_func(const Glib::RefPtr<TreeModel>&,int,const Glib::ustring& x,const TreeModel::iterator& iter)
109 Glib::ustring substr(x.uppercase());
110 Glib::ustring label((*iter)[model.label]);
111 label=label.uppercase();
113 return label.find(substr)==Glib::ustring::npos;
117 Glib::RefPtr<LayerGroupTreeStore>
118 LayerGroupTreeStore::create(etl::loose_handle<synfigapp::CanvasInterface> canvas_interface_)
120 return Glib::RefPtr<LayerGroupTreeStore>(new LayerGroupTreeStore(canvas_interface_));
124 LayerGroupTreeStore::get_value_vfunc (const Gtk::TreeModel::iterator& iter, int column, Glib::ValueBase& value)const
126 if(column==model.child_layers.index())
128 Glib::Value<LayerList> x;
129 g_value_init(x.gobj(),x.value_type());
131 if((bool)(*iter)[model.is_group])
133 set<Layer::Handle> layer_set(canvas_interface()->get_canvas()->get_layers_in_group((Glib::ustring)(*iter)[model.group_name]));
135 x.set(LayerList(layer_set.begin(),layer_set.end()));
137 else if((bool)(*iter)[model.is_layer])
139 LayerList layer_list;
140 layer_list.push_back((Layer::Handle)(*iter)[model.layer]);
144 g_value_init(value.gobj(),x.value_type());
147 else if(column==model.all_layers.index())
149 Glib::Value<LayerList> x;
150 g_value_init(x.gobj(),x.value_type());
152 if((bool)(*iter)[model.is_group])
154 LayerList layer_list;
155 Gtk::TreeModel::iterator child_iter(iter->children().begin());
156 for(;child_iter;++child_iter)
158 LayerList layer_list2((LayerList)(*child_iter)[model.all_layers]);
159 for(;layer_list2.size();layer_list2.pop_front())
160 layer_list.push_back(layer_list2.front());
164 else if((bool)(*iter)[model.is_layer])
166 LayerList layer_list;
167 layer_list.push_back((Layer::Handle)(*iter)[model.layer]);
171 g_value_init(value.gobj(),x.value_type());
174 else if(column==model.group_name.index())
176 if((bool)(*iter)[model.is_group])
177 return Gtk::TreeStore::get_value_vfunc(iter,column,value);
178 return get_value_vfunc(iter->parent(),column,value);
180 else if(column==model.parent_group_name.index())
183 return get_value_vfunc(iter->parent(),model.group_name.index(),value);
184 Glib::Value<Glib::ustring> x;
185 g_value_init(x.gobj(),x.value_type());
186 x.set(Glib::ustring());
187 g_value_init(value.gobj(),x.value_type());
190 else if(column==model.label.index())
192 if((bool)(*iter)[model.is_group])
194 Glib::Value<Glib::ustring> x;
195 g_value_init(x.gobj(),x.value_type());
197 Glib::ustring group_name((*iter)[model.group_name]);
199 // Get rid of any parent group crap
200 while(group_name.find(GROUP_NEST_CHAR)!=Glib::ustring::npos)
201 group_name=Glib::ustring(group_name,group_name.find(GROUP_NEST_CHAR)+1,Glib::ustring::npos);
205 g_value_init(value.gobj(),x.value_type());
209 else if((bool)(*iter)[model.is_layer])
211 synfig::Layer::Handle layer((*iter)[model.layer]);
215 Glib::Value<Glib::ustring> x;
216 g_value_init(x.gobj(),x.value_type());
218 x.set(layer->get_non_empty_description());
220 g_value_init(value.gobj(),x.value_type());
221 //g_value_copy(x.gobj(),value.gobj());
226 if(column==model.tooltip.index())
228 synfig::Layer::Handle layer((*iter)[model.layer]);
232 Glib::Value<Glib::ustring> x;
233 g_value_init(x.gobj(),x.value_type());
236 x.set(layer->get_local_name());
238 g_value_init(value.gobj(),x.value_type());
239 //g_value_copy(x.gobj(),value.gobj());
243 if(column==model.canvas.index())
245 synfig::Layer::Handle layer((*iter)[model.layer]);
249 Glib::Value<Canvas::Handle> x;
250 g_value_init(x.gobj(),x.value_type());
253 x.set(layer->get_canvas());
255 g_value_init(value.gobj(),x.value_type());
256 //g_value_copy(x.gobj(),value.gobj());
260 if(column==model.active.index())
263 g_value_init(x.gobj(),x.value_type());
265 if((bool)(*iter)[model.is_layer])
267 synfig::Layer::Handle layer((*iter)[model.layer]);
268 x.set(layer->active());
270 else if((bool)(*iter)[model.is_group])
272 int activecount(0),total(0);
273 Gtk::TreeModel::iterator child_iter(iter->children().begin());
274 for(;child_iter;++child_iter)
277 if((*child_iter)[model.active])
280 x.set(activecount>total/2);
285 g_value_init(value.gobj(),x.value_type());
286 g_value_copy(x.gobj(),value.gobj());
289 if(column==model.icon.index())
291 Glib::Value<Glib::RefPtr<Gdk::Pixbuf> > x;
292 g_value_init(x.gobj(),x.value_type());
294 if((bool)(*iter)[model.is_layer])
296 synfig::Layer::Handle layer((*iter)[model.layer]);
299 x.set(get_tree_pixbuf_layer(layer->get_name()));
301 if((bool)(*iter)[model.is_group])
304 g_value_init(value.gobj(),x.value_type());
305 g_value_copy(x.gobj(),value.gobj());
308 Gtk::TreeStore::get_value_vfunc(iter,column,value);
312 LayerGroupTreeStore::set_value_impl(const Gtk::TreeModel::iterator& iter, int column, const Glib::ValueBase& value)
314 //if(!iterator_sane(row))
317 if(column>=get_n_columns_vfunc())
319 g_warning("LayerGroupTreeStore::set_value_impl: Bad column (%d)",column);
323 if(!g_value_type_compatible(G_VALUE_TYPE(value.gobj()),get_column_type_vfunc(column)))
325 g_warning("LayerGroupTreeStore::set_value_impl: Bad value type");
331 if(column==model.label.index())
333 Glib::Value<Glib::ustring> x;
334 g_value_init(x.gobj(),model.label.type());
335 g_value_copy(value.gobj(),x.gobj());
337 if((bool)(*iter)[model.is_layer])
339 synfig::Layer::Handle layer((*iter)[model.layer]);
342 synfig::String new_desc(x.get());
344 if(new_desc==layer->get_local_name())
345 new_desc=synfig::String();
347 if(new_desc==layer->get_description())
350 synfigapp::Action::Handle action(synfigapp::Action::create("LayerSetDesc"));
355 action->set_param("canvas",canvas_interface()->get_canvas());
356 action->set_param("canvas_interface",canvas_interface());
357 action->set_param("layer",layer);
358 action->set_param("new_description",synfig::String(x.get()));
360 canvas_interface()->get_instance()->perform_action(action);
363 else if((bool)(*iter)[model.is_group])
365 synfig::String group((Glib::ustring)(*iter)[model.label]);
366 synfig::String new_group(x.get());
371 Glib::ustring group_name((*iter)[model.group_name]);
375 // Get rid of any parent group crap
376 while(group_name.find(GROUP_NEST_CHAR)!=Glib::ustring::npos)
378 new_group+=Glib::ustring(group_name,0,group_name.find(GROUP_NEST_CHAR)+1);
379 group_name=Glib::ustring(group_name,group_name.find(GROUP_NEST_CHAR)+1,Glib::ustring::npos);
383 synfig::info("Renaming group \"%s\" to \"%s\"...",group.c_str(),new_group.c_str());
385 // Check to see if this group is real or not.
386 // If it isn't real, then renaming it is a cinch.
387 // We know it isn't real if it doesn't have any
389 if(iter->children().empty())
391 (*iter)[model.group_name]=new_group;
395 synfigapp::Action::Handle action(synfigapp::Action::create("GroupRename"));
400 action->set_param("canvas",canvas_interface()->get_canvas());
401 action->set_param("canvas_interface",canvas_interface());
402 action->set_param("group",group);
403 action->set_param("new_group",new_group);
405 canvas_interface()->get_instance()->perform_action(action);
412 if(column==model.active.index())
415 g_value_init(x.gobj(),model.active.type());
416 g_value_copy(value.gobj(),x.gobj());
418 if((bool)(*iter)[model.is_layer])
420 synfig::Layer::Handle layer((*iter)[model.layer]);
423 synfigapp::Action::Handle action(synfigapp::Action::create("LayerActivate"));
428 action->set_param("canvas",canvas_interface()->get_canvas());
429 action->set_param("canvas_interface",canvas_interface());
430 action->set_param("layer",layer);
431 action->set_param("new_status",bool(x.get()));
434 canvas_interface()->get_instance()->perform_action(action);
437 else if(!iter->children().empty())
439 synfigapp::Action::PassiveGrouper group(
440 get_canvas_interface()->get_instance().get(),
442 x.get()?_("Activate "):_("Deactivate ")
443 )+(Glib::ustring)(*iter)[model.label]
446 Gtk::TreeModel::iterator child_iter(iter->children().begin());
448 for(;child_iter;++child_iter)
449 (*child_iter)[model.active]=x.get();
451 Gtk::TreeStore::set_value_impl(iter,column, value);
455 Gtk::TreeStore::set_value_impl(iter,column, value);
458 catch(std::exception x)
460 g_warning("%s", x.what());
468 LayerGroupTreeStore::row_draggable_vfunc (const TreeModel::Path& /*path*/)const
470 //if(!get_iter(path)) return false;
471 // Gtk::TreeModel::Row row(*get_iter(path));
474 // return (bool)true;
478 LayerGroupTreeStore::drag_data_get_vfunc (const TreeModel::Path& path, Gtk::SelectionData& selection_data)const
480 if(!const_cast<LayerGroupTreeStore*>(this)->get_iter(path)) return false;
481 //synfig::info("Dragged data of type \"%s\"",selection_data.get_data_type());
482 //synfig::info("Dragged data of target \"%s\"",gdk_atom_name(selection_data->target));
483 //synfig::info("Dragged selection=\"%s\"",gdk_atom_name(selection_data->selection));
485 Gtk::TreeModel::Row row(*const_cast<LayerGroupTreeStore*>(this)->get_iter(path));
487 if((bool)row[model.is_layer])
489 Layer* layer(((Layer::Handle)row[model.layer]).get());
492 std::vector<Layer*> layers;
494 layers.push_back(layer);
496 selection_data.set("LAYER", 8, reinterpret_cast<const guchar*>(&layers.front()), sizeof(void*)*layers.size());
500 else if((bool)row[model.is_group])
502 synfig::String group((Glib::ustring)row[model.group_name]);
506 selection_data.set("GROUP", 8, reinterpret_cast<const guchar*>(&*group.begin()), sizeof(void*)*group.size());
515 LayerGroupTreeStore::drag_data_delete_vfunc (const TreeModel::Path& /*path*/)
521 LayerGroupTreeStore::row_drop_possible_vfunc (const TreeModel::Path& dest, const Gtk::SelectionData& selection_data)const
523 Gtk::TreeIter iter(const_cast<LayerGroupTreeStore*>(this)->get_iter(dest));
524 if(!iter) return false;
526 if(synfig::String(selection_data.get_data_type())=="LAYER")
529 if(synfig::String(selection_data.get_data_type())=="GROUP")
531 synfig::String dest_group((Glib::ustring)(*iter)[model.group_name]);
532 synfig::String src_group(reinterpret_cast<const gchar*>(selection_data.get_data()));
533 //synfig::String src_group(const_cast<gchar*>(selection_data.get_data()));
535 // Avoid putting a group inside of itself
536 if(dest_group.size()>src_group.size() && src_group==String(dest_group,0,src_group.size()))
542 //synfig::info("possible_drop -- data of type \"%s\"",selection_data.get_data_type());
543 //synfig::info("possible_drop -- data of target \"%s\"",gdk_atom_name(selection_data->target));
544 //synfig::info("possible_drop -- selection=\"%s\"",gdk_atom_name(selection_data->selection));
546 //Gtk::TreeModel::Row row(*get_iter(dest));
548 /* if(synfig::String(selection_data.get_data_type())=="LAYER" && (bool)true)
555 LayerGroupTreeStore::drag_data_received_vfunc (const TreeModel::Path& dest, const Gtk::SelectionData& selection_data)
557 if(!get_iter(dest)) return false;
561 Gtk::TreeModel::Row row(*get_iter(dest));
563 //synfig::info("Dropped data of type \"%s\"",selection_data.get_data_type());
564 //synfig::info("Dropped data of target \"%s\"",gdk_atom_name(selection_data->target));
565 //synfig::info("Dropped selection=\"%s\"",gdk_atom_name(selection_data->selection));
566 synfigapp::Action::PassiveGrouper passive_grouper(canvas_interface()->get_instance().get(),_("Regroup"));
568 if ((selection_data.get_length() >= 0) && (selection_data.get_format() == 8))
570 synfig::String dest_group;
572 dest_group=(Glib::ustring)row[model.group_name];
574 if(dest_group.empty())
577 if(synfig::String(selection_data.get_data_type())=="LAYER")
579 synfigapp::Action::Handle action(synfigapp::Action::create("GroupAddLayers"));
584 action->set_param("canvas",canvas_interface()->get_canvas());
585 action->set_param("canvas_interface",canvas_interface());
586 action->set_param("group",dest_group);
588 for(unsigned int i=0;i<selection_data.get_length()/sizeof(void*);i++)
590 Layer::Handle layer(reinterpret_cast<Layer**>(const_cast<guint8*>(selection_data.get_data()))[i]);
593 action->set_param("layer",layer);
595 if(!canvas_interface()->get_instance()->perform_action(action))
597 passive_grouper.cancel();
602 if(synfig::String(selection_data.get_data_type())=="GROUP")
604 synfig::String src_group(reinterpret_cast<const gchar*>(selection_data.get_data()));
605 synfig::String group(src_group);
607 // Get rid of any parent group crap
608 while(group.find(GROUP_NEST_CHAR)!=Glib::ustring::npos)
609 group=Glib::ustring(group,group.find(GROUP_NEST_CHAR)+1,Glib::ustring::npos);
611 group=dest_group+GROUP_NEST_CHAR+group;
613 synfigapp::Action::Handle action(synfigapp::Action::create("GroupRename"));
618 action->set_param("canvas",canvas_interface()->get_canvas());
619 action->set_param("canvas_interface",canvas_interface());
620 action->set_param("group",src_group);
621 action->set_param("new_group",group);
623 if(!canvas_interface()->get_instance()->perform_action(action))
625 passive_grouper.cancel();
631 /* // Save the selection data
632 synfigapp::SelectionManager::LayerList selected_layer_list=canvas_interface()->get_selection_manager()->get_selected_layers();
634 if ((selection_data.get_length() >= 0) && (selection_data.get_format() == 8))
636 Canvas::Handle dest_canvas;
637 Layer::Handle dest_layer;
639 dest_canvas=(Canvas::Handle)(row[model.canvas]);
640 dest_layer=(Layer::Handle)(row[model.layer]);
646 int dest_layer_depth=dest_layer->get_depth();
648 if(synfig::String(selection_data.get_data_type())=="LAYER")for(i=0;i<selection_data.get_length()/sizeof(void*);i++)
650 //synfig::info("dest_layer_depth=%d",dest_layer_depth);
652 Layer::Handle src(reinterpret_cast<Layer**>(const_cast<guint8*>(selection_data.get_data()))[i]);
657 // In this case, we are just moving.
658 // if(dest_canvas==src->get_canvas())
660 if(dest_canvas==src->get_canvas() && dest_layer_depth && dest_layer_depth>src->get_depth())
662 if(dest_canvas==src->get_canvas() && dest_layer_depth==src->get_depth())
665 synfigapp::Action::Handle action(synfigapp::Action::create("LayerMove"));
666 action->set_param("canvas",dest_canvas);
667 action->set_param("canvas_interface",canvas_interface());
668 action->set_param("layer",src);
669 action->set_param("new_index",dest_layer_depth);
670 action->set_param("dest_canvas",dest_canvas);
671 if(canvas_interface()->get_instance()->perform_action(action))
677 passive_grouper.cancel();
684 synfig::info("I supposedly moved %d layers",i);
686 // Reselect the previously selected layers
687 canvas_interface()->get_selection_manager()->set_selected_layers(selected_layer_list);
701 LayerGroupTreeStore::rebuild()
704 // etl::clock timer;timer.reset();
707 // Clear out the current list
709 Canvas::Handle canvas(canvas_interface()->get_canvas());
710 std::set<String> groups(canvas->get_groups());
711 for(;groups.size();groups.erase(groups.begin()))
713 String group(*groups.begin());
714 Gtk::TreeRow row(on_group_added(group));
715 std::set<Layer::Handle> layers(canvas->get_layers_in_group(group));
717 for(;layers.size();layers.erase(layers.begin()))
719 Gtk::TreeRow layer_row(*(prepend(row.children())));
720 Layer::Handle layer(*layers.begin());
721 set_row_layer(layer_row,layer);
725 // Go ahead and add all the layers
727 canvas_interface()->get_canvas()->rbegin(), canvas_interface()->get_canvas()->rend(),
728 sigc::mem_fun(*this, &studio::LayerGroupTreeStore::on_layer_added)
737 // synfig::info("LayerGroupTreeStore::rebuild() took %f seconds",float(timer()));
741 LayerGroupTreeStore::refresh()
747 LayerGroupTreeStore::refresh_row(Gtk::TreeModel::Row &row)
749 if((bool)row[model.is_layer])
751 Layer::Handle layer=row[model.layer];
754 //if(layer->dynamic_param_list().count("z_depth"))
755 // row[model.z_depth]=Time::begin();
758 Gtk::TreeModel::Children children = row.children();
759 Gtk::TreeModel::Children::iterator iter;
761 if(!children.empty())
762 for(iter = children.begin(); iter && iter != children.end(); ++iter)
764 Gtk::TreeRow row=*iter;
771 LayerGroupTreeStore::set_row_layer(Gtk::TreeRow &row,synfig::Layer::Handle &handle)
773 row[model.is_layer] = true;
774 row[model.is_group] = false;
775 row[model.layer] = handle;
779 LayerGroupTreeStore::on_group_added(synfig::String group)
781 // Check to see if this group perhaps already
784 Gtk::TreeModel::Children::iterator iter;
785 if(find_group_row(group, iter))
789 if(group.find(GROUP_NEST_CHAR)!=String::npos)
791 Gtk::TreeModel::Children::iterator iter;
795 if(parent_name.size())
796 parent_name+=GROUP_NEST_CHAR;
797 parent_name+=string(group,0,group.find(GROUP_NEST_CHAR));
799 if(!find_group_row(parent_name, iter))
800 iter=on_group_added(parent_name);
802 group=String(group,group.find(GROUP_NEST_CHAR)+1,String::npos);
803 }while(group.find(GROUP_NEST_CHAR)!=String::npos);
805 if(parent_name.size())
806 parent_name+=GROUP_NEST_CHAR;
811 Gtk::TreeRow row(*(prepend(iter->children())));
812 row[model.group_name]=parent_name;
813 row[model.is_layer]=false;
814 row[model.is_group]=true;
820 Gtk::TreeRow row(*(append()));
821 row[model.group_name]=group;
822 row[model.is_layer]=false;
823 row[model.is_group]=true;
829 LayerGroupTreeStore::on_group_removed(synfig::String group)
831 Gtk::TreeModel::Children::iterator iter;
832 if(find_group_row(group,iter) && iter->children().size()==0)
841 LayerGroupTreeStore::on_group_changed(synfig::String /*group*/)
847 LayerGroupTreeStore::on_group_pair_added(synfig::String group, etl::handle<synfig::Layer> layer)
849 if(!layer->get_canvas())
851 Gtk::TreeModel::Children::iterator iter;
852 if(!find_group_row(group, iter))
853 iter=on_group_added(group);
855 Gtk::TreeRow layer_row(*(append(iter->children())));
856 set_row_layer(layer_row,layer);
861 LayerGroupTreeStore::on_group_pair_removed(synfig::String group, etl::handle<synfig::Layer> layer)
863 if(!layer->get_canvas())
865 Gtk::TreeModel::Children::iterator iter;
866 if(!find_group_row(group, iter))
869 Gtk::TreeModel::Children::iterator prev,layer_iter;
871 if(!find_layer_row_(layer, layer->get_canvas(), iter->children(), layer_iter, prev))
880 LayerGroupTreeStore::on_activity()
882 // If we aren't rebuilding and the last action
883 // had something to do with groups, then go
884 // a head and present the groups dialog.
885 if(!rebuilding && canvas_interface()->get_instance()->get_most_recent_action() && canvas_interface()->get_instance()->get_most_recent_action()->get_name().find("Group")!=String::npos)
888 App::dock_manager->find_dockable("groups").present();
894 LayerGroupTreeStore::on_layer_status_changed(synfig::Layer::Handle handle,bool /*x*/)
896 Gtk::TreeModel::Children::iterator iter;
897 if(find_layer_row(handle,iter))
898 (*iter)[model.layer]=handle;
901 // Not need to send a warning when a layer changes its status and
902 // it is not found in any group.
903 //synfig::warning("Couldn't find layer to be activated in layer list. Rebuilding index...");
910 LayerGroupTreeStore::on_layer_new_description(synfig::Layer::Handle handle,synfig::String desc)
912 Gtk::TreeModel::Children::iterator iter;
913 if(find_layer_row(handle,iter))
915 Gtk::TreeRow row(*iter);
917 Layer::Handle layer(row[model.layer]);
921 //row[model.label]=layer->get_local_name();
922 row[model.tooltip]=Glib::ustring(_("Layer"));
925 //row[model.label]=layer->get_description();
926 row[model.tooltip]=layer->get_local_name();
935 LayerGroupTreeStore::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)
939 //if(layer->get_canvas()==canvas)
941 for(iter=prev=layers.begin(); iter && iter != layers.end(); prev=iter++)
943 Gtk::TreeModel::Row row = *iter;
944 if((bool)row[model.is_layer] && layer==(synfig::Layer::Handle)row[model.layer])
948 iter=children().end();
952 Gtk::TreeModel::Children::iterator iter2;
954 for(iter2 = layers.begin(); iter2 && iter2 != layers.end(); ++iter2)
956 Gtk::TreeModel::Row row = *iter2;
959 if(row.children().empty())
962 /*Canvas::Handle canvas((*row.children().begin())[model.canvas]);
967 if(find_layer_row_(layer,canvas,iter2->children(),iter,prev))
971 iter=children().end();
976 LayerGroupTreeStore::find_layer_row(const synfig::Layer::Handle &layer, Gtk::TreeModel::Children::iterator &iter)
978 Gtk::TreeModel::Children::iterator prev;
979 return find_layer_row_(layer,canvas_interface()->get_canvas(),children(),iter,prev);
983 LayerGroupTreeStore::find_group_row(const synfig::String &group, Gtk::TreeModel::Children::iterator &iter)
985 Gtk::TreeModel::Children::iterator prev;
986 return find_group_row_(group,children(),iter,prev);
990 LayerGroupTreeStore::find_group_row_(const synfig::String &group, Gtk::TreeModel::Children layers, Gtk::TreeModel::Children::iterator &iter, Gtk::TreeModel::Children::iterator &prev)
992 //if(layer->get_canvas()==canvas)
994 for(iter=prev=layers.begin(); iter && iter != layers.end(); prev=iter++)
996 Gtk::TreeModel::Row row = *iter;
997 if((bool)row[model.is_group] && group==(Glib::ustring)row[model.group_name])
1001 iter=children().end();
1005 Gtk::TreeModel::Children::iterator iter2;
1007 for(iter2 = layers.begin(); iter2 && iter2 != layers.end(); ++iter2)
1009 Gtk::TreeModel::Row row = *iter2;
1012 if(row.children().empty())
1015 if(find_group_row_(group,iter2->children(),iter,prev))
1019 iter=children().end();
1024 LayerGroupTreeStore::find_prev_layer_row(const synfig::Layer::Handle &layer, Gtk::TreeModel::Children::iterator &prev)
1026 Gtk::TreeModel::Children::iterator iter;
1027 if(!find_layer_row_(layer,canvas_interface()->get_canvas(),children(),iter,prev))
1029 if(iter==children().begin())