Hello Geany Developers, I’m a software developer who has had fun using Geany for my own projects, so thank you for all the hard work you guys have been doing - I love it! Hopefully this is the right place to post this - if there is somewhere else I should post this additionally and/or instead let me know.
When playing around with modifying plugins I found a potential issue with document closing. The ‘document-close’ signal only supplies plugins with a document that has the ‘changed’ flag set if one document is closed, e.g. a user hit the 'x' on the UI document tab, but not when all documents are being closed, e.g. when quitting Geany, regardless of whether the ‘document’ has changes. The cause for this behavior appears to be the 'document_account_for_saved' function in document.c which sets the 'changed' flag to FALSE when closing all documents. I've attached a patch to this email that could address this. At the bottom of this email I've described the approach I took with this patch. If the patch doesn’t look good let me know what I can do to fix it, or if this behavior is expected, would love suggestions on how a plugin should be able to get this information when a document is being closed. I'm running Geany by installing it from source from the most recent version: 1.34., but the behavior I see is caused by functions and code which appear to have been around for awhile so I don't think this would be much different for previous versions. Thank you for any feedback you guys can give. Again really love the Geany project, and I’m glad you’ve made it possible to have fun coding without requiring shelling out massive amounts of money to use a really nice light-weight editor. Jason The approach in the patch is simple – remove the code that modifies the ‘changed’ flag in 'document_account_for_saved', and add a check in the ‘remove_page’ function for the ‘main_status.closing_all’ to avoid prompting the user when closing all documents. This flag gets set during ‘force_close_all’ which is only called in ‘document_close_all’, so I couldn’t find anything wrong with this approach – let me know if that is not the case. The only other change that was needed is in how ‘main_quit’ handles closing all documents to ensure the current behavior behavior isn’t changed when closing Geany, especially since it also calls ‘document_account_for_unsaved’. The approach I took to this was to remove the ‘document_account_for_unsaved’ out of the ‘main_quit’ function since this will be called with ‘project_close’ or ‘document_close_all’ in 'do_main_quit', and change the ‘do_main_quit’ function to use the return value from ‘project_close’ and/or ‘document_close_all’ to allow aborting the procedure if the user canceled and pass this back up to the ‘main_quit’ , or return TRUE at the end of the function call otherwise.
diff --git a/src/document.c b/src/document.c index d5d37b9b..1afacd5a 100644 --- a/src/document.c +++ b/src/document.c @@ -704,7 +704,7 @@ static gboolean remove_page(guint page_num) g_return_val_if_fail(doc != NULL, FALSE); - if (doc->changed && ! dialogs_show_unsaved_file(doc)) + if (! main_status.closing_all && doc->changed && ! dialogs_show_unsaved_file(doc)) return FALSE; /* tell any plugins that the document is about to be closed */ @@ -3387,11 +3387,7 @@ gboolean document_account_for_unsaved(void) return FALSE; } } - /* all documents should now be accounted for, so ignore any changes */ - foreach_document (i) - { - documents[i]->changed = FALSE; - } + return TRUE; } @@ -3400,14 +3396,6 @@ static void force_close_all(void) { guint i, len = documents_array->len; - /* check all documents have been accounted for */ - for (i = 0; i < len; i++) - { - if (documents[i]->is_valid) - { - g_return_if_fail(!documents[i]->changed); - } - } main_status.closing_all = TRUE; foreach_document(i) diff --git a/src/libmain.c b/src/libmain.c index b7cf745d..de531da5 100644 --- a/src/libmain.c +++ b/src/libmain.c @@ -1262,16 +1262,20 @@ static void queue_free(GQueue *queue) } -static void do_main_quit(void) +static gboolean do_main_quit(void) { geany_debug("Quitting..."); configuration_save(); if (app->project != NULL) - project_close(FALSE); /* save project session files */ + { + if (!project_close(FALSE)) /* save project session files */ + return FALSE; + } - document_close_all(); + if (!document_close_all()) + return FALSE; main_status.quitting = TRUE; @@ -1364,6 +1368,8 @@ static void do_main_quit(void) ui_finalize_builder(); gtk_main_quit(); + + return TRUE; } @@ -1389,19 +1395,16 @@ gboolean main_quit(void) if (! check_no_unsaved()) { - if (document_account_for_unsaved()) - { - do_main_quit(); + if (do_main_quit()) return TRUE; - } } else if (! prefs.confirm_exit || dialogs_show_question_full(NULL, GTK_STOCK_QUIT, GTK_STOCK_CANCEL, NULL, _("Do you really want to quit?"))) { - do_main_quit(); - return TRUE; + if (do_main_quit()) + return TRUE; } main_status.quitting = FALSE;
_______________________________________________ Devel mailing list Devel@lists.geany.org https://lists.geany.org/cgi-bin/mailman/listinfo/devel