[seahorse] KeyManager: use a proper Gtk.SearchEntry.
- From: Niels De Graef <nielsdg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [seahorse] KeyManager: use a proper Gtk.SearchEntry.
- Date: Sat, 5 May 2018 09:40:39 +0000 (UTC)
commit 345deb983d3ca621b4e765eb0b7e7eed4f1b241f
Author: Niels De Graef <nielsdegraef gmail com>
Date: Sat May 5 08:50:45 2018 +0200
KeyManager: use a proper Gtk.SearchEntry.
Also clean up the code and make it actually work again (it seems to have
been broken when the KeyManager got ported to Vala).
common/key-manager-store.vala | 72 ++++++-----------------------------------
src/key-manager.vala | 9 ++---
2 files changed, 14 insertions(+), 67 deletions(-)
---
diff --git a/common/key-manager-store.vala b/common/key-manager-store.vala
index 4025f4d..38ccf60 100644
--- a/common/key-manager-store.vala
+++ b/common/key-manager-store.vala
@@ -42,8 +42,6 @@ public class Seahorse.KeyManagerStore : Gcr.CollectionModel {
{ "XdndDirectSave0", 0, DragInfo.XDS }
};
- private uint filter_stag;
-
private string? drag_destination;
private GLib.Error? drag_error;
private List<GLib.Object>? drag_objects;
@@ -54,39 +52,18 @@ public class Seahorse.KeyManagerStore : Gcr.CollectionModel {
public GLib.Settings settings { get; construct set; }
/**
- * Key store mode controls which keys to display
- */
- public Mode filter_mode {
- get { return this._filter_mode; }
- set {
- if (this._filter_mode != value) {
- this._filter_mode = value;
- refilter_later();
- }
- }
- }
- private Mode _filter_mode;
-
- /**
- * Key store filter for when in filtered mode
+ * Key store filter
*/
- public string? filter {
- get { return (this.filter_mode == Mode.FILTERED)? this._filter : ""; }
+ public string filter {
+ get { return this._filter; }
set {
- // If we're not in filtered mode and there is text OR
- // we're in filtered mode (regardless of text or not)
- // then update the filter
- if ((this._filter_mode != Mode.FILTERED && value != null && value != "")
- || (this._filter_mode == Mode.FILTERED)) {
- this._filter_mode = Mode.FILTERED;
-
- // We always use lower case text (see filter_callback)
- this._filter = value.down();
- refilter_later ();
+ if (this._filter != value) {
+ this._filter = value;
+ refilter ();
}
}
}
- private string? _filter;
+ private string _filter = "";
private enum Column {
ICON,
@@ -114,14 +91,10 @@ public class Seahorse.KeyManagerStore : Gcr.CollectionModel {
}
public KeyManagerStore (Gcr.Collection? collection, Gtk.TreeView? view, Predicate? pred, GLib.Settings
settings) {
- Collection filtered = new Collection.for_predicate (collection, pred, null);
pred.custom = on_filter_visible;
pred.custom_target = this;
-
- GLib.Object (
- collection: filtered,
- settings: settings
- );
+ this.collection = new Collection.for_predicate (collection, pred, null);
+ this.settings = settings;
// The sorted model is the top level model
view.model = this;
@@ -160,10 +133,6 @@ public class Seahorse.KeyManagerStore : Gcr.CollectionModel {
col.set_sort_column_id(Column.LABEL);
// Use predicate to figure out which columns to add
- if (collection is Collection)
- pred = ((Collection) collection).predicate;
- else
- pred = null;
// Also watch for sort-changed on the store
this.sort_column_changed.connect(on_sort_column_changed);
@@ -218,34 +187,13 @@ public class Seahorse.KeyManagerStore : Gcr.CollectionModel {
// Called to filter each row
private static bool on_filter_visible (GLib.Object? obj, void* custom_target) {
KeyManagerStore self = (KeyManagerStore) custom_target;
-
- // Check the row requested
- switch (self.filter_mode) {
- case Mode.FILTERED:
- return self.object_contains_filtered_text (obj, self.filter);
- case Mode.ALL:
- return true;
- default:
- assert_not_reached();
- };
+ return self.object_contains_filtered_text (obj, self.filter);
}
public void refilter() {
((Collection) get_collection()).refresh();
}
- // Refilter the tree after a timeout has passed
- private void refilter_later() {
- if (this.filter_stag != 0)
- Source.remove (this.filter_stag);
-
- this.filter_stag = Timeout.add (200, () => {
- this.filter_stag = 0;
- refilter();
- return false;
- });
- }
-
// Update the sort order for a column
private void set_sort_to(string name) {
// Prefix with a minus means descending
diff --git a/src/key-manager.vala b/src/key-manager.vala
index cd220c8..a9864c3 100644
--- a/src/key-manager.vala
+++ b/src/key-manager.vala
@@ -24,7 +24,7 @@ public class Seahorse.KeyManager : Catalog {
private Gtk.ActionGroup view_actions;
private Gtk.RadioAction show_action;
- private Gtk.Entry filter_entry;
+ private Gtk.SearchEntry filter_entry;
private Predicate pred;
private Sidebar sidebar;
@@ -112,11 +112,11 @@ public class Seahorse.KeyManager : Catalog {
// The toolbar
((Gtk.Button) builder.get_object("new_item_button")).clicked.connect(on_keymanager_new_button);
- this.filter_entry = (Gtk.Entry) builder.get_object("filter_entry");
+ this.filter_entry = (Gtk.SearchEntry) builder.get_object("filter_entry");
on_filter_changed(this.filter_entry);
// For the filtering
- this.filter_entry.changed.connect(on_filter_changed);
+ this.filter_entry.search_changed.connect(on_filter_changed);
this.view.start_interactive_search.connect(() => {
this.filter_entry.grab_focus();
return false;
@@ -222,8 +222,7 @@ public class Seahorse.KeyManager : Catalog {
}
private void on_filter_changed(Gtk.Editable entry) {
- string? text = this.filter_entry.get_text();
- this.store.filter = text;
+ this.store.filter = this.filter_entry.text;
}
private void import_files(string[]? uris) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]