1 /* === S Y N F I G ========================================================= */
3 ** \brief Template File
5 ** $Id: groupactionmanager.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 "groupactionmanager.h"
33 #include "layergrouptree.h"
34 #include <synfigapp/action_param.h>
36 #include <gtkmm/stock.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 GroupActionManager::GroupActionManager():
60 action_group_(Gtk::ActionGroup::create()),
61 popup_id_(no_prev_popup),
66 GroupActionManager::~GroupActionManager()
71 GroupActionManager::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 GroupActionManager::set_group_tree(LayerGroupTree* x)
87 selection_changed_connection.disconnect();
91 selection_changed_connection=group_tree_->get_selection()->signal_changed().connect(
92 sigc::mem_fun(*this,&GroupActionManager::queue_refresh)
98 GroupActionManager::set_canvas_interface(const etl::handle<synfigapp::CanvasInterface> &x)
104 GroupActionManager::clear()
108 // Clear out old stuff
109 if(popup_id_!=no_prev_popup)
111 get_ui_manager()->remove_ui(popup_id_);
112 popup_id_=no_prev_popup;
113 action_group_->set_sensitive(false);
114 #ifdef ONE_ACTION_GROUP
115 while(!action_group_->get_actions().empty())action_group_->remove(*action_group_->get_actions().begin());
116 action_group_->set_sensitive(true);
118 get_ui_manager()->remove_action_group(action_group_);
119 action_group_=Gtk::ActionGroup::create();
126 GroupActionManager::queue_refresh()
131 //queue_refresh_connection.disconnect();
132 queue_refresh_connection=Glib::signal_idle().connect(
134 sigc::mem_fun(*this,&GroupActionManager::refresh),
143 GroupActionManager::refresh()
149 //queue_refresh_connection.disconnect();
155 // Make sure we are ready
156 if(!ui_manager_ || !group_tree_ || !canvas_interface_)
158 synfig::error("GroupActionManager::refresh(): Not ready!");
162 if(group_tree_->get_selection()->count_selected_rows()==0)
173 _("Add a New Group"),
178 &GroupActionManager::on_action_add
184 // bool multiple_selected(group_tree_->get_selection()->count_selected_rows()>1);
185 LayerGroupTree::LayerList selected_layers(group_tree_->get_selected_layers());
186 std::list<synfig::String> selected_groups(group_tree_->get_selected_groups());
188 synfig::info("selected_layers.size()=%d",selected_layers.size());
189 synfig::info("selected_groups.size()=%d",selected_groups.size());
192 bool canvas_set(false);
193 synfigapp::Action::ParamList param_list;
194 param_list.add("time",get_canvas_interface()->get_time());
195 param_list.add("canvas_interface",get_canvas_interface());
198 LayerGroupTree::LayerList::iterator iter;
200 for(iter=selected_layers.begin();iter!=selected_layers.end();++iter)
204 param_list.add("canvas",Canvas::Handle(Layer::Handle(*iter)->get_canvas()));
207 param_list.add("layer",Layer::Handle(*iter));
212 std::list<synfig::String>::iterator iter;
214 for(iter=selected_groups.begin();iter!=selected_groups.end();++iter)
216 param_list.add("group",(synfig::String)*iter);
222 param_list.add("canvas",Canvas::Handle(get_canvas_interface()->get_canvas()));
226 handle<studio::Instance>::cast_static(get_canvas_interface()->get_instance())->
227 add_actions_to_group(action_group_, ui_info, param_list, synfigapp::Action::CATEGORY_GROUP);
233 ui_info="<ui><menubar action='menu-main'><menu action='menu-group'>"+ui_info+"</menu></menubar></ui>";
234 popup_id_=get_ui_manager()->add_ui_from_string(ui_info);
238 get_ui_manager()->ensure_update();
241 #ifdef ONE_ACTION_GROUP
243 get_ui_manager()->insert_action_group(action_group_);
248 GroupActionManager::on_action_add()
250 LayerGroupTreeStore::Model model;
254 Gtk::TreeIter selected_iter;
256 if(group_tree_->get_selection()->count_selected_rows())
259 group_tree_->get_model()->get_iter(
260 (*group_tree_->get_selection()->get_selected_rows().begin())
263 if(selected_iter && selected_iter->parent())
264 group_name=(Glib::ustring)(*selected_iter->parent())[model.group_name]+'.';
267 group_name+=_("UnnamedGroup");
269 Gtk::TreePath path(group_tree_->get_model()->on_group_added(group_name));
271 group_tree_->expand_to_path(path);
272 group_tree_->set_cursor(path,true);