1 /* === S Y N F I G ========================================================= */
2 /*! \file dock_canvases.cpp
3 ** \brief Template File
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 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
32 #include "dock_canvases.h"
34 #include "canvasview.h"
37 /* === U S I N G =========================================================== */
41 using namespace synfig;
42 using namespace studio;
44 /* === M A C R O S ========================================================= */
46 /* === G L O B A L S ======================================================= */
48 /* === P R O C E D U R E S ================================================= */
50 /* === M E T H O D S ======================================================= */
52 Dock_Canvases::Dock_Canvases():
53 Dockable("canvases",_("Canvas Browser"),Gtk::StockID("synfig-canvas"))
56 App::signal_instance_created().connect(sigc::mem_fun(*this,&studio::Dock_Canvases::new_instance));
57 App::signal_instance_deleted().connect(sigc::mem_fun(*this,&studio::Dock_Canvases::delete_instance));
58 App::signal_instance_selected().connect(sigc::mem_fun(*this,&studio::Dock_Canvases::set_selected_instance_signal));
61 add(*create_canvas_tree());
65 Gtk::StockID("synfig-canvas_new"),
66 _("Insert a new canvas")
67 )->signal_clicked().connect(
70 &Dock_Canvases::menu_new_canvas
75 Gtk::StockID("gtk-delete"),
76 _("Remove selected canvas")
77 )->signal_clicked().connect(
80 &Dock_Canvases::menu_delete
85 Gtk::StockID("synfig-rename"),
86 _("Rename selected canvas")
87 )->signal_clicked().connect(
90 &Dock_Canvases::menu_rename
96 Dock_Canvases::~Dock_Canvases()
101 Dock_Canvases::create_canvas_tree()
103 studio::Instance::CanvasTreeModel canvas_tree_model;
104 canvas_tree=manage(new class Gtk::TreeView());
106 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column("ID") );
107 // Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
109 //column->pack_start(*icon_cellrenderer,false);
110 column->pack_start(canvas_tree_model.icon, false); //false = don't expand.
111 column->pack_start(canvas_tree_model.label);
114 // column->add_attribute(icon_cellrenderer->property_pixbuf(), canvas_tree_model.icon);
117 canvas_tree->append_column(*column);
119 canvas_tree->set_rules_hint();
120 canvas_tree->signal_row_activated().connect(sigc::mem_fun(*this,&Dock_Canvases::on_row_activate));
121 //canvas_tree->signal_event().connect(sigc::mem_fun(*this,&Dock_Canvases::on_tree_event));
122 canvas_tree->add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
123 canvas_tree->add_events(Gdk::BUTTON1_MOTION_MASK);
125 canvas_tree->set_headers_visible(false);
127 Gtk::ScrolledWindow *scrolledwindow = manage(new class Gtk::ScrolledWindow());
128 scrolledwindow->set_flags(Gtk::CAN_FOCUS);
129 scrolledwindow->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
130 scrolledwindow->add(*canvas_tree);
131 scrolledwindow->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
132 scrolledwindow->show_all();
134 return scrolledwindow;
137 etl::loose_handle<studio::CanvasView>
138 Dock_Canvases::get_selected_canvas_view()
140 return get_selected_instance()->find_canvas_view(get_selected_canvas());
143 etl::loose_handle<synfig::Canvas>
144 Dock_Canvases::get_selected_canvas()
146 Glib::RefPtr<Gtk::TreeSelection> selection=canvas_tree->get_selection();
148 if(!selection || !selection->get_selected())
151 studio::Instance::CanvasTreeModel canvas_tree_model;
153 return static_cast<etl::handle<synfig::Canvas> >((*selection->get_selected())[canvas_tree_model.canvas]);
159 Dock_Canvases::set_selected_instance_signal(etl::handle<studio::Instance> x)
161 set_selected_instance(x);
165 Dock_Canvases::set_selected_instance_(etl::handle<studio::Instance> instance)
167 if(studio::App::shutdown_in_progress)
170 selected_instance=instance;
173 canvas_tree->set_model(instance->canvas_tree_store());
178 canvas_tree->set_model(Glib::RefPtr< Gtk::TreeModel >());
184 Dock_Canvases::set_selected_instance(etl::loose_handle<studio::Instance> x)
186 if(studio::App::shutdown_in_progress)
189 // if it's already selected, don't select it again
190 if (x==selected_instance)
193 set_selected_instance_(x);
197 Dock_Canvases::new_instance(etl::handle<studio::Instance> instance)
199 if(studio::App::shutdown_in_progress)
204 etl::loose_handle<studio::Instance> loose_instance(instance);
206 instance->synfigapp::Instance::signal_filename_changed().connect(sigc::mem_fun(*this,&Dock_Canvases::refresh_instances));
207 instance->synfigapp::Instance::signal_filename_changed().connect(
208 sigc::bind<etl::loose_handle<studio::Instance> >(
209 sigc::mem_fun(*this,&Dock_Canvases::set_selected_instance),
219 Dock_Canvases::delete_instance(etl::handle<studio::Instance> instance)
221 if(studio::App::shutdown_in_progress)
226 if(selected_instance==instance)
228 set_selected_instance(0);
233 Dock_Canvases::refresh_instances()
235 if(studio::App::shutdown_in_progress)
240 Dock_Canvases::on_row_activate(const Gtk::TreeModel::Path &path, Gtk::TreeViewColumn *)
242 assert(get_selected_instance());
243 studio::Instance::CanvasTreeModel canvas_tree_model;
244 const Gtk::TreeRow row = *(get_selected_instance()->canvas_tree_store()->get_iter(path));
245 if(row[canvas_tree_model.is_canvas])
246 get_selected_instance()->focus(row[canvas_tree_model.canvas]);
248 studio::App::dialog_not_implemented();