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>
48 /* === M A C R O S ========================================================= */
50 #define ADD_TOOLBOX_BUTTON(button,stockid,tooltip) \
51 Gtk::Button *button = manage(new class Gtk::Button()); \
52 button->add(*manage(new Gtk::Image(Gtk::StockID(stockid),Gtk::IconSize(4)))); \
53 tooltips.set_tip(*button,tooltip); \
58 using namespace synfig;
59 using namespace studio;
61 #define COLUMNID_JUMP (787584)
64 /* === G L O B A L S ======================================================= */
66 /* === P R O C E D U R E S ================================================= */
68 /* === M E T H O D S ======================================================= */
71 Gtk::Window(Gtk::WINDOW_TOPLEVEL),
72 dialog_settings(this,"compview")
75 set_type_hint(Gdk::WINDOW_TYPE_HINT_UTILITY);
77 Gtk::Table *table = manage(new class Gtk::Table(2, 1, false));
80 table->attach(*create_instance_selector(), 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
82 notebook=manage(new class Gtk::Notebook());
84 table->attach(*notebook, 0, 1, 1,2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
86 notebook->append_page(*create_canvas_tree(),"Canvases");
87 notebook->append_page(*create_action_tree(),"History");
93 studio::Instance::ImageColumnModel image_column_model;
94 image_list=manage(new class Gtk::TreeView());
95 image_list->append_column("Name",image_column_model.name);
96 image_list->signal_row_activated().connect(sigc::mem_fun(*this,&CompView::on_image_activate));
97 image_list->set_rules_hint();
99 Gtk::Table *image_page = manage(new class Gtk::Table(2, 1, false));
100 Gtk::ScrolledWindow *image_list_scroll = manage(new class Gtk::ScrolledWindow());
101 image_list_scroll->set_flags(Gtk::CAN_FOCUS);
102 image_list_scroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
103 image_list_scroll->add(*image_list);
104 image_page->attach(*image_list_scroll, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
105 Gtk::HBox *image_buttons=manage(new class Gtk::HBox());
106 image_page->attach(*image_buttons, 0, 1, 1,2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
107 ADD_TOOLBOX_BUTTON(button_image_new,"gtk-new","Create a new image");
108 ADD_TOOLBOX_BUTTON(button_image_delete,"gtk-delete","Delete image");
109 ADD_TOOLBOX_BUTTON(button_image_rename,"gtk-rename","Rename image");
110 ADD_TOOLBOX_BUTTON(button_image_copy,"gtk-copy","Duplicate image");
111 button_image_new->signal_clicked().connect(sigc::mem_fun(*this,&CompView::new_image));
112 button_image_delete->signal_clicked().connect(sigc::mem_fun(*this,&CompView::delete_image));
113 button_image_rename->signal_clicked().connect(sigc::mem_fun(*this,&CompView::rename_image));
114 button_image_copy->signal_clicked().connect(sigc::mem_fun(*this,&CompView::copy_image));
115 image_buttons->pack_start(*button_image_new);
116 image_buttons->pack_start(*button_image_delete);
117 image_buttons->pack_start(*button_image_rename);
118 image_buttons->pack_start(*button_image_copy);
120 studio::Instance::ValueNodeColumnModel valuenode_column_model;
121 valuenode_list=manage(new class Gtk::TreeView());
122 valuenode_list->append_column("Name",valuenode_column_model.name);
123 valuenode_list->signal_row_activated().connect(sigc::mem_fun(*this,&CompView::on_valuenode_activate));
124 valuenode_list->set_rules_hint();
126 Gtk::Table *valuenode_page = manage(new class Gtk::Table(2, 1, false));
127 Gtk::ScrolledWindow *valuenode_list_scroll = manage(new class Gtk::ScrolledWindow());
128 valuenode_list_scroll->set_flags(Gtk::CAN_FOCUS);
129 valuenode_list_scroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
130 valuenode_list_scroll->add(*valuenode_list);
131 valuenode_page->attach(*valuenode_list_scroll, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
132 Gtk::HBox *valuenode_buttons=manage(new class Gtk::HBox());
133 valuenode_page->attach(*valuenode_buttons, 0, 1, 1,2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
134 ADD_TOOLBOX_BUTTON(button_valuenode_new,"gtk-new","Create a new value_node");
135 ADD_TOOLBOX_BUTTON(button_valuenode_delete,"gtk-delete","Delete value_node");
136 ADD_TOOLBOX_BUTTON(button_valuenode_rename,"gtk-rename","Rename value_node");
137 ADD_TOOLBOX_BUTTON(button_valuenode_copy,"gtk-copy","Duplicate value_node");
138 button_valuenode_new->signal_clicked().connect(sigc::mem_fun(*this,&CompView::new_value_node));
139 button_valuenode_delete->signal_clicked().connect(sigc::mem_fun(*this,&CompView::delete_value_node));
140 button_valuenode_rename->signal_clicked().connect(sigc::mem_fun(*this,&CompView::rename_value_node));
141 button_valuenode_copy->signal_clicked().connect(sigc::mem_fun(*this,&CompView::copy_value_node));
142 valuenode_buttons->pack_start(*button_valuenode_new);
143 valuenode_buttons->pack_start(*button_valuenode_delete);
144 valuenode_buttons->pack_start(*button_valuenode_rename);
145 valuenode_buttons->pack_start(*button_valuenode_copy);
148 notebook->append_page(*image_page,"Images");
149 notebook->append_page(*valuenode_page,"ValueNodes");
151 image_page->show_all();
152 valuenode_page->show_all();
154 // notebook->set_current_page(0);
155 signal_delete_event().connect(sigc::hide(sigc::mem_fun(*this, &CompView::close)));
156 App::signal_instance_created().connect(sigc::mem_fun(*this,&studio::CompView::new_instance));
157 App::signal_instance_deleted().connect(sigc::mem_fun(*this,&studio::CompView::delete_instance));
158 App::signal_instance_selected().connect(sigc::mem_fun(*this,&studio::CompView::set_selected_instance_signal));
164 set_title("Canvas Browser");
167 property_window_position().set_value(Gtk::WIN_POS_NONE);
168 set_default_size(200,300);
171 CompView::~CompView()
175 etl::loose_handle<studio::CanvasView>
176 CompView::get_selected_canvas_view()
178 return get_selected_instance()->find_canvas_view(get_selected_canvas());
182 CompView::create_canvas_tree()
184 studio::Instance::CanvasTreeModel canvas_tree_model;
185 canvas_tree=manage(new class Gtk::TreeView());
187 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column("ID") );
188 // Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
190 //column->pack_start(*icon_cellrenderer,false);
191 column->pack_start(canvas_tree_model.icon, false); //false = don't expand.
192 column->pack_start(canvas_tree_model.label);
195 // column->add_attribute(icon_cellrenderer->property_pixbuf(), canvas_tree_model.icon);
198 canvas_tree->append_column(*column);
200 canvas_tree->set_rules_hint();
201 canvas_tree->signal_row_activated().connect(sigc::mem_fun(*this,&CompView::on_row_activate));
202 canvas_tree->signal_event().connect(sigc::mem_fun(*this,&CompView::on_tree_event));
203 canvas_tree->add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
204 canvas_tree->add_events(Gdk::BUTTON1_MOTION_MASK);
207 Gtk::ScrolledWindow *scrolledwindow = manage(new class Gtk::ScrolledWindow());
208 scrolledwindow->set_flags(Gtk::CAN_FOCUS);
209 scrolledwindow->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
210 scrolledwindow->add(*canvas_tree);
211 scrolledwindow->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
212 scrolledwindow->show();
214 return scrolledwindow;
218 CompView::create_action_tree()
220 studio::HistoryTreeStore::Model history_tree_model;
221 action_tree=manage(new class Gtk::TreeView());
223 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column("") );
225 Gtk::CellRendererToggle* toggle_cr = Gtk::manage( new Gtk::CellRendererToggle() );
226 toggle_cr->signal_toggled().connect(sigc::mem_fun(*this, &studio::CompView::on_action_toggle) );
228 column->pack_start(*toggle_cr); //false = don't expand.
229 column->add_attribute(toggle_cr->property_active(),history_tree_model.is_active);
230 column->set_resizable();
231 column->set_clickable();
233 action_tree->append_column(*column);
236 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column("Canvas") );
237 Gtk::CellRendererText *text_cr=Gtk::manage(new Gtk::CellRendererText());
238 text_cr->property_foreground()=Glib::ustring("#7f7f7f");
240 column->pack_start(*text_cr);
241 column->add_attribute(text_cr->property_text(),history_tree_model.canvas_id);
242 column->add_attribute(text_cr->property_foreground_set(),history_tree_model.is_redo);
244 action_tree->append_column(*column);
247 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Jump")) );
249 Gtk::CellRendererText* cell_renderer_jump=Gtk::manage(new Gtk::CellRendererText());
250 column->pack_start(*cell_renderer_jump,true);
252 cell_renderer_jump->property_text()="(JMP)";
253 cell_renderer_jump->property_foreground()="#003a7f";
255 column->set_resizable();
256 column->set_clickable();
258 column->set_sort_column_id(COLUMNID_JUMP);
260 action_tree->append_column(*column);
264 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column("Action") );
266 Gtk::CellRendererText *text_cr=Gtk::manage(new Gtk::CellRendererText());
267 text_cr->property_foreground()=Glib::ustring("#7f7f7f");
271 //column->pack_start(history_tree_model.icon, false); //false = don't expand.
272 column->pack_start(*text_cr);
273 column->add_attribute(text_cr->property_text(),history_tree_model.name);
274 column->add_attribute(text_cr->property_foreground_set(),history_tree_model.is_redo);
276 action_tree->append_column(*column);
280 action_tree->set_rules_hint();
281 // action_tree->signal_row_activated().connect(sigc::mem_fun(*this,&CompView::on_row_activate));
282 action_tree->signal_event().connect(sigc::mem_fun(*this,&CompView::on_action_event));
283 // action_tree->add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
284 // action_tree->add_events(Gdk::BUTTON1_MOTION_MASK);
287 Gtk::ScrolledWindow *scrolledwindow = manage(new class Gtk::ScrolledWindow());
288 scrolledwindow->set_flags(Gtk::CAN_FOCUS);
289 scrolledwindow->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
290 scrolledwindow->add(*action_tree);
291 scrolledwindow->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
292 scrolledwindow->show();
294 Gtk::Button* clear_button(manage(new Gtk::Button(_("Clear Undo"))));
295 clear_button->signal_pressed().connect(sigc::mem_fun(*this,&studio::CompView::clear_history));
297 Gtk::Button* clear_redo_button(manage(new Gtk::Button(_("Clear Redo"))));
298 clear_redo_button->signal_pressed().connect(sigc::mem_fun(*this,&studio::CompView::clear_redo));
300 Gtk::Table* table(manage(new Gtk::Table()));
301 table->attach(*scrolledwindow, 0, 2, 0,1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
302 table->attach(*clear_button, 0, 1, 1,2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
303 table->attach(*clear_redo_button, 1, 2, 1,2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
311 CompView::create_instance_selector()
313 instance_selector=manage(new class Gtk::OptionMenu());
314 instance_selector->show();
315 instance_selector->set_menu(instance_list_menu);
316 return instance_selector;
327 CompView::clear_history()
329 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?")))
331 selected_instance->clear_undo_stack();
336 CompView::clear_redo()
338 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?")))
340 selected_instance->clear_redo_stack();
345 CompView::init_menu()
347 menu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
348 menu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("synfig-canvas_new"),
349 sigc::mem_fun(*this,&CompView::menu_new_canvas)));
350 menu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-delete"),
351 sigc::mem_fun(*this,&CompView::menu_delete)));
352 menu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("synfig-rename"),
353 sigc::mem_fun(*this,&CompView::menu_rename)));
356 etl::loose_handle<synfig::Canvas>
357 CompView::get_selected_canvas()
359 Glib::RefPtr<Gtk::TreeSelection> selection=canvas_tree->get_selection();
361 if(!selection || !selection->get_selected())
364 studio::Instance::CanvasTreeModel canvas_tree_model;
366 return static_cast<etl::handle<synfig::Canvas> >((*selection->get_selected())[canvas_tree_model.canvas]);
370 CompView::menu_new_canvas()
374 get_selected_canvas_view()->new_child_canvas();
379 CompView::menu_delete()
381 studio::App::dialog_not_implemented();
385 CompView::menu_rename()
387 studio::App::dialog_not_implemented();
391 CompView::set_selected_instance_signal(etl::handle<studio::Instance> x)
393 set_selected_instance(x);
397 CompView::set_selected_instance_(etl::handle<studio::Instance> instance)
399 if(studio::App::shutdown_in_progress)
402 selected_instance=instance;
405 canvas_tree->set_model(instance->canvas_tree_store());
406 action_tree->set_model(instance->history_tree_store());
412 canvas_tree->set_model(Glib::RefPtr< Gtk::TreeModel >());
413 action_tree->set_model(Glib::RefPtr< Gtk::TreeModel >());
420 CompView::set_selected_instance(etl::loose_handle<studio::Instance> x)
422 if(studio::App::shutdown_in_progress)
425 // if it's already selected, don't select it again
426 if (x==selected_instance)
429 std::list<etl::handle<studio::Instance> >::iterator iter;
434 for(i=0,iter=studio::App::instance_list.begin();iter!=studio::App::instance_list.end() && ((*iter)!=x);iter++,i++);
438 instance_selector->set_history(i);
441 instance_selector->set_history(0);
443 set_selected_instance_(x);
447 CompView::new_instance(etl::handle<studio::Instance> instance)
449 if(studio::App::shutdown_in_progress)
454 etl::loose_handle<studio::Instance> loose_instance(instance);
456 instance->synfigapp::Instance::signal_filename_changed().connect(sigc::mem_fun(*this,&CompView::refresh_instances));
457 instance->synfigapp::Instance::signal_filename_changed().connect(
458 sigc::bind<etl::loose_handle<studio::Instance> >(
459 sigc::mem_fun(*this,&CompView::set_selected_instance),
465 std::string name=basename(instance->get_file_name());
467 instance_list_menu.items().push_back(Gtk::Menu_Helpers::MenuElem(name,
468 sigc::bind<etl::loose_handle<studio::Instance> >(sigc::mem_fun(&studio::App::set_selected_instance),loose_instance) ));
473 CompView::delete_instance(etl::handle<studio::Instance> instance)
475 if(studio::App::shutdown_in_progress)
480 if(selected_instance==instance)
482 set_selected_instance(0);
483 instance_selector->set_history(0);
488 CompView::refresh_instances()
490 if(studio::App::shutdown_in_progress)
493 if(!instance_list_menu.items().empty())
494 instance_list_menu.items().clear();
496 std::list<etl::handle<studio::Instance> >::iterator iter;
497 for(iter=studio::App::instance_list.begin();iter!=studio::App::instance_list.end();iter++)
499 std::string name=basename((*iter)->get_file_name());
501 instance_list_menu.items().push_back(Gtk::Menu_Helpers::MenuElem(name,
502 sigc::bind<etl::loose_handle<studio::Instance> >(sigc::mem_fun(&studio::App::set_selected_instance),*iter) ));
504 instance_selector->set_menu(instance_list_menu);
508 CompView::on_row_activate(const Gtk::TreeModel::Path &path, Gtk::TreeViewColumn *)
510 assert(get_selected_instance());
511 studio::Instance::CanvasTreeModel canvas_tree_model;
512 const Gtk::TreeRow row = *(get_selected_instance()->canvas_tree_store()->get_iter(path));
513 if(row[canvas_tree_model.is_canvas])
514 get_selected_instance()->focus(row[canvas_tree_model.canvas]);
516 studio::App::dialog_not_implemented();
520 CompView::on_action_event(GdkEvent *event)
522 studio::HistoryTreeStore::Model model;
525 case GDK_BUTTON_PRESS:
526 case GDK_2BUTTON_PRESS:
528 Gtk::TreeModel::Path path;
529 Gtk::TreeViewColumn *column;
531 if(!action_tree->get_path_at_pos(
532 int(event->button.x),int(event->button.y), // x, y
533 path, // TreeModel::Path&
534 column, //TreeViewColumn*&
535 cell_x,cell_y //int&cell_x,int&cell_y
538 const Gtk::TreeRow row = *(action_tree->get_model()->get_iter(path));
540 //signal_user_click()(event->button.button,row,(ColumnID)column->get_sort_column_id());
541 if((ColumnID)column->get_sort_column_id()==COLUMNID_JUMP)
543 etl::handle<synfigapp::Action::Undoable> action(row[model.action]);
544 if((bool)row[model.is_undo])
546 while(get_selected_instance()->undo_action_stack().size() && get_selected_instance()->undo_action_stack().front()!=action)
547 get_selected_instance()->undo();
549 else if((bool)row[model.is_redo])
551 while(get_selected_instance()->redo_action_stack().size() && get_selected_instance()->undo_action_stack().front()!=action)
552 get_selected_instance()->redo();
557 case GDK_BUTTON_RELEASE:
566 CompView::on_tree_event(GdkEvent *event)
570 case GDK_BUTTON_PRESS:
571 switch(event->button.button)
574 if(get_selected_canvas())
576 menu.items().clear();
578 synfigapp::Action::ParamList param_list;
579 param_list.add("canvas",synfig::Canvas::Handle(get_selected_canvas()));
580 param_list.add("canvas_interface",get_selected_instance()->find_canvas_interface(get_selected_canvas()));
581 get_selected_instance()->find_canvas_view(get_selected_canvas())->add_actions_to_menu(&menu, param_list,synfigapp::Action::CATEGORY_CANVAS);
590 case GDK_MOTION_NOTIFY:
592 case GDK_BUTTON_RELEASE:
601 CompView::on_action_toggle(const Glib::ustring& path_string)
603 studio::HistoryTreeStore::Model history_tree_model;
605 Gtk::TreePath path(path_string);
607 const Gtk::TreeRow row = *(selected_instance->history_tree_store()->get_iter(path));
609 handle<synfigapp::Action::Undoable> action=row[history_tree_model.action];
611 selected_instance->synfigapp::Instance::set_action_status(action,!action->is_active());