1 /* === S Y N F I G ========================================================= */
2 /*! \file statemanager.cpp
3 ** \brief Template File
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 ** Copyright (c) 2007 Chris Moore
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.
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.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include "statemanager.h"
34 #include <gtkmm/actiongroup.h>
35 #include <gtkmm/action.h>
36 #include <synfig/string.h>
44 /* === U S I N G =========================================================== */
48 using namespace synfig;
49 using namespace studio;
51 /* === M A C R O S ========================================================= */
53 /* === G L O B A L S ======================================================= */
55 /* === P R O C E D U R E S ================================================= */
57 /* === M E T H O D S ======================================================= */
59 StateManager::StateManager():
60 state_group(Gtk::ActionGroup::create("action_group_state_manager")),
61 merge_id(App::ui_manager()->new_merge_id())
63 App::ui_manager()->insert_action_group(get_action_group());
66 StateManager::~StateManager()
68 App::ui_manager()->remove_ui(merge_id);
70 for(;!merge_id_list.empty();merge_id_list.pop_back())
71 App::ui_manager()->remove_ui(merge_id_list.back());
75 StateManager::change_state_(const Smach::state_base *state)
77 App::toolbox->change_state_(state);
81 StateManager::add_state(const Smach::state_base *state)
83 String name(state->get_name());
85 Gtk::StockItem stock_item;
86 Gtk::Stock::lookup(Gtk::StockID("synfig-"+name),stock_item);
88 Glib::RefPtr<Gtk::Action> action(
91 stock_item.get_stock_id(),
92 stock_item.get_label(),
93 stock_item.get_label()
96 /*action->set_sensitive(false);*/
97 state_group->add(action);
99 action->signal_activate().connect(
101 sigc::mem_fun(*this,&studio::StateManager::change_state_),
106 App::ui_manager()->ensure_update();
108 /*App::ui_manager()->add_ui(
110 "/main-menu/menu-state",
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));
119 App::ui_manager()->ensure_update();
121 App::toolbox->add_state(state);
124 Glib::RefPtr<Gtk::ActionGroup>
125 StateManager::get_action_group()