Branch: refs/heads/master Author: Jiří Techet techet@gmail.com Committer: Jiří Techet techet@gmail.com Date: Tue, 12 Nov 2024 19:39:57 UTC Commit: 87cdc362bfe480f830c97ac009d328978156c887 https://github.com/geany/geany/commit/87cdc362bfe480f830c97ac009d328978156c8...
Log Message: ----------- Make "Find" the default button in the wrap search dialog
When the "Wrap search and find again?" dialog appears, it makes more sense to wrap instead of cancel the dialog by default (the dialog can always be canceled by Escape).
The implementation of this patch more or less duplicates the code of dialogs_show_question_full() and makes the Find button default. While it would be possible to add one more parameter to dialogs_show_question_full() controlling this behavior, there's currently no other use of this in Geany (in all other cases, the action button performs a destructive action so Cancel is default) so I believe having this local implementation of the dialog is a better option not complicating other uses.
Fixes #1192.
Modified Paths: -------------- src/document.c
Modified: src/document.c 39 lines changed, 37 insertions(+), 2 deletions(-) =================================================================== @@ -2307,6 +2307,42 @@ gboolean document_search_bar_find(GeanyDocument *doc, const gchar *text, gboolea }
+/* like dialogs_show_question_full() but makes the non-cancel button default */ +static gboolean show_wrap_search_dialog(GtkWidget *parent, const gchar *search_text) +{ + gboolean ret; + GtkWidget *dialog; + GtkWidget *btn; + gchar *question_text; + + if (parent == NULL && main_status.main_window_realized) + parent = main_widgets.window; + + question_text = g_strdup_printf(_(""%s" was not found."), search_text); + + dialog = gtk_message_dialog_new(GTK_WINDOW(parent), + GTK_DIALOG_DESTROY_WITH_PARENT, GTK_MESSAGE_QUESTION, + GTK_BUTTONS_NONE, "%s", question_text); + gtk_widget_set_name(dialog, "GeanyDialog"); + gtk_window_set_title(GTK_WINDOW(dialog), _("Question")); + gtk_window_set_icon_name(GTK_WINDOW(dialog), "geany"); + + gtk_message_dialog_format_secondary_text(GTK_MESSAGE_DIALOG(dialog), + "%s", _("Wrap search and find again?")); + + gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_CANCEL, GTK_RESPONSE_NO); + btn = gtk_dialog_add_button(GTK_DIALOG(dialog), GTK_STOCK_FIND, GTK_RESPONSE_YES); + gtk_widget_grab_default(btn); + + ret = gtk_dialog_run(GTK_DIALOG(dialog)); + + gtk_widget_destroy(dialog); + g_free(question_text); + + return ret == GTK_RESPONSE_YES; +} + + /* General search function, used from the find dialog. * Returns -1 on failure or the start position of the matching text. * Will skip past any selection, ignoring it. @@ -2370,8 +2406,7 @@ gint document_find_text(GeanyDocument *doc, const gchar *text, const gchar *orig
/* we searched only part of the document, so ask whether to wraparound. */ if (search_prefs.always_wrap || - dialogs_show_question_full(parent, GTK_STOCK_FIND, GTK_STOCK_CANCEL, - _("Wrap search and find again?"), _(""%s" was not found."), original_text)) + show_wrap_search_dialog(parent, original_text)) { gint ret;
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).