1 /* === S Y N F I G ========================================================= */
2 /*! \file metadatatreestore.cpp
3 ** \brief Template File
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 "metadatatreestore.h"
33 #include <synfigapp/canvasinterface.h>
37 /* === U S I N G =========================================================== */
41 using namespace synfig;
42 using namespace studio;
44 /* === M A C R O S ========================================================= */
46 /* === G L O B A L S ======================================================= */
48 /* === P R O C E D U R E S ================================================= */
50 /* === M E T H O D S ======================================================= */
52 static MetaDataTreeStore::Model& ModelHack()
54 static MetaDataTreeStore::Model* model(0);
55 if(!model)model=new MetaDataTreeStore::Model;
59 MetaDataTreeStore::MetaDataTreeStore(etl::loose_handle<synfigapp::CanvasInterface> canvas_interface_):
60 Gtk::TreeStore (ModelHack()),
61 canvas_interface_ (canvas_interface_)
64 get_canvas()->signal_meta_data_changed().connect(sigc::mem_fun(*this,&MetaDataTreeStore::meta_data_changed));
69 MetaDataTreeStore::~MetaDataTreeStore()
71 synfig::info("MetaDataTreeStore::~MetaDataTreeStore(): Deleted");
75 Glib::RefPtr<MetaDataTreeStore>
76 MetaDataTreeStore::create(etl::loose_handle<synfigapp::CanvasInterface> canvas_interface_)
78 return Glib::RefPtr<MetaDataTreeStore>(new MetaDataTreeStore(canvas_interface_));
82 MetaDataTreeStore::meta_data_changed(synfig::String /*key*/)
88 MetaDataTreeStore::rebuild()
92 std::list<String> keys(get_canvas()->get_meta_data_keys());
94 for(;!keys.empty();keys.pop_front())
96 Gtk::TreeRow row(*append());
97 row[model.key]=keys.front();
102 MetaDataTreeStore::get_value_vfunc (const Gtk::TreeModel::iterator& iter, int column, Glib::ValueBase& value)const
104 if(column>=get_n_columns_vfunc())
106 g_warning("KeyframeTreeStore::set_value_impl: Bad column (%d)",column);
110 if(column==model.data.index())
112 synfig::String key((Glib::ustring)(*iter)[model.key]);
113 g_value_init(value.gobj(),G_TYPE_STRING);
114 g_value_set_string(value.gobj(),get_canvas()->get_meta_data(key).c_str());
118 Gtk::TreeStore::get_value_vfunc(iter,column,value);
122 MetaDataTreeStore::set_value_impl(const Gtk::TreeModel::iterator& iter, int column, const Glib::ValueBase& value)
124 if(column>=get_n_columns_vfunc())
126 g_warning("KeyframeTreeStore::set_value_impl: Bad column (%d)",column);
130 if(!g_value_type_compatible(G_VALUE_TYPE(value.gobj()),get_column_type_vfunc(column)))
132 g_warning("KeyframeTreeStore::set_value_impl: Bad value type");
136 if(column==model.data.index())
138 Glib::Value<Glib::ustring> x;
139 g_value_init(x.gobj(),model.data.type());
140 g_value_copy(value.gobj(),x.gobj());
142 synfig::String key((Glib::ustring)(*iter)[model.key]);
143 synfig::String new_data(x.get());
145 get_canvas_interface()->set_meta_data(key,new_data);
148 Gtk::TreeStore::set_value_impl(iter,column, value);