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"
39 /* === U S I N G =========================================================== */
43 using namespace synfig;
44 using namespace studio;
46 /* === M A C R O S ========================================================= */
48 /* === G L O B A L S ======================================================= */
50 /* === P R O C E D U R E S ================================================= */
52 /* === M E T H O D S ======================================================= */
54 Dock_Canvases::Dock_Canvases():
55 Dockable("canvases",_("Canvas Browser"),Gtk::StockID("synfig-canvas"))
58 App::signal_instance_created().connect(sigc::mem_fun(*this,&studio::Dock_Canvases::new_instance));
59 App::signal_instance_deleted().connect(sigc::mem_fun(*this,&studio::Dock_Canvases::delete_instance));
60 App::signal_instance_selected().connect(sigc::mem_fun(*this,&studio::Dock_Canvases::set_selected_instance_signal));
63 add(*create_canvas_tree());
67 Gtk::StockID("synfig-canvas_new"),
68 _("Insert a new canvas")
69 )->signal_clicked().connect(
72 &Dock_Canvases::menu_new_canvas
77 Gtk::StockID("gtk-delete"),
78 _("Remove selected canvas")
79 )->signal_clicked().connect(
82 &Dock_Canvases::menu_delete
87 Gtk::StockID("synfig-rename"),
88 _("Rename selected canvas")
89 )->signal_clicked().connect(
92 &Dock_Canvases::menu_rename
98 Dock_Canvases::~Dock_Canvases()
103 Dock_Canvases::create_canvas_tree()
105 studio::Instance::CanvasTreeModel canvas_tree_model;
106 canvas_tree=manage(new class Gtk::TreeView());
108 Gtk::TreeView::Column* column = Gtk::manage( new Gtk::TreeView::Column(_("ID")) );
109 // Gtk::CellRendererPixbuf* icon_cellrenderer = Gtk::manage( new Gtk::CellRendererPixbuf() );
111 //column->pack_start(*icon_cellrenderer,false);
112 column->pack_start(canvas_tree_model.icon, false); //false = don't expand.
113 column->pack_start(canvas_tree_model.label);
116 // column->add_attribute(icon_cellrenderer->property_pixbuf(), canvas_tree_model.icon);
119 canvas_tree->append_column(*column);
121 canvas_tree->set_rules_hint();
122 canvas_tree->signal_row_activated().connect(sigc::mem_fun(*this,&Dock_Canvases::on_row_activate));
123 //canvas_tree->signal_event().connect(sigc::mem_fun(*this,&Dock_Canvases::on_tree_event));
124 canvas_tree->add_events(Gdk::BUTTON_PRESS_MASK | Gdk::BUTTON_RELEASE_MASK);
125 canvas_tree->add_events(Gdk::BUTTON1_MOTION_MASK);
127 canvas_tree->set_headers_visible(false);
129 Gtk::ScrolledWindow *scrolledwindow = manage(new class Gtk::ScrolledWindow());
130 scrolledwindow->set_flags(Gtk::CAN_FOCUS);
131 scrolledwindow->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
132 scrolledwindow->add(*canvas_tree);
133 scrolledwindow->set_shadow_type(Gtk::SHADOW_ETCHED_IN);
134 scrolledwindow->show_all();
136 return scrolledwindow;
139 etl::loose_handle<studio::CanvasView>
140 Dock_Canvases::get_selected_canvas_view()
142 return get_selected_instance()->find_canvas_view(get_selected_canvas());
145 etl::loose_handle<synfig::Canvas>
146 Dock_Canvases::get_selected_canvas()
148 Glib::RefPtr<Gtk::TreeSelection> selection=canvas_tree->get_selection();
150 if(!selection || !selection->get_selected())
153 studio::Instance::CanvasTreeModel canvas_tree_model;
155 return static_cast<etl::handle<synfig::Canvas> >((*selection->get_selected())[canvas_tree_model.canvas]);
161 Dock_Canvases::set_selected_instance_signal(etl::handle<studio::Instance> x)
163 set_selected_instance(x);
167 Dock_Canvases::set_selected_instance_(etl::handle<studio::Instance> instance)
169 if(studio::App::shutdown_in_progress)
172 selected_instance=instance;
175 canvas_tree->set_model(instance->canvas_tree_store());
180 canvas_tree->set_model(Glib::RefPtr< Gtk::TreeModel >());
186 Dock_Canvases::set_selected_instance(etl::loose_handle<studio::Instance> x)
188 if(studio::App::shutdown_in_progress)
191 // if it's already selected, don't select it again
192 if (x==selected_instance)
195 set_selected_instance_(x);
199 Dock_Canvases::new_instance(etl::handle<studio::Instance> instance)
201 if(studio::App::shutdown_in_progress)
206 etl::loose_handle<studio::Instance> loose_instance(instance);
208 instance->synfigapp::Instance::signal_filename_changed().connect(sigc::mem_fun(*this,&Dock_Canvases::refresh_instances));
209 instance->synfigapp::Instance::signal_filename_changed().connect(
210 sigc::bind<etl::loose_handle<studio::Instance> >(
211 sigc::mem_fun(*this,&Dock_Canvases::set_selected_instance),
221 Dock_Canvases::delete_instance(etl::handle<studio::Instance> instance)
223 if(studio::App::shutdown_in_progress)
228 if(selected_instance==instance)
230 set_selected_instance(0);
235 Dock_Canvases::refresh_instances()
237 if(studio::App::shutdown_in_progress)
242 Dock_Canvases::on_row_activate(const Gtk::TreeModel::Path &path, Gtk::TreeViewColumn *)
244 assert(get_selected_instance());
245 studio::Instance::CanvasTreeModel canvas_tree_model;
246 const Gtk::TreeRow row = *(get_selected_instance()->canvas_tree_store()->get_iter(path));
247 if(row[canvas_tree_model.is_canvas])
248 get_selected_instance()->focus(row[canvas_tree_model.canvas]);
250 studio::App::dialog_not_implemented();