1 /* === S Y N F I G ========================================================= */
2 /*! \file historytreestore.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 "trees/historytreestore.h"
34 #include <synfig/valuenode.h>
35 #include "iconcontroller.h"
36 #include <synfig/valuenode_timedswap.h>
37 #include <gtkmm/button.h>
38 #include <synfigapp/action.h>
45 /* === U S I N G =========================================================== */
49 using namespace synfig;
50 using namespace studio;
52 /* === M A C R O S ========================================================= */
54 /* === G L O B A L S ======================================================= */
56 /* === P R O C E D U R E S ================================================= */
58 /* === M E T H O D S ======================================================= */
60 static HistoryTreeStore::Model& ModelHack()
62 static HistoryTreeStore::Model* model(0);
63 if(!model)model=new HistoryTreeStore::Model;
67 HistoryTreeStore::HistoryTreeStore(etl::loose_handle<studio::Instance> instance_):
68 Gtk::TreeStore (ModelHack()),
71 instance_->signal_undo().connect(sigc::mem_fun(*this,&studio::HistoryTreeStore::on_undo));
72 instance_->signal_redo().connect(sigc::mem_fun(*this,&studio::HistoryTreeStore::on_redo));
73 instance_->signal_undo_stack_cleared().connect(sigc::mem_fun(*this,&studio::HistoryTreeStore::on_undo_stack_cleared));
74 instance_->signal_redo_stack_cleared().connect(sigc::mem_fun(*this,&studio::HistoryTreeStore::on_redo_stack_cleared));
75 instance_->signal_new_action().connect(sigc::mem_fun(*this,&studio::HistoryTreeStore::on_new_action));
76 instance_->signal_action_status_changed().connect(sigc::mem_fun(*this,&studio::HistoryTreeStore::on_action_status_changed));
79 HistoryTreeStore::~HistoryTreeStore()
81 if (getenv("SYNFIG_DEBUG_DESTRUCTORS"))
82 synfig::info("HistoryTreeStore::~HistoryTreeStore(): Deleted");
85 Glib::RefPtr<HistoryTreeStore>
86 HistoryTreeStore::create(etl::loose_handle<studio::Instance> instance_)
88 return Glib::RefPtr<HistoryTreeStore>(new HistoryTreeStore(instance_));
92 HistoryTreeStore::rebuild()
94 synfigapp::Action::Stack::const_iterator iter;
98 for(iter=instance()->undo_action_stack().begin();iter!=instance()->undo_action_stack().end();++iter)
100 insert_action(*(prepend()),*iter,true,true,false);
102 curr_row=*children().end();
103 for(iter=instance()->redo_action_stack().begin();iter!=instance()->redo_action_stack().end();++iter)
105 insert_action(*(append()),*iter,true,false,true);
108 signal_undo_tree_changed()();
112 HistoryTreeStore::insert_action(Gtk::TreeRow row,etl::handle<synfigapp::Action::Undoable> action, bool /*is_active*/, bool is_undo, bool is_redo)
116 row[model.action] = action;
117 row[model.name] = static_cast<Glib::ustring>(action->get_local_name());
118 row[model.is_active] = action->is_active();
119 row[model.is_undo] = is_undo;
120 row[model.is_redo] = is_redo;
122 synfigapp::Action::CanvasSpecific *specific_action;
123 specific_action=dynamic_cast<synfigapp::Action::CanvasSpecific*>(action.get());
126 row[model.canvas] = specific_action->get_canvas();
127 row[model.canvas_id] = specific_action->get_canvas()->get_id();
130 etl::handle<synfigapp::Action::Group> group;
131 group=etl::handle<synfigapp::Action::Group>::cast_dynamic(action);
134 synfigapp::Action::ActionList::const_iterator iter;
135 for(iter=group->action_list().begin();iter!=group->action_list().end();++iter)
137 Gtk::TreeRow child_row = *(append(row.children()));
138 insert_action(child_row,*iter,true,is_undo,is_redo);
142 //row[model.icon] = Gtk::Button().render_icon(Gtk::StockID("synfig-canvas"),Gtk::ICON_SIZE_SMALL_TOOLBAR);
147 HistoryTreeStore::on_undo()
153 HistoryTreeStore::on_redo()
159 HistoryTreeStore::on_undo_stack_cleared()
161 Gtk::TreeModel::Children::iterator iter,next;
162 Gtk::TreeModel::Children children_(children());
164 for(next=children_.begin(),iter=next++; iter != children_.end(); iter=(next!=children_.end())?next++:next)
166 Gtk::TreeModel::Row row = *iter;
167 if(row[model.is_undo])
173 HistoryTreeStore::on_redo_stack_cleared()
175 Gtk::TreeModel::Children::iterator iter,next;
176 Gtk::TreeModel::Children children_(children());
178 for(next=children_.begin(),iter=next++; iter != children_.end(); iter=(next!=children_.end())?next++:next)
180 Gtk::TreeModel::Row row = *iter;
181 if(row[model.is_redo])
187 HistoryTreeStore::on_new_action(etl::handle<synfigapp::Action::Undoable> action)
189 // Gtk::TreeRow row = *(append());
191 Gtk::TreeModel::Children::iterator iter;
192 for(iter=children().begin(); iter != children().end(); ++iter)
194 Gtk::TreeModel::Row row = *iter;
195 if(row[model.is_redo])
203 insert_action(row,action);
205 signal_undo_tree_changed()();
209 HistoryTreeStore::on_action_status_changed(etl::handle<synfigapp::Action::Undoable> action)
211 Gtk::TreeModel::Children::iterator iter;
212 Gtk::TreeModel::Children children_(children());
214 for(iter=children_.begin(); iter != children_.end(); ++iter)
216 Gtk::TreeModel::Row row = *iter;
217 if(action == (etl::handle<synfigapp::Action::Undoable>)row[model.action])
219 row[model.is_active]=action->is_active();
226 HistoryTreeStore::search_func(const Glib::RefPtr<Gtk::TreeModel>&,int,const Glib::ustring& x,const Gtk::TreeModel::iterator& iter)
230 Glib::ustring substr(x.uppercase());
231 Glib::ustring name((*iter)[model.name]);
232 name=name.uppercase();
234 return name.find(substr)==Glib::ustring::npos;