Merge lp:~ivaldi/midori/history-list into lp:midori

Proposed by André Stösel
Status: Merged
Approved by: Cris Dywan
Approved revision: 6199
Merged at revision: 6200
Proposed branch: lp:~ivaldi/midori/history-list
Merge into: lp:midori
Diff against target: 157 lines (+63/-22)
1 file modified
extensions/history-list.vala (+63/-22)
To merge this branch: bzr merge lp:~ivaldi/midori/history-list
Reviewer Review Type Date Requested Status
Cris Dywan Approve
Review via email: mp+167997@code.launchpad.net

Commit message

Delete tabs from history list with Del

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

At first I thought close_tab wasn't overlay efficient for counting all rows, but avoiding that is not so obvious and would make the code harder to read.

I like the refactoring of the treeview resizing.

And it's working so smoothly I was tempted to just ack it without review ;-)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'extensions/history-list.vala'
2--- extensions/history-list.vala 2013-05-25 18:18:50 +0000
3+++ extensions/history-list.vala 2013-06-07 10:06:51 +0000
4@@ -66,12 +66,14 @@
5
6 public abstract void make_update ();
7 public abstract void clean_up ();
8+ public abstract void close_tab ();
9 }
10
11 private class TabWindow : HistoryWindow {
12 protected Gtk.HBox? hbox;
13 protected Gtk.VBox? vbox;
14 protected bool is_dirty = false;
15+ protected Gtk.ScrolledWindow? scroll_windows;
16
17 protected void store_append_row (GLib.PtrArray list, Gtk.ListStore store, out Gtk.TreeIter iter) {
18 for (var i = list.len; i > 0; i--) {
19@@ -99,6 +101,28 @@
20 store_append_row (list_new, store, out iter);
21 }
22
23+ protected void resize_treeview () {
24+ Requisition requisition;
25+ int height;
26+ int max_lines = 10;
27+#if HAVE_GTK3
28+ requisition = Requisition();
29+ this.treeview.get_preferred_size(out requisition, null);
30+#else
31+ this.treeview.size_request (out requisition);
32+#endif
33+ Gtk.ListStore model = this.treeview.get_model () as Gtk.ListStore;
34+ int length = model.iter_n_children(null);
35+ if (length > max_lines) {
36+ height = requisition.height / length * max_lines + 2;
37+ } else {
38+ height = requisition.height + 2;
39+ }
40+ this.scroll_windows.set_size_request (320, height);
41+ this.resize (320, height);
42+
43+ }
44+
45 public TabWindow (Midori.Browser browser) {
46 base (browser);
47
48@@ -107,10 +131,10 @@
49
50 this.hbox = new Gtk.HBox (false, 1);
51
52- var sw = new Gtk.ScrolledWindow (null, null);
53- sw.set_policy (PolicyType.NEVER , PolicyType.AUTOMATIC);
54- sw.set_shadow_type (ShadowType.ETCHED_IN);
55- this.hbox.pack_start (sw, true, true, 0);
56+ this.scroll_windows = new Gtk.ScrolledWindow (null, null);
57+ this.scroll_windows.set_policy (PolicyType.NEVER , PolicyType.AUTOMATIC);
58+ this.scroll_windows.set_shadow_type (ShadowType.ETCHED_IN);
59+ this.hbox.pack_start (this.scroll_windows, true, true, 0);
60
61 var store = new Gtk.ListStore (TabTreeCells.TREE_CELL_COUNT,
62 typeof (Gdk.Pixbuf), typeof (string),
63@@ -121,7 +145,7 @@
64 this.vbox.pack_start (this.hbox, true, true, 0);
65
66 this.treeview = new Gtk.TreeView.with_model (store);
67- sw.add (treeview);
68+ this.scroll_windows.add (treeview);
69
70 this.treeview.set_model (store);
71 this.treeview.set ("headers-visible", false);
72@@ -137,23 +161,7 @@
73 "cell-background-gdk", TabTreeCells.TREE_CELL_BG);
74
75 this.show_all ();
76-
77- Requisition requisition;
78- int height;
79- int max_lines = 10;
80-#if HAVE_GTK3
81- requisition = Requisition();
82- this.treeview.get_preferred_size(out requisition, null);
83-#else
84- this.treeview.size_request (out requisition);
85-#endif
86- int length = store.iter_n_children(null);
87- if (length > max_lines) {
88- height = requisition.height / length * max_lines + 2;
89- } else {
90- height = requisition.height + 2;
91- }
92- sw.set_size_request (320, height);
93+ this.resize_treeview ();
94 }
95
96 public override void make_update () {
97@@ -188,6 +196,35 @@
98 this.is_dirty = false;
99 }
100 }
101+
102+ public override void close_tab () {
103+ Gtk.TreePath? path;
104+ Gtk.TreeViewColumn? column;
105+
106+ this.treeview.get_cursor (out path, out column);
107+
108+ Gtk.ListStore model = this.treeview.get_model () as Gtk.ListStore;
109+ int length = model.iter_n_children(null);
110+
111+ if (length > 1) {
112+ Gtk.TreeIter iter;
113+ unowned Midori.View? view = null;
114+
115+ model.get_iter (out iter, path);
116+ model.get (iter, TabTreeCells.TREE_CELL_POINTER, out view);
117+
118+ /*
119+ FixMe: the retrun value of `Gtk.ListStore.remove` should be checked
120+ Note: in some cases the return value of `Gtk.ListStore.remove` is wrong
121+ */
122+ model.remove (iter);
123+ this.browser.close_tab (view);
124+ if (length > 2)
125+ this.resize_treeview ();
126+ else
127+ this.hide ();
128+ }
129+ }
130 }
131
132 private class NewTabWindow : TabWindow {
133@@ -334,6 +371,7 @@
134 public signal void preferences_changed ();
135
136 protected uint escKeyval;
137+ protected uint delKeyval;
138 protected uint modifier_count;
139 protected int closing_behavior;
140 protected HistoryWindow? history_window;
141@@ -378,6 +416,8 @@
142 }
143 this.history_window.destroy ();
144 this.history_window = null;
145+ } else if (event_key.keyval == this.delKeyval) {
146+ this.history_window.close_tab ();
147 }
148 return false;
149 }
150@@ -609,6 +649,7 @@
151 }
152 construct {
153 this.escKeyval = Gdk.keyval_from_name ("Escape");
154+ this.delKeyval = Gdk.keyval_from_name ("Delete");
155 }
156 }
157 }

Subscribers

People subscribed via source and target branches

to all changes: