[Github-comments] [geany/geany] Add reload all keybinding (#2859)
Enrico Tröger
notifications at xxxxx
Thu Aug 12 21:54:13 UTC 2021
@eht16 commented on this pull request.
> @@ -335,6 +335,21 @@ void on_toolbutton_reload_clicked(GtkAction *action, gpointer user_data)
document_reload_prompt(doc, NULL);
}
+/* reload all files */
+void on_toolbutton_reload_all_clicked(GtkAction *action, gpointer user_data)
+{
+ guint i;
+ gint cur_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(main_widgets.notebook));
+
+ foreach_document(i)
+ {
+ if (! (documents[i]->file_name == NULL))
After having a closer look and some testing, the logic and dialog response handling is a litte wrong:
combining the conditions to show the dialog and handling its response in a single if statement is error prone if not impossible. The current implementation doesn't work properly.
As a suggestion, I rewrote the condition handling as follows:
```diff
diff --git a/src/callbacks.c b/src/callbacks.c
index acbd8737..487c48ac 100644
--- a/src/callbacks.c
+++ b/src/callbacks.c
@@ -340,27 +340,35 @@ void on_reload_all(GtkAction *action, gpointer user_data)
{
guint i;
gint cur_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(main_widgets.notebook));
-
+
if (!file_prefs.keep_edit_history_on_reload)
{
+ GeanyDocument *doc;
foreach_document(i)
{
- if (!(documents[i]->changed || (document_can_undo(documents[i]) ||
- document_can_redo(documents[i]))) && dialogs_show_question_full(NULL,
- _("_Reload"), GTK_STOCK_CANCEL, _("Any unsaved changes will be lost."),
- _("Are you sure you want to reload all files?")))
- break;
- else
- return;
+ doc = documents[i];
+ if (doc->changed || document_can_undo(doc) || document_can_redo(doc))
+ {
+ if (dialogs_show_question_full(NULL, _("_Reload"), GTK_STOCK_CANCEL,
+ _("Any unsaved changes will be lost."),
+ _("Are you sure you want to reload all files?")))
+ {
+ break; // break the loop and continue with reloading below
+ }
+ else
+ {
+ return; // cancel reloading
+ }
+ }
}
}
-
+
foreach_document(i)
{
if (! (documents[i]->file_name == NULL))
document_reload_force(documents[i], documents[i]->encoding);
}
-
+
gtk_notebook_set_current_page(GTK_NOTEBOOK(main_widgets.notebook), cur_page);
}
```
This is a bit more verbose but IMO easier to read and understand.
Btw, stripping trailing spaces is always a good idea (at least for Geany code :D).
--
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/geany/geany/pull/2859#discussion_r688110422
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.geany.org/pipermail/github-comments/attachments/20210812/7bf47e0d/attachment.htm>
More information about the Github-comments
mailing list