Allow to store multiple closed URLs #379.
authorDaniel Carl <danielcarl@gmx.de>
Wed, 26 Apr 2017 21:43:24 +0000 (23:43 +0200)
committerDaniel Carl <danielcarl@gmx.de>
Wed, 26 Apr 2017 21:43:24 +0000 (23:43 +0200)
Applied changes of 8ae4cadf58e46b3e9951fa89cf084bd2792984c3 in master
branch to new infrastructure.

doc/vimb.1
src/main.c
src/main.h
src/normal.c
src/setting.c

index 5029790..35316c8 100644 (file)
@@ -644,6 +644,10 @@ This completion starts by `/` or `?` in inputbox and performs a prefix
 comparison for further typed chars.
 .SH SETTINGS
 All settings listed below can be set with the `:set' command.
+.TP
+.B closed-max-items (int)
+Maximum number of stored last closed URLs.
+If closed-max-items is set to 0, closed URLs will not be stored.
 .SH FILES
 .TP
 .IR $XDG_CONFIG_HOME/vimb[/PROFILE]
@@ -660,7 +664,7 @@ Configuration file to set WebKit setting, some GUI styles and keybindings.
 Cookie store file.
 .TP
 .I closed
-Holds the URI of last closed browser windows.
+Holds the URIs of last closed browser windows.
 .TP
 .I history
 This file holds the history of unique opened URIs.
index dddb0f7..f6d6c9a 100644 (file)
@@ -600,6 +600,32 @@ static void client_destroy(Client *c)
 {
     Client *p;
     webkit_web_view_stop_loading(c->webview);
+
+    /* Write last URL into file for recreation.
+     * The URL is only stored if the closed-max-items is not 0 and the file
+     * exists. */
+    if (c->state.uri && vb.config.closed_max && vb.files[FILES_CLOSED]) {
+        char **lines;
+        GString *new;
+
+        /* The latest closed URL is written first and the surplus items are
+         * removed. */
+        lines = util_get_lines(vb.files[FILES_CLOSED]);
+        new   = g_string_new(c->state.uri);
+        g_string_append(new, "\n");
+        if (lines) {
+            int len, i;
+
+            len = g_strv_length(lines);
+            for (i = 0; i < len - 1 && i < vb.config.closed_max - 1; i++) {
+                g_string_append_printf(new, "%s\n", lines[i]);
+            }
+            g_strfreev(lines);
+        }
+        g_file_set_contents(vb.files[FILES_CLOSED], new->str, -1, NULL);
+        g_string_free(new, TRUE);
+    }
+
     gtk_widget_destroy(c->window);
 
     /* Look for the client in the list, if we searched through the list and
index 5124c99..19a593c 100644 (file)
@@ -259,6 +259,7 @@ struct Vimb {
     char        *profile;           /* profile name */
     struct {
         guint   history_max;
+        guint   closed_max;
     } config;
     GtkCssProvider *style_provider;
 };
index a951b6c..5a43836 100644 (file)
@@ -597,12 +597,15 @@ static VbResult normal_open_clipboard(Client *c, const NormalCmdInfo *info)
 static VbResult normal_open(Client *c, const NormalCmdInfo *info)
 {
     Arg a;
-    char *file;
+    if (!vb.files[FILES_CLOSED]) {
+        return RESULT_ERROR;
+    }
 
-    file = g_build_filename(util_get_config_dir(), FILE_CLOSED, NULL);
     a.i = info->key == 'U' ? TARGET_NEW : TARGET_CURRENT;
-    a.s = util_get_file_contents(file, NULL);
-    g_free(file);
+    a.s = util_file_pop_line(vb.files[FILES_CLOSED], NULL);
+    if (!a.s) {
+        return RESULT_ERROR;
+    }
 
     vb_load_uri(c, &a);
     g_free(a.s);
index f0752e8..62261cf 100644 (file)
@@ -141,6 +141,9 @@ void setting_init(Client *c)
     setting_add(c, "default-zoom", TYPE_INTEGER, &i, default_zoom, 0, NULL);
     setting_add(c, "download-path", TYPE_CHAR, &"~/", NULL, 0, NULL);
     setting_add(c, "incsearch", TYPE_BOOLEAN, &off, internal, 0, &c->config.incsearch);
+    i = 10;
+    /* TODO should be global and not overwritten by a new client */
+    setting_add(c, "closed-max-items", TYPE_INTEGER, &i, internal, 0, &vb.config.closed_max);
 
 #ifdef FEATURE_GUI_STYLE_VIMB2_COMPAT
     /* gui style settings vimb2 compatibility */