Skip to content

Commit

Permalink
[action] Added reopen-last-closed-tab action. Refs #309
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
rkd77 committed Sep 1, 2024
1 parent 7025f8d commit 24b3adf
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/config/actions-main.inc
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
9 changes: 9 additions & 0 deletions src/terminal/tab.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/terminal/terminal.c
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
3 changes: 3 additions & 0 deletions src/terminal/terminal.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down Expand Up @@ -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) \
Expand Down
8 changes: 8 additions & 0 deletions src/viewer/action.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 24b3adf

Please sign in to comment.