source: synfigstudio/trunk/fuentes/.pc/c++11.patch/src/gui/docks/dock_metadata.cpp @ 481

Last change on this file since 481 was 481, checked in by jrpelegrina, 4 years ago

First release to xenial

File size: 4.8 KB
Line 
1/* === S Y N F I G ========================================================= */
2/*!     \file dock_metadata.cpp
3**      \brief Template File
4**
5**      $Id$
6**
7**      \legal
8**      Copyright (c) 2002-2005 Robert B. Quattlebaum Jr., Adrian Bentley
9**      Copyright (c) 2011 Carlos López
10**
11**      This package is free software; you can redistribute it and/or
12**      modify it under the terms of the GNU General Public License as
13**      published by the Free Software Foundation; either version 2 of
14**      the License, or (at your option) any later version.
15**
16**      This package is distributed in the hope that it will be useful,
17**      but WITHOUT ANY WARRANTY; without even the implied warranty of
18**      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
19**      General Public License for more details.
20**      \endlegal
21*/
22/* ========================================================================= */
23
24/* === H E A D E R S ======================================================= */
25
26#ifdef USING_PCH
27#       include "pch.h"
28#else
29#ifdef HAVE_CONFIG_H
30#       include <config.h>
31#endif
32
33#include "docks/dock_metadata.h"
34#include "app.h"
35
36#include <gtkmm/scrolledwindow.h>
37#include <cassert>
38#include "instance.h"
39#include <sigc++/signal.h>
40#include <sigc++/hide.h>
41#include <sigc++/slot.h>
42#include "trees/metadatatreestore.h"
43#include "trees/metadatatree.h"
44#include "canvasview.h"
45
46#include "general.h"
47
48#endif
49
50/* === U S I N G =========================================================== */
51
52using namespace std;
53using namespace etl;
54using namespace synfig;
55using 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
65Dock_MetaData::Dock_MetaData():
66        Dock_CanvasSpecific("meta_data",_("Canvas MetaData"),Gtk::StockID("synfig-meta_data")),
67        action_group(Gtk::ActionGroup::create("action_group_dock_meta_data"))
68{
69        action_group->add(Gtk::Action::create(
70                "action-MetadataAdd",
71                Gtk::StockID("gtk-add"),
72                _("Add new MetaData entry"),
73                _("Add a new MetaData entry to the canvas")
74        ),
75                sigc::mem_fun(
76                        *this,
77                        &Dock_MetaData::on_add_pressed
78                )
79        );
80
81        action_group->add(Gtk::Action::create(
82                "action-MetadataRemove",
83                Gtk::StockID("gtk-delete"),
84                _("Remove selected MetaData entry"),
85                _("Remove the selected MetaData entry")
86        ),
87                sigc::mem_fun(
88                        *this,
89                        &Dock_MetaData::on_delete_pressed
90                )
91        );
92
93        action_group->add( Gtk::Action::create("toolbar-meta_data", _("Canvas MetaData")) );
94        App::ui_manager()->insert_action_group(action_group);
95
96        Glib::ustring ui_info =
97        "<ui>"
98        "       <toolbar action='toolbar-meta_data'>"
99        "       <toolitem action='action-MetadataAdd' />"
100        "       <toolitem action='action-MetadataRemove' />"
101        "       </toolbar>"
102        "</ui>"
103        ;
104
105        App::ui_manager()->add_ui_from_string(ui_info);
106
107        action_group->set_sensitive(false);
108
109        set_toolbar(*dynamic_cast<Gtk::Toolbar*>(App::ui_manager()->get_widget("/toolbar-meta_data")));
110}
111
112Dock_MetaData::~Dock_MetaData()
113{
114}
115
116void
117Dock_MetaData::init_canvas_view_vfunc(etl::loose_handle<CanvasView> canvas_view)
118{
119        Glib::RefPtr<MetaDataTreeStore> metadata_tree_store;
120        metadata_tree_store=MetaDataTreeStore::create(canvas_view->canvas_interface());
121        MetaDataTree* metadata_tree(new MetaDataTree());
122        metadata_tree->set_model(metadata_tree_store);
123        metadata_tree->set_editable(true);
124        canvas_view->set_tree_model(get_name(),metadata_tree_store);
125        canvas_view->set_ext_widget(get_name(),metadata_tree);
126}
127
128void
129Dock_MetaData::changed_canvas_view_vfunc(etl::loose_handle<CanvasView> canvas_view)
130{
131        if(canvas_view)
132        {
133                Gtk::Widget* tree_view(canvas_view->get_ext_widget(get_name()));
134                add(*tree_view);
135                tree_view->show();
136
137                action_group->set_sensitive(true);
138        }
139        else
140        {
141                clear_previous();
142                action_group->set_sensitive(false);
143        }
144}
145
146void
147Dock_MetaData::on_add_pressed()
148{
149        if(get_canvas_interface())
150        {
151                synfig::String key;
152                if(App::dialog_entry(_("New Metadata entry"), _("Key Name: "), key, _("Cancel"), _("Ok")) && !key.empty())
153                {
154                        get_canvas_interface()->set_meta_data(key," ");
155                }
156        }
157}
158
159void
160Dock_MetaData::on_delete_pressed()
161{
162        Gtk::TreeView* tree_view(static_cast<Gtk::TreeView*>(get_canvas_view()->get_ext_widget(get_name())));
163        if(tree_view)
164        {
165                Gtk::TreeModel::iterator iter(tree_view->get_selection()->get_selected());
166                if(tree_view->get_selection()->count_selected_rows())
167                {
168                        Gtk::TreeRow row(*iter);
169                        Glib::RefPtr<Gtk::TreeModel> treemodel(get_canvas_view()->get_tree_model(get_name()));
170                        Glib::RefPtr<studio::MetaDataTreeStore> meta_data_tree_store(Glib::RefPtr<studio::MetaDataTreeStore>::cast_dynamic(treemodel));
171                        Glib::ustring key(row[meta_data_tree_store->model.key]);
172                        if(get_canvas_interface())
173                                get_canvas_interface()->erase_meta_data(key);
174                }
175        }
176}
Note: See TracBrowser for help on using the repository browser.