1 /* === S I N F 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 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === H E A D E R S ======================================================= */
31 #include "dock_history.h"
36 #include <gtkmm/scrolledwindow.h>
39 #include <sigc++/signal.h>
40 #include <sigc++/hide.h>
41 #include <sigc++/slot.h>
42 #include <sinfgapp/action.h>
43 #include "historytreestore.h"
47 /* === U S I N G =========================================================== */
51 using namespace sinfg;
52 using namespace studio;
54 /* === M A C R O S ========================================================= */
55 #define COLUMNID_JUMP (787584)
58 /* === G L O B A L S ======================================================= */
60 /* === P R O C E D U R E S ================================================= */
62 /* === M E T H O D S ======================================================= */
64 Dock_History::Dock_History():
65 Dock_CanvasSpecific("history",_("History"),Gtk::StockID("gtk-undo")),
66 action_group(Gtk::ActionGroup::create())
68 App::signal_instance_deleted().connect(sigc::mem_fun(*this,&studio::Dock_History::delete_instance));
69 App::signal_instance_selected().connect(sigc::mem_fun(*this,&studio::Dock_History::set_selected_instance_signal));
71 action_group->add(Gtk::Action::create(
73 Gtk::StockID("sinfg-clear_undo"),
74 _("Clear the UNDO Stack"),
75 _("Clear the UNDO Stack")
79 &Dock_History::clear_undo
82 action_group->add(Gtk::Action::create(
84 Gtk::StockID("sinfg-clear_redo"),
85 _("Clear the REDO Stack"),
86 _("Clear the REDO Stack")
90 &Dock_History::clear_redo
93 action_group->add(Gtk::Action::create(
95 Gtk::StockID("gtk-undo"),
96 _("Undo previous action"),
97 _("Undo previous action")
99 sigc::ptr_fun(studio::App::undo)
101 action_group->add(Gtk::Action::create(
103 Gtk::StockID("gtk-redo"),
104 _("Redo previous action"),
105 _("Redo previous action")
107 sigc::ptr_fun(studio::App::redo)
110 action_group->add( Gtk::Action::create("toolbar-history", "History") );
111 App::ui_manager()->insert_action_group(action_group);
113 Glib::ustring ui_info =
115 " <toolbar action='toolbar-history'>"
116 " <toolitem action='undo' />"
117 " <toolitem action='clear-undo' />"
118 " <toolitem action='clear-redo' />"
119 " <toolitem action='redo' />"
124 App::ui_manager()->add_ui_from_string(ui_info);
126 action_group->set_sensitive(false);
128 set_toolbar(*dynamic_cast<Gtk::Toolbar*>(App::ui_manager()->get_widget("/toolbar-history")));
129 add(*create_action_tree());
133 Gtk::StockID("sinfg-clear_undo"),
134 _("Clear the UNDO Stack")
135 )->signal_clicked().connect(
138 &Dock_History::clear_undo
142 Gtk::StockID("sinfg-clear_redo"),
143 _("Clear the REDO Stack")
144 )->signal_clicked().connect(
147 &Dock_History::clear_redo
153 Dock_History::~Dock_History()
158 Dock_History::init_instance_vfunc(etl::loose_handle<Instance> instance)
160 instance->signal_undo_redo_status_changed().connect(
161 sigc::mem_fun(*this,&Dock_History::update_undo_redo)
166 Dock_History::create_action_tree()
168 studio::HistoryTreeStore::Model history_tree_model;
169 action_tree=manage(new class Gtk::TreeView());
171 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column("") );
173 Gtk::CellRendererToggle* toggle_cr = Gtk::manage( new Gtk::CellRendererToggle() );
174 toggle_cr->signal_toggled().connect(sigc::mem_fun(*this, &studio::Dock_History::on_action_toggle) );
176 column->pack_start(*toggle_cr); //false = don't expand.
177 column->add_attribute(toggle_cr->property_active(),history_tree_model.is_active);
178 column->set_resizable();
179 column->set_clickable();
181 action_tree->append_column(*column);
184 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column("Canvas") );
185 Gtk::CellRendererText *text_cr=Gtk::manage(new Gtk::CellRendererText());
186 text_cr->property_foreground()=Glib::ustring("#7f7f7f");
188 column->pack_start(*text_cr);
189 column->add_attribute(text_cr->property_text(),history_tree_model.canvas_id);
190 column->add_attribute(text_cr->property_foreground_set(),history_tree_model.is_redo);
192 action_tree->append_column(*column);
195 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Jump")) );
197 Gtk::CellRendererText* cell_renderer_jump=Gtk::manage(new Gtk::CellRendererText());
198 column->pack_start(*cell_renderer_jump,true);
200 cell_renderer_jump->property_text()="(JMP)";
201 cell_renderer_jump->property_foreground()="#003a7f";
203 column->set_resizable();
204 column->set_clickable();
206 column->set_sort_column_id(COLUMNID_JUMP);
208 action_tree->append_column(*column);
212 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column("Action") );
214 Gtk::CellRendererText *text_cr=Gtk::manage(new Gtk::CellRendererText());
215 text_cr->property_foreground()=Glib::ustring("#7f7f7f");
219 //column->pack_start(history_tree_model.icon, false); //false = don't expand.
220 column->pack_start(*text_cr);
221 column->add_attribute(text_cr->property_text(),history_tree_model.name);
222 column->add_attribute(text_cr->property_foreground_set(),history_tree_model.is_redo);
224 action_tree->append_column(*column);
228 action_tree->set_rules_hint();
229 // action_tree->signal_row_activated().connect(sigc::mem_fun(*this,&Dock_History::on_row_activate));
230 action_tree->signal_event().connect(sigc::mem_fun(*this,&Dock_History::on_action_event));
231 // action_tree->add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
232 // action_tree->add_events(Gdk::BUTTON1_MOTION_MASK);
235 Gtk::ScrolledWindow *scrolledwindow = manage(new class Gtk::ScrolledWindow());
236 scrolledwindow->set_flags(Gtk::CAN_FOCUS);
237 scrolledwindow->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
238 scrolledwindow->add(*action_tree);
239 scrolledwindow->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
240 scrolledwindow->show_all();
243 Gtk::Widget& widget(*action_tree);
244 Pango::FontDescription font(widget.get_modifier_style()->get_font());
245 font.set_size(Pango::SCALE*5);
246 widget.get_modifier_style()->set_font(font);
247 widget.modify_font(font);
250 return scrolledwindow;
254 Dock_History::clear_undo()
256 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?")))
258 selected_instance->clear_undo_stack();
263 Dock_History::clear_redo()
265 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?")))
267 selected_instance->clear_redo_stack();
272 Dock_History::update_undo_redo()
274 etl::handle<Instance> instance=App::get_selected_instance();
277 action_group->get_action("undo")->set_sensitive(instance->get_undo_status());
278 action_group->get_action("clear-undo")->set_sensitive(instance->get_undo_status());
279 action_group->get_action("redo")->set_sensitive(instance->get_redo_status());
280 action_group->get_action("clear-redo")->set_sensitive(instance->get_redo_status());
285 Dock_History::set_selected_instance_(etl::handle<studio::Instance> instance)
287 if(studio::App::shutdown_in_progress)
290 selected_instance=instance;
293 action_tree->set_model(instance->history_tree_store());
296 action_group->set_sensitive(true);
300 action_tree->set_model(Glib::RefPtr< Gtk::TreeModel >());
302 action_group->set_sensitive(false);
307 Dock_History::set_selected_instance_signal(etl::handle<studio::Instance> x)
309 set_selected_instance(x);
313 Dock_History::set_selected_instance(etl::loose_handle<studio::Instance> x)
315 if(studio::App::shutdown_in_progress)
318 // if it's already selected, don't select it again
319 if (x==selected_instance)
322 std::list<etl::handle<studio::Instance> >::iterator iter;
324 set_selected_instance_(x);
328 Dock_History::delete_instance(etl::handle<studio::Instance> instance)
330 if(studio::App::shutdown_in_progress)
333 if(selected_instance==instance)
335 set_selected_instance(0);
340 Dock_History::on_action_event(GdkEvent *event)
342 studio::HistoryTreeStore::Model model;
345 case GDK_BUTTON_PRESS:
346 case GDK_2BUTTON_PRESS:
348 Gtk::TreeModel::Path path;
349 Gtk::TreeViewColumn *column;
351 if(!action_tree->get_path_at_pos(
352 int(event->button.x),int(event->button.y), // x, y
353 path, // TreeModel::Path&
354 column, //TreeViewColumn*&
355 cell_x,cell_y //int&cell_x,int&cell_y
358 const Gtk::TreeRow row = *(action_tree->get_model()->get_iter(path));
360 //signal_user_click()(event->button.button,row,(ColumnID)column->get_sort_column_id());
361 if((ColumnID)column->get_sort_column_id()==COLUMNID_JUMP)
363 etl::handle<sinfgapp::Action::Undoable> action(row[model.action]);
365 if((bool)row[model.is_undo])
367 while(get_selected_instance()->undo_action_stack().size() && get_selected_instance()->undo_action_stack().front()!=action)
368 if(get_selected_instance()->undo()==false)
371 else if((bool)row[model.is_redo])
373 while(get_selected_instance()->redo_action_stack().size() && get_selected_instance()->undo_action_stack().front()!=action)
374 if(get_selected_instance()->redo()==false)
385 case GDK_BUTTON_RELEASE:
394 Dock_History::on_action_toggle(const Glib::ustring& path_string)
396 studio::HistoryTreeStore::Model history_tree_model;
398 Gtk::TreePath path(path_string);
400 const Gtk::TreeRow row = *(selected_instance->history_tree_store()->get_iter(path));
402 handle<sinfgapp::Action::Undoable> action=row[history_tree_model.action];
404 selected_instance->sinfgapp::Instance::set_action_status(action,!action->is_active());