1 /* === S Y N F I G ========================================================= */
2 /*! \file widget_canvaschooser.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007 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 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include "widget_canvaschooser.h"
34 #include <gtkmm/menu.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 Widget_CanvasChooser::Widget_CanvasChooser()
58 Widget_CanvasChooser::~Widget_CanvasChooser()
63 Widget_CanvasChooser::set_parent_canvas(etl::handle<synfig::Canvas> x)
70 Widget_CanvasChooser::set_value_(etl::handle<synfig::Canvas> data)
77 Widget_CanvasChooser::set_value(etl::handle<synfig::Canvas> data)
79 assert(parent_canvas);
82 canvas_menu=manage(new class Gtk::Menu());
84 synfig::Canvas::Children::iterator iter;
85 synfig::Canvas::Children &children(parent_canvas->children());
90 label=canvas->get_name().empty()?canvas->get_id():canvas->get_name();
91 canvas_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(label));
94 for(iter=children.begin();iter!=children.end();iter++)
97 label=(*iter)->get_name().empty()?(*iter)->get_id():(*iter)->get_name();
98 canvas_menu->items().push_back(
99 Gtk::Menu_Helpers::MenuElem(
104 &Widget_CanvasChooser::set_value_
111 canvas_menu->items().push_back(
112 Gtk::Menu_Helpers::MenuElem(
114 sigc::mem_fun(*this,&Widget_CanvasChooser::chooser_menu)
117 set_menu(*canvas_menu);
123 const etl::handle<synfig::Canvas> &
124 Widget_CanvasChooser::get_value()
130 Widget_CanvasChooser::chooser_menu()
134 if (!App::dialog_entry(_("Choose Canvas"),_("Enter the relative name of the canvas that you want"),canvas_name))
136 // the user hit 'cancel', so set the parameter back to its previous value
141 if (canvas_name == "")
143 App::dialog_error_blocking(_("Error"),_("No canvas name was specified"));
148 Canvas::Handle new_canvas;
151 new_canvas=parent_canvas->find_canvas(canvas_name);
152 set_value_(new_canvas);
154 catch(std::runtime_error x)
156 App::dialog_error_blocking(_("Error:Exception Thrown"),x.what());
161 App::dialog_error_blocking(_("Error"),_("Unknown Exception"));