1 /* === S Y N F I G ========================================================= */
2 /*! \file widget_compselect.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 <gtkmm/menu.h>
33 #include "widget_compselect.h"
34 #include <ETL/stringf>
35 #include <synfig/valuenode.h>
42 /* === U S I N G =========================================================== */
46 using namespace synfig;
47 using namespace studio;
49 /* === M A C R O S ========================================================= */
51 /* === G L O B A L S ======================================================= */
53 /* === P R O C E D U R E S ================================================= */
55 /* === M E T H O D S ======================================================= */
57 Widget_CompSelect::Widget_CompSelect()
59 App::signal_instance_created().connect(sigc::mem_fun(*this,&studio::Widget_CompSelect::new_instance));
60 App::signal_instance_deleted().connect(sigc::mem_fun(*this,&studio::Widget_CompSelect::delete_instance));
61 App::signal_instance_selected().connect(sigc::mem_fun(*this,&studio::Widget_CompSelect::set_selected_instance_signal));
63 set_menu(instance_list_menu);
67 Widget_CompSelect::~Widget_CompSelect()
72 Widget_CompSelect::set_selected_instance_signal(etl::handle<studio::Instance> x)
74 set_selected_instance(x);
78 Widget_CompSelect::set_selected_instance_(etl::handle<studio::Instance> instance)
80 if(studio::App::shutdown_in_progress)
83 selected_instance=instance;
87 Widget_CompSelect::set_selected_instance(etl::loose_handle<studio::Instance> x)
89 if(studio::App::shutdown_in_progress)
92 // if it's already selected, don't select it again
93 if (x==selected_instance)
96 std::list<etl::handle<studio::Instance> >::iterator iter;
101 for(i=0,iter=studio::App::instance_list.begin();iter!=studio::App::instance_list.end() && ((*iter)!=x);iter++,i++);
110 set_selected_instance_(x);
114 Widget_CompSelect::new_instance(etl::handle<studio::Instance> instance)
116 if(studio::App::shutdown_in_progress)
121 etl::loose_handle<studio::Instance> loose_instance(instance);
123 instance->synfigapp::Instance::signal_filename_changed().connect(sigc::mem_fun(*this,&Widget_CompSelect::refresh));
124 instance->synfigapp::Instance::signal_filename_changed().connect(
125 sigc::bind<etl::loose_handle<studio::Instance> >(
126 sigc::mem_fun(*this,&Widget_CompSelect::set_selected_instance),
132 std::string name=basename(instance->get_file_name());
134 instance_list_menu.items().push_back(Gtk::Menu_Helpers::MenuElem(name,
135 sigc::bind<etl::loose_handle<studio::Instance> >(sigc::ptr_fun(&studio::App::set_selected_instance),loose_instance) ));
141 Widget_CompSelect::delete_instance(etl::handle<studio::Instance> instance)
145 if(selected_instance==instance)
147 set_selected_instance(0);
153 Widget_CompSelect::refresh()
157 if(!instance_list_menu.items().empty())
158 instance_list_menu.items().clear();
160 if(studio::App::shutdown_in_progress)
163 std::list<etl::handle<studio::Instance> >::iterator iter;
164 for(iter=studio::App::instance_list.begin();iter!=studio::App::instance_list.end();iter++)
166 std::string name=basename((*iter)->get_file_name());
168 instance_list_menu.items().push_back(Gtk::Menu_Helpers::MenuElem(name,
169 sigc::bind<etl::loose_handle<studio::Instance> >(sigc::ptr_fun(&studio::App::set_selected_instance),*iter) ));
171 set_menu(instance_list_menu);