my log
[synfig.git] / synfig-studio / trunk / src / gtkmm / dock_layergroups.cpp
1 /* === S Y N F I G ========================================================= */
2 /*!     \file dock_layergroups.cpp
3 **      \brief Template File
4 **
5 **      $Id: dock_layergroups.cpp,v 1.1.1.1 2005/01/07 03:34:36 darco Exp $
6 **
7 **      \legal
8 **      Copyright (c) 2002 Robert B. Quattlebaum Jr.
9 **
10 **      This software and associated documentation
11 **      are CONFIDENTIAL and PROPRIETARY property of
12 **      the above-mentioned copyright holder.
13 **
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.
18 **      \endlegal
19 */
20 /* ========================================================================= */
21
22 /* === H E A D E R S ======================================================= */
23
24 #ifdef USING_PCH
25 #       include "pch.h"
26 #else
27 #ifdef HAVE_CONFIG_H
28 #       include <config.h>
29 #endif
30
31 #include "dock_layergroups.h"
32 #include "app.h"
33
34 #include <gtkmm/scrolledwindow.h>
35 #include <cassert>
36 #include "instance.h"
37 #include <sigc++/signal.h>
38 #include <sigc++/hide.h>
39 #include <sigc++/retype_return.h>
40 #include <sigc++/slot.h>
41 #include "canvasview.h"
42
43 #include "layergrouptreestore.h"
44 #include "layergrouptree.h"
45 #include "groupactionmanager.h"
46
47 #endif
48
49 /* === U S I N G =========================================================== */
50
51 using namespace std;
52 using namespace etl;
53 using namespace synfig;
54 using namespace studio;
55
56 /* === M A C R O S ========================================================= */
57
58 /* === G L O B A L S ======================================================= */
59
60 /* === P R O C E D U R E S ================================================= */
61
62 /* === M E T H O D S ======================================================= */
63
64 Dock_LayerGroups::Dock_LayerGroups():
65         Dock_CanvasSpecific("groups",_("Groups"),Gtk::StockID("synfig-group")),
66         action_group_group_ops(Gtk::ActionGroup::create()),
67         group_action_manager(new GroupActionManager)
68 {       
69         group_action_manager->set_ui_manager(App::ui_manager());
70
71         action_group_group_ops->add( Gtk::Action::create("toolbar-groups", "Group Ops") );
72
73         action_group_add=Gtk::Action::create("action-group_add", Gtk::Stock::ADD,_("Add a New Group"),_("Add a New Group"));
74         action_group_group_ops->add(action_group_add);
75         action_group_add->set_sensitive(false);
76         
77         App::ui_manager()->insert_action_group(action_group_group_ops);
78
79     Glib::ustring ui_info =
80         "<ui>"
81         "       <toolbar action='toolbar-groups'>"
82         "       <toolitem action='action-group_remove' />"
83         "       <toolitem action='action-group_add' />"
84         "       </toolbar>"
85         "</ui>"
86         ;
87
88         App::ui_manager()->add_ui_from_string(ui_info);
89
90         set_toolbar(*dynamic_cast<Gtk::Toolbar*>(App::ui_manager()->get_widget("/toolbar-groups")));    
91 }
92
93 Dock_LayerGroups::~Dock_LayerGroups()
94 {
95         delete group_action_manager;
96 }
97
98 void
99 Dock_LayerGroups::init_canvas_view_vfunc(etl::loose_handle<CanvasView> canvas_view)
100 {
101         Glib::RefPtr<LayerGroupTreeStore> layer_group_tree_store;
102         layer_group_tree_store=LayerGroupTreeStore::create(canvas_view->canvas_interface());
103
104         LayerGroupTree* layer_group_tree(new LayerGroupTree());
105         layer_group_tree->set_model(layer_group_tree_store);
106         layer_group_tree->signal_popup_layer_menu().connect(sigc::mem_fun(*canvas_view,&CanvasView::popup_layer_menu));
107
108         canvas_view->set_tree_model(get_name(),layer_group_tree_store);
109         canvas_view->set_ext_widget(get_name(),layer_group_tree);
110 }
111
112 void
113 Dock_LayerGroups::changed_canvas_view_vfunc(etl::loose_handle<CanvasView> canvas_view)
114 {
115         if(canvas_view)
116         {
117                 Gtk::Widget* tree_view(canvas_view->get_ext_widget(get_name()));
118         
119                 add(*tree_view);
120                 tree_view->show();
121                 
122                 group_action_manager->set_group_tree(dynamic_cast<LayerGroupTree*>(tree_view));
123                 group_action_manager->set_canvas_interface(canvas_view->canvas_interface());
124                 group_action_manager->refresh();
125         }
126         else
127         {
128                 clear_previous();               
129                 group_action_manager->clear();
130                 group_action_manager->set_canvas_interface(0);
131                 group_action_manager->set_group_tree(0);
132         }
133 }