Implement filtering by supported extensions
This commit is contained in:
parent
6dd0414d0a
commit
c77bccccb8
|
@ -644,7 +644,8 @@ entry_add_thumbnail(gpointer data, G_GNUC_UNUSED gpointer user_data)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
fastiv_browser_load(FastivBrowser *self, const char *path)
|
fastiv_browser_load(
|
||||||
|
FastivBrowser *self, FastivBrowserFilterCallback cb, const char *path)
|
||||||
{
|
{
|
||||||
g_array_set_size(self->entries, 0);
|
g_array_set_size(self->entries, 0);
|
||||||
g_array_set_size(self->layouted_rows, 0);
|
g_array_set_size(self->layouted_rows, 0);
|
||||||
|
@ -666,8 +667,9 @@ fastiv_browser_load(FastivBrowser *self, const char *path)
|
||||||
if (g_file_info_get_file_type(info) == G_FILE_TYPE_DIRECTORY)
|
if (g_file_info_get_file_type(info) == G_FILE_TYPE_DIRECTORY)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
// TODO(p): Support being passed filter/sort functions.
|
// TODO(p): Support being passed a sort function.
|
||||||
g_file_info_get_name(info);
|
if (cb && !cb(g_file_info_get_name(info)))
|
||||||
|
continue;
|
||||||
|
|
||||||
g_array_append_val(self->entries,
|
g_array_append_val(self->entries,
|
||||||
((Entry) {.thumbnail = NULL, .filename = g_file_get_path(child)}));
|
((Entry) {.thumbnail = NULL, .filename = g_file_get_path(child)}));
|
||||||
|
|
|
@ -22,4 +22,7 @@
|
||||||
#define FASTIV_TYPE_BROWSER (fastiv_browser_get_type())
|
#define FASTIV_TYPE_BROWSER (fastiv_browser_get_type())
|
||||||
G_DECLARE_FINAL_TYPE(FastivBrowser, fastiv_browser, FASTIV, BROWSER, GtkWidget)
|
G_DECLARE_FINAL_TYPE(FastivBrowser, fastiv_browser, FASTIV, BROWSER, GtkWidget)
|
||||||
|
|
||||||
void fastiv_browser_load(FastivBrowser *self, const char *path);
|
typedef gboolean (*FastivBrowserFilterCallback) (const char *);
|
||||||
|
|
||||||
|
void fastiv_browser_load(
|
||||||
|
FastivBrowser *self, FastivBrowserFilterCallback cb, const char *path);
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
struct _FastivSidebar {
|
struct _FastivSidebar {
|
||||||
GtkScrolledWindow parent_instance;
|
GtkScrolledWindow parent_instance;
|
||||||
GtkPlacesSidebar *places;
|
GtkPlacesSidebar *places;
|
||||||
|
GtkWidget *toolbar;
|
||||||
GtkWidget *listbox;
|
GtkWidget *listbox;
|
||||||
GFile *location;
|
GFile *location;
|
||||||
};
|
};
|
||||||
|
@ -358,56 +359,29 @@ fastiv_sidebar_init(FastivSidebar *self)
|
||||||
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(self->places),
|
gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(self->places),
|
||||||
GTK_POLICY_NEVER, GTK_POLICY_NEVER);
|
GTK_POLICY_NEVER, GTK_POLICY_NEVER);
|
||||||
|
|
||||||
// Fill up what would otherwise be wasted space,
|
|
||||||
// as it is in the examples of Nautilus and Thunar.
|
|
||||||
GtkWidget *plus = gtk_button_new_from_icon_name("zoom-in-symbolic",
|
|
||||||
GTK_ICON_SIZE_BUTTON);
|
|
||||||
gtk_widget_set_tooltip_text(plus, "Larger thumbnails");
|
|
||||||
GtkWidget *minus = gtk_button_new_from_icon_name("zoom-out-symbolic",
|
|
||||||
GTK_ICON_SIZE_BUTTON);
|
|
||||||
gtk_widget_set_tooltip_text(minus, "Smaller thumbnails");
|
|
||||||
|
|
||||||
GtkWidget *zoom_group = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
|
|
||||||
gtk_style_context_add_class(
|
|
||||||
gtk_widget_get_style_context(zoom_group), GTK_STYLE_CLASS_LINKED);
|
|
||||||
gtk_box_pack_start(GTK_BOX(zoom_group), plus, FALSE, FALSE, 0);
|
|
||||||
gtk_box_pack_start(GTK_BOX(zoom_group), minus, FALSE, FALSE, 0);
|
|
||||||
|
|
||||||
GtkWidget *funnel = gtk_toggle_button_new();
|
|
||||||
gtk_container_add(GTK_CONTAINER(funnel),
|
|
||||||
gtk_image_new_from_icon_name("funnel-symbolic", GTK_ICON_SIZE_BUTTON));
|
|
||||||
gtk_widget_set_tooltip_text(funnel, "Hide unsupported files");
|
|
||||||
|
|
||||||
// None of GtkActionBar, GtkToolbar, .inline-toolbar is appropriate.
|
// None of GtkActionBar, GtkToolbar, .inline-toolbar is appropriate.
|
||||||
// It is either borders or padding.
|
// It is either side-favouring borders or excess button padding.
|
||||||
GtkWidget *buttons = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 12);
|
self->toolbar = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 12);
|
||||||
gtk_style_context_add_class(
|
gtk_style_context_add_class(
|
||||||
gtk_widget_get_style_context(buttons), GTK_STYLE_CLASS_TOOLBAR);
|
gtk_widget_get_style_context(self->toolbar), GTK_STYLE_CLASS_TOOLBAR);
|
||||||
gtk_box_pack_start(GTK_BOX(buttons), zoom_group, FALSE, FALSE, 0);
|
|
||||||
gtk_box_pack_start(GTK_BOX(buttons), funnel, FALSE, FALSE, 0);
|
|
||||||
gtk_widget_set_halign(buttons, GTK_ALIGN_CENTER);
|
|
||||||
|
|
||||||
// TODO(p): Implement. Probably fill `buttons` in externally.
|
|
||||||
gtk_widget_set_sensitive(plus, FALSE);
|
|
||||||
gtk_widget_set_sensitive(minus, FALSE);
|
|
||||||
gtk_widget_set_sensitive(funnel, FALSE);
|
|
||||||
|
|
||||||
self->listbox = gtk_list_box_new();
|
self->listbox = gtk_list_box_new();
|
||||||
gtk_list_box_set_selection_mode(
|
gtk_list_box_set_selection_mode(
|
||||||
GTK_LIST_BOX(self->listbox), GTK_SELECTION_NONE);
|
GTK_LIST_BOX(self->listbox), GTK_SELECTION_NONE);
|
||||||
g_signal_connect(self->listbox, "row-activated",
|
g_signal_connect(self->listbox, "row-activated",
|
||||||
G_CALLBACK(on_open_breadcrumb), self);
|
G_CALLBACK(on_open_breadcrumb), self);
|
||||||
|
|
||||||
gtk_list_box_set_sort_func(
|
gtk_list_box_set_sort_func(
|
||||||
GTK_LIST_BOX(self->listbox), listbox_sort, self, NULL);
|
GTK_LIST_BOX(self->listbox), listbox_sort, self, NULL);
|
||||||
|
|
||||||
|
// Fill up what would otherwise be wasted space,
|
||||||
|
// as it is in the examples of Nautilus and Thunar.
|
||||||
GtkWidget *superbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
|
GtkWidget *superbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
|
||||||
gtk_container_add(
|
gtk_container_add(
|
||||||
GTK_CONTAINER(superbox), GTK_WIDGET(self->places));
|
GTK_CONTAINER(superbox), GTK_WIDGET(self->places));
|
||||||
gtk_container_add(
|
gtk_container_add(
|
||||||
GTK_CONTAINER(superbox), gtk_separator_new(GTK_ORIENTATION_VERTICAL));
|
GTK_CONTAINER(superbox), gtk_separator_new(GTK_ORIENTATION_VERTICAL));
|
||||||
gtk_container_add(
|
gtk_container_add(
|
||||||
GTK_CONTAINER(superbox), buttons);
|
GTK_CONTAINER(superbox), self->toolbar);
|
||||||
gtk_container_add(
|
gtk_container_add(
|
||||||
GTK_CONTAINER(superbox), gtk_separator_new(GTK_ORIENTATION_VERTICAL));
|
GTK_CONTAINER(superbox), gtk_separator_new(GTK_ORIENTATION_VERTICAL));
|
||||||
gtk_container_add(
|
gtk_container_add(
|
||||||
|
@ -437,3 +411,10 @@ fastiv_sidebar_show_enter_location(FastivSidebar *self)
|
||||||
g_return_if_fail(FASTIV_IS_SIDEBAR(self));
|
g_return_if_fail(FASTIV_IS_SIDEBAR(self));
|
||||||
g_signal_emit_by_name(self->places, "show-enter-location");
|
g_signal_emit_by_name(self->places, "show-enter-location");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GtkBox *
|
||||||
|
fastiv_sidebar_get_toolbar(FastivSidebar *self)
|
||||||
|
{
|
||||||
|
g_return_val_if_fail(FASTIV_IS_SIDEBAR(self), NULL);
|
||||||
|
return GTK_BOX(self->toolbar);
|
||||||
|
}
|
||||||
|
|
|
@ -25,3 +25,4 @@ G_DECLARE_FINAL_TYPE(
|
||||||
|
|
||||||
void fastiv_sidebar_set_location(FastivSidebar *self, GFile *location);
|
void fastiv_sidebar_set_location(FastivSidebar *self, GFile *location);
|
||||||
void fastiv_sidebar_show_enter_location(FastivSidebar *self);
|
void fastiv_sidebar_show_enter_location(FastivSidebar *self);
|
||||||
|
GtkBox *fastiv_sidebar_get_toolbar(FastivSidebar *self);
|
||||||
|
|
43
fastiv.c
43
fastiv.c
|
@ -55,6 +55,7 @@ exit_fatal(const gchar *format, ...)
|
||||||
|
|
||||||
struct {
|
struct {
|
||||||
gchar **supported_globs;
|
gchar **supported_globs;
|
||||||
|
gboolean filtering;
|
||||||
|
|
||||||
gchar *directory;
|
gchar *directory;
|
||||||
GPtrArray *files;
|
GPtrArray *files;
|
||||||
|
@ -118,7 +119,8 @@ load_directory(const gchar *dirname)
|
||||||
GFile *file = g_file_new_for_path(g.directory);
|
GFile *file = g_file_new_for_path(g.directory);
|
||||||
fastiv_sidebar_set_location(FASTIV_SIDEBAR(g.browser_sidebar), file);
|
fastiv_sidebar_set_location(FASTIV_SIDEBAR(g.browser_sidebar), file);
|
||||||
g_object_unref(file);
|
g_object_unref(file);
|
||||||
fastiv_browser_load(FASTIV_BROWSER(g.browser), g.directory);
|
fastiv_browser_load(FASTIV_BROWSER(g.browser),
|
||||||
|
g.filtering ? is_supported : NULL, g.directory);
|
||||||
|
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
GDir *dir = g_dir_open(g.directory, 0, &error);
|
GDir *dir = g_dir_open(g.directory, 0, &error);
|
||||||
|
@ -152,6 +154,14 @@ load_directory(const gchar *dirname)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
on_filtering_toggled(GtkToggleButton *button, G_GNUC_UNUSED gpointer user_data)
|
||||||
|
{
|
||||||
|
g.filtering = gtk_toggle_button_get_active(button);
|
||||||
|
if (g.directory)
|
||||||
|
load_directory(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
open(const gchar *path)
|
open(const gchar *path)
|
||||||
{
|
{
|
||||||
|
@ -549,6 +559,34 @@ main(int argc, char *argv[])
|
||||||
g_signal_connect(g.browser_sidebar, "open-location",
|
g_signal_connect(g.browser_sidebar, "open-location",
|
||||||
G_CALLBACK(on_open_location), NULL);
|
G_CALLBACK(on_open_location), NULL);
|
||||||
|
|
||||||
|
GtkWidget *plus = gtk_button_new_from_icon_name("zoom-in-symbolic",
|
||||||
|
GTK_ICON_SIZE_BUTTON);
|
||||||
|
gtk_widget_set_tooltip_text(plus, "Larger thumbnails");
|
||||||
|
GtkWidget *minus = gtk_button_new_from_icon_name("zoom-out-symbolic",
|
||||||
|
GTK_ICON_SIZE_BUTTON);
|
||||||
|
gtk_widget_set_tooltip_text(minus, "Smaller thumbnails");
|
||||||
|
|
||||||
|
GtkWidget *zoom_group = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
|
||||||
|
gtk_style_context_add_class(
|
||||||
|
gtk_widget_get_style_context(zoom_group), GTK_STYLE_CLASS_LINKED);
|
||||||
|
gtk_box_pack_start(GTK_BOX(zoom_group), plus, FALSE, FALSE, 0);
|
||||||
|
gtk_box_pack_start(GTK_BOX(zoom_group), minus, FALSE, FALSE, 0);
|
||||||
|
|
||||||
|
GtkWidget *funnel = gtk_toggle_button_new();
|
||||||
|
gtk_container_add(GTK_CONTAINER(funnel),
|
||||||
|
gtk_image_new_from_icon_name("funnel-symbolic", GTK_ICON_SIZE_BUTTON));
|
||||||
|
gtk_widget_set_tooltip_text(funnel, "Hide unsupported files");
|
||||||
|
|
||||||
|
// TODO(p): Implement these as well.
|
||||||
|
gtk_widget_set_sensitive(plus, FALSE);
|
||||||
|
gtk_widget_set_sensitive(minus, FALSE);
|
||||||
|
|
||||||
|
GtkBox *toolbar =
|
||||||
|
fastiv_sidebar_get_toolbar(FASTIV_SIDEBAR(g.browser_sidebar));
|
||||||
|
gtk_box_pack_start(toolbar, zoom_group, FALSE, FALSE, 0);
|
||||||
|
gtk_box_pack_start(toolbar, funnel, FALSE, FALSE, 0);
|
||||||
|
gtk_widget_set_halign(GTK_WIDGET(toolbar), GTK_ALIGN_CENTER);
|
||||||
|
|
||||||
g.browser_paned = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
|
g.browser_paned = gtk_paned_new(GTK_ORIENTATION_HORIZONTAL);
|
||||||
gtk_paned_add1(GTK_PANED(g.browser_paned), g.browser_sidebar);
|
gtk_paned_add1(GTK_PANED(g.browser_paned), g.browser_sidebar);
|
||||||
gtk_paned_add2(GTK_PANED(g.browser_paned), g.browser_scroller);
|
gtk_paned_add2(GTK_PANED(g.browser_paned), g.browser_scroller);
|
||||||
|
@ -573,6 +611,9 @@ main(int argc, char *argv[])
|
||||||
g.supported_globs = extract_mime_globs((const char **) types);
|
g.supported_globs = extract_mime_globs((const char **) types);
|
||||||
g_strfreev(types);
|
g_strfreev(types);
|
||||||
|
|
||||||
|
g_signal_connect(funnel, "toggled", G_CALLBACK(on_filtering_toggled), NULL);
|
||||||
|
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(funnel), TRUE);
|
||||||
|
|
||||||
g.files = g_ptr_array_new_full(16, g_free);
|
g.files = g_ptr_array_new_full(16, g_free);
|
||||||
g.directory = g_get_current_dir();
|
g.directory = g_get_current_dir();
|
||||||
if (!path_arg || !open_any_path(path_arg))
|
if (!path_arg || !open_any_path(path_arg))
|
||||||
|
|
Loading…
Reference in New Issue