Mercurial > geeqie
annotate src/view_dir_tree.c @ 135:15c1925b3bfb
improved external delete command
| author | nadvornik |
|---|---|
| date | Thu, 16 Aug 2007 20:57:09 +0000 |
| parents | ee857b4ac902 |
| children | 71e1ebee420e |
| rev | line source |
|---|---|
| 9 | 1 /* |
| 2 * GQview | |
|
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
3 * (C) 2006 John Ellis |
| 9 | 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 | |
| 12 #include "gqview.h" | |
| 13 #include "view_dir_tree.h" | |
| 14 | |
| 15 | |
| 16 #include "dnd.h" | |
| 17 #include "dupe.h" | |
| 18 #include "filelist.h" | |
| 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" | |
| 27 | |
| 28 #include <gdk/gdkkeysyms.h> /* for keyboard values */ | |
| 29 | |
| 30 | |
| 31 #define VDTREE_INDENT 14 | |
| 32 #define VDTREE_PAD 4 | |
| 33 | |
| 34 enum { | |
| 35 DIR_COLUMN_POINTER = 0, | |
| 36 DIR_COLUMN_ICON, | |
| 37 DIR_COLUMN_NAME, | |
| 38 DIR_COLUMN_COLOR, | |
| 39 DIR_COLUMN_COUNT | |
| 40 }; | |
| 41 | |
| 42 | |
| 43 typedef struct _PathData PathData; | |
| 44 struct _PathData | |
| 45 { | |
| 46 gchar *name; | |
| 47 FileData *node; | |
| 48 }; | |
| 49 | |
| 50 typedef struct _NodeData NodeData; | |
| 51 struct _NodeData | |
| 52 { | |
| 53 FileData *fd; | |
| 54 gint expanded; | |
| 55 time_t last_update; | |
| 56 }; | |
| 57 | |
| 58 | |
| 59 static gint vdtree_populate_path_by_iter(ViewDirTree *vdt, GtkTreeIter *iter, gint force, const gchar *target_path); | |
| 60 static FileData *vdtree_populate_path(ViewDirTree *vdt, const gchar *path, gint expand, gint force); | |
| 61 | |
| 62 | |
| 63 /* | |
| 64 *---------------------------------------------------------------------------- | |
| 65 * utils | |
| 66 *---------------------------------------------------------------------------- | |
| 67 */ | |
| 68 | |
| 69 static void set_cursor(GtkWidget *widget, GdkCursorType cursor_type) | |
| 70 { | |
| 71 GdkCursor *cursor = NULL; | |
| 72 | |
| 73 if (!widget || !widget->window) return; | |
| 74 | |
| 75 if (cursor_type > -1) cursor = gdk_cursor_new (cursor_type); | |
| 76 gdk_window_set_cursor (widget->window, cursor); | |
| 77 if (cursor) gdk_cursor_unref(cursor); | |
| 78 gdk_flush(); | |
| 79 } | |
| 80 | |
| 81 static void vdtree_busy_push(ViewDirTree *vdt) | |
| 82 { | |
| 83 if (vdt->busy_ref == 0) set_cursor(vdt->treeview, GDK_WATCH); | |
| 84 vdt->busy_ref++; | |
| 85 } | |
| 86 | |
| 87 static void vdtree_busy_pop(ViewDirTree *vdt) | |
| 88 { | |
| 89 if (vdt->busy_ref == 1) set_cursor(vdt->treeview, -1); | |
| 90 if (vdt->busy_ref > 0) vdt->busy_ref--; | |
| 91 } | |
| 92 | |
| 93 static gint vdtree_find_row(ViewDirTree *vdt, FileData *fd, GtkTreeIter *iter, GtkTreeIter *parent) | |
| 94 { | |
| 95 GtkTreeModel *store; | |
| 96 gint valid; | |
| 97 | |
| 98 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
| 99 if (parent) | |
| 100 { | |
| 101 valid = gtk_tree_model_iter_children(store, iter, parent); | |
| 102 } | |
| 103 else | |
| 104 { | |
| 105 valid = gtk_tree_model_get_iter_first(store, iter); | |
| 106 } | |
| 107 while (valid) | |
| 108 { | |
| 109 NodeData *nd; | |
| 110 GtkTreeIter found; | |
| 111 | |
| 112 gtk_tree_model_get(GTK_TREE_MODEL(store), iter, DIR_COLUMN_POINTER, &nd, -1); | |
| 113 if (nd->fd == fd) return TRUE; | |
| 114 | |
| 115 if (vdtree_find_row(vdt, fd, &found, iter)) | |
| 116 { | |
| 117 memcpy(iter, &found, sizeof(found)); | |
| 118 return TRUE; | |
| 119 } | |
| 120 | |
| 121 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), iter); | |
| 122 } | |
| 123 | |
| 124 return FALSE; | |
| 125 } | |
| 126 | |
| 127 static void vdtree_icon_set_by_iter(ViewDirTree *vdt, GtkTreeIter *iter, GdkPixbuf *pixbuf) | |
| 128 { | |
| 129 GtkTreeModel *store; | |
| 130 GdkPixbuf *old; | |
| 131 | |
| 132 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
| 133 gtk_tree_model_get(store, iter, DIR_COLUMN_ICON, &old, -1); | |
| 134 if (old != vdt->pf->deny) | |
| 135 { | |
| 136 gtk_tree_store_set(GTK_TREE_STORE(store), iter, DIR_COLUMN_ICON, pixbuf, -1); | |
| 137 } | |
| 138 } | |
| 139 | |
| 140 static void vdtree_expand_by_iter(ViewDirTree *vdt, GtkTreeIter *iter, gint expand) | |
| 141 { | |
| 142 GtkTreeModel *store; | |
| 143 GtkTreePath *tpath; | |
| 144 | |
| 145 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
| 146 tpath = gtk_tree_model_get_path(store, iter); | |
| 147 if (expand) | |
| 148 { | |
| 149 gtk_tree_view_expand_row(GTK_TREE_VIEW(vdt->treeview), tpath, FALSE); | |
| 150 vdtree_icon_set_by_iter(vdt, iter, vdt->pf->open); | |
| 151 } | |
| 152 else | |
| 153 { | |
| 154 gtk_tree_view_collapse_row(GTK_TREE_VIEW(vdt->treeview), tpath); | |
| 155 } | |
| 156 gtk_tree_path_free(tpath); | |
| 157 } | |
| 158 | |
| 159 static void vdtree_expand_by_data(ViewDirTree *vdt, FileData *fd, gint expand) | |
| 160 { | |
| 161 GtkTreeIter iter; | |
| 162 | |
| 163 if (vdtree_find_row(vdt, fd, &iter, NULL)) | |
| 164 { | |
| 165 vdtree_expand_by_iter(vdt, &iter, expand); | |
| 166 } | |
| 167 } | |
| 168 | |
| 169 static void vdtree_color_set(ViewDirTree *vdt, FileData *fd, gint color_set) | |
| 170 { | |
| 171 GtkTreeModel *store; | |
| 172 GtkTreeIter iter; | |
| 173 | |
| 174 if (!vdtree_find_row(vdt, fd, &iter, NULL)) return; | |
| 175 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
| 176 gtk_tree_store_set(GTK_TREE_STORE(store), &iter, DIR_COLUMN_COLOR, color_set, -1); | |
| 177 } | |
| 178 | |
| 179 static gint vdtree_rename_row_cb(TreeEditData *td, const gchar *old, const gchar *new, gpointer data) | |
| 180 { | |
| 181 ViewDirTree *vdt = data; | |
| 182 GtkTreeModel *store; | |
| 183 GtkTreeIter iter; | |
| 184 NodeData *nd; | |
| 185 gchar *old_path; | |
| 186 gchar *new_path; | |
| 187 gchar *base; | |
| 188 | |
| 189 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
| 190 if (!gtk_tree_model_get_iter(store, &iter, td->path)) return FALSE; | |
| 191 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
| 192 if (!nd) return FALSE; | |
| 193 | |
| 194 old_path = g_strdup(nd->fd->path); | |
| 195 | |
| 196 base = remove_level_from_path(old_path); | |
| 197 new_path = concat_dir_and_file(base, new); | |
| 198 g_free(base); | |
| 199 | |
|
44
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
25
diff
changeset
|
200 if (file_util_rename_dir(old_path, new_path, vdt->treeview)) |
| 9 | 201 { |
| 202 vdtree_populate_path(vdt, new_path, TRUE, TRUE); | |
| 203 | |
| 204 if (vdt->layout && strcmp(vdt->path, old_path) == 0) | |
| 205 { | |
| 206 layout_set_path(vdt->layout, new_path); | |
| 207 } | |
| 208 } | |
| 209 | |
| 210 g_free(old_path); | |
| 211 g_free(new_path); | |
| 212 | |
| 213 return FALSE; | |
| 214 } | |
| 215 | |
| 216 static void vdtree_rename_by_data(ViewDirTree *vdt, FileData *fd) | |
| 217 { | |
| 218 GtkTreeModel *store; | |
| 219 GtkTreePath *tpath; | |
| 220 GtkTreeIter iter; | |
| 221 | |
| 222 if (!fd || | |
| 223 !vdtree_find_row(vdt, fd, &iter, NULL)) return; | |
| 224 | |
| 225 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
| 226 tpath = gtk_tree_model_get_path(store, &iter); | |
| 227 | |
| 228 tree_edit_by_path(GTK_TREE_VIEW(vdt->treeview), tpath, 0, fd->name, | |
| 229 vdtree_rename_row_cb, vdt); | |
| 230 gtk_tree_path_free(tpath); | |
| 231 } | |
| 232 | |
| 233 static void vdtree_node_free(NodeData *nd) | |
| 234 { | |
| 235 if (!nd) return; | |
| 236 | |
| 237 file_data_free(nd->fd); | |
| 238 g_free(nd); | |
| 239 } | |
| 240 | |
| 241 static void vdtree_popup_destroy_cb(GtkWidget *widget, gpointer data) | |
| 242 { | |
| 243 ViewDirTree *vdt = data; | |
| 244 | |
| 245 vdtree_color_set(vdt, vdt->click_fd, FALSE); | |
| 246 vdt->click_fd = NULL; | |
| 247 vdt->popup = NULL; | |
| 248 | |
| 249 vdtree_color_set(vdt, vdt->drop_fd, FALSE); | |
| 250 path_list_free(vdt->drop_list); | |
| 251 vdt->drop_list = NULL; | |
| 252 vdt->drop_fd = NULL; | |
| 253 } | |
| 254 | |
| 255 /* | |
| 256 *----------------------------------------------------------------------------- | |
| 257 * drop menu (from dnd) | |
| 258 *----------------------------------------------------------------------------- | |
| 259 */ | |
| 260 | |
| 261 static void vdtree_drop_menu_copy_cb(GtkWidget *widget, gpointer data) | |
| 262 { | |
| 263 ViewDirTree *vdt = data; | |
| 264 const gchar *path; | |
| 265 GList *list; | |
| 266 | |
| 267 if (!vdt->drop_fd) return; | |
| 268 | |
| 269 path = vdt->drop_fd->path; | |
| 270 list = vdt->drop_list; | |
| 271 | |
| 272 vdt->drop_list = NULL; | |
| 273 | |
| 274 file_util_copy_simple(list, path); | |
| 275 } | |
| 276 | |
| 277 static void vdtree_drop_menu_move_cb(GtkWidget *widget, gpointer data) | |
| 278 { | |
| 279 ViewDirTree *vdt = data; | |
| 280 const gchar *path; | |
| 281 GList *list; | |
| 282 | |
| 283 if (!vdt->drop_fd) return; | |
| 284 | |
| 285 path = vdt->drop_fd->path; | |
| 286 list = vdt->drop_list; | |
| 287 | |
| 288 vdt->drop_list = NULL; | |
| 289 | |
| 290 file_util_move_simple(list, path); | |
| 291 } | |
| 292 | |
| 293 static GtkWidget *vdtree_drop_menu(ViewDirTree *vdt, gint active) | |
| 294 { | |
| 295 GtkWidget *menu; | |
| 296 | |
| 297 menu = popup_menu_short_lived(); | |
| 298 g_signal_connect(G_OBJECT(menu), "destroy", | |
| 299 G_CALLBACK(vdtree_popup_destroy_cb), vdt); | |
| 300 | |
| 301 menu_item_add_stock_sensitive(menu, _("_Copy"), GTK_STOCK_COPY, active, | |
| 302 G_CALLBACK(vdtree_drop_menu_copy_cb), vdt); | |
| 303 menu_item_add_sensitive(menu, _("_Move"), active, G_CALLBACK(vdtree_drop_menu_move_cb), vdt); | |
| 304 | |
| 305 menu_item_add_divider(menu); | |
| 306 menu_item_add_stock(menu, _("Cancel"), GTK_STOCK_CANCEL, NULL, vdt); | |
| 307 | |
| 308 return menu; | |
| 309 } | |
| 310 | |
| 311 /* | |
| 312 *----------------------------------------------------------------------------- | |
| 313 * pop-up menu | |
| 314 *----------------------------------------------------------------------------- | |
| 315 */ | |
| 316 | |
| 317 static void vdtree_pop_menu_up_cb(GtkWidget *widget, gpointer data) | |
| 318 { | |
| 319 ViewDirTree *vdt = data; | |
| 320 gchar *path; | |
| 321 | |
| 322 if (!vdt->path || strcmp(vdt->path, "/") == 0) return; | |
| 323 path = remove_level_from_path(vdt->path); | |
| 324 | |
| 325 if (vdt->select_func) | |
| 326 { | |
| 327 vdt->select_func(vdt, path, vdt->select_data); | |
| 328 } | |
| 329 | |
| 330 g_free(path); | |
| 331 } | |
| 332 | |
| 333 static void vdtree_pop_menu_slide_cb(GtkWidget *widget, gpointer data) | |
| 334 { | |
| 335 ViewDirTree *vdt = data; | |
| 336 gchar *path; | |
| 337 | |
| 338 if (!vdt->layout) return; | |
| 339 | |
| 340 if (!vdt->click_fd) return; | |
| 341 path = g_strdup(vdt->click_fd->path); | |
| 342 | |
| 343 layout_set_path(vdt->layout, path); | |
| 344 layout_select_none(vdt->layout); | |
| 345 layout_image_slideshow_stop(vdt->layout); | |
| 346 layout_image_slideshow_start(vdt->layout); | |
| 347 | |
| 348 g_free(path); | |
| 349 } | |
| 350 | |
| 351 static void vdtree_pop_menu_slide_rec_cb(GtkWidget *widget, gpointer data) | |
| 352 { | |
| 353 ViewDirTree *vdt = data; | |
| 354 gchar *path; | |
| 355 GList *list; | |
| 356 | |
| 357 if (!vdt->layout) return; | |
| 358 | |
| 359 if (!vdt->click_fd) return; | |
| 360 path = g_strdup(vdt->click_fd->path); | |
| 361 | |
| 362 list = path_list_recursive(path); | |
| 363 | |
| 364 layout_image_slideshow_stop(vdt->layout); | |
| 365 layout_image_slideshow_start_from_list(vdt->layout, list); | |
| 366 | |
| 367 g_free(path); | |
| 368 } | |
| 369 | |
| 370 static void vdtree_pop_menu_dupe(ViewDirTree *vdt, gint recursive) | |
| 371 { | |
| 372 DupeWindow *dw; | |
| 373 const gchar *path; | |
| 374 GList *list = NULL; | |
| 375 | |
| 376 if (!vdt->click_fd) return; | |
| 377 path = vdt->click_fd->path; | |
| 378 | |
| 379 if (recursive) | |
| 380 { | |
| 381 list = g_list_append(list, g_strdup(path)); | |
| 382 } | |
| 383 else | |
| 384 { | |
| 385 path_list(path, &list, NULL); | |
| 386 list = path_list_filter(list, FALSE); | |
| 387 } | |
| 388 | |
| 389 dw = dupe_window_new(DUPE_MATCH_NAME); | |
| 390 dupe_window_add_files(dw, list, recursive); | |
| 391 | |
| 392 path_list_free(list); | |
| 393 } | |
| 394 | |
| 395 static void vdtree_pop_menu_dupe_cb(GtkWidget *widget, gpointer data) | |
| 396 { | |
| 397 ViewDirTree *vdt = data; | |
| 398 vdtree_pop_menu_dupe(vdt, FALSE); | |
| 399 } | |
| 400 | |
| 401 static void vdtree_pop_menu_dupe_rec_cb(GtkWidget *widget, gpointer data) | |
| 402 { | |
| 403 ViewDirTree *vdt = data; | |
| 404 vdtree_pop_menu_dupe(vdt, TRUE); | |
| 405 } | |
| 406 | |
| 407 static void vdtree_pop_menu_new_cb(GtkWidget *widget, gpointer data) | |
| 408 { | |
| 409 ViewDirTree *vdt = data; | |
| 410 const gchar *path; | |
| 411 gchar *new_path; | |
| 412 gchar *buf; | |
| 413 | |
| 414 if (!vdt->click_fd) return; | |
| 415 path = vdt->click_fd->path; | |
| 416 | |
| 417 buf = concat_dir_and_file(path, _("new_folder")); | |
| 418 new_path = unique_filename(buf, NULL, NULL, FALSE); | |
| 419 g_free(buf); | |
| 420 if (!new_path) return; | |
| 421 | |
| 422 if (!mkdir_utf8(new_path, 0755)) | |
| 423 { | |
| 424 gchar *text; | |
| 425 | |
| 426 text = g_strdup_printf(_("Unable to create folder:\n%s"), new_path); | |
| 427 file_util_warning_dialog(_("Error creating folder"), text, GTK_STOCK_DIALOG_ERROR, vdt->treeview); | |
| 428 g_free(text); | |
| 429 } | |
| 430 else | |
| 431 { | |
| 432 FileData *fd; | |
| 433 | |
| 434 fd = vdtree_populate_path(vdt, new_path, TRUE, TRUE); | |
| 435 | |
| 436 vdtree_rename_by_data(vdt, fd); | |
| 437 } | |
| 438 | |
| 439 g_free(new_path); | |
| 440 } | |
| 441 | |
| 442 static void vdtree_pop_menu_rename_cb(GtkWidget *widget, gpointer data) | |
| 443 { | |
| 444 ViewDirTree *vdt = data; | |
| 445 | |
| 446 vdtree_rename_by_data(vdt, vdt->click_fd); | |
| 447 } | |
| 448 | |
|
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
449 static void vdtree_pop_menu_delete_cb(GtkWidget *widget, gpointer data) |
|
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
450 { |
|
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
451 ViewDirTree *vdt = data; |
|
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
452 |
|
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
453 if (!vdt->click_fd) return; |
|
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
454 file_util_delete_dir(vdt->click_fd->path, vdt->widget); |
|
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
455 } |
|
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
456 |
| 9 | 457 static void vdtree_pop_menu_tree_cb(GtkWidget *widget, gpointer data) |
| 458 { | |
| 459 ViewDirTree *vdt = data; | |
| 460 | |
| 461 if (vdt->layout) layout_views_set(vdt->layout, FALSE, vdt->layout->icon_view); | |
| 462 } | |
| 463 | |
| 464 static void vdtree_pop_menu_refresh_cb(GtkWidget *widget, gpointer data) | |
| 465 { | |
| 466 ViewDirTree *vdt = data; | |
| 467 | |
| 468 if (vdt->layout) layout_refresh(vdt->layout); | |
| 469 } | |
| 470 | |
| 471 static GtkWidget *vdtree_pop_menu(ViewDirTree *vdt, FileData *fd) | |
| 472 { | |
| 473 GtkWidget *menu; | |
| 474 gint active; | |
|
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
475 gint parent_active = FALSE; |
| 9 | 476 |
| 477 active = (fd != NULL); | |
|
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
478 if (fd) |
|
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
479 { |
|
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
480 gchar *parent; |
|
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
481 |
|
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
482 parent = remove_level_from_path(fd->path); |
|
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
483 parent_active = access_file(parent, W_OK | X_OK); |
|
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
484 g_free(parent); |
|
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
485 } |
| 9 | 486 |
| 487 menu = popup_menu_short_lived(); | |
| 488 g_signal_connect(G_OBJECT(menu), "destroy", | |
| 489 G_CALLBACK(vdtree_popup_destroy_cb), vdt); | |
| 490 | |
| 491 menu_item_add_stock_sensitive(menu, _("_Up to parent"), GTK_STOCK_GO_UP, | |
| 492 (vdt->path && strcmp(vdt->path, "/") != 0), | |
| 493 G_CALLBACK(vdtree_pop_menu_up_cb), vdt); | |
| 494 | |
| 495 menu_item_add_divider(menu); | |
| 496 menu_item_add_sensitive(menu, _("_Slideshow"), active, | |
| 497 G_CALLBACK(vdtree_pop_menu_slide_cb), vdt); | |
| 498 menu_item_add_sensitive(menu, _("Slideshow recursive"), active, | |
| 499 G_CALLBACK(vdtree_pop_menu_slide_rec_cb), vdt); | |
| 500 | |
| 501 menu_item_add_divider(menu); | |
| 502 menu_item_add_stock_sensitive(menu, _("Find _duplicates..."), GTK_STOCK_FIND, active, | |
| 503 G_CALLBACK(vdtree_pop_menu_dupe_cb), vdt); | |
| 504 menu_item_add_stock_sensitive(menu, _("Find duplicates recursive..."), GTK_STOCK_FIND, active, | |
| 505 G_CALLBACK(vdtree_pop_menu_dupe_rec_cb), vdt); | |
| 506 | |
| 507 menu_item_add_divider(menu); | |
| 508 | |
| 509 active = (fd && | |
| 510 access_file(fd->path, W_OK | X_OK)); | |
| 511 menu_item_add_sensitive(menu, _("_New folder..."), active, | |
| 512 G_CALLBACK(vdtree_pop_menu_new_cb), vdt); | |
| 513 | |
|
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
514 menu_item_add_sensitive(menu, _("_Rename..."), parent_active, |
| 9 | 515 G_CALLBACK(vdtree_pop_menu_rename_cb), vdt); |
|
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
516 menu_item_add_stock_sensitive(menu, _("_Delete..."), GTK_STOCK_DELETE, parent_active, |
|
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
517 G_CALLBACK(vdtree_pop_menu_delete_cb), vdt); |
| 9 | 518 |
| 519 menu_item_add_divider(menu); | |
| 520 menu_item_add_check(menu, _("View as _tree"), TRUE, | |
| 521 G_CALLBACK(vdtree_pop_menu_tree_cb), vdt); | |
| 522 menu_item_add_stock(menu, _("Re_fresh"), GTK_STOCK_REFRESH, | |
| 523 G_CALLBACK(vdtree_pop_menu_refresh_cb), vdt); | |
| 524 | |
| 525 return menu; | |
| 526 } | |
| 527 | |
| 528 /* | |
| 529 *---------------------------------------------------------------------------- | |
| 530 * dnd | |
| 531 *---------------------------------------------------------------------------- | |
| 532 */ | |
| 533 | |
| 534 static GtkTargetEntry vdtree_dnd_drop_types[] = { | |
| 535 { "text/uri-list", 0, TARGET_URI_LIST } | |
| 536 }; | |
| 537 static gint vdtree_dnd_drop_types_count = 1; | |
| 538 | |
| 539 | |
| 540 static void vdtree_dest_set(ViewDirTree *vdt, gint enable) | |
| 541 { | |
| 542 if (enable) | |
| 543 { | |
| 544 gtk_drag_dest_set(vdt->treeview, | |
| 545 GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP, | |
| 546 vdtree_dnd_drop_types, vdtree_dnd_drop_types_count, | |
| 547 GDK_ACTION_MOVE | GDK_ACTION_COPY); | |
| 548 } | |
| 549 else | |
| 550 { | |
| 551 gtk_drag_dest_unset(vdt->treeview); | |
| 552 } | |
| 553 } | |
| 554 | |
| 555 static void vdtree_dnd_get(GtkWidget *widget, GdkDragContext *context, | |
| 556 GtkSelectionData *selection_data, guint info, | |
| 557 guint time, gpointer data) | |
| 558 { | |
| 559 ViewDirTree *vdt = data; | |
| 560 gchar *path; | |
| 561 GList *list; | |
| 562 gchar *uri_text = NULL; | |
| 563 gint length = 0; | |
| 564 | |
| 565 if (!vdt->click_fd) return; | |
| 566 path = vdt->click_fd->path; | |
| 567 | |
| 568 switch (info) | |
| 569 { | |
| 570 case TARGET_URI_LIST: | |
| 571 case TARGET_TEXT_PLAIN: | |
| 572 list = g_list_prepend(NULL, path); | |
| 573 uri_text = uri_text_from_list(list, &length, (info == TARGET_TEXT_PLAIN)); | |
| 574 g_list_free(list); | |
| 575 break; | |
| 576 } | |
| 577 | |
| 578 if (uri_text) | |
| 579 { | |
| 580 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:
63
diff
changeset
|
581 8, (guchar *)uri_text, length); |
| 9 | 582 g_free(uri_text); |
| 583 } | |
| 584 } | |
| 585 | |
| 586 static void vdtree_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data) | |
| 587 { | |
| 588 ViewDirTree *vdt = data; | |
| 589 | |
| 590 vdtree_color_set(vdt, vdt->click_fd, TRUE); | |
| 591 vdtree_dest_set(vdt, FALSE); | |
| 592 } | |
| 593 | |
| 594 static void vdtree_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data) | |
| 595 { | |
| 596 ViewDirTree *vdt = data; | |
| 597 | |
| 598 vdtree_color_set(vdt, vdt->click_fd, FALSE); | |
| 599 vdtree_dest_set(vdt, TRUE); | |
| 600 } | |
| 601 | |
| 602 static void vdtree_dnd_drop_receive(GtkWidget *widget, | |
| 603 GdkDragContext *context, gint x, gint y, | |
| 604 GtkSelectionData *selection_data, guint info, | |
| 605 guint time, gpointer data) | |
| 606 { | |
| 607 ViewDirTree *vdt = data; | |
| 608 GtkTreePath *tpath; | |
| 609 GtkTreeIter iter; | |
| 610 FileData *fd = NULL; | |
| 611 | |
| 612 vdt->click_fd = NULL; | |
| 613 | |
| 614 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), x, y, | |
| 615 &tpath, NULL, NULL, NULL)) | |
| 616 { | |
| 617 GtkTreeModel *store; | |
| 618 NodeData *nd; | |
| 619 | |
| 620 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
| 621 gtk_tree_model_get_iter(store, &iter, tpath); | |
| 622 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
| 623 gtk_tree_path_free(tpath); | |
| 624 | |
| 625 fd = (nd) ? nd->fd : NULL; | |
| 626 } | |
| 627 | |
| 628 if (!fd) return; | |
| 629 | |
| 630 if (info == TARGET_URI_LIST) | |
| 631 { | |
| 632 GList *list; | |
| 633 gint active; | |
| 634 | |
|
64
04ff0df3ad2f
Mon Aug 15 17:13:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
63
diff
changeset
|
635 list = uri_list_from_text((gchar *)selection_data->data, TRUE); |
| 9 | 636 if (!list) return; |
| 637 | |
| 638 active = access_file(fd->path, W_OK | X_OK); | |
| 639 | |
| 640 vdtree_color_set(vdt, fd, TRUE); | |
| 641 vdt->popup = vdtree_drop_menu(vdt, active); | |
| 642 gtk_menu_popup(GTK_MENU(vdt->popup), NULL, NULL, NULL, NULL, 0, time); | |
| 643 | |
| 644 vdt->drop_fd = fd; | |
| 645 vdt->drop_list = list; | |
| 646 } | |
| 647 } | |
| 648 | |
| 649 static gint vdtree_dnd_drop_expand_cb(gpointer data) | |
| 650 { | |
| 651 ViewDirTree *vdt = data; | |
| 652 GtkTreeIter iter; | |
| 653 | |
| 654 if (vdt->drop_fd && | |
| 655 vdtree_find_row(vdt, vdt->drop_fd, &iter, NULL)) | |
| 656 { | |
| 657 vdtree_populate_path_by_iter(vdt, &iter, FALSE, vdt->path); | |
| 658 vdtree_expand_by_data(vdt, vdt->drop_fd, TRUE); | |
| 659 } | |
| 660 | |
| 661 vdt->drop_expand_id = -1; | |
| 662 return FALSE; | |
| 663 } | |
| 664 | |
| 665 static void vdtree_dnd_drop_expand_cancel(ViewDirTree *vdt) | |
| 666 { | |
| 667 if (vdt->drop_expand_id != -1) g_source_remove(vdt->drop_expand_id); | |
| 668 vdt->drop_expand_id = -1; | |
| 669 } | |
| 670 | |
| 671 static void vdtree_dnd_drop_expand(ViewDirTree *vdt) | |
| 672 { | |
| 673 vdtree_dnd_drop_expand_cancel(vdt); | |
| 674 vdt->drop_expand_id = g_timeout_add(1000, vdtree_dnd_drop_expand_cb, vdt); | |
| 675 } | |
| 676 | |
| 677 static void vdtree_drop_update(ViewDirTree *vdt, gint x, gint y) | |
| 678 { | |
| 679 GtkTreePath *tpath; | |
| 680 GtkTreeIter iter; | |
| 681 FileData *fd = NULL; | |
| 682 | |
| 683 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vdt->treeview), x, y, | |
| 684 &tpath, NULL, NULL, NULL)) | |
| 685 { | |
| 686 GtkTreeModel *store; | |
| 687 NodeData *nd; | |
| 688 | |
| 689 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
| 690 gtk_tree_model_get_iter(store, &iter, tpath); | |
| 691 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
| 692 gtk_tree_path_free(tpath); | |
| 693 | |
| 694 fd = (nd) ? nd->fd : NULL; | |
| 695 } | |
| 696 | |
| 697 if (fd != vdt->drop_fd) | |
| 698 { | |
| 699 vdtree_color_set(vdt, vdt->drop_fd, FALSE); | |
| 700 vdtree_color_set(vdt, fd, TRUE); | |
| 701 if (fd) vdtree_dnd_drop_expand(vdt); | |
| 702 } | |
| 703 | |
| 704 vdt->drop_fd = fd; | |
| 705 } | |
| 706 | |
| 707 static void vdtree_dnd_drop_scroll_cancel(ViewDirTree *vdt) | |
| 708 { | |
| 709 if (vdt->drop_scroll_id != -1) g_source_remove(vdt->drop_scroll_id); | |
| 710 vdt->drop_scroll_id = -1; | |
| 711 } | |
| 712 | |
| 713 static gint vdtree_auto_scroll_idle_cb(gpointer data) | |
| 714 { | |
| 715 ViewDirTree *vdt = data; | |
| 716 | |
| 717 if (vdt->drop_fd) | |
| 718 { | |
| 719 GdkWindow *window; | |
| 720 gint x, y; | |
| 721 gint w, h; | |
| 722 | |
| 723 window = vdt->treeview->window; | |
| 724 gdk_window_get_pointer(window, &x, &y, NULL); | |
| 725 gdk_drawable_get_size(window, &w, &h); | |
| 726 if (x >= 0 && x < w && y >= 0 && y < h) | |
| 727 { | |
| 728 vdtree_drop_update(vdt, x, y); | |
| 729 } | |
| 730 } | |
| 731 | |
| 732 vdt->drop_scroll_id = -1; | |
| 733 return FALSE; | |
| 734 } | |
| 735 | |
| 736 static gint vdtree_auto_scroll_notify_cb(GtkWidget *widget, gint x, gint y, gpointer data) | |
| 737 { | |
| 738 ViewDirTree *vdt = data; | |
| 739 | |
| 740 if (!vdt->drop_fd || vdt->drop_list) return FALSE; | |
| 741 | |
| 742 if (vdt->drop_scroll_id == -1) vdt->drop_scroll_id = g_idle_add(vdtree_auto_scroll_idle_cb, vdt); | |
| 743 | |
| 744 return TRUE; | |
| 745 } | |
| 746 | |
| 747 static gint vdtree_dnd_drop_motion(GtkWidget *widget, GdkDragContext *context, | |
| 748 gint x, gint y, guint time, gpointer data) | |
| 749 { | |
| 750 ViewDirTree *vdt = data; | |
| 751 | |
| 752 vdt->click_fd = NULL; | |
| 753 | |
| 754 if (gtk_drag_get_source_widget(context) == vdt->treeview) | |
| 755 { | |
| 756 gdk_drag_status(context, 0, time); | |
| 757 return TRUE; | |
| 758 } | |
| 759 else | |
| 760 { | |
| 761 gdk_drag_status(context, context->suggested_action, time); | |
| 762 } | |
| 763 | |
| 764 vdtree_drop_update(vdt, x, y); | |
| 765 | |
| 766 if (vdt->drop_fd) | |
| 767 { | |
| 768 GtkAdjustment *adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(vdt->treeview)); | |
| 769 widget_auto_scroll_start(vdt->treeview, adj, -1, -1, vdtree_auto_scroll_notify_cb, vdt); | |
| 770 } | |
| 771 | |
| 772 return FALSE; | |
| 773 } | |
| 774 | |
| 775 static void vdtree_dnd_drop_leave(GtkWidget *widget, GdkDragContext *context, guint time, gpointer data) | |
| 776 { | |
| 777 ViewDirTree *vdt = data; | |
| 778 | |
| 779 if (vdt->drop_fd != vdt->click_fd) vdtree_color_set(vdt, vdt->drop_fd, FALSE); | |
| 780 | |
| 781 vdt->drop_fd = NULL; | |
| 782 | |
| 783 vdtree_dnd_drop_expand_cancel(vdt); | |
| 784 } | |
| 785 | |
| 786 static void vdtree_dnd_init(ViewDirTree *vdt) | |
| 787 { | |
| 788 gtk_drag_source_set(vdt->treeview, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, | |
| 789 dnd_file_drag_types, dnd_file_drag_types_count, | |
| 790 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_ASK); | |
| 791 g_signal_connect(G_OBJECT(vdt->treeview), "drag_data_get", | |
| 792 G_CALLBACK(vdtree_dnd_get), vdt); | |
| 793 g_signal_connect(G_OBJECT(vdt->treeview), "drag_begin", | |
| 794 G_CALLBACK(vdtree_dnd_begin), vdt); | |
| 795 g_signal_connect(G_OBJECT(vdt->treeview), "drag_end", | |
| 796 G_CALLBACK(vdtree_dnd_end), vdt); | |
| 797 | |
| 798 vdtree_dest_set(vdt, TRUE); | |
| 799 g_signal_connect(G_OBJECT(vdt->treeview), "drag_data_received", | |
| 800 G_CALLBACK(vdtree_dnd_drop_receive), vdt); | |
| 801 g_signal_connect(G_OBJECT(vdt->treeview), "drag_motion", | |
| 802 G_CALLBACK(vdtree_dnd_drop_motion), vdt); | |
| 803 g_signal_connect(G_OBJECT(vdt->treeview), "drag_leave", | |
| 804 G_CALLBACK(vdtree_dnd_drop_leave), vdt); | |
| 805 } | |
| 806 | |
| 807 /* | |
| 808 *---------------------------------------------------------------------------- | |
| 809 * parts lists | |
| 810 *---------------------------------------------------------------------------- | |
| 811 */ | |
| 812 | |
| 813 static GList *parts_list(const gchar *path) | |
| 814 { | |
| 815 GList *list = NULL; | |
| 816 const gchar *strb, *strp; | |
| 817 gint l; | |
| 818 | |
| 819 strp = path; | |
| 820 | |
| 821 if (*strp != '/') return NULL; | |
| 822 | |
| 823 strp++; | |
| 824 strb = strp; | |
| 825 l = 0; | |
| 826 | |
| 827 while (*strp != '\0') | |
| 828 { | |
| 829 if (*strp == '/') | |
| 830 { | |
| 831 if (l > 0) list = g_list_prepend(list, g_strndup(strb, l)); | |
| 832 strp++; | |
| 833 strb = strp; | |
| 834 l = 0; | |
| 835 } | |
| 836 else | |
| 837 { | |
| 838 strp++; | |
| 839 l++; | |
| 840 } | |
| 841 } | |
| 842 if (l > 0) list = g_list_prepend(list, g_strndup(strb, l)); | |
| 843 | |
| 844 list = g_list_reverse(list); | |
| 845 | |
| 846 list = g_list_prepend(list, g_strdup("/")); | |
| 847 | |
| 848 return list; | |
| 849 } | |
| 850 | |
| 851 static void parts_list_free(GList *list) | |
| 852 { | |
| 853 GList *work = list; | |
| 854 while (work) | |
| 855 { | |
| 856 PathData *pd = work->data; | |
| 857 g_free(pd->name); | |
| 858 g_free(pd); | |
| 859 work = work->next; | |
| 860 } | |
| 861 | |
| 862 g_list_free(list); | |
| 863 } | |
| 864 | |
| 865 static GList *parts_list_add_node_points(ViewDirTree *vdt, GList *list) | |
| 866 { | |
| 867 GList *work; | |
| 868 GtkTreeModel *store; | |
| 869 GtkTreeIter iter; | |
| 870 gint valid; | |
| 871 | |
| 872 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
| 873 valid = gtk_tree_model_get_iter_first(store, &iter); | |
| 874 | |
| 875 work = list; | |
| 876 while (work) | |
| 877 { | |
| 878 PathData *pd; | |
| 879 FileData *fd = NULL; | |
| 880 | |
| 881 pd = g_new0(PathData, 1); | |
| 882 pd->name = work->data; | |
| 883 | |
| 884 while (valid && !fd) | |
| 885 { | |
| 886 NodeData *nd; | |
| 887 | |
| 888 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
| 889 if (strcmp(nd->fd->name, pd->name) == 0) | |
| 890 { | |
| 891 fd = nd->fd; | |
| 892 } | |
| 893 else | |
| 894 { | |
| 895 valid = gtk_tree_model_iter_next(store, &iter); | |
| 896 } | |
| 897 } | |
| 898 | |
| 899 pd->node = fd; | |
| 900 work->data = pd; | |
| 901 | |
| 902 if (fd) | |
| 903 { | |
| 904 GtkTreeIter parent; | |
| 905 memcpy(&parent, &iter, sizeof(parent)); | |
| 906 valid = gtk_tree_model_iter_children(store, &iter, &parent); | |
| 907 } | |
| 908 | |
| 909 work = work->next; | |
| 910 } | |
| 911 | |
| 912 return list; | |
| 913 } | |
| 914 | |
| 915 /* | |
| 916 *---------------------------------------------------------------------------- | |
| 917 * misc | |
| 918 *---------------------------------------------------------------------------- | |
| 919 */ | |
| 920 | |
| 921 #if 0 | |
| 922 static void vdtree_row_deleted_cb(GtkTreeModel *tree_model, GtkTreePath *tpath, gpointer data) | |
| 923 { | |
| 924 GtkTreeIter iter; | |
| 925 NodeData *nd; | |
| 926 | |
| 927 gtk_tree_model_get_iter(tree_model, &iter, tpath); | |
| 928 gtk_tree_model_get(tree_model, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
| 929 | |
| 930 if (!nd) return; | |
| 931 | |
| 932 file_data_free(nd->fd); | |
| 933 g_free(nd); | |
| 934 } | |
| 935 #endif | |
| 936 | |
| 937 /* | |
| 938 *---------------------------------------------------------------------------- | |
| 939 * node traversal, management | |
| 940 *---------------------------------------------------------------------------- | |
| 941 */ | |
| 942 | |
| 943 static gint vdtree_find_iter_by_data(ViewDirTree *vdt, GtkTreeIter *parent, NodeData *nd, GtkTreeIter *iter) | |
| 944 { | |
| 945 GtkTreeModel *store; | |
| 946 | |
| 947 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
| 948 if (!nd || !gtk_tree_model_iter_children(store, iter, parent)) return -1; | |
| 949 do { | |
| 950 NodeData *cnd; | |
| 951 | |
| 952 gtk_tree_model_get(store, iter, DIR_COLUMN_POINTER, &cnd, -1); | |
| 953 if (cnd == nd) return TRUE; | |
| 954 } while (gtk_tree_model_iter_next(store, iter)); | |
| 955 | |
| 956 return FALSE; | |
| 957 } | |
| 958 | |
| 959 static NodeData *vdtree_find_iter_by_name(ViewDirTree *vdt, GtkTreeIter *parent, const gchar *name, GtkTreeIter *iter) | |
| 960 { | |
| 961 GtkTreeModel *store; | |
| 962 | |
| 963 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
| 964 if (!name || !gtk_tree_model_iter_children(store, iter, parent)) return NULL; | |
| 965 do { | |
| 966 NodeData *nd; | |
| 967 | |
| 968 gtk_tree_model_get(store, iter, DIR_COLUMN_POINTER, &nd, -1); | |
| 969 if (nd && strcmp(nd->fd->name, name) == 0) return nd; | |
| 970 } while (gtk_tree_model_iter_next(store, iter)); | |
| 971 | |
| 972 return NULL; | |
| 973 } | |
| 974 | |
| 975 static void vdtree_add_by_data(ViewDirTree *vdt, FileData *fd, GtkTreeIter *parent) | |
| 976 { | |
| 977 GtkTreeStore *store; | |
| 978 GtkTreeIter child; | |
| 979 NodeData *nd; | |
| 980 GdkPixbuf *pixbuf; | |
| 981 NodeData *end; | |
| 982 GtkTreeIter empty; | |
| 983 | |
| 984 if (!fd) return; | |
| 985 | |
| 986 if (access_file(fd->path, R_OK | X_OK)) | |
| 987 { | |
| 988 pixbuf = vdt->pf->close; | |
| 989 } | |
| 990 else | |
| 991 { | |
| 992 pixbuf = vdt->pf->deny; | |
| 993 } | |
| 994 | |
| 995 nd = g_new0(NodeData, 1); | |
| 996 nd->fd = fd; | |
| 997 nd->expanded = FALSE; | |
| 998 nd->last_update = time(NULL); | |
| 999 | |
| 1000 store = GTK_TREE_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview))); | |
| 1001 gtk_tree_store_append(store, &child, parent); | |
| 1002 gtk_tree_store_set(store, &child, DIR_COLUMN_POINTER, nd, | |
| 1003 DIR_COLUMN_ICON, pixbuf, | |
| 1004 DIR_COLUMN_NAME, nd->fd->name, | |
| 1005 DIR_COLUMN_COLOR, FALSE, -1); | |
| 1006 | |
| 1007 /* all nodes are created with an "empty" node, so that the expander is shown | |
| 1008 * this is removed when the child is populated */ | |
| 1009 end = g_new0(NodeData, 1); | |
| 1010 end->fd = g_new0(FileData, 1); | |
| 1011 end->fd->path = g_strdup(""); | |
| 1012 end->fd->name = end->fd->path; | |
| 1013 end->expanded = TRUE; | |
| 1014 | |
| 1015 gtk_tree_store_append(store, &empty, &child); | |
| 1016 gtk_tree_store_set(store, &empty, DIR_COLUMN_POINTER, end, | |
| 1017 DIR_COLUMN_NAME, "empty", -1); | |
| 1018 | |
| 1019 if (parent) | |
| 1020 { | |
| 1021 NodeData *pnd; | |
| 1022 GtkTreePath *tpath; | |
| 1023 | |
| 1024 gtk_tree_model_get(GTK_TREE_MODEL(store), parent, DIR_COLUMN_POINTER, &pnd, -1); | |
| 1025 tpath = gtk_tree_model_get_path(GTK_TREE_MODEL(store), parent); | |
| 1026 if (tree_descend_subdirs && | |
| 1027 gtk_tree_view_row_expanded(GTK_TREE_VIEW(vdt->treeview), tpath) && | |
| 1028 !nd->expanded) | |
| 1029 { | |
| 1030 vdtree_populate_path_by_iter(vdt, &child, FALSE, vdt->path); | |
| 1031 } | |
| 1032 gtk_tree_path_free(tpath); | |
| 1033 } | |
| 1034 } | |
| 1035 | |
| 1036 static gint vdtree_populate_path_by_iter(ViewDirTree *vdt, GtkTreeIter *iter, gint force, const gchar *target_path) | |
| 1037 { | |
| 1038 GtkTreeModel *store; | |
| 1039 GList *list; | |
| 1040 GList *work; | |
| 1041 GList *old; | |
| 1042 time_t current_time; | |
| 1043 GtkTreeIter child; | |
| 1044 NodeData *nd; | |
| 1045 | |
| 1046 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
| 1047 gtk_tree_model_get(store, iter, DIR_COLUMN_POINTER, &nd, -1); | |
| 1048 | |
| 1049 if (!nd) return FALSE; | |
| 1050 | |
| 1051 current_time = time(NULL); | |
| 1052 | |
| 1053 if (nd->expanded) | |
| 1054 { | |
| 1055 if (!force && current_time - nd->last_update < 10) return TRUE; | |
| 1056 if (!isdir(nd->fd->path)) | |
| 1057 { | |
| 1058 if (vdt->click_fd == nd->fd) vdt->click_fd = NULL; | |
| 1059 if (vdt->drop_fd == nd->fd) vdt->drop_fd = NULL; | |
| 1060 gtk_tree_store_remove(GTK_TREE_STORE(store), iter); | |
| 1061 vdtree_node_free(nd); | |
| 1062 return FALSE; | |
| 1063 } | |
| 1064 if (!force && filetime(nd->fd->path) == nd->fd->date) return TRUE; | |
| 1065 } | |
| 1066 | |
| 1067 vdtree_busy_push(vdt); | |
| 1068 | |
| 1069 list = NULL; | |
| 1070 filelist_read(nd->fd->path, NULL, &list); | |
| 1071 | |
| 1072 /* when hidden files are not enabled, and the user enters a hidden path, | |
| 1073 * allow the tree to display that path by specifically inserting the hidden entries | |
| 1074 */ | |
| 1075 if (!show_dot_files && | |
| 1076 target_path && | |
| 1077 strncmp(nd->fd->path, target_path, strlen(nd->fd->path)) == 0) | |
| 1078 { | |
| 1079 gint n; | |
| 1080 | |
| 1081 n = strlen(nd->fd->path); | |
| 1082 if (target_path[n] == '/' && target_path[n+1] == '.') | |
| 1083 { | |
| 1084 gchar *name8; | |
| 1085 gchar *namel; | |
| 1086 struct stat sbuf; | |
| 1087 | |
| 1088 n++; | |
| 1089 | |
| 1090 while (target_path[n] != '\0' && target_path[n] != '/') n++; | |
| 1091 name8 = g_strndup(target_path, n); | |
| 1092 namel = path_from_utf8(name8); | |
| 1093 | |
| 1094 if (stat_utf8(name8, &sbuf)) | |
| 1095 { | |
| 1096 list = g_list_prepend(list, file_data_new(namel, &sbuf)); | |
| 1097 } | |
| 1098 | |
| 1099 g_free(namel); | |
| 1100 g_free(name8); | |
| 1101 } | |
| 1102 } | |
| 1103 | |
| 1104 old = NULL; | |
| 1105 if (gtk_tree_model_iter_children(store, &child, iter)) | |
| 1106 { | |
| 1107 do { | |
| 1108 NodeData *cnd; | |
| 1109 | |
| 1110 gtk_tree_model_get(store, &child, DIR_COLUMN_POINTER, &cnd, -1); | |
| 1111 old = g_list_prepend(old, cnd); | |
| 1112 } while (gtk_tree_model_iter_next(store, &child)); | |
| 1113 } | |
| 1114 | |
| 1115 work = list; | |
| 1116 while (work) | |
| 1117 { | |
| 1118 FileData *fd; | |
| 1119 | |
| 1120 fd = work->data; | |
| 1121 work = work->next; | |
| 1122 | |
| 1123 if (strcmp(fd->name, ".") == 0 || strcmp(fd->name, "..") == 0) | |
| 1124 { | |
| 1125 file_data_free(fd); | |
| 1126 } | |
| 1127 else | |
| 1128 { | |
| 1129 NodeData *cnd; | |
| 1130 | |
| 1131 cnd = vdtree_find_iter_by_name(vdt, iter, fd->name, &child); | |
| 1132 if (cnd) | |
| 1133 { | |
| 1134 old = g_list_remove(old, cnd); | |
| 1135 if (cnd->expanded && cnd->fd->date != fd->date && | |
| 1136 vdtree_populate_path_by_iter(vdt, &child, FALSE, target_path)) | |
| 1137 { | |
| 1138 cnd->fd->size = fd->size; | |
| 1139 cnd->fd->date = fd->date; | |
| 1140 } | |
| 1141 | |
| 1142 file_data_free(fd); | |
| 1143 } | |
| 1144 else | |
| 1145 { | |
| 1146 vdtree_add_by_data(vdt, fd, iter); | |
| 1147 } | |
| 1148 } | |
| 1149 } | |
| 1150 | |
| 1151 work = old; | |
| 1152 while (work) | |
| 1153 { | |
| 1154 NodeData *cnd = work->data; | |
| 1155 work = work->next; | |
| 1156 | |
| 1157 if (vdt->click_fd == cnd->fd) vdt->click_fd = NULL; | |
| 1158 if (vdt->drop_fd == cnd->fd) vdt->drop_fd = NULL; | |
| 1159 | |
| 1160 if (vdtree_find_iter_by_data(vdt, iter, cnd, &child)) | |
| 1161 { | |
| 1162 gtk_tree_store_remove(GTK_TREE_STORE(store), &child); | |
| 1163 vdtree_node_free(cnd); | |
| 1164 } | |
| 1165 } | |
| 1166 | |
| 1167 g_list_free(old); | |
| 1168 g_list_free(list); | |
| 1169 | |
| 1170 vdtree_busy_pop(vdt); | |
| 1171 | |
| 1172 nd->expanded = TRUE; | |
| 1173 nd->last_update = current_time; | |
| 1174 | |
| 1175 return TRUE; | |
| 1176 } | |
| 1177 | |
| 1178 static FileData *vdtree_populate_path(ViewDirTree *vdt, const gchar *path, gint expand, gint force) | |
| 1179 { | |
| 1180 GList *list; | |
| 1181 GList *work; | |
| 1182 FileData *fd = NULL; | |
| 1183 | |
| 1184 if (!path) return NULL; | |
| 1185 | |
| 1186 vdtree_busy_push(vdt); | |
| 1187 | |
| 1188 list = parts_list(path); | |
| 1189 list = parts_list_add_node_points(vdt, list); | |
| 1190 | |
| 1191 work = list; | |
| 1192 while (work) | |
| 1193 { | |
| 1194 PathData *pd = work->data; | |
| 1195 if (pd->node == NULL) | |
| 1196 { | |
| 1197 PathData *parent_pd; | |
| 1198 GtkTreeIter parent_iter; | |
| 1199 GtkTreeIter iter; | |
| 1200 NodeData *nd; | |
| 1201 | |
| 1202 if (work == list) | |
| 1203 { | |
| 1204 /* should not happen */ | |
| 1205 printf("vdtree warning, root node not found\n"); | |
| 1206 parts_list_free(list); | |
| 1207 vdtree_busy_pop(vdt); | |
| 1208 return NULL; | |
| 1209 } | |
| 1210 | |
| 1211 parent_pd = work->prev->data; | |
| 1212 | |
| 1213 if (!vdtree_find_row(vdt, parent_pd->node, &parent_iter, NULL) || | |
| 1214 !vdtree_populate_path_by_iter(vdt, &parent_iter, force, path) || | |
| 1215 (nd = vdtree_find_iter_by_name(vdt, &parent_iter, pd->name, &iter)) == NULL) | |
| 1216 { | |
| 1217 printf("vdtree warning, aborted at %s\n", parent_pd->name); | |
| 1218 parts_list_free(list); | |
| 1219 vdtree_busy_pop(vdt); | |
| 1220 return NULL; | |
| 1221 } | |
| 1222 | |
| 1223 pd->node = nd->fd; | |
| 1224 | |
| 1225 if (pd->node) | |
| 1226 { | |
| 1227 if (expand) | |
| 1228 { | |
| 1229 vdtree_expand_by_iter(vdt, &parent_iter, TRUE); | |
| 1230 vdtree_expand_by_iter(vdt, &iter, TRUE); | |
| 1231 } | |
| 1232 vdtree_populate_path_by_iter(vdt, &iter, force, path); | |
| 1233 } | |
| 1234 } | |
| 1235 else | |
| 1236 { | |
| 1237 GtkTreeIter iter; | |
| 1238 | |
| 1239 if (vdtree_find_row(vdt, pd->node, &iter, NULL)) | |
| 1240 { | |
| 1241 if (expand) vdtree_expand_by_iter(vdt, &iter, TRUE); | |
| 1242 vdtree_populate_path_by_iter(vdt, &iter, force, path); | |
| 1243 } | |
| 1244 } | |
| 1245 | |
| 1246 work = work->next; | |
| 1247 } | |
| 1248 | |
| 1249 work = g_list_last(list); | |
| 1250 if (work) | |
| 1251 { | |
| 1252 PathData *pd = work->data; | |
| 1253 fd = pd->node; | |
| 1254 } | |
| 1255 parts_list_free(list); | |
| 1256 | |
| 1257 vdtree_busy_pop(vdt); | |
| 1258 | |
| 1259 return fd; | |
| 1260 } | |
| 1261 | |
| 1262 /* | |
| 1263 *---------------------------------------------------------------------------- | |
| 1264 * access | |
| 1265 *---------------------------------------------------------------------------- | |
| 1266 */ | |
| 1267 | |
| 1268 static gint selection_is_ok = FALSE; | |
| 1269 | |
| 1270 static gboolean vdtree_select_cb(GtkTreeSelection *selection, GtkTreeModel *store, GtkTreePath *tpath, | |
| 1271 gboolean path_currently_selected, gpointer data) | |
| 1272 { | |
| 1273 return selection_is_ok; | |
| 1274 } | |
| 1275 | |
| 1276 static void vdtree_select_row(ViewDirTree *vdt, FileData *fd) | |
| 1277 { | |
| 1278 GtkTreeSelection *selection; | |
| 1279 GtkTreeIter iter; | |
| 1280 | |
| 1281 if (!vdtree_find_row(vdt, fd, &iter, NULL)) return; | |
| 1282 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vdt->treeview)); | |
| 1283 | |
| 1284 /* hack, such that selection is only allowed to be changed from here */ | |
| 1285 selection_is_ok = TRUE; | |
| 1286 gtk_tree_selection_select_iter(selection, &iter); | |
| 1287 selection_is_ok = FALSE; | |
| 1288 | |
| 1289 if (!vdtree_populate_path_by_iter(vdt, &iter, FALSE, vdt->path)) return; | |
| 1290 | |
| 1291 vdtree_expand_by_iter(vdt, &iter, TRUE); | |
| 1292 | |
| 1293 if (fd && vdt->select_func) | |
| 1294 { | |
| 1295 vdt->select_func(vdt, fd->path, vdt->select_data); | |
| 1296 } | |
| 1297 } | |
| 1298 | |
| 1299 gint vdtree_set_path(ViewDirTree *vdt, const gchar *path) | |
| 1300 { | |
| 1301 FileData *fd; | |
| 1302 GtkTreeIter iter; | |
| 1303 | |
| 1304 if (!path) return FALSE; | |
| 1305 if (vdt->path && strcmp(path, vdt->path) == 0) return TRUE; | |
| 1306 | |
| 1307 g_free(vdt->path); | |
| 1308 vdt->path = g_strdup(path); | |
| 1309 | |
|
63
e29c291e106b
Mon Aug 15 16:35:15 2005 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
1310 fd = vdtree_populate_path(vdt, vdt->path, TRUE, FALSE); |
| 9 | 1311 |
| 1312 if (!fd) return FALSE; | |
| 1313 | |
| 1314 if (vdtree_find_row(vdt, fd, &iter, NULL)) | |
| 1315 { | |
| 1316 GtkTreeModel *store; | |
| 1317 GtkTreePath *tpath; | |
| 1318 | |
| 1319 tree_view_row_make_visible(GTK_TREE_VIEW(vdt->treeview), &iter, TRUE); | |
| 1320 | |
| 1321 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
| 1322 tpath = gtk_tree_model_get_path(store, &iter); | |
| 1323 gtk_tree_view_set_cursor(GTK_TREE_VIEW(vdt->treeview), tpath, NULL, FALSE); | |
| 1324 gtk_tree_path_free(tpath); | |
| 1325 | |
| 1326 vdtree_select_row(vdt, fd); | |
| 1327 } | |
| 1328 | |
| 1329 return TRUE; | |
| 1330 } | |
| 1331 | |
| 1332 #if 0 | |
| 1333 const gchar *vdtree_get_path(ViewDirTree *vdt) | |
| 1334 { | |
| 1335 return vdt->path; | |
| 1336 } | |
| 1337 #endif | |
| 1338 | |
| 1339 void vdtree_refresh(ViewDirTree *vdt) | |
| 1340 { | |
| 1341 vdtree_populate_path(vdt, vdt->path, FALSE, TRUE); | |
| 1342 } | |
| 1343 | |
| 1344 const gchar *vdtree_row_get_path(ViewDirTree *vdt, gint row) | |
| 1345 { | |
| 1346 printf("FIXME: no get row path\n"); | |
| 1347 return NULL; | |
| 1348 } | |
| 1349 | |
| 1350 /* | |
| 1351 *---------------------------------------------------------------------------- | |
| 1352 * callbacks | |
| 1353 *---------------------------------------------------------------------------- | |
| 1354 */ | |
| 1355 | |
| 1356 static void vdtree_menu_position_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data) | |
| 1357 { | |
| 1358 ViewDirTree *vdt = data; | |
| 1359 GtkTreeModel *store; | |
| 1360 GtkTreeIter iter; | |
| 1361 GtkTreePath *tpath; | |
| 1362 gint cw, ch; | |
| 1363 | |
| 1364 if (vdtree_find_row(vdt, vdt->click_fd, &iter, NULL) < 0) return; | |
| 1365 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
| 1366 tpath = gtk_tree_model_get_path(store, &iter); | |
| 1367 tree_view_get_cell_clamped(GTK_TREE_VIEW(vdt->treeview), tpath, 0, TRUE, x, y, &cw, &ch); | |
| 1368 gtk_tree_path_free(tpath); | |
| 1369 *y += ch; | |
| 1370 popup_menu_position_clamp(menu, x, y, 0); | |
| 1371 } | |
| 1372 | |
| 1373 static gint vdtree_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) | |
| 1374 { | |
| 1375 ViewDirTree *vdt = data; | |
| 1376 GtkTreePath *tpath; | |
| 1377 GtkTreeIter iter; | |
| 1378 FileData *fd = NULL; | |
| 1379 | |
| 1380 gtk_tree_view_get_cursor(GTK_TREE_VIEW(vdt->treeview), &tpath, NULL); | |
| 1381 if (tpath) | |
| 1382 { | |
| 1383 GtkTreeModel *store; | |
| 1384 NodeData *nd; | |
| 1385 | |
| 1386 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
| 1387 gtk_tree_model_get_iter(store, &iter, tpath); | |
| 1388 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
| 1389 | |
| 1390 gtk_tree_path_free(tpath); | |
| 1391 | |
| 1392 fd = (nd) ? nd->fd : NULL; | |
| 1393 } | |
| 1394 | |
| 1395 switch (event->keyval) | |
| 1396 { | |
| 1397 case GDK_Menu: | |
| 1398 vdt->click_fd = fd; | |
| 1399 vdtree_color_set(vdt, vdt->click_fd, TRUE); | |
| 1400 | |
| 1401 vdt->popup = vdtree_pop_menu(vdt, vdt->click_fd); | |
| 1402 gtk_menu_popup(GTK_MENU(vdt->popup), NULL, NULL, vdtree_menu_position_cb, vdt, 0, GDK_CURRENT_TIME); | |
| 1403 | |
| 1404 return TRUE; | |
| 1405 break; | |
| 1406 case GDK_plus: | |
| 1407 case GDK_Right: | |
| 1408 case GDK_KP_Add: | |
| 1409 if (fd) | |
| 1410 { | |
| 1411 vdtree_populate_path_by_iter(vdt, &iter, FALSE, vdt->path); | |
| 1412 vdtree_icon_set_by_iter(vdt, &iter, vdt->pf->open); | |
| 1413 } | |
| 1414 break; | |
| 1415 } | |
| 1416 | |
| 1417 return FALSE; | |
| 1418 } | |
| 1419 | |
| 1420 static gint vdtree_clicked_on_expander(GtkTreeView *treeview, GtkTreePath *tpath, | |
| 1421 GtkTreeViewColumn *column, gint x, gint y, gint *left_of_expander) | |
| 1422 { | |
| 1423 gint depth; | |
| 1424 gint size; | |
| 1425 gint sep; | |
| 1426 gint exp_width; | |
| 1427 | |
| 1428 if (column != gtk_tree_view_get_expander_column(treeview)) return FALSE; | |
| 1429 | |
| 1430 gtk_widget_style_get(GTK_WIDGET(treeview), "expander-size", &size, "horizontal-separator", &sep, NULL); | |
| 1431 depth = gtk_tree_path_get_depth(tpath); | |
| 1432 | |
| 1433 exp_width = sep + size + sep; | |
| 1434 | |
| 1435 if (x <= depth * exp_width) | |
| 1436 { | |
| 1437 if (left_of_expander) *left_of_expander = !(x >= (depth - 1) * exp_width); | |
| 1438 return TRUE; | |
| 1439 } | |
| 1440 | |
| 1441 return FALSE; | |
| 1442 } | |
| 1443 | |
| 1444 static gint vdtree_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
| 1445 { | |
| 1446 ViewDirTree *vdt = data; | |
| 1447 GtkTreePath *tpath; | |
| 1448 GtkTreeViewColumn *column; | |
| 1449 GtkTreeIter iter; | |
| 1450 NodeData *nd = NULL; | |
| 1451 | |
| 1452 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | |
| 1453 &tpath, &column, NULL, NULL)) | |
| 1454 { | |
| 1455 GtkTreeModel *store; | |
| 1456 gint left_of_expander; | |
| 1457 | |
| 1458 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
| 1459 gtk_tree_model_get_iter(store, &iter, tpath); | |
| 1460 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
| 1461 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE); | |
| 1462 | |
| 1463 if (vdtree_clicked_on_expander(GTK_TREE_VIEW(widget), tpath, column, bevent->x, bevent->y, &left_of_expander)) | |
| 1464 { | |
| 1465 vdt->click_fd = NULL; | |
| 1466 | |
| 1467 /* clicking this region should automatically reveal an expander, if necessary | |
| 1468 * treeview bug: the expander will not expand until a button_motion_event highlights it. | |
| 1469 */ | |
| 1470 if (bevent->button == 1 && | |
| 1471 !left_of_expander && | |
| 1472 !gtk_tree_view_row_expanded(GTK_TREE_VIEW(vdt->treeview), tpath)) | |
| 1473 { | |
| 1474 vdtree_populate_path_by_iter(vdt, &iter, FALSE, vdt->path); | |
| 1475 vdtree_icon_set_by_iter(vdt, &iter, vdt->pf->open); | |
| 1476 } | |
| 1477 | |
| 1478 gtk_tree_path_free(tpath); | |
| 1479 return FALSE; | |
| 1480 } | |
| 1481 | |
| 1482 gtk_tree_path_free(tpath); | |
| 1483 } | |
| 1484 | |
| 1485 vdt->click_fd = (nd) ? nd->fd : NULL; | |
| 1486 vdtree_color_set(vdt, vdt->click_fd, TRUE); | |
| 1487 | |
| 1488 if (bevent->button == 3) | |
| 1489 { | |
| 1490 vdt->popup = vdtree_pop_menu(vdt, vdt->click_fd); | |
| 1491 gtk_menu_popup(GTK_MENU(vdt->popup), NULL, NULL, NULL, NULL, | |
| 1492 bevent->button, bevent->time); | |
| 1493 } | |
| 1494 | |
| 1495 return (bevent->button != 1); | |
| 1496 } | |
| 1497 | |
| 1498 static gint vdtree_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
| 1499 { | |
| 1500 ViewDirTree *vdt = data; | |
| 1501 GtkTreePath *tpath; | |
| 1502 GtkTreeIter iter; | |
| 1503 NodeData *nd = NULL; | |
| 1504 | |
| 1505 if (!vdt->click_fd) return FALSE; | |
| 1506 vdtree_color_set(vdt, vdt->click_fd, FALSE); | |
| 1507 | |
| 1508 if (bevent->button != 1) return TRUE; | |
| 1509 | |
| 1510 if ((bevent->x != 0 || bevent->y != 0) && | |
| 1511 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | |
| 1512 &tpath, NULL, NULL, NULL)) | |
| 1513 { | |
| 1514 GtkTreeModel *store; | |
| 1515 | |
| 1516 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
| 1517 gtk_tree_model_get_iter(store, &iter, tpath); | |
| 1518 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
| 1519 gtk_tree_path_free(tpath); | |
| 1520 } | |
| 1521 | |
| 1522 if (nd && vdt->click_fd == nd->fd) | |
| 1523 { | |
| 1524 vdtree_select_row(vdt, vdt->click_fd); | |
| 1525 } | |
| 1526 | |
| 1527 return FALSE; | |
| 1528 } | |
| 1529 | |
| 1530 static void vdtree_row_expanded(GtkTreeView *treeview, GtkTreeIter *iter, GtkTreePath *tpath, gpointer data) | |
| 1531 { | |
| 1532 ViewDirTree *vdt = data; | |
| 1533 | |
|
25
0c3b353b666e
Fri Mar 25 22:39:30 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
1534 vdtree_populate_path_by_iter(vdt, iter, FALSE, NULL); |
| 9 | 1535 vdtree_icon_set_by_iter(vdt, iter, vdt->pf->open); |
| 1536 } | |
| 1537 | |
| 1538 static void vdtree_row_collapsed(GtkTreeView *treeview, GtkTreeIter *iter, GtkTreePath *tpath, gpointer data) | |
| 1539 { | |
| 1540 ViewDirTree *vdt = data; | |
| 1541 | |
| 1542 vdtree_icon_set_by_iter(vdt, iter, vdt->pf->close); | |
| 1543 } | |
| 1544 | |
| 1545 static gint vdtree_sort_cb(GtkTreeModel *store, GtkTreeIter *a, GtkTreeIter *b, gpointer data) | |
| 1546 { | |
| 1547 NodeData *nda; | |
| 1548 NodeData *ndb; | |
| 1549 | |
| 1550 gtk_tree_model_get(store, a, DIR_COLUMN_POINTER, &nda, -1); | |
| 1551 gtk_tree_model_get(store, b, DIR_COLUMN_POINTER, &ndb, -1); | |
| 1552 | |
| 1553 return CASE_SORT(nda->fd->name, ndb->fd->name); | |
| 1554 } | |
| 1555 | |
| 1556 /* | |
| 1557 *---------------------------------------------------------------------------- | |
| 1558 * core | |
| 1559 *---------------------------------------------------------------------------- | |
| 1560 */ | |
| 1561 | |
| 1562 static void vdtree_setup_root(ViewDirTree *vdt) | |
| 1563 { | |
| 1564 const gchar *path = "/"; | |
| 1565 FileData *fd; | |
| 1566 | |
| 1567 fd = g_new0(FileData, 1); | |
| 1568 fd->path = g_strdup(path); | |
| 1569 fd->name = fd->path; | |
| 1570 fd->size = 0; | |
| 1571 fd->date = filetime(path); | |
| 1572 vdtree_add_by_data(vdt, fd, NULL); | |
| 1573 | |
| 1574 vdtree_expand_by_data(vdt, fd, TRUE); | |
| 1575 vdtree_populate_path(vdt, path, FALSE, FALSE); | |
| 1576 } | |
| 1577 | |
| 1578 static void vdtree_activate_cb(GtkTreeView *tview, GtkTreePath *tpath, GtkTreeViewColumn *column, gpointer data) | |
| 1579 { | |
| 1580 ViewDirTree *vdt = data; | |
| 1581 GtkTreeModel *store; | |
| 1582 GtkTreeIter iter; | |
| 1583 NodeData *nd; | |
| 1584 | |
| 1585 store = gtk_tree_view_get_model(tview); | |
| 1586 gtk_tree_model_get_iter(store, &iter, tpath); | |
| 1587 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &nd, -1); | |
| 1588 | |
| 1589 vdtree_select_row(vdt, nd->fd); | |
| 1590 } | |
| 1591 | |
| 1592 static GdkColor *vdtree_color_shifted(GtkWidget *widget) | |
| 1593 { | |
| 1594 static GdkColor color; | |
| 1595 static GtkWidget *done = NULL; | |
| 1596 | |
| 1597 if (done != widget) | |
| 1598 { | |
| 1599 GtkStyle *style; | |
| 1600 | |
| 1601 style = gtk_widget_get_style(widget); | |
| 1602 memcpy(&color, &style->base[GTK_STATE_NORMAL], sizeof(color)); | |
| 1603 shift_color(&color, -1, 0); | |
| 1604 done = widget; | |
| 1605 } | |
| 1606 | |
| 1607 return &color; | |
| 1608 } | |
| 1609 | |
| 1610 static void vdtree_color_cb(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, | |
| 1611 GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data) | |
| 1612 { | |
| 1613 ViewDirTree *vdt = data; | |
| 1614 gboolean set; | |
| 1615 | |
| 1616 gtk_tree_model_get(tree_model, iter, DIR_COLUMN_COLOR, &set, -1); | |
| 1617 g_object_set(G_OBJECT(cell), | |
| 1618 "cell-background-gdk", vdtree_color_shifted(vdt->treeview), | |
| 1619 "cell-background-set", set, NULL); | |
| 1620 } | |
| 1621 | |
| 1622 static gboolean vdtree_destroy_node_cb(GtkTreeModel *store, GtkTreePath *tpath, GtkTreeIter *iter, gpointer data) | |
| 1623 { | |
| 1624 NodeData *nd; | |
| 1625 | |
| 1626 gtk_tree_model_get(store, iter, DIR_COLUMN_POINTER, &nd, -1); | |
| 1627 vdtree_node_free(nd); | |
| 1628 | |
| 1629 return FALSE; | |
| 1630 } | |
| 1631 | |
| 1632 static void vdtree_destroy_cb(GtkWidget *widget, gpointer data) | |
| 1633 { | |
| 1634 ViewDirTree *vdt = data; | |
| 1635 GtkTreeModel *store; | |
| 1636 | |
| 1637 if (vdt->popup) | |
| 1638 { | |
| 1639 g_signal_handlers_disconnect_matched(G_OBJECT(vdt->popup), G_SIGNAL_MATCH_DATA, | |
| 1640 0, 0, 0, NULL, vdt); | |
| 1641 gtk_widget_destroy(vdt->popup); | |
| 1642 } | |
| 1643 | |
| 1644 vdtree_dnd_drop_expand_cancel(vdt); | |
| 1645 vdtree_dnd_drop_scroll_cancel(vdt); | |
| 1646 widget_auto_scroll_stop(vdt->treeview); | |
| 1647 | |
| 1648 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdt->treeview)); | |
| 1649 gtk_tree_model_foreach(store, vdtree_destroy_node_cb, vdt); | |
| 1650 | |
| 1651 path_list_free(vdt->drop_list); | |
| 1652 | |
| 1653 folder_icons_free(vdt->pf); | |
| 1654 | |
| 1655 g_free(vdt->path); | |
| 1656 g_free(vdt); | |
| 1657 } | |
| 1658 | |
| 1659 ViewDirTree *vdtree_new(const gchar *path, gint expand) | |
| 1660 { | |
| 1661 ViewDirTree *vdt; | |
| 1662 GtkTreeStore *store; | |
| 1663 GtkTreeSelection *selection; | |
| 1664 GtkTreeViewColumn *column; | |
| 1665 GtkCellRenderer *renderer; | |
| 1666 | |
| 1667 vdt = g_new0(ViewDirTree, 1); | |
| 1668 | |
| 1669 vdt->path = NULL; | |
| 1670 vdt->click_fd = NULL; | |
| 1671 | |
| 1672 vdt->drop_fd = NULL; | |
| 1673 vdt->drop_list = NULL; | |
| 1674 vdt->drop_scroll_id = -1; | |
| 1675 vdt->drop_expand_id = -1; | |
| 1676 | |
| 1677 vdt->popup = NULL; | |
| 1678 | |
| 1679 vdt->busy_ref = 0; | |
| 1680 | |
| 1681 vdt->widget = gtk_scrolled_window_new(NULL, NULL); | |
| 1682 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(vdt->widget), GTK_SHADOW_IN); | |
| 1683 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(vdt->widget), | |
| 1684 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
| 1685 g_signal_connect(G_OBJECT(vdt->widget), "destroy", | |
| 1686 G_CALLBACK(vdtree_destroy_cb), vdt); | |
| 1687 | |
| 1688 store = gtk_tree_store_new(4, G_TYPE_POINTER, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_INT); | |
| 1689 vdt->treeview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | |
| 1690 g_object_unref(store); | |
| 1691 | |
| 1692 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(vdt->treeview), FALSE); | |
| 1693 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(vdt->treeview), FALSE); | |
| 1694 gtk_tree_sortable_set_default_sort_func(GTK_TREE_SORTABLE(store), vdtree_sort_cb, vdt, NULL); | |
| 1695 gtk_tree_sortable_set_sort_column_id(GTK_TREE_SORTABLE(store), | |
| 1696 GTK_TREE_SORTABLE_DEFAULT_SORT_COLUMN_ID, GTK_SORT_ASCENDING); | |
| 1697 | |
| 1698 g_signal_connect(G_OBJECT(vdt->treeview), "row_activated", | |
| 1699 G_CALLBACK(vdtree_activate_cb), vdt); | |
| 1700 g_signal_connect(G_OBJECT(vdt->treeview), "row_expanded", | |
| 1701 G_CALLBACK(vdtree_row_expanded), vdt); | |
| 1702 g_signal_connect(G_OBJECT(vdt->treeview), "row_collapsed", | |
| 1703 G_CALLBACK(vdtree_row_collapsed), vdt); | |
| 1704 #if 0 | |
| 1705 g_signal_connect(G_OBJECT(store), "row_deleted", | |
| 1706 G_CALLBACK(vdtree_row_deleted_cb), vdt); | |
| 1707 #endif | |
| 1708 | |
| 1709 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vdt->treeview)); | |
| 1710 gtk_tree_selection_set_mode(selection, GTK_SELECTION_SINGLE); | |
| 1711 gtk_tree_selection_set_select_function(selection, vdtree_select_cb, vdt, NULL); | |
| 1712 | |
| 1713 column = gtk_tree_view_column_new(); | |
| 1714 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_GROW_ONLY); | |
| 1715 | |
| 1716 renderer = gtk_cell_renderer_pixbuf_new(); | |
| 1717 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
| 1718 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", DIR_COLUMN_ICON); | |
| 1719 gtk_tree_view_column_set_cell_data_func(column, renderer, vdtree_color_cb, vdt, NULL); | |
| 1720 | |
| 1721 renderer = gtk_cell_renderer_text_new(); | |
| 1722 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
| 1723 gtk_tree_view_column_add_attribute(column, renderer, "text", DIR_COLUMN_NAME); | |
| 1724 gtk_tree_view_column_set_cell_data_func(column, renderer, vdtree_color_cb, vdt, NULL); | |
| 1725 | |
| 1726 gtk_tree_view_append_column(GTK_TREE_VIEW(vdt->treeview), column); | |
| 1727 | |
| 1728 g_signal_connect(G_OBJECT(vdt->treeview), "key_press_event", | |
| 1729 G_CALLBACK(vdtree_press_key_cb), vdt); | |
| 1730 | |
| 1731 gtk_container_add(GTK_CONTAINER(vdt->widget), vdt->treeview); | |
| 1732 gtk_widget_show(vdt->treeview); | |
| 1733 | |
| 1734 vdt->pf = folder_icons_new(); | |
| 1735 | |
| 1736 vdtree_setup_root(vdt); | |
| 1737 | |
| 1738 vdtree_dnd_init(vdt); | |
| 1739 | |
| 1740 g_signal_connect(G_OBJECT(vdt->treeview), "button_press_event", | |
| 1741 G_CALLBACK(vdtree_press_cb), vdt); | |
| 1742 g_signal_connect(G_OBJECT(vdt->treeview), "button_release_event", | |
| 1743 G_CALLBACK(vdtree_release_cb), vdt); | |
| 1744 | |
| 1745 vdtree_set_path(vdt, path); | |
| 1746 | |
| 1747 return vdt; | |
| 1748 } | |
| 1749 | |
| 1750 void vdtree_set_select_func(ViewDirTree *vdt, | |
| 1751 void (*func)(ViewDirTree *vdt, const gchar *path, gpointer data), gpointer data) | |
| 1752 { | |
| 1753 vdt->select_func = func; | |
| 1754 vdt->select_data = data; | |
| 1755 } | |
| 1756 | |
| 1757 #if 0 | |
| 1758 void vdtree_set_click_func(ViewDirTree *vdt, | |
| 1759 void (*func)(ViewDirTree *vdt, GdkEventButton *event, FileData *fd, gpointer), gpointer data) | |
| 1760 { | |
| 1761 if (!td) return; | |
| 1762 vdt->click_func = func; | |
| 1763 vdt->click_data = data; | |
| 1764 } | |
| 1765 #endif | |
| 1766 | |
| 1767 void vdtree_set_layout(ViewDirTree *vdt, LayoutWindow *layout) | |
| 1768 { | |
| 1769 vdt->layout = layout; | |
| 1770 } | |
| 1771 |
