diff options
author | Matthias Clasen <mclasen@redhat.com> | 2020-07-04 12:15:47 -0400 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2020-07-06 10:36:35 -0400 |
commit | 76290e8ddb7001165e9f245730346de84e773058 (patch) | |
tree | 1921478791dbee38eba5eea86f6bd336ab1cdf13 /gtk/gtkfilechoosernativequartz.c | |
parent | 1a613de2f68e28827679340d2ec3bdef32acfed6 (diff) | |
download | gtk+-76290e8ddb7001165e9f245730346de84e773058.tar.gz |
filechooser: Add gtk_file_chooser_get_filters
Replace gtk_file_chooser_list_filters with a new
api that returns a list model.
Update all callers.
Diffstat (limited to 'gtk/gtkfilechoosernativequartz.c')
-rw-r--r-- | gtk/gtkfilechoosernativequartz.c | 50 |
1 files changed, 36 insertions, 14 deletions
diff --git a/gtk/gtkfilechoosernativequartz.c b/gtk/gtkfilechoosernativequartz.c index 6ce0e936f7..d7cf4113a4 100644 --- a/gtk/gtkfilechoosernativequartz.c +++ b/gtk/gtkfilechoosernativequartz.c @@ -99,9 +99,10 @@ typedef struct { else [data->panel setAllowedFileTypes:filter]; - GSList *filters = gtk_file_chooser_list_filters (GTK_FILE_CHOOSER (data->self)); - data->self->current_filter = g_slist_nth_data (filters, selected_index); - g_slist_free (filters); + GListModel *filters = gtk_file_chooser_get_filters (GTK_FILE_CHOOSER (data->self)); + data->self->current_filter = g_list_model_get_item (filters, selected_index); + g_object_unref (data->self->current_filter); + g_object_unref (filters); g_object_notify (G_OBJECT (data->self), "filter"); } @end @@ -307,13 +308,28 @@ filechooser_quartz_launch (FileChooserQuartzData *data) if (data->self->current_filter) { - GSList *filters = gtk_file_chooser_list_filters (GTK_FILE_CHOOSER (data->self)); - gint current_filter_index = g_slist_index (filters, data->self->current_filter); - g_slist_free (filters); + GListModel *filters; + guint i, n; + guint current_filter_index = GTK_INVALID_LIST_POSITION; - if (current_filter_index >= 0) + filters = gtk_file_chooser_get_filters (GTK_FILE_CHOOSER (data->self)); + n = g_list_model_get_n_items (filters); + for (i = 0; i < n; i++) + { + gpointer item = g_list_model_get_item (filters, i); + if (item == data->self->current_filter) + { + g_object_unref (item); + current_filter_index = i; + break; + } + g_object_unref (item); + } + g_object_unref (filters); + + if (current_filter_index != GTK_INVALID_LIST_POSITION) [data->filter_combo_box selectItemAtIndex:current_filter_index]; - else + else [data->filter_combo_box selectItemAtIndex:0]; } else @@ -437,15 +453,15 @@ gtk_file_chooser_native_quartz_show (GtkFileChooserNative *self) GtkWindow *transient_for; GtkFileChooserAction action; - GSList *filters, *l; - int n_filters, i; + GListModel *filters; + guint n_filters, i; char *message = NULL; data = g_new0 (FileChooserQuartzData, 1); // examine filters! - filters = gtk_file_chooser_list_filters (GTK_FILE_CHOOSER (self)); - n_filters = g_slist_length (filters); + filters = gtk_file_chooser_get_filters (GTK_FILE_CHOOSER (self)); + n_filters = g_list_model_get_n_items (filters); if (n_filters > 0) { data->filters = [NSMutableArray arrayWithCapacity:n_filters]; @@ -453,13 +469,17 @@ gtk_file_chooser_native_quartz_show (GtkFileChooserNative *self) data->filter_names = [NSMutableArray arrayWithCapacity:n_filters]; [data->filter_names retain]; - for (l = filters, i = 0; l != NULL; l = l->next, i++) + for (i = 0; i < n; i++) { - if (!file_filter_to_quartz (l->data, data->filters, data->filter_names)) + GtkFileFilter *filter = g_list_model_get_item (filters, i); + if (!file_filter_to_quartz (filter, data->filters, data->filter_names)) { filechooser_quartz_data_free (data); + g_object_unref (filter); + g_object_unref (filters); return FALSE; } + g_object_unref (filter); } self->current_filter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (self)); } @@ -467,6 +487,8 @@ gtk_file_chooser_native_quartz_show (GtkFileChooserNative *self) { self->current_filter = NULL; } + g_object_unref (filters); + self->mode_data = data; data->self = g_object_ref (self); |