From: Daniel Carl Date: Sun, 6 Jan 2013 19:13:46 +0000 (+0100) Subject: Save last closed page into file (#9). X-Git-Url: https://git.owens.tech/assets/static/git-logo.png/assets/static/git-logo.png/git?a=commitdiff_plain;h=462f8539e1571ad4dd8629bc1ed5e388df50ff7f;p=vimb.git Save last closed page into file (#9). Added command to reopen the last closed page 'open-closed' and 'tabopen-closed'. --- diff --git a/doc/vimp.1.txt b/doc/vimp.1.txt index c6c816d..5212ce5 100644 --- a/doc/vimp.1.txt +++ b/doc/vimp.1.txt @@ -66,6 +66,12 @@ Opens the configured 'home-page' into current window. .TP .B tabopen-home Opens the home page into a new window. +.TP +.B open-closed +Open the last closed page into current window. +.TP +.B tabopen-closed +Open the last closed page into new window. .SS Input Switches the browser into Command Mode and prefill the inputbox on th bottom of the browser with various prefilled content. diff --git a/src/command.c b/src/command.c index 10801a6..58abc48 100644 --- a/src/command.c +++ b/src/command.c @@ -26,10 +26,12 @@ static CommandInfo cmd_list[] = { /* command function arg mode */ - {"open", command_open, {VP_TARGET_CURRENT, ""}, VP_MODE_NORMAL}, - {"tabopen", command_open, {VP_TARGET_NEW, ""}, VP_MODE_NORMAL}, - {"open-home", command_open_home, {VP_TARGET_CURRENT, ""}, VP_MODE_NORMAL}, - {"tabopen-home", command_open_home, {VP_TARGET_NEW, ""}, VP_MODE_NORMAL}, + {"open", command_open, {VP_TARGET_CURRENT}, VP_MODE_NORMAL}, + {"tabopen", command_open, {VP_TARGET_NEW}, VP_MODE_NORMAL}, + {"open-home", command_open_home, {VP_TARGET_CURRENT}, VP_MODE_NORMAL}, + {"tabopen-home", command_open_home, {VP_TARGET_NEW}, VP_MODE_NORMAL}, + {"open-closed", command_open_closed, {VP_TARGET_CURRENT}, VP_MODE_NORMAL}, + {"tabopen-closed", command_open_closed, {VP_TARGET_NEW}, VP_MODE_NORMAL}, {"input", command_input, {0, ":"}, VP_MODE_COMMAND}, {"inputopen", command_input, {0, ":open "}, VP_MODE_COMMAND}, {"inputtabopen", command_input, {0, ":tabopen "}, VP_MODE_COMMAND}, @@ -129,11 +131,22 @@ gboolean command_open(const Arg* arg) } gboolean command_open_home(const Arg* arg) +{ + Arg a = {arg->i, vp.config.home_page}; + return vp_load_uri(&a); +} + +/** + * Reopens the last closed page. + */ +gboolean command_open_closed(const Arg* arg) { gboolean result; - Arg a = {.i = arg->i, .s = vp.config.home_page}; + Arg a = {arg->i}; + g_file_get_contents(vp.files[FILES_CLOSED], &a.s, NULL, NULL); result = vp_load_uri(&a); + g_free(a.s); return result; } diff --git a/src/command.h b/src/command.h index 62fc6d7..8c5a235 100644 --- a/src/command.h +++ b/src/command.h @@ -44,6 +44,7 @@ gboolean command_run(const gchar* name, const gchar* param); gboolean command_open(const Arg* arg); gboolean command_open_home(const Arg* arg); +gboolean command_open_closed(const Arg* arg); gboolean command_input(const Arg* arg); gboolean command_close(const Arg* arg); gboolean command_view_source(const Arg* arg); diff --git a/src/config.h b/src/config.h index 045ed54..dd30068 100644 --- a/src/config.h +++ b/src/config.h @@ -36,6 +36,8 @@ const struct { {"nmap T=inputtabopencurrent"}, {"nmap gh=open-home"}, {"nmap gH=tabopen-home"}, + {"nmap u=open-closed"}, + {"nmap U=tabopen-closed"}, {"nmap d=quit"}, {"nmap =back"}, {"nmap =forward"}, diff --git a/src/main.c b/src/main.c index f37c337..c345f8a 100644 --- a/src/main.c +++ b/src/main.c @@ -334,6 +334,12 @@ static const gchar* vp_get_cookies(SoupURI *uri) void vp_clean_up(void) { + const gchar* uri = CURRENT_URL(); + /* write last URL into file for recreation */ + if (uri) { + g_file_set_contents(vp.files[FILES_CLOSED], uri, -1, NULL); + } + if (vp.behave.commands) { g_hash_table_destroy(vp.behave.commands); vp.behave.commands = NULL; @@ -662,6 +668,9 @@ static void vp_init_files(void) vp.files[FILES_COOKIE] = g_build_filename(path, "cookies", NULL); util_create_file_if_not_exists(vp.files[FILES_COOKIE]); + vp.files[FILES_CLOSED] = g_build_filename(path, "closed", NULL); + util_create_file_if_not_exists(vp.files[FILES_CLOSED]); + g_free(path); } diff --git a/src/main.h b/src/main.h index d36cb55..031f71c 100644 --- a/src/main.h +++ b/src/main.h @@ -151,6 +151,7 @@ enum { FILES_FIRST = 0, FILES_CONFIG = 0, FILES_COOKIE, + FILES_CLOSED, FILES_LAST };