comparison src/layout.c @ 783:d6a7fb4b8e7c

replaced directory path with FileData* dir_fd
author nadvornik
date Tue, 03 Jun 2008 19:44:19 +0000
parents e095a66b428f
children a2209b1f769d
comparison
equal deleted inserted replaced
782:3f7a0420c293 783:d6a7fb4b8e7c
121 gchar *buf; 121 gchar *buf;
122 122
123 if (gtk_combo_box_get_active(GTK_COMBO_BOX(widget)) < 0) return; 123 if (gtk_combo_box_get_active(GTK_COMBO_BOX(widget)) < 0) return;
124 124
125 buf = g_strdup(gtk_entry_get_text(GTK_ENTRY(lw->path_entry))); 125 buf = g_strdup(gtk_entry_get_text(GTK_ENTRY(lw->path_entry)));
126 if (!buf || (lw->path && strcmp(buf, lw->path) == 0)) 126 if (!buf || (lw->dir_fd && strcmp(buf, lw->dir_fd->path) == 0))
127 { 127 {
128 g_free(buf); 128 g_free(buf);
129 return; 129 return;
130 } 130 }
131 131
144 parse_out_relatives(buf); 144 parse_out_relatives(buf);
145 base = remove_level_from_path(buf); 145 base = remove_level_from_path(buf);
146 146
147 if (isdir(buf)) 147 if (isdir(buf))
148 { 148 {
149 if ((!lw->path || strcmp(lw->path, buf) != 0) && layout_set_path(lw, buf)) 149 if ((!lw->dir_fd || strcmp(lw->dir_fd->path, buf) != 0) && layout_set_path(lw, buf))
150 { 150 {
151 gint pos = -1; 151 gint pos = -1;
152 /* put the G_DIR_SEPARATOR back, if we are in tab completion for a dir and result was path change */ 152 /* put the G_DIR_SEPARATOR back, if we are in tab completion for a dir and result was path change */
153 gtk_editable_insert_text(GTK_EDITABLE(lw->path_entry), G_DIR_SEPARATOR_S, -1, &pos); 153 gtk_editable_insert_text(GTK_EDITABLE(lw->path_entry), G_DIR_SEPARATOR_S, -1, &pos);
154 gtk_editable_set_position(GTK_EDITABLE(lw->path_entry), 154 gtk_editable_set_position(GTK_EDITABLE(lw->path_entry),
155 strlen(gtk_entry_get_text(GTK_ENTRY(lw->path_entry)))); 155 strlen(gtk_entry_get_text(GTK_ENTRY(lw->path_entry))));
156 } 156 }
157 } 157 }
158 else if (lw->path && strcmp(lw->path, base) == 0) 158 else if (lw->dir_fd && strcmp(lw->dir_fd->path, base) == 0)
159 { 159 {
160 layout_list_scroll_to_subpart(lw, filename_from_path(buf)); 160 layout_list_scroll_to_subpart(lw, filename_from_path(buf));
161 } 161 }
162 162
163 g_free(base); 163 g_free(base);
207 gtk_widget_show(tabcomp); 207 gtk_widget_show(tabcomp);
208 208
209 g_signal_connect(G_OBJECT(lw->path_entry->parent), "changed", 209 g_signal_connect(G_OBJECT(lw->path_entry->parent), "changed",
210 G_CALLBACK(layout_path_entry_changed_cb), lw); 210 G_CALLBACK(layout_path_entry_changed_cb), lw);
211 211
212 lw->vd = vd_new(lw->dir_view_type, lw->path); 212 lw->vd = vd_new(lw->dir_view_type, lw->dir_fd);
213 vd_set_layout(lw->vd, lw); 213 vd_set_layout(lw->vd, lw);
214 vd_set_select_func(lw->vd, layout_vd_select_cb, lw); 214 vd_set_select_func(lw->vd, layout_vd_select_cb, lw);
215 215
216 lw->dir_view = lw->vd->widget; 216 lw->dir_view = lw->vd->widget;
217 217
792 if (lw->vf) return vf_index_get_data(lw->vf, index); 792 if (lw->vf) return vf_index_get_data(lw->vf, index);
793 793
794 return NULL; 794 return NULL;
795 } 795 }
796 796
797 gint layout_list_get_index(LayoutWindow *lw, const gchar *path) 797 gint layout_list_get_index(LayoutWindow *lw, FileData *fd)
798 { 798 {
799 if (!layout_valid(&lw)) return -1; 799 if (!layout_valid(&lw) || !fd) return -1;
800 800
801 if (lw->vf) return vf_index_by_path(lw->vf, path); 801 if (lw->vf) return vf_index_by_path(lw->vf, fd->path);
802 802
803 return -1; 803 return -1;
804 } 804 }
805 805
806 void layout_list_sync_fd(LayoutWindow *lw, FileData *fd) 806 void layout_list_sync_fd(LayoutWindow *lw, FileData *fd)
897 */ 897 */
898 898
899 const gchar *layout_get_path(LayoutWindow *lw) 899 const gchar *layout_get_path(LayoutWindow *lw)
900 { 900 {
901 if (!layout_valid(&lw)) return NULL; 901 if (!layout_valid(&lw)) return NULL;
902 return lw->path; 902 return lw->dir_fd ? lw->dir_fd->path : NULL;
903 } 903 }
904 904
905 static void layout_sync_path(LayoutWindow *lw) 905 static void layout_sync_path(LayoutWindow *lw)
906 { 906 {
907 if (!lw->path) return; 907 if (!lw->dir_fd) return;
908 908
909 lw->last_time = filetime(lw->path); 909 lw->last_version = lw->dir_fd->version;
910 910
911 if (lw->path_entry) gtk_entry_set_text(GTK_ENTRY(lw->path_entry), lw->path); 911 if (lw->path_entry) gtk_entry_set_text(GTK_ENTRY(lw->path_entry), lw->dir_fd->path);
912 if (lw->vd) vd_set_path(lw->vd, lw->path); 912 if (lw->vd) vd_set_fd(lw->vd, lw->dir_fd);
913 913
914 if (lw->vf) vf_set_path(lw->vf, lw->path); 914 if (lw->vf) vf_set_fd(lw->vf, lw->dir_fd);
915 } 915 }
916 916
917 gint layout_set_path(LayoutWindow *lw, const gchar *path) 917 gint layout_set_path(LayoutWindow *lw, const gchar *path)
918 { 918 {
919 FileData *fd = file_data_new_simple(path);
920 gint ret = layout_set_fd(lw, fd);
921 file_data_unref(fd);
922 return ret;
923 }
924
925
926 gint layout_set_fd(LayoutWindow *lw, FileData *fd)
927 {
919 gint have_file = FALSE; 928 gint have_file = FALSE;
920 929
921 if (!layout_valid(&lw)) return FALSE; 930 if (!layout_valid(&lw)) return FALSE;
922 931
923 if (!path || !isname(path)) return FALSE; 932 if (!fd || !isname(fd->path)) return FALSE;
924 if (lw->path && path && strcmp(path, lw->path) == 0) 933 if (lw->dir_fd && fd == lw->dir_fd)
925 { 934 {
926 return TRUE; 935 return TRUE;
927 } 936 }
928 937
929 if (isdir(path)) 938 if (isdir(fd->path))
930 { 939 {
931 g_free(lw->path); 940 file_data_unref(lw->dir_fd);
932 lw->path = g_strdup(path); 941 lw->dir_fd = file_data_ref(fd);
933 } 942 }
934 else 943 else
935 { 944 {
936 gchar *base; 945 gchar *base;
937 946
938 base = remove_level_from_path(path); 947 base = remove_level_from_path(fd->path);
939 if (lw->path && strcmp(lw->path, base) == 0) 948 if (lw->dir_fd && strcmp(lw->dir_fd->path, base) == 0)
940 { 949 {
941 g_free(base); 950 g_free(base);
942 } 951 }
943 else if (isdir(base)) 952 else if (isdir(base))
944 { 953 {
945 g_free(lw->path); 954 file_data_unref(lw->dir_fd);
946 lw->path = base; 955 lw->dir_fd = file_data_new_simple(base);
956 g_free(base);
947 } 957 }
948 else 958 else
949 { 959 {
950 g_free(base); 960 g_free(base);
951 return FALSE; 961 return FALSE;
952 } 962 }
953 if (isfile(path)) have_file = TRUE; 963 if (isfile(fd->path)) have_file = TRUE;
954 } 964 }
955 965
956 if (lw->path_entry) tab_completion_append_to_history(lw->path_entry, lw->path); 966 if (lw->path_entry) tab_completion_append_to_history(lw->path_entry, lw->dir_fd->path);
957 layout_sync_path(lw); 967 layout_sync_path(lw);
958 968
959 if (have_file) 969 if (have_file)
960 { 970 {
961 gint row; 971 gint row;
962 972
963 row = layout_list_get_index(lw, path); 973 row = layout_list_get_index(lw, fd);
964 if (row >= 0) 974 if (row >= 0)
965 { 975 {
966 layout_image_set_index(lw, row); 976 layout_image_set_index(lw, row);
967 } 977 }
968 else 978 else
969 { 979 {
970 layout_image_set_fd(lw, file_data_new_simple(path)); 980 layout_image_set_fd(lw, fd);
971 } 981 }
972 } 982 }
973 else if (!options->lazy_image_sync) 983 else if (!options->lazy_image_sync)
974 { 984 {
975 layout_image_set_index(lw, 0); 985 layout_image_set_index(lw, 0);
978 return TRUE; 988 return TRUE;
979 } 989 }
980 990
981 static void layout_refresh_lists(LayoutWindow *lw) 991 static void layout_refresh_lists(LayoutWindow *lw)
982 { 992 {
983 if (lw->path) lw->last_time = filetime(lw->path); 993 if (lw->dir_fd) lw->last_version = lw->dir_fd->version;
984 994
985 if (lw->vd) vd_refresh(lw->vd); 995 if (lw->vd) vd_refresh(lw->vd);
986 996
987 if (lw->vf) vf_refresh(lw->vf); 997 if (lw->vf) vf_refresh(lw->vf);
988 } 998 }
989 999
990 static void layout_refresh_by_time(LayoutWindow *lw) 1000 static void layout_refresh_by_time(LayoutWindow *lw)
991 { 1001 {
992 layout_refresh_lists(lw); 1002 layout_refresh_lists(lw);
993 1003
994 if (lw->image && filetime(layout_image_get_path(lw)) >= lw->last_time) 1004 if (lw->image && layout_image_get_fd(lw)->version != lw->last_version) // FIXME - move to layout_image and fix
995 { 1005 {
996 layout_image_refresh(lw); 1006 layout_image_refresh(lw);
997 } 1007 }
998 } 1008 }
999 1009
1012 { 1022 {
1013 LayoutWindow *lw = data; 1023 LayoutWindow *lw = data;
1014 1024
1015 if (!options->update_on_time_change) return TRUE; 1025 if (!options->update_on_time_change) return TRUE;
1016 1026
1017 if (lw->path) 1027 if (lw->dir_fd)
1018 { 1028 {
1019 time_t new_time; 1029 if (lw->dir_fd->version != lw->last_version)
1020
1021 new_time = filetime(lw->path);
1022
1023 if (new_time > 0 && new_time > lw->last_time)
1024 { 1030 {
1025 DEBUG_1("layout path time changed, refreshing..."); 1031 DEBUG_1("layout path time changed, refreshing...");
1026 layout_refresh_by_time(lw); 1032 layout_refresh_by_time(lw);
1027 } 1033 }
1028 } 1034 }
1574 gtk_widget_grab_focus(lw->image->widget); 1580 gtk_widget_grab_focus(lw->image->widget);
1575 } 1581 }
1576 1582
1577 void layout_style_set(LayoutWindow *lw, gint style, const gchar *order) 1583 void layout_style_set(LayoutWindow *lw, gint style, const gchar *order)
1578 { 1584 {
1579 gchar *path; 1585 FileData *dir_fd;
1580 gint i; 1586 gint i;
1581 1587
1582 if (!layout_valid(&lw)) return; 1588 if (!layout_valid(&lw)) return;
1583 1589
1584 if (style != -1) 1590 if (style != -1)
1599 /* remember state */ 1605 /* remember state */
1600 1606
1601 layout_image_slideshow_stop(lw); 1607 layout_image_slideshow_stop(lw);
1602 layout_image_full_screen_stop(lw); 1608 layout_image_full_screen_stop(lw);
1603 1609
1604 path = lw->path; 1610 dir_fd = lw->dir_fd;
1605 lw->path = NULL; 1611 lw->dir_fd = NULL;
1606 lw->image = NULL; 1612 lw->image = NULL;
1607 lw->utility_box = NULL; 1613 lw->utility_box = NULL;
1608 1614
1609 layout_geometry_get_dividers(lw, &lw->div_h, &lw->div_v); 1615 layout_geometry_get_dividers(lw, &lw->div_h, &lw->div_v);
1610 1616
1656 layout_util_sync(lw); 1662 layout_util_sync(lw);
1657 layout_status_update_all(lw); 1663 layout_status_update_all(lw);
1658 1664
1659 /* sync */ 1665 /* sync */
1660 1666
1661 if (image_get_path(lw->image)) 1667 if (image_get_fd(lw->image))
1662 { 1668 {
1663 layout_set_path(lw, image_get_path(lw->image)); 1669 layout_set_fd(lw, image_get_fd(lw->image));
1664 } 1670 }
1665 else 1671 else
1666 { 1672 {
1667 layout_set_path(lw, path); 1673 layout_set_fd(lw, dir_fd);
1668 } 1674 }
1669 image_top_window_set_sync(lw->image, (lw->tools_float || lw->tools_hidden)); 1675 image_top_window_set_sync(lw->image, (lw->tools_float || lw->tools_hidden));
1670 1676
1671 /* clean up */ 1677 /* clean up */
1672 1678
1673 g_free(path); 1679 file_data_unref(dir_fd);
1674 } 1680 }
1675 1681
1676 void layout_styles_update(void) 1682 void layout_styles_update(void)
1677 { 1683 {
1678 GList *work; 1684 GList *work;
1827 1833
1828 layout_bars_close(lw); 1834 layout_bars_close(lw);
1829 1835
1830 gtk_widget_destroy(lw->window); 1836 gtk_widget_destroy(lw->window);
1831 1837
1832 g_free(lw->path); 1838 file_data_unref(lw->dir_fd);
1833 1839
1834 g_free(lw); 1840 g_free(lw);
1835 } 1841 }
1836 1842
1837 static gint layout_delete_cb(GtkWidget *widget, GdkEventAny *event, gpointer data) 1843 static gint layout_delete_cb(GtkWidget *widget, GdkEventAny *event, gpointer data)
1840 1846
1841 layout_close(lw); 1847 layout_close(lw);
1842 return TRUE; 1848 return TRUE;
1843 } 1849 }
1844 1850
1845 LayoutWindow *layout_new(const gchar *path, gint popped, gint hidden) 1851 LayoutWindow *layout_new(FileData *dir_fd, gint popped, gint hidden)
1846 { 1852 {
1847 return layout_new_with_geometry(path, popped, hidden, NULL); 1853 return layout_new_with_geometry(dir_fd, popped, hidden, NULL);
1848 } 1854 }
1849 1855
1850 LayoutWindow *layout_new_with_geometry(const gchar *path, gint popped, gint hidden, 1856 LayoutWindow *layout_new_with_geometry(FileData *dir_fd, gint popped, gint hidden,
1851 const gchar *geometry) 1857 const gchar *geometry)
1852 { 1858 {
1853 LayoutWindow *lw; 1859 LayoutWindow *lw;
1854 GdkGeometry hint; 1860 GdkGeometry hint;
1855 GdkWindowHints hint_mask; 1861 GdkWindowHints hint_mask;
1956 image_top_window_set_sync(lw->image, (lw->tools_float || lw->tools_hidden)); 1962 image_top_window_set_sync(lw->image, (lw->tools_float || lw->tools_hidden));
1957 1963
1958 layout_util_sync(lw); 1964 layout_util_sync(lw);
1959 layout_status_update_all(lw); 1965 layout_status_update_all(lw);
1960 1966
1961 if (path) 1967 if (dir_fd)
1962 { 1968 {
1963 layout_set_path(lw, path); 1969 layout_set_fd(lw, dir_fd);
1964 } 1970 }
1965 else 1971 else
1966 { 1972 {
1967 GdkPixbuf *pixbuf; 1973 GdkPixbuf *pixbuf;
1968 1974
1970 image_change_pixbuf(lw->image, pixbuf, 1.0); 1976 image_change_pixbuf(lw->image, pixbuf, 1.0);
1971 gdk_pixbuf_unref(pixbuf); 1977 gdk_pixbuf_unref(pixbuf);
1972 } 1978 }
1973 1979
1974 /* set up the time stat timeout */ 1980 /* set up the time stat timeout */
1975 lw->last_time = 0; 1981 lw->last_version = 0;
1976 lw->last_time_id = g_timeout_add(5000, layout_check_for_update_cb, lw); 1982 lw->last_time_id = g_timeout_add(5000, layout_check_for_update_cb, lw);
1977 1983
1978 if (geometry) 1984 if (geometry)
1979 { 1985 {
1980 if (!gtk_window_parse_geometry(GTK_WINDOW(lw->window), geometry)) 1986 if (!gtk_window_parse_geometry(GTK_WINDOW(lw->window), geometry))
1998 */ 2004 */
1999 2005
2000 static void layout_real_time_update(LayoutWindow *lw) 2006 static void layout_real_time_update(LayoutWindow *lw)
2001 { 2007 {
2002 /* this resets the last time stamp of path so that a refresh does not occur 2008 /* this resets the last time stamp of path so that a refresh does not occur
2003 * from an internal file operation. 2009 * from an internal file operation. FIXME
2004 */ 2010 */
2005 2011
2006 if (lw->path) lw->last_time = filetime(lw->path); 2012 if (lw->dir_fd) lw->last_version = lw->dir_fd->version;
2007 } 2013 }
2008 2014
2009 static void layout_real_renamed(LayoutWindow *lw, FileData *fd) 2015 static void layout_real_renamed(LayoutWindow *lw, FileData *fd)
2010 { 2016 {
2011 if (lw->image) layout_image_maint_renamed(lw, fd); 2017 if (lw->image) layout_image_maint_renamed(lw, fd);