1 /* === S Y N F I G ========================================================= */
2 /*! \file dialog_history.cpp
3 ** \brief Template File
5 ** $Id: dock_history.cpp,v 1.1.1.1 2005/01/07 03:34:36 darco Exp $
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 "dock_history.h"
37 #include <gtkmm/scrolledwindow.h>
40 #include <sigc++/signal.h>
41 #include <sigc++/hide.h>
42 #include <sigc++/slot.h>
43 #include <synfigapp/action.h>
44 #include "historytreestore.h"
48 /* === U S I N G =========================================================== */
52 using namespace synfig;
53 using namespace studio;
55 /* === M A C R O S ========================================================= */
56 #define COLUMNID_JUMP (787584)
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 Dock_History::Dock_History():
66 Dock_CanvasSpecific("history",_("History"),Gtk::StockID("gtk-undo")),
67 action_group(Gtk::ActionGroup::create())
69 App::signal_instance_deleted().connect(sigc::mem_fun(*this,&studio::Dock_History::delete_instance));
70 App::signal_instance_selected().connect(sigc::mem_fun(*this,&studio::Dock_History::set_selected_instance_signal));
72 action_group->add(Gtk::Action::create(
74 Gtk::StockID("synfig-clear_undo"),
75 _("Clear the UNDO Stack"),
76 _("Clear the UNDO Stack")
80 &Dock_History::clear_undo
83 action_group->add(Gtk::Action::create(
85 Gtk::StockID("synfig-clear_redo"),
86 _("Clear the REDO Stack"),
87 _("Clear the REDO Stack")
91 &Dock_History::clear_redo
94 action_group->add(Gtk::Action::create(
96 Gtk::StockID("gtk-undo"),
97 _("Undo previous action"),
98 _("Undo previous action")
100 sigc::ptr_fun(studio::App::undo)
102 action_group->add(Gtk::Action::create(
104 Gtk::StockID("gtk-redo"),
105 _("Redo previous action"),
106 _("Redo previous action")
108 sigc::ptr_fun(studio::App::redo)
111 action_group->add( Gtk::Action::create("toolbar-history", "History") );
112 App::ui_manager()->insert_action_group(action_group);
114 Glib::ustring ui_info =
116 " <toolbar action='toolbar-history'>"
117 " <toolitem action='undo' />"
118 " <toolitem action='clear-undo' />"
119 " <toolitem action='clear-redo' />"
120 " <toolitem action='redo' />"
125 App::ui_manager()->add_ui_from_string(ui_info);
127 action_group->set_sensitive(false);
129 set_toolbar(*dynamic_cast<Gtk::Toolbar*>(App::ui_manager()->get_widget("/toolbar-history")));
130 add(*create_action_tree());
134 Gtk::StockID("synfig-clear_undo"),
135 _("Clear the UNDO Stack")
136 )->signal_clicked().connect(
139 &Dock_History::clear_undo
143 Gtk::StockID("synfig-clear_redo"),
144 _("Clear the REDO Stack")
145 )->signal_clicked().connect(
148 &Dock_History::clear_redo
154 Dock_History::~Dock_History()
159 Dock_History::init_instance_vfunc(etl::loose_handle<Instance> instance)
161 instance->signal_undo_redo_status_changed().connect(
162 sigc::mem_fun(*this,&Dock_History::update_undo_redo)
167 Dock_History::create_action_tree()
169 studio::HistoryTreeStore::Model history_tree_model;
170 action_tree=manage(new class Gtk::TreeView());
172 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column("") );
174 Gtk::CellRendererToggle* toggle_cr = Gtk::manage( new Gtk::CellRendererToggle() );
175 toggle_cr->signal_toggled().connect(sigc::mem_fun(*this, &studio::Dock_History::on_action_toggle) );
177 column->pack_start(*toggle_cr); //false = don't expand.
178 column->add_attribute(toggle_cr->property_active(),history_tree_model.is_active);
179 column->set_resizable();
180 column->set_clickable();
182 action_tree->append_column(*column);
185 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column("Canvas") );
186 Gtk::CellRendererText *text_cr=Gtk::manage(new Gtk::CellRendererText());
187 text_cr->property_foreground()=Glib::ustring("#7f7f7f");
189 column->pack_start(*text_cr);
190 column->add_attribute(text_cr->property_text(),history_tree_model.canvas_id);
191 column->add_attribute(text_cr->property_foreground_set(),history_tree_model.is_redo);
193 action_tree->append_column(*column);
196 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Jump")) );
198 Gtk::CellRendererText* cell_renderer_jump=Gtk::manage(new Gtk::CellRendererText());
199 column->pack_start(*cell_renderer_jump,true);
201 cell_renderer_jump->property_text()="(JMP)";
202 cell_renderer_jump->property_foreground()="#003a7f";
204 column->set_resizable();
205 column->set_clickable();
207 column->set_sort_column_id(COLUMNID_JUMP);
209 action_tree->append_column(*column);
213 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column("Action") );
215 Gtk::CellRendererText *text_cr=Gtk::manage(new Gtk::CellRendererText());
216 text_cr->property_foreground()=Glib::ustring("#7f7f7f");
220 //column->pack_start(history_tree_model.icon, false); //false = don't expand.
221 column->pack_start(*text_cr);
222 column->add_attribute(text_cr->property_text(),history_tree_model.name);
223 column->add_attribute(text_cr->property_foreground_set(),history_tree_model.is_redo);
225 action_tree->append_column(*column);
229 action_tree->set_rules_hint();
230 // action_tree->signal_row_activated().connect(sigc::mem_fun(*this,&Dock_History::on_row_activate));
231 action_tree->signal_event().connect(sigc::mem_fun(*this,&Dock_History::on_action_event));
232 // action_tree->add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
233 // action_tree->add_events(Gdk::BUTTON1_MOTION_MASK);
236 Gtk::ScrolledWindow *scrolledwindow = manage(new class Gtk::ScrolledWindow());
237 scrolledwindow->set_flags(Gtk::CAN_FOCUS);
238 scrolledwindow->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
239 scrolledwindow->add(*action_tree);
240 scrolledwindow->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
241 scrolledwindow->show_all();
244 Gtk::Widget& widget(*action_tree);
245 Pango::FontDescription font(widget.get_modifier_style()->get_font());
246 font.set_size(Pango::SCALE*5);
247 widget.get_modifier_style()->set_font(font);
248 widget.modify_font(font);
251 return scrolledwindow;
255 Dock_History::clear_undo()
257 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?")))
259 selected_instance->clear_undo_stack();
264 Dock_History::clear_redo()
266 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?")))
268 selected_instance->clear_redo_stack();
273 Dock_History::update_undo_redo()
275 etl::handle<Instance> instance=App::get_selected_instance();
278 action_group->get_action("undo")->set_sensitive(instance->get_undo_status());
279 action_group->get_action("clear-undo")->set_sensitive(instance->get_undo_status());
280 action_group->get_action("redo")->set_sensitive(instance->get_redo_status());
281 action_group->get_action("clear-redo")->set_sensitive(instance->get_redo_status());
286 Dock_History::set_selected_instance_(etl::handle<studio::Instance> instance)
288 if(studio::App::shutdown_in_progress)
291 selected_instance=instance;
294 action_tree->set_model(instance->history_tree_store());
297 action_group->set_sensitive(true);
301 action_tree->set_model(Glib::RefPtr< Gtk::TreeModel >());
303 action_group->set_sensitive(false);
308 Dock_History::set_selected_instance_signal(etl::handle<studio::Instance> x)
310 set_selected_instance(x);
314 Dock_History::set_selected_instance(etl::loose_handle<studio::Instance> x)
316 if(studio::App::shutdown_in_progress)
319 // if it's already selected, don't select it again
320 if (x==selected_instance)
323 std::list<etl::handle<studio::Instance> >::iterator iter;
325 set_selected_instance_(x);
329 Dock_History::delete_instance(etl::handle<studio::Instance> instance)
331 if(studio::App::shutdown_in_progress)
334 if(selected_instance==instance)
336 set_selected_instance(0);
341 Dock_History::on_action_event(GdkEvent *event)
343 studio::HistoryTreeStore::Model model;
346 case GDK_BUTTON_PRESS:
347 case GDK_2BUTTON_PRESS:
349 Gtk::TreeModel::Path path;
350 Gtk::TreeViewColumn *column;
352 if(!action_tree->get_path_at_pos(
353 int(event->button.x),int(event->button.y), // x, y
354 path, // TreeModel::Path&
355 column, //TreeViewColumn*&
356 cell_x,cell_y //int&cell_x,int&cell_y
359 const Gtk::TreeRow row = *(action_tree->get_model()->get_iter(path));
361 //signal_user_click()(event->button.button,row,(ColumnID)column->get_sort_column_id());
362 if((ColumnID)column->get_sort_column_id()==COLUMNID_JUMP)
364 etl::handle<synfigapp::Action::Undoable> action(row[model.action]);
366 if((bool)row[model.is_undo])
368 while(get_selected_instance()->undo_action_stack().size() && get_selected_instance()->undo_action_stack().front()!=action)
369 if(get_selected_instance()->undo()==false)
372 else if((bool)row[model.is_redo])
374 while(get_selected_instance()->redo_action_stack().size() && get_selected_instance()->undo_action_stack().front()!=action)
375 if(get_selected_instance()->redo()==false)
386 case GDK_BUTTON_RELEASE:
395 Dock_History::on_action_toggle(const Glib::ustring& path_string)
397 studio::HistoryTreeStore::Model history_tree_model;
399 Gtk::TreePath path(path_string);
401 const Gtk::TreeRow row = *(selected_instance->history_tree_store()->get_iter(path));
403 handle<synfigapp::Action::Undoable> action=row[history_tree_model.action];
405 selected_instance->synfigapp::Instance::set_action_status(action,!action->is_active());