Fix 1675309: CanvasView::close() was previously just hiding the canvas, not closing it.
[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: dock_keyframes.cpp,v 1.3 2005/01/13 20:23:01 darco Exp $
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 #endif
47
48 /* === U S I N G =========================================================== */
49
50 using namespace std;
51 using namespace etl;
52 using namespace synfig;
53 using namespace studio;
54
55 /* === M A C R O S ========================================================= */
56
57 /* === G L O B A L S ======================================================= */
58
59 /* === P R O C E D U R E S ================================================= */
60
61 /* === M E T H O D S ======================================================= */
62
63 Dock_Keyframes::Dock_Keyframes():
64         Dock_CanvasSpecific("keyframes",_("Keyframes"),Gtk::StockID("synfig-keyframes")),
65         action_group(Gtk::ActionGroup::create()),
66         keyframe_action_manager(new KeyframeActionManager)
67 {
68         keyframe_action_manager->set_ui_manager(App::ui_manager());
69         keyframe_action_manager->signal_show_keyframe_properties().connect(
70                 sigc::mem_fun(*this,&Dock_Keyframes::show_keyframe_properties)
71         );
72 /*      add_button(
73                 Gtk::StockID("gtk-add"),
74                 _("Inserts a Keyframe at the current time")
75         )->signal_clicked().connect(
76                 sigc::mem_fun(
77                         *this,
78                         &Dock_Keyframes::add_keyframe_pressed
79                 )
80         );
81
82         add_button(
83                 Gtk::StockID("synfig-duplicate"),
84                 _("Duplicates the selected keyframe at the current time")
85         )->signal_clicked().connect(
86                 sigc::mem_fun(
87                         *this,
88                         &Dock_Keyframes::duplicate_keyframe_pressed
89                 )
90         );
91
92         add_button(
93                 Gtk::StockID("gtk-delete"),
94                 _("Deletes the selected Keyframe")
95         )->signal_clicked().connect(
96                 sigc::mem_fun(
97                         *this,
98                         &Dock_Keyframes::delete_keyframe_pressed
99                 )
100         );
101 */
102     Glib::ustring ui_info =
103         "<ui>"
104         "       <toolbar action='toolbar-keyframe'>"
105         "       <toolitem action='action-keyframe_add' />"
106         "       <toolitem action='action-keyframe_duplicate' />"
107         "       <toolitem action='action-keyframe_remove' />"
108         "       <toolitem action='keyframe-properties' />"
109         "       </toolbar>"
110         "</ui>"
111         ;
112
113         App::ui_manager()->add_ui_from_string(ui_info);
114
115         set_toolbar(*dynamic_cast<Gtk::Toolbar*>(App::ui_manager()->get_widget("/toolbar-keyframe")));  
116 }
117
118 Dock_Keyframes::~Dock_Keyframes()
119 {
120 }
121
122 void
123 Dock_Keyframes::show_keyframe_properties()
124 {
125         if(get_canvas_view())
126                 get_canvas_view()->show_keyframe_dialog();
127 }
128
129 /*
130 void
131 Dock_Keyframes::add_keyframe_pressed()
132 {
133         if(get_canvas_view())
134                 get_canvas_view()->on_keyframe_add_pressed();
135 }
136
137 void
138 Dock_Keyframes::duplicate_keyframe_pressed()
139 {
140         if(get_canvas_view())
141                 get_canvas_view()->on_keyframe_duplicate_pressed();
142 }
143
144 void
145 Dock_Keyframes::delete_keyframe_pressed()
146 {
147         if(get_canvas_view())
148                 get_canvas_view()->on_keyframe_remove_pressed();
149 }
150 */
151
152 void
153 Dock_Keyframes::init_canvas_view_vfunc(etl::loose_handle<CanvasView> canvas_view)
154 {
155         Glib::RefPtr<KeyframeTreeStore> keyframe_tree_store;
156         keyframe_tree_store=KeyframeTreeStore::create(canvas_view->canvas_interface());
157
158         KeyframeTree* keyframe_tree(new KeyframeTree());
159         keyframe_tree->set_model(keyframe_tree_store);
160         keyframe_tree->set_editable(true);
161
162         canvas_view->set_tree_model(get_name(),keyframe_tree_store);
163         canvas_view->set_ext_widget(get_name(),keyframe_tree);
164 }
165
166 void
167 Dock_Keyframes::changed_canvas_view_vfunc(etl::loose_handle<CanvasView> canvas_view)
168 {
169         if(canvas_view)
170         {
171                 Gtk::Widget* tree_view(canvas_view->get_ext_widget(get_name()));
172         
173                 add(*tree_view);
174                 tree_view->show();
175                 
176                 keyframe_action_manager->set_keyframe_tree(dynamic_cast<KeyframeTree*>(canvas_view->get_ext_widget(get_name())));
177                 keyframe_action_manager->set_canvas_interface(canvas_view->canvas_interface());
178                 keyframe_action_manager->refresh();
179         }
180         else
181         {
182                 clear_previous();
183                 
184                 keyframe_action_manager->set_keyframe_tree(0);
185                 keyframe_action_manager->set_canvas_interface(0);
186                 keyframe_action_manager->refresh();
187         }
188 }