xmpedit

GTK+ editor for XMP metadata embedded in images
git clone https://code.djc.id.au/git/xmpedit/
commit a3fb9f072154d34d25fd4337274a09d5123dd2d5
parent 8ae5e0ba7547a9f051b407de34ef6f4c1d7a003a
Author: Dan Callaghan <djc@djc.id.au>
Date:   Mon, 23 Aug 2010 19:39:38 +1000

custom CellRenderer for properties TreeView, to avoid having an extra column

Diffstat:
Msrc/ImageMetadata.vala | 20++++++--------------
Msrc/MetadataTreeView.vala | 19+++++++++++++++++--
Msrc/PropertyDetailView.vala | 2+-
3 files changed, 24 insertions(+), 17 deletions(-)
diff --git a/src/ImageMetadata.vala b/src/ImageMetadata.vala
@@ -208,15 +208,13 @@ public class ImageMetadata : Object, Gtk.TreeModel {
     
     /****** TREEMODEL IMPLEMENTATION STUFF **********/
     
-    // XXX use custom cellrenderer instead of having a string column
-    
     public Type get_column_type(int column) {
-        return_if_fail(column == 0 || column == 1);
-        return column == 0 ? typeof(string) : typeof(PropertyEditor);
+        return_if_fail(column == 0);
+        return typeof(PropertyEditor);
     }
     
     public int get_n_columns() {
-        return 2;
+        return 1;
     }
     
     public Gtk.TreeModelFlags get_flags() {
@@ -239,15 +237,9 @@ public class ImageMetadata : Object, Gtk.TreeModel {
     
     public void get_value(Gtk.TreeIter iter, int column, out Value value) {
         return_if_fail(iter.stamp == stamp);
-        return_if_fail(column == 0 || column == 1);
-        var pe = (PropertyEditor) iter.user_data;
-        if (column == 0) {
-            value = Value(typeof(string));
-            value.take_string(pe.list_markup()); // XXX
-        } else {
-            value = Value(typeof(PropertyEditor));
-            value.set_object(pe);
-        }
+        return_if_fail(column == 0);
+        value = Value(typeof(PropertyEditor));
+        value.set_object((PropertyEditor) iter.user_data);
     }
     
     public bool iter_children(out Gtk.TreeIter iter, Gtk.TreeIter? parent) {
diff --git a/src/MetadataTreeView.vala b/src/MetadataTreeView.vala
@@ -1,6 +1,21 @@
 
 namespace Xmpedit {
 
+private class PropertySummaryCellRenderer : Gtk.CellRendererText {
+
+    private PropertyEditor _property_editor;
+    public PropertyEditor property_editor {
+        get {
+            return _property_editor;
+        }
+        set {
+            _property_editor = value;
+            markup = value.list_markup();
+        }
+    }
+
+}
+
 public class MetadataTreeView : Gtk.TreeView {
 
     public MetadataTreeView.connected_to(ImageMetadata metadata) {
@@ -12,9 +27,9 @@ public class MetadataTreeView : Gtk.TreeView {
         column.title = "Image properties";
         column.sizing = Gtk.TreeViewColumnSizing.FIXED;
         column.fixed_width = 300;
-        Gtk.CellRendererText cell_renderer = new Gtk.CellRendererText();
+        var cell_renderer = new PropertySummaryCellRenderer();
         column.pack_start(cell_renderer, /* expand */ true);
-        column.add_attribute(cell_renderer, "markup", 0);
+        column.add_attribute(cell_renderer, "property_editor", 0);
         append_column(column);
         get_selection().set_mode(Gtk.SelectionMode.BROWSE);
     }
diff --git a/src/PropertyDetailView.vala b/src/PropertyDetailView.vala
@@ -15,7 +15,7 @@ public class PropertyDetailView : Gtk.Alignment {
             Gtk.TreeIter iter;
             tree_view.get_selection().get_selected(null, out iter);
             Value value;
-            tree_view.model.get_value(iter, 1, out value);
+            tree_view.model.get_value(iter, 0, out value);
             PropertyEditor pe = (PropertyEditor) value.get_object();
             if (child != null) {
                 ((PropertyEditor) child).commit();