Skip to content

Commit

Permalink
Merge pull request geany#3572 from techee/document_before_save_as
Browse files Browse the repository at this point in the history
Add "document-before-save-as" signal
  • Loading branch information
techee authored Jun 12, 2024
2 parents a096404 + 0dfd465 commit 37e8618
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 @@ -1835,6 +1835,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 37e8618

Please sign in to comment.