1 /* === S I N F 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 Robert B. Quattlebaum Jr.
10 ** This software and associated documentation
11 ** are CONFIDENTIAL and PROPRIETARY property of
12 ** the above-mentioned copyright holder.
14 ** You may not copy, print, publish, or in any
15 ** other way distribute this software without
16 ** a prior written agreement with
17 ** the copyright holder.
20 /* ========================================================================= */
22 /* === H E A D E R S ======================================================= */
31 #include "groupactionmanager.h"
32 #include "layergrouptree.h"
33 #include <sinfgapp/action_param.h>
35 #include <gtkmm/stock.h>
39 /* === U S I N G =========================================================== */
43 using namespace sinfg;
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 GroupActionManager::GroupActionManager():
59 action_group_(Gtk::ActionGroup::create()),
60 popup_id_(no_prev_popup),
65 GroupActionManager::~GroupActionManager()
70 GroupActionManager::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 GroupActionManager::set_group_tree(LayerGroupTree* x)
86 selection_changed_connection.disconnect();
90 selection_changed_connection=group_tree_->get_selection()->signal_changed().connect(
91 sigc::mem_fun(*this,&GroupActionManager::queue_refresh)
97 GroupActionManager::set_canvas_interface(const etl::handle<sinfgapp::CanvasInterface> &x)
103 GroupActionManager::clear()
107 // Clear out old stuff
108 if(popup_id_!=no_prev_popup)
110 get_ui_manager()->remove_ui(popup_id_);
111 popup_id_=no_prev_popup;
112 action_group_->set_sensitive(false);
113 #ifdef ONE_ACTION_GROUP
114 while(!action_group_->get_actions().empty())action_group_->remove(*action_group_->get_actions().begin());
115 action_group_->set_sensitive(true);
117 get_ui_manager()->remove_action_group(action_group_);
118 action_group_=Gtk::ActionGroup::create();
125 GroupActionManager::queue_refresh()
130 //queue_refresh_connection.disconnect();
131 queue_refresh_connection=Glib::signal_idle().connect(
133 sigc::mem_fun(*this,&GroupActionManager::refresh),
142 GroupActionManager::refresh()
148 //queue_refresh_connection.disconnect();
154 // Make sure we are ready
155 if(!ui_manager_ || !group_tree_ || !canvas_interface_)
157 sinfg::error("GroupActionManager::refresh(): Not ready!");
161 if(group_tree_->get_selection()->count_selected_rows()==0)
172 _("Add a New Group"),
177 &GroupActionManager::on_action_add
183 // bool multiple_selected(group_tree_->get_selection()->count_selected_rows()>1);
184 LayerGroupTree::LayerList selected_layers(group_tree_->get_selected_layers());
185 std::list<sinfg::String> selected_groups(group_tree_->get_selected_groups());
187 sinfg::info("selected_layers.size()=%d",selected_layers.size());
188 sinfg::info("selected_groups.size()=%d",selected_groups.size());
191 bool canvas_set(false);
192 sinfgapp::Action::ParamList param_list;
193 param_list.add("time",get_canvas_interface()->get_time());
194 param_list.add("canvas_interface",get_canvas_interface());
197 LayerGroupTree::LayerList::iterator iter;
199 for(iter=selected_layers.begin();iter!=selected_layers.end();++iter)
203 param_list.add("canvas",Canvas::Handle(Layer::Handle(*iter)->get_canvas()));
206 param_list.add("layer",Layer::Handle(*iter));
211 std::list<sinfg::String>::iterator iter;
213 for(iter=selected_groups.begin();iter!=selected_groups.end();++iter)
215 param_list.add("group",(sinfg::String)*iter);
221 param_list.add("canvas",Canvas::Handle(get_canvas_interface()->get_canvas()));
225 handle<studio::Instance>::cast_static(get_canvas_interface()->get_instance())->
226 add_actions_to_group(action_group_, ui_info, param_list, sinfgapp::Action::CATEGORY_GROUP);
232 ui_info="<ui><menubar action='menu-main'><menu action='menu-group'>"+ui_info+"</menu></menubar></ui>";
233 popup_id_=get_ui_manager()->add_ui_from_string(ui_info);
237 get_ui_manager()->ensure_update();
240 #ifdef ONE_ACTION_GROUP
242 get_ui_manager()->insert_action_group(action_group_);
247 GroupActionManager::on_action_add()
249 LayerGroupTreeStore::Model model;
253 Gtk::TreeIter selected_iter;
255 if(group_tree_->get_selection()->count_selected_rows())
258 group_tree_->get_model()->get_iter(
259 (*group_tree_->get_selection()->get_selected_rows().begin())
262 if(selected_iter && selected_iter->parent())
263 group_name=(Glib::ustring)(*selected_iter->parent())[model.group_name]+'.';
266 group_name+=_("UnnamedGroup");
268 Gtk::TreePath path(group_tree_->get_model()->on_group_added(group_name));
270 group_tree_->expand_to_path(path);
271 group_tree_->set_cursor(path,true);