changeset 964:ba1d3c4bc0cd

implemented marks filter
author nadvornik
date Sat, 16 Aug 2008 20:34:14 +0000
parents 323dab9321bb
children cbdabb499684
files src/filedata.c src/filedata.h src/typedefs.h src/view_file.c src/view_file.h src/view_file_icon.c src/view_file_list.c
diffstat 7 files changed, 120 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/src/filedata.c	Sat Aug 16 07:18:16 2008 +0000
+++ b/src/filedata.c	Sat Aug 16 20:34:14 2008 +0000
@@ -1068,6 +1068,33 @@
 	file_data_send_notification(fd, NOTIFY_TYPE_INTERNAL);
 }
 
+gboolean file_data_filter_marks(FileData *fd, guint filter)
+{
+	return ((fd->marks & filter) == filter);
+}
+
+GList *file_data_filter_marks_list(GList *list, guint filter)
+{
+	GList *work;
+
+	work = list;
+	while (work)
+		{
+		FileData *fd = work->data;
+		GList *link = work;
+		work = work->next;
+
+		if (!file_data_filter_marks(fd, filter))
+			{
+			list = g_list_remove_link(list, link);
+			file_data_unref(fd);
+			g_list_free(link);
+			}
+		}
+
+	return list;
+}
+
 gint file_data_get_user_orientation(FileData *fd)
 {
 	return fd->user_orientation;
--- a/src/filedata.h	Sat Aug 16 07:18:16 2008 +0000
+++ b/src/filedata.h	Sat Aug 16 20:34:14 2008 +0000
@@ -65,6 +65,9 @@
 
 gboolean file_data_get_mark(FileData *fd, gint n);
 void file_data_set_mark(FileData *fd, gint n, gboolean value);
+gboolean file_data_filter_marks(FileData *fd, guint filter);
+GList *file_data_filter_marks_list(GList *list, guint filter);
+
 gint file_data_get_user_orientation(FileData *fd);
 void file_data_set_user_orientation(FileData *fd, gint value);
 
--- a/src/typedefs.h	Sat Aug 16 07:18:16 2008 +0000
+++ b/src/typedefs.h	Sat Aug 16 20:34:14 2008 +0000
@@ -640,6 +640,9 @@
 
 	GtkWidget *widget;
 	GtkWidget *listview;
+	GtkWidget *scrolled;
+	GtkWidget *filter;
+	GtkWidget *filter_check[FILEDATA_MARKS_SIZE];
 
 	FileData *dir_fd;
 	GList *list;
--- a/src/view_file.c	Sat Aug 16 07:18:16 2008 +0000
+++ b/src/view_file.c	Sat Aug 16 20:34:14 2008 +0000
@@ -656,6 +656,35 @@
 	g_free(vf);
 }
 
+static void vf_marks_filter_toggle_cb(GtkWidget *widget, gpointer data)
+{
+	ViewFile *vf = data;
+	vf_refresh_idle(vf);
+}
+
+
+static GtkWidget *vf_marks_filter_init(ViewFile *vf)
+{
+	GtkWidget *frame = gtk_frame_new(NULL);
+	GtkWidget *hbox = gtk_hbox_new(FALSE, 0);
+	
+	gint i;
+	
+	for (i = 0; i < FILEDATA_MARKS_SIZE ; i++)
+		{
+		GtkWidget *check = gtk_check_button_new();
+		gtk_box_pack_start(GTK_BOX(hbox), check, FALSE, FALSE, 0);
+		g_signal_connect(G_OBJECT(check), "toggled",
+			 G_CALLBACK(vf_marks_filter_toggle_cb), vf);
+
+		gtk_widget_show(check);
+		vf->filter_check[i] = check;
+		}
+	gtk_container_add(GTK_CONTAINER(frame), hbox);
+	gtk_widget_show(hbox);
+	return frame;
+}
+
 ViewFile *vf_new(FileViewType type, FileData *dir_fd)
 {
 	ViewFile *vf;
@@ -678,11 +707,18 @@
 
 	vf->refresh_idle_id = -1;
 
-	vf->widget = gtk_scrolled_window_new(NULL, NULL);
-	gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(vf->widget), GTK_SHADOW_IN);
-	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(vf->widget),
+	vf->scrolled = gtk_scrolled_window_new(NULL, NULL);
+	gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(vf->scrolled), GTK_SHADOW_IN);
+	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(vf->scrolled),
 				       GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
 	
+	vf->filter = vf_marks_filter_init(vf);
+
+	vf->widget = gtk_vbox_new(FALSE, 0);
+	gtk_box_pack_start(GTK_BOX(vf->widget), vf->filter, FALSE, FALSE, 0);
+	gtk_box_pack_start(GTK_BOX(vf->widget), vf->scrolled, TRUE, TRUE, 0);
+	gtk_widget_show(vf->scrolled);
+	
 	g_signal_connect(G_OBJECT(vf->widget), "destroy",
 			 G_CALLBACK(vf_destroy_cb), vf);
 
@@ -701,7 +737,7 @@
 	g_signal_connect(G_OBJECT(vf->listview), "button_release_event",
 			 G_CALLBACK(vf_release_cb), vf);
 
