[gnome-boxes] i-props-provider: Separate property for editable strings



commit 32576729cc04627c328c34e69c27b964b4f15c5d
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Wed Feb 18 13:46:01 2015 +0000

    i-props-provider: Separate property for editable strings
    
    Lets have a separate property for Editable strings and use simple labels
    for nonmutable string properties.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=720788

 src/i-properties-provider.vala      |   28 +++++++++++++++++++++++-----
 src/libvirt-machine-properties.vala |    5 ++---
 src/remote-machine.vala             |   19 ++++++++++---------
 3 files changed, 35 insertions(+), 17 deletions(-)
---
diff --git a/src/i-properties-provider.vala b/src/i-properties-provider.vala
index a88f597..0a3b1a4 100644
--- a/src/i-properties-provider.vala
+++ b/src/i-properties-provider.vala
@@ -142,12 +142,20 @@ private class Boxes.SizeProperty : Boxes.Property {
 }
 
 private class Boxes.StringProperty : Boxes.Property {
-    public signal bool changed (string value);
+    public string text {
+        get { return (widget as Gtk.Label).label; }
+    }
 
-    public bool editable {
-        get { return entry.editable; }
-        set { entry.editable = value; }
+    public StringProperty (string name, string value) {
+        var label = new Gtk.Label (value);
+        label.halign = Gtk.Align.START;
+
+        base (name, label, null);
     }
+}
+
+private class Boxes.EditableStringProperty : Boxes.Property {
+    public signal bool changed (string value);
 
     public string text {
         get { return entry.text; }
@@ -156,8 +164,9 @@ private class Boxes.StringProperty : Boxes.Property {
 
     private Boxes.EditableEntry entry;
 
-    public StringProperty (string name, string value) {
+    public EditableStringProperty (string name, string value) {
         var entry = new Boxes.EditableEntry ();
+        entry.editable = true;
 
         base (name, entry, null);
         this.entry = entry;
@@ -199,6 +208,15 @@ private interface Boxes.IPropertiesProvider: GLib.Object {
         return property;
     }
 
+    protected Boxes.EditableStringProperty add_editable_string_property (ref List<Boxes.Property> list,
+                                                                         string                   name,
+                                                                         string                   value) {
+        var property = new EditableStringProperty (name, value);
+        list.append (property);
+
+        return property;
+    }
+
     protected Boxes.SizeProperty add_size_property (ref List<Boxes.Property> list,
                                                     string                   name,
                                                     uint64                   size,
diff --git a/src/libvirt-machine-properties.vala b/src/libvirt-machine-properties.vala
index 98fe625..6e6408e 100644
--- a/src/libvirt-machine-properties.vala
+++ b/src/libvirt-machine-properties.vala
@@ -115,8 +115,7 @@ private class Boxes.LibvirtMachineProperties: GLib.Object, Boxes.IPropertiesProv
 
         switch (page) {
         case PropertiesPage.GENERAL:
-            var property = add_string_property (ref list, _("Name"), machine.name);
-            property.editable = true;
+            var property = add_editable_string_property (ref list, _("Name"), machine.name);
             property.changed.connect ((property, name) => {
                 machine.name = name;
 
@@ -134,7 +133,7 @@ private class Boxes.LibvirtMachineProperties: GLib.Object, Boxes.IPropertiesProv
             add_string_property (ref list, _("Broker"), machine.source.name);
             if (machine.display != null) {
                 add_string_property (ref list, _("Protocol"), machine.display.protocol);
-                property = add_string_property (ref list, _("URI"), machine.display.uri);
+                add_string_property (ref list, _("URI"), machine.display.uri);
             }
             break;
 
diff --git a/src/remote-machine.vala b/src/remote-machine.vala
index d2030d7..f28664e 100644
--- a/src/remote-machine.vala
+++ b/src/remote-machine.vala
@@ -52,8 +52,7 @@ private class Boxes.RemoteMachine: Boxes.Machine, Boxes.IPropertiesProvider {
 
         switch (page) {
         case PropertiesPage.GENERAL:
-            var property = add_string_property (ref list, _("Name"), source.name);
-            property.editable = true;
+            var property = add_editable_string_property (ref list, _("Name"), source.name);
             property.changed.connect ((property, name) => {
                 this.name = name;
                 return true;
@@ -65,13 +64,15 @@ private class Boxes.RemoteMachine: Boxes.Machine, Boxes.IPropertiesProvider {
             });
 
             add_string_property (ref list, _("Protocol"), source.source_type.up ());
-            property = add_string_property (ref list, _("URI"), source.uri);
-            if (!is_connected ())
-                property.editable = true;
-            property.changed.connect ((property, uri) => {
-                source.uri = uri;
-                return true;
-            });
+            if (is_connected ()) {
+                add_string_property (ref list, _("URI"), source.uri);
+            } else {
+                property = add_editable_string_property (ref list, _("URI"), source.uri);
+                property.changed.connect ((property, uri) => {
+                    source.uri = uri;
+                    return true;
+               });
+            }
 
             break;
         }


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]