[dconf-editor] Remove TreeView.
- From: Arnaud Bonatti <arnaudb src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [dconf-editor] Remove TreeView.
- Date: Tue, 28 Nov 2017 06:28:28 +0000 (UTC)
commit 954094b3e15d1ee2f6e0a9102ce9f227fc94f6db
Author: Arnaud Bonatti <arnaud bonatti gmail com>
Date: Mon Oct 30 09:38:14 2017 +0100
Remove TreeView.
editor/dconf-model.vala | 137 +--------------------------------------------
editor/registry-view.ui | 10 ---
editor/registry-view.vala | 97 +++++++++++---------------------
3 files changed, 34 insertions(+), 210 deletions(-)
---
diff --git a/editor/dconf-model.vala b/editor/dconf-model.vala
index 0d69947..f252eff 100644
--- a/editor/dconf-model.vala
+++ b/editor/dconf-model.vala
@@ -540,7 +540,7 @@ public class GSettingsKey : Key
} */
}
-public class SettingsModel : Object, Gtk.TreeModel
+public class SettingsModel : Object
{
private DConf.Client client = new DConf.Client ();
private Directory root;
@@ -627,141 +627,6 @@ public class SettingsModel : Object, Gtk.TreeModel
parent_view.child_map.insert (name, new_view);
return new_view;
}
-
- /*\
- * * TreeModel things
- \*/
-
- public Gtk.TreeModelFlags get_flags()
- {
- return 0;
- }
-
- public int get_n_columns()
- {
- return 3;
- }
-
- public Type get_column_type (int index)
- {
- return index == 0 ? typeof (Directory) : typeof (string);
- }
-
- private void set_iter (ref Gtk.TreeIter iter, Directory directory)
- {
- iter.stamp = 0;
- iter.user_data = directory;
- iter.user_data2 = directory;
- iter.user_data3 = directory;
- }
-
- public Directory get_directory (Gtk.TreeIter? iter)
- {
- return iter == null ? root : (Directory) ((!) iter).user_data;
- }
-
- public bool get_iter(out Gtk.TreeIter iter, Gtk.TreePath path)
- {
- iter = Gtk.TreeIter();
-
- if (!iter_nth_child(out iter, null, path.get_indices()[0]))
- return false;
-
- for (int i = 1; i < path.get_depth(); i++)
- {
- Gtk.TreeIter parent = iter;
- if (!iter_nth_child(out iter, parent, path.get_indices()[i]))
- return false;
- }
-
- return true;
- }
-
- public Gtk.TreePath? get_path(Gtk.TreeIter iter)
- {
- var path = new Gtk.TreePath();
- for (var d = get_directory(iter); d != root; d = d.parent)
- path.prepend_index((int)d.index);
- return path;
- }
-
- public void get_value (Gtk.TreeIter iter, int column, out Value value)
- {
- switch (column)
- {
- case 0: value = get_directory (iter); break;
- case 1: value = get_directory (iter).name; break;
- case 2: value = get_directory (iter).full_name; break;
- default: assert_not_reached ();
- }
- }
-
- public bool iter_next(ref Gtk.TreeIter iter)
- {
- var directory = get_directory(iter);
- if (directory.index >= directory.parent.children.length() - 1)
- return false;
- set_iter(ref iter, directory.parent.children.nth_data(directory.index+1));
-
- return true;
- }
-
- public bool iter_children(out Gtk.TreeIter iter, Gtk.TreeIter? parent)
- {
- iter = Gtk.TreeIter();
-
- var directory = get_directory(parent);
- if (directory.children.length() == 0)
- return false;
- set_iter(ref iter, directory.children.nth_data(0));
-
- return true;
- }
-
- public bool iter_has_child(Gtk.TreeIter iter)
- {
- return get_directory(iter).children.length() > 0;
- }
-
- public int iter_n_children(Gtk.TreeIter? iter)
- {
- return (int) get_directory(iter).children.length();
- }
-
- public bool iter_nth_child(out Gtk.TreeIter iter, Gtk.TreeIter? parent, int n)
- {
- iter = Gtk.TreeIter();
-
- var directory = get_directory(parent);
- if (n >= directory.children.length())
- return false;
- set_iter(ref iter, directory.children.nth_data(n));
-
- return true;
- }
-
- public bool iter_parent(out Gtk.TreeIter iter, Gtk.TreeIter child)
- {
- iter = Gtk.TreeIter();
-
- var directory = get_directory(child);
- if (directory.parent == root)
- return false;
-
- set_iter(ref iter, directory.parent);
-
- return true;
- }
-
- public void ref_node(Gtk.TreeIter iter)
- {
- get_directory(iter).ref();
- }
-
- public void unref_node(Gtk.TreeIter iter)
- {
- get_directory(iter).unref();
- }
}
/*\
diff --git a/editor/registry-view.ui b/editor/registry-view.ui
index dfb71cb..cbfd84f 100644
--- a/editor/registry-view.ui
+++ b/editor/registry-view.ui
@@ -4,16 +4,6 @@
<template class="RegistryView" parent="GtkGrid">
<property name="orientation">vertical</property>
<child>
- <object class="GtkTreeView" id="dir_tree_view">
- <property name="visible">False</property>
- <child internal-child="selection">
- <object class="GtkTreeSelection" id="dir_tree_selection">
- <signal name="changed" handler="dir_selected_cb"/>
- </object>
- </child>
- </object>
- </child>
- <child>
<object class="GtkRevealer" id="multiple_schemas_warning_revealer">
<property name="visible">True</property>
<property name="reveal-child">False</property>
diff --git a/editor/registry-view.vala b/editor/registry-view.vala
index 82f5f54..50aff5d 100644
--- a/editor/registry-view.vala
+++ b/editor/registry-view.vala
@@ -29,8 +29,7 @@ class RegistryView : Grid, PathElement
private bool multiple_schemas_warning_needed;
private SettingsModel model = new SettingsModel ();
- [GtkChild] private TreeView dir_tree_view;
- [GtkChild] private TreeSelection dir_tree_selection;
+ private Directory current_directory;
[GtkChild] private Stack stack;
[GtkChild] private RegistryInfo properties_view;
@@ -86,14 +85,11 @@ class RegistryView : Grid, PathElement
public void init (string path, bool restore_view) // TODO check path format
{
- dir_tree_view.set_model (model);
- dir_tree_view.expand_all ();
-
current_path = (restore_view && path != "" && path [0] == '/') ? path : "/";
path_requested (current_path, null, true);
sorting_options.notify.connect (() => {
- if (!is_not_browsing_view () && get_selected_directory ().need_sorting (sorting_options))
+ if (!is_not_browsing_view () && current_directory.need_sorting (sorting_options))
need_reload_warning_revealer.set_reveal_child (true);
});
}
@@ -108,7 +104,7 @@ class RegistryView : Grid, PathElement
need_reload_warning_revealer.set_reveal_child (false);
multiple_schemas_warning_revealer.set_reveal_child (multiple_schemas_warning_needed);
update_current_path (path);
- get_selected_directory ().sort_key_model (sorting_options);
+ current_directory.sort_key_model (sorting_options);
stack.set_visible_child_name ("browse-view");
if (selected != null)
{
@@ -171,30 +167,19 @@ class RegistryView : Grid, PathElement
}
/*\
- * * Dir TreeView
+ * * Directories tree
\*/
- [GtkCallback]
private void dir_selected_cb ()
{
- Directory dir = get_selected_directory ();
- dir.sort_key_model (sorting_options);
- key_model = dir.key_model;
+ current_directory.sort_key_model (sorting_options);
+ key_model = current_directory.key_model;
- multiple_schemas_warning_needed = dir.warning_multiple_schemas;
+ multiple_schemas_warning_needed = current_directory.warning_multiple_schemas;
key_list_box.bind_model (key_model, new_list_box_row);
}
- private Directory get_selected_directory ()
- {
- TreeIter iter;
- if (dir_tree_selection.get_selected (null, out iter))
- return model.get_directory (iter);
- else
- return model.get_root_directory ();
- }
-
public void path_requested (string _full_name, string? selected, bool tolerant = false)
{
string full_name = _full_name.dup ();
@@ -208,6 +193,8 @@ class RegistryView : Grid, PathElement
{
window.show_notification (_("Cannot find folder ā%sā.").printf (folder_name));
current_path = "/";
+ current_directory = model.get_root_directory ();
+ dir_selected_cb ();
show_browse_view ("/", null);
return;
}
@@ -250,37 +237,39 @@ class RegistryView : Grid, PathElement
{
if (full_name == "/")
{
- dir_tree_selection.unselect_all ();
+ current_directory = model.get_root_directory ();
+ dir_selected_cb ();
return true;
}
- TreeIter iter;
- Directory dir;
+ Directory? dir = model.get_root_directory ();
- if (dir_tree_selection.get_selected (null, out iter))
+ string [] names = full_name.split ("/");
+ uint index = 1;
+ while (index < names.length - 1)
{
- dir = model.get_directory (iter);
- if (dir.full_name == full_name)
- return true;
+ ((!) dir).sort_key_model (sorting_options);
+ dir = get_directory (((!) dir).key_model, names [index]);
+ if (dir == null)
+ return false;
+ index++;
}
- if (model.get_iter_first (out iter))
+ current_directory = (!) dir;
+ dir_selected_cb ();
+ return true;
+ }
+ private Directory? get_directory (GLib.ListStore dir_key_model, string object_name)
+ {
+ uint position = 0;
+ while (position < dir_key_model.get_n_items ())
{
- do
- {
- dir = model.get_directory (iter);
-
- if (dir.full_name == full_name)
- {
- dir_tree_selection.select_iter (iter);
- return true;
- }
- }
- while (get_next_iter (ref iter));
+ SettingObject object = (SettingObject) dir_key_model.get_object (position);
+ if ((object is Directory) && (object.name == object_name))
+ return (Directory) object;
+ position++;
}
- else
- assert_not_reached ();
- return false;
+ return null;
}
private SettingObject? get_object_from_name (string object_name)
requires (key_model != null)
@@ -616,24 +605,4 @@ class RegistryView : Grid, PathElement
return null;
return (ListBoxRow?) key_list_box.get_selected_row ();
}
-
- private bool get_next_iter (ref TreeIter iter)
- {
- /* Search children next */
- if (model.iter_has_child (iter))
- {
- model.iter_nth_child (out iter, iter, 0);
- return true;
- }
-
- /* Move to the next branch */
- while (!model.iter_next (ref iter))
- {
- /* Otherwise move to the parent and onto the next iter */
- if (!model.iter_parent (out iter, iter))
- return false;
- }
-
- return true;
- }
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]