Branch: refs/heads/master Author: Thomas Martitz thomas.martitz@student.htw-berlin.de Committer: Thomas Martitz thomas.martitz@student.htw-berlin.de Date: Wed, 13 Nov 2013 22:57:18 UTC Commit: 4cb69f39e0c202c122f3c6aee36ad075fcd90aed https://github.com/geany/geany-plugins/commit/4cb69f39e0c202c122f3c6aee36ad0...
Log Message: ----------- autoclose: Refactor so that "document-close" is not necessary.
The document-close handler was just to free data and disconnect handlers associated to the sci widget. The former can be simplified with g_object_set_data_full() and the signal handler will be disconnected anyway on widget destroy.
Modified Paths: -------------- autoclose/src/autoclose.c
Modified: autoclose/src/autoclose.c 23 files changed, 4 insertions(+), 19 deletions(-) =================================================================== @@ -780,9 +780,8 @@ struct_semicolon( if (!ac_info->jump_on_tab) return; g_return_if_fail(data); - g_return_if_fail(DOC_VALID(data->doc));
- ScintillaObject *sci = data->doc->editor->sci; + ScintillaObject *sci = SCINTILLA(obj); /* reset jump_on_tab state when user clicked away */ gboolean updated_sel = nt->updated & SC_UPDATE_SELECTION; gboolean updated_text = nt->updated & SC_UPDATE_CONTENT; @@ -801,8 +800,6 @@ struct_semicolon( data->last_line = new_line; }
-#define AC_GOBJECT_KEY "autoclose-userdata" - static void on_document_open(GObject *obj, GeanyDocument *doc, gpointer user_data) { @@ -814,29 +811,17 @@ struct_semicolon( data = g_new0(AutocloseUserData, 1); data->doc = doc; plugin_signal_connect(geany_plugin, G_OBJECT(sci), "sci-notify", - FALSE, G_CALLBACK(on_sci_notify), data); + FALSE, G_CALLBACK(on_sci_notify), data); plugin_signal_connect(geany_plugin, G_OBJECT(sci), "key-press-event", FALSE, G_CALLBACK(on_key_press), data); - /* save data pointer via GObject too for on_document_close() */ - g_object_set_data(G_OBJECT(sci), AC_GOBJECT_KEY, data); -} - -static void -on_document_close(GObject *obj, GeanyDocument *doc, gpointer user_data) -{ - /* free the AutocloseUserData instance and disconnect the handler */ - ScintillaObject *sci = doc->editor->sci; - AutocloseUserData *data = g_object_steal_data(G_OBJECT(sci), AC_GOBJECT_KEY); - /* no plugin_signal_disconnect() ?? */ - g_signal_handlers_disconnect_by_func(G_OBJECT(sci), G_CALLBACK(on_sci_notify), data); - g_free(data); + /* This will free the data when the sci is destroyed */ + g_object_set_data_full(G_OBJECT(sci), "autoclose-userdata", data, g_free); }
PluginCallback plugin_callbacks[] = { { "document-open", (GCallback) &on_document_open, FALSE, NULL }, { "document-new", (GCallback) &on_document_open, FALSE, NULL }, - { "document-close", (GCallback) &on_document_close, FALSE, NULL }, { NULL, NULL, FALSE, NULL } };
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
plugins-commits@lists.geany.org