From 0dfd4655a98778c74ba2f3c2de135627acb84e01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ji=C5=99=C3=AD=20Techet?= Date: Tue, 19 Sep 2023 20:37:23 +0200 Subject: [PATCH] Add "document-before-save-as" signal Right now only the "document-save" is fired when performing "save as" which lacks the information about the original file name (which, for instance, is necessary for the LSP client where it needs to notify the server that the "old" document was closed and the document under the new name opened). --- doc/pluginsignals.c | 11 +++++++++++ src/document.c | 2 ++ src/geanyobject.c | 7 +++++++ src/geanyobject.h | 1 + 4 files changed, 21 insertions(+) diff --git a/doc/pluginsignals.c b/doc/pluginsignals.c index 7cd38ce543..ca50912ed1 100644 --- a/doc/pluginsignals.c +++ b/doc/pluginsignals.c @@ -92,6 +92,17 @@ signal void (*document_reload)(GObject *obj, GeanyDocument *doc, gpointer user_d */ signal void (*document_before_save)(GObject *obj, GeanyDocument *doc, gpointer user_data); +/** Sent before save as is performed with the original document. + * + * @param obj a GeanyObject instance, should be ignored. + * @param doc the original document. The document with the new file name is still + * reported by the "document-save" signal sent afterwards. + * @param user_data user data. + * + * @since 2.1 + */ +signal void (*document_before_save_as)(GObject *obj, GeanyDocument *doc, gpointer user_data); + /** Sent when a new document is saved. * * @param obj a GeanyObject instance, should be ignored. diff --git a/src/document.c b/src/document.c index 4cf74105b1..d03a88ea31 100644 --- a/src/document.c +++ b/src/document.c @@ -1836,6 +1836,8 @@ gboolean document_save_file_as(GeanyDocument *doc, const gchar *utf8_fname) g_return_val_if_fail(doc != NULL, FALSE); + g_signal_emit_by_name(geany_object, "document-before-save-as", doc); + new_file = document_need_save_as(doc) || (utf8_fname != NULL && strcmp(doc->file_name, utf8_fname) != 0); if (utf8_fname != NULL) SETPTR(doc->file_name, g_strdup(utf8_fname)); diff --git a/src/geanyobject.c b/src/geanyobject.c index 47999c09d5..0b3d996903 100644 --- a/src/geanyobject.c +++ b/src/geanyobject.c @@ -105,6 +105,13 @@ static void create_signals(GObjectClass *g_object_class) 0, NULL, NULL, g_cclosure_marshal_VOID__BOXED, G_TYPE_NONE, 1, GEANY_TYPE_DOCUMENT); + geany_object_signals[GCB_DOCUMENT_BEFORE_SAVE_AS] = g_signal_new ( + "document-before-save-as", + G_OBJECT_CLASS_TYPE (g_object_class), + G_SIGNAL_RUN_FIRST, + 0, NULL, NULL, g_cclosure_marshal_VOID__BOXED, + G_TYPE_NONE, 1, + GEANY_TYPE_DOCUMENT); geany_object_signals[GCB_DOCUMENT_SAVE] = g_signal_new ( "document-save", G_OBJECT_CLASS_TYPE (g_object_class), diff --git a/src/geanyobject.h b/src/geanyobject.h index e6cb988044..62d3524090 100644 --- a/src/geanyobject.h +++ b/src/geanyobject.h @@ -57,6 +57,7 @@ typedef enum GCB_SAVE_SETTINGS, GCB_LOAD_SETTINGS, GCB_KEY_PRESS_NOTIFY, + GCB_DOCUMENT_BEFORE_SAVE_AS, GCB_MAX } GeanyCallbackId;