[dconf-editor] Use PropertyRow for editable properties also.
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf-editor] Use PropertyRow for editable properties also.
- Date: Sat, 7 May 2016 11:50:44 +0000 (UTC)
commit 1854c6edefa599e42bd89946fc46cc32cf0b5a9a
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Fri May 6 16:29:34 2016 +0200
Use PropertyRow for editable properties also.
editor/dconf-view.vala | 89 +++++++++++++++++++++++++++-------------
editor/key-editor-no-schema.ui | 20 +--------
editor/key-editor.ui | 47 ++-------------------
editor/property-row.ui | 16 +-------
4 files changed, 67 insertions(+), 105 deletions(-)
---
diff --git a/editor/dconf-view.vala b/editor/dconf-view.vala
index 8f99b2e..c2fb512 100644
--- a/editor/dconf-view.vala
+++ b/editor/dconf-view.vala
@@ -20,8 +20,10 @@ using Gtk;
[GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/property-row.ui")]
private class PropertyRow : ListBoxRow
{
+ bool locked = false;
+
+ [GtkChild] private Grid grid;
[GtkChild] private Label name_label;
- [GtkChild] private Label value_label;
public string label { get; construct; }
@@ -30,9 +32,54 @@ private class PropertyRow : ListBoxRow
name_label.set_text (label);
}
- public void set_text (string text) /* TODO all properties cannot be edited after construction */
+ public void set_text (string text)
+ requires (locked == false) /* TODO some properties can be edited after construction */
{
- value_label.set_text (text);
+ Label value_label = new Label (text);
+ value_label.valign = Align.START;
+ value_label.xalign = 0;
+ value_label.yalign = 0;
+ value_label.wrap = true;
+ value_label.selectable = true;
+ value_label.max_width_chars = 42;
+ value_label.width_chars = 42;
+ value_label.show ();
+ grid.attach (value_label, 1, 0, 1, 1);
+
+ locked = true;
+ }
+
+ public void set_widget (Widget widget, Widget? warning)
+ requires (locked == false)
+ {
+ grid.attach (widget, 1, 0, 1, 1);
+ widget.valign = Align.CENTER;
+
+ if (warning != null)
+ {
+ grid.row_spacing = 4;
+ grid.attach ((!) warning, 0, 1, 2, 1);
+ warning.hexpand = true;
+ warning.halign = Align.CENTER;
+ }
+
+ locked = true;
+ }
+
+ public Switch set_switch ()
+ requires (locked == false)
+ {
+ Switch custom_value_switch = new Switch ();
+ custom_value_switch.width_request = 100; /* same request than for button_cancel/button_apply on
scale 1; TODO better */
+ custom_value_switch.halign = Align.END;
+ custom_value_switch.hexpand = true;
+ custom_value_switch.valign = Align.CENTER;
+ custom_value_switch.show ();
+ grid.attach (custom_value_switch, 1, 0, 1, 1);
+
+ locked = true;
+
+ return custom_value_switch;
}
}
@@ -223,9 +270,8 @@ private abstract class KeyEditorDialog : Dialog
private class KeyEditorNoSchema : KeyEditorDialog // TODO add type information, or integrate type
information in KeyEditorChilds; doesn't have a "Custom value" text
{
[GtkChild] private Button button_apply;
- [GtkChild] private Grid grid;
-
[GtkChild] private PropertyRow type_row;
+ [GtkChild] private PropertyRow value_row;
private DConfKey key;
@@ -238,17 +284,7 @@ private class KeyEditorNoSchema : KeyEditorDialog // TODO add type informa
if (this.use_header_bar == 1) // TODO else..?
((HeaderBar) this.get_header_bar ()).subtitle = ((!) key.parent).full_name; // TODO
get_header_bar() is [transfer none]
- Widget _key_editor_child = create_child ((Key) _key);
- grid.attach (_key_editor_child, 1, 0, 1, 1);
- _key_editor_child.valign = Align.CENTER;
-
- Widget? warning = add_warning ((Key) _key);
- if (warning != null)
- {
- grid.attach ((!) warning, 0, 1, 2, 1);
- warning.hexpand = true;
- warning.halign = Align.CENTER;
- }
+ value_row.set_widget (create_child ((Key) _key), add_warning ((Key) _key));
type_row.set_text (key_to_description ());
@@ -267,15 +303,15 @@ private class KeyEditorNoSchema : KeyEditorDialog // TODO add type informa
private class KeyEditor : KeyEditorDialog
{
[GtkChild] private Button button_apply;
- [GtkChild] private Grid grid;
-
[GtkChild] private PropertyRow schema_row;
[GtkChild] private PropertyRow summary_row;
[GtkChild] private PropertyRow description_row;
[GtkChild] private PropertyRow type_row;
[GtkChild] private PropertyRow default_row;
+ [GtkChild] private PropertyRow custom_value_row;
+ [GtkChild] private PropertyRow value_row;
- [GtkChild] private Switch custom_value_switch;
+ private Switch custom_value_switch;
protected GSettingsKey key;
@@ -288,18 +324,13 @@ private class KeyEditor : KeyEditorDialog
if (this.use_header_bar == 1) // TODO else..?
((HeaderBar) this.get_header_bar ()).subtitle = ((!) key.parent).full_name; // TODO
get_header_bar() is [transfer none]
+ // actions
+
Widget _key_editor_child = create_child ((Key) key);
- grid.attach (_key_editor_child, 1, 0, 1, 1);
- _key_editor_child.valign = Align.CENTER;
- custom_value_switch.bind_property ("active", _key_editor_child, "sensitive",
BindingFlags.SYNC_CREATE | BindingFlags.INVERT_BOOLEAN);
+ value_row.set_widget (_key_editor_child, add_warning ((Key) _key));
- Widget? warning = add_warning ((Key) _key);
- if (warning != null)
- {
- grid.attach ((!) warning, 0, 1, 2, 1);
- warning.hexpand = true;
- warning.halign = Align.CENTER;
- }
+ custom_value_switch = custom_value_row.set_switch ();
+ custom_value_switch.bind_property ("active", _key_editor_child, "sensitive",
BindingFlags.SYNC_CREATE | BindingFlags.INVERT_BOOLEAN);
// infos
diff --git a/editor/key-editor-no-schema.ui b/editor/key-editor-no-schema.ui
index 306a872..73b824c 100644
--- a/editor/key-editor-no-schema.ui
+++ b/editor/key-editor-no-schema.ui
@@ -63,25 +63,9 @@
</object>
</child><!-- TODO report bug; doesn't warn if </child><child> is removed -->
<child>
- <object class="GtkListBoxRow">
+ <object class="PropertyRow" id="value_row">
<property name="visible">True</property>
- <property name="can-focus">False</property>
- <child>
- <object class="GtkGrid" id="grid">
- <property name="visible">True</property>
- <property name="orientation">horizontal</property>
- <property name="row-spacing">6</property>
- <child>
- <object class="GtkLabel">
- <property name="visible">True</property>
- <property name="valign">center</property>
- <property name="vexpand">true</property>
- <property name="xalign">1</property>
- <property name="label" translatable="yes">Custom value</property>
- </object>
- </child>
- </object>
- </child>
+ <property name="label" translatable="yes">Custom value</property>
</object>
</child>
</object>
diff --git a/editor/key-editor.ui b/editor/key-editor.ui
index 10a3805..399364a 100644
--- a/editor/key-editor.ui
+++ b/editor/key-editor.ui
@@ -67,54 +67,15 @@
</object>
</child>
<child>
- <object class="GtkListBoxRow">
+ <object class="PropertyRow" id="custom_value_row">
<property name="visible">True</property>
- <property name="can-focus">False</property>
- <child>
- <object class="GtkGrid">
- <property name="visible">True</property>
- <property name="orientation">horizontal</property>
- <child>
- <object class="GtkLabel">
- <property name="visible">True</property>
- <property name="valign">center</property>
- <property name="vexpand">true</property>
- <property name="xalign">1</property>
- <property name="label" translatable="yes">Use default value</property>
- </object>
- </child>
- <child>
- <object class="GtkSwitch" id="custom_value_switch">
- <property name="visible">True</property>
- <property name="width-request">100</property><!-- same request than for
button_cancel/button_apply -->
- <property name="halign">end</property>
- <property name="hexpand">True</property>
- <property name="valign">center</property>
- </object>
- </child>
- </object>
- </child>
+ <property name="label" translatable="yes">Use default value</property>
</object>
</child>
<child>
- <object class="GtkListBoxRow">
+ <object class="PropertyRow" id="value_row">
<property name="visible">True</property>
- <property name="can-focus">False</property>
- <child>
- <object class="GtkGrid" id="grid">
- <property name="visible">True</property>
- <property name="orientation">horizontal</property>
- <child>
- <object class="GtkLabel">
- <property name="visible">True</property>
- <property name="valign">center</property>
- <property name="vexpand">true</property>
- <property name="xalign">1</property>
- <property name="label" translatable="yes">Custom value</property>
- </object>
- </child>
- </object>
- </child>
+ <property name="label" translatable="yes">Custom value</property>
</object>
</child>
</object>
diff --git a/editor/property-row.ui b/editor/property-row.ui
index 5be3285..3bc71a2 100644
--- a/editor/property-row.ui
+++ b/editor/property-row.ui
@@ -4,7 +4,7 @@
<template class="PropertyRow" parent="GtkListBoxRow">
<property name="can-focus">False</property>
<child>
- <object class="GtkGrid">
+ <object class="GtkGrid" id="grid">
<property name="visible">True</property>
<property name="orientation">horizontal</property>
<child>
@@ -16,20 +16,6 @@
<property name="yalign">0</property>
</object>
</child>
- <child>
- <object class="GtkLabel" id="value_label">
- <property name="visible">True</property>
- <property name="valign">start</property>
- <property name="vexpand">true</property>
- <property name="xalign">0</property>
- <property name="yalign">0</property>
- <property name="wrap">True</property>
- <property name="selectable">True</property>
- <property name="can-focus">False</property>
- <property name="max-width-chars">42</property>
- <property name="width-chars">42</property>
- </object>
- </child>
</object>
</child>
</template>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]