1 /*! ========================================================================
4 ** $Id: compview.cpp,v 1.1.1.1 2005/01/07 03:34:36 darco Exp $
6 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
8 ** This package is free software; you can redistribute it and/or
9 ** modify it under the terms of the GNU General Public License as
10 ** published by the Free Software Foundation; either version 2 of
11 ** the License, or (at your option) any later version.
13 ** This package is distributed in the hope that it will be useful,
14 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 ** General Public License for more details.
18 ** === N O T E S ===========================================================
20 ** ========================================================================= */
22 /* === H E A D E R S ======================================================= */
33 #include <gtkmm/scrolledwindow.h>
37 #include <sigc++/signal.h>
38 #include <sigc++/hide.h>
39 #include <sigc++/slot.h>
40 #include "canvasview.h"
41 #include <synfigapp/action.h>
45 /* === M A C R O S ========================================================= */
47 #define ADD_TOOLBOX_BUTTON(button,stockid,tooltip) \
48 Gtk::Button *button = manage(new class Gtk::Button()); \
49 button->add(*manage(new Gtk::Image(Gtk::StockID(stockid),Gtk::IconSize(4)))); \
50 tooltips.set_tip(*button,tooltip); \
55 using namespace synfig;
56 using namespace studio;
58 #define COLUMNID_JUMP (787584)
61 /* === G L O B A L S ======================================================= */
63 /* === P R O C E D U R E S ================================================= */
65 /* === M E T H O D S ======================================================= */
68 Gtk::Window(Gtk::WINDOW_TOPLEVEL),
69 dialog_settings(this,"compview")
72 set_type_hint(Gdk::WINDOW_TYPE_HINT_UTILITY);
74 Gtk::Table *table = manage(new class Gtk::Table(2, 1, false));
77 table->attach(*create_instance_selector(), 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
79 notebook=manage(new class Gtk::Notebook());
81 table->attach(*notebook, 0, 1, 1,2, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
83 notebook->append_page(*create_canvas_tree(),"Canvases");
84 notebook->append_page(*create_action_tree(),"History");
90 studio::Instance::ImageColumnModel image_column_model;
91 image_list=manage(new class Gtk::TreeView());
92 image_list->append_column("Name",image_column_model.name);
93 image_list->signal_row_activated().connect(sigc::mem_fun(*this,&CompView::on_image_activate));
94 image_list->set_rules_hint();
96 Gtk::Table *image_page = manage(new class Gtk::Table(2, 1, false));
97 Gtk::ScrolledWindow *image_list_scroll = manage(new class Gtk::ScrolledWindow());
98 image_list_scroll->set_flags(Gtk::CAN_FOCUS);
99 image_list_scroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
100 image_list_scroll->add(*image_list);
101 image_page->attach(*image_list_scroll, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
102 Gtk::HBox *image_buttons=manage(new class Gtk::HBox());
103 image_page->attach(*image_buttons, 0, 1, 1,2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
104 ADD_TOOLBOX_BUTTON(button_image_new,"gtk-new","Create a new image");
105 ADD_TOOLBOX_BUTTON(button_image_delete,"gtk-delete","Delete image");
106 ADD_TOOLBOX_BUTTON(button_image_rename,"gtk-rename","Rename image");
107 ADD_TOOLBOX_BUTTON(button_image_copy,"gtk-copy","Duplicate image");
108 button_image_new->signal_clicked().connect(sigc::mem_fun(*this,&CompView::new_image));
109 button_image_delete->signal_clicked().connect(sigc::mem_fun(*this,&CompView::delete_image));
110 button_image_rename->signal_clicked().connect(sigc::mem_fun(*this,&CompView::rename_image));
111 button_image_copy->signal_clicked().connect(sigc::mem_fun(*this,&CompView::copy_image));
112 image_buttons->pack_start(*button_image_new);
113 image_buttons->pack_start(*button_image_delete);
114 image_buttons->pack_start(*button_image_rename);
115 image_buttons->pack_start(*button_image_copy);
117 studio::Instance::ValueNodeColumnModel valuenode_column_model;
118 valuenode_list=manage(new class Gtk::TreeView());
119 valuenode_list->append_column("Name",valuenode_column_model.name);
120 valuenode_list->signal_row_activated().connect(sigc::mem_fun(*this,&CompView::on_valuenode_activate));
121 valuenode_list->set_rules_hint();
123 Gtk::Table *valuenode_page = manage(new class Gtk::Table(2, 1, false));
124 Gtk::ScrolledWindow *valuenode_list_scroll = manage(new class Gtk::ScrolledWindow());
125 valuenode_list_scroll->set_flags(Gtk::CAN_FOCUS);
126 valuenode_list_scroll->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
127 valuenode_list_scroll->add(*valuenode_list);
128 valuenode_page->attach(*valuenode_list_scroll, 0, 1, 0, 1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
129 Gtk::HBox *valuenode_buttons=manage(new class Gtk::HBox());
130 valuenode_page->attach(*valuenode_buttons, 0, 1, 1,2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
131 ADD_TOOLBOX_BUTTON(button_valuenode_new,"gtk-new","Create a new value_node");
132 ADD_TOOLBOX_BUTTON(button_valuenode_delete,"gtk-delete","Delete value_node");
133 ADD_TOOLBOX_BUTTON(button_valuenode_rename,"gtk-rename","Rename value_node");
134 ADD_TOOLBOX_BUTTON(button_valuenode_copy,"gtk-copy","Duplicate value_node");
135 button_valuenode_new->signal_clicked().connect(sigc::mem_fun(*this,&CompView::new_value_node));
136 button_valuenode_delete->signal_clicked().connect(sigc::mem_fun(*this,&CompView::delete_value_node));
137 button_valuenode_rename->signal_clicked().connect(sigc::mem_fun(*this,&CompView::rename_value_node));
138 button_valuenode_copy->signal_clicked().connect(sigc::mem_fun(*this,&CompView::copy_value_node));
139 valuenode_buttons->pack_start(*button_valuenode_new);
140 valuenode_buttons->pack_start(*button_valuenode_delete);
141 valuenode_buttons->pack_start(*button_valuenode_rename);
142 valuenode_buttons->pack_start(*button_valuenode_copy);
145 notebook->append_page(*image_page,"Images");
146 notebook->append_page(*valuenode_page,"ValueNodes");
148 image_page->show_all();
149 valuenode_page->show_all();
151 // notebook->set_current_page(0);
152 signal_delete_event().connect(sigc::hide(sigc::mem_fun(*this, &CompView::close)));
153 App::signal_instance_created().connect(sigc::mem_fun(*this,&studio::CompView::new_instance));
154 App::signal_instance_deleted().connect(sigc::mem_fun(*this,&studio::CompView::delete_instance));
155 App::signal_instance_selected().connect(sigc::mem_fun(*this,&studio::CompView::set_selected_instance_signal));
161 set_title("Canvas Browser");
164 property_window_position().set_value(Gtk::WIN_POS_NONE);
165 set_default_size(200,300);
168 CompView::~CompView()
172 etl::loose_handle<studio::CanvasView>
173 CompView::get_selected_canvas_view()
175 return get_selected_instance()->find_canvas_view(get_selected_canvas());
179 CompView::create_canvas_tree()
181 studio::Instance::CanvasTreeModel canvas_tree_model;
182 canvas_tree=manage(new class Gtk::TreeView());
184 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column("ID") );
185 // Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
187 //column->pack_start(*icon_cellrenderer,false);
188 column->pack_start(canvas_tree_model.icon, false); //false = don't expand.
189 column->pack_start(canvas_tree_model.label);
192 // column->add_attribute(icon_cellrenderer->property_pixbuf(), canvas_tree_model.icon);
195 canvas_tree->append_column(*column);
197 canvas_tree->set_rules_hint();
198 canvas_tree->signal_row_activated().connect(sigc::mem_fun(*this,&CompView::on_row_activate));
199 canvas_tree->signal_event().connect(sigc::mem_fun(*this,&CompView::on_tree_event));
200 canvas_tree->add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
201 canvas_tree->add_events(Gdk::BUTTON1_MOTION_MASK);
204 Gtk::ScrolledWindow *scrolledwindow = manage(new class Gtk::ScrolledWindow());
205 scrolledwindow->set_flags(Gtk::CAN_FOCUS);
206 scrolledwindow->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
207 scrolledwindow->add(*canvas_tree);
208 scrolledwindow->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
209 scrolledwindow->show();
211 return scrolledwindow;
215 CompView::create_action_tree()
217 studio::HistoryTreeStore::Model history_tree_model;
218 action_tree=manage(new class Gtk::TreeView());
220 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column("") );
222 Gtk::CellRendererToggle* toggle_cr = Gtk::manage( new Gtk::CellRendererToggle() );
223 toggle_cr->signal_toggled().connect(sigc::mem_fun(*this, &studio::CompView::on_action_toggle) );
225 column->pack_start(*toggle_cr); //false = don't expand.
226 column->add_attribute(toggle_cr->property_active(),history_tree_model.is_active);
227 column->set_resizable();
228 column->set_clickable();
230 action_tree->append_column(*column);
233 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column("Canvas") );
234 Gtk::CellRendererText *text_cr=Gtk::manage(new Gtk::CellRendererText());
235 text_cr->property_foreground()=Glib::ustring("#7f7f7f");
237 column->pack_start(*text_cr);
238 column->add_attribute(text_cr->property_text(),history_tree_model.canvas_id);
239 column->add_attribute(text_cr->property_foreground_set(),history_tree_model.is_redo);
241 action_tree->append_column(*column);
244 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("Jump")) );
246 Gtk::CellRendererText* cell_renderer_jump=Gtk::manage(new Gtk::CellRendererText());
247 column->pack_start(*cell_renderer_jump,true);
249 cell_renderer_jump->property_text()="(JMP)";
250 cell_renderer_jump->property_foreground()="#003a7f";
252 column->set_resizable();
253 column->set_clickable();
255 column->set_sort_column_id(COLUMNID_JUMP);
257 action_tree->append_column(*column);
261 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column("Action") );
263 Gtk::CellRendererText *text_cr=Gtk::manage(new Gtk::CellRendererText());
264 text_cr->property_foreground()=Glib::ustring("#7f7f7f");
268 //column->pack_start(history_tree_model.icon, false); //false = don't expand.
269 column->pack_start(*text_cr);
270 column->add_attribute(text_cr->property_text(),history_tree_model.name);
271 column->add_attribute(text_cr->property_foreground_set(),history_tree_model.is_redo);
273 action_tree->append_column(*column);
277 action_tree->set_rules_hint();
278 // action_tree->signal_row_activated().connect(sigc::mem_fun(*this,&CompView::on_row_activate));
279 action_tree->signal_event().connect(sigc::mem_fun(*this,&CompView::on_action_event));
280 // action_tree->add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
281 // action_tree->add_events(Gdk::BUTTON1_MOTION_MASK);
284 Gtk::ScrolledWindow *scrolledwindow = manage(new class Gtk::ScrolledWindow());
285 scrolledwindow->set_flags(Gtk::CAN_FOCUS);
286 scrolledwindow->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
287 scrolledwindow->add(*action_tree);
288 scrolledwindow->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
289 scrolledwindow->show();
291 Gtk::Button* clear_button(manage(new Gtk::Button(_("Clear Undo"))));
292 clear_button->signal_pressed().connect(sigc::mem_fun(*this,&studio::CompView::clear_history));
294 Gtk::Button* clear_redo_button(manage(new Gtk::Button(_("Clear Redo"))));
295 clear_redo_button->signal_pressed().connect(sigc::mem_fun(*this,&studio::CompView::clear_redo));
297 Gtk::Table* table(manage(new Gtk::Table()));
298 table->attach(*scrolledwindow, 0, 2, 0,1, Gtk::EXPAND|Gtk::FILL, Gtk::EXPAND|Gtk::FILL, 0, 0);
299 table->attach(*clear_button, 0, 1, 1,2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
300 table->attach(*clear_redo_button, 1, 2, 1,2, Gtk::EXPAND|Gtk::FILL, Gtk::SHRINK, 0, 0);
308 CompView::create_instance_selector()
310 instance_selector=manage(new class Gtk::OptionMenu());
311 instance_selector->show();
312 instance_selector->set_menu(instance_list_menu);
313 return instance_selector;
324 CompView::clear_history()
326 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?")))
328 selected_instance->clear_undo_stack();
333 CompView::clear_redo()
335 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?")))
337 selected_instance->clear_redo_stack();
342 CompView::init_menu()
344 menu.items().push_back(Gtk::Menu_Helpers::SeparatorElem());
345 menu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("synfig-canvas_new"),
346 sigc::mem_fun(*this,&CompView::menu_new_canvas)));
347 menu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("gtk-delete"),
348 sigc::mem_fun(*this,&CompView::menu_delete)));
349 menu.items().push_back(Gtk::Menu_Helpers::StockMenuElem(Gtk::StockID("synfig-rename"),
350 sigc::mem_fun(*this,&CompView::menu_rename)));
353 etl::loose_handle<synfig::Canvas>
354 CompView::get_selected_canvas()
356 Glib::RefPtr<Gtk::TreeSelection> selection=canvas_tree->get_selection();
358 if(!selection || !selection->get_selected())
361 studio::Instance::CanvasTreeModel canvas_tree_model;
363 return static_cast<etl::handle<synfig::Canvas> >((*selection->get_selected())[canvas_tree_model.canvas]);
367 CompView::menu_new_canvas()
371 get_selected_canvas_view()->new_child_canvas();
376 CompView::menu_delete()
378 studio::App::dialog_not_implemented();
382 CompView::menu_rename()
384 studio::App::dialog_not_implemented();
388 CompView::set_selected_instance_signal(etl::handle<studio::Instance> x)
390 set_selected_instance(x);
394 CompView::set_selected_instance_(etl::handle<studio::Instance> instance)
396 if(studio::App::shutdown_in_progress)
399 selected_instance=instance;
402 canvas_tree->set_model(instance->canvas_tree_store());
403 action_tree->set_model(instance->history_tree_store());
409 canvas_tree->set_model(Glib::RefPtr< Gtk::TreeModel >());
410 action_tree->set_model(Glib::RefPtr< Gtk::TreeModel >());
417 CompView::set_selected_instance(etl::loose_handle<studio::Instance> x)
419 if(studio::App::shutdown_in_progress)
422 // if it's already selected, don't select it again
423 if (x==selected_instance)
426 std::list<etl::handle<studio::Instance> >::iterator iter;
431 for(i=0,iter=studio::App::instance_list.begin();iter!=studio::App::instance_list.end() && ((*iter)!=x);iter++,i++);
435 instance_selector->set_history(i);
438 instance_selector->set_history(0);
440 set_selected_instance_(x);
444 CompView::new_instance(etl::handle<studio::Instance> instance)
446 if(studio::App::shutdown_in_progress)
451 etl::loose_handle<studio::Instance> loose_instance(instance);
453 instance->synfigapp::Instance::signal_filename_changed().connect(sigc::mem_fun(*this,&CompView::refresh_instances));
454 instance->synfigapp::Instance::signal_filename_changed().connect(
455 sigc::bind<etl::loose_handle<studio::Instance> >(
456 sigc::mem_fun(*this,&CompView::set_selected_instance),
462 std::string name=basename(instance->get_file_name());
464 instance_list_menu.items().push_back(Gtk::Menu_Helpers::MenuElem(name,
465 sigc::bind<etl::loose_handle<studio::Instance> >(sigc::mem_fun(&studio::App::set_selected_instance),loose_instance) ));
470 CompView::delete_instance(etl::handle<studio::Instance> instance)
472 if(studio::App::shutdown_in_progress)
477 if(selected_instance==instance)
479 set_selected_instance(0);
480 instance_selector->set_history(0);
485 CompView::refresh_instances()
487 if(studio::App::shutdown_in_progress)
490 if(!instance_list_menu.items().empty())
491 instance_list_menu.items().clear();
493 std::list<etl::handle<studio::Instance> >::iterator iter;
494 for(iter=studio::App::instance_list.begin();iter!=studio::App::instance_list.end();iter++)
496 std::string name=basename((*iter)->get_file_name());
498 instance_list_menu.items().push_back(Gtk::Menu_Helpers::MenuElem(name,
499 sigc::bind<etl::loose_handle<studio::Instance> >(sigc::mem_fun(&studio::App::set_selected_instance),*iter) ));
501 instance_selector->set_menu(instance_list_menu);
505 CompView::on_row_activate(const Gtk::TreeModel::Path &path, Gtk::TreeViewColumn *)
507 assert(get_selected_instance());
508 studio::Instance::CanvasTreeModel canvas_tree_model;
509 const Gtk::TreeRow row = *(get_selected_instance()->canvas_tree_store()->get_iter(path));
510 if(row[canvas_tree_model.is_canvas])
511 get_selected_instance()->focus(row[canvas_tree_model.canvas]);
513 studio::App::dialog_not_implemented();
517 CompView::on_action_event(GdkEvent *event)
519 studio::HistoryTreeStore::Model model;
522 case GDK_BUTTON_PRESS:
523 case GDK_2BUTTON_PRESS:
525 Gtk::TreeModel::Path path;
526 Gtk::TreeViewColumn *column;
528 if(!action_tree->get_path_at_pos(
529 int(event->button.x),int(event->button.y), // x, y
530 path, // TreeModel::Path&
531 column, //TreeViewColumn*&
532 cell_x,cell_y //int&cell_x,int&cell_y
535 const Gtk::TreeRow row = *(action_tree->get_model()->get_iter(path));
537 //signal_user_click()(event->button.button,row,(ColumnID)column->get_sort_column_id());
538 if((ColumnID)column->get_sort_column_id()==COLUMNID_JUMP)
540 etl::handle<synfigapp::Action::Undoable> action(row[model.action]);
541 if((bool)row[model.is_undo])
543 while(get_selected_instance()->undo_action_stack().size() && get_selected_instance()->undo_action_stack().front()!=action)
544 get_selected_instance()->undo();
546 else if((bool)row[model.is_redo])
548 while(get_selected_instance()->redo_action_stack().size() && get_selected_instance()->undo_action_stack().front()!=action)
549 get_selected_instance()->redo();
554 case GDK_BUTTON_RELEASE:
563 CompView::on_tree_event(GdkEvent *event)
567 case GDK_BUTTON_PRESS:
568 switch(event->button.button)
571 if(get_selected_canvas())
573 menu.items().clear();
575 synfigapp::Action::ParamList param_list;
576 param_list.add("canvas",synfig::Canvas::Handle(get_selected_canvas()));
577 param_list.add("canvas_interface",get_selected_instance()->find_canvas_interface(get_selected_canvas()));
578 get_selected_instance()->find_canvas_view(get_selected_canvas())->add_actions_to_menu(&menu, param_list,synfigapp::Action::CATEGORY_CANVAS);
587 case GDK_MOTION_NOTIFY:
589 case GDK_BUTTON_RELEASE:
598 CompView::on_action_toggle(const Glib::ustring& path_string)
600 studio::HistoryTreeStore::Model history_tree_model;
602 Gtk::TreePath path(path_string);
604 const Gtk::TreeRow row = *(selected_instance->history_tree_store()->get_iter(path));
606 handle<synfigapp::Action::Undoable> action=row[history_tree_model.action];
608 selected_instance->synfigapp::Instance::set_action_status(action,!action->is_active());