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")
77 assert(0); //CHECK: This class does not appear to be used.
79 set_type_hint(Gdk::WINDOW_TYPE_HINT_UTILITY);
81 Gtk::Table *table = manage(new class Gtk::Table(2, 1, false));
84 table->attach(*create_instance_selector(), 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
86 notebook=manage(new class Gtk::Notebook());
88 table->attach(*notebook, 0, 1, 1,2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
90 notebook->append_page(*create_canvas_tree(),_("Canvases"));
91 notebook->append_page(*create_action_tree(),_("History"));
97 studio::Instance::ImageColumnModel image_column_model;
98 image_list=manage(new class Gtk::TreeView());
99 image_list->append_column(_("Name"),image_column_model.name);
100 image_list->signal_row_activated().connect(sigc::mem_fun(*this,&CompView::on_image_activate));
101 image_list->set_rules_hint();
103 Gtk::Table *image_page = manage(new class Gtk::Table(2, 1, false));
104 Gtk::ScrolledWindow *image_list_scroll = manage(new class Gtk::ScrolledWindow());
105 image_list_scroll->set_flags(Gtk::CAN_FOCUS);
106 image_list_scroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
107 image_list_scroll->add(*image_list);
108 image_page->attach(*image_list_scroll, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
109 Gtk::HBox *image_buttons=manage(new class Gtk::HBox());
110 image_page->attach(*image_buttons, 0, 1, 1,2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
111 ADD_TOOLBOX_BUTTON(button_image_new,"gtk-new",_("Create a new image"));
112 ADD_TOOLBOX_BUTTON(button_image_delete,"gtk-delete",_("Delete image"));
113 ADD_TOOLBOX_BUTTON(button_image_rename,"gtk-rename",_("Rename image"));
114 ADD_TOOLBOX_BUTTON(button_image_copy,"gtk-copy",_("Duplicate image"));
115 button_image_new->signal_clicked().connect(sigc::mem_fun(*this,&CompView::new_image));
116 button_image_delete->signal_clicked().connect(sigc::mem_fun(*this,&CompView::delete_image));
117 button_image_rename->signal_clicked().connect(sigc::mem_fun(*this,&CompView::rename_image));
118 button_image_copy->signal_clicked().connect(sigc::mem_fun(*this,&CompView::copy_image));
119 image_buttons->pack_start(*button_image_new);
120 image_buttons->pack_start(*button_image_delete);
121 image_buttons->pack_start(*button_image_rename);
122 image_buttons->pack_start(*button_image_copy);
124 studio::Instance::ValueNodeColumnModel valuenode_column_model;
125 valuenode_list=manage(new class Gtk::TreeView());
126 valuenode_list->append_column(_("Name"),valuenode_column_model.name);
127 valuenode_list->signal_row_activated().connect(sigc::mem_fun(*this,&CompView::on_valuenode_activate));
128 valuenode_list->set_rules_hint();
130 Gtk::Table *valuenode_page = manage(new class Gtk::Table(2, 1, false));
131 Gtk::ScrolledWindow *valuenode_list_scroll = manage(new class Gtk::ScrolledWindow());
132 valuenode_list_scroll->set_flags(Gtk::CAN_FOCUS);
133 valuenode_list_scroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
134 valuenode_list_scroll->add(*valuenode_list);
135 valuenode_page->attach(*valuenode_list_scroll, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
136 Gtk::HBox *valuenode_buttons=manage(new class Gtk::HBox());
137 valuenode_page->attach(*valuenode_buttons, 0, 1, 1,2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
138 ADD_TOOLBOX_BUTTON(button_valuenode_new,"gtk-new",_("Create a new value_node"));
139 ADD_TOOLBOX_BUTTON(button_valuenode_delete,"gtk-delete",_("Delete value_node"));
140 ADD_TOOLBOX_BUTTON(button_valuenode_rename,"gtk-rename",_("Rename value_node"));
141 ADD_TOOLBOX_BUTTON(button_valuenode_copy,"gtk-copy",_("Duplicate value_node"));
142 button_valuenode_new->signal_clicked().connect(sigc::mem_fun(*this,&CompView::new_value_node));
143 button_valuenode_delete->signal_clicked().connect(sigc::mem_fun(*this,&CompView::delete_value_node));
144 button_valuenode_rename->signal_clicked().connect(sigc::mem_fun(*this,&CompView::rename_value_node));
145 button_valuenode_copy->signal_clicked().connect(sigc::mem_fun(*this,&CompView::copy_value_node));
146 valuenode_buttons->pack_start(*button_valuenode_new);
147 valuenode_buttons->pack_start(*button_valuenode_delete);
148 valuenode_buttons->pack_start(*button_valuenode_rename);
149 valuenode_buttons->pack_start(*button_valuenode_copy);
152 notebook->append_page(*image_page,_("Images"));
153 notebook->append_page(*valuenode_page,_("ValueNodes"));
155 image_page->show_all();
156 valuenode_page->show_all();
158 // notebook->set_current_page(0);
159 signal_delete_event().connect(sigc::hide(sigc::mem_fun(*this, &CompView::close)));
160 App::signal_instance_created().connect(sigc::mem_fun(*this,&studio::CompView::new_instance));
161 App::signal_instance_deleted().connect(sigc::mem_fun(*this,&studio::CompView::delete_instance));
162 App::signal_instance_selected().connect(sigc::mem_fun(*this,&studio::CompView::set_selected_instance_signal));
168 set_title(_("Canvas Browser"));
171 property_window_position().set_value(Gtk::WIN_POS_NONE);
172 set_default_size(200,300);
175 CompView::~CompView()
179 etl::loose_handle<studio::CanvasView>
180 CompView::get_selected_canvas_view()
182 return get_selected_instance()->find_canvas_view(get_selected_canvas());
186 CompView::create_canvas_tree()
188 studio::Instance::CanvasTreeModel canvas_tree_model;
189 canvas_tree=manage(new class Gtk::TreeView());
191 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("ID")) );
192 // Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
194 //column->pack_start(*icon_cellrenderer,false);
195 column->pack_start(canvas_tree_model.icon, false); //false = don't expand.
196 column->pack_start(canvas_tree_model.label);
199 // column->add_attribute(icon_cellrenderer->property_pixbuf(), canvas_tree_model.icon);
202 canvas_tree->append_column(*column);
204 canvas_tree->set_rules_hint();
205 canvas_tree->signal_row_activated().connect(sigc::mem_fun(*this,&CompView::on_row_activate));
206 canvas_tree->signal_event().connect(sigc::mem_fun(*this,&CompView::on_tree_event));
207 canvas_tree->add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
208 canvas_tree->add_events(Gdk::BUTTON1_MOTION_MASK);
211 Gtk::ScrolledWindow *scrolledwindow = manage(new class Gtk::ScrolledWindow());
212 scrolledwindow->set_flags(Gtk::CAN_FOCUS);
213 scrolledwindow->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
214 scrolledwindow->add(*canvas_tree);
215 scrolledwindow->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
216 scrolledwindow->show();
218 return scrolledwindow;
222 CompView::create_action_tree()
224 studio::HistoryTreeStore::Model history_tree_model;
225 action_tree=manage(new class Gtk::TreeView());
227 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column("") );
229 Gtk::CellRendererToggle* toggle_cr = Gtk::manage( new Gtk::CellRendererToggle() );
230 toggle_cr->signal_toggled().connect(sigc::mem_fun(*this, &studio::CompView::on_action_toggle) );
232 column->pack_start(*toggle_cr); //false = don't expand.
233 column->add_attribute(toggle_cr->property_active(),history_tree_model.is_active);
234 column->set_resizable();
235 column->set_clickable();
237 action_tree->append_column(*column);
240 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Canvas")) );
241 Gtk::CellRendererText *text_cr=Gtk::manage(new Gtk::CellRendererText());
242 text_cr->property_foreground()=Glib::ustring("#7f7f7f");
244 column->pack_start(*text_cr);
245 column->add_attribute(text_cr->property_text(),history_tree_model.canvas_id);
246 column->add_attribute(text_cr->property_foreground_set(),history_tree_model.is_redo);
248 action_tree->append_column(*column);
251 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Jump")) );
253 Gtk::CellRendererText* cell_renderer_jump=Gtk::manage(new Gtk::CellRendererText());
254 column->pack_start(*cell_renderer_jump,true);
256 cell_renderer_jump->property_text()=_("(JMP)");
257 cell_renderer_jump->property_foreground()="#003a7f";
259 column->set_resizable();
260 column->set_clickable();
262 column->set_sort_column(COLUMNID_JUMP);
264 action_tree->append_column(*column);
268 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Action")) );
270 Gtk::CellRendererText *text_cr=Gtk::manage(new Gtk::CellRendererText());
271 text_cr->property_foreground()=Glib::ustring("#7f7f7f");
275 //column->pack_start(history_tree_model.icon, false); //false = don't expand.
276 column->pack_start(*text_cr);
277 column->add_attribute(text_cr->property_text(),history_tree_model.name);
278 column->add_attribute(text_cr->property_foreground_set(),history_tree_model.is_redo);
280 action_tree->append_column(*column);
284 action_tree->set_rules_hint();
285 // action_tree->signal_row_activated().connect(sigc::mem_fun(*this,&CompView::on_row_activate));
286 action_tree->signal_event().connect(sigc::mem_fun(*this,&CompView::on_action_event));
287 // action_tree->add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
288 // action_tree->add_events(Gdk::BUTTON1_MOTION_MASK);
291 Gtk::ScrolledWindow *scrolledwindow = manage(new class Gtk::ScrolledWindow());
292 scrolledwindow->set_flags(Gtk::CAN_FOCUS);
293 scrolledwindow->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
294 scrolledwindow->add(*action_tree);
295 scrolledwindow->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
296 scrolledwindow->show();
298 Gtk::Button* clear_button(manage(new Gtk::Button(_("Clear Undo"))));
299 clear_button->signal_pressed().connect(sigc::mem_fun(*this,&studio::CompView::clear_history));
301 Gtk::Button* clear_redo_button(manage(new Gtk::Button(_("Clear Redo"))));
302 clear_redo_button->signal_pressed().connect(sigc::mem_fun(*this,&studio::CompView::clear_redo));
304 Gtk::Table* table(manage(new Gtk::Table()));
305 table->attach(*scrolledwindow, 0, 2, 0,1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
306 table->attach(*clear_button, 0, 1, 1,2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
307 table->attach(*clear_redo_button, 1, 2, 1,2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
315 CompView::create_instance_selector()
317 instance_selector=manage(new class Gtk::OptionMenu());
318 instance_selector->show();
319 instance_selector->set_menu(instance_list_menu);
320 return instance_selector;
331 CompView::clear_history()
333 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?")))
335 selected_instance->clear_undo_stack();
340 CompView::clear_redo()
342 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?")))
344 selected_instance->clear_redo_stack();
349 CompView::init_menu()
351 menu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
352 menu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("synfig-canvas_new"),
353 sigc::mem_fun(*this,&CompView::menu_new_canvas)));
354 menu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-delete"),
355 sigc::mem_fun(*this,&CompView::menu_delete)));
356 menu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("synfig-rename"),
357 sigc::mem_fun(*this,&CompView::menu_rename)));
360 etl::loose_handle<synfig::Canvas>
361 CompView::get_selected_canvas()
363 Glib::RefPtr<Gtk::TreeSelection> selection=canvas_tree->get_selection();
365 if(!selection || !selection->get_selected())
368 studio::Instance::CanvasTreeModel canvas_tree_model;
370 return static_cast<etl::handle<synfig::Canvas> >((*selection->get_selected())[canvas_tree_model.canvas]);
374 CompView::menu_new_canvas()
378 get_selected_canvas_view()->new_child_canvas();
383 CompView::menu_delete()
385 studio::App::dialog_not_implemented();
389 CompView::menu_rename()
391 studio::App::dialog_not_implemented();
395 CompView::set_selected_instance_signal(etl::handle<studio::Instance> x)
397 set_selected_instance(x);
401 CompView::set_selected_instance_(etl::handle<studio::Instance> instance)
403 if(studio::App::shutdown_in_progress)
406 selected_instance=instance;
409 canvas_tree->set_model(instance->canvas_tree_store());
410 action_tree->set_model(instance->history_tree_store());
416 canvas_tree->set_model(Glib::RefPtr< Gtk::TreeModel >());
417 action_tree->set_model(Glib::RefPtr< Gtk::TreeModel >());
424 CompView::set_selected_instance(etl::loose_handle<studio::Instance> x)
426 if(studio::App::shutdown_in_progress)
429 // if it's already selected, don't select it again
430 if (x==selected_instance)
433 std::list<etl::handle<studio::Instance> >::iterator iter;
438 for(i=0,iter=studio::App::instance_list.begin();iter!=studio::App::instance_list.end() && ((*iter)!=x);iter++,i++);
442 instance_selector->set_history(i);
445 instance_selector->set_history(0);
447 set_selected_instance_(x);
451 CompView::new_instance(etl::handle<studio::Instance> instance)
453 if(studio::App::shutdown_in_progress)
458 etl::loose_handle<studio::Instance> loose_instance(instance);
460 instance->synfigapp::Instance::signal_filename_changed().connect(sigc::mem_fun(*this,&CompView::refresh_instances));
461 instance->synfigapp::Instance::signal_filename_changed().connect(
462 sigc::bind<etl::loose_handle<studio::Instance> >(
463 sigc::mem_fun(*this,&CompView::set_selected_instance),
469 std::string name=basename(instance->get_file_name());
471 instance_list_menu.items().push_back(Gtk::Menu_Helpers::MenuElem(name,
472 sigc::bind<etl::loose_handle<studio::Instance> >(sigc::mem_fun(&studio::App::set_selected_instance),loose_instance) ));
477 CompView::delete_instance(etl::handle<studio::Instance> instance)
479 if(studio::App::shutdown_in_progress)
484 if(selected_instance==instance)
486 set_selected_instance(0);
487 instance_selector->set_history(0);
492 CompView::refresh_instances()
494 if(studio::App::shutdown_in_progress)
497 if(!instance_list_menu.items().empty())
498 instance_list_menu.items().clear();
500 std::list<etl::handle<studio::Instance> >::iterator iter;
501 for(iter=studio::App::instance_list.begin();iter!=studio::App::instance_list.end();iter++)
503 std::string name=basename((*iter)->get_file_name());
505 instance_list_menu.items().push_back(Gtk::Menu_Helpers::MenuElem(name,
506 sigc::bind<etl::loose_handle<studio::Instance> >(sigc::mem_fun(&studio::App::set_selected_instance),*iter) ));
508 instance_selector->set_menu(instance_list_menu);
512 CompView::on_row_activate(const Gtk::TreeModel::Path &path, Gtk::TreeViewColumn *)
514 assert(get_selected_instance());
515 studio::Instance::CanvasTreeModel canvas_tree_model;
516 const Gtk::TreeRow row = *(get_selected_instance()->canvas_tree_store()->get_iter(path));
517 if(row[canvas_tree_model.is_canvas])
518 get_selected_instance()->focus(row[canvas_tree_model.canvas]);
520 studio::App::dialog_not_implemented();
524 CompView::on_action_event(GdkEvent *event)
526 studio::HistoryTreeStore::Model model;
529 case GDK_BUTTON_PRESS:
530 case GDK_2BUTTON_PRESS:
532 Gtk::TreeModel::Path path;
533 Gtk::TreeViewColumn *column;
535 if(!action_tree->get_path_at_pos(
536 int(event->button.x),int(event->button.y), // x, y
537 path, // TreeModel::Path&
538 column, //TreeViewColumn*&
539 cell_x,cell_y //int&cell_x,int&cell_y
542 const Gtk::TreeRow row = *(action_tree->get_model()->get_iter(path));
544 //signal_user_click()(event->button.button,row,(ColumnID)column->get_sort_column_id());
545 if((ColumnID)column->get_sort_column_id()==COLUMNID_JUMP)
547 etl::handle<synfigapp::Action::Undoable> action(row[model.action]);
548 if((bool)row[model.is_undo])
550 while(get_selected_instance()->undo_action_stack().size() && get_selected_instance()->undo_action_stack().front()!=action)
551 get_selected_instance()->undo();
553 else if((bool)row[model.is_redo])
555 while(get_selected_instance()->redo_action_stack().size() && get_selected_instance()->undo_action_stack().front()!=action)
556 get_selected_instance()->redo();
561 case GDK_BUTTON_RELEASE:
570 CompView::on_tree_event(GdkEvent *event)
574 case GDK_BUTTON_PRESS:
575 switch(event->button.button)
578 if(get_selected_canvas())
580 menu.items().clear();
582 synfigapp::Action::ParamList param_list;
583 param_list.add("canvas",synfig::Canvas::Handle(get_selected_canvas()));
584 param_list.add("canvas_interface",get_selected_instance()->find_canvas_interface(get_selected_canvas()));
585 get_selected_instance()->find_canvas_view(get_selected_canvas())->add_actions_to_menu(&menu, param_list,synfigapp::Action::CATEGORY_CANVAS);
594 case GDK_MOTION_NOTIFY:
596 case GDK_BUTTON_RELEASE:
605 CompView::on_action_toggle(const Glib::ustring& path_string)
607 studio::HistoryTreeStore::Model history_tree_model;
609 Gtk::TreePath path(path_string);
611 const Gtk::TreeRow row = *(selected_instance->history_tree_store()->get_iter(path));
613 handle<synfigapp::Action::Undoable> action=row[history_tree_model.action];
615 selected_instance->synfigapp::Instance::set_action_status(action,!action->is_active());