1
0
mirror of https://github.com/rkd77/elinks.git synced 2024-09-19 01:36:33 -04:00

[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.
This commit is contained in:
Witold Filipczyk 2024-09-01 14:19:48 +02:00
parent 7025f8da92
commit 24b3adfc9d
5 changed files with 26 additions and 0 deletions

View File

@ -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, "really-quit", REALLY_QUIT, N__("Quit without confirmation"), 0),
ACTION_(MAIN, "redraw", REDRAW, N__("Redraw the terminal"), 0), ACTION_(MAIN, "redraw", REDRAW, N__("Redraw the terminal"), 0),
ACTION_(MAIN, "reload", RELOAD, N__("Reload the current page"), 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, "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, "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), ACTION_(MAIN, "resource-info", RESOURCE_INFO, N__("Show information about the currently used resources"), 0),

View File

@ -15,6 +15,7 @@
#include "intl/libintl.h" #include "intl/libintl.h"
#include "main/select.h" #include "main/select.h"
#include "protocol/uri.h" #include "protocol/uri.h"
#include "session/location.h"
#include "session/session.h" #include "session/session.h"
#include "terminal/screen.h" #include "terminal/screen.h"
#include "terminal/tab.h" #include "terminal/tab.h"
@ -186,6 +187,14 @@ really_close_tab(void *ses_)
struct session *ses = (struct session *)ses_; struct session *ses = (struct session *)ses_;
struct terminal *term = ses->tab->term; struct terminal *term = ses->tab->term;
struct window *current_tab = get_current_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) { if (ses->tab == current_tab) {
int tabs_count = number_of_tabs(term); int tabs_count = number_of_tabs(term);

View File

@ -286,6 +286,11 @@ destroy_terminal(struct terminal *term)
} }
object_unlock(term->spec); object_unlock(term->spec);
if (term->closed_tab_uri) {
done_uri(term->closed_tab_uri);
}
mem_free(term); mem_free(term);
check_if_no_terminal(); check_if_no_terminal();
} }

View File

@ -2,6 +2,7 @@
#define EL__TERMINAL_TERMINAL_H #define EL__TERMINAL_TERMINAL_H
#include "config/options.h" #include "config/options.h"
#include "protocol/uri.h"
#include "terminal/event.h" #include "terminal/event.h"
#include "util/lists.h" #include "util/lists.h"
@ -182,6 +183,8 @@ struct terminal {
#endif #endif
int cell_width; int cell_width;
int cell_height; int cell_height;
struct uri *closed_tab_uri;
}; };
#define do_not_ignore_next_mouse_event(term) \ #define do_not_ignore_next_mouse_event(term) \

View File

@ -675,6 +675,14 @@ do_action(struct session *ses, main_action_T action_id, int verbose)
close_all_tabs_but_current(ses); close_all_tabs_but_current(ses);
break; 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: case ACT_MAIN_TAB_EXTERNAL_COMMAND:
status = pass_uri_to_command(ses, doc_view, status = pass_uri_to_command(ses, doc_view,
PASS_URI_TAB); PASS_URI_TAB);