source: synfigstudio/trunk/fuentes/src/gui/statemanager.cpp @ 481

Last change on this file since 481 was 481, checked in by jrpelegrina, 4 years ago

First release to xenial

File size: 3.3 KB
Line 
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 "docks/dock_toolbox.h"
39
40#include "general.h"
41
42#endif
43
44/* === U S I N G =========================================================== */
45
46using namespace std;
47using namespace etl;
48using namespace synfig;
49using 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
59StateManager::StateManager():
60        state_group(Gtk::ActionGroup::create("action_group_state_manager")),
61        merge_id(App::ui_manager()->new_merge_id())
62{
63        App::ui_manager()->insert_action_group(get_action_group());
64}
65
66StateManager::~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
74void
75StateManager::change_state_(const Smach::state_base *state)
76{
77        App::dock_toolbox->change_state_(state);
78}
79
80void
81StateManager::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        String uid_def;
107        uid_def = "<ui><popup action='menu-main'><menu action='menu-toolbox'><menuitem action='state-"+name+"' /></menu></popup></ui>";
108        merge_id_list.push_back(App::ui_manager()->add_ui_from_string(uid_def));
109        uid_def = "<ui><menubar action='menubar-main'><menu action='menu-toolbox'><menuitem action='state-"+name+"' /></menu></menubar></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::dock_toolbox->add_state(state);
115}
116
117Glib::RefPtr<Gtk::ActionGroup>
118StateManager::get_action_group()
119{
120        return state_group;
121}
Note: See TracBrowser for help on using the repository browser.