summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Dywan <christian@twotoasts.de>2019-07-07 15:33:07 +0200
committerGitHub <noreply@github.com>2019-07-07 15:33:07 +0200
commit747f77735c67fc5be9f60fe9a5ccdb12e4a47679 (patch)
treef44dcc0d8836ed859009686be1577ccfe8323702
parentb7656f5f7e74bf85758b4b4aff384716d2f23580 (diff)
downloadmidori-git-747f77735c67fc5be9f60fe9a5ccdb12e4a47679.tar.gz
(Re-)Store pinned state of tabs (#339)
The most interesting non-obvious detail here is that undelaying a pinned tab after creating it didn't work with the previous code. Fixes: #178
-rw-r--r--core/tab.vala6
-rw-r--r--data/tabby/Update2.sql1
-rw-r--r--extensions/session.vala14
-rw-r--r--gresource.xml1
4 files changed, 21 insertions, 1 deletions
diff --git a/core/tab.vala b/core/tab.vala
index 5e3baa1f..ac06bebe 100644
--- a/core/tab.vala
+++ b/core/tab.vala
@@ -53,6 +53,12 @@ namespace Midori {
item.title = display_title;
}
});
+ notify["pinned"].connect ((pspec) => {
+ // Undelay if needed
+ if (display_uri != uri) {
+ load_uri (display_uri);
+ }
+ });
}
public Tab (Tab? related, WebKit.WebContext web_context,
diff --git a/data/tabby/Update2.sql b/data/tabby/Update2.sql
new file mode 100644
index 00000000..743eb4c4
--- /dev/null
+++ b/data/tabby/Update2.sql
@@ -0,0 +1 @@
+ALTER TABLE tabs ADD pinned INTEGER DEFAULT 0;
diff --git a/extensions/session.vala b/extensions/session.vala
index 8307d5cc..80833104 100644
--- a/extensions/session.vala
+++ b/extensions/session.vala
@@ -50,7 +50,7 @@ namespace Tabby {
async List<Midori.DatabaseItem>? get_items (int64 session_id, string? filter=null, int64 max_items=15, Cancellable? cancellable=null) throws Midori.DatabaseError {
string where = filter != null ? "AND (uri LIKE :filter OR title LIKE :filter)" : "";
string sqlcmd = """
- SELECT id, uri, title, tstamp FROM %s
+ SELECT id, uri, title, tstamp, pinned FROM %s
WHERE session_id = :session_id %s
ORDER BY tstamp DESC LIMIT :limit
""".printf (table, where);
@@ -71,6 +71,7 @@ namespace Tabby {
item.database = this;
item.id = statement.get_int64 ("id");
item.set_data<int64> ("session_id", session_id);
+ item.set_data<int64> ("pinned", statement.get_int64 ("pinned"));
items.append (item);
uint src = Idle.add (get_items.callback);
@@ -182,6 +183,15 @@ namespace Tabby {
}
}
+ async void update_tab (Midori.DatabaseItem item) throws Midori.DatabaseError {
+ string sqlcmd = """
+ UPDATE %s SET pinned=:pinned WHERE rowid = :id
+ """.printf (table);
+ prepare (sqlcmd,
+ ":id", typeof (int64), item.id,
+ ":pinned", typeof (int64), item.get_data<int64> ("pinned")).exec ();
+ }
+
public async override bool clear (TimeSpan timespan) throws Midori.DatabaseError {
// Note: TimeSpan is defined in microseconds
int64 maximum_age = new DateTime.now_local ().to_unix () - timespan / 1000000;
@@ -215,6 +225,7 @@ namespace Tabby {
}
var tab = new Midori.Tab (null, browser.web_context,
item.uri, item.title);
+ tab.pinned = item.get_data<bool> ("pinned");
connect_tab (tab, item);
browser.add (tab);
}
@@ -257,6 +268,7 @@ namespace Tabby {
tab.set_data<Midori.DatabaseItem?> ("tabby-item", item);
tab.notify["uri"].connect ((pspec) => { item.uri = tab.uri; update.begin (item); });
tab.notify["title"].connect ((pspec) => { item.title = tab.title; });
+ tab.notify["pinned"].connect ((pspec) => { item.set_data<bool> ("pinned", tab.pinned); update_tab.begin (item); });
tab.close.connect (() => { tab_removed (tab); });
}
diff --git a/gresource.xml b/gresource.xml
index 3d41bdd5..596f524c 100644
--- a/gresource.xml
+++ b/gresource.xml
@@ -22,6 +22,7 @@
<file compressed="true">data/history/Day.sql</file>
<file compressed="true">data/tabby/Create.sql</file>
<file compressed="true">data/tabby/Update1.sql</file>
+ <file compressed="true">data/tabby/Update2.sql</file>
<file compressed="true" preprocess="xml-stripblanks">ui/about.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/bookmarks-button.ui</file>
<file compressed="true" preprocess="xml-stripblanks">ui/browser.ui</file>