filefilter: Drop custom filters

These don't work with native file choosers.
This commit is contained in:
Matthias Clasen 2020-07-05 13:51:42 -04:00
parent a8b0125da1
commit 644d522d19
4 changed files with 1 additions and 104 deletions

View File

@ -1414,14 +1414,12 @@ GtkFileChooserButtonPrivate
<FILE>gtkfilefilter</FILE>
GtkFileFilter
GtkFileFilterFlags
GtkFileFilterFunc
gtk_file_filter_new
gtk_file_filter_set_name
gtk_file_filter_get_name
gtk_file_filter_add_mime_type
gtk_file_filter_add_pattern
gtk_file_filter_add_pixbuf_formats
gtk_file_filter_add_custom
gtk_file_filter_get_needed
gtk_file_filter_filter

View File

@ -85,8 +85,7 @@ typedef struct _FilterRule FilterRule;
typedef enum {
FILTER_RULE_PATTERN,
FILTER_RULE_MIME_TYPE,
FILTER_RULE_PIXBUF_FORMATS,
FILTER_RULE_CUSTOM
FILTER_RULE_PIXBUF_FORMATS
} FilterRuleType;
struct _GtkFileFilterClass
@ -113,11 +112,6 @@ struct _FilterRule
gchar *pattern;
gchar *mime_type;
GSList *pixbuf_formats;
struct {
GtkFileFilterFunc func;
gpointer data;
GDestroyNotify notify;
} custom;
} u;
};
@ -205,10 +199,6 @@ filter_rule_free (FilterRule *rule)
case FILTER_RULE_PATTERN:
g_free (rule->u.pattern);
break;
case FILTER_RULE_CUSTOM:
if (rule->u.custom.notify)
rule->u.custom.notify (rule->u.custom.data);
break;
case FILTER_RULE_PIXBUF_FORMATS:
g_slist_free (rule->u.pixbuf_formats);
break;
@ -580,45 +570,6 @@ gtk_file_filter_add_pixbuf_formats (GtkFileFilter *filter)
file_filter_add_rule (filter, rule);
}
/**
* gtk_file_filter_add_custom:
* @filter: a #GtkFileFilter
* @needed: bitfield of flags indicating the information that the custom
* filter function needs.
* @func: callback function; if the function returns %TRUE, then
* the file will be displayed.
* @data: data to pass to @func
* @notify: function to call to free @data when it is no longer needed.
*
* Adds rule to a filter that allows files based on a custom callback
* function. The bitfield @needed which is passed in provides information
* about what sorts of information that the filter function needs;
* this allows GTK+ to avoid retrieving expensive information when
* it isnt needed by the filter.
**/
void
gtk_file_filter_add_custom (GtkFileFilter *filter,
GtkFileFilterFlags needed,
GtkFileFilterFunc func,
gpointer data,
GDestroyNotify notify)
{
FilterRule *rule;
g_return_if_fail (GTK_IS_FILE_FILTER (filter));
g_return_if_fail (func != NULL);
rule = g_slice_new (FilterRule);
rule->type = FILTER_RULE_CUSTOM;
rule->needed = needed;
rule->u.custom.func = func;
rule->u.custom.data = data;
rule->u.custom.notify = notify;
file_filter_add_rule (filter, rule);
}
/**
* gtk_file_filter_get_needed:
* @filter: a #GtkFileFilter
@ -654,10 +605,6 @@ NSArray * _gtk_file_filter_get_as_pattern_nsstrings (GtkFileFilter *filter)
switch (rule->type)
{
case FILTER_RULE_CUSTOM:
[array release];
return NULL;
break;
case FILTER_RULE_MIME_TYPE:
{
// convert mime-types to UTI
@ -731,7 +678,6 @@ _gtk_file_filter_get_as_patterns (GtkFileFilter *filter)
switch (rule->type)
{
case FILTER_RULE_CUSTOM:
case FILTER_RULE_MIME_TYPE:
g_ptr_array_free (array, TRUE);
return NULL;
@ -853,10 +799,6 @@ gtk_file_filter_filter (GtkFileFilter *filter,
}
}
break;
case FILTER_RULE_CUSTOM:
if (rule->u.custom.func (info, rule->u.custom.data))
return TRUE;
break;
default:
break;
@ -910,7 +852,6 @@ gtk_file_filter_to_gvariant (GtkFileFilter *filter)
}
}
break;
case FILTER_RULE_CUSTOM:
default:
break;
}

View File

@ -52,19 +52,6 @@ typedef enum {
GTK_FILE_FILTER_MIME_TYPE = 1 << 3
} GtkFileFilterFlags;
/**
* GtkFileFilterFunc:
* @info: a #GFileInfo
* @data: (closure): user data passed to gtk_file_filter_add_custom()
*
* The type of function that is used with custom filters, see
* gtk_file_filter_add_custom().
*
* Returns: %TRUE if the file should be displayed
*/
typedef gboolean (*GtkFileFilterFunc) (GFileInfo *info,
gpointer data);
GDK_AVAILABLE_IN_ALL
GType gtk_file_filter_get_type (void) G_GNUC_CONST;
@ -84,12 +71,6 @@ void gtk_file_filter_add_pattern (GtkFileFilter *filter,
const gchar *pattern);
GDK_AVAILABLE_IN_ALL
void gtk_file_filter_add_pixbuf_formats (GtkFileFilter *filter);
GDK_AVAILABLE_IN_ALL
void gtk_file_filter_add_custom (GtkFileFilter *filter,
GtkFileFilterFlags needed,
GtkFileFilterFunc func,
gpointer data,
GDestroyNotify notify);
GDK_AVAILABLE_IN_ALL
GtkFileFilterFlags gtk_file_filter_get_needed (GtkFileFilter *filter);

View File

@ -118,21 +118,6 @@ response_cb (GtkDialog *dialog,
g_main_context_wakeup (NULL);
}
static gboolean
no_backup_files_filter (GFileInfo *info,
gpointer data)
{
const char *display_name;
gsize len;
display_name = g_file_info_get_display_name (info);
len = strlen (display_name);
if (len > 0 && display_name[len - 1] == '~')
return 0;
else
return 1;
}
static void
filter_changed (GtkFileChooserDialog *dialog,
gpointer data)
@ -399,14 +384,6 @@ main (int argc, char **argv)
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
g_object_unref (filter);
filter = gtk_file_filter_new ();
gtk_file_filter_set_name (filter, "No backup files");
gtk_file_filter_add_custom (filter, GTK_FILE_FILTER_DISPLAY_NAME,
no_backup_files_filter, NULL, NULL);
gtk_file_filter_add_mime_type (filter, "image/png");
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
g_object_unref (filter);
filter = gtk_file_filter_new ();
gtk_file_filter_set_name (filter, "Starts with D");
gtk_file_filter_add_pattern (filter, "D*");