summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Dywan <christian@twotoasts.de>2018-07-31 23:23:24 +0200
committerChristian Dywan <christian@twotoasts.de>2018-07-31 23:23:24 +0200
commited9b8f168ef55d57bd836758f88fc20447292133 (patch)
treef746ff31bdc829940e54efa2344b99f25b74e325
parent22b6b89e7d03e479b6e81a7c5557e38c0a1d3107 (diff)
downloadmidori-git-completion-robust-placeholder.tar.gz
Make completion more reliable and add placeholdercompletion-robust-placeholder
-rw-r--r--core/completion.vala6
-rw-r--r--core/database.vala23
-rw-r--r--core/suggestion-row.vala3
-rw-r--r--core/urlbar.vala10
-rw-r--r--ui/urlbar.ui1
5 files changed, 27 insertions, 16 deletions
diff --git a/core/completion.vala b/core/completion.vala
index 22b262ce..ab41df41 100644
--- a/core/completion.vala
+++ b/core/completion.vala
@@ -43,7 +43,11 @@ namespace Midori {
public Completion () {
}
- void add (ListModel model) {
+ /*
+ * Add a model to complete from. Items need to be based on DatabaseItem
+ * and filtered by key if set.
+ */
+ public virtual signal void add (ListModel model) {
if (model is Database) {
bind_property ("key", model, "key");
}
diff --git a/core/database.vala b/core/database.vala
index 36c217f8..f47f96a7 100644
--- a/core/database.vala
+++ b/core/database.vala
@@ -192,9 +192,14 @@ namespace Midori {
public string? table { get; protected set; default = null; }
public string path { get; protected set; default = ":memory:"; }
string? _key = null;
+ Cancellable? populate_cancellable = null;
public string? key { get { return _key; } set {
_key = value;
- populate.begin ();
+ if (populate_cancellable != null) {
+ populate_cancellable.cancel ();
+ }
+ populate_cancellable = new Cancellable ();
+ populate.begin (populate_cancellable);
} }
/*
@@ -396,7 +401,7 @@ namespace Midori {
/*
* Query items from the database, matching filter if given.
*/
- public async List<DatabaseItem>? query (string? filter=null, int64 max_items=15, Cancellable? cancellable=null) throws DatabaseError {
+ public async virtual List<DatabaseItem>? query (string? filter=null, int64 max_items=15, Cancellable? cancellable=null) throws DatabaseError {
string sqlcmd = """
SELECT uri, title, date, count () AS ct FROM %s
WHERE uri LIKE :filter OR title LIKE :filter
@@ -500,17 +505,25 @@ namespace Midori {
public uint get_n_items () {
if (_items == null) {
- populate.begin ();
+ if (populate_cancellable != null) {
+ populate_cancellable.cancel ();
+ }
+ populate_cancellable = new Cancellable ();
+ populate.begin (populate_cancellable);
return 0;
}
return _items.length ();
}
- async void populate () {
+ async void populate (Cancellable? cancellable) {
try {
uint old_length = _items.length ();
_items = yield query (key);
- items_changed (0, old_length, _items.length ());
+ if (cancellable.is_cancelled ()) {
+ _items = null;
+ } else {
+ items_changed (0, old_length, _items.length ());
+ }
} catch (DatabaseError error) {
debug ("Failed to populate: %s", error.message);
}
diff --git a/core/suggestion-row.vala b/core/suggestion-row.vala
index 3521f782..402d2578 100644
--- a/core/suggestion-row.vala
+++ b/core/suggestion-row.vala
@@ -47,7 +47,8 @@ namespace Midori {
title.label = item.title;
}
});
- } else {
+ // Double-check type for the sake of plugins
+ } else if (item is DatabaseItem) {
icon.uri = item.uri;
escaped_title = item.title != null ? Markup.escape_text (item.title) : "";
title.label = escaped_title;
diff --git a/core/urlbar.vala b/core/urlbar.vala
index 1b5c70b6..48bef498 100644
--- a/core/urlbar.vala
+++ b/core/urlbar.vala
@@ -246,22 +246,14 @@ namespace Midori {
}
protected override bool focus_out_event (Gdk.EventFocus event) {
- suggestions.hide ();
+ popdown ();
return base.focus_out_event (event);
}
- /*
- https://ac.duckduckgo.com/ac/?q={searchTerms}&type=list
- ["cat",["catlux","cathay pacific","cats","catherine zeta-jones","caterpillar","cathy fischer","cate blanchett","cat stevens","catwoman","catch the millionaire"]]
- https://encrypted.google.com/complete/search?output=firefox&q={searchTerms}
- ["cat",["catching fire","catalina island","catching fire movie","cathay pacific","caterpillar","cats","catching fire cast","catwoman","catherine zeta jones","cato"]]
- */
-
public void popdown () {
// Note: Guard against popover being destroyed before popdown
if (suggestions != null) {
suggestions.hide ();
- grab_focus_without_selecting ();
}
}
diff --git a/ui/urlbar.ui b/ui/urlbar.ui
index 9a93fb31..3b31b824 100644
--- a/ui/urlbar.ui
+++ b/ui/urlbar.ui
@@ -21,5 +21,6 @@
</object>
<template class="MidoriUrlbar" parent="GtkEntry">
<property name="can-default">yes</property>
+ <property name="placeholder-text" translatable="yes">Search or enter an address</property>
</template>
</interface>