Revision: 1837 http://geany-plugins.svn.sourceforge.net/geany-plugins/?rev=1837&view=re... Author: colombanw Date: 2011-01-13 19:40:26 +0000 (Thu, 13 Jan 2011)
Log Message: ----------- WebHelper: Add support for keybindings (to come)
This uses Geany's keybinding mechanism, but also supports the keybindings in the other windows (actually, in the web view and inspector).
Modified Paths: -------------- trunk/geany-plugins/webhelper/src/Makefile.am trunk/geany-plugins/webhelper/src/gwh-browser.c trunk/geany-plugins/webhelper/src/gwh-plugin.c trunk/geany-plugins/webhelper/wscript_build
Added Paths: ----------- trunk/geany-plugins/webhelper/src/gwh-keybindings.c trunk/geany-plugins/webhelper/src/gwh-keybindings.h
Modified: trunk/geany-plugins/webhelper/src/Makefile.am =================================================================== --- trunk/geany-plugins/webhelper/src/Makefile.am 2011-01-13 19:39:51 UTC (rev 1836) +++ trunk/geany-plugins/webhelper/src/Makefile.am 2011-01-13 19:40:26 UTC (rev 1837) @@ -12,10 +12,12 @@
sources = gwh-browser.c \ + gwh-keybindings.c \ gwh-plugin.c \ gwh-settings.c \ gwh-utils.c headers = gwh-browser.h \ + gwh-keybindings.h \ gwh-plugin.h \ gwh-settings.h \ gwh-utils.h
Modified: trunk/geany-plugins/webhelper/src/gwh-browser.c =================================================================== --- trunk/geany-plugins/webhelper/src/gwh-browser.c 2011-01-13 19:39:51 UTC (rev 1836) +++ trunk/geany-plugins/webhelper/src/gwh-browser.c 2011-01-13 19:40:26 UTC (rev 1837) @@ -29,6 +29,7 @@
#include "gwh-utils.h" #include "gwh-settings.h" +#include "gwh-keybindings.h"
#if ! GTK_CHECK_VERSION (2, 18, 0) @@ -238,6 +239,7 @@ inspector_hide_window (self); gtk_toggle_tool_button_set_active (GTK_TOGGLE_TOOL_BUTTON (self->priv->item_inspector), FALSE); + gtk_widget_grab_focus (self->priv->web_view);
return TRUE; } @@ -838,6 +840,11 @@ g_signal_connect (G_OBJECT (self->priv->web_view), "scroll-event", G_CALLBACK (on_web_view_scroll_event), self);
+ g_signal_connect (self->priv->web_view, "key-press-event", + G_CALLBACK (gwh_keybindings_handle_event), self); + g_signal_connect (self->priv->inspector_view, "key-press-event", + G_CALLBACK (gwh_keybindings_handle_event), self); + gtk_widget_grab_focus (self->priv->url_entry);
g_signal_connect (self->priv->settings, "notify::browser-last-uri",
Added: trunk/geany-plugins/webhelper/src/gwh-keybindings.c =================================================================== --- trunk/geany-plugins/webhelper/src/gwh-keybindings.c (rev 0) +++ trunk/geany-plugins/webhelper/src/gwh-keybindings.c 2011-01-13 19:40:26 UTC (rev 1837) @@ -0,0 +1,91 @@ +/* + * + * Copyright (C) 2010-2011 Colomban Wendling ban@herbesfolles.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + * + */ + +#include "gwh-keybindings.h" + +#include <glib.h> +#include <gtk/gtk.h> + +#include <geanyplugin.h> +#include <geany.h> + +#include "gwh-plugin.h" + + +static GeanyKeyGroup *G_key_group; + + +void +gwh_keybindings_init (void) +{ + G_key_group = plugin_set_key_group (geany_plugin, "webhelper", GWH_KB_COUNT, + NULL); +} + +void +gwh_keybindings_cleanup (void) +{ + G_key_group = NULL; +} + +GeanyKeyGroup * +gwh_keybindings_get_group (void) +{ + return G_key_group; +} + +/** + * ghw_keybindings_handle_event: + * @widget: Unused, may be %NULL + * @event: A GdkEventKey to handle + * @data: Unused, may be %NULL + * + * Handles a GDK key event and calls corresponding keybindings callbacks. + * This function is meant to be used as the callback for a + * GtkWidget:key-press-event signal. + * + * Returns: Whether the event was handled or not + */ +gboolean +gwh_keybindings_handle_event (GtkWidget *widget, + GdkEventKey *event, + gpointer data) +{ + guint mods = event->state & gtk_accelerator_get_default_mod_mask (); + gboolean handled = FALSE; + guint i; + + for (i = 0; ! handled && i < GWH_KB_COUNT; i++) { + GeanyKeyBinding *kb; + + kb = keybindings_get_item (G_key_group, i); + if (kb->key == event->keyval && kb->mods == mods) { + if (kb->callback) { + kb->callback (i); + /* We can't handle key group callback since we can't acces key group + * fields. However, we don't use it so it's not a real problem. */ + /*} else if (G_key_group->callback) { + G_key_group->callback (i);*/ + } + handled = TRUE; + } + } + + return handled; +}
Added: trunk/geany-plugins/webhelper/src/gwh-keybindings.h =================================================================== --- trunk/geany-plugins/webhelper/src/gwh-keybindings.h (rev 0) +++ trunk/geany-plugins/webhelper/src/gwh-keybindings.h 2011-01-13 19:40:26 UTC (rev 1837) @@ -0,0 +1,51 @@ +/* + * + * Copyright (C) 2010-2011 Colomban Wendling ban@herbesfolles.org + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see http://www.gnu.org/licenses/. + * + */ + +#ifndef H_GWH_KEYBINDINGS +#define H_GWH_KEYBINDINGS + +#include <glib.h> +#include <gtk/gtk.h> + +#include <geanyplugin.h> +#include <geany.h> + +G_BEGIN_DECLS + + +enum { + GWH_KB_COUNT +}; + + +G_GNUC_INTERNAL +void gwh_keybindings_init (void); +G_GNUC_INTERNAL +void gwh_keybindings_cleanup (void); +G_GNUC_INTERNAL +GeanyKeyGroup *gwh_keybindings_get_group (void); +G_GNUC_INTERNAL +gboolean gwh_keybindings_handle_event (GtkWidget *widget G_GNUC_UNUSED, + GdkEventKey *event, + gpointer data G_GNUC_UNUSED); + + +G_END_DECLS + +#endif /* guard */
Modified: trunk/geany-plugins/webhelper/src/gwh-plugin.c =================================================================== --- trunk/geany-plugins/webhelper/src/gwh-plugin.c 2011-01-13 19:39:51 UTC (rev 1836) +++ trunk/geany-plugins/webhelper/src/gwh-plugin.c 2011-01-13 19:40:26 UTC (rev 1837) @@ -33,6 +33,7 @@ #include "gwh-browser.h" #include "gwh-settings.h" #include "gwh-plugin.h" +#include "gwh-keybindings.h"
GeanyPlugin *geany_plugin; @@ -296,6 +297,7 @@ plugin_module_make_resident (geany_plugin);
load_config (); + gwh_keybindings_init ();
G_browser = gwh_browser_new (); g_signal_connect (G_browser, "populate-popup", @@ -317,6 +319,7 @@ { detach_browser ();
+ gwh_keybindings_cleanup (); save_config (); }
Modified: trunk/geany-plugins/webhelper/wscript_build =================================================================== --- trunk/geany-plugins/webhelper/wscript_build 2011-01-13 19:39:51 UTC (rev 1836) +++ trunk/geany-plugins/webhelper/wscript_build 2011-01-13 19:40:26 UTC (rev 1837) @@ -27,11 +27,13 @@ name = 'WebHelper' sources = [ 'src/gwh-browser.c', + 'src/gwh-keybindings.c', 'src/gwh-plugin.c', 'src/gwh-settings.c', 'src/gwh-utils.c'] header = [ 'src/gwh-browser.h', + 'src/gwh-keybindings.h', 'src/gwh-plugin.h', 'src/gwh-settings.h', 'src/gwh-utils.h']
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
plugins-commits@lists.geany.org