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