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>
39 /* === U S I N G =========================================================== */
43 using namespace synfig;
44 using namespace studio;
46 /* === M A C R O S ========================================================= */
48 /* === G L O B A L S ======================================================= */
50 /* === P R O C E D U R E S ================================================= */
52 /* === M E T H O D S ======================================================= */
54 static MetaDataTreeStore::Model& ModelHack()
56 static MetaDataTreeStore::Model* model(0);
57 if(!model)model=new MetaDataTreeStore::Model;
61 MetaDataTreeStore::MetaDataTreeStore(etl::loose_handle<synfigapp::CanvasInterface> canvas_interface_):
62 Gtk::TreeStore (ModelHack()),
63 canvas_interface_ (canvas_interface_)
66 get_canvas()->signal_meta_data_changed().connect(sigc::mem_fun(*this,&MetaDataTreeStore::meta_data_changed));
71 MetaDataTreeStore::~MetaDataTreeStore()
73 if (getenv("SYNFIG_DEBUG_DESTRUCTORS"))
74 synfig::info("MetaDataTreeStore::~MetaDataTreeStore(): Deleted");
77 Glib::RefPtr<MetaDataTreeStore>
78 MetaDataTreeStore::create(etl::loose_handle<synfigapp::CanvasInterface> canvas_interface_)
80 return Glib::RefPtr<MetaDataTreeStore>(new MetaDataTreeStore(canvas_interface_));
84 MetaDataTreeStore::meta_data_changed(synfig::String /*key*/)
90 MetaDataTreeStore::rebuild()
94 std::list<String> keys(get_canvas()->get_meta_data_keys());
96 for(;!keys.empty();keys.pop_front())
98 Gtk::TreeRow row(*append());
99 row[model.key]=keys.front();
104 MetaDataTreeStore::get_value_vfunc (const Gtk::TreeModel::iterator& iter, int column, Glib::ValueBase& value)const
106 if(column>=get_n_columns_vfunc())
108 g_warning("KeyframeTreeStore::set_value_impl: Bad column (%d)",column);
112 if(column==model.data.index())
114 synfig::String key((Glib::ustring)(*iter)[model.key]);
115 g_value_init(value.gobj(),G_TYPE_STRING);
116 g_value_set_string(value.gobj(),get_canvas()->get_meta_data(key).c_str());
120 Gtk::TreeStore::get_value_vfunc(iter,column,value);
124 MetaDataTreeStore::set_value_impl(const Gtk::TreeModel::iterator& iter, int column, const Glib::ValueBase& value)
126 if(column>=get_n_columns_vfunc())
128 g_warning("KeyframeTreeStore::set_value_impl: Bad column (%d)",column);
132 if(!g_value_type_compatible(G_VALUE_TYPE(value.gobj()),get_column_type_vfunc(column)))
134 g_warning("KeyframeTreeStore::set_value_impl: Bad value type");
138 if(column==model.data.index())
140 Glib::Value<Glib::ustring> x;
141 g_value_init(x.gobj(),model.data.type());
142 g_value_copy(value.gobj(),x.gobj());
144 synfig::String key((Glib::ustring)(*iter)[model.key]);
145 synfig::String new_data(x.get());
147 get_canvas_interface()->set_meta_data(key,new_data);
150 Gtk::TreeStore::set_value_impl(iter,column, value);