Commit ff3bba1c authored by Jesse van den Kieboom's avatar Jesse van den Kieboom

Implement simple pattern filters for file dialog

parent ca513047
......@@ -451,7 +451,8 @@ _gedit_cmd_file_open (GSimpleAction *action,
open_dialog = gedit_file_chooser_dialog_create (_("Open"),
window ? GTK_WINDOW (window) : NULL,
GEDIT_FILE_CHOOSER_OPEN |
GEDIT_FILE_CHOOSER_ENABLE_ENCODING,
GEDIT_FILE_CHOOSER_ENABLE_ENCODING |
GEDIT_FILE_CHOOSER_ENABLE_DEFAULT_FILTERS,
NULL,
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_Open"), GTK_RESPONSE_OK);
......@@ -875,7 +876,8 @@ _gedit_cmd_file_save_as_tab (GeditTab *tab,
GTK_WINDOW (window),
GEDIT_FILE_CHOOSER_SAVE |
GEDIT_FILE_CHOOSER_ENABLE_ENCODING |
GEDIT_FILE_CHOOSER_ENABLE_LINE_ENDING,
GEDIT_FILE_CHOOSER_ENABLE_LINE_ENDING |
GEDIT_FILE_CHOOSER_ENABLE_DEFAULT_FILTERS,
NULL,
_("_Cancel"), GTK_RESPONSE_CANCEL,
_("_Save"), GTK_RESPONSE_OK);
......
......@@ -223,6 +223,26 @@ chooser_get_window (GeditFileChooserDialog *dialog)
return GTK_WINDOW (dialog);
}
static void
chooser_add_pattern_filter (GeditFileChooserDialog *dialog,
const gchar *name,
const gchar *pattern)
{
GtkFileFilter *filter;
filter = gtk_file_filter_new ();
gtk_file_filter_set_name (filter, name);
gtk_file_filter_add_pattern (filter, pattern);
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (dialog), filter);
if (gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (dialog)) == NULL)
{
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (dialog), filter);
}
}
static void
gedit_file_chooser_dialog_gtk_chooser_init (gpointer g_iface,
gpointer iface_data)
......@@ -245,6 +265,7 @@ gedit_file_chooser_dialog_gtk_chooser_init (gpointer g_iface,
iface->destroy = chooser_destroy;
iface->set_modal = chooser_set_modal;
iface->get_window = chooser_get_window;
iface->add_pattern_filter = chooser_add_pattern_filter;
}
static void
......@@ -568,38 +589,41 @@ gedit_file_chooser_dialog_gtk_create (const gchar *title,
GEDIT_SETTINGS_ACTIVE_FILE_FILTER);
gedit_debug_message (DEBUG_COMMANDS, "Active filter: %d", active_filter);
/* Filters */
filter = gtk_file_filter_new ();
if ((flags & GEDIT_FILE_CHOOSER_ENABLE_DEFAULT_FILTERS) != 0)
{
/* Filters */
filter = gtk_file_filter_new ();
gtk_file_filter_set_name (filter, ALL_FILES);
gtk_file_filter_add_pattern (filter, "*");
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (result), filter);
gtk_file_filter_set_name (filter, ALL_FILES);
gtk_file_filter_add_pattern (filter, "*");
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (result), filter);
if (active_filter != 1)
{
/* Make this filter the default */
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (result), filter);
}
if (active_filter != 1)
{
/* Make this filter the default */
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (result), filter);
}
filter = gtk_file_filter_new ();
gtk_file_filter_set_name (filter, ALL_TEXT_FILES);
gtk_file_filter_add_custom (filter,
GTK_FILE_FILTER_MIME_TYPE,
all_text_files_filter,
NULL,
NULL);
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (result), filter);
if (active_filter == 1)
{
/* Make this filter the default */
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (result), filter);
}
filter = gtk_file_filter_new ();
gtk_file_filter_set_name (filter, ALL_TEXT_FILES);
gtk_file_filter_add_custom (filter,
GTK_FILE_FILTER_MIME_TYPE,
all_text_files_filter,
NULL,
NULL);
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (result), filter);
if (active_filter == 1)
{
/* Make this filter the default */
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (result), filter);
}
g_signal_connect (result,
"notify::filter",
G_CALLBACK (filter_changed),
NULL);
g_signal_connect (result,
"notify::filter",
G_CALLBACK (filter_changed),
NULL);
}
if (parent != NULL)
{
......
......@@ -305,4 +305,21 @@ gedit_file_chooser_dialog_get_window (GeditFileChooserDialog *dialog)
return NULL;
}
void
gedit_file_chooser_dialog_add_pattern_filter (GeditFileChooserDialog *dialog,
const gchar *name,
const gchar *pattern)
{
GeditFileChooserDialogInterface *iface;
g_return_if_fail (GEDIT_IS_FILE_CHOOSER_DIALOG (dialog));
iface = GEDIT_FILE_CHOOSER_DIALOG_GET_IFACE (dialog);
if (iface->add_pattern_filter)
{
iface->add_pattern_filter (dialog, name, pattern);
}
}
/* ex:set ts=8 noet: */
......@@ -81,14 +81,19 @@ struct _GeditFileChooserDialogInterface
GtkWindow *
(*get_window) (GeditFileChooserDialog *dialog);
void (*add_pattern_filter) (GeditFileChooserDialog *dilaog,
const gchar *name,
const gchar *pattern);
};
typedef enum
{
GEDIT_FILE_CHOOSER_SAVE = 1 << 0,
GEDIT_FILE_CHOOSER_OPEN = 1 << 1,
GEDIT_FILE_CHOOSER_ENABLE_ENCODING = 1 << 2,
GEDIT_FILE_CHOOSER_ENABLE_LINE_ENDING = 1 << 3
GEDIT_FILE_CHOOSER_SAVE = 1 << 0,
GEDIT_FILE_CHOOSER_OPEN = 1 << 1,
GEDIT_FILE_CHOOSER_ENABLE_ENCODING = 1 << 2,
GEDIT_FILE_CHOOSER_ENABLE_LINE_ENDING = 1 << 3,
GEDIT_FILE_CHOOSER_ENABLE_DEFAULT_FILTERS = 1 << 4
} GeditFileChooserFlags;
/*
......@@ -145,6 +150,9 @@ void gedit_file_chooser_dialog_set_modal (GeditFileChooserDialog *dialog,
GtkWindow *gedit_file_chooser_dialog_get_window (GeditFileChooserDialog *dialog);
void gedit_file_chooser_dialog_add_pattern_filter (GeditFileChooserDialog *dialog,
const gchar *name,
const gchar *pattern);
G_END_DECLS
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment