Use the short form for toggle-onion-skin because we can.
[synfig.git] / synfig-studio / trunk / src / gtkmm / dock_keyframes.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file dock_keyframes.cpp
3 **      \brief Template File
4 **
5 **      $Id$
6 **
7 **      \legal
8 **      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9 **
10 **      This package is free software; you can redistribute it and/or
11 **      modify it under the terms of the GNU General Public License as
12 **      published by the Free Software Foundation; either version 2 of
13 **      the License, or (at your option) any later version.
14 **
15 **      This package is distributed in the hope that it will be useful,
16 **      but WITHOUT ANY WARRANTY; without even the implied warranty of
17 **      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 **      General Public License for more details.
19 **      \endlegal
20 */
21 /* ========================================================================= */
22
23 /* === H E A D E R S ======================================================= */
24
25 #ifdef USING_PCH
26 #       include "pch.h"
27 #else
28 #ifdef HAVE_CONFIG_H
29 #       include <config.h>
30 #endif
31
32 #include "dock_keyframes.h"
33 #include "app.h"
34
35 #include <gtkmm/scrolledwindow.h>
36 #include <cassert>
37 #include "instance.h"
38 #include <sigc++/signal.h>
39 #include <sigc++/hide.h>
40 #include <sigc++/slot.h>
41 #include "keyframetreestore.h"
42 #include "keyframetree.h"
43 #include "canvasview.h"
44 #include "keyframeactionmanager.h"
45
46 #include "general.h"
47
48 #endif
49
50 /* === U S I N G =========================================================== */
51
52 using namespace std;
53 using namespace etl;
54 using namespace synfig;
55 using namespace studio;
56
57 /* === M A C R O S ========================================================= */
58
59 /* === G L O B A L S ======================================================= */
60
61 /* === P R O C E D U R E S ================================================= */
62
63 /* === M E T H O D S ======================================================= */
64
65 Dock_Keyframes::Dock_Keyframes():
66         Dock_CanvasSpecific("keyframes",_("Keyframes"),Gtk::StockID("synfig-keyframes")),
67         action_group(Gtk::ActionGroup::create()),
68         keyframe_action_manager(new KeyframeActionManager)
69 {
70         keyframe_action_manager->set_ui_manager(App::ui_manager());
71         keyframe_action_manager->signal_show_keyframe_properties().connect(
72                 sigc::mem_fun(*this,&Dock_Keyframes::show_keyframe_properties)
73         );
74 /*      add_button(
75                 Gtk::StockID("gtk-add"),
76                 _("Inserts a Keyframe at the current time")
77         )->signal_clicked().connect(
78                 sigc::mem_fun(
79                         *this,
80                         &Dock_Keyframes::add_keyframe_pressed
81                 )
82         );
83
84         add_button(
85                 Gtk::StockID("synfig-duplicate"),
86                 _("Duplicates the selected keyframe at the current time")
87         )->signal_clicked().connect(
88                 sigc::mem_fun(
89                         *this,
90                         &Dock_Keyframes::duplicate_keyframe_pressed
91                 )
92         );
93
94         add_button(
95                 Gtk::StockID("gtk-delete"),
96                 _("Deletes the selected Keyframe")
97         )->signal_clicked().connect(
98                 sigc::mem_fun(
99                         *this,
100                         &Dock_Keyframes::delete_keyframe_pressed
101                 )
102         );
103 */
104     Glib::ustring ui_info =
105         "<ui>"
106         "       <toolbar action='toolbar-keyframe'>"
107         "       <toolitem action='action-KeyframeAdd' />"
108         "       <toolitem action='action-KeyframeDuplicate' />"
109         "       <toolitem action='action-KeyframeRemove' />"
110         "       <toolitem action='keyframe-properties' />"
111         "       </toolbar>"
112         "</ui>"
113         ;
114
115         App::ui_manager()->add_ui_from_string(ui_info);
116
117         set_toolbar(*dynamic_cast<Gtk::Toolbar*>(App::ui_manager()->get_widget("/toolbar-keyframe")));
118 }
119
120 Dock_Keyframes::~Dock_Keyframes()
121 {
122 }
123
124 void
125 Dock_Keyframes::show_keyframe_properties()
126 {
127         if(get_canvas_view())
128                 get_canvas_view()->show_keyframe_dialog();
129 }
130
131 /*
132 void
133 Dock_Keyframes::add_keyframe_pressed()
134 {
135         if(get_canvas_view())
136                 get_canvas_view()->on_keyframe_add_pressed();
137 }
138
139 void
140 Dock_Keyframes::duplicate_keyframe_pressed()
141 {
142         if(get_canvas_view())
143                 get_canvas_view()->on_keyframe_duplicate_pressed();
144 }
145
146 void
147 Dock_Keyframes::delete_keyframe_pressed()
148 {
149         if(get_canvas_view())
150                 get_canvas_view()->on_keyframe_remove_pressed();
151 }
152 */
153
154 void
155 Dock_Keyframes::init_canvas_view_vfunc(etl::loose_handle<CanvasView> canvas_view)
156 {
157         Glib::RefPtr<KeyframeTreeStore> keyframe_tree_store;
158         keyframe_tree_store=KeyframeTreeStore::create(canvas_view->canvas_interface());
159
160         KeyframeTree* keyframe_tree(new KeyframeTree());
161         keyframe_tree->set_model(keyframe_tree_store);
162         keyframe_tree->set_editable(true);
163
164         canvas_view->set_tree_model(get_name(),keyframe_tree_store);
165         canvas_view->set_ext_widget(get_name(),keyframe_tree);
166 }
167
168 void
169 Dock_Keyframes::changed_canvas_view_vfunc(etl::loose_handle<CanvasView> canvas_view)
170 {
171         if(canvas_view)
172         {
173                 Gtk::Widget* tree_view(canvas_view->get_ext_widget(get_name()));
174
175                 add(*tree_view);
176                 tree_view->show();
177
178                 keyframe_action_manager->set_keyframe_tree(dynamic_cast<KeyframeTree*>(canvas_view->get_ext_widget(get_name())));
179                 keyframe_action_manager->set_canvas_interface(canvas_view->canvas_interface());
180                 keyframe_action_manager->refresh();
181         }
182         else
183         {
184                 clear_previous();
185
186                 keyframe_action_manager->set_keyframe_tree(0);
187                 keyframe_action_manager->set_canvas_interface(0);
188                 keyframe_action_manager->refresh();
189         }
190 }