From a90347ab617bd09a4376c2609cd84e409c4031c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Tr=C3=B6ger?= Date: Sun, 29 Oct 2017 15:15:21 +0100 Subject: [PATCH 1/2] Connect button-press signal handlers on plugin activation If the plugin gets activated *after* Geany has been started already, we need to iterate all open documents and attach the "button-press" signal handler. Fixes #638. --- addons/src/ao_markword.c | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/addons/src/ao_markword.c b/addons/src/ao_markword.c index 5a0650ebd..90e15e1fc 100644 --- a/addons/src/ao_markword.c +++ b/addons/src/ao_markword.c @@ -65,6 +65,7 @@ enum static void ao_mark_word_finalize (GObject *object); +static void connect_documents_button_press_signal_handler(AoMarkWord *mw); G_DEFINE_TYPE(AoMarkWord, ao_mark_word, G_TYPE_OBJECT) @@ -78,6 +79,13 @@ static void ao_mark_word_set_property(GObject *object, guint prop_id, { case PROP_ENABLE_MARKWORD: priv->enable_markword = g_value_get_boolean(value); + /* if the plugin is loaded while Geany is already running, we need to connect the + * button press signal for open documents, if Geany is just booting, + * it happens automatically */ + if (main_is_realized()) + { + connect_documents_button_press_signal_handler(AO_MARKWORD(object)); + } break; case PROP_ENABLE_MARKWORD_SINGLE_CLICK_DESELECT: priv->enable_single_click_deselect = g_value_get_boolean(value); @@ -197,14 +205,7 @@ void ao_mark_editor_notify(AoMarkWord *mw, GeanyEditor *editor, SCNotification * } -void ao_mark_document_new(AoMarkWord *mw, GeanyDocument *document) -{ - /* there is nothing different to handling open documents, so do the same */ - ao_mark_document_open(mw, document); -} - - -void ao_mark_document_open(AoMarkWord *mw, GeanyDocument *document) +static void connect_document_button_press_signal_handler(AoMarkWord *mw, GeanyDocument *document) { g_return_if_fail(DOC_VALID(document)); @@ -218,6 +219,29 @@ void ao_mark_document_open(AoMarkWord *mw, GeanyDocument *document) } +static void connect_documents_button_press_signal_handler(AoMarkWord *mw) +{ + guint i = 0; + /* connect the button-press event for all open documents */ + foreach_document(i) + { + connect_document_button_press_signal_handler(mw, documents[i]); + } +} + + +void ao_mark_document_new(AoMarkWord *mw, GeanyDocument *document) +{ + connect_document_button_press_signal_handler(mw, document); +} + + +void ao_mark_document_open(AoMarkWord *mw, GeanyDocument *document) +{ + connect_document_button_press_signal_handler(mw, document); +} + + void ao_mark_document_close(AoMarkWord *mw, GeanyDocument *document) { g_return_if_fail(DOC_VALID(document)); From 71e26d8f69092ddaa2da305bb3cee4f76378a8b5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Enrico=20Tr=C3=B6ger?= Date: Sun, 29 Oct 2017 23:03:35 +0100 Subject: [PATCH 2/2] Connect button press handler to open documents only if activated --- addons/src/ao_markword.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/src/ao_markword.c b/addons/src/ao_markword.c index 90e15e1fc..84d811a69 100644 --- a/addons/src/ao_markword.c +++ b/addons/src/ao_markword.c @@ -82,7 +82,7 @@ static void ao_mark_word_set_property(GObject *object, guint prop_id, /* if the plugin is loaded while Geany is already running, we need to connect the * button press signal for open documents, if Geany is just booting, * it happens automatically */ - if (main_is_realized()) + if (priv->enable_markword && main_is_realized()) { connect_documents_button_press_signal_handler(AO_MARKWORD(object)); }