Merge lp:~ivaldi/midori/tabby-tab-usage into lp:midori

Proposed by André Stösel
Status: Merged
Merge reported by: Cris Dywan
Merged at revision: not available
Proposed branch: lp:~ivaldi/midori/tabby-tab-usage
Merge into: lp:midori
Diff against target: 116 lines (+51/-2)
1 file modified
extensions/tabby.vala (+51/-2)
To merge this branch: bzr merge lp:~ivaldi/midori/tabby-tab-usage
Reviewer Review Type Date Requested Status
Cris Dywan Abstain
Review via email: mp+185031@code.launchpad.net

Commit message

restore tabs in order of last usage

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

We need to keep the order of tabs in the notebook. Some discussion on IRC suggests that's what is expected from static tab labels - there's interest in re-thinking the default switching behavior but it would be surprising to visibly re-order after startup.

review: Needs Fixing
Revision history for this message
André Stösel (ivaldi) wrote :

I know and agree with this but I planned to fix this in another branch/commit.
(I try to keep the commits small in order to simplify the review.)

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

For the record, I would approve of the change by itself. I just feel uneasy formally approving because the notebook is affected even without being explicitly changed - it's a historic mistake that it's only ordered by insertion.

review: Abstain
Revision history for this message
Musee "lae" Ullah (sleepingkyoto) wrote :

If anything, I would leave this feature as optional and up to the user. This basically makes manually organizing/grouping tabs (by moving them around in the tab bar) completely useless, as their order would be reset on startup (so I'm agreeing with kalikiana). Although, I would prefer this over the current state of trunk.

Revision history for this message
André Stösel (ivaldi) wrote :

for clarification: this commit/branch only affects the order in which the tabs should be restored, not the tab soring itself. the problem is that the tab sorting part isn't implemented yet - it looks like it changes the sorting, but it dosn't (or shouldn't)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'extensions/tabby.vala'
2--- extensions/tabby.vala 2013-09-09 21:00:43 +0000
3+++ extensions/tabby.vala 2013-09-11 12:21:52 +0000
4@@ -65,17 +65,24 @@
5 }
6
7 public abstract class Session : GLib.Object, ISession {
8+ public Midori.Browser browser { get; protected set; }
9+
10 public abstract void add_item (Katze.Item item);
11 public abstract void uri_changed (Midori.View view, string uri);
12 public abstract void tab_added (Midori.Browser browser, Midori.View view);
13 public abstract void tab_removed (Midori.Browser browser, Midori.View view);
14- public abstract void close ();
15+ public abstract void tab_switched (Midori.View? old_view, Midori.View? new_view);
16+
17 public abstract Katze.Array get_tabs ();
18
19 public void attach (Midori.Browser browser) {
20+ this.browser = browser;
21+
22 browser.add_tab.connect (this.tab_added);
23 browser.add_tab.connect (this.helper_uri_changed);
24 browser.remove_tab.connect (this.tab_removed);
25+ browser.switch_tab.connect (this.tab_switched);
26+ browser.delete_event.connect_after(this.delete_event);
27
28 foreach (Midori.View view in browser.get_tabs ()) {
29 this.tab_added (browser, view);
30@@ -84,6 +91,8 @@
31 }
32
33 public void restore (Midori.Browser browser) {
34+ this.browser = browser;
35+
36 Katze.Array tabs = this.get_tabs ();
37
38 if(tabs.is_empty ()) {
39@@ -95,6 +104,8 @@
40 browser.add_tab.connect (this.tab_added);
41 browser.add_tab.connect (this.helper_uri_changed);
42 browser.remove_tab.connect (this.tab_removed);
43+ browser.switch_tab.connect (this.tab_switched);
44+ browser.delete_event.connect_after(this.delete_event);
45
46 GLib.List<unowned Katze.Item> items = tabs.get_items ();
47 unowned GLib.List<unowned Katze.Item> u_items = items;
48@@ -110,6 +121,8 @@
49
50 Katze.Item t_item = u_items.data<Katze.Item>;
51
52+ t_item.set_meta_integer ("append", 1);
53+
54 if (delay)
55 t_item.set_meta_integer ("delay", Midori.Delay.DELAYED);
56 else
57@@ -124,6 +137,25 @@
58 });
59 }
60
61+ public virtual void close () {
62+ this.browser.add_tab.disconnect (this.tab_added);
63+ this.browser.add_tab.disconnect (this.helper_uri_changed);
64+ this.browser.remove_tab.disconnect (this.tab_removed);
65+ this.browser.switch_tab.disconnect (this.tab_switched);
66+ this.browser.delete_event.disconnect (this.delete_event);
67+ }
68+
69+#if HAVE_GTK3
70+ protected bool delete_event (Gtk.Widget widget, Gdk.EventAny event) {
71+#else
72+ protected bool delete_event (Gtk.Widget widget, Gdk.Event event) {
73+#endif
74+
75+ this.close();
76+ return false;
77+
78+ }
79+
80 private void helper_uri_changed (Midori.Browser browser, Midori.View view) {
81 /* FixMe: skip first event while restoring the session */
82 view.web_view.notify["uri"].connect ( () => {
83@@ -194,7 +226,24 @@
84 critical (_("Failed to update database: %s"), db.errmsg ());
85 }
86
87+ protected override void tab_switched (Midori.View? old_view, Midori.View? new_view) {
88+ GLib.DateTime time = new DateTime.now_local ();
89+ unowned Katze.Item item = new_view.get_proxy_item ();
90+ int64 tab_id = item.get_meta_integer ("tabby-id");
91+ string sqlcmd = "UPDATE `tabs` SET tstamp = :tstamp WHERE session_id = :session_id AND id = :tab_id;";
92+ Sqlite.Statement stmt;
93+ if (this.db.prepare_v2 (sqlcmd, -1, out stmt, null) != Sqlite.OK)
94+ critical (_("Failed to update database: %s"), db.errmsg ());
95+ stmt.bind_int64 (stmt.bind_parameter_index (":session_id"), this.id);
96+ stmt.bind_int64 (stmt.bind_parameter_index (":tab_id"), tab_id);
97+ stmt.bind_int64 (stmt.bind_parameter_index (":tstamp"), time.to_unix ());
98+ if (stmt.step () != Sqlite.DONE)
99+ critical (_("Failed to update database: %s"), db.errmsg ());
100+ }
101+
102 public override void close() {
103+ base.close ();
104+
105 if (Session.open_sessions == 1)
106 return;
107
108@@ -213,7 +262,7 @@
109 public override Katze.Array get_tabs() {
110 Katze.Array tabs = new Katze.Array (typeof (Katze.Item));
111
112- string sqlcmd = "SELECT id, uri, title FROM tabs WHERE session_id = :session_id";
113+ string sqlcmd = "SELECT id, uri, title FROM tabs WHERE session_id = :session_id ORDER BY tstamp DESC";
114 Sqlite.Statement stmt;
115 if (this.db.prepare_v2 (sqlcmd, -1, out stmt, null) != Sqlite.OK)
116 critical (_("Failed to select from database: %s"), db.errmsg ());

Subscribers

People subscribed via source and target branches

to all changes: