comparison src/view_dir_tree.c @ 396:a01535f52b56

Merge few more functions to view_dir.c.
author zas_
date Thu, 17 Apr 2008 17:19:41 +0000
parents c359fc2c5a1f
children a7be56e84870
comparison
equal deleted inserted replaced
395:c359fc2c5a1f 396:a01535f52b56
656 gboolean path_currently_selected, gpointer data) 656 gboolean path_currently_selected, gpointer data)
657 { 657 {
658 return selection_is_ok; 658 return selection_is_ok;
659 } 659 }
660 660
661 static void vdtree_select_row(ViewDir *vd, FileData *fd) 661 void vdtree_select_row(ViewDir *vd, FileData *fd)
662 { 662 {
663 GtkTreeSelection *selection; 663 GtkTreeSelection *selection;
664 GtkTreeIter iter; 664 GtkTreeIter iter;
665 665
666 if (!vd_find_row(vd, fd, &iter)) return; 666 if (!vd_find_row(vd, fd, &iter)) return;
938 938
939 vdtree_expand_by_data(vd, fd, TRUE); 939 vdtree_expand_by_data(vd, fd, TRUE);
940 vdtree_populate_path(vd, path, FALSE, FALSE); 940 vdtree_populate_path(vd, path, FALSE, FALSE);
941 } 941 }
942 942
943 static void vdtree_activate_cb(GtkTreeView *tview, GtkTreePath *tpath, GtkTreeViewColumn *column, gpointer data)
944 {
945 ViewDir *vd = data;
946 GtkTreeModel *store;
947 GtkTreeIter iter;
948 NodeData *nd;
949
950 store = gtk_tree_view_get_model(tview);
951 gtk_tree_model_get_iter(store, &iter, tpath);
952 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1);
953
954 vdtree_select_row(vd, nd->fd);
955 }
956
957 static GdkColor *vdtree_color_shifted(GtkWidget *widget)
958 {
959 static GdkColor color;
960 static GtkWidget *done = NULL;
961
962 if (done != widget)
963 {
964 GtkStyle *style;
965
966 style = gtk_widget_get_style(widget);
967 memcpy(&color, &style->base[GTK_STATE_NORMAL], sizeof(color));
968 shift_color(&color, -1, 0);
969 done = widget;
970 }
971
972 return &color;
973 }
974
975 static void vdtree_color_cb(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell,
976 GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data)
977 {
978 ViewDir *vd = data;
979 gboolean set;
980
981 gtk_tree_model_get(tree_model, iter, DIR_COLUMN_COLOR, &set, -1);
982 g_object_set(G_OBJECT(cell),
983 "cell-background-gdk", vdtree_color_shifted(vd->view),
984 "cell-background-set", set, NULL);
985 }
986
987 static gboolean vdtree_destroy_node_cb(GtkTreeModel *store, GtkTreePath *tpath, GtkTreeIter *iter, gpointer data) 943 static gboolean vdtree_destroy_node_cb(GtkTreeModel *store, GtkTreePath *tpath, GtkTreeIter *iter, gpointer data)
988 { 944 {
989 NodeData *nd; 945 NodeData *nd;
990 946
991 gtk_tree_model_get(store, iter, DIR_COLUMN_POINTER, &nd, -1); 947 gtk_tree_model_get(store, iter, DIR_COLUMN_POINTER, &nd, -1);
1031 gtk_tree_sortable_set_default_sort_func(GTK_TREE_SORTABLE(store), vdtree_sort_cb, vd, NULL); 987 gtk_tree_sortable_set_default_sort_func(GTK_TREE_SORTABLE(store), vdtree_sort_cb, vd, NULL);
1032 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), 988 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store),
1033 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING); 989 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING);
1034 990
1035 g_signal_connect(G_OBJECT(vd->view), "row_activated", 991 g_signal_connect(G_OBJECT(vd->view), "row_activated",
1036 G_CALLBACK(vdtree_activate_cb), vd); 992 G_CALLBACK(vd_activate_cb), vd);
1037 g_signal_connect(G_OBJECT(vd->view), "row_expanded", 993 g_signal_connect(G_OBJECT(vd->view), "row_expanded",
1038 G_CALLBACK(vdtree_row_expanded), vd); 994 G_CALLBACK(vdtree_row_expanded), vd);
1039 g_signal_connect(G_OBJECT(vd->view), "row_collapsed", 995 g_signal_connect(G_OBJECT(vd->view), "row_collapsed",
1040 G_CALLBACK(vdtree_row_collapsed), vd); 996 G_CALLBACK(vdtree_row_collapsed), vd);
1041 #if 0 997 #if 0
1051 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY); 1007 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY);
1052 1008
1053 renderer = gtk_cell_renderer_pixbuf_new(); 1009 renderer = gtk_cell_renderer_pixbuf_new();
1054 gtk_tree_view_column_pack_start(column, renderer, FALSE); 1010 gtk_tree_view_column_pack_start(column, renderer, FALSE);
1055 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", DIR_COLUMN_ICON); 1011 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", DIR_COLUMN_ICON);
1056 gtk_tree_view_column_set_cell_data_func(column, renderer, vdtree_color_cb, vd, NULL); 1012 gtk_tree_view_column_set_cell_data_func(column, renderer, vd_color_cb, vd, NULL);
1057 1013
1058 renderer = gtk_cell_renderer_text_new(); 1014 renderer = gtk_cell_renderer_text_new();
1059 gtk_tree_view_column_pack_start(column, renderer, TRUE); 1015 gtk_tree_view_column_pack_start(column, renderer, TRUE);
1060 gtk_tree_view_column_add_attribute(column, renderer, "text", DIR_COLUMN_NAME); 1016 gtk_tree_view_column_add_attribute(column, renderer, "text", DIR_COLUMN_NAME);
1061 gtk_tree_view_column_set_cell_data_func(column, renderer, vdtree_color_cb, vd, NULL); 1017 gtk_tree_view_column_set_cell_data_func(column, renderer, vd_color_cb, vd, NULL);
1062 1018
1063 gtk_tree_view_append_column(GTK_TREE_VIEW(vd->view), column); 1019 gtk_tree_view_append_column(GTK_TREE_VIEW(vd->view), column);
1064 1020
1065 g_signal_connect(G_OBJECT(vd->view), "key_press_event", 1021 g_signal_connect(G_OBJECT(vd->view), "key_press_event",
1066 G_CALLBACK(vdtree_press_key_cb), vd); 1022 G_CALLBACK(vdtree_press_key_cb), vd);