-	gtk_container_add(GTK_CONTAINER(vf->widget), vf->listview);
+	gtk_container_add(GTK_CONTAINER(vf->scrolled), vf->listview);
 	gtk_widget_show(vf->listview);
 
 	if (dir_fd) vf_set_fd(vf, dir_fd);
@@ -741,6 +777,28 @@
 	case FILEVIEW_LIST: vflist_marks_set(vf, enable); break;
 	case FILEVIEW_ICON: vficon_marks_set(vf, enable); break;
 	}
+	if (enable)
+		gtk_widget_show(vf->filter);
+	else
+		gtk_widget_hide(vf->filter);
+
+	vf_refresh_idle(vf);
+}
+
+guint vf_marks_get_filter(ViewFile *vf)
+{
+	guint ret = 0;
+	gint i;
+	if (!vf->marks_enabled) return 0;
+	
+	for (i = 0; i < FILEDATA_MARKS_SIZE ; i++)
+		{
+		if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(vf->filter_check[i])))
+			{
+			ret |= 1 << i;
+			}
+		}
+	return ret;
 }
 
 void vf_set_layout(ViewFile *vf, LayoutWindow *layout)
@@ -771,6 +829,14 @@
 }
 
 
+void vf_refresh_idle(ViewFile *vf)
+{
+	if (vf->refresh_idle_id == -1)
+		{
+		vf->refresh_idle_id = g_idle_add(vf_refresh_idle_cb, vf);
+		}
+}
+
 void vf_notify_cb(FileData *fd, NotifyType type, gpointer data)
 {
 	ViewFile *vf = data;
@@ -804,9 +870,9 @@
 			}
 		}
 	
-	if (refresh && vf->refresh_idle_id == -1)
+	if (refresh)
 		{
-		vf->refresh_idle_id = g_idle_add(vf_refresh_idle_cb, vf);
+		vf_refresh_idle(vf);
 		}
 }
 
--- a/src/view_file.h	Sat Aug 16 07:18:16 2008 +0000
+++ b/src/view_file.h	Sat Aug 16 20:34:14 2008 +0000
@@ -31,11 +31,14 @@
 
 gint vf_set_fd(ViewFile *vf, FileData *fd);
 gint vf_refresh(ViewFile *vf);
+void vf_refresh_idle(ViewFile *vf);
 
 void vf_thumb_set(ViewFile *vf, gint enable);
 void vf_marks_set(ViewFile *vf, gint enable);
 void vf_sort_set(ViewFile *vf, SortType type, gint ascend);
 
+guint vf_marks_get_filter(ViewFile *vf);
+
 GList *vf_pop_menu_file_list(ViewFile *vf);
 GtkWidget *vf_pop_menu(ViewFile *vf);
 
--- a/src/view_file_icon.c	Sat Aug 16 07:18:16 2008 +0000
+++ b/src/view_file_icon.c	Sat Aug 16 20:34:14 2008 +0000
@@ -2107,6 +2107,7 @@
 	if (vf->dir_fd)
 		{
 		ret = filelist_read(vf->dir_fd, &new_filelist, NULL);
+		new_filelist = file_data_filter_marks_list(new_filelist, vf_marks_get_filter(vf));
 		}
 
 	vf->list = iconlist_sort(vf->list, vf->sort_method, vf->sort_ascend); /* the list might not be sorted if there were renames */
--- a/src/view_file_list.c	Sat Aug 16 07:18:16 2008 +0000
+++ b/src/view_file_list.c	Sat Aug 16 20:34:14 2008 +0000
@@ -1564,6 +1564,12 @@
 				break;
 			}
 		
+		if (!file_data_filter_marks(fd, vf_marks_get_filter(vf))) /* file no longer matches the filter -> remove it */
+			{
+			vf_refresh_idle(vf);
+			}
+
+		
 		file_data_register_notify_func(vf_notify_cb, vf, NOTIFY_PRIORITY_MEDIUM);
 
 		gtk_tree_store_set(GTK_TREE_STORE(store), &iter, FILE_COLUMN_MARKS + n, file_data_get_mark(fd, n), -1);
@@ -1693,7 +1699,7 @@
 		file_data_unregister_notify_func(vf_notify_cb, vf); /* we don't need the notification of changes detected by filelist_read */
 
 		ret = filelist_read(vf->dir_fd, &vf->list, NULL);
-
+		vf->list = file_data_filter_marks_list(vf->list, vf_marks_get_filter(vf));
 		file_data_register_notify_func(vf_notify_cb, vf, NOTIFY_PRIORITY_MEDIUM);
 
 		DEBUG_1("%s vflist_refresh: sort", get_exec_time());
@@ -1820,6 +1826,10 @@
 	mark = !mark;
 	file_data_unregister_notify_func(vf_notify_cb, vf); /* we don't need the notification */
 	file_data_set_mark(fd, col_idx - FILE_COLUMN_MARKS, mark);
+	if (!file_data_filter_marks(fd, vf_marks_get_filter(vf))) /* file no longer matches the filter -> remove it */
+		{
+		vf_refresh_idle(vf);
+		}
 	file_data_register_notify_func(vf_notify_cb, vf, NOTIFY_PRIORITY_MEDIUM);
 
 	gtk_tree_store_set(store, &iter, col_idx, mark, -1);