Mercurial > geeqie
annotate src/view_dir_list.c @ 1586:249b539cc952
force the metadata dialog if it was triggered by the menu or the button
author | nadvornik |
---|---|
date | Sat, 02 May 2009 11:14:24 +0000 |
parents | 626adbb26387 |
children | 66bf394d162a |
rev | line source |
---|---|
9 | 1 /* |
196 | 2 * Geeqie |
9 | 3 * (C) 2004 John Ellis |
1284 | 4 * Copyright (C) 2008 - 2009 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_fileops.h" | |
24 #include "ui_menu.h" | |
25 #include "ui_tree_edit.h" | |
380
5afe77bb563a
Introduce a new struct ViewDir to handle directory views common
zas_
parents:
373
diff
changeset
|
26 #include "view_dir.h" |
9 | 27 |
28 #include <gdk/gdkkeysyms.h> /* for keyboard values */ | |
29 | |
30 | |
979 | 31 #define VDLIST(_vd_) ((ViewDirInfoList *)(_vd_->info)) |
9 | 32 |
33 | |
34 /* | |
35 *----------------------------------------------------------------------------- | |
36 * misc | |
37 *----------------------------------------------------------------------------- | |
38 */ | |
39 | |
1452 | 40 gboolean vdlist_find_row(ViewDir *vd, FileData *fd, GtkTreeIter *iter) |
9 | 41 { |
42 GtkTreeModel *store; | |
1452 | 43 gboolean valid; |
9 | 44 |
381 | 45 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); |
9 | 46 valid = gtk_tree_model_get_iter_first(store, iter); |
47 while (valid) | |
48 { | |
49 FileData *fd_n; | |
50 gtk_tree_model_get(GTK_TREE_MODEL(store), iter, DIR_COLUMN_POINTER, &fd_n, -1); | |
1501 | 51 if (fd_n == fd) return TRUE; |
9 | 52 |
53 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), iter); | |
54 } | |
55 | |
1501 | 56 return FALSE; |
9 | 57 } |
58 | |
59 | |
388
5186f8e38cb8
Make directory view popup menu common and move it to view_dir.{c,h}.
zas_
parents:
385
diff
changeset
|
60 FileData *vdlist_row_by_path(ViewDir *vd, const gchar *path, gint *row) |
9 | 61 { |
62 GList *work; | |
63 gint n; | |
64 | |
65 if (!path) | |
66 { | |
67 if (row) *row = -1; | |
68 return NULL; | |
69 } | |
70 | |
71 n = 0; | |
978
9ff64efe11eb
Replace macros VDLIST_INFO() and VDTREE_INFO() by shorter VDLIST() and VDTREE(). VDLIST_INFO(vd, part) becomes VDLIST(vd)->part.
zas_
parents:
973
diff
changeset
|
72 work = VDLIST(vd)->list; |
9 | 73 while (work) |
74 { | |
75 FileData *fd = work->data; | |
76 if (strcmp(fd->path, path) == 0) | |
77 { | |
78 if (row) *row = n; | |
79 return fd; | |
80 } | |
81 work = work->next; | |
82 n++; | |
83 } | |
84 | |
85 if (row) *row = -1; | |
86 return NULL; | |
87 } | |
88 | |
89 /* | |
90 *----------------------------------------------------------------------------- | |
91 * dnd | |
92 *----------------------------------------------------------------------------- | |
93 */ | |
94 | |
381 | 95 static void vdlist_scroll_to_row(ViewDir *vd, FileData *fd, gfloat y_align) |
9 | 96 { |
97 GtkTreeIter iter; | |
98 | |
1553 | 99 if (GTK_WIDGET_REALIZED(vd->view) && vd_find_row(vd, fd, &iter)) |
9 | 100 { |
101 GtkTreeModel *store; | |
102 GtkTreePath *tpath; | |
103 | |
381 | 104 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); |
9 | 105 tpath = gtk_tree_model_get_path(store, &iter); |
381 | 106 gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(vd->view), tpath, NULL, TRUE, y_align, 0.0); |
107 gtk_tree_view_set_cursor(GTK_TREE_VIEW(vd->view), tpath, NULL, FALSE); | |
9 | 108 gtk_tree_path_free(tpath); |
109 | |
381 | 110 if (!GTK_WIDGET_HAS_FOCUS(vd->view)) gtk_widget_grab_focus(vd->view); |
9 | 111 } |
112 } | |
113 | |
114 /* | |
115 *----------------------------------------------------------------------------- | |
116 * main | |
117 *----------------------------------------------------------------------------- | |
442 | 118 */ |
9 | 119 |
396 | 120 void vdlist_select_row(ViewDir *vd, FileData *fd) |
9 | 121 { |
381 | 122 if (fd && vd->select_func) |
9 | 123 { |
124 gchar *path; | |
125 | |
126 path = g_strdup(fd->path); | |
381 | 127 vd->select_func(vd, path, vd->select_data); |
9 | 128 g_free(path); |
129 } | |
130 } | |
131 | |
381 | 132 const gchar *vdlist_row_get_path(ViewDir *vd, gint row) |
9 | 133 { |
134 FileData *fd; | |
135 | |
978
9ff64efe11eb
Replace macros VDLIST_INFO() and VDTREE_INFO() by shorter VDLIST() and VDTREE(). VDLIST_INFO(vd, part) becomes VDLIST(vd)->part.
zas_
parents:
973
diff
changeset
|
136 fd = g_list_nth_data(VDLIST(vd)->list, row); |
9 | 137 |
138 if (fd) return fd->path; | |
139 | |
140 return NULL; | |
141 } | |
142 | |
1452 | 143 static gboolean vdlist_populate(ViewDir *vd, gboolean clear) |
9 | 144 { |
145 GtkListStore *store; | |
146 GList *work; | |
973 | 147 GtkTreeIter iter; |
1452 | 148 gboolean valid; |
973 | 149 gchar *filepath; |
150 GList *old_list; | |
1452 | 151 gboolean ret; |
973 | 152 FileData *fd; |
153 | |
978
9ff64efe11eb
Replace macros VDLIST_INFO() and VDTREE_INFO() by shorter VDLIST() and VDTREE(). VDLIST_INFO(vd, part) becomes VDLIST(vd)->part.
zas_
parents:
973
diff
changeset
|
154 old_list = VDLIST(vd)->list; |
973 | 155 |
978
9ff64efe11eb
Replace macros VDLIST_INFO() and VDTREE_INFO() by shorter VDLIST() and VDTREE(). VDLIST_INFO(vd, part) becomes VDLIST(vd)->part.
zas_
parents:
973
diff
changeset
|
156 ret = filelist_read(vd->dir_fd, NULL, &VDLIST(vd)->list); |
9ff64efe11eb
Replace macros VDLIST_INFO() and VDTREE_INFO() by shorter VDLIST() and VDTREE(). VDLIST_INFO(vd, part) becomes VDLIST(vd)->part.
zas_
parents:
973
diff
changeset
|
157 VDLIST(vd)->list = filelist_sort(VDLIST(vd)->list, SORT_NAME, TRUE); |
973 | 158 |
159 /* add . and .. */ | |
160 | |
161 if (strcmp(vd->dir_fd->path, G_DIR_SEPARATOR_S) != 0) | |
162 { | |
163 filepath = g_build_filename(vd->dir_fd->path, "..", NULL); | |
164 fd = file_data_new_simple(filepath); | |
978
9ff64efe11eb
Replace macros VDLIST_INFO() and VDTREE_INFO() by shorter VDLIST() and VDTREE(). VDLIST_INFO(vd, part) becomes VDLIST(vd)->part.
zas_
parents:
973
diff
changeset
|
165 VDLIST(vd)->list = g_list_prepend(VDLIST(vd)->list, fd); |
973 | 166 g_free(filepath); |
167 } | |
168 | |
169 if (options->file_filter.show_dot_directory) | |
170 { | |
171 filepath = g_build_filename(vd->dir_fd->path, ".", NULL); | |
172 fd = file_data_new_simple(filepath); | |
978
9ff64efe11eb
Replace macros VDLIST_INFO() and VDTREE_INFO() by shorter VDLIST() and VDTREE(). VDLIST_INFO(vd, part) becomes VDLIST(vd)->part.
zas_
parents:
973
diff
changeset
|
173 VDLIST(vd)->list = g_list_prepend(VDLIST(vd)->list, fd); |
973 | 174 g_free(filepath); |
175 } | |
9 | 176 |
381 | 177 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view))); |
973 | 178 if (clear) gtk_list_store_clear(store); |
179 | |
180 valid = gtk_tree_model_iter_children(GTK_TREE_MODEL(store), &iter, NULL); | |
9 | 181 |
978
9ff64efe11eb
Replace macros VDLIST_INFO() and VDTREE_INFO() by shorter VDLIST() and VDTREE(). VDLIST_INFO(vd, part) becomes VDLIST(vd)->part.
zas_
parents:
973
diff
changeset
|
182 work = VDLIST(vd)->list; |
9 | 183 while (work) |
184 { | |
973 | 185 gint match; |
9 | 186 GdkPixbuf *pixbuf; |
825 | 187 const gchar *date = ""; |
1452 | 188 gboolean done = FALSE; |
189 | |
9 | 190 fd = work->data; |
191 | |
192 if (access_file(fd->path, R_OK | X_OK) && fd->name) | |
193 { | |
194 if (fd->name[0] == '.' && fd->name[1] == '\0') | |
195 { | |
381 | 196 pixbuf = vd->pf->open; |
9 | 197 } |
198 else if (fd->name[0] == '.' && fd->name[1] == '.' && fd->name[2] == '\0') | |
199 { | |
381 | 200 pixbuf = vd->pf->parent; |
9 | 201 } |
202 else | |
203 { | |
381 | 204 pixbuf = vd->pf->close; |
1436
d7a6fb7a90dd
completely separated global and layout window options
nadvornik
parents:
1365
diff
changeset
|
205 if (vd->layout && vd->layout->options.show_directory_date) |
825 | 206 date = text_from_time(fd->date); |
9 | 207 } |
208 } | |
209 else | |
210 { | |
381 | 211 pixbuf = vd->pf->deny; |
9 | 212 } |
213 | |
973 | 214 while (!done) |
215 { | |
216 FileData *old_fd = NULL; | |
217 | |
218 if (valid) | |
219 { | |
220 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, | |
221 DIR_COLUMN_POINTER, &old_fd, | |
222 -1); | |
223 | |
224 if (fd == old_fd) | |
225 { | |
226 match = 0; | |
227 } | |
228 else | |
229 { | |
995 | 230 match = filelist_sort_compare_filedata_full(fd, old_fd, SORT_NAME, TRUE); |
973 | 231 |
232 if (match == 0) g_warning("multiple fd for the same path"); | |
233 } | |
234 | |
235 } | |
236 else | |
237 { | |
238 match = -1; | |
239 } | |
240 | |
241 if (match < 0) | |
242 { | |
243 GtkTreeIter new; | |
9 | 244 |
973 | 245 if (valid) |
246 { | |
247 gtk_list_store_insert_before(store, &new, &iter); | |
248 } | |
249 else | |
250 { | |
251 gtk_list_store_append(store, &new); | |
252 } | |
253 | |
254 gtk_list_store_set(store, &new, | |
255 DIR_COLUMN_POINTER, fd, | |
256 DIR_COLUMN_ICON, pixbuf, | |
257 DIR_COLUMN_NAME, fd->name, | |
258 DIR_COLUMN_DATE, date, | |
259 -1); | |
260 | |
261 done = TRUE; | |
262 } | |
263 else if (match > 0) | |
264 { | |
265 valid = gtk_list_store_remove(store, &iter); | |
266 } | |
267 else | |
268 { | |
269 gtk_list_store_set(store, &iter, | |
270 DIR_COLUMN_ICON, pixbuf, | |
271 DIR_COLUMN_NAME, fd->name, | |
272 DIR_COLUMN_DATE, date, | |
273 -1); | |
274 | |
275 if (valid) valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), &iter); | |
276 | |
277 done = TRUE; | |
278 } | |
279 } | |
9 | 280 work = work->next; |
281 } | |
282 | |
973 | 283 while (valid) |
284 { | |
285 FileData *old_fd; | |
286 gtk_tree_model_get(GTK_TREE_MODEL(store), &iter, DIR_COLUMN_POINTER, &old_fd, -1); | |
287 | |
288 valid = gtk_list_store_remove(store, &iter); | |
289 } | |
290 | |
291 | |
381 | 292 vd->click_fd = NULL; |
293 vd->drop_fd = NULL; | |
973 | 294 |
295 filelist_free(old_list); | |
296 return ret; | |
9 | 297 } |
298 | |
1452 | 299 gboolean vdlist_set_fd(ViewDir *vd, FileData *dir_fd) |
9 | 300 { |
1452 | 301 gboolean ret; |
9 | 302 gchar *old_path = NULL; |
303 | |
783 | 304 if (!dir_fd) return FALSE; |
305 if (vd->dir_fd == dir_fd) return TRUE; | |
9 | 306 |
783 | 307 if (vd->dir_fd) |
9 | 308 { |
309 gchar *base; | |
310 | |
783 | 311 base = remove_level_from_path(vd->dir_fd->path); |
312 if (strcmp(base, dir_fd->path) == 0) | |
9 | 313 { |
783 | 314 old_path = g_strdup(vd->dir_fd->name); |
9 | 315 } |
316 g_free(base); | |
317 } | |
318 | |
783 | 319 file_data_unref(vd->dir_fd); |
320 vd->dir_fd = file_data_ref(dir_fd); | |
9 | 321 |
973 | 322 ret = vdlist_populate(vd, TRUE); |
9 | 323 |
324 if (old_path) | |
325 { | |
326 /* scroll to make last path visible */ | |
327 FileData *found = NULL; | |
328 GList *work; | |
329 | |
978
9ff64efe11eb
Replace macros VDLIST_INFO() and VDTREE_INFO() by shorter VDLIST() and VDTREE(). VDLIST_INFO(vd, part) becomes VDLIST(vd)->part.
zas_
parents:
973
diff
changeset
|
330 work = VDLIST(vd)->list; |
9 | 331 while (work && !found) |
332 { | |
333 FileData *fd = work->data; | |
334 if (strcmp(old_path, fd->name) == 0) found = fd; | |
335 work = work->next; | |
336 } | |
337 | |
381 | 338 if (found) vdlist_scroll_to_row(vd, found, 0.5); |
9 | 339 |
340 g_free(old_path); | |
341 return ret; | |
342 } | |
343 | |
381 | 344 if (GTK_WIDGET_REALIZED(vd->view)) |
9 | 345 { |
381 | 346 gtk_tree_view_scroll_to_point(GTK_TREE_VIEW(vd->view), 0, 0); |
9 | 347 } |
348 | |
349 return ret; | |
350 } | |
351 | |
381 | 352 void vdlist_refresh(ViewDir *vd) |
9 | 353 { |
973 | 354 vdlist_populate(vd, FALSE); |
9 | 355 } |
356 | |
1452 | 357 gboolean vdlist_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) |
9 | 358 { |
381 | 359 ViewDir *vd = data; |
9 | 360 GtkTreePath *tpath; |
442 | 361 |
9 | 362 if (event->keyval != GDK_Menu) return FALSE; |
363 | |
381 | 364 gtk_tree_view_get_cursor(GTK_TREE_VIEW(vd->view), &tpath, NULL); |
9 | 365 if (tpath) |
366 { | |
367 GtkTreeModel *store; | |
368 GtkTreeIter iter; | |
369 | |
370 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
371 gtk_tree_model_get_iter(store, &iter, tpath); | |
381 | 372 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &vd->click_fd, -1); |
442 | 373 |
9 | 374 gtk_tree_path_free(tpath); |
375 } | |
376 else | |
377 { | |
381 | 378 vd->click_fd = NULL; |
9 | 379 } |
380 | |
383
499d7ba62261
Move some dnd common code from view_dir_list.c and view_dir_tree.c
zas_
parents:
381
diff
changeset
|
381 vd_color_set(vd, vd->click_fd, TRUE); |
9 | 382 |
388
5186f8e38cb8
Make directory view popup menu common and move it to view_dir.{c,h}.
zas_
parents:
385
diff
changeset
|
383 vd->popup = vd_pop_menu(vd, vd->click_fd); |
9 | 384 |
395 | 385 gtk_menu_popup(GTK_MENU(vd->popup), NULL, NULL, vd_menu_position_cb, vd, 0, GDK_CURRENT_TIME); |
9 | 386 |
387 return TRUE; | |
388 } | |
389 | |
1452 | 390 gboolean vdlist_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) |
9 | 391 { |
381 | 392 ViewDir *vd = data; |
9 | 393 GtkTreePath *tpath; |
394 GtkTreeIter iter; | |
395 FileData *fd = NULL; | |
396 | |
397 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | |
398 &tpath, NULL, NULL, NULL)) | |
399 { | |
400 GtkTreeModel *store; | |
401 | |
402 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
403 gtk_tree_model_get_iter(store, &iter, tpath); | |
404 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1); | |
405 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE); | |
406 gtk_tree_path_free(tpath); | |
407 } | |
408 | |
381 | 409 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
|
410 vd_color_set(vd, vd->click_fd, TRUE); |
9 | 411 |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
442
diff
changeset
|
412 if (bevent->button == MOUSE_BUTTON_RIGHT) |
9 | 413 { |
388
5186f8e38cb8
Make directory view popup menu common and move it to view_dir.{c,h}.
zas_
parents:
385
diff
changeset
|
414 vd->popup = vd_pop_menu(vd, vd->click_fd); |
381 | 415 gtk_menu_popup(GTK_MENU(vd->popup), NULL, NULL, NULL, NULL, |
9 | 416 bevent->button, bevent->time); |
417 } | |
418 | |
419 return TRUE; | |
420 } | |
421 | |
401
0a2e1b130a25
Add some wrappers in view_dir.c and simplify even more.
zas_
parents:
397
diff
changeset
|
422 void vdlist_destroy_cb(GtkWidget *widget, gpointer data) |
9 | 423 { |
381 | 424 ViewDir *vd = data; |
9 | 425 |
394 | 426 vd_dnd_drop_scroll_cancel(vd); |
381 | 427 widget_auto_scroll_stop(vd->view); |
9 | 428 |
978
9ff64efe11eb
Replace macros VDLIST_INFO() and VDTREE_INFO() by shorter VDLIST() and VDTREE(). VDLIST_INFO(vd, part) becomes VDLIST(vd)->part.
zas_
parents:
973
diff
changeset
|
429 filelist_free(VDLIST(vd)->list); |
9 | 430 } |
431 | |
783 | 432 ViewDir *vdlist_new(ViewDir *vd, FileData *dir_fd) |
9 | 433 { |
434 GtkListStore *store; | |
435 GtkTreeSelection *selection; | |
436 GtkTreeViewColumn *column; | |
437 GtkCellRenderer *renderer; | |
438 | |
381 | 439 vd->info = g_new0(ViewDirInfoList, 1); |
1365
249bf204004a
When g_new0() is used, drop redundant initializations to NULL, FALSE or 0.
zas_
parents:
1284
diff
changeset
|
440 |
381 | 441 vd->type = DIRVIEW_LIST; |
9 | 442 |
825 | 443 store = gtk_list_store_new(5, G_TYPE_POINTER, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_BOOLEAN, G_TYPE_STRING); |
381 | 444 vd->view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); |
9 | 445 g_object_unref(store); |
446 | |
381 | 447 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(vd->view), FALSE); |
448 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(vd->view), FALSE); | |
9 | 449 |
381 | 450 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vd->view)); |
9 | 451 gtk_tree_selection_set_mode(selection, GTK_SELECTION_NONE); |
452 | |
453 column = gtk_tree_view_column_new(); | |
454 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); | |
455 | |
456 renderer = gtk_cell_renderer_pixbuf_new(); | |
457 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
458 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", DIR_COLUMN_ICON); | |
396 | 459 gtk_tree_view_column_set_cell_data_func(column, renderer, vd_color_cb, vd, NULL); |
9 | 460 |
461 renderer = gtk_cell_renderer_text_new(); | |
462 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
463 gtk_tree_view_column_add_attribute(column, renderer, "text", DIR_COLUMN_NAME); | |
396 | 464 gtk_tree_view_column_set_cell_data_func(column, renderer, vd_color_cb, vd, NULL); |
9 | 465 |
825 | 466 renderer = gtk_cell_renderer_text_new(); |
467 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
468 gtk_tree_view_column_add_attribute(column, renderer, "text", DIR_COLUMN_DATE); | |
469 gtk_tree_view_column_set_cell_data_func(column, renderer, vd_color_cb, vd, NULL); | |
470 | |
381 | 471 gtk_tree_view_append_column(GTK_TREE_VIEW(vd->view), column); |
9 | 472 |
381 | 473 return vd; |
9 | 474 } |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
995
diff
changeset
|
475 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |