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>
42 /* === U S I N G =========================================================== */
46 using namespace synfig;
47 using namespace studio;
49 static const guint no_prev_popup((guint)-1);
51 /* === M A C R O S ========================================================= */
53 //#define ONE_ACTION_GROUP 1
55 /* === G L O B A L S ======================================================= */
57 /* === P R O C E D U R E S ================================================= */
59 /* === M E T H O D S ======================================================= */
61 KeyframeActionManager::KeyframeActionManager():
62 action_group_(Gtk::ActionGroup::create("action_group_keyframe_action_manager")),
63 popup_id_(no_prev_popup),
68 KeyframeActionManager::~KeyframeActionManager()
73 KeyframeActionManager::set_ui_manager(const Glib::RefPtr<Gtk::UIManager> &x)
77 #ifdef ONE_ACTION_GROUP
78 if(ui_manager_) get_ui_manager()->remove_action_group(action_group_);
80 if(ui_manager_) get_ui_manager()->insert_action_group(action_group_);
87 KeyframeActionManager::set_keyframe_tree(KeyframeTree* x)
89 selection_changed_connection.disconnect();
93 selection_changed_connection=keyframe_tree_->get_selection()->signal_changed().connect(
94 sigc::mem_fun(*this,&KeyframeActionManager::queue_refresh)
100 KeyframeActionManager::set_canvas_interface(const etl::handle<synfigapp::CanvasInterface> &x)
102 time_changed_connection.disconnect();
104 if(canvas_interface_)
106 canvas_interface_->signal_time_changed().connect(
107 sigc::mem_fun(*this,&KeyframeActionManager::queue_refresh)
113 KeyframeActionManager::clear()
117 // Clear out old stuff
118 if(popup_id_!=no_prev_popup)
120 get_ui_manager()->remove_ui(popup_id_);
121 popup_id_=no_prev_popup;
122 #ifdef ONE_ACTION_GROUP
123 while(!action_group_->get_actions().empty())action_group_->remove(*action_group_->get_actions().begin());
125 get_ui_manager()->remove_action_group(action_group_);
126 action_group_=Gtk::ActionGroup::create("action_group_keyframe_action_manager");
133 KeyframeActionManager::queue_refresh()
138 //queue_refresh_connection.disconnect();
139 queue_refresh_connection=Glib::signal_idle().connect(
141 sigc::mem_fun(*this,&KeyframeActionManager::refresh),
150 KeyframeActionManager::on_keyframe_properties()
152 signal_show_keyframe_properties_();
156 KeyframeActionManager::on_add_keyframe()
158 synfigapp::Action::Handle action(synfigapp::Action::create("KeyframeAdd"));
163 action->set_param("canvas",canvas_interface_->get_canvas());
164 action->set_param("canvas_interface",canvas_interface_);
165 action->set_param("keyframe",Keyframe(canvas_interface_->get_time()));
167 canvas_interface_->get_instance()->perform_action(action);
171 KeyframeActionManager::refresh()
173 KeyframeTreeStore::Model model;
178 //queue_refresh_connection.disconnect();
184 // Make sure we are ready
185 if(!ui_manager_ || !keyframe_tree_ || !canvas_interface_)
187 synfig::error("KeyframeActionManager::refresh(): Not ready!");
194 synfigapp::Action::ParamList param_list;
195 param_list.add("time",get_canvas_interface()->get_time());
196 param_list.add("canvas",get_canvas_interface()->get_canvas());
197 param_list.add("canvas_interface",get_canvas_interface());
198 if(keyframe_tree_->get_selection()->count_selected_rows()==1)
200 Keyframe keyframe((*keyframe_tree_->get_selection()->get_selected())[model.keyframe]);
201 param_list.add("keyframe",keyframe);
204 handle<studio::Instance>::cast_static(
205 get_canvas_interface()->get_instance()
206 )->add_actions_to_group(
210 synfigapp::Action::CATEGORY_KEYFRAME
213 if(action_group_->get_action("action-KeyframeAdd"))
215 action_group_->remove(action_group_->get_action("action-KeyframeAdd"));
218 action_group_->add(Gtk::Action::create(
219 "action-KeyframeAdd",
220 Gtk::StockID("gtk-add"),
221 _("Add New Keyframe"),_("Add New Keyframe")
223 sigc::mem_fun(*this,&KeyframeActionManager::on_add_keyframe)
228 canvas_interface_->get_canvas()->keyframe_list().find(canvas_interface_->get_time());
229 action_group_->get_action("action-KeyframeAdd")->set_sensitive(false);
230 if(action_group_->get_action("action-KeyframeDuplicate"))
231 action_group_->get_action("action-KeyframeDuplicate")->set_sensitive(false);
238 Glib::RefPtr<Gtk::Action> action(Gtk::Action::create("keyframe-properties", Gtk::StockID("gtk-properties"),
239 _("Keyframe Properties"), _("Keyframe Properties")));
240 action_group_->add(action,sigc::mem_fun(*this,&KeyframeActionManager::on_keyframe_properties));
241 if(keyframe_tree_->get_selection()->count_selected_rows()==0)
242 action->set_sensitive(false);
245 ui_info="<ui><popup action='menu-main'><menu action='menu-keyframe'>"+ui_info+"</menu></popup></ui>";
246 popup_id_=get_ui_manager()->add_ui_from_string(ui_info);
247 #ifdef ONE_ACTION_GROUP
249 get_ui_manager()->insert_action_group(action_group_);