Mercurial > geeqie
comparison src/view_dir.c @ 399:d071a3555011
Reduce code redundancy with the introduction of a new
function named vd_get_fd_from_tree_path().
author | zas_ |
---|---|
date | Thu, 17 Apr 2008 18:44:17 +0000 |
parents | a7be56e84870 |
children | 35346871af88 |
comparison
equal
deleted
inserted
replaced
398:c4080362d619 | 399:d071a3555011 |
---|---|
152 } | 152 } |
153 | 153 |
154 return ret; | 154 return ret; |
155 } | 155 } |
156 | 156 |
157 FileData *vd_get_fd_from_tree_path(ViewDir *vd, GtkTreeView *tview, GtkTreePath *tpath) | |
158 { | |
159 GtkTreeIter iter; | |
160 FileData *fd = NULL; | |
161 GtkTreeModel *store; | |
162 | |
163 store = gtk_tree_view_get_model(tview); | |
164 gtk_tree_model_get_iter(store, &iter, tpath); | |
165 switch (vd->type) | |
166 { | |
167 case DIRVIEW_LIST: | |
168 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1); | |
169 break; | |
170 case DIRVIEW_TREE: | |
171 { | |
172 NodeData *nd; | |
173 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
174 fd = (nd) ? nd->fd : NULL; | |
175 }; | |
176 break; | |
177 } | |
178 | |
179 return fd; | |
180 } | |
181 | |
157 static gint vd_rename_cb(TreeEditData *td, const gchar *old, const gchar *new, gpointer data) | 182 static gint vd_rename_cb(TreeEditData *td, const gchar *old, const gchar *new, gpointer data) |
158 { | 183 { |
159 ViewDir *vd = data; | 184 ViewDir *vd = data; |
160 GtkTreeModel *store; | |
161 GtkTreeIter iter; | |
162 FileData *fd; | 185 FileData *fd; |
163 gchar *old_path; | 186 gchar *old_path; |
164 gchar *new_path; | 187 gchar *new_path; |
165 gchar *base; | 188 gchar *base; |
166 | 189 |
167 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); | 190 fd = vd_get_fd_from_tree_path(vd, GTK_TREE_VIEW(vd->view), td->path); |
168 if (!gtk_tree_model_get_iter(store, &iter, td->path)) return FALSE; | |
169 | |
170 switch(vd->type) | |
171 { | |
172 case DIRVIEW_LIST: | |
173 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1); | |
174 break; | |
175 case DIRVIEW_TREE: | |
176 { | |
177 NodeData *nd; | |
178 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
179 if (!nd) return FALSE; | |
180 fd = nd->fd; | |
181 }; | |
182 break; | |
183 } | |
184 | |
185 if (!fd) return FALSE; | 191 if (!fd) return FALSE; |
186 | 192 |
187 old_path = g_strdup(fd->path); | 193 old_path = g_strdup(fd->path); |
188 | 194 |
189 base = remove_level_from_path(old_path); | 195 base = remove_level_from_path(old_path); |
667 GtkSelectionData *selection_data, guint info, | 673 GtkSelectionData *selection_data, guint info, |
668 guint time, gpointer data) | 674 guint time, gpointer data) |
669 { | 675 { |
670 ViewDir *vd = data; | 676 ViewDir *vd = data; |
671 GtkTreePath *tpath; | 677 GtkTreePath *tpath; |
672 GtkTreeIter iter; | |
673 FileData *fd = NULL; | 678 FileData *fd = NULL; |
674 | 679 |
675 vd->click_fd = NULL; | 680 vd->click_fd = NULL; |
676 | 681 |
677 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), x, y, | 682 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), x, y, |
678 &tpath, NULL, NULL, NULL)) | 683 &tpath, NULL, NULL, NULL)) |
679 { | 684 { |
680 GtkTreeModel *store; | 685 fd = vd_get_fd_from_tree_path(vd, GTK_TREE_VIEW(widget), tpath); |
681 | |
682 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
683 gtk_tree_model_get_iter(store, &iter, tpath); | |
684 switch (vd->type) | |
685 { | |
686 case DIRVIEW_LIST: | |
687 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1); | |
688 break; | |
689 case DIRVIEW_TREE: | |
690 { | |
691 NodeData *nd; | |
692 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
693 fd = (nd) ? nd->fd : NULL; | |
694 }; | |
695 break; | |
696 } | |
697 gtk_tree_path_free(tpath); | 686 gtk_tree_path_free(tpath); |
698 } | 687 } |
699 | 688 |
700 if (!fd) return; | 689 if (!fd) return; |
701 | 690 |
719 } | 708 } |
720 | 709 |
721 static void vd_drop_update(ViewDir *vd, gint x, gint y) | 710 static void vd_drop_update(ViewDir *vd, gint x, gint y) |
722 { | 711 { |
723 GtkTreePath *tpath; | 712 GtkTreePath *tpath; |
724 GtkTreeIter iter; | |
725 FileData *fd = NULL; | 713 FileData *fd = NULL; |
726 | 714 |
727 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vd->view), x, y, | 715 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vd->view), x, y, |
728 &tpath, NULL, NULL, NULL)) | 716 &tpath, NULL, NULL, NULL)) |
729 { | 717 { |
730 GtkTreeModel *store; | 718 fd = vd_get_fd_from_tree_path(vd, GTK_TREE_VIEW(vd->view), tpath); |
731 | |
732 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); | |
733 gtk_tree_model_get_iter(store, &iter, tpath); | |
734 switch (vd->type) | |
735 { | |
736 case DIRVIEW_LIST: | |
737 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1); | |
738 break; | |
739 case DIRVIEW_TREE: | |
740 { | |
741 NodeData *nd; | |
742 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
743 fd = (nd) ? nd->fd : NULL; | |
744 }; | |
745 break; | |
746 } | |
747 gtk_tree_path_free(tpath); | 719 gtk_tree_path_free(tpath); |
748 } | 720 } |
749 | 721 |
750 if (fd != vd->drop_fd) | 722 if (fd != vd->drop_fd) |
751 { | 723 { |
882 } | 854 } |
883 | 855 |
884 void vd_activate_cb(GtkTreeView *tview, GtkTreePath *tpath, GtkTreeViewColumn *column, gpointer data) | 856 void vd_activate_cb(GtkTreeView *tview, GtkTreePath *tpath, GtkTreeViewColumn *column, gpointer data) |
885 { | 857 { |
886 ViewDir *vd = data; | 858 ViewDir *vd = data; |
887 GtkTreeModel *store; | 859 FileData *fd = vd_get_fd_from_tree_path(vd, tview, tpath); |
888 GtkTreeIter iter; | |
889 FileData *fd; | |
890 | |
891 store = gtk_tree_view_get_model(tview); | |
892 gtk_tree_model_get_iter(store, &iter, tpath); | |
893 switch (vd->type) | |
894 { | |
895 case DIRVIEW_LIST: | |
896 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1); | |
897 break; | |
898 case DIRVIEW_TREE: | |
899 { | |
900 NodeData *nd; | |
901 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
902 fd = (nd) ? nd->fd : NULL; | |
903 }; | |
904 break; | |
905 } | |
906 | 860 |
907 vd_select_row(vd, fd); | 861 vd_select_row(vd, fd); |
908 } | 862 } |
909 | 863 |
910 static GdkColor *vd_color_shifted(GtkWidget *widget) | 864 static GdkColor *vd_color_shifted(GtkWidget *widget) |
939 | 893 |
940 gint vd_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | 894 gint vd_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) |
941 { | 895 { |
942 ViewDir *vd = data; | 896 ViewDir *vd = data; |
943 GtkTreePath *tpath; | 897 GtkTreePath *tpath; |
944 GtkTreeIter iter; | |
945 FileData *fd = NULL; | 898 FileData *fd = NULL; |
946 | 899 |
947 vd_color_set(vd, vd->click_fd, FALSE); | 900 vd_color_set(vd, vd->click_fd, FALSE); |
948 | 901 |
949 if (bevent->button != 1) return TRUE; | 902 if (bevent->button != 1) return TRUE; |
950 | 903 |
951 if ((bevent->x != 0 || bevent->y != 0) && | 904 if ((bevent->x != 0 || bevent->y != 0) && |
952 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | 905 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, |
953 &tpath, NULL, NULL, NULL)) | 906 &tpath, NULL, NULL, NULL)) |
954 { | 907 { |
955 GtkTreeModel *store; | 908 fd = vd_get_fd_from_tree_path(vd, GTK_TREE_VIEW(widget), tpath); |
956 | |
957 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
958 gtk_tree_model_get_iter(store, &iter, tpath); | |
959 switch (vd->type) | |
960 { | |
961 case DIRVIEW_LIST: | |
962 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1); | |
963 break; | |
964 case DIRVIEW_TREE: | |
965 { | |
966 NodeData *nd; | |
967 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
968 fd = (nd) ? nd->fd : NULL; | |
969 }; | |
970 break; | |
971 } | |
972 | |
973 gtk_tree_path_free(tpath); | 909 gtk_tree_path_free(tpath); |
974 } | 910 } |
975 | 911 |
976 if (fd && vd->click_fd == fd) | 912 if (fd && vd->click_fd == fd) |
977 { | 913 { |