[dconf-editor] Permit to edit keys without schemas or with relocatable ones.
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf-editor] Permit to edit keys without schemas or with relocatable ones.
- Date: Thu, 1 Oct 2015 12:06:59 +0000 (UTC)
commit e66336478f52c3b8719fc7692ee694705ef58252
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Thu Oct 1 14:06:43 2015 +0200
Permit to edit keys without schemas or with relocatable ones.
https://bugzilla.gnome.org/show_bug.cgi?id=755925
editor/Makefile.am | 3 +-
editor/dconf-editor.gresource.xml | 1 +
editor/dconf-model.vala | 2 +-
editor/dconf-schema.vala | 6 +-
editor/dconf-view.vala | 74 +++++++++++++++++++++++++++++++++++-
editor/dconf-window.vala | 58 +++++++++++++++++++++++------
po/POTFILES.in | 1 +
7 files changed, 125 insertions(+), 20 deletions(-)
---
diff --git a/editor/Makefile.am b/editor/Makefile.am
index 3b903e0..b982659 100644
--- a/editor/Makefile.am
+++ b/editor/Makefile.am
@@ -25,7 +25,8 @@ resource_data = \
dconf-editor-menu.ui \
dconf-editor.ui \
key-list-box-row.ui \
- key-editor.ui
+ key-editor.ui \
+ key-editor-no-schema.ui
resources.c: $(resource_data)
$(AM_V_GEN) $(GLIB_COMPILE_RESOURCES) --sourcedir=$(srcdir) --target=$@ --generate-source $<
diff --git a/editor/dconf-editor.gresource.xml b/editor/dconf-editor.gresource.xml
index 67da824..174029e 100644
--- a/editor/dconf-editor.gresource.xml
+++ b/editor/dconf-editor.gresource.xml
@@ -4,6 +4,7 @@
<file preprocess="xml-stripblanks">dconf-editor.ui</file>
<file preprocess="xml-stripblanks">key-list-box-row.ui</file>
<file preprocess="xml-stripblanks">key-editor.ui</file>
+ <file preprocess="xml-stripblanks">key-editor-no-schema.ui</file>
</gresource>
<gresource prefix="/ca/desrt/dconf-editor/gtk">
<file preprocess="xml-stripblanks" alias="menus.ui">dconf-editor-menu.ui</file>
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index 3a33414..8b480fd 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -258,7 +258,7 @@ public class SettingsModel: GLib.Object, Gtk.TreeModel
schema.path = settings_schema.get_path (); // TODO will always returns null for relocatable
schemas
foreach (string key_id in settings_schema.list_keys ())
{
- SchemaKey key = new SchemaKey (key_id, settings_schema.get_key (key_id));
+ SchemaKey key = new SchemaKey (schema_id, settings_schema.get_key (key_id));
schema.keys.insert (key.name, key);
keys.insert (schema.path + key.name, key);
}
diff --git a/editor/dconf-schema.vala b/editor/dconf-schema.vala
index b35696f..8f248b1 100644
--- a/editor/dconf-schema.vala
+++ b/editor/dconf-schema.vala
@@ -17,7 +17,7 @@
public class SchemaKey : GLib.Object
{
- public string id;
+ public string schema_id;
public SettingsSchemaKey settings_schema_key;
public string name;
@@ -29,9 +29,9 @@ public class SchemaKey : GLib.Object
public string range_type;
public Variant range_content;
- public SchemaKey (string _id, SettingsSchemaKey _settings_schema_key)
+ public SchemaKey (string _schema_id, SettingsSchemaKey _settings_schema_key)
{
- this.id = _id;
+ this.schema_id = _schema_id;
this.settings_schema_key = _settings_schema_key;
name = settings_schema_key.get_name ();
diff --git a/editor/dconf-view.vala b/editor/dconf-view.vala
index 0ecfd3c..2e73533 100644
--- a/editor/dconf-view.vala
+++ b/editor/dconf-view.vala
@@ -17,18 +17,85 @@
using Gtk;
+[GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/key-editor-no-schema.ui")]
+private class KeyEditorNoSchema : Dialog
+{
+ [GtkChild] private Button button_apply;
+ [GtkChild] private Grid custom_value_grid;
+
+ private Key key;
+ private bool custom_value_is_valid = true;
+
+ public KeyEditorNoSchema (Key _key)
+ requires (!_key.has_schema)
+ {
+ Object (use_header_bar: Gtk.Settings.get_default ().gtk_dialogs_use_header ? 1 : 0);
+
+ this.key = _key;
+
+ // infos
+
+ this.title = key.name;
+ 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]
+
+ // widgets creation
+ custom_value_grid.add (create_child ());
+
+ this.response.connect (response_cb);
+ }
+
+ private KeyEditorChild create_child ()
+ {
+ switch (key.type_string)
+ {
+ case "<enum>":
+ return new KeyEditorChildEnum (key);
+ case "b":
+ return new KeyEditorChildBool (key.value.get_boolean ());
+ case "s":
+ return new KeyEditorChildString (key.value.get_string ());
+ case "y":
+ case "n":
+ case "q":
+ case "i":
+ case "u":
+ case "x":
+ case "t":
+ case "d":
+ return new KeyEditorChildNumber (key);
+ default:
+ KeyEditorChildDefault key_editor_child_default = new KeyEditorChildDefault (key.type_string,
key.value);
+ key_editor_child_default.is_valid.connect ((is_valid) => { custom_value_is_valid = is_valid;
button_apply.set_sensitive (is_valid); });
+ return key_editor_child_default;
+ }
+ }
+
+ private void response_cb (Dialog dialog, int response_id)
+ {
+ if (response_id == ResponseType.APPLY)
+ {
+ Variant variant = ((KeyEditorChild) custom_value_grid.get_child_at (0, 0)).get_variant ();
+ if (key.is_default || key.value != variant)
+ key.value = variant;
+ }
+ this.destroy ();
+ }
+}
+
[GtkTemplate (ui = "/ca/desrt/dconf-editor/ui/key-editor.ui")]
private class KeyEditor : Dialog
{
+ [GtkChild] private Button button_apply;
+ [GtkChild] private Grid custom_value_grid;
+
[GtkChild] private Label schema_label;
[GtkChild] private Label summary_label;
[GtkChild] private Label description_label;
[GtkChild] private Label type_label;
[GtkChild] private Label default_label;
- [GtkChild] private Button button_apply;
[GtkChild] private Switch custom_value_switch;
- [GtkChild] private Grid custom_value_grid;
private Key key;
private bool custom_value_is_valid = true;
@@ -41,6 +108,7 @@ private class KeyEditor : Dialog
this.key = _key;
// infos
+
this.title = key.name;
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]
@@ -48,7 +116,7 @@ private class KeyEditor : Dialog
string summary = key.schema.summary ?? "";
string description = key.schema.description ?? "";
- schema_label.set_text (key.schema.id);
+ schema_label.set_text (key.schema.schema_id);
summary_label.set_text (summary.strip ());
description_label.set_text (description.strip ());
type_label.set_text (key_to_description ());
diff --git a/editor/dconf-window.vala b/editor/dconf-window.vala
index ae16e45..d348f97 100644
--- a/editor/dconf-window.vala
+++ b/editor/dconf-window.vala
@@ -108,12 +108,12 @@ class DConfWindow : ApplicationWindow
}
else
{
- KeyListBoxRow key_list_box_row = new KeyListBoxRow.fixed_strings (key.name, key.cool_text_value
());
+ KeyListBoxRowEditableNoSchema key_list_box_row = new KeyListBoxRowEditableNoSchema (key);
key_list_box_row.button_press_event.connect (on_button_pressed);
key_list_box_row.show_dialog.connect (() => {
- MessageDialog dialog = new MessageDialog (this, DialogFlags.MODAL, MessageType.WARNING,
ButtonsType.OK, _("No Schema, cannot edit value.")); // TODO with or without punctuation? // TODO
insert key name/path/..?
- dialog.run ();
- dialog.destroy ();
+ KeyEditorNoSchema key_editor = new KeyEditorNoSchema (key);
+ key_editor.set_transient_for (this);
+ key_editor.run ();
});
return key_list_box_row;
}
@@ -259,13 +259,6 @@ private class KeyListBoxRow : EventBox
public signal void show_dialog ();
- public KeyListBoxRow.fixed_strings (string key_name, string key_value)
- {
- key_name_label.label = key_name;
- key_value_label.label = key_value;
- key_info_label.set_markup ("<i>" + _("No Schema") + "</i>");
- }
-
protected ContextPopover? popover = null;
protected virtual bool generate_popover () { return false; }
@@ -291,6 +284,47 @@ private class KeyListBoxRow : EventBox
}
}
+private class KeyListBoxRowEditableNoSchema : KeyListBoxRow
+{
+ public Key key { get; private set; }
+
+ public KeyListBoxRowEditableNoSchema (Key _key)
+ {
+ this.key = _key;
+
+ Pango.AttrList attr_list = new Pango.AttrList ();
+ attr_list.change (Pango.attr_weight_new (Pango.Weight.BOLD)); // TODO good?
+ key_name_label.set_attributes (attr_list);
+ key_value_label.set_attributes (attr_list);
+
+ key_name_label.label = key.name;
+ key_value_label.label = key.cool_text_value ();
+ key_info_label.set_markup ("<i>" + _("No Schema Found") + "</i>");
+
+ key.value_changed.connect (() => { key_value_label.label = key.cool_text_value (); if (popover !=
null) popover.destroy (); });
+ }
+
+ protected override bool generate_popover ()
+ {
+ popover = new ContextPopover ();
+ popover.add_action_button (_("Customize…"), () => { show_dialog (); });
+ popover.add_action_button (_("Copy"), () => {
+ Clipboard clipboard = Clipboard.get_default (Gdk.Display.get_default ());
+ string copy = key.full_name + " " + key.value.print (false);
+ clipboard.set_text (copy, copy.length);
+ });
+
+ if (key.type_string == "b")
+ {
+ popover.add_separator ();
+ popover.create_buttons_list (key, false);
+
+ popover.value_changed.connect ((bytes) => { key.value = new Variant.from_bytes
(key.value.get_type (), bytes, true); popover.destroy (); });
+ }
+ return true;
+ }
+}
+
private class KeyListBoxRowEditable : KeyListBoxRow
{
public Key key { get; private set; }
@@ -316,7 +350,7 @@ private class KeyListBoxRowEditable : KeyListBoxRow
popover.add_action_button (_("Customize…"), () => { show_dialog (); });
popover.add_action_button (_("Copy"), () => {
Clipboard clipboard = Clipboard.get_default (Gdk.Display.get_default ());
- string copy = key.schema.id + " " + key.name + " " + key.value.print (false);
+ string copy = key.schema.schema_id + " " + key.name + " " + key.value.print (false);
clipboard.set_text (copy, copy.length);
});
diff --git a/po/POTFILES.in b/po/POTFILES.in
index ef756cf..227522c 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -8,3 +8,4 @@ editor/dconf-schema.vala
editor/dconf-view.vala
editor/dconf-window.vala
[type: gettext/glade]editor/key-editor.ui
+[type: gettext/glade]editor/key-editor-no-schema.ui
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]