Skip to content

Commit

Permalink
Add "document-before-save-as" signal
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
techee committed May 11, 2024
1 parent 2dc8c22 commit 0dfd465
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 0 deletions.
11 changes: 11 additions & 0 deletions doc/pluginsignals.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 2 additions & 0 deletions src/document.c
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down
7 changes: 7 additions & 0 deletions src/geanyobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions src/geanyobject.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ typedef enum
GCB_SAVE_SETTINGS,
GCB_LOAD_SETTINGS,
GCB_KEY_PRESS_NOTIFY,
GCB_DOCUMENT_BEFORE_SAVE_AS,
GCB_MAX
}
GeanyCallbackId;
Expand Down

0 comments on commit 0dfd465

Please sign in to comment.