[dconf-editor] Rework a bit the handle-type thing.



commit be77980914ca4b3886c04fc2fd7a19e41fe7b8f0
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date:   Thu Jan 3 12:20:57 2019 +0100

    Rework a bit the handle-type thing.

 editor/key-editor-child.vala | 45 +++++++++++++++++++++++---------------------
 editor/registry-info.vala    | 40 ++++++++++++++++++++-------------------
 2 files changed, 45 insertions(+), 40 deletions(-)
---
diff --git a/editor/key-editor-child.vala b/editor/key-editor-child.vala
index c45a817..a6e5f47 100644
--- a/editor/key-editor-child.vala
+++ b/editor/key-editor-child.vala
@@ -574,6 +574,9 @@ private class KeyEditorChildNumberInt : SpinButton, KeyEditorChild
         double min_double, max_double;
         if (range_content_or_null != null)
         {
+            if (type_string == "h")
+                assert_not_reached ();
+
             Variant min_variant = ((!) range_content_or_null).get_child_value (0);
             Variant max_variant = ((!) range_content_or_null).get_child_value (1);
             min_double = get_variant_as_double (min_variant);
@@ -614,12 +617,12 @@ private class KeyEditorChildNumberInt : SpinButton, KeyEditorChild
     {
         switch (variant_type)
         {
-            case "y": min = (double) uint8.MIN;     max = (double) uint8.MAX;   break;
-            case "n": min = (double) int16.MIN;     max = (double) int16.MAX;   break;
-            case "q": min = (double) uint16.MIN;    max = (double) uint16.MAX;  break;
-            case "i": min = (double) int32.MIN;     max = (double) int32.MAX;   break;
+            case "i": min = (double)  int32.MIN;    max = (double)  int32.MAX;  break;
             case "u": min = (double) uint32.MIN;    max = (double) uint32.MAX;  break;
-            case "h": min = (double) int32.MIN;     max = (double) int32.MAX;   break;
+            case "n": min = (double)  int16.MIN;    max = (double)  int16.MAX;  break;
+            case "q": min = (double) uint16.MIN;    max = (double) uint16.MAX;  break;
+            case "y": min = (double) uint8.MIN;     max = (double) uint8.MAX;   break;
+            case "h": min = (double)  int32.MIN;    max = (double)  int32.MAX;  break;
             default: assert_not_reached ();
         }
     }
@@ -627,12 +630,12 @@ private class KeyEditorChildNumberInt : SpinButton, KeyEditorChild
     {
         switch (variant_type)
         {
-            case "y": min = (int64) uint8.MIN;      max = (int64) uint8.MAX;    break;
-            case "n": min = (int64) int16.MIN;      max = (int64) int16.MAX;    break;
-            case "q": min = (int64) uint16.MIN;     max = (int64) uint16.MAX;   break;
-            case "i": min = (int64) int32.MIN;      max = (int64) int32.MAX;    break;
+            case "i": min = (int64)  int32.MIN;     max = (int64)  int32.MAX;   break;
             case "u": min = (int64) uint32.MIN;     max = (int64) uint32.MAX;   break;
-            case "h": min = (int64) int32.MIN;      max = (int64) int32.MAX;    break;
+            case "n": min = (int64)  int16.MIN;     max = (int64)  int16.MAX;   break;
+            case "q": min = (int64) uint16.MIN;     max = (int64) uint16.MAX;   break;
+            case "y": min = (int64) uint8.MIN;      max = (int64) uint8.MAX;    break;
+            case "h": min = (int64)  int32.MIN;     max = (int64)  int32.MAX;   break;
             default: assert_not_reached ();
         }
     }
@@ -641,11 +644,11 @@ private class KeyEditorChildNumberInt : SpinButton, KeyEditorChild
     {
         switch (variant.classify ())
         {
-            case Variant.Class.BYTE:    return (double) variant.get_byte ();
-            case Variant.Class.INT16:   return (double) variant.get_int16 ();
-            case Variant.Class.UINT16:  return (double) variant.get_uint16 ();
             case Variant.Class.INT32:   return (double) variant.get_int32 ();
             case Variant.Class.UINT32:  return (double) variant.get_uint32 ();
+            case Variant.Class.INT16:   return (double) variant.get_int16 ();
+            case Variant.Class.UINT16:  return (double) variant.get_uint16 ();
+            case Variant.Class.BYTE:    return (double) variant.get_byte ();
             case Variant.Class.HANDLE:  return (double) variant.get_handle ();
             default: assert_not_reached ();
         }
@@ -654,11 +657,11 @@ private class KeyEditorChildNumberInt : SpinButton, KeyEditorChild
     {
         switch (variant.classify ())
         {
-            case Variant.Class.BYTE:    return (int64) variant.get_byte ();
-            case Variant.Class.INT16:   return (int64) variant.get_int16 ();
-            case Variant.Class.UINT16:  return (int64) variant.get_uint16 ();
             case Variant.Class.INT32:   return (int64) variant.get_int32 ();
             case Variant.Class.UINT32:  return (int64) variant.get_uint32 ();
+            case Variant.Class.INT16:   return (int64) variant.get_int16 ();
+            case Variant.Class.UINT16:  return (int64) variant.get_uint16 ();
+            case Variant.Class.BYTE:    return (int64) variant.get_byte ();
             case Variant.Class.HANDLE:  return (int64) variant.get_handle ();
             default: assert_not_reached ();
         }
@@ -730,12 +733,12 @@ private class KeyEditorChildNumberInt : SpinButton, KeyEditorChild
     {
         switch (key_type)
         {
-            case "y": return new Variant.byte   ((uint8)  int64_value);
-            case "n": return new Variant.int16  ((int16)  int64_value);
-            case "q": return new Variant.uint16 ((uint16) int64_value);
-            case "i": return new Variant.int32  ((int32)  int64_value);
+            case "i": return new Variant.int32  ( (int32) int64_value);
             case "u": return new Variant.uint32 ((uint32) int64_value);
-            case "h": return new Variant.handle ((int32)  int64_value);
+            case "n": return new Variant.int16  ( (int16) int64_value);
+            case "q": return new Variant.uint16 ((uint16) int64_value);
+            case "y": return new Variant.byte   ((uint8)  int64_value);
+            case "h": return new Variant.handle ( (int32) int64_value);
             default: assert_not_reached ();
         }
     }
diff --git a/editor/registry-info.vala b/editor/registry-info.vala
index 3523a2e..c9ce56a 100644
--- a/editor/registry-info.vala
+++ b/editor/registry-info.vala
@@ -305,26 +305,25 @@ private class RegistryInfo : Grid, BrowsableView
         Variant initial_value = modifications_handler.get_key_custom_value (full_name, context_id);
         switch (type_code)
         {
-            case "b":
+            case "b":       // boolean
                 key_editor_child = (KeyEditorChild) new KeyEditorChildBool (initial_value.get_boolean ());   
                       break;
 
-            case "i":   // int32
-            case "u":   // uint32
-            case "n":   // int16
-            case "q":   // uint16
-            case "y":   // uint8
-            case "h":   // handle type
-                if (minimum_is_maximum && type_code != "h")
+            case "i":       // int32
+            case "u":       // uint32
+            case "n":       // int16
+            case "q":       // uint16
+            case "y":       // byte (uint8)
+                if (minimum_is_maximum)
                     key_editor_child = (KeyEditorChild) new KeyEditorChildSingle (initial_value, 
initial_value.print (false));
                 else
                 {
                     Variant? range = null;
-                    if (has_schema && range_type_is_range && !properties.lookup 
(PropertyQuery.RANGE_CONTENT, "v", out range))  // type_string != "h"
+                    if (has_schema && range_type_is_range && !properties.lookup 
(PropertyQuery.RANGE_CONTENT, "v", out range))
                         assert_not_reached ();
                     key_editor_child = (KeyEditorChild) new KeyEditorChildNumberInt (initial_value, 
type_code, range);
                 }                                                                                            
                       break;
 
-            case "d":   // double
+            case "d":       // double
                 if (minimum_is_maximum)
                     key_editor_child = (KeyEditorChild) new KeyEditorChildSingle (initial_value, 
initial_value.print (false));
                 else
@@ -334,7 +333,7 @@ private class RegistryInfo : Grid, BrowsableView
                         assert_not_reached ();
                     key_editor_child = (KeyEditorChild) new KeyEditorChildNumberDouble (initial_value, 
range);
                 }                                                                                            
                       break;
-            case "t":   // uint64
+            case "t":       // uint64
                 if (minimum_is_maximum)
                     key_editor_child = (KeyEditorChild) new KeyEditorChildSingle (initial_value, 
initial_value.print (false));
                 else
@@ -344,7 +343,7 @@ private class RegistryInfo : Grid, BrowsableView
                         assert_not_reached ();
                     key_editor_child = (KeyEditorChild) new KeyEditorChildNumberUint64 (initial_value, 
range);
                 }                                                                                            
                       break;
-            case "x":   // int64
+            case "x":       // int64
                 if (minimum_is_maximum)
                     key_editor_child = (KeyEditorChild) new KeyEditorChildSingle (initial_value, 
initial_value.print (false));
                 else
@@ -355,26 +354,29 @@ private class RegistryInfo : Grid, BrowsableView
                     key_editor_child = (KeyEditorChild) new KeyEditorChildNumberInt64 (initial_value, range);
                 }                                                                                            
                       break;
 
-            case "mb":
+            case "mb":      // nullable boolean
                 key_editor_child = create_child_mb (initial_value, full_name, has_schema, 
modifications_handler);                   break;
-            case "<enum>":  // has_schema
+            case "<enum>":  // enumeration, so has_schema == true
                 Variant range_content;
                 if (!properties.lookup (PropertyQuery.RANGE_CONTENT,    "v",    out range_content))
                     assert_not_reached ();
                 key_editor_child = create_child_enum (range_content, initial_value, full_name, 
modifications_handler);              break;
-            case "<flags>": // has_schema
+            case "<flags>": // flags, so has_schema == true
                 Variant range_content;
                 if (!properties.lookup (PropertyQuery.RANGE_CONTENT,    "v",    out range_content))
                     assert_not_reached ();
                 key_editor_child = create_child_flags (full_name, context_id, range_content, initial_value, 
modifications_handler); break;
 
-            case "()":
+            case "h":       // handle type, no range allowed
+                key_editor_child = (KeyEditorChild) new KeyEditorChildNumberInt (initial_value, type_code, 
/* range */ null);       break;
+
+            case "()":      // empty tuple
                 key_editor_child = (KeyEditorChild) new KeyEditorChildSingle (new Variant ("()", "()"), 
"()");                      break;
 
-            default:
-                if ("a" in type_code)
+            default:        // others
+                if ("a" in type_code)   // if there is an array, the variant string might be quite long, so 
use a textview
                     key_editor_child = (KeyEditorChild) new KeyEditorChildArray (type_code, initial_value);
-                else
+                else                    // else, use a single-line entry
                     key_editor_child = (KeyEditorChild) new KeyEditorChildDefault (type_code, 
initial_value);                       break;
         }
 


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