1 /* === S Y N F I G ========================================================= */
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2008 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 ** === N O T E S ===========================================================
24 ** ========================================================================= */
26 /* === H E A D E R S ======================================================= */
37 #include <gtkmm/scrolledwindow.h>
41 #include <sigc++/signal.h>
42 #include <sigc++/hide.h>
43 #include <sigc++/slot.h>
44 #include "canvasview.h"
45 #include <synfigapp/action.h>
51 /* === M A C R O S ========================================================= */
53 #define ADD_TOOLBOX_BUTTON(button,stockid,tooltip) \
54 Gtk::Button *button = manage(new class Gtk::Button()); \
55 button->add(*manage(new Gtk::Image(Gtk::StockID(stockid),Gtk::IconSize(4)))); \
56 tooltips.set_tip(*button,tooltip); \
61 using namespace synfig;
62 using namespace studio;
64 #define COLUMNID_JUMP (787584)
67 /* === G L O B A L S ======================================================= */
69 /* === P R O C E D U R E S ================================================= */
71 /* === M E T H O D S ======================================================= */
74 Gtk::Window(Gtk::WINDOW_TOPLEVEL),
75 dialog_settings(this,"compview")
78 set_type_hint(Gdk::WINDOW_TYPE_HINT_UTILITY);
80 Gtk::Table *table = manage(new class Gtk::Table(2, 1, false));
83 table->attach(*create_instance_selector(), 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
85 notebook=manage(new class Gtk::Notebook());
87 table->attach(*notebook, 0, 1, 1,2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
89 notebook->append_page(*create_canvas_tree(),_("Canvases"));
90 notebook->append_page(*create_action_tree(),_("History"));
96 studio::Instance::ImageColumnModel image_column_model;
97 image_list=manage(new class Gtk::TreeView());
98 image_list->append_column(_("Name"),image_column_model.name);
99 image_list->signal_row_activated().connect(sigc::mem_fun(*this,&CompView::on_image_activate));
100 image_list->set_rules_hint();
102 Gtk::Table *image_page = manage(new class Gtk::Table(2, 1, false));
103 Gtk::ScrolledWindow *image_list_scroll = manage(new class Gtk::ScrolledWindow());
104 image_list_scroll->set_flags(Gtk::CAN_FOCUS);
105 image_list_scroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
106 image_list_scroll->add(*image_list);
107 image_page->attach(*image_list_scroll, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
108 Gtk::HBox *image_buttons=manage(new class Gtk::HBox());
109 image_page->attach(*image_buttons, 0, 1, 1,2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
110 ADD_TOOLBOX_BUTTON(button_image_new,"gtk-new",_("Create a new image"));
111 ADD_TOOLBOX_BUTTON(button_image_delete,"gtk-delete",_("Delete image"));
112 ADD_TOOLBOX_BUTTON(button_image_rename,"gtk-rename",_("Rename image"));
113 ADD_TOOLBOX_BUTTON(button_image_copy,"gtk-copy",_("Duplicate image"));
114 button_image_new->signal_clicked().connect(sigc::mem_fun(*this,&CompView::new_image));
115 button_image_delete->signal_clicked().connect(sigc::mem_fun(*this,&CompView::delete_image));
116 button_image_rename->signal_clicked().connect(sigc::mem_fun(*this,&CompView::rename_image));
117 button_image_copy->signal_clicked().connect(sigc::mem_fun(*this,&CompView::copy_image));
118 image_buttons->pack_start(*button_image_new);
119 image_buttons->pack_start(*button_image_delete);
120 image_buttons->pack_start(*button_image_rename);
121 image_buttons->pack_start(*button_image_copy);
123 studio::Instance::ValueNodeColumnModel valuenode_column_model;
124 valuenode_list=manage(new class Gtk::TreeView());
125 valuenode_list->append_column(_("Name"),valuenode_column_model.name);
126 valuenode_list->signal_row_activated().connect(sigc::mem_fun(*this,&CompView::on_valuenode_activate));
127 valuenode_list->set_rules_hint();
129 Gtk::Table *valuenode_page = manage(new class Gtk::Table(2, 1, false));
130 Gtk::ScrolledWindow *valuenode_list_scroll = manage(new class Gtk::ScrolledWindow());
131 valuenode_list_scroll->set_flags(Gtk::CAN_FOCUS);
132 valuenode_list_scroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
133 valuenode_list_scroll->add(*valuenode_list);
134 valuenode_page->attach(*valuenode_list_scroll, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
135 Gtk::HBox *valuenode_buttons=manage(new class Gtk::HBox());
136 valuenode_page->attach(*valuenode_buttons, 0, 1, 1,2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
137 ADD_TOOLBOX_BUTTON(button_valuenode_new,"gtk-new",_("Create a new value_node"));
138 ADD_TOOLBOX_BUTTON(button_valuenode_delete,"gtk-delete",_("Delete value_node"));
139 ADD_TOOLBOX_BUTTON(button_valuenode_rename,"gtk-rename",_("Rename value_node"));
140 ADD_TOOLBOX_BUTTON(button_valuenode_copy,"gtk-copy",_("Duplicate value_node"));
141 button_valuenode_new->signal_clicked().connect(sigc::mem_fun(*this,&CompView::new_value_node));
142 button_valuenode_delete->signal_clicked().connect(sigc::mem_fun(*this,&CompView::delete_value_node));
143 button_valuenode_rename->signal_clicked().connect(sigc::mem_fun(*this,&CompView::rename_value_node));
144 button_valuenode_copy->signal_clicked().connect(sigc::mem_fun(*this,&CompView::copy_value_node));
145 valuenode_buttons->pack_start(*button_valuenode_new);
146 valuenode_buttons->pack_start(*button_valuenode_delete);
147 valuenode_buttons->pack_start(*button_valuenode_rename);
148 valuenode_buttons->pack_start(*button_valuenode_copy);
151 notebook->append_page(*image_page,_("Images"));
152 notebook->append_page(*valuenode_page,_("ValueNodes"));
154 image_page->show_all();
155 valuenode_page->show_all();
157 // notebook->set_current_page(0);
158 signal_delete_event().connect(sigc::hide(sigc::mem_fun(*this, &CompView::close)));
159 App::signal_instance_created().connect(sigc::mem_fun(*this,&studio::CompView::new_instance));
160 App::signal_instance_deleted().connect(sigc::mem_fun(*this,&studio::CompView::delete_instance));
161 App::signal_instance_selected().connect(sigc::mem_fun(*this,&studio::CompView::set_selected_instance_signal));
167 set_title(_("Canvas Browser"));
170 property_window_position().set_value(Gtk::WIN_POS_NONE);
171 set_default_size(200,300);
174 CompView::~CompView()
178 etl::loose_handle<studio::CanvasView>
179 CompView::get_selected_canvas_view()
181 return get_selected_instance()->find_canvas_view(get_selected_canvas());
185 CompView::create_canvas_tree()
187 studio::Instance::CanvasTreeModel canvas_tree_model;
188 canvas_tree=manage(new class Gtk::TreeView());
190 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("ID")) );
191 // Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
193 //column->pack_start(*icon_cellrenderer,false);
194 column->pack_start(canvas_tree_model.icon, false); //false = don't expand.
195 column->pack_start(canvas_tree_model.label);
198 // column->add_attribute(icon_cellrenderer->property_pixbuf(), canvas_tree_model.icon);
201 canvas_tree->append_column(*column);
203 canvas_tree->set_rules_hint();
204 canvas_tree->signal_row_activated().connect(sigc::mem_fun(*this,&CompView::on_row_activate));
205 canvas_tree->signal_event().connect(sigc::mem_fun(*this,&CompView::on_tree_event));
206 canvas_tree->add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
207 canvas_tree->add_events(Gdk::BUTTON1_MOTION_MASK);
210 Gtk::ScrolledWindow *scrolledwindow = manage(new class Gtk::ScrolledWindow());
211 scrolledwindow->set_flags(Gtk::CAN_FOCUS);
212 scrolledwindow->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
213 scrolledwindow->add(*canvas_tree);
214 scrolledwindow->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
215 scrolledwindow->show();
217 return scrolledwindow;
221 CompView::create_action_tree()
223 studio::HistoryTreeStore::Model history_tree_model;
224 action_tree=manage(new class Gtk::TreeView());
226 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column("") );
228 Gtk::CellRendererToggle* toggle_cr = Gtk::manage( new Gtk::CellRendererToggle() );
229 toggle_cr->signal_toggled().connect(sigc::mem_fun(*this, &studio::CompView::on_action_toggle) );
231 column->pack_start(*toggle_cr); //false = don't expand.
232 column->add_attribute(toggle_cr->property_active(),history_tree_model.is_active);
233 column->set_resizable();
234 column->set_clickable();
236 action_tree->append_column(*column);
239 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Canvas")) );
240 Gtk::CellRendererText *text_cr=Gtk::manage(new Gtk::CellRendererText());
241 text_cr->property_foreground()=Glib::ustring("#7f7f7f");
243 column->pack_start(*text_cr);
244 column->add_attribute(text_cr->property_text(),history_tree_model.canvas_id);
245 column->add_attribute(text_cr->property_foreground_set(),history_tree_model.is_redo);
247 action_tree->append_column(*column);
250 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Jump")) );
252 Gtk::CellRendererText* cell_renderer_jump=Gtk::manage(new Gtk::CellRendererText());
253 column->pack_start(*cell_renderer_jump,true);
255 cell_renderer_jump->property_text()=_("(JMP)");
256 cell_renderer_jump->property_foreground()="#003a7f";
258 column->set_resizable();
259 column->set_clickable();
261 column->set_sort_column(COLUMNID_JUMP);
263 action_tree->append_column(*column);
267 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Action")) );
269 Gtk::CellRendererText *text_cr=Gtk::manage(new Gtk::CellRendererText());
270 text_cr->property_foreground()=Glib::ustring("#7f7f7f");
274 //column->pack_start(history_tree_model.icon, false); //false = don't expand.
275 column->pack_start(*text_cr);
276 column->add_attribute(text_cr->property_text(),history_tree_model.name);
277 column->add_attribute(text_cr->property_foreground_set(),history_tree_model.is_redo);
279 action_tree->append_column(*column);
283 action_tree->set_rules_hint();
284 // action_tree->signal_row_activated().connect(sigc::mem_fun(*this,&CompView::on_row_activate));
285 action_tree->signal_event().connect(sigc::mem_fun(*this,&CompView::on_action_event));
286 // action_tree->add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
287 // action_tree->add_events(Gdk::BUTTON1_MOTION_MASK);
290 Gtk::ScrolledWindow *scrolledwindow = manage(new class Gtk::ScrolledWindow());
291 scrolledwindow->set_flags(Gtk::CAN_FOCUS);
292 scrolledwindow->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
293 scrolledwindow->add(*action_tree);
294 scrolledwindow->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
295 scrolledwindow->show();
297 Gtk::Button* clear_button(manage(new Gtk::Button(_("Clear Undo"))));
298 clear_button->signal_pressed().connect(sigc::mem_fun(*this,&studio::CompView::clear_history));
300 Gtk::Button* clear_redo_button(manage(new Gtk::Button(_("Clear Redo"))));
301 clear_redo_button->signal_pressed().connect(sigc::mem_fun(*this,&studio::CompView::clear_redo));
303 Gtk::Table* table(manage(new Gtk::Table()));
304 table->attach(*scrolledwindow, 0, 2, 0,1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
305 table->attach(*clear_button, 0, 1, 1,2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
306 table->attach(*clear_redo_button, 1, 2, 1,2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
314 CompView::create_instance_selector()
316 instance_selector=manage(new class Gtk::OptionMenu());
317 instance_selector->show();
318 instance_selector->set_menu(instance_list_menu);
319 return instance_selector;
330 CompView::clear_history()
332 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?")))
334 selected_instance->clear_undo_stack();
339 CompView::clear_redo()
341 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?")))
343 selected_instance->clear_redo_stack();
348 CompView::init_menu()
350 menu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
351 menu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("synfig-canvas_new"),
352 sigc::mem_fun(*this,&CompView::menu_new_canvas)));
353 menu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-delete"),
354 sigc::mem_fun(*this,&CompView::menu_delete)));
355 menu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("synfig-rename"),
356 sigc::mem_fun(*this,&CompView::menu_rename)));
359 etl::loose_handle<synfig::Canvas>
360 CompView::get_selected_canvas()
362 Glib::RefPtr<Gtk::TreeSelection> selection=canvas_tree->get_selection();
364 if(!selection || !selection->get_selected())
367 studio::Instance::CanvasTreeModel canvas_tree_model;
369 return static_cast<etl::handle<synfig::Canvas> >((*selection->get_selected())[canvas_tree_model.canvas]);
373 CompView::menu_new_canvas()
377 get_selected_canvas_view()->new_child_canvas();
382 CompView::menu_delete()
384 studio::App::dialog_not_implemented();
388 CompView::menu_rename()
390 studio::App::dialog_not_implemented();
394 CompView::set_selected_instance_signal(etl::handle<studio::Instance> x)
396 set_selected_instance(x);
400 CompView::set_selected_instance_(etl::handle<studio::Instance> instance)
402 if(studio::App::shutdown_in_progress)
405 selected_instance=instance;
408 canvas_tree->set_model(instance->canvas_tree_store());
409 action_tree->set_model(instance->history_tree_store());
415 canvas_tree->set_model(Glib::RefPtr< Gtk::TreeModel >());
416 action_tree->set_model(Glib::RefPtr< Gtk::TreeModel >());
423 CompView::set_selected_instance(etl::loose_handle<studio::Instance> x)
425 if(studio::App::shutdown_in_progress)
428 // if it's already selected, don't select it again
429 if (x==selected_instance)
432 std::list<etl::handle<studio::Instance> >::iterator iter;
437 for(i=0,iter=studio::App::instance_list.begin();iter!=studio::App::instance_list.end() && ((*iter)!=x);iter++,i++);
441 instance_selector->set_history(i);
444 instance_selector->set_history(0);
446 set_selected_instance_(x);
450 CompView::new_instance(etl::handle<studio::Instance> instance)
452 if(studio::App::shutdown_in_progress)
457 etl::loose_handle<studio::Instance> loose_instance(instance);
459 instance->synfigapp::Instance::signal_filename_changed().connect(sigc::mem_fun(*this,&CompView::refresh_instances));
460 instance->synfigapp::Instance::signal_filename_changed().connect(
461 sigc::bind<etl::loose_handle<studio::Instance> >(
462 sigc::mem_fun(*this,&CompView::set_selected_instance),
468 std::string name=basename(instance->get_file_name());
470 instance_list_menu.items().push_back(Gtk::Menu_Helpers::MenuElem(name,
471 sigc::bind<etl::loose_handle<studio::Instance> >(sigc::mem_fun(&studio::App::set_selected_instance),loose_instance) ));
476 CompView::delete_instance(etl::handle<studio::Instance> instance)
478 if(studio::App::shutdown_in_progress)
483 if(selected_instance==instance)
485 set_selected_instance(0);
486 instance_selector->set_history(0);
491 CompView::refresh_instances()
493 if(studio::App::shutdown_in_progress)
496 if(!instance_list_menu.items().empty())
497 instance_list_menu.items().clear();
499 std::list<etl::handle<studio::Instance> >::iterator iter;
500 for(iter=studio::App::instance_list.begin();iter!=studio::App::instance_list.end();iter++)
502 std::string name=basename((*iter)->get_file_name());
504 instance_list_menu.items().push_back(Gtk::Menu_Helpers::MenuElem(name,
505 sigc::bind<etl::loose_handle<studio::Instance> >(sigc::mem_fun(&studio::App::set_selected_instance),*iter) ));
507 instance_selector->set_menu(instance_list_menu);
511 CompView::on_row_activate(const Gtk::TreeModel::Path &path, Gtk::TreeViewColumn *)
513 assert(get_selected_instance());
514 studio::Instance::CanvasTreeModel canvas_tree_model;
515 const Gtk::TreeRow row = *(get_selected_instance()->canvas_tree_store()->get_iter(path));
516 if(row[canvas_tree_model.is_canvas])
517 get_selected_instance()->focus(row[canvas_tree_model.canvas]);
519 studio::App::dialog_not_implemented();
523 CompView::on_action_event(GdkEvent *event)
525 studio::HistoryTreeStore::Model model;
528 case GDK_BUTTON_PRESS:
529 case GDK_2BUTTON_PRESS:
531 Gtk::TreeModel::Path path;
532 Gtk::TreeViewColumn *column;
534 if(!action_tree->get_path_at_pos(
535 int(event->button.x),int(event->button.y), // x, y
536 path, // TreeModel::Path&
537 column, //TreeViewColumn*&
538 cell_x,cell_y //int&cell_x,int&cell_y
541 const Gtk::TreeRow row = *(action_tree->get_model()->get_iter(path));
543 //signal_user_click()(event->button.button,row,(ColumnID)column->get_sort_column_id());
544 if((ColumnID)column->get_sort_column_id()==COLUMNID_JUMP)
546 etl::handle<synfigapp::Action::Undoable> action(row[model.action]);
547 if((bool)row[model.is_undo])
549 while(get_selected_instance()->undo_action_stack().size() && get_selected_instance()->undo_action_stack().front()!=action)
550 get_selected_instance()->undo();
552 else if((bool)row[model.is_redo])
554 while(get_selected_instance()->redo_action_stack().size() && get_selected_instance()->undo_action_stack().front()!=action)
555 get_selected_instance()->redo();
560 case GDK_BUTTON_RELEASE:
569 CompView::on_tree_event(GdkEvent *event)
573 case GDK_BUTTON_PRESS:
574 switch(event->button.button)
577 if(get_selected_canvas())
579 menu.items().clear();
581 synfigapp::Action::ParamList param_list;
582 param_list.add("canvas",synfig::Canvas::Handle(get_selected_canvas()));
583 param_list.add("canvas_interface",get_selected_instance()->find_canvas_interface(get_selected_canvas()));
584 get_selected_instance()->find_canvas_view(get_selected_canvas())->add_actions_to_menu(&menu, param_list,synfigapp::Action::CATEGORY_CANVAS);
593 case GDK_MOTION_NOTIFY:
595 case GDK_BUTTON_RELEASE:
604 CompView::on_action_toggle(const Glib::ustring& path_string)
606 studio::HistoryTreeStore::Model history_tree_model;
608 Gtk::TreePath path(path_string);
610 const Gtk::TreeRow row = *(selected_instance->history_tree_store()->get_iter(path));
612 handle<synfigapp::Action::Undoable> action=row[history_tree_model.action];
614 selected_instance->synfigapp::Instance::set_action_status(action,!action->is_active());