Fix bugs in previous commit that caused FTBFS in synfig and ETL FTBFS with older...
[synfig.git] / synfig-studio / tags / synfigstudio_0_61_07_rc2 / 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 #endif
41
42 /* === U S I N G =========================================================== */
43
44 using namespace std;
45 using namespace etl;
46 using namespace synfig;
47 using 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
57 StateManager::StateManager():
58         state_group(Gtk::ActionGroup::create()),
59         merge_id(App::ui_manager()->new_merge_id())
60 {
61         App::ui_manager()->insert_action_group(get_action_group());
62 }
63
64 StateManager::~StateManager()
65 {
66         App::ui_manager()->remove_ui(merge_id);
67
68         for(;!merge_id_list.empty();merge_id_list.pop_back())
69                 App::ui_manager()->remove_ui(merge_id_list.back());
70 }
71
72 void
73 StateManager::change_state_(const Smach::state_base *state)
74 {
75         App::toolbox->change_state_(state);
76 }
77
78 void
79 StateManager::add_state(const Smach::state_base *state)
80 {
81         String name(state->get_name());
82
83         Gtk::StockItem stock_item;
84         Gtk::Stock::lookup(Gtk::StockID("synfig-"+name),stock_item);
85
86         Glib::RefPtr<Gtk::Action> action(
87                 Gtk::Action::create(
88                         "state-"+name,
89                         stock_item.get_stock_id(),
90                         stock_item.get_label(),
91                         stock_item.get_label()
92                 )
93         );
94         /*action->set_sensitive(false);*/
95         state_group->add(action);
96
97         action->signal_activate().connect(
98                 sigc::bind(
99                         sigc::mem_fun(*this,&studio::StateManager::change_state_),
100                         state
101                 )
102         );
103
104         App::ui_manager()->ensure_update();
105
106         /*App::ui_manager()->add_ui(
107                 merge_id,
108                 "/main-menu/menu-state",
109                 "state-"+name,
110                 "state-"+name
111         );
112         */
113
114         String uid_def("<ui><popup action='menu-main'><menu action='menu-state'><menuitem action='state-"+name+"' /></menu></popup></ui>");
115         merge_id_list.push_back(App::ui_manager()->add_ui_from_string(uid_def));
116
117         App::ui_manager()->ensure_update();
118
119         App::toolbox->add_state(state);
120 }
121
122 Glib::RefPtr<Gtk::ActionGroup>
123 StateManager::get_action_group()
124 {
125         return state_group;
126 }