From 24b3adfc9dd6d94baef85c670376ed78f3df2c30 Mon Sep 17 00:00:00 2001 From: Witold Filipczyk Date: Sun, 1 Sep 2024 14:19:48 +0200 Subject: [PATCH] [action] Added reopen-last-closed-tab action. Refs #309 The uri of the latest closed tab uri is remembered in struct terminal. And when the reopen-last-closed-tab action is executed, then uri is open in new tab in foreground. Only one is in memory. If you close two tabs, only on one of them can be reopened. No key is assigned to this action by default. --- src/config/actions-main.inc | 1 + src/terminal/tab.c | 9 +++++++++ src/terminal/terminal.c | 5 +++++ src/terminal/terminal.h | 3 +++ src/viewer/action.c | 8 ++++++++ 5 files changed, 26 insertions(+) diff --git a/src/config/actions-main.inc b/src/config/actions-main.inc index 98991b89..c74b112c 100644 --- a/src/config/actions-main.inc +++ b/src/config/actions-main.inc @@ -100,6 +100,7 @@ ACTION_(MAIN, "quit", QUIT, N__("Open a quit confirmation dialog box"), 0), ACTION_(MAIN, "really-quit", REALLY_QUIT, N__("Quit without confirmation"), 0), ACTION_(MAIN, "redraw", REDRAW, N__("Redraw the terminal"), 0), ACTION_(MAIN, "reload", RELOAD, N__("Reload the current page"), 0), +ACTION_(MAIN, "reopen-last-closed-tab", REOPEN_LAST_CLOSED_TAB, N__("Reopen last closed tab"), 0), ACTION_(MAIN, "rerender", RERENDER, N__("Re-render the current page"), 0), ACTION_(MAIN, "reset-form", RESET_FORM, N__("Reset form items to their initial values"), ACTION_REQUIRE_VIEW_STATE | ACTION_REQUIRE_LOCATION), ACTION_(MAIN, "resource-info", RESOURCE_INFO, N__("Show information about the currently used resources"), 0), diff --git a/src/terminal/tab.c b/src/terminal/tab.c index 045e5099..8b36fc10 100644 --- a/src/terminal/tab.c +++ b/src/terminal/tab.c @@ -15,6 +15,7 @@ #include "intl/libintl.h" #include "main/select.h" #include "protocol/uri.h" +#include "session/location.h" #include "session/session.h" #include "terminal/screen.h" #include "terminal/tab.h" @@ -186,6 +187,14 @@ really_close_tab(void *ses_) struct session *ses = (struct session *)ses_; struct terminal *term = ses->tab->term; struct window *current_tab = get_current_tab(term); + struct uri *uri = have_location(ses) ? cur_loc(ses)->vs.uri : ses->loading_uri; + + if (uri) { + if (term->closed_tab_uri) { + done_uri(term->closed_tab_uri); + } + term->closed_tab_uri = get_uri_reference(uri); + } if (ses->tab == current_tab) { int tabs_count = number_of_tabs(term); diff --git a/src/terminal/terminal.c b/src/terminal/terminal.c index 8245dd2f..3b011e26 100644 --- a/src/terminal/terminal.c +++ b/src/terminal/terminal.c @@ -286,6 +286,11 @@ destroy_terminal(struct terminal *term) } object_unlock(term->spec); + + if (term->closed_tab_uri) { + done_uri(term->closed_tab_uri); + } + mem_free(term); check_if_no_terminal(); } diff --git a/src/terminal/terminal.h b/src/terminal/terminal.h index 53c62f56..36e13918 100644 --- a/src/terminal/terminal.h +++ b/src/terminal/terminal.h @@ -2,6 +2,7 @@ #define EL__TERMINAL_TERMINAL_H #include "config/options.h" +#include "protocol/uri.h" #include "terminal/event.h" #include "util/lists.h" @@ -182,6 +183,8 @@ struct terminal { #endif int cell_width; int cell_height; + + struct uri *closed_tab_uri; }; #define do_not_ignore_next_mouse_event(term) \ diff --git a/src/viewer/action.c b/src/viewer/action.c index 31a61fb0..62a2a711 100644 --- a/src/viewer/action.c +++ b/src/viewer/action.c @@ -675,6 +675,14 @@ do_action(struct session *ses, main_action_T action_id, int verbose) close_all_tabs_but_current(ses); break; + case ACT_MAIN_REOPEN_LAST_CLOSED_TAB: + if (term->closed_tab_uri) { + open_uri_in_new_tab(ses, term->closed_tab_uri, 0, 1); + done_uri(term->closed_tab_uri); + term->closed_tab_uri = NULL; + } + break; + case ACT_MAIN_TAB_EXTERNAL_COMMAND: status = pass_uri_to_command(ses, doc_view, PASS_URI_TAB);