1 /* === S Y N F I G ========================================================= */
2 /*! \file dock_history.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007 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 "dock_history.h"
38 #include <gtkmm/scrolledwindow.h>
41 #include <sigc++/signal.h>
42 #include <sigc++/hide.h>
43 #include <sigc++/slot.h>
44 #include <synfigapp/action.h>
45 #include "historytreestore.h"
49 /* === U S I N G =========================================================== */
53 using namespace synfig;
54 using namespace studio;
56 /* === M A C R O S ========================================================= */
57 #define COLUMNID_JUMP (787584)
60 /* === G L O B A L S ======================================================= */
62 /* === P R O C E D U R E S ================================================= */
64 /* === M E T H O D S ======================================================= */
66 Dock_History::Dock_History():
67 Dock_CanvasSpecific("history",_("History"),Gtk::StockID("gtk-undo")),
68 action_group(Gtk::ActionGroup::create())
70 App::signal_instance_deleted().connect(sigc::mem_fun(*this,&studio::Dock_History::delete_instance));
71 App::signal_instance_selected().connect(sigc::mem_fun(*this,&studio::Dock_History::set_selected_instance_signal));
73 action_group->add(Gtk::Action::create(
75 Gtk::StockID("synfig-clear_undo"),
76 _("Clear Undo Stack"),
77 _("Clear the undo stack")
81 &Dock_History::clear_undo
84 action_group->add(Gtk::Action::create(
86 Gtk::StockID("synfig-clear_redo"),
87 _("Clear Redo Stack"),
88 _("Clear the redo stack")
92 &Dock_History::clear_redo
95 action_group->add(Gtk::Action::create(
97 Gtk::StockID("gtk-undo"),
99 _("Undo the previous action")
101 sigc::ptr_fun(studio::App::undo)
103 action_group->add(Gtk::Action::create(
105 Gtk::StockID("gtk-redo"),
107 _("Redo the previously undone action")
109 sigc::ptr_fun(studio::App::redo)
112 action_group->add( Gtk::Action::create("toolbar-history", "History") );
113 App::ui_manager()->insert_action_group(action_group);
115 Glib::ustring ui_info =
117 " <toolbar action='toolbar-history'>"
118 " <toolitem action='undo' />"
119 " <toolitem action='redo' />"
120 " <toolitem action='clear-undo' />"
121 " <toolitem action='clear-redo' />"
126 App::ui_manager()->add_ui_from_string(ui_info);
128 action_group->set_sensitive(false);
130 set_toolbar(*dynamic_cast<Gtk::Toolbar*>(App::ui_manager()->get_widget("/toolbar-history")));
131 add(*create_action_tree());
135 Gtk::StockID("synfig-clear_undo"),
136 _("Clear the UNDO Stack")
137 )->signal_clicked().connect(
140 &Dock_History::clear_undo
144 Gtk::StockID("synfig-clear_redo"),
145 _("Clear the REDO Stack")
146 )->signal_clicked().connect(
149 &Dock_History::clear_redo
155 Dock_History::~Dock_History()
160 Dock_History::init_instance_vfunc(etl::loose_handle<Instance> instance)
162 instance->signal_undo_redo_status_changed().connect(
163 sigc::mem_fun(*this,&Dock_History::update_undo_redo)
168 Dock_History::create_action_tree()
170 studio::HistoryTreeStore::Model history_tree_model;
171 action_tree=manage(new class Gtk::TreeView());
173 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column("") );
175 Gtk::CellRendererToggle* toggle_cr = Gtk::manage( new Gtk::CellRendererToggle() );
176 toggle_cr->signal_toggled().connect(sigc::mem_fun(*this, &studio::Dock_History::on_action_toggle) );
178 column->pack_start(*toggle_cr); //false = don't expand.
179 column->add_attribute(toggle_cr->property_active(),history_tree_model.is_active);
180 column->set_resizable();
181 column->set_clickable();
183 action_tree->append_column(*column);
186 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column("Canvas") );
187 Gtk::CellRendererText *text_cr=Gtk::manage(new Gtk::CellRendererText());
188 text_cr->property_foreground()=Glib::ustring("#7f7f7f");
190 column->pack_start(*text_cr);
191 column->add_attribute(text_cr->property_text(),history_tree_model.canvas_id);
192 column->add_attribute(text_cr->property_foreground_set(),history_tree_model.is_redo);
194 action_tree->append_column(*column);
197 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Jump")) );
199 Gtk::CellRendererText* cell_renderer_jump=Gtk::manage(new Gtk::CellRendererText());
200 column->pack_start(*cell_renderer_jump,true);
202 cell_renderer_jump->property_text()="(JMP)";
203 cell_renderer_jump->property_foreground()="#003a7f";
205 column->set_resizable();
206 column->set_clickable();
208 column->set_sort_column_id(COLUMNID_JUMP);
210 action_tree->append_column(*column);
214 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column("Action") );
216 Gtk::CellRendererText *text_cr=Gtk::manage(new Gtk::CellRendererText());
217 text_cr->property_foreground()=Glib::ustring("#7f7f7f");
221 //column->pack_start(history_tree_model.icon, false); //false = don't expand.
222 column->pack_start(*text_cr);
223 column->add_attribute(text_cr->property_text(),history_tree_model.name);
224 column->add_attribute(text_cr->property_foreground_set(),history_tree_model.is_redo);
226 action_tree->append_column(*column);
230 action_tree->set_rules_hint();
231 // action_tree->signal_row_activated().connect(sigc::mem_fun(*this,&Dock_History::on_row_activate));
232 action_tree->signal_event().connect(sigc::mem_fun(*this,&Dock_History::on_action_event));
233 // action_tree->add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
234 // action_tree->add_events(Gdk::BUTTON1_MOTION_MASK);
237 Gtk::ScrolledWindow *scrolledwindow = manage(new class Gtk::ScrolledWindow());
238 scrolledwindow->set_flags(Gtk::CAN_FOCUS);
239 scrolledwindow->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
240 scrolledwindow->add(*action_tree);
241 scrolledwindow->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
242 scrolledwindow->show_all();
245 Gtk::Widget& widget(*action_tree);
246 Pango::FontDescription font(widget.get_modifier_style()->get_font());
247 font.set_size(Pango::SCALE*5);
248 widget.get_modifier_style()->set_font(font);
249 widget.modify_font(font);
252 return scrolledwindow;
256 Dock_History::clear_undo()
258 if(selected_instance && App::dialog_yes_no(_("Clear History"), _("You will not be able to undo any changes that you have made!\nAre you sure you want to clear the undo stack?")))
260 selected_instance->clear_undo_stack();
265 Dock_History::clear_redo()
267 if(selected_instance && App::dialog_yes_no(_("Clear History"), _("You will not be able to redo any changes that you have made!\nAre you sure you want to clear the redo stack?")))
269 selected_instance->clear_redo_stack();
274 Dock_History::update_undo_redo()
276 etl::handle<Instance> instance=App::get_selected_instance();
279 action_group->get_action("undo")->set_sensitive(instance->get_undo_status());
280 action_group->get_action("clear-undo")->set_sensitive(instance->get_undo_status());
281 action_group->get_action("redo")->set_sensitive(instance->get_redo_status());
282 action_group->get_action("clear-redo")->set_sensitive(instance->get_redo_status());
287 Dock_History::set_selected_instance_(etl::handle<studio::Instance> instance)
289 if(studio::App::shutdown_in_progress)
292 selected_instance=instance;
295 action_tree->set_model(instance->history_tree_store());
298 action_group->set_sensitive(true);
302 action_tree->set_model(Glib::RefPtr< Gtk::TreeModel >());
304 action_group->set_sensitive(false);
309 Dock_History::set_selected_instance_signal(etl::handle<studio::Instance> x)
311 set_selected_instance(x);
315 Dock_History::set_selected_instance(etl::loose_handle<studio::Instance> x)
317 if(studio::App::shutdown_in_progress)
320 // if it's already selected, don't select it again
321 if (x==selected_instance)
324 std::list<etl::handle<studio::Instance> >::iterator iter;
326 set_selected_instance_(x);
330 Dock_History::delete_instance(etl::handle<studio::Instance> instance)
332 if(studio::App::shutdown_in_progress)
335 if(selected_instance==instance)
337 set_selected_instance(0);
342 Dock_History::on_action_event(GdkEvent *event)
344 studio::HistoryTreeStore::Model model;
347 case GDK_BUTTON_PRESS:
348 case GDK_2BUTTON_PRESS:
350 Gtk::TreeModel::Path path;
351 Gtk::TreeViewColumn *column;
353 if(!action_tree->get_path_at_pos(
354 int(event->button.x),int(event->button.y), // x, y
355 path, // TreeModel::Path&
356 column, //TreeViewColumn*&
357 cell_x,cell_y //int&cell_x,int&cell_y
360 const Gtk::TreeRow row = *(action_tree->get_model()->get_iter(path));
362 //signal_user_click()(event->button.button,row,(ColumnID)column->get_sort_column_id());
363 if((ColumnID)column->get_sort_column_id()==COLUMNID_JUMP)
365 etl::handle<synfigapp::Action::Undoable> action(row[model.action]);
367 if((bool)row[model.is_undo])
369 while(get_selected_instance()->undo_action_stack().size() && get_selected_instance()->undo_action_stack().front()!=action)
370 if(get_selected_instance()->undo()==false)
373 else if((bool)row[model.is_redo])
375 while(get_selected_instance()->redo_action_stack().size() && get_selected_instance()->undo_action_stack().front()!=action)
376 if(get_selected_instance()->redo()==false)
387 case GDK_BUTTON_RELEASE:
396 Dock_History::on_action_toggle(const Glib::ustring& path_string)
398 studio::HistoryTreeStore::Model history_tree_model;
400 Gtk::TreePath path(path_string);
402 const Gtk::TreeRow row = *(selected_instance->history_tree_store()->get_iter(path));
404 handle<synfigapp::Action::Undoable> action=row[history_tree_model.action];
406 selected_instance->synfigapp::Instance::set_action_status(action,!action->is_active());