source: synfigstudio/trunk/fuentes/src/gui/widgets/widget_compselect.cpp @ 481

Last change on this file since 481 was 481, checked in by jrpelegrina, 4 years ago

First release to xenial

File size: 4.4 KB
Line 
1/* === S Y N F I G ========================================================= */
2/*!     \file widget_compselect.cpp
3**      \brief Template File
4**
5**      $Id$
6**
7**      \legal
8**      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9**
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.
14**
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.
19**      \endlegal
20*/
21/* ========================================================================= */
22
23/* === H E A D E R S ======================================================= */
24
25#ifdef USING_PCH
26#       include "pch.h"
27#else
28#ifdef HAVE_CONFIG_H
29#       include <config.h>
30#endif
31
32#include <gtkmm/menu.h>
33#include "widgets/widget_compselect.h"
34#include <ETL/stringf>
35#include <synfig/valuenode.h>
36#include "instance.h"
37
38#include "general.h"
39
40#endif
41
42/* === U S I N G =========================================================== */
43
44using namespace std;
45using namespace etl;
46using namespace synfig;
47using namespace studio;
48
49/* === M A C R O S ========================================================= */
50
51/* === G L O B A L S ======================================================= */
52
53/* === P R O C E D U R E S ================================================= */
54
55/* === M E T H O D S ======================================================= */
56
57Widget_CompSelect::Widget_CompSelect()
58{
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));
62
63        refresh();
64}
65
66Widget_CompSelect::~Widget_CompSelect()
67{
68}
69
70void
71Widget_CompSelect::set_selected_instance_signal(etl::handle<studio::Instance> x)
72{
73        set_selected_instance(x);
74}
75
76void
77Widget_CompSelect::set_selected_instance_(etl::handle<studio::Instance> instance)
78{
79        if(studio::App::shutdown_in_progress)
80                return;
81
82        selected_instance=instance;
83}
84
85void
86Widget_CompSelect::on_changed()
87{
88        int i = get_active_row_number();
89        if (i < 0 || i >= (int)instances.size()) return;
90        if (selected_instance == instances[i]) return;
91        studio::App::set_selected_instance(instances[i]);
92}
93
94void
95Widget_CompSelect::set_selected_instance(etl::loose_handle<studio::Instance> x)
96{
97        if(studio::App::shutdown_in_progress)
98                return;
99
100        // if it's already selected, don't select it again
101        if (x==selected_instance)
102                return;
103
104        std::list<etl::handle<studio::Instance> >::iterator iter;
105
106        if(x)
107        {
108                int i;
109                for(i=0,iter=studio::App::instance_list.begin();iter!=studio::App::instance_list.end() && ((*iter)!=x);iter++,i++)
110                        ;
111
112                if (*iter==x) 
113                {
114                        set_active(i);
115                } else {
116                        synfig::warning("Can't set selected instance! (already closed?)");
117                        iter = studio::App::instance_list.begin();
118                }
119        }
120        else
121                set_active(0);
122
123        set_selected_instance_(x);
124}
125
126void
127Widget_CompSelect::new_instance(etl::handle<studio::Instance> instance)
128{
129        if(studio::App::shutdown_in_progress)
130                return;
131
132        assert(instance);
133
134        etl::loose_handle<studio::Instance> loose_instance(instance);
135
136        instance->synfigapp::Instance::signal_filename_changed().connect(sigc::mem_fun(*this,&Widget_CompSelect::refresh));
137        instance->synfigapp::Instance::signal_filename_changed().connect(
138                sigc::bind<etl::loose_handle<studio::Instance> >(
139                        sigc::mem_fun(*this,&Widget_CompSelect::set_selected_instance),
140                        loose_instance
141                )
142        );
143
144        {
145                std::string name=basename(instance->get_file_name());
146                instances.push_back(loose_instance);
147                append(name);
148        }
149
150}
151
152void
153Widget_CompSelect::delete_instance(etl::handle<studio::Instance> instance)
154{
155        refresh();
156
157        if(selected_instance==instance)
158        {
159                set_selected_instance(0);
160                set_active(0);
161        }
162}
163
164void
165Widget_CompSelect::refresh()
166{
167        set_active(-1);
168        remove_all();
169        instances.clear();
170
171        if(studio::App::shutdown_in_progress)
172                return;
173
174        std::list<etl::handle<studio::Instance> >::iterator iter;
175        for(iter=studio::App::instance_list.begin();iter!=studio::App::instance_list.end();iter++)
176        {
177                std::string name=basename((*iter)->get_file_name());
178                instances.push_back( etl::loose_handle<studio::Instance>(*iter) );
179                append(name);
180        }
181}
Note: See TracBrowser for help on using the repository browser.