Merge lp:~evfool/midori/lp1170850 into lp:midori

Proposed by Robert Roth
Status: Merged
Approved by: Cris Dywan
Approved revision: 6557
Merged at revision: 6563
Proposed branch: lp:~evfool/midori/lp1170850
Merge into: lp:midori
Diff against target: 149 lines (+30/-12)
5 files modified
midori/midori-completion.vala (+25/-8)
midori/midori-historycompletion.vala (+1/-1)
midori/midori-locationaction.c (+2/-2)
midori/midori-searchcompletion.vala (+1/-0)
midori/midori-viewcompletion.vala (+1/-1)
To merge this branch: bzr merge lp:~evfool/midori/lp1170850
Reviewer Review Type Date Requested Status
Cris Dywan Approve
Review via email: mp+205869@code.launchpad.net

Commit message

Display locationbar suggestions in the correct order

Description of the change

Copied from the commit message:

    Display locationbar suggestions in the correct order (lp:1170850)

    This consists of the following changes:
    * Add a priority property to the suggestion objects, initialized to the
    position of the parent completion item
    * When adding the results of an async call of a completion to get the
    suggestions, find the index of the last item with higher priority, and
    add the new suggestions after that.

    This is required, as the current async loading order can not guarantee
    that the suggestions will appear in the correct order, as it depends
    on the execution time of the completion loading, when suggestions of a
    specific completion will be added. Calculating the start index based on
    the position of the completion in itself, as we would also need to know
    how many items the other completions (appearing before this one) will add.

To post a comment you must log in.
Revision history for this message
Cris Dywan (kalikiana) wrote :

I'm liking this priority concept! Just two comments here:

Might it have been simpler to use the List instead of TreeModelForeachFunc? Though no strong opinion, it looks sensible just unexpected.

One thing I do find awkward is adding the position to every Suggestion - there's nothing useful to do with it for a Completion subclass. Given that Autocompleter gets one complete List<Suggestion> always and knows where it comes from I'd prefer it to handle this behind the scenes.

review: Needs Fixing
Revision history for this message
Robert Roth (evfool) wrote :

I'm not sure I can follow you: I am aware that the Autocompleter gets one complete List<Suggestion>, which gets added to the full list, but finding the position where it needs to be inserted depends on the items already in the list. Consider the following usecase:
* Async tabs completion starts
* Async history completion starts
* Async search completion starts
* Async tabs completion finishes with 3 results, the model is empty, we simply add the elements of the list
* Async search completes before the history, now we have to find where to insert the results: we have the model having 3 elements, and we have the current list of elements,knowing that their position (from the completion) is 2. Unfortunately we don't know what that means, whether the 3 items in the model are the aggregated list of the Completions with position 0 and 1, or are coming from only one Completion, and the other one has not finished yet.
* Async history completion finishes, with Completion position 1, but we still don't know what to do with it.

Are you sure finding the correct position is possible without knowing the origin of each model element currently in the model?

Revision history for this message
Cris Dywan (kalikiana) wrote :

I didn't mean to never save the position but it should not be visible to the individual completion classes. At the point where the List<Suggestion> is passed to Autocompleter it will know what Completion it came from so position can be taken from that, no? If it has to be stored on the Suggestion, fair enough, but I'd prefer it to be handled transparently by Autocompleter.

lp:~evfool/midori/lp1170850 updated
6557. By Robert Roth

Merged from trunk.

Revision history for this message
Cris Dywan (kalikiana) wrote :

Well, I'm gonna say let's get this in as-is, I really like this fix despite that little quirk.

review: Approve
Revision history for this message
Robert Roth (evfool) wrote :

