Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / synfigstudio_0_61_06 / src / gtkmm / statemanager.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file statemanager.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 "statemanager.h"
33 #include <gtkmm/actiongroup.h>
34 #include <gtkmm/action.h>
35 #include <synfig/string.h>
36 #include "app.h"
37 #include "toolbox.h"
38
39 #endif
40
41 /* === U S I N G =========================================================== */
42
43 using namespace std;
44 using namespace etl;
45 using namespace synfig;
46 using namespace studio;
47
48 /* === M A C R O S ========================================================= */
49
50 /* === G L O B A L S ======================================================= */
51
52 /* === P R O C E D U R E S ================================================= */
53
54 /* === M E T H O D S ======================================================= */
55
56 StateManager::StateManager():
57         state_group(Gtk::ActionGroup::create()),
58         merge_id(App::ui_manager()->new_merge_id())
59 {
60         App::ui_manager()->insert_action_group(get_action_group());
61 }
62
63 StateManager::~StateManager()
64 {
65         App::ui_manager()->remove_ui(merge_id);
66
67         for(;!merge_id_list.empty();merge_id_list.pop_back())
68                 App::ui_manager()->remove_ui(merge_id_list.back());
69 }
70
71 void
72 StateManager::change_state_(const Smach::state_base *state)
73 {
74         App::toolbox->change_state_(state);
75 }
76
77 void
78 StateManager::add_state(const Smach::state_base *state)
79 {
80         String name(state->get_name());
81
82         Glib::RefPtr<Gtk::Action> action(
83                 Gtk::Action::create(
84                         "state-"+name,
85                         Gtk::StockID("synfig-"+name),
86                         name,
87                         name
88                 )
89         );
90         /*action->set_sensitive(false);*/
91         state_group->add(action);
92
93         action->signal_activate().connect(
94                 sigc::bind(
95                         sigc::mem_fun(*this,&studio::StateManager::change_state_),
96                         state
97                 )
98         );
99
100         App::ui_manager()->ensure_update();
101
102         /*App::ui_manager()->add_ui(
103                 merge_id,
104                 "/main-menu/menu-state",
105                 "state-"+name,
106                 "state-"+name
107         );
108         */
109
110         String uid_def("<ui><popup action='menu-main'><menu action='menu-state'><menuitem action='state-"+name+"' /></menu></popup></ui>");
111         merge_id_list.push_back(App::ui_manager()->add_ui_from_string(uid_def));
112
113         App::ui_manager()->ensure_update();
114
115         App::toolbox->add_state(state);
116 }
117
118 Glib::RefPtr<Gtk::ActionGroup>
119 StateManager::get_action_group()
120 {
121         return state_group;
122 }