Skip to content

Commit f5fde28

Browse files
committed
Add keybindings for opening history and downloads
1 parent b7bbe2d commit f5fde28

3 files changed

Lines changed: 41 additions & 8 deletions

File tree

src/wig-application.c

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,28 @@ static void wig_application_add_new_tab_with_uri(WigApplication *app, WigWindow
7373
webkit_web_view_load_uri(web_view, uri);
7474
}
7575

76+
void wig_application_open_internal_page(WigApplication *app, GtkWindow *win, const char *uri)
77+
{
78+
if (win && wig_window_focus_tab_by_site(WIG_WINDOW(win), uri))
79+
return;
80+
81+
for (GList *l = gtk_application_get_windows(GTK_APPLICATION(app)); l; l = l->next) {
82+
if (l->data == win)
83+
continue;
84+
85+
if (wig_window_focus_tab_by_site(WIG_WINDOW(l->data), uri)) {
86+
gtk_window_present(GTK_WINDOW(l->data));
87+
return;
88+
}
89+
}
90+
91+
if (!win)
92+
win = gtk_application_get_active_window(GTK_APPLICATION(app));
93+
94+
if (win)
95+
wig_application_add_new_tab_with_uri(app, WIG_WINDOW(win), uri);
96+
}
97+
7698
static gboolean uri_should_be_recorded(const char *uri)
7799
{
78100
if (!uri || !*uri)
@@ -230,13 +252,7 @@ static gboolean on_decide_destination(WebKitDownload *download, const char *sugg
230252
g_autofree char *path = g_build_filename(dir ? dir : fallback, suggested_filename, NULL);
231253
webkit_download_set_destination(download, path);
232254

233-
for (GList *l = gtk_application_get_windows(GTK_APPLICATION(app)); l; l = l->next) {
234-
if (wig_window_focus_tab_by_site(WIG_WINDOW(l->data), "wig:downloads"))
235-
return TRUE;
236-
}
237-
238-
GtkWindow *active = gtk_application_get_active_window(GTK_APPLICATION(app));
239-
wig_application_add_new_tab_with_uri(app, WIG_WINDOW(active), "wig:downloads");
255+
wig_application_open_internal_page(app, NULL, "wig:downloads");
240256
return TRUE;
241257
}
242258

@@ -426,6 +442,8 @@ static void wig_application_startup(GApplication *application)
426442
{ "win.find", { "<Primary>f", NULL } },
427443
{ "win.find-next", { "<Primary>g", "F3", NULL } },
428444
{ "win.find-previous", { "<Primary><Shift>g", "<Shift>F3", NULL } },
445+
{ "win.show-downloads", { "<Primary>j", NULL } },
446+
{ "win.show-history", { "<Primary>h", NULL } },
429447

430448
};
431449

src/wig-application.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,8 @@ WPEDisplay *wig_application_get_display(WigApplication *app);
7676
WebKitNetworkSession *wig_application_get_network_session(WigApplication *app);
7777
WebKitWebView *wig_application_create_web_view(WigApplication *app);
7878
WigHistoryStore *wig_application_get_history_store(WigApplication *app);
79+
void wig_application_open_internal_page(WigApplication *app, GtkWindow *win, const char *uri);
80+
7981
void wig_application_mark_typed_navigation(WigApplication *app, WebKitWebView *web_view, const char *uri);
8082
void wig_application_mark_internal_navigation(WigApplication *app, WebKitWebView *web_view, const char *uri);
8183
gboolean wig_application_take_internal_navigation(WigApplication *app, WebKitWebView *web_view, const char *uri);

src/wig-window.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,6 +483,16 @@ static void wig_window_search_bar_closed(WigSearchBar *search_bar, WigWindow *wi
483483
gtk_widget_grab_focus(wig_tab_get_widget(tab));
484484
}
485485

486+
static void wig_window_show_downloads(GSimpleAction *action, GVariant *parameter, gpointer user_data)
487+
{
488+
wig_application_open_internal_page(wig_application_get(), GTK_WINDOW(user_data), "wig:downloads");
489+
}
490+
491+
static void wig_window_show_history(GSimpleAction *action, GVariant *parameter, gpointer user_data)
492+
{
493+
wig_application_open_internal_page(wig_application_get(), GTK_WINDOW(user_data), "wig:history");
494+
}
495+
486496
static void wig_window_close_tab_action(GSimpleAction *action, GVariant *parameter, gpointer user_data)
487497
{
488498
WigWindow *win = WIG_WINDOW(user_data);
@@ -834,6 +844,8 @@ static const GActionEntry actions[] = {
834844
{ "find", wig_window_find },
835845
{ "find-next", wig_window_find_next },
836846
{ "find-previous", wig_window_find_previous },
847+
{ "show-downloads", wig_window_show_downloads },
848+
{ "show-history", wig_window_show_history },
837849
{ "close-tab", wig_window_close_tab_action },
838850
{ "reload", wig_window_reload },
839851
{ "reload-bypass-cache", wig_window_reload_bypass_cache },
@@ -1753,5 +1765,6 @@ void wig_window_add_web_view(WigWindow *win, WebKitWebView *web_view)
17531765
g_return_if_fail(WIG_IS_WINDOW(win));
17541766
g_return_if_fail(WEBKIT_IS_WEB_VIEW(web_view));
17551767

1756-
wig_window_add_tab_for_view(win, web_view);
1768+
WigTab *tab = wig_window_add_tab_for_view(win, web_view);
1769+
wig_tab_list_set_active(win->tab_list, tab);
17571770
}

0 commit comments

Comments
 (0)