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
9 ** Copyright (c) 2008 Chris Moore
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.
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.
22 /* ========================================================================= */
24 /* === H E A D E R S ======================================================= */
33 #include "metadatatreestore.h"
34 #include <synfigapp/canvasinterface.h>
40 /* === U S I N G =========================================================== */
44 using namespace synfig;
45 using namespace studio;
47 /* === M A C R O S ========================================================= */
49 /* === G L O B A L S ======================================================= */
51 /* === P R O C E D U R E S ================================================= */
53 /* === M E T H O D S ======================================================= */
55 static MetaDataTreeStore::Model& ModelHack()
57 static MetaDataTreeStore::Model* model(0);
58 if(!model)model=new MetaDataTreeStore::Model;
62 MetaDataTreeStore::MetaDataTreeStore(etl::loose_handle<synfigapp::CanvasInterface> canvas_interface_):
63 Gtk::TreeStore (ModelHack()),
64 canvas_interface_ (canvas_interface_)
67 get_canvas()->signal_meta_data_changed().connect(sigc::mem_fun(*this,&MetaDataTreeStore::meta_data_changed));
72 MetaDataTreeStore::~MetaDataTreeStore()
74 if (getenv("SYNFIG_DEBUG_DESTRUCTORS"))
75 synfig::info("MetaDataTreeStore::~MetaDataTreeStore(): Deleted");
78 Glib::RefPtr<MetaDataTreeStore>
79 MetaDataTreeStore::create(etl::loose_handle<synfigapp::CanvasInterface> canvas_interface_)
81 return Glib::RefPtr<MetaDataTreeStore>(new MetaDataTreeStore(canvas_interface_));
85 MetaDataTreeStore::meta_data_changed(synfig::String /*key*/)
91 MetaDataTreeStore::rebuild()
95 std::list<String> keys(get_canvas()->get_meta_data_keys());
97 for(;!keys.empty();keys.pop_front())
99 Gtk::TreeRow row(*append());
100 row[model.key]=keys.front();
105 MetaDataTreeStore::get_value_vfunc (const Gtk::TreeModel::iterator& iter, int column, Glib::ValueBase& value)const
107 if(column>=get_n_columns_vfunc())
109 g_warning("KeyframeTreeStore::set_value_impl: Bad column (%d)",column);
113 if(column==model.data.index())
115 synfig::String key((Glib::ustring)(*iter)[model.key]);
116 g_value_init(value.gobj(),G_TYPE_STRING);
117 g_value_set_string(value.gobj(),get_canvas()->get_meta_data(key).c_str());
121 Gtk::TreeStore::get_value_vfunc(iter,column,value);
125 MetaDataTreeStore::set_value_impl(const Gtk::TreeModel::iterator& iter, int column, const Glib::ValueBase& value)
127 if(column>=get_n_columns_vfunc())
129 g_warning("KeyframeTreeStore::set_value_impl: Bad column (%d)",column);
133 if(!g_value_type_compatible(G_VALUE_TYPE(value.gobj()),get_column_type_vfunc(column)))
135 g_warning("KeyframeTreeStore::set_value_impl: Bad value type");
139 if(column==model.data.index())
141 Glib::Value<Glib::ustring> x;
142 g_value_init(x.gobj(),model.data.type());
143 g_value_copy(value.gobj(),x.gobj());
145 synfig::String key((Glib::ustring)(*iter)[model.key]);
146 synfig::String new_data(x.get());
148 get_canvas_interface()->set_meta_data(key,new_data);
151 Gtk::TreeStore::set_value_impl(iter,column, value);