comparison src/view_file_icon.c @ 810:602cec932587

optimized vficon_refresh_real
author nadvornik
date Mon, 09 Jun 2008 18:28:28 +0000
parents 5a3fc27147ab
children f1ce59985518
comparison
equal deleted inserted replaced
809:83d3abd80b64 810:602cec932587
2057 */ 2057 */
2058 2058
2059 static gint vficon_refresh_real(ViewFile *vf, gint keep_position) 2059 static gint vficon_refresh_real(ViewFile *vf, gint keep_position)
2060 { 2060 {
2061 gint ret = TRUE; 2061 gint ret = TRUE;
2062 GList *old_list; 2062 GList *work, *work_fd;
2063 GList *work;
2064 IconData *focus_id; 2063 IconData *focus_id;
2064 GList *new_filelist = NULL;
2065 2065
2066 focus_id = VFICON_INFO(vf, focus_id); 2066 focus_id = VFICON_INFO(vf, focus_id);
2067 2067
2068 old_list = vf->list;
2069 vf->list = NULL;
2070
2071 if (vf->dir_fd) 2068 if (vf->dir_fd)
2072 { 2069 {
2073 ret = iconlist_read(vf->dir_fd, &vf->list); 2070 ret = filelist_read(vf->dir_fd, &new_filelist, NULL);
2074 } 2071 }
2072
2073 vf->list = iconlist_sort(vf->list, vf->sort_method, vf->sort_ascend); /* the list might not be sorted if there were renames */
2074 new_filelist = filelist_sort(new_filelist, vf->sort_method, vf->sort_ascend);
2075 2075
2076 /* check for same files from old_list */ 2076 /* check for same files from old_list */
2077 work = old_list; 2077 work = vf->list;
2078 while (work) 2078 work_fd = new_filelist;
2079 { 2079 while (work || work_fd)
2080 IconData *id = work->data; 2080 {
2081 FileData *fd = id->fd; 2081 IconData *id = NULL;
2082 GList *needle = vf->list; 2082 FileData *fd = NULL;
2083 2083 FileData *new_fd = NULL;
2084 while (needle) 2084 gint match;
2085 { 2085
2086 IconData *idn = needle->data; 2086 if (work && work_fd)
2087 FileData *fdn = idn->fd; 2087 {
2088 2088 id = work->data;
2089 if (fdn == fd) 2089 fd = id->fd;
2090
2091 new_fd = work_fd->data;
2092
2093 if (fd == new_fd)
2090 { 2094 {
2091 /* swap, to retain old thumb, selection */ 2095 /* not changed, go to next */
2092 needle->data = id; 2096 work = work->next;
2093 work->data = idn; 2097 work_fd = work_fd->next;
2094 needle = NULL; 2098 continue;
2095 } 2099 }
2096 else 2100
2097 { 2101 match = filelist_sort_compare_filedata_full(fd, new_fd, vf->sort_method, vf->sort_ascend);
2098 needle = needle->next; 2102 if (match == 0) g_warning("multiple fd for the same path");
2099 } 2103 }
2100 } 2104 else if (work)
2101 2105 {
2102 work = work->next; 2106 id = work->data;
2103 } 2107 fd = id->fd;
2104 2108 match = -1;
2105 vf->list = iconlist_sort(vf->list, vf->sort_method, vf->sort_ascend); 2109 }
2106 2110 else /* work_fd */
2107 work = old_list; 2111 {
2108 while (work) 2112 new_fd = work_fd->data;
2109 { 2113 match = 1;
2110 IconData *id = work->data; 2114 }
2111 work = work->next; 2115
2112 2116 if (match < 0)
2113 if (id == VFICON_INFO(vf, prev_selection)) VFICON_INFO(vf, prev_selection) = NULL; 2117 {
2114 if (id == VFICON_INFO(vf, click_id)) VFICON_INFO(vf, click_id) = NULL; 2118 /* file no longer exists, delete from vf->list */
2115 } 2119 GList *to_delete = work;
2120 work = work->next;
2121 if (id == VFICON_INFO(vf, prev_selection)) VFICON_INFO(vf, prev_selection) = NULL;
2122 if (id == VFICON_INFO(vf, click_id)) VFICON_INFO(vf, click_id) = NULL;
2123 file_data_unref(fd);
2124 g_free(id);
2125 vf->list = g_list_delete_link(vf->list, to_delete);
2126 }
2127 else
2128 {
2129 /* new file, add to vf->list */
2130 id = g_new0(IconData, 1);
2131
2132 id->selected = SELECTION_NONE;
2133 id->row = -1;
2134 id->fd = file_data_ref(new_fd);
2135 vf->list = g_list_insert_before(vf->list, work, id);
2136 work_fd = work_fd->next;
2137 }
2138
2139 }
2140
2141 filelist_free(new_filelist);
2116 2142
2117 vficon_populate(vf, TRUE, keep_position); 2143 vficon_populate(vf, TRUE, keep_position);
2118 2144
2119 /* attempt to keep focus on same icon when refreshing */ 2145 /* attempt to keep focus on same icon when refreshing */
2120 if (focus_id && g_list_find(vf->list, focus_id)) 2146 if (focus_id && g_list_find(vf->list, focus_id))
2121 { 2147 {
2122 vficon_set_focus(vf, focus_id); 2148 vficon_set_focus(vf, focus_id);
2123 } 2149 }
2124
2125 iconlist_free(old_list);
2126 2150
2127 return ret; 2151 return ret;
2128 } 2152 }
2129 2153
2130 gint vficon_refresh(ViewFile *vf) 2154 gint vficon_refresh(ViewFile *vf)