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