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>
41 /* === U S I N G =========================================================== */
45 using namespace synfig;
46 using namespace studio;
48 /* === M A C R O S ========================================================= */
50 /* === G L O B A L S ======================================================= */
52 /* === P R O C E D U R E S ================================================= */
54 /* === M E T H O D S ======================================================= */
56 Widget_CanvasChooser::Widget_CanvasChooser()
60 Widget_CanvasChooser::~Widget_CanvasChooser()
65 Widget_CanvasChooser::set_parent_canvas(synfig::Canvas::Handle x)
72 Widget_CanvasChooser::set_value_(synfig::Canvas::Handle data)
79 Widget_CanvasChooser::set_value(synfig::Canvas::Handle data)
81 assert(parent_canvas);
84 canvas_menu=manage(new class Gtk::Menu());
86 synfig::Canvas::Children::iterator iter;
87 synfig::Canvas::Children &children(parent_canvas->children());
92 label=canvas->get_name().empty()?canvas->get_id():canvas->get_name();
93 canvas_menu->items().push_back(Gtk::Menu_Helpers::MenuElem(label));
96 for(iter=children.begin();iter!=children.end();iter++)
99 label=(*iter)->get_name().empty()?(*iter)->get_id():(*iter)->get_name();
100 canvas_menu->items().push_back(
101 Gtk::Menu_Helpers::MenuElem(
106 &Widget_CanvasChooser::set_value_
113 canvas_menu->items().push_back(
114 Gtk::Menu_Helpers::MenuElem(
116 sigc::mem_fun(*this,&Widget_CanvasChooser::chooser_menu)
119 set_menu(*canvas_menu);
125 const etl::handle<synfig::Canvas> &
126 Widget_CanvasChooser::get_value()
132 Widget_CanvasChooser::chooser_menu()
136 if (!App::dialog_entry(_("Choose Canvas"),_("Enter the relative name of the canvas that you want"),canvas_name))
138 // the user hit 'cancel', so set the parameter back to its previous value
143 if (canvas_name == "")
145 App::dialog_error_blocking(_("Error"),_("No canvas name was specified"));
150 Canvas::Handle new_canvas;
153 new_canvas=parent_canvas->find_canvas(canvas_name);
154 set_value_(new_canvas);
156 catch(std::runtime_error x)
158 App::dialog_error_blocking(_("Error:Exception Thrown"),x.what());
163 App::dialog_error_blocking(_("Error"),_("Unknown Exception"));