Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: Colomban Wendling ban@herbesfolles.org Date: Tue, 11 Jun 2024 20:21:26 UTC Commit: 3106a938506c3b73e775d055025fb774aa828b80 https://github.com/geany/geany/commit/3106a938506c3b73e775d055025fb774aa828b...
Log Message: ----------- Do not create empty file filters
The xdg-desktop-portal file chooser implementation (that can be forced with `GTK_USE_PORTAL=1`) doesn't allow those and fails to create the dialog if there are any such filter.
This seems like a potential xdg-desktop-portal bug, but it's easy enough to workaround, and there's no guarantee yet it will change.
It's also unlikely to actually happen that we create such an empty filter, but it is possible if a filetype doesn't have a corresponding filetype_extensions.conf entry.
Modified Paths: -------------- src/dialogs.c src/filetypes.c
Modified: src/dialogs.c 12 lines changed, 7 insertions(+), 5 deletions(-) =================================================================== @@ -372,6 +372,7 @@ static GtkWidget *add_file_open_extra_widget(GtkWidget *dialog) static GtkFileChooser *create_open_file_dialog(void) { GtkFileChooser *dialog; + GtkFileFilter *filter; GtkWidget *viewbtn; GSList *node;
@@ -408,18 +409,19 @@ static GtkFileChooser *create_open_file_dialog(void) }
/* add FileFilters(start with "All Files") */ - gtk_file_chooser_add_filter(dialog, - filetypes_create_file_filter(filetypes[GEANY_FILETYPES_NONE])); + if ((filter = filetypes_create_file_filter(filetypes[GEANY_FILETYPES_NONE]))) + gtk_file_chooser_add_filter(dialog, filter); /* now create meta filter "All Source" */ - gtk_file_chooser_add_filter(dialog, - filetypes_create_file_filter_all_source()); + if ((filter = filetypes_create_file_filter_all_source())) + gtk_file_chooser_add_filter(dialog, filter); foreach_slist(node, filetypes_by_title) { GeanyFiletype *ft = node->data;
if (G_UNLIKELY(ft->id == GEANY_FILETYPES_NONE)) continue; - gtk_file_chooser_add_filter(dialog, filetypes_create_file_filter(ft)); + if ((filter = filetypes_create_file_filter(ft))) + gtk_file_chooser_add_filter(dialog, filter); }
gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);
Modified: src/filetypes.c 17 lines changed, 17 insertions(+), 0 deletions(-) =================================================================== @@ -1187,6 +1187,7 @@ GtkFileFilter *filetypes_create_file_filter_all_source(void) { GtkFileFilter *new_filter; guint i, j; + guint n_patterns = 0;
new_filter = gtk_file_filter_new(); gtk_file_filter_set_name(new_filter, _("All Source")); @@ -1200,7 +1201,16 @@ GtkFileFilter *filetypes_create_file_filter_all_source(void) { gtk_file_filter_add_pattern(new_filter, filetypes[i]->pattern[j]); } + n_patterns += j; } + + /* very unlikely case where there is *no* patterns at all */ + if (n_patterns == 0) + { + g_object_unref(new_filter); + new_filter = NULL; + } + return new_filter; }
@@ -1213,6 +1223,13 @@ GtkFileFilter *filetypes_create_file_filter(const GeanyFiletype *ft)
g_return_val_if_fail(ft != NULL, NULL);
+ /* unlikely case where the ft has no patterns */ + if (! ft->pattern[0]) + { + g_debug("Not creating filter for filetype %s that has no pattern", ft->name); + return NULL; + } + new_filter = gtk_file_filter_new(); title = ft->id == GEANY_FILETYPES_NONE ? _("All files") : ft->title; gtk_file_filter_set_name(new_filter, title);
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).