Kaydet (Commit) 38a0e4f5 authored tarafından Jiří Techet's avatar Jiří Techet Kaydeden (comit) elextr

Allow plugins to process keypress events before Geany (#1829)

In addition, the signal allows plugins swallow the event so it's not
processed by Geany.
üst 07643499
......@@ -270,3 +270,23 @@ signal void (*update_editor_menu)(GObject *obj, const gchar *word, gint pos, Gea
*/
signal gboolean (*editor_notify)(GObject *obj, GeanyEditor *editor, SCNotification *nt,
gpointer user_data);
/** Sent whenever a key is pressed.
*
* This signal allows plugins to receive key press events before they are processed
* by Geany. Plugins can then process key presses before Geany and decide,
* whether Geany should receive the key press event or not.
*
* @warning This signal should be used carefully. If multiple plugins use this
* signal, the result could be unpredictble depending on which plugin
* receives the signal first.
*
* @param obj a GeanyObject instance, should be ignored.
* @param key The GdkEventKey corresponding to the key press.
* @param user_data user data.
* @return @c TRUE to stop other handlers from being invoked for the event.
* @c FALSE to propagate the event further.
*
* @since 1.34
*/
signal gboolean (*key_press)(GObject *obj, GdkEventKey *key, gpointer user_data);
......@@ -229,6 +229,15 @@ static void create_signals(GObjectClass *g_object_class)
0, NULL, NULL, g_cclosure_marshal_VOID__BOXED,
G_TYPE_NONE, 1,
G_TYPE_KEY_FILE);
/* Key press signal */
geany_object_signals[GCB_KEY_PRESS_NOTIFY] = g_signal_new (
"key-press",
G_OBJECT_CLASS_TYPE (g_object_class),
G_SIGNAL_RUN_LAST,
0, boolean_handled_accumulator, NULL, NULL,
G_TYPE_BOOLEAN, 1,
GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE);
}
......
......@@ -57,6 +57,7 @@ typedef enum
GCB_BUILD_START,
GCB_SAVE_SETTINGS,
GCB_LOAD_SETTINGS,
GCB_KEY_PRESS_NOTIFY,
GCB_MAX
}
GeanyCallbackId;
......
......@@ -38,6 +38,7 @@
#include "callbacks.h"
#include "documentprivate.h"
#include "filetypes.h"
#include "geanyobject.h"
#include "keybindingsprivate.h"
#include "main.h"
#include "msgwindow.h"
......@@ -1350,10 +1351,15 @@ static gboolean on_key_press_event(GtkWidget *widget, GdkEventKey *ev, gpointer
GeanyDocument *doc;
GeanyKeyGroup *group;
GeanyKeyBinding *kb;
gboolean key_press_ret;
if (ev->keyval == 0)
return FALSE;
g_signal_emit_by_name(geany_object, "key-press", ev, &key_press_ret);
if (key_press_ret)
return TRUE;
doc = document_get_current();
if (doc)
document_check_disk_status(doc, FALSE);
......
......@@ -59,7 +59,7 @@ G_BEGIN_DECLS
* @warning You should not test for values below 200 as previously
* @c GEANY_API_VERSION was defined as an enum value, not a macro.
*/
#define GEANY_API_VERSION 236
#define GEANY_API_VERSION 237
/* hack to have a different ABI when built with GTK3 because loading GTK2-linked plugins
* with GTK3-linked Geany leads to crash */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment