1 /* === S Y N F I G ========================================================= */
2 /*! \file keyframeactionmanager.cpp
3 ** \brief Template File
5 ** $Id: keyframeactionmanager.cpp,v 1.1.1.1 2005/01/07 03:34:36 darco Exp $
8 ** Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
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.
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.
21 /* ========================================================================= */
23 /* === H E A D E R S ======================================================= */
32 #include "keyframeactionmanager.h"
33 #include "keyframetree.h"
34 #include <synfigapp/action_param.h>
39 /* === U S I N G =========================================================== */
43 using namespace synfig;
44 using namespace studio;
46 static const guint no_prev_popup((guint)-1);
48 /* === M A C R O S ========================================================= */
50 //#define ONE_ACTION_GROUP 1
52 /* === G L O B A L S ======================================================= */
54 /* === P R O C E D U R E S ================================================= */
56 /* === M E T H O D S ======================================================= */
58 KeyframeActionManager::KeyframeActionManager():
59 action_group_(Gtk::ActionGroup::create()),
60 popup_id_(no_prev_popup),
65 KeyframeActionManager::~KeyframeActionManager()
70 KeyframeActionManager::set_ui_manager(const Glib::RefPtr<Gtk::UIManager> &x)
74 #ifdef ONE_ACTION_GROUP
75 if(ui_manager_) get_ui_manager()->remove_action_group(action_group_);
77 if(ui_manager_) get_ui_manager()->insert_action_group(action_group_);
84 KeyframeActionManager::set_keyframe_tree(KeyframeTree* x)
86 selection_changed_connection.disconnect();
90 selection_changed_connection=keyframe_tree_->get_selection()->signal_changed().connect(
91 sigc::mem_fun(*this,&KeyframeActionManager::queue_refresh)
97 KeyframeActionManager::set_canvas_interface(const etl::handle<synfigapp::CanvasInterface> &x)
99 time_changed_connection.disconnect();
101 if(canvas_interface_)
103 canvas_interface_->signal_time_changed().connect(
104 sigc::mem_fun(*this,&KeyframeActionManager::queue_refresh)
110 KeyframeActionManager::clear()
114 // Clear out old stuff
115 if(popup_id_!=no_prev_popup)
117 get_ui_manager()->remove_ui(popup_id_);
118 popup_id_=no_prev_popup;
119 #ifdef ONE_ACTION_GROUP
120 while(!action_group_->get_actions().empty())action_group_->remove(*action_group_->get_actions().begin());
122 get_ui_manager()->remove_action_group(action_group_);
123 action_group_=Gtk::ActionGroup::create();
130 KeyframeActionManager::queue_refresh()
135 //queue_refresh_connection.disconnect();
136 queue_refresh_connection=Glib::signal_idle().connect(
138 sigc::mem_fun(*this,&KeyframeActionManager::refresh),
147 KeyframeActionManager::on_keyframe_properties()
149 signal_show_keyframe_properties_();
153 KeyframeActionManager::on_add_keyframe()
155 synfigapp::Action::Handle action(synfigapp::Action::create("keyframe_add"));
160 action->set_param("canvas",canvas_interface_->get_canvas());
161 action->set_param("canvas_interface",canvas_interface_);
162 action->set_param("keyframe",Keyframe(canvas_interface_->get_time()));
164 canvas_interface_->get_instance()->perform_action(action);
168 KeyframeActionManager::refresh()
170 KeyframeTreeStore::Model model;
175 //queue_refresh_connection.disconnect();
181 // Make sure we are ready
182 if(!ui_manager_ || !keyframe_tree_ || !canvas_interface_)
184 synfig::error("KeyframeActionManager::refresh(): Not ready!");
191 synfigapp::Action::ParamList param_list;
192 param_list.add("time",get_canvas_interface()->get_time());
193 param_list.add("canvas",get_canvas_interface()->get_canvas());
194 param_list.add("canvas_interface",get_canvas_interface());
195 if(keyframe_tree_->get_selection()->count_selected_rows()==1)
197 Keyframe keyframe((*keyframe_tree_->get_selection()->get_selected())[model.keyframe]);
198 param_list.add("keyframe",keyframe);
201 handle<studio::Instance>::cast_static(
202 get_canvas_interface()->get_instance()
203 )->add_actions_to_group(
207 synfigapp::Action::CATEGORY_KEYFRAME
210 if(action_group_->get_action("action-keyframe_add"))
212 action_group_->remove(action_group_->get_action("action-keyframe_add"));
215 action_group_->add(Gtk::Action::create(
216 "action-keyframe_add",
217 Gtk::StockID("gtk-add"),
218 _("Add new Keyframe"),_("Add new Keyframe")
220 sigc::mem_fun(*this,&KeyframeActionManager::on_add_keyframe)
225 canvas_interface_->get_canvas()->keyframe_list().find(canvas_interface_->get_time());
226 action_group_->get_action("action-keyframe_add")->set_sensitive(false);
227 if(action_group_->get_action("action-keyframe_duplicate"))
228 action_group_->get_action("action-keyframe_duplicate")->set_sensitive(false);
235 Glib::RefPtr<Gtk::Action> action(Gtk::Action::create("keyframe-properties", Gtk::StockID("gtk-properties"), _("Keyframe Properties")));
236 action_group_->add(action,sigc::mem_fun(*this,&KeyframeActionManager::on_keyframe_properties));
237 if(keyframe_tree_->get_selection()->count_selected_rows()==0)
238 action->set_sensitive(false);
241 ui_info="<ui><menubar action='menu-main'><menu action='menu-keyframe'>"+ui_info+"</menu></menubar></ui>";
242 popup_id_=get_ui_manager()->add_ui_from_string(ui_info);
243 #ifdef ONE_ACTION_GROUP
245 get_ui_manager()->insert_action_group(action_group_);