Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: Colomban Wendling ban@herbesfolles.org Date: Tue, 21 Nov 2023 23:39:43 UTC Commit: d19aee697472477c0e53c12a75303121e47f5b64 https://github.com/geany/geany-plugins/commit/d19aee697472477c0e53c12a753031...
Log Message: ----------- webhelper: Add support for loading the current file in the web view
This is a somewhat popular request, which is easy enough to implement and can be handy when working on static HTML files.
Modified Paths: -------------- webhelper/src/gwh-browser.c webhelper/src/gwh-browser.h webhelper/src/gwh-keybindings.h webhelper/src/gwh-plugin.c
Modified: webhelper/src/gwh-browser.c 51 lines changed, 51 insertions(+), 0 deletions(-) =================================================================== @@ -31,6 +31,8 @@ #include <gtk/gtk.h> #include <webkit2/webkit2.h>
+#include <document.h> + #include "gwh-utils.h" #include "gwh-settings.h" #include "gwh-keybindings.h" @@ -271,6 +273,36 @@ on_url_entry_icon_press (GtkEntry *entry, } }
+static void +on_item_load_current_file_activate (GtkMenuItem *item, + GwhBrowser *self) +{ + gwh_browser_set_uri_from_document (self, document_get_current ()); +} + +static void +on_url_entry_populate_popup (GtkEntry *entry, + GtkWidget *menu, + GwhBrowser *self) +{ + GtkWidget *item; + GeanyDocument *doc = document_get_current (); + + /* separator */ + item = gtk_separator_menu_item_new (); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + gtk_widget_show (item); + + /* load current file item */ + item = gtk_menu_item_new_with_mnemonic (_("_Load current file")); + gtk_widget_set_sensitive (item, doc && doc->real_path); + g_signal_connect (item, "activate", + G_CALLBACK (on_item_load_current_file_activate), self); + gtk_menu_shell_append (GTK_MENU_SHELL (menu), item); + gtk_widget_show (item); + item_show_accelerator (item, GWH_KB_LOAD_CURRENT_FILE); +} + static gboolean on_entry_completion_match_selected (GtkEntryCompletion *comp, GtkTreeModel *model, @@ -773,6 +805,8 @@ create_toolbar (GwhBrowser *self) G_CALLBACK (on_url_entry_activate), self); g_signal_connect (G_OBJECT (self->priv->url_entry), "icon-press", G_CALLBACK (on_url_entry_icon_press), self); + g_signal_connect (G_OBJECT (self->priv->url_entry), "populate-popup", + G_CALLBACK (on_url_entry_populate_popup), self); g_signal_connect (G_OBJECT (self->priv->url_combo), "notify::active", G_CALLBACK (on_url_combo_active_notify), self); g_signal_connect (G_OBJECT (comp), "match-selected", @@ -972,6 +1006,23 @@ gwh_browser_set_uri (GwhBrowser *self, g_free (real_uri); }
+gboolean +gwh_browser_set_uri_from_document (GwhBrowser *self, + GeanyDocument *doc) +{ + gchar *uri; + + /* document must exist on disk */ + if (! doc || ! doc->real_path) + return FALSE; + + uri = g_strconcat ("file://", doc->file_name, NULL); + gwh_browser_set_uri (self, uri); + g_free (uri); + + return TRUE; +} + const gchar * gwh_browser_get_uri (GwhBrowser *self) {
Modified: webhelper/src/gwh-browser.h 5 lines changed, 5 insertions(+), 0 deletions(-) =================================================================== @@ -24,6 +24,8 @@ #include <gtk/gtk.h> #include <webkit2/webkit2.h>
+#include <document.h> + G_BEGIN_DECLS
@@ -69,6 +71,9 @@ G_GNUC_INTERNAL void gwh_browser_set_uri (GwhBrowser *self, const gchar *uri); G_GNUC_INTERNAL +gboolean gwh_browser_set_uri_from_document (GwhBrowser *self, + GeanyDocument *doc); +G_GNUC_INTERNAL const gchar *gwh_browser_get_uri (GwhBrowser *self); G_GNUC_INTERNAL GtkToolbar *gwh_browser_get_toolbar (GwhBrowser *self);
Modified: webhelper/src/gwh-keybindings.h 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -33,6 +33,7 @@ enum { GWH_KB_TOGGLE_INSPECTOR, GWH_KB_SHOW_HIDE_SEPARATE_WINDOW, GWH_KB_TOGGLE_BOOKMARK, + GWH_KB_LOAD_CURRENT_FILE, GWH_KB_COUNT };
Modified: webhelper/src/gwh-plugin.c 10 lines changed, 10 insertions(+), 0 deletions(-) =================================================================== @@ -300,6 +300,13 @@ on_kb_toggle_bookmark (guint key_id) } }
+static void +on_kb_load_current_file (guint key_id) +{ + gwh_browser_set_uri_from_document (GWH_BROWSER (G_browser), + document_get_current ()); +} +
static gchar * get_config_filename (void) @@ -460,6 +467,9 @@ plugin_init (GeanyData *data) keybindings_set_item (gwh_keybindings_get_group (), GWH_KB_TOGGLE_BOOKMARK, on_kb_toggle_bookmark, 0, 0, "toggle_bookmark", _("Toggle bookmark for the current website"), NULL); + keybindings_set_item (gwh_keybindings_get_group (), GWH_KB_LOAD_CURRENT_FILE, + on_kb_load_current_file, 0, 0, "load_current_file", + _("Load the current file in the web view"), NULL); }
void
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).