Mercurial > geeqie.yaz
annotate src/view_dir_list.c @ 793:baade53888be
used new notification in cache_maint
author | nadvornik |
---|---|
date | Fri, 06 Jun 2008 22:34:15 +0000 |
parents | d6a7fb4b8e7c |
children | ee33d2ddb661 |
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; | |
160 | |
161 fd = work->data; | |
162 | |
163 if (access_file(fd->path, R_OK | X_OK) && fd->name) | |
164 { | |
165 if (fd->name[0] == '.' && fd->name[1] == '\0') | |
166 { | |
381 | 167 pixbuf = vd->pf->open; |
9 | 168 } |
169 else if (fd->name[0] == '.' && fd->name[1] == '.' && fd->name[2] == '\0') | |
170 { | |
381 | 171 pixbuf = vd->pf->parent; |
9 | 172 } |
173 else | |
174 { | |
381 | 175 pixbuf = vd->pf->close; |
9 | 176 } |
177 } | |
178 else | |
179 { | |
381 | 180 pixbuf = vd->pf->deny; |
9 | 181 } |
182 | |
183 gtk_list_store_append(store, &iter); | |
184 gtk_list_store_set(store, &iter, | |
185 DIR_COLUMN_POINTER, fd, | |
186 DIR_COLUMN_ICON, pixbuf, | |
187 DIR_COLUMN_NAME, fd->name, -1); | |
188 | |
189 work = work->next; | |
190 } | |
191 | |
381 | 192 vd->click_fd = NULL; |
193 vd->drop_fd = NULL; | |
9 | 194 } |
195 | |
783 | 196 gint vdlist_set_fd(ViewDir *vd, FileData *dir_fd) |
9 | 197 { |
198 gint ret; | |
199 FileData *fd; | |
200 gchar *old_path = NULL; | |
138 | 201 gchar *filepath; |
9 | 202 |
783 | 203 if (!dir_fd) return FALSE; |
204 if (vd->dir_fd == dir_fd) return TRUE; | |
9 | 205 |
783 | 206 if (vd->dir_fd) |
9 | 207 { |
208 gchar *base; | |
209 | |
783 | 210 base = remove_level_from_path(vd->dir_fd->path); |
211 if (strcmp(base, dir_fd->path) == 0) | |
9 | 212 { |
783 | 213 old_path = g_strdup(vd->dir_fd->name); |
9 | 214 } |
215 g_free(base); | |
216 } | |
217 | |
783 | 218 file_data_unref(vd->dir_fd); |
219 vd->dir_fd = file_data_ref(dir_fd); | |
9 | 220 |
381 | 221 filelist_free(VDLIST_INFO(vd, list)); |
9 | 222 |
783 | 223 ret = filelist_read(vd->dir_fd, NULL, &VDLIST_INFO(vd, list)); |
381 | 224 VDLIST_INFO(vd, list) = filelist_sort(VDLIST_INFO(vd, list), SORT_NAME, TRUE); |
9 | 225 |
226 /* add . and .. */ | |
227 | |
783 | 228 if (strcmp(vd->dir_fd->path, G_DIR_SEPARATOR_S) != 0) |
9 | 229 { |
783 | 230 filepath = g_build_filename(vd->dir_fd->path, "..", NULL); |
138 | 231 fd = file_data_new_simple(filepath); |
381 | 232 VDLIST_INFO(vd, list) = g_list_prepend(VDLIST_INFO(vd, list), fd); |
138 | 233 g_free(filepath); |
9 | 234 } |
442 | 235 |
373
61a3c8b05b24
Add a new option in Preferences > Filtering to allow the
zas_
parents:
356
diff
changeset
|
236 if (options->file_filter.show_dot_directory) |
61a3c8b05b24
Add a new option in Preferences > Filtering to allow the
zas_
parents:
356
diff
changeset
|
237 { |
783 | 238 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
|
239 fd = file_data_new_simple(filepath); |
381 | 240 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
|
241 g_free(filepath); |
61a3c8b05b24
Add a new option in Preferences > Filtering to allow the
zas_
parents:
356
diff
changeset
|
242 } |
9 | 243 |
381 | 244 vdlist_populate(vd); |
9 | 245 |
246 if (old_path) | |
247 { | |
248 /* scroll to make last path visible */ | |
249 FileData *found = NULL; | |
250 GList *work; | |
251 | |
381 | 252 work = VDLIST_INFO(vd, list); |
9 | 253 while (work && !found) |
254 { | |
255 FileData *fd = work->data; | |
256 if (strcmp(old_path, fd->name) == 0) found = fd; | |
257 work = work->next; | |
258 } | |
259 | |
381 | 260 if (found) vdlist_scroll_to_row(vd, found, 0.5); |
9 | 261 |
262 g_free(old_path); | |
263 return ret; | |
264 } | |
265 | |
381 | 266 if (GTK_WIDGET_REALIZED(vd->view)) |
9 | 267 { |
381 | 268 gtk_tree_view_scroll_to_point(GTK_TREE_VIEW(vd->view), 0, 0); |
9 | 269 } |
270 | |
271 return ret; | |
272 } | |
273 | |
381 | 274 void vdlist_refresh(ViewDir *vd) |
9 | 275 { |
783 | 276 FileData *dir_fd; |
9 | 277 |
783 | 278 dir_fd = vd->dir_fd; |
279 vd->dir_fd = NULL; | |
280 vdlist_set_fd(vd, dir_fd); | |
281 file_data_unref(dir_fd); | |
9 | 282 } |
283 | |
401
0a2e1b130a25
Add some wrappers in view_dir.c and simplify even more.
zas_
parents:
397
diff
changeset
|
284 gint vdlist_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) |
9 | 285 { |
381 | 286 ViewDir *vd = data; |
9 | 287 GtkTreePath *tpath; |
442 | 288 |
9 | 289 if (event->keyval != GDK_Menu) return FALSE; |
290 | |
381 | 291 gtk_tree_view_get_cursor(GTK_TREE_VIEW(vd->view), &tpath, NULL); |
9 | 292 if (tpath) |
293 { | |
294 GtkTreeModel *store; | |
295 GtkTreeIter iter; | |
296 | |
297 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
298 gtk_tree_model_get_iter(store, &iter, tpath); | |
381 | 299 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &vd->click_fd, -1); |
442 | 300 |
9 | 301 gtk_tree_path_free(tpath); |
302 } | |
303 else | |
304 { | |
381 | 305 vd->click_fd = NULL; |
9 | 306 } |
307 | |
383
499d7ba62261
Move some dnd common code from view_dir_list.c and view_dir_tree.c
zas_
parents:
381
diff
changeset
|
308 vd_color_set(vd, vd->click_fd, TRUE); |
9 | 309 |
388
5186f8e38cb8
Make directory view popup menu common and move it to view_dir.{c,h}.
zas_
parents:
385
diff
changeset
|
310 vd->popup = vd_pop_menu(vd, vd->click_fd); |
9 | 311 |
395 | 312 gtk_menu_popup(GTK_MENU(vd->popup), NULL, NULL, vd_menu_position_cb, vd, 0, GDK_CURRENT_TIME); |
9 | 313 |
314 return TRUE; | |
315 } | |
316 | |
401
0a2e1b130a25
Add some wrappers in view_dir.c and simplify even more.
zas_
parents:
397
diff
changeset
|
317 gint vdlist_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) |
9 | 318 { |
381 | 319 ViewDir *vd = data; |
9 | 320 GtkTreePath *tpath; |
321 GtkTreeIter iter; | |
322 FileData *fd = NULL; | |
323 | |
324 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | |
325 &tpath, NULL, NULL, NULL)) | |
326 { | |
327 GtkTreeModel *store; | |
328 | |
329 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
330 gtk_tree_model_get_iter(store, &iter, tpath); | |
331 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1); | |
332 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE); | |
333 gtk_tree_path_free(tpath); | |
334 } | |
335 | |
381 | 336 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
|
337 vd_color_set(vd, vd->click_fd, TRUE); |
9 | 338 |
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
442
diff
changeset
|
339 if (bevent->button == MOUSE_BUTTON_RIGHT) |
9 | 340 { |
388
5186f8e38cb8
Make directory view popup menu common and move it to view_dir.{c,h}.
zas_
parents:
385
diff
changeset
|
341 vd->popup = vd_pop_menu(vd, vd->click_fd); |
381 | 342 gtk_menu_popup(GTK_MENU(vd->popup), NULL, NULL, NULL, NULL, |
9 | 343 bevent->button, bevent->time); |
344 } | |
345 | |
346 return TRUE; | |
347 } | |
348 | |
401
0a2e1b130a25
Add some wrappers in view_dir.c and simplify even more.
zas_
parents:
397
diff
changeset
|
349 void vdlist_destroy_cb(GtkWidget *widget, gpointer data) |
9 | 350 { |
381 | 351 ViewDir *vd = data; |
9 | 352 |
394 | 353 vd_dnd_drop_scroll_cancel(vd); |
381 | 354 widget_auto_scroll_stop(vd->view); |
9 | 355 |
381 | 356 filelist_free(VDLIST_INFO(vd, list)); |
9 | 357 } |
358 | |
783 | 359 ViewDir *vdlist_new(ViewDir *vd, FileData *dir_fd) |
9 | 360 { |
361 GtkListStore *store; | |
362 GtkTreeSelection *selection; | |
363 GtkTreeViewColumn *column; | |
364 GtkCellRenderer *renderer; | |
365 | |
381 | 366 vd->info = g_new0(ViewDirInfoList, 1); |
367 vd->type = DIRVIEW_LIST; | |
9 | 368 |
384
392dd6541d51
Merge parts of view_dir_list/tree constructors/destructors to
zas_
parents:
383
diff
changeset
|
369 VDLIST_INFO(vd, list) = NULL; |
9 | 370 |
371 store = gtk_list_store_new(4, G_TYPE_POINTER, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_BOOLEAN); | |
381 | 372 vd->view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); |
9 | 373 g_object_unref(store); |
374 | |
381 | 375 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(vd->view), FALSE); |
376 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(vd->view), FALSE); | |
9 | 377 |
381 | 378 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vd->view)); |
9 | 379 gtk_tree_selection_set_mode(selection, GTK_SELECTION_NONE); |
380 | |
381 column = gtk_tree_view_column_new(); | |
382 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); | |
383 | |
384 renderer = gtk_cell_renderer_pixbuf_new(); | |
385 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
386 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", DIR_COLUMN_ICON); | |
396 | 387 gtk_tree_view_column_set_cell_data_func(column, renderer, vd_color_cb, vd, NULL); |
9 | 388 |
389 renderer = gtk_cell_renderer_text_new(); | |
390 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
391 gtk_tree_view_column_add_attribute(column, renderer, "text", DIR_COLUMN_NAME); | |
396 | 392 gtk_tree_view_column_set_cell_data_func(column, renderer, vd_color_cb, vd, NULL); |
9 | 393 |
381 | 394 gtk_tree_view_append_column(GTK_TREE_VIEW(vd->view), column); |
9 | 395 |
381 | 396 return vd; |
9 | 397 } |