my log
[synfig.git] / synfig-studio / trunk / src / gtkmm / statemanager.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file template.cpp
3 **      \brief Template File
4 **
5 **      $Id: statemanager.cpp,v 1.1.1.1 2005/01/07 03:34:36 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
14 **      You may not copy, print, publish, or in any
15 **      other way distribute this software without
16 **      a prior written agreement with
17 **      the copyright holder.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === H E A D E R S ======================================================= */
23
24 #ifdef USING_PCH
25 #       include "pch.h"
26 #else
27 #ifdef HAVE_CONFIG_H
28 #       include <config.h>
29 #endif
30
31 #include "statemanager.h"
32 #include <gtkmm/actiongroup.h>
33 #include <gtkmm/action.h>
34 #include <synfig/string.h>
35 #include "app.h"
36 #include "toolbox.h"
37
38 #endif
39
40 /* === U S I N G =========================================================== */
41
42 using namespace std;
43 using namespace etl;
44 using namespace synfig;
45 using namespace studio;
46
47 /* === M A C R O S ========================================================= */
48
49 /* === G L O B A L S ======================================================= */
50
51 /* === P R O C E D U R E S ================================================= */
52
53 /* === M E T H O D S ======================================================= */
54
55 StateManager::StateManager():
56         state_group(Gtk::ActionGroup::create()),
57         merge_id(App::ui_manager()->new_merge_id())
58 {
59         App::ui_manager()->insert_action_group(get_action_group());
60 }
61
62 StateManager::~StateManager()
63 {
64         App::ui_manager()->remove_ui(merge_id);
65
66         for(;!merge_id_list.empty();merge_id_list.pop_back())
67                 App::ui_manager()->remove_ui(merge_id_list.back());
68 }
69
70 void
71 StateManager::change_state_(const Smach::state_base *state)
72 {
73         App::toolbox->change_state_(state);
74 }
75
76 void
77 StateManager::add_state(const Smach::state_base *state)
78 {
79         String name(state->get_name());
80         
81         Glib::RefPtr<Gtk::Action> action(
82                 Gtk::Action::create(
83                         "state-"+name,
84                         Gtk::StockID("synfig-"+name),
85                         name,
86                         name
87                 )
88         );
89         /*action->set_sensitive(false);*/
90         state_group->add(action);
91         
92         action->signal_activate().connect(
93                 sigc::bind(
94                         sigc::mem_fun(*this,&studio::StateManager::change_state_),
95                         state
96                 )
97         );
98         
99         App::ui_manager()->ensure_update();
100
101         /*App::ui_manager()->add_ui(
102                 merge_id,
103                 "/main-menu/menu-state",
104                 "state-"+name,
105                 "state-"+name
106         );
107         */
108         
109         String uid_def("<ui><popup action='menu-main'><menu action='menu-state'><menuitem action='state-"+name+"' /></menu></popup></ui>");
110         merge_id_list.push_back(App::ui_manager()->add_ui_from_string(uid_def));
111         
112         App::ui_manager()->ensure_update();
113
114         App::toolbox->add_state(state);
115 }
116
117 Glib::RefPtr<Gtk::ActionGroup>
118 StateManager::get_action_group()
119 {
120         return state_group;
121 }