1 /* === S Y N F I G ========================================================= */
2 /*! \file widget_compselect.cpp
3 ** \brief Template File
5 ** $Id: widget_compselect.cpp,v 1.1.1.1 2005/01/07 03:34:37 darco Exp $
8 ** Copyright (c) 2002 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === H E A D E R S ======================================================= */
31 #include <gtkmm/menu.h>
32 #include "widget_compselect.h"
33 #include <ETL/stringf>
34 #include <synfig/valuenode.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_CompSelect::Widget_CompSelect()
56 App::signal_instance_created().connect(sigc::mem_fun(*this,&studio::Widget_CompSelect::new_instance));
57 App::signal_instance_deleted().connect(sigc::mem_fun(*this,&studio::Widget_CompSelect::delete_instance));
58 App::signal_instance_selected().connect(sigc::mem_fun(*this,&studio::Widget_CompSelect::set_selected_instance_signal));
60 set_menu(instance_list_menu);
64 Widget_CompSelect::~Widget_CompSelect()
69 Widget_CompSelect::set_selected_instance_signal(etl::handle<studio::Instance> x)
71 set_selected_instance(x);
75 Widget_CompSelect::set_selected_instance_(etl::handle<studio::Instance> instance)
77 if(studio::App::shutdown_in_progress)
80 selected_instance=instance;
84 Widget_CompSelect::set_selected_instance(etl::loose_handle<studio::Instance> x)
86 if(studio::App::shutdown_in_progress)
89 // if it's already selected, don't select it again
90 if (x==selected_instance)
93 std::list<etl::handle<studio::Instance> >::iterator iter;
98 for(i=0,iter=studio::App::instance_list.begin();iter!=studio::App::instance_list.end() && ((*iter)!=x);iter++,i++);
107 set_selected_instance_(x);
111 Widget_CompSelect::new_instance(etl::handle<studio::Instance> instance)
113 if(studio::App::shutdown_in_progress)
118 etl::loose_handle<studio::Instance> loose_instance(instance);
120 instance->synfigapp::Instance::signal_filename_changed().connect(sigc::mem_fun(*this,&Widget_CompSelect::refresh));
121 instance->synfigapp::Instance::signal_filename_changed().connect(
122 sigc::bind<etl::loose_handle<studio::Instance> >(
123 sigc::mem_fun(*this,&Widget_CompSelect::set_selected_instance),
129 std::string name=basename(instance->get_file_name());
131 instance_list_menu.items().push_back(Gtk::Menu_Helpers::MenuElem(name,
132 sigc::bind<etl::loose_handle<studio::Instance> >(sigc::ptr_fun(&studio::App::set_selected_instance),loose_instance) ));
138 Widget_CompSelect::delete_instance(etl::handle<studio::Instance> instance)
143 if(selected_instance==instance)
145 set_selected_instance(0);
151 Widget_CompSelect::refresh()
155 if(!instance_list_menu.items().empty())
156 instance_list_menu.items().clear();
158 if(studio::App::shutdown_in_progress)
161 std::list<etl::handle<studio::Instance> >::iterator iter;
162 for(iter=studio::App::instance_list.begin();iter!=studio::App::instance_list.end();iter++)
164 std::string name=basename((*iter)->get_file_name());
166 instance_list_menu.items().push_back(Gtk::Menu_Helpers::MenuElem(name,
167 sigc::bind<etl::loose_handle<studio::Instance> >(sigc::ptr_fun(&studio::App::set_selected_instance),*iter) ));
169 set_menu(instance_list_menu);