Mercurial > geeqie
comparison src/view_dir_tree.c @ 783:d6a7fb4b8e7c
replaced directory path with FileData* dir_fd
author | nadvornik |
---|---|
date | Tue, 03 Jun 2008 19:44:19 +0000 |
parents | 44128da39e13 |
children | 548b193c084c |
comparison
equal
deleted
inserted
replaced
782:3f7a0420c293 | 783:d6a7fb4b8e7c |
---|---|
40 FileData *node; | 40 FileData *node; |
41 }; | 41 }; |
42 | 42 |
43 | 43 |
44 | 44 |
45 static gint vdtree_populate_path_by_iter(ViewDir *vd, GtkTreeIter *iter, gint force, const gchar *target_path); | 45 static gint vdtree_populate_path_by_iter(ViewDir *vd, GtkTreeIter *iter, gint force, FileData *target_fd); |
46 | 46 |
47 | 47 |
48 /* | 48 /* |
49 *---------------------------------------------------------------------------- | 49 *---------------------------------------------------------------------------- |
50 * utils | 50 * utils |
170 ViewDir *vd = data; | 170 ViewDir *vd = data; |
171 GtkTreeIter iter; | 171 GtkTreeIter iter; |
172 | 172 |
173 if (vd->drop_fd && vd_find_row(vd, vd->drop_fd, &iter)) | 173 if (vd->drop_fd && vd_find_row(vd, vd->drop_fd, &iter)) |
174 { | 174 { |
175 vdtree_populate_path_by_iter(vd, &iter, FALSE, vd->path); | 175 vdtree_populate_path_by_iter(vd, &iter, FALSE, vd->dir_fd); |
176 vdtree_expand_by_data(vd, vd->drop_fd, TRUE); | 176 vdtree_expand_by_data(vd, vd->drop_fd, TRUE); |
177 } | 177 } |
178 | 178 |
179 VDTREE_INFO(vd, drop_expand_id) = -1; | 179 VDTREE_INFO(vd, drop_expand_id) = -1; |
180 return FALSE; | 180 return FALSE; |
411 tpath = gtk_tree_model_get_path(GTK_TREE_MODEL(store), parent); | 411 tpath = gtk_tree_model_get_path(GTK_TREE_MODEL(store), parent); |
412 if (options->tree_descend_subdirs && | 412 if (options->tree_descend_subdirs && |
413 gtk_tree_view_row_expanded(GTK_TREE_VIEW(vd->view), tpath) && | 413 gtk_tree_view_row_expanded(GTK_TREE_VIEW(vd->view), tpath) && |
414 !nd->expanded) | 414 !nd->expanded) |
415 { | 415 { |
416 vdtree_populate_path_by_iter(vd, &child, FALSE, vd->path); | 416 vdtree_populate_path_by_iter(vd, &child, FALSE, vd->dir_fd); |
417 } | 417 } |
418 gtk_tree_path_free(tpath); | 418 gtk_tree_path_free(tpath); |
419 } | 419 } |
420 } | 420 } |
421 | 421 |
422 static gint vdtree_populate_path_by_iter(ViewDir *vd, GtkTreeIter *iter, gint force, const gchar *target_path) | 422 static gint vdtree_populate_path_by_iter(ViewDir *vd, GtkTreeIter *iter, gint force, FileData *target_fd) |
423 { | 423 { |
424 GtkTreeModel *store; | 424 GtkTreeModel *store; |
425 GList *list; | 425 GList *list; |
426 GList *work; | 426 GList *work; |
427 GList *old; | 427 GList *old; |
450 if (!force && filetime(nd->fd->path) == nd->fd->date) return TRUE; | 450 if (!force && filetime(nd->fd->path) == nd->fd->date) return TRUE; |
451 } | 451 } |
452 | 452 |
453 vdtree_busy_push(vd); | 453 vdtree_busy_push(vd); |
454 | 454 |
455 filelist_read(nd->fd->path, NULL, &list); | 455 filelist_read(nd->fd, NULL, &list); |
456 | 456 |
457 /* when hidden files are not enabled, and the user enters a hidden path, | 457 /* when hidden files are not enabled, and the user enters a hidden path, |
458 * allow the tree to display that path by specifically inserting the hidden entries | 458 * allow the tree to display that path by specifically inserting the hidden entries |
459 */ | 459 */ |
460 if (!options->file_filter.show_hidden_files && | 460 if (!options->file_filter.show_hidden_files && |
461 target_path && | 461 target_fd && |
462 strncmp(nd->fd->path, target_path, strlen(nd->fd->path)) == 0) | 462 strncmp(nd->fd->path, target_fd->path, strlen(nd->fd->path)) == 0) |
463 { | 463 { |
464 gint n; | 464 gint n; |
465 | 465 |
466 n = strlen(nd->fd->path); | 466 n = strlen(nd->fd->path); |
467 if (target_path[n] == G_DIR_SEPARATOR && target_path[n+1] == '.') | 467 if (target_fd->path[n] == G_DIR_SEPARATOR && target_fd->path[n+1] == '.') |
468 { | 468 { |
469 gchar *name8; | 469 gchar *name8; |
470 struct stat sbuf; | 470 struct stat sbuf; |
471 | 471 |
472 n++; | 472 n++; |
473 | 473 |
474 while (target_path[n] != '\0' && target_path[n] != G_DIR_SEPARATOR) n++; | 474 while (target_fd->path[n] != '\0' && target_fd->path[n] != G_DIR_SEPARATOR) n++; |
475 name8 = g_strndup(target_path, n); | 475 name8 = g_strndup(target_fd->path, n); |
476 | 476 |
477 if (stat_utf8(name8, &sbuf)) | 477 if (stat_utf8(name8, &sbuf)) |
478 { | 478 { |
479 list = g_list_prepend(list, file_data_new_simple(name8)); | 479 list = g_list_prepend(list, file_data_new_simple(name8)); |
480 } | 480 } |
513 cnd = vdtree_find_iter_by_name(vd, iter, fd->name, &child); | 513 cnd = vdtree_find_iter_by_name(vd, iter, fd->name, &child); |
514 if (cnd) | 514 if (cnd) |
515 { | 515 { |
516 old = g_list_remove(old, cnd); | 516 old = g_list_remove(old, cnd); |
517 if (cnd->expanded && cnd->fd->date != fd->date && | 517 if (cnd->expanded && cnd->fd->date != fd->date && |
518 vdtree_populate_path_by_iter(vd, &child, FALSE, target_path)) | 518 vdtree_populate_path_by_iter(vd, &child, FALSE, target_fd)) |
519 { | 519 { |
520 cnd->fd->size = fd->size; | 520 cnd->fd->size = fd->size; |
521 cnd->fd->date = fd->date; | 521 cnd->fd->date = fd->date; |
522 } | 522 } |
523 | 523 |
555 nd->last_update = current_time; | 555 nd->last_update = current_time; |
556 | 556 |
557 return TRUE; | 557 return TRUE; |
558 } | 558 } |
559 | 559 |
560 FileData *vdtree_populate_path(ViewDir *vd, const gchar *path, gint expand, gint force) | 560 FileData *vdtree_populate_path(ViewDir *vd, FileData *target_fd, gint expand, gint force) |
561 { | 561 { |
562 GList *list; | 562 GList *list; |
563 GList *work; | 563 GList *work; |
564 FileData *fd = NULL; | 564 FileData *fd = NULL; |
565 | 565 |
566 if (!path) return NULL; | 566 if (!target_fd) return NULL; |
567 | 567 |
568 vdtree_busy_push(vd); | 568 vdtree_busy_push(vd); |
569 | 569 |
570 list = parts_list(path); | 570 list = parts_list(target_fd->path); |
571 list = parts_list_add_node_points(vd, list); | 571 list = parts_list_add_node_points(vd, list); |
572 | 572 |
573 work = list; | 573 work = list; |
574 while (work) | 574 while (work) |
575 { | 575 { |
591 } | 591 } |
592 | 592 |
593 parent_pd = work->prev->data; | 593 parent_pd = work->prev->data; |
594 | 594 |
595 if (!vd_find_row(vd, parent_pd->node, &parent_iter) || | 595 if (!vd_find_row(vd, parent_pd->node, &parent_iter) || |
596 !vdtree_populate_path_by_iter(vd, &parent_iter, force, path) || | 596 !vdtree_populate_path_by_iter(vd, &parent_iter, force, target_fd) || |
597 (nd = vdtree_find_iter_by_name(vd, &parent_iter, pd->name, &iter)) == NULL) | 597 (nd = vdtree_find_iter_by_name(vd, &parent_iter, pd->name, &iter)) == NULL) |
598 { | 598 { |
599 log_printf("vdtree warning, aborted at %s\n", parent_pd->name); | 599 log_printf("vdtree warning, aborted at %s\n", parent_pd->name); |
600 parts_list_free(list); | 600 parts_list_free(list); |
601 vdtree_busy_pop(vd); | 601 vdtree_busy_pop(vd); |
609 if (expand) | 609 if (expand) |
610 { | 610 { |
611 vdtree_expand_by_iter(vd, &parent_iter, TRUE); | 611 vdtree_expand_by_iter(vd, &parent_iter, TRUE); |
612 vdtree_expand_by_iter(vd, &iter, TRUE); | 612 vdtree_expand_by_iter(vd, &iter, TRUE); |
613 } | 613 } |
614 vdtree_populate_path_by_iter(vd, &iter, force, path); | 614 vdtree_populate_path_by_iter(vd, &iter, force, target_fd); |
615 } | 615 } |
616 } | 616 } |
617 else | 617 else |
618 { | 618 { |
619 GtkTreeIter iter; | 619 GtkTreeIter iter; |
620 | 620 |
621 if (vd_find_row(vd, pd->node, &iter)) | 621 if (vd_find_row(vd, pd->node, &iter)) |
622 { | 622 { |
623 if (expand) vdtree_expand_by_iter(vd, &iter, TRUE); | 623 if (expand) vdtree_expand_by_iter(vd, &iter, TRUE); |
624 vdtree_populate_path_by_iter(vd, &iter, force, path); | 624 vdtree_populate_path_by_iter(vd, &iter, force, target_fd); |
625 } | 625 } |
626 } | 626 } |
627 | 627 |
628 work = work->next; | 628 work = work->next; |
629 } | 629 } |
666 /* hack, such that selection is only allowed to be changed from here */ | 666 /* hack, such that selection is only allowed to be changed from here */ |
667 selection_is_ok = TRUE; | 667 selection_is_ok = TRUE; |
668 gtk_tree_selection_select_iter(selection, &iter); | 668 gtk_tree_selection_select_iter(selection, &iter); |
669 selection_is_ok = FALSE; | 669 selection_is_ok = FALSE; |
670 | 670 |
671 if (!vdtree_populate_path_by_iter(vd, &iter, FALSE, vd->path)) return; | 671 if (!vdtree_populate_path_by_iter(vd, &iter, FALSE, vd->dir_fd)) return; |
672 | 672 |
673 vdtree_expand_by_iter(vd, &iter, TRUE); | 673 vdtree_expand_by_iter(vd, &iter, TRUE); |
674 | 674 |
675 if (fd && vd->select_func) | 675 if (fd && vd->select_func) |
676 { | 676 { |
677 vd->select_func(vd, fd->path, vd->select_data); | 677 vd->select_func(vd, fd->path, vd->select_data); |
678 } | 678 } |
679 } | 679 } |
680 | 680 |
681 gint vdtree_set_path(ViewDir *vd, const gchar *path) | 681 gint vdtree_set_fd(ViewDir *vd, FileData *dir_fd) |
682 { | 682 { |
683 FileData *fd; | 683 FileData *fd; |
684 GtkTreeIter iter; | 684 GtkTreeIter iter; |
685 | 685 |
686 if (!path) return FALSE; | 686 if (!dir_fd) return FALSE; |
687 if (vd->path && strcmp(path, vd->path) == 0) return TRUE; | 687 if (vd->dir_fd == dir_fd) return TRUE; |
688 | 688 |
689 g_free(vd->path); | 689 file_data_unref(vd->dir_fd); |
690 vd->path = g_strdup(path); | 690 vd->dir_fd = file_data_ref(dir_fd);; |
691 | 691 |
692 fd = vdtree_populate_path(vd, vd->path, TRUE, FALSE); | 692 fd = vdtree_populate_path(vd, vd->dir_fd, TRUE, FALSE); |
693 | 693 |
694 if (!fd) return FALSE; | 694 if (!fd) return FALSE; |
695 | 695 |
696 if (vd_find_row(vd, fd, &iter)) | 696 if (vd_find_row(vd, fd, &iter)) |
697 { | 697 { |
718 } | 718 } |
719 #endif | 719 #endif |
720 | 720 |
721 void vdtree_refresh(ViewDir *vd) | 721 void vdtree_refresh(ViewDir *vd) |
722 { | 722 { |
723 vdtree_populate_path(vd, vd->path, FALSE, TRUE); | 723 vdtree_populate_path(vd, vd->dir_fd, FALSE, TRUE); |
724 } | 724 } |
725 | 725 |
726 const gchar *vdtree_row_get_path(ViewDir *vd, gint row) | 726 const gchar *vdtree_row_get_path(ViewDir *vd, gint row) |
727 { | 727 { |
728 log_printf("FIXME: no get row path\n"); | 728 log_printf("FIXME: no get row path\n"); |
771 case GDK_plus: | 771 case GDK_plus: |
772 case GDK_Right: | 772 case GDK_Right: |
773 case GDK_KP_Add: | 773 case GDK_KP_Add: |
774 if (fd) | 774 if (fd) |
775 { | 775 { |
776 vdtree_populate_path_by_iter(vd, &iter, FALSE, vd->path); | 776 vdtree_populate_path_by_iter(vd, &iter, FALSE, vd->dir_fd); |
777 vdtree_icon_set_by_iter(vd, &iter, vd->pf->open); | 777 vdtree_icon_set_by_iter(vd, &iter, vd->pf->open); |
778 } | 778 } |
779 break; | 779 break; |
780 } | 780 } |
781 | 781 |
834 */ | 834 */ |
835 if (bevent->button == MOUSE_BUTTON_LEFT && | 835 if (bevent->button == MOUSE_BUTTON_LEFT && |
836 !left_of_expander && | 836 !left_of_expander && |
837 !gtk_tree_view_row_expanded(GTK_TREE_VIEW(vd->view), tpath)) | 837 !gtk_tree_view_row_expanded(GTK_TREE_VIEW(vd->view), tpath)) |
838 { | 838 { |
839 vdtree_populate_path_by_iter(vd, &iter, FALSE, vd->path); | 839 vdtree_populate_path_by_iter(vd, &iter, FALSE, vd->dir_fd); |
840 vdtree_icon_set_by_iter(vd, &iter, vd->pf->open); | 840 vdtree_icon_set_by_iter(vd, &iter, vd->pf->open); |
841 } | 841 } |
842 | 842 |
843 gtk_tree_path_free(tpath); | 843 gtk_tree_path_free(tpath); |
844 return FALSE; | 844 return FALSE; |
900 | 900 |
901 fd = file_data_new_simple(path); | 901 fd = file_data_new_simple(path); |
902 vdtree_add_by_data(vd, fd, NULL); | 902 vdtree_add_by_data(vd, fd, NULL); |
903 | 903 |
904 vdtree_expand_by_data(vd, fd, TRUE); | 904 vdtree_expand_by_data(vd, fd, TRUE); |
905 vdtree_populate_path(vd, path, FALSE, FALSE); | 905 vdtree_populate_path(vd, fd, FALSE, FALSE); |
906 } | 906 } |
907 | 907 |
908 static gboolean vdtree_destroy_node_cb(GtkTreeModel *store, GtkTreePath *tpath, GtkTreeIter *iter, gpointer data) | 908 static gboolean vdtree_destroy_node_cb(GtkTreeModel *store, GtkTreePath *tpath, GtkTreeIter *iter, gpointer data) |
909 { | 909 { |
910 NodeData *nd; | 910 NodeData *nd; |
926 | 926 |
927 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); | 927 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); |
928 gtk_tree_model_foreach(store, vdtree_destroy_node_cb, vd); | 928 gtk_tree_model_foreach(store, vdtree_destroy_node_cb, vd); |
929 } | 929 } |
930 | 930 |
931 ViewDir *vdtree_new(ViewDir *vd, const gchar *path) | 931 ViewDir *vdtree_new(ViewDir *vd, FileData *dir_fd) |
932 { | 932 { |
933 GtkTreeStore *store; | 933 GtkTreeStore *store; |
934 GtkTreeSelection *selection; | 934 GtkTreeSelection *selection; |
935 GtkTreeViewColumn *column; | 935 GtkTreeViewColumn *column; |
936 GtkCellRenderer *renderer; | 936 GtkCellRenderer *renderer; |