Mercurial > geeqie
annotate src/view_dir_tree.c @ 916:64fd2fc5cb7a
Fix warning: passing argument 1 of 'gtk_tree_store_set' from incompatible pointer type
| author | zas_ |
|---|---|
| date | Wed, 23 Jul 2008 08:59:29 +0000 |
| parents | ca8022a156ec |
| children | b483d8cdedb6 |
| rev | line source |
|---|---|
| 9 | 1 /* |
| 196 | 2 * Geeqie |
|
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
3 * (C) 2006 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_tree.h" |
| 15 | |
| 16 | |
| 17 #include "dnd.h" | |
| 18 #include "dupe.h" | |
| 586 | 19 #include "filedata.h" |
| 9 | 20 #include "layout.h" |
| 21 #include "layout_image.h" | |
| 22 #include "layout_util.h" | |
| 23 #include "utilops.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:
356
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:
356
diff
changeset
|
32 #define VDTREE_INFO(_vd_, _part_) (((ViewDirInfoTree *)(_vd_->info))->_part_) |
| 9 | 33 |
| 34 | |
| 35 typedef struct _PathData PathData; | |
| 36 struct _PathData | |
| 37 { | |
| 38 gchar *name; | |
| 39 FileData *node; | |
| 40 }; | |
| 41 | |
| 42 | |
| 43 | |
| 44 | |
| 45 /* | |
| 46 *---------------------------------------------------------------------------- | |
| 47 * utils | |
| 48 *---------------------------------------------------------------------------- | |
| 49 */ | |
| 50 | |
| 51 static void set_cursor(GtkWidget *widget, GdkCursorType cursor_type) | |
| 52 { | |
| 53 GdkCursor *cursor = NULL; | |
| 54 | |
| 55 if (!widget || !widget->window) return; | |
| 56 | |
|
512
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
475
diff
changeset
|
57 if (cursor_type > -1) cursor = gdk_cursor_new(cursor_type); |
|
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
475
diff
changeset
|
58 gdk_window_set_cursor(widget->window, cursor); |
| 9 | 59 if (cursor) gdk_cursor_unref(cursor); |
| 60 gdk_flush(); | |
| 61 } | |
| 62 | |
| 382 | 63 static void vdtree_busy_push(ViewDir *vd) |
| 9 | 64 { |
| 382 | 65 if (VDTREE_INFO(vd, busy_ref) == 0) set_cursor(vd->view, GDK_WATCH); |
| 66 VDTREE_INFO(vd, busy_ref)++; | |
| 9 | 67 } |
| 68 | |
| 382 | 69 static void vdtree_busy_pop(ViewDir *vd) |
| 9 | 70 { |
| 382 | 71 if (VDTREE_INFO(vd, busy_ref) == 1) set_cursor(vd->view, -1); |
| 72 if (VDTREE_INFO(vd, busy_ref) > 0) VDTREE_INFO(vd, busy_ref)--; | |
| 9 | 73 } |
| 74 | |
|
383
499d7ba62261
Move some dnd common code from view_dir_list.c and view_dir_tree.c
zas_
parents:
382
diff
changeset
|
75 gint vdtree_find_row(ViewDir *vd, FileData *fd, GtkTreeIter *iter, GtkTreeIter *parent) |
| 9 | 76 { |
| 77 GtkTreeModel *store; | |
| 78 gint valid; | |
| 79 | |
| 382 | 80 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); |
| 9 | 81 if (parent) |
| 82 { | |
| 83 valid = gtk_tree_model_iter_children(store, iter, parent); | |
| 84 } | |
| 85 else | |
| 86 { | |
| 87 valid = gtk_tree_model_get_iter_first(store, iter); | |
| 88 } | |
| 89 while (valid) | |
| 90 { | |
| 91 NodeData *nd; | |
| 92 GtkTreeIter found; | |
| 93 | |
| 94 gtk_tree_model_get(GTK_TREE_MODEL(store), iter, DIR_COLUMN_POINTER, &nd, -1); | |
| 95 if (nd->fd == fd) return TRUE; | |
| 96 | |
| 382 | 97 if (vdtree_find_row(vd, fd, &found, iter)) |
| 9 | 98 { |
| 99 memcpy(iter, &found, sizeof(found)); | |
| 100 return TRUE; | |
| 101 } | |
| 102 | |
| 103 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), iter); | |
| 104 } | |
| 105 | |
| 106 return FALSE; | |
| 107 } | |
| 108 | |
| 382 | 109 static void vdtree_icon_set_by_iter(ViewDir *vd, GtkTreeIter *iter, GdkPixbuf *pixbuf) |
| 9 | 110 { |
| 111 GtkTreeModel *store; | |
| 112 GdkPixbuf *old; | |
| 113 | |
| 382 | 114 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); |
| 9 | 115 gtk_tree_model_get(store, iter, DIR_COLUMN_ICON, &old, -1); |
| 382 | 116 if (old != vd->pf->deny) |
| 9 | 117 { |
| 118 gtk_tree_store_set(GTK_TREE_STORE(store), iter, DIR_COLUMN_ICON, pixbuf, -1); | |
| 119 } | |
| 120 } | |
| 121 | |
| 382 | 122 static void vdtree_expand_by_iter(ViewDir *vd, GtkTreeIter *iter, gint expand) |
| 9 | 123 { |
| 124 GtkTreeModel *store; | |
| 125 GtkTreePath *tpath; | |
| 126 | |
| 382 | 127 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); |
| 9 | 128 tpath = gtk_tree_model_get_path(store, iter); |
| 129 if (expand) | |
| 130 { | |
| 382 | 131 gtk_tree_view_expand_row(GTK_TREE_VIEW(vd->view), tpath, FALSE); |
| 132 vdtree_icon_set_by_iter(vd, iter, vd->pf->open); | |
| 9 | 133 } |
| 134 else | |
| 135 { | |
| 382 | 136 gtk_tree_view_collapse_row(GTK_TREE_VIEW(vd->view), tpath); |
| 9 | 137 } |
| 138 gtk_tree_path_free(tpath); | |
| 139 } | |
| 140 | |
| 382 | 141 static void vdtree_expand_by_data(ViewDir *vd, FileData *fd, gint expand) |
| 9 | 142 { |
| 143 GtkTreeIter iter; | |
| 144 | |
| 389 | 145 if (vd_find_row(vd, fd, &iter)) |
| 9 | 146 { |
| 382 | 147 vdtree_expand_by_iter(vd, &iter, expand); |
| 9 | 148 } |
| 149 } | |
| 150 | |
| 151 static void vdtree_node_free(NodeData *nd) | |
| 152 { | |
| 153 if (!nd) return; | |
| 154 | |
| 138 | 155 file_data_unref(nd->fd); |
| 9 | 156 g_free(nd); |
| 157 } | |
| 158 | |
| 159 /* | |
| 160 *---------------------------------------------------------------------------- | |
| 161 * dnd | |
| 162 *---------------------------------------------------------------------------- | |
| 163 */ | |
| 164 | |
| 165 static gint vdtree_dnd_drop_expand_cb(gpointer data) | |
| 166 { | |
| 382 | 167 ViewDir *vd = data; |
| 9 | 168 GtkTreeIter iter; |
| 169 | |
| 394 | 170 if (vd->drop_fd && vd_find_row(vd, vd->drop_fd, &iter)) |
| 9 | 171 { |
| 783 | 172 vdtree_populate_path_by_iter(vd, &iter, FALSE, vd->dir_fd); |
| 382 | 173 vdtree_expand_by_data(vd, vd->drop_fd, TRUE); |
| 9 | 174 } |
| 175 | |
| 382 | 176 VDTREE_INFO(vd, drop_expand_id) = -1; |
| 9 | 177 return FALSE; |
| 178 } | |
| 179 | |
| 407 | 180 static void vdtree_dnd_drop_expand_cancel(ViewDir *vd) |
| 9 | 181 { |
| 382 | 182 if (VDTREE_INFO(vd, drop_expand_id) != -1) g_source_remove(VDTREE_INFO(vd, drop_expand_id)); |
| 183 VDTREE_INFO(vd, drop_expand_id) = -1; | |
| 9 | 184 } |
| 185 | |
| 407 | 186 static void vdtree_dnd_drop_expand(ViewDir *vd) |
| 9 | 187 { |
| 382 | 188 vdtree_dnd_drop_expand_cancel(vd); |
| 189 VDTREE_INFO(vd, drop_expand_id) = g_timeout_add(1000, vdtree_dnd_drop_expand_cb, vd); | |
| 9 | 190 } |
| 191 | |
| 192 /* | |
| 193 *---------------------------------------------------------------------------- | |
| 194 * parts lists | |
| 195 *---------------------------------------------------------------------------- | |
| 196 */ | |
| 197 | |
| 198 static GList *parts_list(const gchar *path) | |
| 199 { | |
| 200 GList *list = NULL; | |
| 201 const gchar *strb, *strp; | |
| 202 gint l; | |
| 203 | |
| 204 strp = path; | |
| 205 | |
| 726 | 206 if (*strp != G_DIR_SEPARATOR) return NULL; |
| 9 | 207 |
| 208 strp++; | |
| 209 strb = strp; | |
| 210 l = 0; | |
| 211 | |
| 212 while (*strp != '\0') | |
| 213 { | |
| 726 | 214 if (*strp == G_DIR_SEPARATOR) |
| 9 | 215 { |
| 216 if (l > 0) list = g_list_prepend(list, g_strndup(strb, l)); | |
| 217 strp++; | |
| 218 strb = strp; | |
| 219 l = 0; | |
| 220 } | |
| 221 else | |
| 222 { | |
| 223 strp++; | |
| 224 l++; | |
| 225 } | |
| 226 } | |
| 227 if (l > 0) list = g_list_prepend(list, g_strndup(strb, l)); | |
| 228 | |
| 229 list = g_list_reverse(list); | |
| 230 | |
| 725 | 231 list = g_list_prepend(list, g_strdup(G_DIR_SEPARATOR_S)); |
| 9 | 232 |
| 233 return list; | |
| 234 } | |
| 235 | |
| 236 static void parts_list_free(GList *list) | |
| 237 { | |
| 238 GList *work = list; | |
| 239 while (work) | |
| 240 { | |
| 241 PathData *pd = work->data; | |
| 242 g_free(pd->name); | |
| 243 g_free(pd); | |
| 244 work = work->next; | |
| 245 } | |
| 246 | |
| 247 g_list_free(list); | |
| 248 } | |
| 249 | |
| 382 | 250 static GList *parts_list_add_node_points(ViewDir *vd, GList *list) |
| 9 | 251 { |
| 252 GList *work; | |
| 253 GtkTreeModel *store; | |
| 254 GtkTreeIter iter; | |
| 255 gint valid; | |
| 256 | |
| 382 | 257 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); |
| 9 | 258 valid = gtk_tree_model_get_iter_first(store, &iter); |
| 259 | |
| 260 work = list; | |
| 261 while (work) | |
| 262 { | |
| 263 PathData *pd; | |
| 264 FileData *fd = NULL; | |
| 265 | |
| 266 pd = g_new0(PathData, 1); | |
| 267 pd->name = work->data; | |
| 268 | |
| 269 while (valid && !fd) | |
| 270 { | |
| 271 NodeData *nd; | |
| 272 | |
| 273 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
| 274 if (strcmp(nd->fd->name, pd->name) == 0) | |
| 275 { | |
| 276 fd = nd->fd; | |
| 277 } | |
| 278 else | |
| 279 { | |
| 280 valid = gtk_tree_model_iter_next(store, &iter); | |
| 281 } | |
| 282 } | |
| 283 | |
| 284 pd->node = fd; | |
| 285 work->data = pd; | |
| 286 | |
| 287 if (fd) | |
| 288 { | |
| 289 GtkTreeIter parent; | |
| 290 memcpy(&parent, &iter, sizeof(parent)); | |
| 291 valid = gtk_tree_model_iter_children(store, &iter, &parent); | |
| 292 } | |
| 293 | |
| 294 work = work->next; | |
| 295 } | |
| 296 | |
| 297 return list; | |
| 298 } | |
| 299 | |
| 300 /* | |
| 301 *---------------------------------------------------------------------------- | |
| 302 * misc | |
| 303 *---------------------------------------------------------------------------- | |
| 304 */ | |
| 305 | |
| 306 #if 0 | |
| 307 static void vdtree_row_deleted_cb(GtkTreeModel *tree_model, GtkTreePath *tpath, gpointer data) | |
| 308 { | |
| 309 GtkTreeIter iter; | |
| 310 NodeData *nd; | |
| 311 | |
| 312 gtk_tree_model_get_iter(tree_model, &iter, tpath); | |
| 313 gtk_tree_model_get(tree_model, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
| 314 | |
| 315 if (!nd) return; | |
| 316 | |
| 138 | 317 file_data_unref(nd->fd); |
| 9 | 318 g_free(nd); |
| 319 } | |
| 320 #endif | |
| 321 | |
| 322 /* | |
| 323 *---------------------------------------------------------------------------- | |
| 324 * node traversal, management | |
| 325 *---------------------------------------------------------------------------- | |
| 326 */ | |
| 327 | |
| 382 | 328 static gint vdtree_find_iter_by_data(ViewDir *vd, GtkTreeIter *parent, NodeData *nd, GtkTreeIter *iter) |
| 9 | 329 { |
| 330 GtkTreeModel *store; | |
| 331 | |
| 382 | 332 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); |
| 9 | 333 if (!nd || !gtk_tree_model_iter_children(store, iter, parent)) return -1; |
| 334 do { | |
| 335 NodeData *cnd; | |
| 336 | |
| 337 gtk_tree_model_get(store, iter, DIR_COLUMN_POINTER, &cnd, -1); | |
| 338 if (cnd == nd) return TRUE; | |
| 339 } while (gtk_tree_model_iter_next(store, iter)); | |
| 340 | |
| 341 return FALSE; | |
| 342 } | |
| 343 | |
| 382 | 344 static NodeData *vdtree_find_iter_by_name(ViewDir *vd, GtkTreeIter *parent, const gchar *name, GtkTreeIter *iter) |
| 9 | 345 { |
| 346 GtkTreeModel *store; | |
| 347 | |
| 382 | 348 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); |
| 9 | 349 if (!name || !gtk_tree_model_iter_children(store, iter, parent)) return NULL; |
| 350 do { | |
| 351 NodeData *nd; | |
| 352 | |
| 353 gtk_tree_model_get(store, iter, DIR_COLUMN_POINTER, &nd, -1); | |
| 354 if (nd && strcmp(nd->fd->name, name) == 0) return nd; | |
| 355 } while (gtk_tree_model_iter_next(store, iter)); | |
| 356 | |
| 357 return NULL; | |
| 358 } | |
| 359 | |
| 382 | 360 static void vdtree_add_by_data(ViewDir *vd, FileData *fd, GtkTreeIter *parent) |
| 9 | 361 { |
| 362 GtkTreeStore *store; | |
| 363 GtkTreeIter child; | |
| 364 NodeData *nd; | |
| 365 GdkPixbuf *pixbuf; | |
| 366 NodeData *end; | |
| 367 GtkTreeIter empty; | |
| 368 | |
| 369 if (!fd) return; | |
| 370 | |
| 371 if (access_file(fd->path, R_OK | X_OK)) | |
| 372 { | |
| 382 | 373 pixbuf = vd->pf->close; |
| 9 | 374 } |
| 375 else | |
| 376 { | |
| 382 | 377 pixbuf = vd->pf->deny; |
| 9 | 378 } |
| 379 | |
| 380 nd = g_new0(NodeData, 1); | |
| 381 nd->fd = fd; | |
| 907 | 382 nd->version = fd->version; |
| 9 | 383 nd->expanded = FALSE; |
| 384 nd->last_update = time(NULL); | |
| 385 | |
| 382 | 386 store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view))); |
| 9 | 387 gtk_tree_store_append(store, &child, parent); |
| 388 gtk_tree_store_set(store, &child, DIR_COLUMN_POINTER, nd, | |
| 389 DIR_COLUMN_ICON, pixbuf, | |
| 390 DIR_COLUMN_NAME, nd->fd->name, | |
| 391 DIR_COLUMN_COLOR, FALSE, -1); | |
| 392 | |
| 393 /* all nodes are created with an "empty" node, so that the expander is shown | |
| 394 * this is removed when the child is populated */ | |
| 395 end = g_new0(NodeData, 1); | |
| 138 | 396 end->fd = file_data_new_simple(""); |
| 9 | 397 end->expanded = TRUE; |
| 398 | |
| 399 gtk_tree_store_append(store, &empty, &child); | |
| 400 gtk_tree_store_set(store, &empty, DIR_COLUMN_POINTER, end, | |
| 401 DIR_COLUMN_NAME, "empty", -1); | |
| 402 | |
| 403 if (parent) | |
| 404 { | |
| 405 NodeData *pnd; | |
| 406 GtkTreePath *tpath; | |
| 407 | |
| 408 gtk_tree_model_get(GTK_TREE_MODEL(store), parent, DIR_COLUMN_POINTER, &pnd, -1); | |
| 409 tpath = gtk_tree_model_get_path(GTK_TREE_MODEL(store), parent); | |
| 320 | 410 if (options->tree_descend_subdirs && |
| 382 | 411 gtk_tree_view_row_expanded(GTK_TREE_VIEW(vd->view), tpath) && |
| 9 | 412 !nd->expanded) |
| 413 { | |
| 783 | 414 vdtree_populate_path_by_iter(vd, &child, FALSE, vd->dir_fd); |
| 9 | 415 } |
| 416 gtk_tree_path_free(tpath); | |
| 417 } | |
| 418 } | |
| 419 | |
| 907 | 420 gint vdtree_populate_path_by_iter(ViewDir *vd, GtkTreeIter *iter, gint force, FileData *target_fd) |
| 9 | 421 { |
| 422 GtkTreeModel *store; | |
| 423 GList *list; | |
| 424 GList *work; | |
| 425 GList *old; | |
| 426 time_t current_time; | |
| 427 GtkTreeIter child; | |
| 428 NodeData *nd; | |
| 429 | |
| 382 | 430 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); |
| 9 | 431 gtk_tree_model_get(store, iter, DIR_COLUMN_POINTER, &nd, -1); |
| 432 | |
| 433 if (!nd) return FALSE; | |
| 434 | |
| 435 current_time = time(NULL); | |
| 442 | 436 |
| 9 | 437 if (nd->expanded) |
| 438 { | |
| 439 if (!force && current_time - nd->last_update < 10) return TRUE; | |
| 440 if (!isdir(nd->fd->path)) | |
| 441 { | |
| 382 | 442 if (vd->click_fd == nd->fd) vd->click_fd = NULL; |
| 443 if (vd->drop_fd == nd->fd) vd->drop_fd = NULL; | |
| 9 | 444 gtk_tree_store_remove(GTK_TREE_STORE(store), iter); |
| 445 vdtree_node_free(nd); | |
| 446 return FALSE; | |
| 447 } | |
| 907 | 448 if (!force && nd->fd->version == nd->version) return TRUE; |
| 9 | 449 } |
| 450 | |
| 382 | 451 vdtree_busy_push(vd); |
| 9 | 452 |
| 783 | 453 filelist_read(nd->fd, NULL, &list); |
| 9 | 454 |
| 455 /* when hidden files are not enabled, and the user enters a hidden path, | |
| 456 * allow the tree to display that path by specifically inserting the hidden entries | |
| 457 */ | |
| 356 | 458 if (!options->file_filter.show_hidden_files && |
| 783 | 459 target_fd && |
| 460 strncmp(nd->fd->path, target_fd->path, strlen(nd->fd->path)) == 0) | |
| 9 | 461 { |
| 462 gint n; | |
| 463 | |
| 464 n = strlen(nd->fd->path); | |
| 783 | 465 if (target_fd->path[n] == G_DIR_SEPARATOR && target_fd->path[n+1] == '.') |
| 9 | 466 { |
| 467 gchar *name8; | |
| 468 struct stat sbuf; | |
| 469 | |
| 470 n++; | |
| 471 | |
| 783 | 472 while (target_fd->path[n] != '\0' && target_fd->path[n] != G_DIR_SEPARATOR) n++; |
| 473 name8 = g_strndup(target_fd->path, n); | |
| 9 | 474 |
| 475 if (stat_utf8(name8, &sbuf)) | |
| 476 { | |
|
145
8be2cc687304
fixed grouping sidecar files and made it configurable via config file
nadvornik
parents:
138
diff
changeset
|
477 list = g_list_prepend(list, file_data_new_simple(name8)); |
| 9 | 478 } |
| 479 | |
| 480 g_free(name8); | |
| 481 } | |
| 482 } | |
| 483 | |
| 484 old = NULL; | |
| 485 if (gtk_tree_model_iter_children(store, &child, iter)) | |
| 486 { | |
| 487 do { | |
| 488 NodeData *cnd; | |
| 489 | |
| 490 gtk_tree_model_get(store, &child, DIR_COLUMN_POINTER, &cnd, -1); | |
| 491 old = g_list_prepend(old, cnd); | |
| 492 } while (gtk_tree_model_iter_next(store, &child)); | |
| 493 } | |
| 494 | |
| 495 work = list; | |
| 496 while (work) | |
| 497 { | |
| 498 FileData *fd; | |
| 499 | |
| 500 fd = work->data; | |
| 501 work = work->next; | |
| 502 | |
| 503 if (strcmp(fd->name, ".") == 0 || strcmp(fd->name, "..") == 0) | |
| 504 { | |
| 138 | 505 file_data_unref(fd); |
| 9 | 506 } |
| 507 else | |
| 508 { | |
| 509 NodeData *cnd; | |
| 510 | |
| 382 | 511 cnd = vdtree_find_iter_by_name(vd, iter, fd->name, &child); |
| 9 | 512 if (cnd) |
| 513 { | |
| 514 old = g_list_remove(old, cnd); | |
| 907 | 515 if (cnd->expanded && cnd->version != fd->version && |
| 783 | 516 vdtree_populate_path_by_iter(vd, &child, FALSE, target_fd)) |
| 9 | 517 { |
|
916
64fd2fc5cb7a
Fix warning: passing argument 1 of 'gtk_tree_store_set' from incompatible pointer type
zas_
parents:
907
diff
changeset
|
518 gtk_tree_store_set(GTK_TREE_STORE(store), &child, DIR_COLUMN_NAME, fd->name, -1); |
| 907 | 519 cnd->version = fd->version; |
| 9 | 520 } |
| 521 | |
| 138 | 522 file_data_unref(fd); |
| 9 | 523 } |
| 524 else | |
| 525 { | |
| 382 | 526 vdtree_add_by_data(vd, fd, iter); |
| 9 | 527 } |
| 528 } | |
| 529 } | |
| 530 | |
| 531 work = old; | |
| 532 while (work) | |
| 533 { | |
| 534 NodeData *cnd = work->data; | |
| 535 work = work->next; | |
| 536 | |
| 382 | 537 if (vd->click_fd == cnd->fd) vd->click_fd = NULL; |
| 538 if (vd->drop_fd == cnd->fd) vd->drop_fd = NULL; | |
| 9 | 539 |
| 382 | 540 if (vdtree_find_iter_by_data(vd, iter, cnd, &child)) |
| 9 | 541 { |
| 542 gtk_tree_store_remove(GTK_TREE_STORE(store), &child); | |
| 543 vdtree_node_free(cnd); | |
| 544 } | |
| 545 } | |
| 546 | |
| 547 g_list_free(old); | |
| 548 g_list_free(list); | |
| 549 | |
| 382 | 550 vdtree_busy_pop(vd); |
| 9 | 551 |
| 552 nd->expanded = TRUE; | |
| 553 nd->last_update = current_time; | |
| 554 | |
| 555 return TRUE; | |
| 556 } | |
| 557 | |
| 783 | 558 FileData *vdtree_populate_path(ViewDir *vd, FileData *target_fd, gint expand, gint force) |
| 9 | 559 { |
| 560 GList *list; | |
| 561 GList *work; | |
| 562 FileData *fd = NULL; | |
| 563 | |
| 783 | 564 if (!target_fd) return NULL; |
| 9 | 565 |
| 382 | 566 vdtree_busy_push(vd); |
| 9 | 567 |
| 783 | 568 list = parts_list(target_fd->path); |
| 382 | 569 list = parts_list_add_node_points(vd, list); |
| 9 | 570 |
| 571 work = list; | |
| 572 while (work) | |
| 573 { | |
| 574 PathData *pd = work->data; | |
| 575 if (pd->node == NULL) | |
| 576 { | |
| 577 PathData *parent_pd; | |
| 578 GtkTreeIter parent_iter; | |
| 579 GtkTreeIter iter; | |
| 580 NodeData *nd; | |
| 581 | |
| 582 if (work == list) | |
| 583 { | |
| 584 /* should not happen */ | |
|
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
586
diff
changeset
|
585 log_printf("vdtree warning, root node not found\n"); |
| 9 | 586 parts_list_free(list); |
| 382 | 587 vdtree_busy_pop(vd); |
| 9 | 588 return NULL; |
| 589 } | |
| 590 | |
| 591 parent_pd = work->prev->data; | |
| 592 | |
| 389 | 593 if (!vd_find_row(vd, parent_pd->node, &parent_iter) || |
| 783 | 594 !vdtree_populate_path_by_iter(vd, &parent_iter, force, target_fd) || |
| 382 | 595 (nd = vdtree_find_iter_by_name(vd, &parent_iter, pd->name, &iter)) == NULL) |
| 9 | 596 { |
|
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
586
diff
changeset
|
597 log_printf("vdtree warning, aborted at %s\n", parent_pd->name); |
| 9 | 598 parts_list_free(list); |
| 382 | 599 vdtree_busy_pop(vd); |
| 9 | 600 return NULL; |
| 601 } | |
| 602 | |
| 603 pd->node = nd->fd; | |
| 604 | |
| 605 if (pd->node) | |
| 606 { | |
| 607 if (expand) | |
| 608 { | |
| 382 | 609 vdtree_expand_by_iter(vd, &parent_iter, TRUE); |
| 610 vdtree_expand_by_iter(vd, &iter, TRUE); | |
| 9 | 611 } |
| 783 | 612 vdtree_populate_path_by_iter(vd, &iter, force, target_fd); |
| 9 | 613 } |
| 614 } | |
| 615 else | |
| 616 { | |
| 617 GtkTreeIter iter; | |
| 618 | |
| 389 | 619 if (vd_find_row(vd, pd->node, &iter)) |
| 9 | 620 { |
| 382 | 621 if (expand) vdtree_expand_by_iter(vd, &iter, TRUE); |
| 783 | 622 vdtree_populate_path_by_iter(vd, &iter, force, target_fd); |
| 9 | 623 } |
| 624 } | |
| 625 | |
| 626 work = work->next; | |
| 627 } | |
| 628 | |
| 629 work = g_list_last(list); | |
| 630 if (work) | |
| 631 { | |
| 632 PathData *pd = work->data; | |
| 633 fd = pd->node; | |
| 634 } | |
| 635 parts_list_free(list); | |
| 636 | |
| 382 | 637 vdtree_busy_pop(vd); |
| 9 | 638 |
| 639 return fd; | |
| 640 } | |
| 641 | |
| 642 /* | |
| 643 *---------------------------------------------------------------------------- | |
| 644 * access | |
| 645 *---------------------------------------------------------------------------- | |
| 646 */ | |
| 647 | |
| 648 static gint selection_is_ok = FALSE; | |
| 649 | |
| 650 static gboolean vdtree_select_cb(GtkTreeSelection *selection, GtkTreeModel *store, GtkTreePath *tpath, | |
| 442 | 651 gboolean path_currently_selected, gpointer data) |
| 9 | 652 { |
| 653 return selection_is_ok; | |
| 654 } | |
| 655 | |
| 396 | 656 void vdtree_select_row(ViewDir *vd, FileData *fd) |
| 9 | 657 { |
| 658 GtkTreeSelection *selection; | |
| 659 GtkTreeIter iter; | |
| 442 | 660 |
| 389 | 661 if (!vd_find_row(vd, fd, &iter)) return; |
| 382 | 662 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vd->view)); |
| 9 | 663 |
| 664 /* hack, such that selection is only allowed to be changed from here */ | |
| 665 selection_is_ok = TRUE; | |
| 666 gtk_tree_selection_select_iter(selection, &iter); | |
| 667 selection_is_ok = FALSE; | |
| 668 | |
| 783 | 669 if (!vdtree_populate_path_by_iter(vd, &iter, FALSE, vd->dir_fd)) return; |
| 9 | 670 |
| 382 | 671 vdtree_expand_by_iter(vd, &iter, TRUE); |
| 9 | 672 |
| 442 | 673 if (fd && vd->select_func) |
| 674 { | |
| 675 vd->select_func(vd, fd->path, vd->select_data); | |
| 676 } | |
| 9 | 677 } |
| 678 | |
| 783 | 679 gint vdtree_set_fd(ViewDir *vd, FileData *dir_fd) |
| 9 | 680 { |
| 681 FileData *fd; | |
| 682 GtkTreeIter iter; | |
| 683 | |
| 783 | 684 if (!dir_fd) return FALSE; |
| 685 if (vd->dir_fd == dir_fd) return TRUE; | |
| 9 | 686 |
| 783 | 687 file_data_unref(vd->dir_fd); |
| 688 vd->dir_fd = file_data_ref(dir_fd);; | |
| 9 | 689 |
| 783 | 690 fd = vdtree_populate_path(vd, vd->dir_fd, TRUE, FALSE); |
| 9 | 691 |
| 692 if (!fd) return FALSE; | |
| 693 | |
| 389 | 694 if (vd_find_row(vd, fd, &iter)) |
| 9 | 695 { |
| 696 GtkTreeModel *store; | |
| 697 GtkTreePath *tpath; | |
| 698 | |
| 382 | 699 tree_view_row_make_visible(GTK_TREE_VIEW(vd->view), &iter, TRUE); |
| 9 | 700 |
| 382 | 701 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); |
| 9 | 702 tpath = gtk_tree_model_get_path(store, &iter); |
| 382 | 703 gtk_tree_view_set_cursor(GTK_TREE_VIEW(vd->view), tpath, NULL, FALSE); |
| 9 | 704 gtk_tree_path_free(tpath); |
| 705 | |
| 382 | 706 vdtree_select_row(vd, fd); |
| 9 | 707 } |
| 708 | |
| 709 return TRUE; | |
| 710 } | |
| 711 | |
| 712 #if 0 | |
| 382 | 713 const gchar *vdtree_get_path(ViewDir *vd) |
| 9 | 714 { |
| 382 | 715 return vd->path; |
| 9 | 716 } |
| 717 #endif | |
| 718 | |
| 382 | 719 void vdtree_refresh(ViewDir *vd) |
| 9 | 720 { |
| 783 | 721 vdtree_populate_path(vd, vd->dir_fd, FALSE, TRUE); |
| 9 | 722 } |
| 723 | |
| 382 | 724 const gchar *vdtree_row_get_path(ViewDir *vd, gint row) |
| 9 | 725 { |
|
673
fbebf5cf4a55
Do not use printf() directly but use new wrapper function log_printf() instead.
zas_
parents:
586
diff
changeset
|
726 log_printf("FIXME: no get row path\n"); |
| 9 | 727 return NULL; |
| 728 } | |
| 729 | |
| 730 /* | |
| 731 *---------------------------------------------------------------------------- | |
| 732 * callbacks | |
| 733 *---------------------------------------------------------------------------- | |
| 734 */ | |
| 735 | |
|
401
0a2e1b130a25
Add some wrappers in view_dir.c and simplify even more.
zas_
parents:
397
diff
changeset
|
736 gint vdtree_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) |
| 9 | 737 { |
| 382 | 738 ViewDir *vd = data; |
| 9 | 739 GtkTreePath *tpath; |
| 740 GtkTreeIter iter; | |
| 741 FileData *fd = NULL; | |
| 742 | |
| 382 | 743 gtk_tree_view_get_cursor(GTK_TREE_VIEW(vd->view), &tpath, NULL); |
| 9 | 744 if (tpath) |
| 745 { | |
| 746 GtkTreeModel *store; | |
| 747 NodeData *nd; | |
| 748 | |
| 749 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
| 750 gtk_tree_model_get_iter(store, &iter, tpath); | |
| 751 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
| 752 | |
| 753 gtk_tree_path_free(tpath); | |
| 754 | |
| 755 fd = (nd) ? nd->fd : NULL; | |
| 756 } | |
| 757 | |
| 758 switch (event->keyval) | |
| 759 { | |
| 760 case GDK_Menu: | |
| 382 | 761 vd->click_fd = fd; |
|
383
499d7ba62261
Move some dnd common code from view_dir_list.c and view_dir_tree.c
zas_
parents:
382
diff
changeset
|
762 vd_color_set(vd, vd->click_fd, TRUE); |
| 9 | 763 |
|
388
5186f8e38cb8
Make directory view popup menu common and move it to view_dir.{c,h}.
zas_
parents:
384
diff
changeset
|
764 vd->popup = vd_pop_menu(vd, vd->click_fd); |
| 395 | 765 gtk_menu_popup(GTK_MENU(vd->popup), NULL, NULL, vd_menu_position_cb, vd, 0, GDK_CURRENT_TIME); |
| 9 | 766 |
| 767 return TRUE; | |
| 768 break; | |
| 769 case GDK_plus: | |
| 770 case GDK_Right: | |
| 771 case GDK_KP_Add: | |
| 772 if (fd) | |
| 773 { | |
| 783 | 774 vdtree_populate_path_by_iter(vd, &iter, FALSE, vd->dir_fd); |
| 382 | 775 vdtree_icon_set_by_iter(vd, &iter, vd->pf->open); |
| 9 | 776 } |
| 777 break; | |
| 778 } | |
| 779 | |
| 780 return FALSE; | |
| 781 } | |
| 782 | |
| 783 static gint vdtree_clicked_on_expander(GtkTreeView *treeview, GtkTreePath *tpath, | |
| 784 GtkTreeViewColumn *column, gint x, gint y, gint *left_of_expander) | |
| 785 { | |
| 786 gint depth; | |
| 787 gint size; | |
| 788 gint sep; | |
| 789 gint exp_width; | |
| 790 | |
| 791 if (column != gtk_tree_view_get_expander_column(treeview)) return FALSE; | |
| 792 | |
| 793 gtk_widget_style_get(GTK_WIDGET(treeview), "expander-size", &size, "horizontal-separator", &sep, NULL); | |
| 794 depth = gtk_tree_path_get_depth(tpath); | |
| 795 | |
| 796 exp_width = sep + size + sep; | |
| 797 | |
| 798 if (x <= depth * exp_width) | |
| 799 { | |
| 800 if (left_of_expander) *left_of_expander = !(x >= (depth - 1) * exp_width); | |
| 801 return TRUE; | |
| 802 } | |
| 803 | |
| 804 return FALSE; | |
| 805 } | |
| 806 | |
|
401
0a2e1b130a25
Add some wrappers in view_dir.c and simplify even more.
zas_
parents:
397
diff
changeset
|
807 gint vdtree_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) |
| 9 | 808 { |
| 382 | 809 ViewDir *vd = data; |
| 9 | 810 GtkTreePath *tpath; |
| 811 GtkTreeViewColumn *column; | |
| 812 GtkTreeIter iter; | |
| 813 NodeData *nd = NULL; | |
| 814 | |
| 815 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | |
| 816 &tpath, &column, NULL, NULL)) | |
| 817 { | |
| 818 GtkTreeModel *store; | |
| 819 gint left_of_expander; | |
| 820 | |
| 821 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
| 822 gtk_tree_model_get_iter(store, &iter, tpath); | |
| 823 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
| 824 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE); | |
| 825 | |
| 826 if (vdtree_clicked_on_expander(GTK_TREE_VIEW(widget), tpath, column, bevent->x, bevent->y, &left_of_expander)) | |
| 827 { | |
| 382 | 828 vd->click_fd = NULL; |
| 9 | 829 |
| 830 /* clicking this region should automatically reveal an expander, if necessary | |
| 831 * treeview bug: the expander will not expand until a button_motion_event highlights it. | |
| 832 */ | |
|
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
442
diff
changeset
|
833 if (bevent->button == MOUSE_BUTTON_LEFT && |
| 9 | 834 !left_of_expander && |
| 382 | 835 !gtk_tree_view_row_expanded(GTK_TREE_VIEW(vd->view), tpath)) |
| 9 | 836 { |
| 783 | 837 vdtree_populate_path_by_iter(vd, &iter, FALSE, vd->dir_fd); |
| 382 | 838 vdtree_icon_set_by_iter(vd, &iter, vd->pf->open); |
| 9 | 839 } |
| 840 | |
| 841 gtk_tree_path_free(tpath); | |
| 842 return FALSE; | |
| 843 } | |
| 844 | |
| 845 gtk_tree_path_free(tpath); | |
| 846 } | |
| 847 | |
| 382 | 848 vd->click_fd = (nd) ? nd->fd : NULL; |
|
383
499d7ba62261
Move some dnd common code from view_dir_list.c and view_dir_tree.c
zas_
parents:
382
diff
changeset
|
849 vd_color_set(vd, vd->click_fd, TRUE); |
| 9 | 850 |
|
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
442
diff
changeset
|
851 if (bevent->button == MOUSE_BUTTON_RIGHT) |
| 9 | 852 { |
|
388
5186f8e38cb8
Make directory view popup menu common and move it to view_dir.{c,h}.
zas_
parents:
384
diff
changeset
|
853 vd->popup = vd_pop_menu(vd, vd->click_fd); |
| 382 | 854 gtk_menu_popup(GTK_MENU(vd->popup), NULL, NULL, NULL, NULL, |
| 9 | 855 bevent->button, bevent->time); |
| 856 } | |
| 857 | |
|
448
a73cc0fa14d0
Use explicit names for mouse buttons instead of numbers.
zas_
parents:
442
diff
changeset
|
858 return (bevent->button != MOUSE_BUTTON_LEFT); |
| 9 | 859 } |
| 860 | |
| 861 static void vdtree_row_expanded(GtkTreeView *treeview, GtkTreeIter *iter, GtkTreePath *tpath, gpointer data) | |
| 862 { | |
| 382 | 863 ViewDir *vd = data; |
| 9 | 864 |
| 382 | 865 vdtree_populate_path_by_iter(vd, iter, FALSE, NULL); |
| 866 vdtree_icon_set_by_iter(vd, iter, vd->pf->open); | |
| 9 | 867 } |
| 868 | |
| 869 static void vdtree_row_collapsed(GtkTreeView *treeview, GtkTreeIter *iter, GtkTreePath *tpath, gpointer data) | |
| 870 { | |
| 382 | 871 ViewDir *vd = data; |
| 9 | 872 |
| 382 | 873 vdtree_icon_set_by_iter(vd, iter, vd->pf->close); |
| 9 | 874 } |
| 875 | |
| 876 static gint vdtree_sort_cb(GtkTreeModel *store, GtkTreeIter *a, GtkTreeIter *b, gpointer data) | |
| 877 { | |
| 878 NodeData *nda; | |
| 879 NodeData *ndb; | |
| 880 | |
| 881 gtk_tree_model_get(store, a, DIR_COLUMN_POINTER, &nda, -1); | |
| 882 gtk_tree_model_get(store, b, DIR_COLUMN_POINTER, &ndb, -1); | |
| 883 | |
| 785 | 884 if (options->file_sort.case_sensitive) |
| 819 | 885 return strcmp(nda->fd->collate_key_name, ndb->fd->collate_key_name); |
| 785 | 886 else |
| 819 | 887 return strcmp(nda->fd->collate_key_name_nocase, ndb->fd->collate_key_name_nocase); |
| 9 | 888 } |
| 889 | |
| 890 /* | |
| 891 *---------------------------------------------------------------------------- | |
| 892 * core | |
| 893 *---------------------------------------------------------------------------- | |
| 894 */ | |
| 895 | |
| 382 | 896 static void vdtree_setup_root(ViewDir *vd) |
| 9 | 897 { |
| 725 | 898 const gchar *path = G_DIR_SEPARATOR_S; |
| 9 | 899 FileData *fd; |
| 900 | |
| 138 | 901 |
| 902 fd = file_data_new_simple(path); | |
| 382 | 903 vdtree_add_by_data(vd, fd, NULL); |
| 9 | 904 |
| 382 | 905 vdtree_expand_by_data(vd, fd, TRUE); |
| 783 | 906 vdtree_populate_path(vd, fd, FALSE, FALSE); |
| 9 | 907 } |
| 908 | |
| 909 static gboolean vdtree_destroy_node_cb(GtkTreeModel *store, GtkTreePath *tpath, GtkTreeIter *iter, gpointer data) | |
| 910 { | |
| 911 NodeData *nd; | |
| 912 | |
| 913 gtk_tree_model_get(store, iter, DIR_COLUMN_POINTER, &nd, -1); | |
| 914 vdtree_node_free(nd); | |
| 915 | |
| 916 return FALSE; | |
| 917 } | |
| 918 | |
|
401
0a2e1b130a25
Add some wrappers in view_dir.c and simplify even more.
zas_
parents:
397
diff
changeset
|
919 void vdtree_destroy_cb(GtkWidget *widget, gpointer data) |
| 9 | 920 { |
| 382 | 921 ViewDir *vd = data; |
| 9 | 922 GtkTreeModel *store; |
| 923 | |
| 382 | 924 vdtree_dnd_drop_expand_cancel(vd); |
| 394 | 925 vd_dnd_drop_scroll_cancel(vd); |
| 382 | 926 widget_auto_scroll_stop(vd->view); |
| 9 | 927 |
| 382 | 928 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vd->view)); |
| 929 gtk_tree_model_foreach(store, vdtree_destroy_node_cb, vd); | |
| 9 | 930 } |
| 931 | |
| 783 | 932 ViewDir *vdtree_new(ViewDir *vd, FileData *dir_fd) |
| 9 | 933 { |
| 934 GtkTreeStore *store; | |
| 935 GtkTreeSelection *selection; | |
| 936 GtkTreeViewColumn *column; | |
| 937 GtkCellRenderer *renderer; | |
| 938 | |
| 382 | 939 vd->info = g_new0(ViewDirInfoTree, 1); |
| 940 vd->type = DIRVIEW_TREE; | |
| 9 | 941 |
| 382 | 942 VDTREE_INFO(vd, drop_expand_id) = -1; |
| 943 VDTREE_INFO(vd, busy_ref) = 0; | |
| 442 | 944 |
| 407 | 945 vd->dnd_drop_leave_func = vdtree_dnd_drop_expand_cancel; |
| 946 vd->dnd_drop_update_func = vdtree_dnd_drop_expand; | |
| 9 | 947 |
| 948 store = gtk_tree_store_new(4, G_TYPE_POINTER, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_INT); | |
| 382 | 949 vd->view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); |
| 9 | 950 g_object_unref(store); |
| 951 | |
| 382 | 952 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(vd->view), FALSE); |
| 953 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(vd->view), FALSE); | |
| 954 gtk_tree_sortable_set_default_sort_func(GTK_TREE_SORTABLE(store), vdtree_sort_cb, vd, NULL); | |
| 9 | 955 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), |
| 956 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING); | |
| 957 | |
| 382 | 958 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vd->view)); |
| 9 | 959 gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE); |
| 382 | 960 gtk_tree_selection_set_select_function(selection, vdtree_select_cb, vd, NULL); |
| 9 | 961 |
| 962 column = gtk_tree_view_column_new(); | |
| 963 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY); | |
| 964 | |
| 965 renderer = gtk_cell_renderer_pixbuf_new(); | |
| 966 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
| 967 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", DIR_COLUMN_ICON); | |
| 396 | 968 gtk_tree_view_column_set_cell_data_func(column, renderer, vd_color_cb, vd, NULL); |
| 9 | 969 |
| 970 renderer = gtk_cell_renderer_text_new(); | |
| 971 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
| 972 gtk_tree_view_column_add_attribute(column, renderer, "text", DIR_COLUMN_NAME); | |
| 396 | 973 gtk_tree_view_column_set_cell_data_func(column, renderer, vd_color_cb, vd, NULL); |
| 9 | 974 |
| 382 | 975 gtk_tree_view_append_column(GTK_TREE_VIEW(vd->view), column); |
| 9 | 976 |
| 382 | 977 vdtree_setup_root(vd); |
| 9 | 978 |
| 405 | 979 g_signal_connect(G_OBJECT(vd->view), "row_expanded", |
| 980 G_CALLBACK(vdtree_row_expanded), vd); | |
| 981 g_signal_connect(G_OBJECT(vd->view), "row_collapsed", | |
| 982 G_CALLBACK(vdtree_row_collapsed), vd); | |
| 9 | 983 |
| 382 | 984 return vd; |
| 9 | 985 } |
