Mercurial > geeqie
annotate src/view_dir_list.c @ 392:5a73f2e1bf79
Fix new folder feature in dirlist mode, it was broken by revision 481.
author | zas_ |
---|---|
date | Wed, 16 Apr 2008 22:31:52 +0000 |
parents | b78077f65eff |
children | 4a5e1377f3d7 |
rev | line source |
---|---|
9 | 1 /* |
196 | 2 * Geeqie |
9 | 3 * (C) 2004 John Ellis |
4 * | |
5 * Author: John Ellis | |
6 * | |
7 * This software is released under the GNU General Public License (GNU GPL). | |
8 * Please read the included file COPYING for more information. | |
9 * This software comes with no warranty of any kind, use at your own risk! | |
10 */ | |
11 | |
281 | 12 #include "main.h" |
9 | 13 #include "view_dir_list.h" |
14 | |
15 #include "dnd.h" | |
16 #include "dupe.h" | |
17 #include "filelist.h" | |
18 #include "layout.h" | |
19 #include "layout_image.h" | |
20 #include "layout_util.h" | |
21 #include "utilops.h" | |
22 #include "ui_bookmark.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 | |
31 #define VDLIST_PAD 4 | |
32 | |
380
5afe77bb563a
Introduce a new struct ViewDir to handle directory views common
zas_
parents:
373
diff
changeset
|
33 #define VDLIST_INFO(_vd_, _part_) (((ViewDirInfoList *)(_vd_->info))->_part_) |
9 | 34 |
35 | |
36 static gint vdlist_auto_scroll_notify_cb(GtkWidget *widget, gint x, gint y, gpointer data); | |
37 | |
38 /* | |
39 *----------------------------------------------------------------------------- | |
40 * misc | |
41 *----------------------------------------------------------------------------- | |
42 */ | |
43 | |
383
499d7ba62261
Move some dnd common code from view_dir_list.c and view_dir_tree.c
zas_
parents:
381
diff
changeset
|
44 gint vdlist_find_row(ViewDir *vd, FileData *fd, GtkTreeIter *iter) |
9 | 45 { |
46 GtkTreeModel *store; | |
47 gint valid; | |
48 gint row = 0; | |
49 | |
381 | 50 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); |
9 | 51 valid = gtk_tree_model_get_iter_first(store, iter); |
52 while (valid) | |
53 { | |
54 FileData *fd_n; | |
55 gtk_tree_model_get(GTK_TREE_MODEL(store), iter, DIR_COLUMN_POINTER, &fd_n, -1); | |
56 if (fd_n == fd) return row; | |
57 | |
58 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), iter); | |
59 row++; | |
60 } | |
61 | |
62 return -1; | |
63 } | |
64 | |
65 | |
388
5186f8e38cb8
Make directory view popup menu common and move it to view_dir.{c,h}.
zas_
parents:
385
diff
changeset
|
66 FileData *vdlist_row_by_path(ViewDir *vd, const gchar *path, gint *row) |
9 | 67 { |
68 GList *work; | |
69 gint n; | |
70 | |
71 if (!path) | |
72 { | |
73 if (row) *row = -1; | |
74 return NULL; | |
75 } | |
76 | |
77 n = 0; | |
381 | 78 work = VDLIST_INFO(vd, list); |
9 | 79 while (work) |
80 { | |
81 FileData *fd = work->data; | |
82 if (strcmp(fd->path, path) == 0) | |
83 { | |
84 if (row) *row = n; | |
85 return fd; | |
86 } | |
87 work = work->next; | |
88 n++; | |
89 } | |
90 | |
91 if (row) *row = -1; | |
92 return NULL; | |
93 } | |
94 | |
95 /* | |
96 *----------------------------------------------------------------------------- | |
97 * dnd | |
98 *----------------------------------------------------------------------------- | |
99 */ | |
100 | |
101 static GtkTargetEntry vdlist_dnd_drop_types[] = { | |
102 { "text/uri-list", 0, TARGET_URI_LIST } | |
103 }; | |
104 static gint vdlist_dnd_drop_types_count = 1; | |
105 | |
381 | 106 static void vdlist_dest_set(ViewDir *vd, gint enable) |
9 | 107 { |
108 if (enable) | |
109 { | |
381 | 110 gtk_drag_dest_set(vd->view, |
9 | 111 GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP, |
112 vdlist_dnd_drop_types, vdlist_dnd_drop_types_count, | |
113 GDK_ACTION_MOVE | GDK_ACTION_COPY); | |
114 } | |
115 else | |
116 { | |
381 | 117 gtk_drag_dest_unset(vd->view); |
9 | 118 } |
119 } | |
120 | |
121 static void vdlist_dnd_get(GtkWidget *widget, GdkDragContext *context, | |
122 GtkSelectionData *selection_data, guint info, | |
123 guint time, gpointer data) | |
124 { | |
381 | 125 ViewDir *vd = data; |
9 | 126 GList *list; |
127 gchar *text = NULL; | |
128 gint length = 0; | |
129 | |
381 | 130 if (!vd->click_fd) return; |
9 | 131 |
132 switch (info) | |
133 { | |
134 case TARGET_URI_LIST: | |
135 case TARGET_TEXT_PLAIN: | |
381 | 136 list = g_list_prepend(NULL, vd->click_fd); |
138 | 137 text = uri_text_from_filelist(list, &length, (info == TARGET_TEXT_PLAIN)); |
9 | 138 g_list_free(list); |
139 break; | |
140 } | |
141 if (text) | |
142 { | |
143 gtk_selection_data_set (selection_data, selection_data->target, | |
64
04ff0df3ad2f
Mon Aug 15 17:13:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
144 8, (guchar *)text, length); |
9 | 145 g_free(text); |
146 } | |
147 } | |
148 | |
149 static void vdlist_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data) | |
150 { | |
381 | 151 ViewDir *vd = data; |
9 | 152 |
383
499d7ba62261
Move some dnd common code from view_dir_list.c and view_dir_tree.c
zas_
parents:
381
diff
changeset
|
153 vd_color_set(vd, vd->click_fd, TRUE); |
381 | 154 vdlist_dest_set(vd, FALSE); |
9 | 155 } |
156 | |
157 static void vdlist_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data) | |
158 { | |
381 | 159 ViewDir *vd = data; |
9 | 160 |
383
499d7ba62261
Move some dnd common code from view_dir_list.c and view_dir_tree.c
zas_
parents:
381
diff
changeset
|
161 vd_color_set(vd, vd->click_fd, FALSE); |
9 | 162 |
163 if (context->action == GDK_ACTION_MOVE) | |
164 { | |
381 | 165 vdlist_refresh(vd); |
9 | 166 } |
381 | 167 vdlist_dest_set(vd, TRUE); |
9 | 168 } |
169 | |
170 static void vdlist_dnd_drop_receive(GtkWidget *widget, | |
171 GdkDragContext *context, gint x, gint y, | |
172 GtkSelectionData *selection_data, guint info, | |
173 guint time, gpointer data) | |
174 { | |
381 | 175 ViewDir *vd = data; |
9 | 176 GtkTreePath *tpath; |
177 GtkTreeIter iter; | |
178 FileData *fd = NULL; | |
179 | |
381 | 180 vd->click_fd = NULL; |
9 | 181 |
182 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), x, y, | |
183 &tpath, NULL, NULL, NULL)) | |
184 { | |
185 GtkTreeModel *store; | |
186 | |
187 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
188 gtk_tree_model_get_iter(store, &iter, tpath); | |
189 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1); | |
190 gtk_tree_path_free(tpath); | |
191 } | |
192 | |
193 if (!fd) return; | |
194 | |
195 if (info == TARGET_URI_LIST) | |
196 { | |
197 GList *list; | |
198 gint active; | |
199 | |
138 | 200 list = uri_filelist_from_text((gchar *)selection_data->data, TRUE); |
9 | 201 if (!list) return; |
202 | |
203 active = access_file(fd->path, W_OK | X_OK); | |
204 | |
383
499d7ba62261
Move some dnd common code from view_dir_list.c and view_dir_tree.c
zas_
parents:
381
diff
changeset
|
205 vd_color_set(vd, fd, TRUE); |
499d7ba62261
Move some dnd common code from view_dir_list.c and view_dir_tree.c
zas_
parents:
381
diff
changeset
|
206 vd->popup = vd_drop_menu(vd, active); |
381 | 207 gtk_menu_popup(GTK_MENU(vd->popup), NULL, NULL, NULL, NULL, 0, time); |
9 | 208 |
381 | 209 vd->drop_fd = fd; |
210 vd->drop_list = list; | |
9 | 211 } |
212 } | |
213 | |
214 #if 0 | |
381 | 215 static gint vdlist_get_row_visibility(ViewDir *vd, FileData *fd) |
9 | 216 { |
217 GtkTreeModel *store; | |
218 GtkTreeViewColumn *column; | |
219 GtkTreePath *tpath; | |
220 GtkTreeIter iter; | |
221 | |
222 GdkRectangle vrect; | |
223 GdkRectangle crect; | |
224 | |
389 | 225 if (!fd || vd_find_row(vd, fd, &iter) < 0) return 0; |
9 | 226 |
381 | 227 column = gtk_tree_view_get_column(GTK_TREE_VIEW(vd->view), 0); |
228 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); | |
9 | 229 tpath = gtk_tree_model_get_path(store, &iter); |
230 | |
381 | 231 gtk_tree_view_get_visible_rect(GTK_TREE_VIEW(vd->view), &vrect); |
232 gtk_tree_view_get_cell_area(GTK_TREE_VIEW(vd->view), tpath, column, &crect); | |
9 | 233 printf("window: %d + %d; cell: %d + %d\n", vrect.y, vrect.height, crect.y, crect.height); |
234 gtk_tree_path_free(tpath); | |
235 | |
236 if (crect.y + crect.height < vrect.y) return -1; | |
237 if (crect.y > vrect.y + vrect.height) return 1; | |
238 return 0; | |
239 } | |
240 #endif | |
241 | |
381 | 242 static void vdlist_scroll_to_row(ViewDir *vd, FileData *fd, gfloat y_align) |
9 | 243 { |
244 GtkTreeIter iter; | |
245 | |
381 | 246 if (GTK_WIDGET_REALIZED(vd->view) && |
389 | 247 vd_find_row(vd, fd, &iter) >= 0) |
9 | 248 { |
249 GtkTreeModel *store; | |
250 GtkTreePath *tpath; | |
251 | |
381 | 252 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); |
9 | 253 tpath = gtk_tree_model_get_path(store, &iter); |
381 | 254 gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(vd->view), tpath, NULL, TRUE, y_align, 0.0); |
255 gtk_tree_view_set_cursor(GTK_TREE_VIEW(vd->view), tpath, NULL, FALSE); | |
9 | 256 gtk_tree_path_free(tpath); |
257 | |
381 | 258 if (!GTK_WIDGET_HAS_FOCUS(vd->view)) gtk_widget_grab_focus(vd->view); |
9 | 259 } |
260 } | |
261 | |
381 | 262 static void vdlist_drop_update(ViewDir *vd, gint x, gint y) |
9 | 263 { |
264 GtkTreePath *tpath; | |
265 GtkTreeIter iter; | |
266 FileData *fd = NULL; | |
267 | |
381 | 268 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vd->view), x, y, |
9 | 269 &tpath, NULL, NULL, NULL)) |
270 { | |
271 GtkTreeModel *store; | |
272 | |
381 | 273 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); |
9 | 274 gtk_tree_model_get_iter(store, &iter, tpath); |
275 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1); | |
276 gtk_tree_path_free(tpath); | |
277 } | |
278 | |
381 | 279 if (fd != vd->drop_fd) |
9 | 280 { |
383
499d7ba62261
Move some dnd common code from view_dir_list.c and view_dir_tree.c
zas_
parents:
381
diff
changeset
|
281 vd_color_set(vd, vd->drop_fd, FALSE); |
499d7ba62261
Move some dnd common code from view_dir_list.c and view_dir_tree.c
zas_
parents:
381
diff
changeset
|
282 vd_color_set(vd, fd, TRUE); |
9 | 283 } |
284 | |
381 | 285 vd->drop_fd = fd; |
9 | 286 } |
287 | |
381 | 288 static void vdlist_dnd_drop_scroll_cancel(ViewDir *vd) |
9 | 289 { |
381 | 290 if (vd->drop_scroll_id != -1) g_source_remove(vd->drop_scroll_id); |
291 vd->drop_scroll_id = -1; | |
9 | 292 } |
293 | |
294 static gint vdlist_auto_scroll_idle_cb(gpointer data) | |
295 { | |
381 | 296 ViewDir *vd = data; |
9 | 297 |
381 | 298 if (vd->drop_fd) |
9 | 299 { |
300 GdkWindow *window; | |
301 gint x, y; | |
302 gint w, h; | |
303 | |
381 | 304 window = vd->view->window; |
9 | 305 gdk_window_get_pointer(window, &x, &y, NULL); |
306 gdk_drawable_get_size(window, &w, &h); | |
307 if (x >= 0 && x < w && y >= 0 && y < h) | |
308 { | |
381 | 309 vdlist_drop_update(vd, x, y); |
9 | 310 } |
311 } | |
312 | |
381 | 313 vd->drop_scroll_id = -1; |
9 | 314 return FALSE; |
315 } | |
316 | |
317 static gint vdlist_auto_scroll_notify_cb(GtkWidget *widget, gint x, gint y, gpointer data) | |
318 { | |
381 | 319 ViewDir *vd = data; |
9 | 320 |
381 | 321 if (!vd->drop_fd || vd->drop_list) return FALSE; |
9 | 322 |
381 | 323 if (vd->drop_scroll_id == -1) vd->drop_scroll_id = g_idle_add(vdlist_auto_scroll_idle_cb, vd); |
9 | 324 |
325 return TRUE; | |
326 } | |
327 | |
328 static gint vdlist_dnd_drop_motion(GtkWidget *widget, GdkDragContext *context, | |
329 gint x, gint y, guint time, gpointer data) | |
330 { | |
381 | 331 ViewDir *vd = data; |
9 | 332 |
381 | 333 vd->click_fd = NULL; |
9 | 334 |
381 | 335 if (gtk_drag_get_source_widget(context) == vd->view) |
9 | 336 { |
337 /* from same window */ | |
338 gdk_drag_status(context, 0, time); | |
339 return TRUE; | |
340 } | |
341 else | |
342 { | |
343 gdk_drag_status(context, context->suggested_action, time); | |
344 } | |
345 | |
381 | 346 vdlist_drop_update(vd, x, y); |
9 | 347 |
381 | 348 if (vd->drop_fd) |
9 | 349 { |
381 | 350 GtkAdjustment *adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(vd->view)); |
351 widget_auto_scroll_start(vd->view, adj, -1, -1, vdlist_auto_scroll_notify_cb, vd); | |
9 | 352 } |
353 | |
354 return FALSE; | |
355 } | |
356 | |
357 static void vdlist_dnd_drop_leave(GtkWidget *widget, GdkDragContext *context, guint time, gpointer data) | |
358 { | |
381 | 359 ViewDir *vd = data; |
9 | 360 |
383
499d7ba62261
Move some dnd common code from view_dir_list.c and view_dir_tree.c
zas_
parents:
381
diff
changeset
|
361 if (vd->drop_fd != vd->click_fd) vd_color_set(vd, vd->drop_fd, FALSE); |
9 | 362 |
381 | 363 vd->drop_fd = NULL; |
9 | 364 } |
365 | |
381 | 366 static void vdlist_dnd_init(ViewDir *vd) |
9 | 367 { |
381 | 368 gtk_drag_source_set(vd->view, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, |
9 | 369 dnd_file_drag_types, dnd_file_drag_types_count, |
370 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK); | |
381 | 371 g_signal_connect(G_OBJECT(vd->view), "drag_data_get", |
372 G_CALLBACK(vdlist_dnd_get), vd); | |
373 g_signal_connect(G_OBJECT(vd->view), "drag_begin", | |
374 G_CALLBACK(vdlist_dnd_begin), vd); | |
375 g_signal_connect(G_OBJECT(vd->view), "drag_end", | |
376 G_CALLBACK(vdlist_dnd_end), vd); | |
9 | 377 |
381 | 378 vdlist_dest_set(vd, TRUE); |
379 g_signal_connect(G_OBJECT(vd->view), "drag_data_received", | |
380 G_CALLBACK(vdlist_dnd_drop_receive), vd); | |
381 g_signal_connect(G_OBJECT(vd->view), "drag_motion", | |
382 G_CALLBACK(vdlist_dnd_drop_motion), vd); | |
383 g_signal_connect(G_OBJECT(vd->view), "drag_leave", | |
384 G_CALLBACK(vdlist_dnd_drop_leave), vd); | |
9 | 385 } |
386 | |
387 /* | |
388 *----------------------------------------------------------------------------- | |
389 * main | |
390 *----------------------------------------------------------------------------- | |
391 */ | |
392 | |
381 | 393 static void vdlist_select_row(ViewDir *vd, FileData *fd) |
9 | 394 { |
381 | 395 if (fd && vd->select_func) |
9 | 396 { |
397 gchar *path; | |
398 | |
399 path = g_strdup(fd->path); | |
381 | 400 vd->select_func(vd, path, vd->select_data); |
9 | 401 g_free(path); |
402 } | |
403 } | |
404 | |
381 | 405 const gchar *vdlist_row_get_path(ViewDir *vd, gint row) |
9 | 406 { |
407 FileData *fd; | |
408 | |
381 | 409 fd = g_list_nth_data(VDLIST_INFO(vd, list), row); |
9 | 410 |
411 if (fd) return fd->path; | |
412 | |
413 return NULL; | |
414 } | |
415 | |
381 | 416 static void vdlist_populate(ViewDir *vd) |
9 | 417 { |
418 GtkListStore *store; | |
419 GList *work; | |
420 | |
381 | 421 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view))); |
9 | 422 gtk_list_store_clear(store); |
423 | |
381 | 424 work = VDLIST_INFO(vd, list); |
9 | 425 while (work) |
426 { | |
427 FileData *fd; | |
428 GtkTreeIter iter; | |
429 GdkPixbuf *pixbuf; | |
430 | |
431 fd = work->data; | |
432 | |
433 if (access_file(fd->path, R_OK | X_OK) && fd->name) | |
434 { | |
435 if (fd->name[0] == '.' && fd->name[1] == '\0') | |
436 { | |
381 | 437 pixbuf = vd->pf->open; |
9 | 438 } |
439 else if (fd->name[0] == '.' && fd->name[1] == '.' && fd->name[2] == '\0') | |
440 { | |
381 | 441 pixbuf = vd->pf->parent; |
9 | 442 } |
443 else | |
444 { | |
381 | 445 pixbuf = vd->pf->close; |
9 | 446 } |
447 } | |
448 else | |
449 { | |
381 | 450 pixbuf = vd->pf->deny; |
9 | 451 } |
452 | |
453 gtk_list_store_append(store, &iter); | |
454 gtk_list_store_set(store, &iter, | |
455 DIR_COLUMN_POINTER, fd, | |
456 DIR_COLUMN_ICON, pixbuf, | |
457 DIR_COLUMN_NAME, fd->name, -1); | |
458 | |
459 work = work->next; | |
460 } | |
461 | |
381 | 462 vd->click_fd = NULL; |
463 vd->drop_fd = NULL; | |
9 | 464 } |
465 | |
381 | 466 gint vdlist_set_path(ViewDir *vd, const gchar *path) |
9 | 467 { |
468 gint ret; | |
469 FileData *fd; | |
470 gchar *old_path = NULL; | |
138 | 471 gchar *filepath; |
9 | 472 |
473 if (!path) return FALSE; | |
381 | 474 if (vd->path && strcmp(path, vd->path) == 0) return TRUE; |
9 | 475 |
381 | 476 if (vd->path) |
9 | 477 { |
478 gchar *base; | |
479 | |
381 | 480 base = remove_level_from_path(vd->path); |
9 | 481 if (strcmp(base, path) == 0) |
482 { | |
381 | 483 old_path = g_strdup(filename_from_path(vd->path)); |
9 | 484 } |
485 g_free(base); | |
486 } | |
487 | |
381 | 488 g_free(vd->path); |
489 vd->path = g_strdup(path); | |
9 | 490 |
381 | 491 filelist_free(VDLIST_INFO(vd, list)); |
492 VDLIST_INFO(vd, list) = NULL; | |
9 | 493 |
381 | 494 ret = filelist_read(vd->path, NULL, &VDLIST_INFO(vd, list)); |
9 | 495 |
381 | 496 VDLIST_INFO(vd, list) = filelist_sort(VDLIST_INFO(vd, list), SORT_NAME, TRUE); |
9 | 497 |
498 /* add . and .. */ | |
499 | |
381 | 500 if (strcmp(vd->path, "/") != 0) |
9 | 501 { |
381 | 502 filepath = g_strconcat(vd->path, "/", "..", NULL); |
138 | 503 fd = file_data_new_simple(filepath); |
381 | 504 VDLIST_INFO(vd, list) = g_list_prepend(VDLIST_INFO(vd, list), fd); |
138 | 505 g_free(filepath); |
9 | 506 } |
373
61a3c8b05b24
Add a new option in Preferences > Filtering to allow the
zas_
parents:
356
diff
changeset
|
507 |
61a3c8b05b24
Add a new option in Preferences > Filtering to allow the
zas_
parents:
356
diff
changeset
|
508 if (options->file_filter.show_dot_directory) |
61a3c8b05b24
Add a new option in Preferences > Filtering to allow the
zas_
parents:
356
diff
changeset
|
509 { |
381 | 510 filepath = g_strconcat(vd->path, "/", ".", NULL); |
373
61a3c8b05b24
Add a new option in Preferences > Filtering to allow the
zas_
parents:
356
diff
changeset
|
511 fd = file_data_new_simple(filepath); |
381 | 512 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
|
513 g_free(filepath); |
61a3c8b05b24
Add a new option in Preferences > Filtering to allow the
zas_
parents:
356
diff
changeset
|
514 } |
9 | 515 |
381 | 516 vdlist_populate(vd); |
9 | 517 |
518 if (old_path) | |
519 { | |
520 /* scroll to make last path visible */ | |
521 FileData *found = NULL; | |
522 GList *work; | |
523 | |
381 | 524 work = VDLIST_INFO(vd, list); |
9 | 525 while (work && !found) |
526 { | |
527 FileData *fd = work->data; | |
528 if (strcmp(old_path, fd->name) == 0) found = fd; | |
529 work = work->next; | |
530 } | |
531 | |
381 | 532 if (found) vdlist_scroll_to_row(vd, found, 0.5); |
9 | 533 |
534 g_free(old_path); | |
535 return ret; | |
536 } | |
537 | |
381 | 538 if (GTK_WIDGET_REALIZED(vd->view)) |
9 | 539 { |
381 | 540 gtk_tree_view_scroll_to_point(GTK_TREE_VIEW(vd->view), 0, 0); |
9 | 541 } |
542 | |
543 return ret; | |
544 } | |
545 | |
381 | 546 void vdlist_refresh(ViewDir *vd) |
9 | 547 { |
548 gchar *path; | |
549 | |
381 | 550 path = g_strdup(vd->path); |
551 vd->path = NULL; | |
552 vdlist_set_path(vd, path); | |
9 | 553 g_free(path); |
554 } | |
555 | |
556 static void vdlist_menu_position_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data) | |
557 { | |
381 | 558 ViewDir *vd = data; |
9 | 559 GtkTreeModel *store; |
560 GtkTreeIter iter; | |
561 GtkTreePath *tpath; | |
562 gint cw, ch; | |
563 | |
389 | 564 if (vd_find_row(vd, vd->click_fd, &iter) < 0) return; |
381 | 565 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); |
9 | 566 tpath = gtk_tree_model_get_path(store, &iter); |
381 | 567 tree_view_get_cell_clamped(GTK_TREE_VIEW(vd->view), tpath, 0, TRUE, x, y, &cw, &ch); |
9 | 568 gtk_tree_path_free(tpath); |
569 *y += ch; | |
570 popup_menu_position_clamp(menu, x, y, 0); | |
571 } | |
572 | |
573 static gint vdlist_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) | |
574 { | |
381 | 575 ViewDir *vd = data; |
9 | 576 GtkTreePath *tpath; |
577 | |
578 if (event->keyval != GDK_Menu) return FALSE; | |
579 | |
381 | 580 gtk_tree_view_get_cursor(GTK_TREE_VIEW(vd->view), &tpath, NULL); |
9 | 581 if (tpath) |
582 { | |
583 GtkTreeModel *store; | |
584 GtkTreeIter iter; | |
585 | |
586 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
587 gtk_tree_model_get_iter(store, &iter, tpath); | |
381 | 588 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &vd->click_fd, -1); |
9 | 589 |
590 gtk_tree_path_free(tpath); | |
591 } | |
592 else | |
593 { | |
381 | 594 vd->click_fd = NULL; |
9 | 595 } |
596 | |
383
499d7ba62261
Move some dnd common code from view_dir_list.c and view_dir_tree.c
zas_
parents:
381
diff
changeset
|
597 vd_color_set(vd, vd->click_fd, TRUE); |
9 | 598 |
388
5186f8e38cb8
Make directory view popup menu common and move it to view_dir.{c,h}.
zas_
parents:
385
diff
changeset
|
599 vd->popup = vd_pop_menu(vd, vd->click_fd); |
9 | 600 |
381 | 601 gtk_menu_popup(GTK_MENU(vd->popup), NULL, NULL, vdlist_menu_position_cb, vd, 0, GDK_CURRENT_TIME); |
9 | 602 |
603 return TRUE; | |
604 } | |
605 | |
606 static gint vdlist_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
607 { | |
381 | 608 ViewDir *vd = data; |
9 | 609 GtkTreePath *tpath; |
610 GtkTreeIter iter; | |
611 FileData *fd = NULL; | |
612 | |
613 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | |
614 &tpath, NULL, NULL, NULL)) | |
615 { | |
616 GtkTreeModel *store; | |
617 | |
618 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
619 gtk_tree_model_get_iter(store, &iter, tpath); | |
620 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1); | |
621 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE); | |
622 gtk_tree_path_free(tpath); | |
623 } | |
624 | |
381 | 625 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
|
626 vd_color_set(vd, vd->click_fd, TRUE); |
9 | 627 |
628 if (bevent->button == 3) | |
629 { | |
388
5186f8e38cb8
Make directory view popup menu common and move it to view_dir.{c,h}.
zas_
parents:
385
diff
changeset
|
630 vd->popup = vd_pop_menu(vd, vd->click_fd); |
381 | 631 gtk_menu_popup(GTK_MENU(vd->popup), NULL, NULL, NULL, NULL, |
9 | 632 bevent->button, bevent->time); |
633 } | |
634 | |
635 return TRUE; | |
636 } | |
637 | |
638 static gint vdlist_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
639 { | |
381 | 640 ViewDir *vd = data; |
9 | 641 GtkTreePath *tpath; |
642 GtkTreeIter iter; | |
643 FileData *fd = NULL; | |
644 | |
383
499d7ba62261
Move some dnd common code from view_dir_list.c and view_dir_tree.c
zas_
parents:
381
diff
changeset
|
645 vd_color_set(vd, vd->click_fd, FALSE); |
9 | 646 |
647 if (bevent->button != 1) return TRUE; | |
648 | |
649 if ((bevent->x != 0 || bevent->y != 0) && | |
650 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | |
651 &tpath, NULL, NULL, NULL)) | |
652 { | |
653 GtkTreeModel *store; | |
654 | |
655 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
656 gtk_tree_model_get_iter(store, &iter, tpath); | |
657 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1); | |
658 gtk_tree_path_free(tpath); | |
659 } | |
660 | |
381 | 661 if (fd && vd->click_fd == fd) |
9 | 662 { |
381 | 663 vdlist_select_row(vd, vd->click_fd); |
9 | 664 } |
665 | |
666 return TRUE; | |
667 } | |
668 | |
669 static void vdlist_select_cb(GtkTreeView *tview, GtkTreePath *tpath, GtkTreeViewColumn *column, gpointer data) | |
670 { | |
381 | 671 ViewDir *vd = data; |
9 | 672 GtkTreeModel *store; |
673 GtkTreeIter iter; | |
674 FileData *fd; | |
675 | |
676 store = gtk_tree_view_get_model(tview); | |
677 gtk_tree_model_get_iter(store, &iter, tpath); | |
678 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1); | |
679 | |
381 | 680 vdlist_select_row(vd, fd); |
9 | 681 } |
682 | |
683 static GdkColor *vdlist_color_shifted(GtkWidget *widget) | |
684 { | |
685 static GdkColor color; | |
686 static GtkWidget *done = NULL; | |
687 | |
688 if (done != widget) | |
689 { | |
690 GtkStyle *style; | |
384
392dd6541d51
Merge parts of view_dir_list/tree constructors/destructors to
zas_
parents:
383
diff
changeset
|
691 |
9 | 692 style = gtk_widget_get_style(widget); |
693 memcpy(&color, &style->base[GTK_STATE_NORMAL], sizeof(color)); | |
694 shift_color(&color, -1, 0); | |
695 done = widget; | |
696 } | |
697 | |
698 return &color; | |
699 } | |
700 | |
701 static void vdlist_color_cb(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, | |
702 GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data) | |
703 { | |
381 | 704 ViewDir *vd = data; |
9 | 705 gboolean set; |
706 | |
707 gtk_tree_model_get(tree_model, iter, DIR_COLUMN_COLOR, &set, -1); | |
708 g_object_set(G_OBJECT(cell), | |
381 | 709 "cell-background-gdk", vdlist_color_shifted(vd->view), |
9 | 710 "cell-background-set", set, NULL); |
711 } | |
712 | |
713 static void vdlist_destroy_cb(GtkWidget *widget, gpointer data) | |
714 { | |
381 | 715 ViewDir *vd = data; |
9 | 716 |
381 | 717 vdlist_dnd_drop_scroll_cancel(vd); |
718 widget_auto_scroll_stop(vd->view); | |
9 | 719 |
381 | 720 filelist_free(VDLIST_INFO(vd, list)); |
9 | 721 } |
722 | |
384
392dd6541d51
Merge parts of view_dir_list/tree constructors/destructors to
zas_
parents:
383
diff
changeset
|
723 ViewDir *vdlist_new(ViewDir *vd, const gchar *path) |
9 | 724 { |
725 GtkListStore *store; | |
726 GtkTreeSelection *selection; | |
727 GtkTreeViewColumn *column; | |
728 GtkCellRenderer *renderer; | |
729 | |
381 | 730 vd->info = g_new0(ViewDirInfoList, 1); |
731 vd->type = DIRVIEW_LIST; | |
384
392dd6541d51
Merge parts of view_dir_list/tree constructors/destructors to
zas_
parents:
383
diff
changeset
|
732 vd->widget_destroy_cb = vdlist_destroy_cb; |
9 | 733 |
384
392dd6541d51
Merge parts of view_dir_list/tree constructors/destructors to
zas_
parents:
383
diff
changeset
|
734 VDLIST_INFO(vd, list) = NULL; |
9 | 735 |
736 store = gtk_list_store_new(4, G_TYPE_POINTER, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_BOOLEAN); | |
381 | 737 vd->view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); |
9 | 738 g_object_unref(store); |
739 | |
381 | 740 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(vd->view), FALSE); |
741 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(vd->view), FALSE); | |
742 g_signal_connect(G_OBJECT(vd->view), "row_activated", | |
9 | 743 |
381 | 744 G_CALLBACK(vdlist_select_cb), vd); |
9 | 745 |
381 | 746 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vd->view)); |
9 | 747 gtk_tree_selection_set_mode(selection, GTK_SELECTION_NONE); |
748 | |
749 column = gtk_tree_view_column_new(); | |
750 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); | |
751 | |
752 renderer = gtk_cell_renderer_pixbuf_new(); | |
753 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
754 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", DIR_COLUMN_ICON); | |
381 | 755 gtk_tree_view_column_set_cell_data_func(column, renderer, vdlist_color_cb, vd, NULL); |
9 | 756 |
757 renderer = gtk_cell_renderer_text_new(); | |
758 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
759 gtk_tree_view_column_add_attribute(column, renderer, "text", DIR_COLUMN_NAME); | |
381 | 760 gtk_tree_view_column_set_cell_data_func(column, renderer, vdlist_color_cb, vd, NULL); |
9 | 761 |
381 | 762 gtk_tree_view_append_column(GTK_TREE_VIEW(vd->view), column); |
9 | 763 |
381 | 764 g_signal_connect(G_OBJECT(vd->view), "key_press_event", |
765 G_CALLBACK(vdlist_press_key_cb), vd); | |
766 gtk_container_add(GTK_CONTAINER(vd->widget), vd->view); | |
767 gtk_widget_show(vd->view); | |
9 | 768 |
381 | 769 vdlist_dnd_init(vd); |
9 | 770 |
381 | 771 g_signal_connect(G_OBJECT(vd->view), "button_press_event", |
772 G_CALLBACK(vdlist_press_cb), vd); | |
773 g_signal_connect(G_OBJECT(vd->view), "button_release_event", | |
774 G_CALLBACK(vdlist_release_cb), vd); | |
9 | 775 |
381 | 776 if (path) vdlist_set_path(vd, path); |
9 | 777 |
381 | 778 return vd; |
9 | 779 } |