Thanks, I'm still thinking on a better solution, but haven't found it yet. I have tried various solutions, but none of them worked as expected, so I have dropped them. Anyway, when I'll have a better solution, I'll propose another merge. Thanks for accepting this though until a better solution.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'midori/midori-completion.vala'
2--- midori/midori-completion.vala 2013-06-25 17:13:34 +0000
3+++ midori/midori-completion.vala 2014-02-16 07:32:20 +0000
4@@ -17,12 +17,13 @@
5 public string? background { get; set; }
6 public GLib.Icon? icon { get; set; }
7 public bool action { get; set; default = false; }
8+ public int priority {get; set; default = 0; }
9
10 public Suggestion (string? uri, string? markup, bool use_markup=false,
11- string? background=null, GLib.Icon? icon=null) {
12+ string? background=null, GLib.Icon? icon=null, int? priority=0) {
13
14 GLib.Object (uri: uri, markup: markup, use_markup: use_markup,
15- background: background, icon: icon);
16+ background: background, icon: icon, priority: priority);
17 }
18 }
19
20@@ -53,6 +54,7 @@
21 BACKGROUND,
22 YALIGN,
23 SIZE,
24+ PRIORITY,
25 N
26 }
27
28@@ -62,7 +64,7 @@
29 next_position = 0;
30 model = new Gtk.ListStore (Columns.N,
31 typeof (GLib.Icon), typeof (string), typeof (string),
32- typeof (string), typeof (float), typeof (uint));
33+ typeof (string), typeof (float), typeof (uint), typeof (int));
34 }
35
36 public void add (Completion completion) {
37@@ -96,20 +98,34 @@
38 need_to_clear = false;
39 current_count = 0;
40 }
41+ int start = 0;
42+ // find the first index with priority greater than the current one
43+ Gtk.TreeModelForeachFunc find_index = (model, path, iter) => {
44+ GLib.Value priority;
45
46+ model.get_value (iter,Columns.PRIORITY, out priority);
47+ if ((int)priority < completion.position) {
48+ start++;
49+ return false;
50+ }
51+ return true;
52+ };
53+ model.foreach(find_index);
54+ int count = 0;
55 #if HAVE_GRANITE
56 if (completion.description != null) {
57- model.insert_with_values (null, completion.position,
58+ model.insert_with_values (null, start,
59 Columns.URI, "about:completion-description",
60 Columns.MARKUP, "<b>%s</b>\n".printf (Markup.escape_text (completion.description)),
61 Columns.ICON, null,
62 Columns.SIZE, Gtk.IconSize.MENU,
63 Columns.BACKGROUND, null,
64- Columns.YALIGN, 0.25);
65+ Columns.YALIGN, 0.25,
66+ Columns.PRIORITY, completion.position);
67+ count++;
68 }
69 #endif
70
71- int count = 1;
72 foreach (var suggestion in suggestions) {
73 if (suggestion.uri == null) {
74 warning ("suggestion.uri != null");
75@@ -119,14 +135,15 @@
76 warning ("suggestion.markup != null");
77 continue;
78 }
79- model.insert_with_values (null, completion.position + count,
80+ model.insert_with_values (null, start + count,
81 Columns.URI, suggestion.uri,
82 Columns.MARKUP, suggestion.use_markup
83 ? suggestion.markup : Markup.escape_text (suggestion.markup),
84 Columns.ICON, scale_if_needed (suggestion.icon),
85 Columns.SIZE, Gtk.IconSize.MENU,
86 Columns.BACKGROUND, suggestion.background,
87- Columns.YALIGN, 0.25);
88+ Columns.YALIGN, 0.25,
89+ Columns.PRIORITY, completion.position);
90
91 count++;
92 if (count > completion.max_items)
93
94=== modified file 'midori/midori-historycompletion.vala'
95--- midori/midori-historycompletion.vala 2013-09-13 21:24:57 +0000
96+++ midori/midori-historycompletion.vala 2014-02-16 07:32:20 +0000
97@@ -51,7 +51,7 @@
98 else if (item is Midori.HistorySearch) {
99 var search = item as Midori.HistorySearch;
100 suggestions.append (new Suggestion (search.uri, search.title + "\n" + search.uri,
101- false, "gray", Midori.Paths.get_icon (search.uri, null)));
102+ false, "gray", Midori.Paths.get_icon (search.uri, null), this.position));
103 }
104 else
105 warn_if_reached ();
106
107=== modified file 'midori/midori-locationaction.c'
108--- midori/midori-locationaction.c 2013-11-05 14:51:49 +0000
109+++ midori/midori-locationaction.c 2014-02-16 07:32:20 +0000
110@@ -661,12 +661,12 @@
111 g_object_unref (app);
112 midori_autocompleter_add (action->autocompleter,
113 MIDORI_COMPLETION (midori_view_completion_new ()));
114- midori_autocompleter_add (action->autocompleter,
115- MIDORI_COMPLETION (midori_search_completion_new ()));
116 /* FIXME: Currently HistoryCompletion doesn't work in memory */
117 if (action->history != NULL)
118 midori_autocompleter_add (action->autocompleter,
119 MIDORI_COMPLETION (midori_history_completion_new ()));
120+ midori_autocompleter_add (action->autocompleter,
121+ MIDORI_COMPLETION (midori_search_completion_new ()));
122 }
123
124 if (!midori_autocompleter_can_complete (action->autocompleter, action->key))
125
126=== modified file 'midori/midori-searchcompletion.vala'
127--- midori/midori-searchcompletion.vala 2013-08-08 23:31:08 +0000
128+++ midori/midori-searchcompletion.vala 2014-02-16 07:32:20 +0000
129@@ -56,6 +56,7 @@
130 if (n == 3 && action == null) {
131 suggestion = new Suggestion ("complete:more/search", _("Search with…"), false, background);
132 suggestion.action = true;
133+ suggestion.priority = this.position;
134 suggestions.append (suggestion);
135 break;
136 }
137
138=== modified file 'midori/midori-viewcompletion.vala'
139--- midori/midori-viewcompletion.vala 2013-08-08 23:31:08 +0000
140+++ midori/midori-viewcompletion.vala 2014-02-16 07:32:20 +0000
141@@ -72,7 +72,7 @@
142 Gdk.Pixbuf? icon = Midori.Paths.get_icon (uri, null);
143 /* FIXME: Theming? Win32? */
144 string background = "gray";
145- var suggestion = new Suggestion (uri, title + "\n" + uri, false, background, icon);
146+ var suggestion = new Suggestion (uri, title + "\n" + uri, false, background, icon, this.position);
147 suggestions.append (suggestion);
148
149 n++;

Subscribers

People subscribed via source and target branches

to all changes: