[Xfce4-commits] <midori:master> Fix positions of suggestions in model
Christian Dywan
noreply at xfce.org
Fri Oct 5 21:24:02 CEST 2012
Updating branch refs/heads/master
to 69bcbd3d6e291248d9d26185f3e405e6a0369f82 (commit)
from 57dc168353de2fed736121c9b1b94977a3268c67 (commit)
commit 69bcbd3d6e291248d9d26185f3e405e6a0369f82
Author: Christian Dywan <christian at twotoasts.de>
Date: Fri Oct 5 20:49:35 2012 +0200
Fix positions of suggestions in model
midori/midori-completion.vala | 4 +-
midori/midori-historycompletion.vala | 5 ++-
tests/completion.vala | 48 +++++++++++++++++++++++++++++++++-
3 files changed, 52 insertions(+), 5 deletions(-)
diff --git a/midori/midori-completion.vala b/midori/midori-completion.vala
index f3327f5..0d64ee1 100644
--- a/midori/midori-completion.vala
+++ b/midori/midori-completion.vala
@@ -90,9 +90,9 @@ namespace Midori {
current_count = 0;
}
- uint count = 0;
+ int count = 0;
foreach (var suggestion in suggestions) {
- model.insert_with_values (null, completion.position,
+ model.insert_with_values (null, completion.position + count,
Columns.URI, suggestion.uri,
Columns.MARKUP, suggestion.use_markup
? suggestion.markup : Markup.escape_text (suggestion.markup),
diff --git a/midori/midori-historycompletion.vala b/midori/midori-historycompletion.vala
index 5a194d9..2bc761f 100644
--- a/midori/midori-historycompletion.vala
+++ b/midori/midori-historycompletion.vala
@@ -76,17 +76,18 @@ namespace Midori {
unowned string uri = stmt.column_text (1);
unowned string title = stmt.column_text (2);
Gdk.Pixbuf? icon = Katze.load_cached_icon (uri, null);
+ Suggestion suggestion;
switch (type) {
case 1: /* history_view */
- var suggestion = new Suggestion (uri, title, false, null, icon);
+ suggestion = new Suggestion (uri, title, false, null, icon);
suggestions.append (suggestion);
break;
case 2: /* search_view */
string desc = _("Search for %s").printf (title) + "\n" + uri;
/* FIXME: Theming? Win32? */
string background = "gray";
- var suggestion = new Suggestion (uri, desc, false, background, icon);
+ suggestion = new Suggestion (uri, desc, false, background, icon);
suggestions.append (suggestion);
break;
default:
diff --git a/tests/completion.vala b/tests/completion.vala
index 98d7d99..04c60bf 100644
--- a/tests/completion.vala
+++ b/tests/completion.vala
@@ -11,6 +11,7 @@
class TestCompletion : Midori.Completion {
public bool test_can_complete { get; set; }
+ public uint test_suggestions { get; set; }
public TestCompletion () {
}
@@ -27,7 +28,18 @@ class TestCompletion : Midori.Completion {
}
public override async List<Midori.Suggestion>? complete (string text, string? action, Cancellable cancellable) {
- return null;
+ var suggestions = new List<Midori.Suggestion> ();
+ if (test_suggestions == 0)
+ return null;
+ if (test_suggestions >= 1)
+ suggestions.append (new Midori.Suggestion (null, "First"));
+ if (test_suggestions >= 2)
+ suggestions.append (new Midori.Suggestion (null, "Second"));
+ if (test_suggestions >= 3)
+ suggestions.append (new Midori.Suggestion (null, "Third"));
+ if (cancellable.is_cancelled ())
+ return null;
+ return suggestions;
}
}
@@ -41,6 +53,40 @@ void completion_autocompleter () {
assert (!autocompleter.can_complete (""));
completion.test_can_complete = true;
assert (autocompleter.can_complete (""));
+
+ completion.test_suggestions = 0;
+ autocompleter.complete ("");
+ var loop = MainContext.default ();
+ do { loop.iteration (true); } while (loop.pending ());
+ assert (autocompleter.model.iter_n_children (null) == 0);
+
+ completion.test_suggestions = 1;
+ autocompleter.complete ("");
+ do { loop.iteration (true); } while (loop.pending ());
+ assert (autocompleter.model.iter_n_children (null) == 1);
+
+ /* Order */
+ completion.test_suggestions = 2;
+ autocompleter.complete ("");
+ do { loop.iteration (true); } while (loop.pending ());
+ assert (autocompleter.model.iter_n_children (null) == 2);
+ Gtk.TreeIter iter_first;
+ autocompleter.model.get_iter_first (out iter_first);
+ string title;
+ autocompleter.model.get (iter_first, Midori.Autocompleter.Columns.MARKUP, out title);
+ if (title != "First")
+ error ("Expected %s but got %s", "First", title);
+
+ /* Cancellation */
+ /*
+ autocompleter.complete ("");
+ completion.test_suggestions = 3;
+ autocompleter.complete ("");
+ do { loop.iteration (true); } while (loop.pending ());
+ int n = autocompleter.model.iter_n_children (null);
+ if (n != 3)
+ error ("Expected %d but got %d", 3, n);
+ */
}
struct TestCaseCompletion {
More information about the Xfce4-commits
mailing list