[gedit] Implement simple pattern filters for file dialog
- From: Jesse van den Kieboom <jessevdk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] Implement simple pattern filters for file dialog
- Date: Sat, 6 Sep 2014 09:09:02 +0000 (UTC)
commit ff3bba1c84a957a9c9faa10199646db541737f99
Author: Jesse van den Kieboom <jessevdk gmail com>
Date: Sat Sep 6 11:04:50 2014 +0200
Implement simple pattern filters for file dialog
gedit/gedit-commands-file.c | 6 ++-
gedit/gedit-file-chooser-dialog-gtk.c | 80 +++++++++++++++++++++-----------
gedit/gedit-file-chooser-dialog.c | 17 +++++++
gedit/gedit-file-chooser-dialog.h | 16 +++++--
4 files changed, 85 insertions(+), 34 deletions(-)
---
diff --git a/gedit/gedit-commands-file.c b/gedit/gedit-commands-file.c
index 2225d07..d512333 100644
--- a/gedit/gedit-commands-file.c
+++ b/gedit/gedit-commands-file.c
@@ -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);
diff --git a/gedit/gedit-file-chooser-dialog-gtk.c b/gedit/gedit-file-chooser-dialog-gtk.c
index ca8373d..9f9cdfc 100644
--- a/gedit/gedit-file-chooser-dialog-gtk.c
+++ b/gedit/gedit-file-chooser-dialog-gtk.c
@@ -224,6 +224,26 @@ chooser_get_window (GeditFileChooserDialog *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)
{
diff --git a/gedit/gedit-file-chooser-dialog.c b/gedit/gedit-file-chooser-dialog.c
index d8c13cf..29dae56 100644
--- a/gedit/gedit-file-chooser-dialog.c
+++ b/gedit/gedit-file-chooser-dialog.c
@@ -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: */
diff --git a/gedit/gedit-file-chooser-dialog.h b/gedit/gedit-file-chooser-dialog.h
index 41e6771..3ec6f6d 100644
--- a/gedit/gedit-file-chooser-dialog.h
+++ b/gedit/gedit-file-chooser-dialog.h
@@ -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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]