1 /* === S Y N F I G ========================================================= */
2 /*! \file keyframeactionmanager.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 "keyframeactionmanager.h"
34 #include "keyframetree.h"
35 #include <synfigapp/action_param.h>
40 /* === U S I N G =========================================================== */
44 using namespace synfig;
45 using namespace studio;
47 static const guint no_prev_popup((guint)-1);
49 /* === M A C R O S ========================================================= */
51 //#define ONE_ACTION_GROUP 1
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 KeyframeActionManager::KeyframeActionManager():
60 action_group_(Gtk::ActionGroup::create()),
61 popup_id_(no_prev_popup),
66 KeyframeActionManager::~KeyframeActionManager()
71 KeyframeActionManager::set_ui_manager(const Glib::RefPtr<Gtk::UIManager> &x)
75 #ifdef ONE_ACTION_GROUP
76 if(ui_manager_) get_ui_manager()->remove_action_group(action_group_);
78 if(ui_manager_) get_ui_manager()->insert_action_group(action_group_);
85 KeyframeActionManager::set_keyframe_tree(KeyframeTree* x)
87 selection_changed_connection.disconnect();
91 selection_changed_connection=keyframe_tree_->get_selection()->signal_changed().connect(
92 sigc::mem_fun(*this,&KeyframeActionManager::queue_refresh)
98 KeyframeActionManager::set_canvas_interface(const etl::handle<synfigapp::CanvasInterface> &x)
100 time_changed_connection.disconnect();
102 if(canvas_interface_)
104 canvas_interface_->signal_time_changed().connect(
105 sigc::mem_fun(*this,&KeyframeActionManager::queue_refresh)
111 KeyframeActionManager::clear()
115 // Clear out old stuff
116 if(popup_id_!=no_prev_popup)
118 get_ui_manager()->remove_ui(popup_id_);
119 popup_id_=no_prev_popup;
120 #ifdef ONE_ACTION_GROUP
121 while(!action_group_->get_actions().empty())action_group_->remove(*action_group_->get_actions().begin());
123 get_ui_manager()->remove_action_group(action_group_);
124 action_group_=Gtk::ActionGroup::create();
131 KeyframeActionManager::queue_refresh()
136 //queue_refresh_connection.disconnect();
137 queue_refresh_connection=Glib::signal_idle().connect(
139 sigc::mem_fun(*this,&KeyframeActionManager::refresh),
148 KeyframeActionManager::on_keyframe_properties()
150 signal_show_keyframe_properties_();
154 KeyframeActionManager::on_add_keyframe()
156 synfigapp::Action::Handle action(synfigapp::Action::create("keyframe_add"));
161 action->set_param("canvas",canvas_interface_->get_canvas());
162 action->set_param("canvas_interface",canvas_interface_);
163 action->set_param("keyframe",Keyframe(canvas_interface_->get_time()));
165 canvas_interface_->get_instance()->perform_action(action);
169 KeyframeActionManager::refresh()
171 KeyframeTreeStore::Model model;
176 //queue_refresh_connection.disconnect();
182 // Make sure we are ready
183 if(!ui_manager_ || !keyframe_tree_ || !canvas_interface_)
185 synfig::error("KeyframeActionManager::refresh(): Not ready!");
192 synfigapp::Action::ParamList param_list;
193 param_list.add("time",get_canvas_interface()->get_time());
194 param_list.add("canvas",get_canvas_interface()->get_canvas());
195 param_list.add("canvas_interface",get_canvas_interface());
196 if(keyframe_tree_->get_selection()->count_selected_rows()==1)
198 Keyframe keyframe((*keyframe_tree_->get_selection()->get_selected())[model.keyframe]);
199 param_list.add("keyframe",keyframe);
202 handle<studio::Instance>::cast_static(
203 get_canvas_interface()->get_instance()
204 )->add_actions_to_group(
208 synfigapp::Action::CATEGORY_KEYFRAME
211 if(action_group_->get_action("action-keyframe_add"))
213 action_group_->remove(action_group_->get_action("action-keyframe_add"));
216 action_group_->add(Gtk::Action::create(
217 "action-keyframe_add",
218 Gtk::StockID("gtk-add"),
219 _("Add new Keyframe"),_("Add new Keyframe")
221 sigc::mem_fun(*this,&KeyframeActionManager::on_add_keyframe)
226 canvas_interface_->get_canvas()->keyframe_list().find(canvas_interface_->get_time());
227 action_group_->get_action("action-keyframe_add")->set_sensitive(false);
228 if(action_group_->get_action("action-keyframe_duplicate"))
229 action_group_->get_action("action-keyframe_duplicate")->set_sensitive(false);
236 Glib::RefPtr<Gtk::Action> action(Gtk::Action::create("keyframe-properties", Gtk::StockID("gtk-properties"), _("Keyframe Properties")));
237 action_group_->add(action,sigc::mem_fun(*this,&KeyframeActionManager::on_keyframe_properties));
238 if(keyframe_tree_->get_selection()->count_selected_rows()==0)
239 action->set_sensitive(false);
242 ui_info="<ui><popup action='menu-main'><menu action='menu-keyframe'>"+ui_info+"</menu></popup></ui>";
243 popup_id_=get_ui_manager()->add_ui_from_string(ui_info);
244 #ifdef ONE_ACTION_GROUP
246 get_ui_manager()->insert_action_group(action_group_);