1 /* === S Y N F I G ========================================================= */
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 ** === N O T E S ===========================================================
23 ** ========================================================================= */
25 /* === H E A D E R S ======================================================= */
36 #include <gtkmm/scrolledwindow.h>
40 #include <sigc++/signal.h>
41 #include <sigc++/hide.h>
42 #include <sigc++/slot.h>
43 #include "canvasview.h"
44 #include <synfigapp/action.h>
50 /* === M A C R O S ========================================================= */
52 #define ADD_TOOLBOX_BUTTON(button,stockid,tooltip) \
53 Gtk::Button *button = manage(new class Gtk::Button()); \
54 button->add(*manage(new Gtk::Image(Gtk::StockID(stockid),Gtk::IconSize(4)))); \
55 tooltips.set_tip(*button,tooltip); \
60 using namespace synfig;
61 using namespace studio;
63 #define COLUMNID_JUMP (787584)
66 /* === G L O B A L S ======================================================= */
68 /* === P R O C E D U R E S ================================================= */
70 /* === M E T H O D S ======================================================= */
73 Gtk::Window(Gtk::WINDOW_TOPLEVEL),
74 dialog_settings(this,"compview")
77 set_type_hint(Gdk::WINDOW_TYPE_HINT_UTILITY);
79 Gtk::Table *table = manage(new class Gtk::Table(2, 1, false));
82 table->attach(*create_instance_selector(), 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
84 notebook=manage(new class Gtk::Notebook());
86 table->attach(*notebook, 0, 1, 1,2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
88 notebook->append_page(*create_canvas_tree(),_("Canvases"));
89 notebook->append_page(*create_action_tree(),_("History"));
95 studio::Instance::ImageColumnModel image_column_model;
96 image_list=manage(new class Gtk::TreeView());
97 image_list->append_column(_("Name"),image_column_model.name);
98 image_list->signal_row_activated().connect(sigc::mem_fun(*this,&CompView::on_image_activate));
99 image_list->set_rules_hint();
101 Gtk::Table *image_page = manage(new class Gtk::Table(2, 1, false));
102 Gtk::ScrolledWindow *image_list_scroll = manage(new class Gtk::ScrolledWindow());
103 image_list_scroll->set_flags(Gtk::CAN_FOCUS);
104 image_list_scroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
105 image_list_scroll->add(*image_list);
106 image_page->attach(*image_list_scroll, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
107 Gtk::HBox *image_buttons=manage(new class Gtk::HBox());
108 image_page->attach(*image_buttons, 0, 1, 1,2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
109 ADD_TOOLBOX_BUTTON(button_image_new,"gtk-new",_("Create a new image"));
110 ADD_TOOLBOX_BUTTON(button_image_delete,"gtk-delete",_("Delete image"));
111 ADD_TOOLBOX_BUTTON(button_image_rename,"gtk-rename",_("Rename image"));
112 ADD_TOOLBOX_BUTTON(button_image_copy,"gtk-copy",_("Duplicate image"));
113 button_image_new->signal_clicked().connect(sigc::mem_fun(*this,&CompView::new_image));
114 button_image_delete->signal_clicked().connect(sigc::mem_fun(*this,&CompView::delete_image));
115 button_image_rename->signal_clicked().connect(sigc::mem_fun(*this,&CompView::rename_image));
116 button_image_copy->signal_clicked().connect(sigc::mem_fun(*this,&CompView::copy_image));
117 image_buttons->pack_start(*button_image_new);
118 image_buttons->pack_start(*button_image_delete);
119 image_buttons->pack_start(*button_image_rename);
120 image_buttons->pack_start(*button_image_copy);
122 studio::Instance::ValueNodeColumnModel valuenode_column_model;
123 valuenode_list=manage(new class Gtk::TreeView());
124 valuenode_list->append_column(_("Name"),valuenode_column_model.name);
125 valuenode_list->signal_row_activated().connect(sigc::mem_fun(*this,&CompView::on_valuenode_activate));
126 valuenode_list->set_rules_hint();
128 Gtk::Table *valuenode_page = manage(new class Gtk::Table(2, 1, false));
129 Gtk::ScrolledWindow *valuenode_list_scroll = manage(new class Gtk::ScrolledWindow());
130 valuenode_list_scroll->set_flags(Gtk::CAN_FOCUS);
131 valuenode_list_scroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
132 valuenode_list_scroll->add(*valuenode_list);
133 valuenode_page->attach(*valuenode_list_scroll, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
134 Gtk::HBox *valuenode_buttons=manage(new class Gtk::HBox());
135 valuenode_page->attach(*valuenode_buttons, 0, 1, 1,2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
136 ADD_TOOLBOX_BUTTON(button_valuenode_new,"gtk-new",_("Create a new value_node"));
137 ADD_TOOLBOX_BUTTON(button_valuenode_delete,"gtk-delete",_("Delete value_node"));
138 ADD_TOOLBOX_BUTTON(button_valuenode_rename,"gtk-rename",_("Rename value_node"));
139 ADD_TOOLBOX_BUTTON(button_valuenode_copy,"gtk-copy",_("Duplicate value_node"));
140 button_valuenode_new->signal_clicked().connect(sigc::mem_fun(*this,&CompView::new_value_node));
141 button_valuenode_delete->signal_clicked().connect(sigc::mem_fun(*this,&CompView::delete_value_node));
142 button_valuenode_rename->signal_clicked().connect(sigc::mem_fun(*this,&CompView::rename_value_node));
143 button_valuenode_copy->signal_clicked().connect(sigc::mem_fun(*this,&CompView::copy_value_node));
144 valuenode_buttons->pack_start(*button_valuenode_new);
145 valuenode_buttons->pack_start(*button_valuenode_delete);
146 valuenode_buttons->pack_start(*button_valuenode_rename);
147 valuenode_buttons->pack_start(*button_valuenode_copy);
150 notebook->append_page(*image_page,_("Images"));
151 notebook->append_page(*valuenode_page,_("ValueNodes"));
153 image_page->show_all();
154 valuenode_page->show_all();
156 // notebook->set_current_page(0);
157 signal_delete_event().connect(sigc::hide(sigc::mem_fun(*this, &CompView::close)));
158 App::signal_instance_created().connect(sigc::mem_fun(*this,&studio::CompView::new_instance));
159 App::signal_instance_deleted().connect(sigc::mem_fun(*this,&studio::CompView::delete_instance));
160 App::signal_instance_selected().connect(sigc::mem_fun(*this,&studio::CompView::set_selected_instance_signal));
166 set_title(_("Canvas Browser"));
169 property_window_position().set_value(Gtk::WIN_POS_NONE);
170 set_default_size(200,300);
173 CompView::~CompView()
177 etl::loose_handle<studio::CanvasView>
178 CompView::get_selected_canvas_view()
180 return get_selected_instance()->find_canvas_view(get_selected_canvas());
184 CompView::create_canvas_tree()
186 studio::Instance::CanvasTreeModel canvas_tree_model;
187 canvas_tree=manage(new class Gtk::TreeView());
189 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("ID")) );
190 // Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
192 //column->pack_start(*icon_cellrenderer,false);
193 column->pack_start(canvas_tree_model.icon, false); //false = don't expand.
194 column->pack_start(canvas_tree_model.label);
197 // column->add_attribute(icon_cellrenderer->property_pixbuf(), canvas_tree_model.icon);
200 canvas_tree->append_column(*column);
202 canvas_tree->set_rules_hint();
203 canvas_tree->signal_row_activated().connect(sigc::mem_fun(*this,&CompView::on_row_activate));
204 canvas_tree->signal_event().connect(sigc::mem_fun(*this,&CompView::on_tree_event));
205 canvas_tree->add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
206 canvas_tree->add_events(Gdk::BUTTON1_MOTION_MASK);
209 Gtk::ScrolledWindow *scrolledwindow = manage(new class Gtk::ScrolledWindow());
210 scrolledwindow->set_flags(Gtk::CAN_FOCUS);
211 scrolledwindow->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
212 scrolledwindow->add(*canvas_tree);
213 scrolledwindow->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
214 scrolledwindow->show();
216 return scrolledwindow;
220 CompView::create_action_tree()
222 studio::HistoryTreeStore::Model history_tree_model;
223 action_tree=manage(new class Gtk::TreeView());
225 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column("") );
227 Gtk::CellRendererToggle* toggle_cr = Gtk::manage( new Gtk::CellRendererToggle() );
228 toggle_cr->signal_toggled().connect(sigc::mem_fun(*this, &studio::CompView::on_action_toggle) );
230 column->pack_start(*toggle_cr); //false = don't expand.
231 column->add_attribute(toggle_cr->property_active(),history_tree_model.is_active);
232 column->set_resizable();
233 column->set_clickable();
235 action_tree->append_column(*column);
238 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Canvas")) );
239 Gtk::CellRendererText *text_cr=Gtk::manage(new Gtk::CellRendererText());
240 text_cr->property_foreground()=Glib::ustring("#7f7f7f");
242 column->pack_start(*text_cr);
243 column->add_attribute(text_cr->property_text(),history_tree_model.canvas_id);
244 column->add_attribute(text_cr->property_foreground_set(),history_tree_model.is_redo);
246 action_tree->append_column(*column);
249 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Jump")) );
251 Gtk::CellRendererText* cell_renderer_jump=Gtk::manage(new Gtk::CellRendererText());
252 column->pack_start(*cell_renderer_jump,true);
254 cell_renderer_jump->property_text()=_("(JMP)");
255 cell_renderer_jump->property_foreground()="#003a7f";
257 column->set_resizable();
258 column->set_clickable();
260 column->set_sort_column(COLUMNID_JUMP);
262 action_tree->append_column(*column);
266 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Action")) );
268 Gtk::CellRendererText *text_cr=Gtk::manage(new Gtk::CellRendererText());
269 text_cr->property_foreground()=Glib::ustring("#7f7f7f");
273 //column->pack_start(history_tree_model.icon, false); //false = don't expand.
274 column->pack_start(*text_cr);
275 column->add_attribute(text_cr->property_text(),history_tree_model.name);
276 column->add_attribute(text_cr->property_foreground_set(),history_tree_model.is_redo);
278 action_tree->append_column(*column);
282 action_tree->set_rules_hint();
283 // action_tree->signal_row_activated().connect(sigc::mem_fun(*this,&CompView::on_row_activate));
284 action_tree->signal_event().connect(sigc::mem_fun(*this,&CompView::on_action_event));
285 // action_tree->add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
286 // action_tree->add_events(Gdk::BUTTON1_MOTION_MASK);
289 Gtk::ScrolledWindow *scrolledwindow = manage(new class Gtk::ScrolledWindow());
290 scrolledwindow->set_flags(Gtk::CAN_FOCUS);
291 scrolledwindow->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
292 scrolledwindow->add(*action_tree);
293 scrolledwindow->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
294 scrolledwindow->show();
296 Gtk::Button* clear_button(manage(new Gtk::Button(_("Clear Undo"))));
297 clear_button->signal_pressed().connect(sigc::mem_fun(*this,&studio::CompView::clear_history));
299 Gtk::Button* clear_redo_button(manage(new Gtk::Button(_("Clear Redo"))));
300 clear_redo_button->signal_pressed().connect(sigc::mem_fun(*this,&studio::CompView::clear_redo));
302 Gtk::Table* table(manage(new Gtk::Table()));
303 table->attach(*scrolledwindow, 0, 2, 0,1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
304 table->attach(*clear_button, 0, 1, 1,2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
305 table->attach(*clear_redo_button, 1, 2, 1,2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
313 CompView::create_instance_selector()
315 instance_selector=manage(new class Gtk::OptionMenu());
316 instance_selector->show();
317 instance_selector->set_menu(instance_list_menu);
318 return instance_selector;
329 CompView::clear_history()
331 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?")))
333 selected_instance->clear_undo_stack();
338 CompView::clear_redo()
340 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?")))
342 selected_instance->clear_redo_stack();
347 CompView::init_menu()
349 menu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
350 menu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("synfig-canvas_new"),
351 sigc::mem_fun(*this,&CompView::menu_new_canvas)));
352 menu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-delete"),
353 sigc::mem_fun(*this,&CompView::menu_delete)));
354 menu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("synfig-rename"),
355 sigc::mem_fun(*this,&CompView::menu_rename)));
358 etl::loose_handle<synfig::Canvas>
359 CompView::get_selected_canvas()
361 Glib::RefPtr<Gtk::TreeSelection> selection=canvas_tree->get_selection();
363 if(!selection || !selection->get_selected())
366 studio::Instance::CanvasTreeModel canvas_tree_model;
368 return static_cast<etl::handle<synfig::Canvas> >((*selection->get_selected())[canvas_tree_model.canvas]);
372 CompView::menu_new_canvas()
376 get_selected_canvas_view()->new_child_canvas();
381 CompView::menu_delete()
383 studio::App::dialog_not_implemented();
387 CompView::menu_rename()
389 studio::App::dialog_not_implemented();
393 CompView::set_selected_instance_signal(etl::handle<studio::Instance> x)
395 set_selected_instance(x);
399 CompView::set_selected_instance_(etl::handle<studio::Instance> instance)
401 if(studio::App::shutdown_in_progress)
404 selected_instance=instance;
407 canvas_tree->set_model(instance->canvas_tree_store());
408 action_tree->set_model(instance->history_tree_store());
414 canvas_tree->set_model(Glib::RefPtr< Gtk::TreeModel >());
415 action_tree->set_model(Glib::RefPtr< Gtk::TreeModel >());
422 CompView::set_selected_instance(etl::loose_handle<studio::Instance> x)
424 if(studio::App::shutdown_in_progress)
427 // if it's already selected, don't select it again
428 if (x==selected_instance)
431 std::list<etl::handle<studio::Instance> >::iterator iter;
436 for(i=0,iter=studio::App::instance_list.begin();iter!=studio::App::instance_list.end() && ((*iter)!=x);iter++,i++);
440 instance_selector->set_history(i);
443 instance_selector->set_history(0);
445 set_selected_instance_(x);
449 CompView::new_instance(etl::handle<studio::Instance> instance)
451 if(studio::App::shutdown_in_progress)
456 etl::loose_handle<studio::Instance> loose_instance(instance);
458 instance->synfigapp::Instance::signal_filename_changed().connect(sigc::mem_fun(*this,&CompView::refresh_instances));
459 instance->synfigapp::Instance::signal_filename_changed().connect(
460 sigc::bind<etl::loose_handle<studio::Instance> >(
461 sigc::mem_fun(*this,&CompView::set_selected_instance),
467 std::string name=basename(instance->get_file_name());
469 instance_list_menu.items().push_back(Gtk::Menu_Helpers::MenuElem(name,
470 sigc::bind<etl::loose_handle<studio::Instance> >(sigc::mem_fun(&studio::App::set_selected_instance),loose_instance) ));
475 CompView::delete_instance(etl::handle<studio::Instance> instance)
477 if(studio::App::shutdown_in_progress)
482 if(selected_instance==instance)
484 set_selected_instance(0);
485 instance_selector->set_history(0);
490 CompView::refresh_instances()
492 if(studio::App::shutdown_in_progress)
495 if(!instance_list_menu.items().empty())
496 instance_list_menu.items().clear();
498 std::list<etl::handle<studio::Instance> >::iterator iter;
499 for(iter=studio::App::instance_list.begin();iter!=studio::App::instance_list.end();iter++)
501 std::string name=basename((*iter)->get_file_name());
503 instance_list_menu.items().push_back(Gtk::Menu_Helpers::MenuElem(name,
504 sigc::bind<etl::loose_handle<studio::Instance> >(sigc::mem_fun(&studio::App::set_selected_instance),*iter) ));
506 instance_selector->set_menu(instance_list_menu);
510 CompView::on_row_activate(const Gtk::TreeModel::Path &path, Gtk::TreeViewColumn *)
512 assert(get_selected_instance());
513 studio::Instance::CanvasTreeModel canvas_tree_model;
514 const Gtk::TreeRow row = *(get_selected_instance()->canvas_tree_store()->get_iter(path));
515 if(row[canvas_tree_model.is_canvas])
516 get_selected_instance()->focus(row[canvas_tree_model.canvas]);
518 studio::App::dialog_not_implemented();
522 CompView::on_action_event(GdkEvent *event)
524 studio::HistoryTreeStore::Model model;
527 case GDK_BUTTON_PRESS:
528 case GDK_2BUTTON_PRESS:
530 Gtk::TreeModel::Path path;
531 Gtk::TreeViewColumn *column;
533 if(!action_tree->get_path_at_pos(
534 int(event->button.x),int(event->button.y), // x, y
535 path, // TreeModel::Path&
536 column, //TreeViewColumn*&
537 cell_x,cell_y //int&cell_x,int&cell_y
540 const Gtk::TreeRow row = *(action_tree->get_model()->get_iter(path));
542 //signal_user_click()(event->button.button,row,(ColumnID)column->get_sort_column_id());
543 if((ColumnID)column->get_sort_column_id()==COLUMNID_JUMP)
545 etl::handle<synfigapp::Action::Undoable> action(row[model.action]);
546 if((bool)row[model.is_undo])
548 while(get_selected_instance()->undo_action_stack().size() && get_selected_instance()->undo_action_stack().front()!=action)
549 get_selected_instance()->undo();
551 else if((bool)row[model.is_redo])
553 while(get_selected_instance()->redo_action_stack().size() && get_selected_instance()->undo_action_stack().front()!=action)
554 get_selected_instance()->redo();
559 case GDK_BUTTON_RELEASE:
568 CompView::on_tree_event(GdkEvent *event)
572 case GDK_BUTTON_PRESS:
573 switch(event->button.button)
576 if(get_selected_canvas())
578 menu.items().clear();
580 synfigapp::Action::ParamList param_list;
581 param_list.add("canvas",synfig::Canvas::Handle(get_selected_canvas()));
582 param_list.add("canvas_interface",get_selected_instance()->find_canvas_interface(get_selected_canvas()));
583 get_selected_instance()->find_canvas_view(get_selected_canvas())->add_actions_to_menu(&menu, param_list,synfigapp::Action::CATEGORY_CANVAS);
592 case GDK_MOTION_NOTIFY:
594 case GDK_BUTTON_RELEASE:
603 CompView::on_action_toggle(const Glib::ustring& path_string)
605 studio::HistoryTreeStore::Model history_tree_model;
607 Gtk::TreePath path(path_string);
609 const Gtk::TreeRow row = *(selected_instance->history_tree_store()->get_iter(path));
611 handle<synfigapp::Action::Undoable> action=row[history_tree_model.action];
613 selected_instance->synfigapp::Instance::set_action_status(action,!action->is_active());