[dconf-editor] Reduce strings duplication.



commit b0f01e1e0c7076214a5d120ffcdccfa5bd61c5fb
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Thu Oct 8 07:02:03 2015 +0200

    Reduce strings duplication.

 editor/dconf-model.vala  |   39 ++++++++++++++++++++++++++++++++++++---
 editor/dconf-view.vala   |    6 +++---
 editor/dconf-window.vala |    4 ++--
 3 files changed, 41 insertions(+), 8 deletions(-)
---
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index 59be07e..73a7350 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -57,11 +57,44 @@ public class Key : SettingObject
     private SettingsModel model;
 
     public string path;
-    public string cool_text_value ()   // TODO better
+    public string cool_text_value ()    // TODO cannot do a property from this because of ownership problem 
with variant.print()
     {
+        return cool_text_value_from_variant (value, type_string);
+    }
+    public static string cool_text_value_from_variant (Variant variant, string type)
+    {
+        if (type == "b")
+            return cool_boolean_text_value (variant.get_boolean (), false);
+        if (type.has_prefix ("m"))
+        {
+            Variant? maybe_variant = variant.get_maybe ();
+            if (maybe_variant == null)
+                return cool_boolean_text_value (null, false);
+            if (type == "mb")
+                return cool_boolean_text_value (maybe_variant.get_boolean (), false);
+        }
         // TODO number of chars after coma for double
-        // bool is the only type that permits translation; keep strings for translators
-        return type_string == "b" ? (value.get_boolean () ? _("True") : _("False")) : value.print (false);
+        return variant.print (false);
+    }
+    public static string cool_boolean_text_value (bool? nullable_boolean, bool capitalized = true)
+    {
+        if (capitalized)
+        {
+            if (nullable_boolean == true)
+                return _("True");
+            if (nullable_boolean == false)
+                return _("False");
+            return _("Nothing");
+        }
+        else
+        {
+            if (nullable_boolean == true)
+                return _("true");
+            if (nullable_boolean == false)
+                return _("false");
+            /* Translators: "nothing" here is a keyword that should appear for consistence; please translate 
as "yourtranslation (nothing)" */
+            return _("nothing");
+        }
     }
 
     public SchemaKey? schema;
diff --git a/editor/dconf-view.vala b/editor/dconf-view.vala
index c679e5e..89d7c0c 100644
--- a/editor/dconf-view.vala
+++ b/editor/dconf-view.vala
@@ -200,7 +200,7 @@ private class KeyEditor : KeyEditorDialog
         summary_label.set_text (summary.strip ());
         description_label.set_text (description.strip ());
         type_label.set_text (key_to_description ());
-        default_label.set_text (key.schema.default_value.print (false));
+        default_label.set_text ((key.schema.type == "b" || key.schema.type == "mb") ? 
Key.cool_text_value_from_variant (key.schema.default_value, key.schema.type) : key.schema.default_value.print 
(false));
 
         // switch
 
@@ -297,12 +297,12 @@ private class KeyEditorChildBool : Grid, KeyEditorChild // might be managed by a
 
         ToggleButton button_false = new ToggleButton ();
         button_false.visible = true;
-        button_false.label = _("False");
+        button_false.label = Key.cool_boolean_text_value (false);
         grid.attach (button_false, 0, 0, 1, 1);
 
         button_true = new ToggleButton ();
         button_true.visible = true;
-        button_true.label = _("True");
+        button_true.label = Key.cool_boolean_text_value (true);
         grid.attach (button_true, 1, 0, 1, 1);
 
         button_true.active = initial_value;
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index 8823a85..eed0acf 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -443,8 +443,8 @@ private class ContextPopover : Popover
 
         if (key.type_string == "b")
         {
-            add_model_button (_("True"), new Variant.maybe (original_type, new Variant.boolean (true)));     
   // TODO string duplication
-            add_model_button (_("False"), new Variant.maybe (original_type, new Variant.boolean (false)));   
   // TODO string duplication
+            add_model_button (Key.cool_boolean_text_value (true), new Variant.maybe (original_type, new 
Variant.boolean (true)));
+            add_model_button (Key.cool_boolean_text_value (false), new Variant.maybe (original_type, new 
Variant.boolean (false)));
         }
         else if (key.type_string == "<enum>")
         {


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