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
10 ** This package is free software; you can redistribute it and/or
11 ** modify it under the terms of the GNU General Public License as
12 ** published by the Free Software Foundation; either version 2 of
13 ** the License, or (at your option) any later version.
15 ** This package is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 ** General Public License for more details.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
32 #include "historytreestore.h"
33 #include <synfig/valuenode.h>
34 #include "iconcontroller.h"
35 #include <synfig/valuenode_timedswap.h>
36 #include <gtkmm/button.h>
37 #include <synfigapp/action.h>
44 /* === U S I N G =========================================================== */
48 using namespace synfig;
49 using namespace studio;
51 /* === M A C R O S ========================================================= */
53 /* === G L O B A L S ======================================================= */
55 /* === P R O C E D U R E S ================================================= */
57 /* === M E T H O D S ======================================================= */
59 static HistoryTreeStore::Model& ModelHack()
61 static HistoryTreeStore::Model* model(0);
62 if(!model)model=new HistoryTreeStore::Model;
66 HistoryTreeStore::HistoryTreeStore(etl::loose_handle<studio::Instance> instance_):
67 Gtk::TreeStore (ModelHack()),
70 instance_->signal_undo().connect(sigc::mem_fun(*this,&studio::HistoryTreeStore::on_undo));
71 instance_->signal_redo().connect(sigc::mem_fun(*this,&studio::HistoryTreeStore::on_redo));
72 instance_->signal_undo_stack_cleared().connect(sigc::mem_fun(*this,&studio::HistoryTreeStore::on_undo_stack_cleared));
73 instance_->signal_redo_stack_cleared().connect(sigc::mem_fun(*this,&studio::HistoryTreeStore::on_redo_stack_cleared));
74 instance_->signal_new_action().connect(sigc::mem_fun(*this,&studio::HistoryTreeStore::on_new_action));
75 instance_->signal_action_status_changed().connect(sigc::mem_fun(*this,&studio::HistoryTreeStore::on_action_status_changed));
78 HistoryTreeStore::~HistoryTreeStore()
80 if (getenv("SYNFIG_DEBUG_DESTRUCTORS"))
81 synfig::info("HistoryTreeStore::~HistoryTreeStore(): Deleted");
84 Glib::RefPtr<HistoryTreeStore>
85 HistoryTreeStore::create(etl::loose_handle<studio::Instance> instance_)
87 return Glib::RefPtr<HistoryTreeStore>(new HistoryTreeStore(instance_));
91 HistoryTreeStore::rebuild()
93 synfigapp::Action::Stack::const_iterator iter;
97 for(iter=instance()->undo_action_stack().begin();iter!=instance()->undo_action_stack().end();++iter)
99 insert_action(*(prepend()),*iter,true,true,false);
101 curr_row=*children().end();
102 for(iter=instance()->redo_action_stack().begin();iter!=instance()->redo_action_stack().end();++iter)
104 insert_action(*(append()),*iter,true,false,true);
109 HistoryTreeStore::insert_action(Gtk::TreeRow row,etl::handle<synfigapp::Action::Undoable> action, bool /*is_active*/, bool is_undo, bool is_redo)
113 row[model.action] = action;
114 row[model.name] = static_cast<Glib::ustring>(action->get_local_name());
115 row[model.is_active] = action->is_active();
116 row[model.is_undo] = is_undo;
117 row[model.is_redo] = is_redo;
119 synfigapp::Action::CanvasSpecific *specific_action;
120 specific_action=dynamic_cast<synfigapp::Action::CanvasSpecific*>(action.get());
123 row[model.canvas] = specific_action->get_canvas();
124 row[model.canvas_id] = specific_action->get_canvas()->get_id();
127 etl::handle<synfigapp::Action::Group> group;
128 group=etl::handle<synfigapp::Action::Group>::cast_dynamic(action);
131 synfigapp::Action::ActionList::const_iterator iter;
132 for(iter=group->action_list().begin();iter!=group->action_list().end();++iter)
134 Gtk::TreeRow child_row = *(append(row.children()));
135 insert_action(child_row,*iter,true,is_undo,is_redo);
139 //row[model.icon] = Gtk::Button().render_icon(Gtk::StockID("synfig-canvas"),Gtk::ICON_SIZE_SMALL_TOOLBAR);
144 HistoryTreeStore::on_undo()
150 HistoryTreeStore::on_redo()
156 HistoryTreeStore::on_undo_stack_cleared()
158 Gtk::TreeModel::Children::iterator iter,next;
159 Gtk::TreeModel::Children children_(children());
161 for(next=children_.begin(),iter=next++; iter != children_.end(); iter=(next!=children_.end())?next++:next)
163 Gtk::TreeModel::Row row = *iter;
164 if(row[model.is_undo])
170 HistoryTreeStore::on_redo_stack_cleared()
172 Gtk::TreeModel::Children::iterator iter,next;
173 Gtk::TreeModel::Children children_(children());
175 for(next=children_.begin(),iter=next++; iter != children_.end(); iter=(next!=children_.end())?next++:next)
177 Gtk::TreeModel::Row row = *iter;
178 if(row[model.is_redo])
184 HistoryTreeStore::on_new_action(etl::handle<synfigapp::Action::Undoable> action)
186 // Gtk::TreeRow row = *(append());
188 Gtk::TreeModel::Children::iterator iter;
189 for(iter=children().begin(); iter != children().end(); ++iter)
191 Gtk::TreeModel::Row row = *iter;
192 if(row[model.is_redo])
200 insert_action(row,action);
204 HistoryTreeStore::on_action_status_changed(etl::handle<synfigapp::Action::Undoable> action)
206 Gtk::TreeModel::Children::iterator iter;
207 Gtk::TreeModel::Children children_(children());
209 for(iter=children_.begin(); iter != children_.end(); ++iter)
211 Gtk::TreeModel::Row row = *iter;
212 if(action == (etl::handle<synfigapp::Action::Undoable>)row[model.action])
214 row[model.is_active]=action->is_active();
221 HistoryTreeStore::search_func(const Glib::RefPtr<Gtk::TreeModel>&,int,const Glib::ustring& x,const Gtk::TreeModel::iterator& iter)
225 Glib::ustring substr(x.uppercase());
226 Glib::ustring name((*iter)[model.name]);
227 name=name.uppercase();
229 return name.find(substr)==Glib::ustring::npos;