Mercurial > geeqie.yaz
annotate src/view_dir_list.c @ 853:b54e3fc9cafb
optimized marks drawing
author | nadvornik |
---|---|
date | Sun, 22 Jun 2008 20:07:32 +0000 |
parents | ee33d2ddb661 |
children | c414002a1f27 |
rev | line source |
---|---|
9 | 1 /* |
196 | 2 * Geeqie |
9 | 3 * (C) 2004 John Ellis |
475 | 4 * Copyright (C) 2008 The Geeqie Team |
9 | 5 * |
6 * Author: John Ellis | |
7 * | |
8 * This software is released under the GNU General Public License (GNU GPL). | |
9 * Please read the included file COPYING for more information. | |
10 * This software comes with no warranty of any kind, use at your own risk! | |
11 */ | |
12 | |
281 | 13 #include "main.h" |
9 | 14 #include "view_dir_list.h" |
15 | |
16 #include "dnd.h" | |
17 #include "dupe.h" | |
586 | 18 #include "filedata.h" |
9 | 19 #include "layout.h" |
20 #include "layout_image.h" | |
21 #include "layout_util.h" | |
22 #include "utilops.h" | |
23 #include "ui_bookmark.h" | |
24 #include "ui_fileops.h" | |
25 #include "ui_menu.h" | |
26 #include "ui_tree_edit.h" | |
380
5afe77bb563a
Introduce a new struct ViewDir to handle directory views common
zas_
parents:
373
diff
changeset
|
27 #include "view_dir.h" |
9 | 28 |
29 #include <gdk/gdkkeysyms.h> /* for keyboard values */ | |
30 | |
31 | |
380
5afe77bb563a
Introduce a new struct ViewDir to handle directory views common
zas_
parents:
373
diff
changeset
|
32 #define VDLIST_INFO(_vd_, _part_) (((ViewDirInfoList *)(_vd_->info))->_part_) |
9 | 33 |
34 | |
35 /* | |
36 *----------------------------------------------------------------------------- | |
37 * misc | |
38 *----------------------------------------------------------------------------- | |
39 */ | |
40 | |
383
499d7ba62261
Move some dnd common code from view_dir_list.c and view_dir_tree.c
zas_
parents:
381
diff
changeset
|
41 gint vdlist_find_row(ViewDir *vd, FileData *fd, GtkTreeIter *iter) |
9 | 42 { |
43 GtkTreeModel *store; | |
44 gint valid; | |
45 gint row = 0; | |
46 | |
381 | 47 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); |
9 | 48 valid = gtk_tree_model_get_iter_first(store, iter); |
49 while (valid) | |
50 { | |
51 FileData *fd_n; | |
52 gtk_tree_model_get(GTK_TREE_MODEL(store), iter, DIR_COLUMN_POINTER, &fd_n, -1); | |
53 if (fd_n == fd) return row; | |
54 | |
55 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), iter); | |
56 row++; | |
57 } | |
58 | |
59 return -1; | |
60 } | |
61 | |
62 | |
388
5186f8e38cb8
Make directory view popup menu common and move it to view_dir.{c,h}.
zas_
parents:
385
diff
changeset
|
63 FileData *vdlist_row_by_path(ViewDir *vd, const gchar *path, gint *row) |
9 | 64 { |
65 GList *work; | |
66 gint n; | |
67 | |
68 if (!path) | |
69 { | |
70 if (row) *row = -1; | |
71 return NULL; | |
72 } | |
73 | |
74 n = 0; | |
381 | 75 work = VDLIST_INFO(vd, list); |
9 | 76 while (work) |
77 { | |
78 FileData *fd = work->data; | |
79 if (strcmp(fd->path, path) == 0) | |
80 { | |
81 if (row) *row = n; | |
82 return fd; | |
83 } | |
84 work = work->next; | |
85 n++; | |
86 } | |
87 | |
88 if (row) *row = -1; | |
89 return NULL; | |
90 } | |
91 | |
92 /* | |
93 *----------------------------------------------------------------------------- | |
94 * dnd | |
95 *----------------------------------------------------------------------------- | |
96 */ | |
97 | |
381 | 98 static void vdlist_scroll_to_row(ViewDir *vd, FileData *fd, gfloat y_align) |
9 | 99 { |
100 GtkTreeIter iter; | |
101 | |
394 | 102 if (GTK_WIDGET_REALIZED(vd->view) && vd_find_row(vd, fd, &iter) >= 0) |
9 | 103 { |
104 GtkTreeModel *store; | |
105 GtkTreePath *tpath; | |
106 | |
381 | 107 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); |
9 | 108 tpath = gtk_tree_model_get_path(store, &iter); |
381 | 109 gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(vd->view), tpath, NULL, TRUE, y_align, 0.0); |
110 gtk_tree_view_set_cursor(GTK_TREE_VIEW(vd->view), tpath, NULL, FALSE); | |
9 | 111 gtk_tree_path_free(tpath); |
112 | |
381 | 113 if (!GTK_WIDGET_HAS_FOCUS(vd->view)) gtk_widget_grab_focus(vd->view); |
9 | 114 } |
115 } | |
116 | |
117 /* | |
118 *----------------------------------------------------------------------------- | |
119 * main | |
120 *----------------------------------------------------------------------------- | |
442 | 121 */ |
9 | 122 |
396 | 123 void vdlist_select_row(ViewDir *vd, FileData *fd) |
9 | 124 { |
381 | 125 if (fd && vd->select_func) |
9 | 126 { |
127 gchar *path; | |
128 | |
129 path = g_strdup(fd->path); | |
381 | 130 vd->select_func(vd, path, vd->select_data); |
9 | 131 g_free(path); |
132 } | |
133 } | |
134 | |
381 | 135 const gchar *vdlist_row_get_path(ViewDir *vd, gint row) |
9 | 136 { |
137 FileData *fd; | |
138 | |
381 | 139 fd = g_list_nth_data(VDLIST_INFO(vd, list), row); |
9 | 140 |
141 if (fd) return fd->path; | |
142 | |
143 return NULL; | |
144 } | |
145 | |
381 | 146 static void vdlist_populate(ViewDir *vd) |
9 | 147 { |
148 GtkListStore *store; | |
149 GList *work; | |
150 | |
381 | 151 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view))); |
9 | 152 gtk_list_store_clear(store); |
153 | |
381 | 154 work = VDLIST_INFO(vd, list); |
9 | 155 while (work) |
156 { | |
157 FileData *fd; | |
158 GtkTreeIter iter; | |
159 GdkPixbuf *pixbuf; | |
825 | 160 const gchar *date = ""; |
9 | 161 |
162 fd = work->data; | |
163 | |
164 if (access_file(fd->path, R_OK | X_OK) && fd->name) | |
165 { | |
166 if (fd->name[0] == '.' && fd->name[1] == '\0') | |
167 { | |
381 | 168 pixbuf = vd->pf->open; |
9 | 169 } |
170 else if (fd->name[0] == '.' && fd->name[1] == '.' && fd->name[2] == '\0') | |
171 { | |
381 | 172 pixbuf = vd->pf->parent; |
9 | 173 } |
174 else | |
175 { | |
381 | 176 pixbuf = vd->pf->close; |
825 | 177 if (options->layout.show_directory_date) |
178 date = text_from_time(fd->date); | |
9 | 179 } |
180 } | |
181 else | |
182 { | |
381 | 183 pixbuf = vd->pf->deny; |
9 | 184 } |
185 | |
186 gtk_list_store_append(store, &iter); | |
187 gtk_list_store_set(store, &iter, | |
188 DIR_COLUMN_POINTER, fd, | |
189 DIR_COLUMN_ICON, pixbuf, | |
825 | 190 DIR_COLUMN_NAME, fd->name, |
191 DIR_COLUMN_DATE, date, | |
192 -1); | |
9 | 193 |
194 work = work->next; | |
195 } | |
196 | |
381 | 197 vd->click_fd = NULL; |
198 vd->drop_fd = NULL; | |
9 | 199 } |
200 | |
783 | 201 gint vdlist_set_fd(ViewDir *vd, FileData *dir_fd) |
9 | 202 { |
203 gint ret; | |
204 FileData *fd; | |
205 gchar *old_path = NULL; | |
138 | 206 gchar *filepath; |
9 | 207 |
783 | 208 if (!dir_fd) return FALSE; |
209 if (vd->dir_fd == dir_fd) return TRUE; | |
9 | 210 |
783 | 211 if (vd->dir_fd) |
9 | 212 { |
213 gchar *base; | |
214 | |
783 | 215 base = remove_level_from_path(vd->dir_fd->path); |
216 if (strcmp(base, dir_fd->path) == 0) | |
9 | 217 { |
783 | 218 old_path = g_strdup(vd->dir_fd->name); |
9 | 219 } |
220 g_free(base); | |
221 } | |
222 | |
783 | 223 file_data_unref(vd->dir_fd); |
224 vd->dir_fd = file_data_ref(dir_fd); | |
9 | 225 |
381 | 226 filelist_free(VDLIST_INFO(vd, list)); |
9 | 227 |
783 | 228 ret = filelist_read(vd->dir_fd, NULL, &VDLIST_INFO(vd, list)); |
381 | 229 VDLIST_INFO(vd, list) = filelist_sort(VDLIST_INFO(vd, list), SORT_NAME, TRUE); |
9 | 230 |
231 /* add . and .. */ | |
232 | |
783 | 233 if (strcmp(vd->dir_fd->path, G_DIR_SEPARATOR_S) != 0) |
9 | 234 { |
783 | 235 filepath = g_build_filename(vd->dir_fd->path, "..", NULL); |
138 | 236 fd = file_data_new_simple(filepath); |
381 | 237 VDLIST_INFO(vd, list) = g_list_prepend(VDLIST_INFO(vd, list), fd); |
138 | 238 g_free(filepath); |
9 | 239 } |
442 | 240 |
373
61a3c8b05b24
Add a new option in Preferences > Filtering to allow the
zas_
parents:
356
diff
changeset
|
241 if (options->file_filter.show_dot_directory) |
61a3c8b05b24
Add a new option in Preferences > Filtering to allow the
zas_
parents:
356
diff
changeset
|
242 { |
783 | 243 filepath = g_build_filename(vd->dir_fd->path, ".", NULL); |
373
61a3c8b05b24
Add a new option in Preferences > Filtering to allow the
zas_
parents:
356
diff
changeset
|
244 fd = file_data_new_simple(filepath); |
381 | 245 VDLIST_INFO(vd, list) = g_list_prepend(VDLIST_INFO(vd, list), fd); |
373
61a3c8b05b24
Add a new option in Preferences > Filtering to allow the
zas_
parents:
356
diff
changeset
|
246 g_free(filepath); |
61a3c8b05b24
Add a new option in Preferences > Filtering to allow the
zas_
parents:
356
diff
changeset
|
247 } |
9 | 248 |
381 | 249 vdlist_populate(vd); |
9 | 250 |
251 if (old_path) | |
252 { | |
253 /* scroll to make last path visible */ | |
254 FileData *found = NULL; | |
255 GList *work; | |
256 | |
381 | 257 work = VDLIST_INFO(vd, list); |
9 | 258 while (work && !found) |
259 { | |
260 FileData *fd = work->data; | |
261 if (strcmp(old_path, fd->name) == 0) found = fd; | |
262 work = work->next; | |
263 } | |
264 | |
381 | 265 if (found) vdlist_scroll_to_row(vd, found, 0.5); |
9 | 266 |
267 g_free(old_path); | |
268 return ret; | |
269 } | |
270 | |
381 | 271 if (GTK_WIDGET_REALIZED(vd->view)) |
9 | 272 { |
381 | 273 gtk_tree_view_scroll_to_point(GTK_TREE_VIEW(vd->view), 0, 0); |
9 | 274 } |
275 | |
276 return ret; | |
277 } | |
278 | |
381 | 279 void vdlist_refresh(ViewDir *vd) |
9 | 280 { |
783 | 281 FileData *dir_fd; |
9 | 282 |
783 | 283 dir_fd = vd->dir_fd; |
284 vd->dir_fd = NULL; | |
285 vdlist_set_fd(vd, dir_fd); | |
286 file_data_unref(dir_fd); | |
9 | 287 } |
288 | |
401
0a2e1b130a25
Add some wrappers in view_dir.c and simplify even more.
zas_
parents:
397
diff
changeset
|
289 gint vdlist_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) |
9 | 290 { |
381 | 291 ViewDir *vd = data; |
9 | 292 GtkTreePath *tpath; |
442 | 293 |
9 | 294 if (event->keyval != GDK_Menu) return FALSE; |
295 | |
381 | 296 gtk_tree_view_get_cursor(GTK_TREE_VIEW(vd->view), &tpath, NULL); |
9 | 297 if (tpath) |
298 { | |
299 GtkTreeModel *store; | |
300 GtkTreeIter iter; | |
301 | |
302 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
303 gtk_tree_model_get_iter(store, &iter, tpath); | |
381 | 304 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &vd->click_fd, -1); |
442 | 305 |
9 | 306 gtk_tree_path_free(tpath); |
307 } | |
308 else | |
309 { | |
381 | 310 vd->click_fd = NULL; |
9 | 311 } |
312 | |
383
499d7ba62261
Move some dnd common code from view_dir_list.c and view_dir_tree.c
zas_
parents:
381
diff
changeset
|
313 vd_color_set(vd, vd->click_fd, TRUE); |
9 | 314 |
388
5186f8e38cb8
Make directory view popup menu common and move it to view_dir.{c,h}.
zas_
parents:
385
diff
changeset
|
315 vd->popup = vd_pop_menu(vd, vd->click_fd); |
9 | 316 |
395 | 317 gtk_menu_popup(GTK_MENU(vd->popup), NULL, NULL, vd_menu_position_cb, vd, 0, GDK_CURRENT_TIME); |
9 | 318 |
319 return TRUE; | |
320 } | |
321 | |
401
0a2e1b130a25
Add some wrappers in view_dir.c and simplify even more.
zas_
parents:
397
diff
changeset
|
322 gint vdlist_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) |
9 | 323 { |
381 | 324 ViewDir *vd = data; |
9 | 325 GtkTreePath *tpath; |
326 GtkTreeIter iter; | |
327 FileData *fd = NULL; | |
328 | |
329 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | |
330 &tpath, NULL, NULL, NULL)) | |
331 { | |
332 GtkTreeModel *store; | |
333 | |
334 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
335 gtk_tree_model_get_iter(store, &iter, tpath); | |
336 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1); | |
337 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE); | |
338 gtk_tree_path_free(tpath); | |
339 } | |
340 | |
381 | 341 vd->click_fd = fd; |
383
499d7ba62261
Move some dnd common code from view_dir_list.c and view_dir_tree.c
zas_
parents:
381
diff
changeset
|
342 vd_color_set(vd, vd->click_fd, TRUE); |
9 | 343 |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
442
diff
changeset
|
344 if (bevent->button == MOUSE_BUTTON_RIGHT) |
9 | 345 { |
388
5186f8e38cb8
Make directory view popup menu common and move it to view_dir.{c,h}.
zas_
parents:
385
diff
changeset
|
346 vd->popup = vd_pop_menu(vd, vd->click_fd); |
381 | 347 gtk_menu_popup(GTK_MENU(vd->popup), NULL, NULL, NULL, NULL, |
9 | 348 bevent->button, bevent->time); |
349 } | |
350 | |
351 return TRUE; | |
352 } | |
353 | |
401
0a2e1b130a25
Add some wrappers in view_dir.c and simplify even more.
zas_
parents:
397
diff
changeset
|
354 void vdlist_destroy_cb(GtkWidget *widget, gpointer data) |
9 | 355 { |
381 | 356 ViewDir *vd = data; |
9 | 357 |
394 | 358 vd_dnd_drop_scroll_cancel(vd); |
381 | 359 widget_auto_scroll_stop(vd->view); |
9 | 360 |
381 | 361 filelist_free(VDLIST_INFO(vd, list)); |
9 | 362 } |
363 | |
783 | 364 ViewDir *vdlist_new(ViewDir *vd, FileData *dir_fd) |
9 | 365 { |
366 GtkListStore *store; | |
367 GtkTreeSelection *selection; | |
368 GtkTreeViewColumn *column; | |
369 GtkCellRenderer *renderer; | |
370 | |
381 | 371 vd->info = g_new0(ViewDirInfoList, 1); |
372 vd->type = DIRVIEW_LIST; | |
9 | 373 |
384
392dd6541d51
Merge parts of view_dir_list/tree constructors/destructors to
zas_
parents:
383
diff
changeset
|
374 VDLIST_INFO(vd, list) = NULL; |
9 | 375 |
825 | 376 store = gtk_list_store_new(5, G_TYPE_POINTER, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING); |
381 | 377 vd->view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); |
9 | 378 g_object_unref(store); |
379 | |
381 | 380 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(vd->view), FALSE); |
381 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(vd->view), FALSE); | |
9 | 382 |
381 | 383 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vd->view)); |
9 | 384 gtk_tree_selection_set_mode(selection, GTK_SELECTION_NONE); |
385 | |
386 column = gtk_tree_view_column_new(); | |
387 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); | |
388 | |
389 renderer = gtk_cell_renderer_pixbuf_new(); | |
390 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
391 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", DIR_COLUMN_ICON); | |
396 | 392 gtk_tree_view_column_set_cell_data_func(column, renderer, vd_color_cb, vd, NULL); |
9 | 393 |
394 renderer = gtk_cell_renderer_text_new(); | |
395 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
396 gtk_tree_view_column_add_attribute(column, renderer, "text", DIR_COLUMN_NAME); | |
396 | 397 gtk_tree_view_column_set_cell_data_func(column, renderer, vd_color_cb, vd, NULL); |
9 | 398 |
825 | 399 renderer = gtk_cell_renderer_text_new(); |
400 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
401 gtk_tree_view_column_add_attribute(column, renderer, "text", DIR_COLUMN_DATE); | |
402 gtk_tree_view_column_set_cell_data_func(column, renderer, vd_color_cb, vd, NULL); | |
403 | |
381 | 404 gtk_tree_view_append_column(GTK_TREE_VIEW(vd->view), column); |
9 | 405 |
381 | 406 return vd; |
9 | 407 } |