Mercurial > geeqie
annotate src/view_dir_list.c @ 135:15c1925b3bfb
improved external delete command
| author | nadvornik |
|---|---|
| date | Thu, 16 Aug 2007 20:57:09 +0000 |
| parents | b15d4c18168f |
| children | 71e1ebee420e |
| rev | line source |
|---|---|
| 9 | 1 /* |
| 2 * GQview | |
| 3 * (C) 2004 John Ellis | |
| 4 * | |
| 5 * Author: John Ellis | |
| 6 * | |
| 7 * This software is released under the GNU General Public License (GNU GPL). | |
| 8 * Please read the included file COPYING for more information. | |
| 9 * This software comes with no warranty of any kind, use at your own risk! | |
| 10 */ | |
| 11 | |
| 12 #include "gqview.h" | |
| 13 #include "view_dir_list.h" | |
| 14 | |
| 15 #include "dnd.h" | |
| 16 #include "dupe.h" | |
| 17 #include "filelist.h" | |
| 18 #include "layout.h" | |
| 19 #include "layout_image.h" | |
| 20 #include "layout_util.h" | |
| 21 #include "utilops.h" | |
| 22 #include "ui_bookmark.h" | |
| 23 #include "ui_fileops.h" | |
| 24 #include "ui_menu.h" | |
| 25 #include "ui_tree_edit.h" | |
| 26 | |
| 27 #include <gdk/gdkkeysyms.h> /* for keyboard values */ | |
| 28 | |
| 29 | |
| 30 #define VDLIST_PAD 4 | |
| 31 | |
| 32 | |
| 33 enum { | |
| 34 DIR_COLUMN_POINTER = 0, | |
| 35 DIR_COLUMN_ICON, | |
| 36 DIR_COLUMN_NAME, | |
| 37 DIR_COLUMN_COLOR, | |
| 38 DIR_COLUMN_COUNT | |
| 39 }; | |
| 40 | |
| 41 | |
| 42 static void vdlist_popup_destroy_cb(GtkWidget *widget, gpointer data); | |
| 43 static gint vdlist_auto_scroll_notify_cb(GtkWidget *widget, gint x, gint y, gpointer data); | |
| 44 | |
| 45 /* | |
| 46 *----------------------------------------------------------------------------- | |
| 47 * misc | |
| 48 *----------------------------------------------------------------------------- | |
| 49 */ | |
| 50 | |
| 51 static gint vdlist_find_row(ViewDirList *vdl, FileData *fd, GtkTreeIter *iter) | |
| 52 { | |
| 53 GtkTreeModel *store; | |
| 54 gint valid; | |
| 55 gint row = 0; | |
| 56 | |
| 57 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdl->listview)); | |
| 58 valid = gtk_tree_model_get_iter_first(store, iter); | |
| 59 while (valid) | |
| 60 { | |
| 61 FileData *fd_n; | |
| 62 gtk_tree_model_get(GTK_TREE_MODEL(store), iter, DIR_COLUMN_POINTER, &fd_n, -1); | |
| 63 if (fd_n == fd) return row; | |
| 64 | |
| 65 valid = gtk_tree_model_iter_next(GTK_TREE_MODEL(store), iter); | |
| 66 row++; | |
| 67 } | |
| 68 | |
| 69 return -1; | |
| 70 } | |
| 71 | |
| 72 static gint vdlist_rename_row_cb(TreeEditData *td, const gchar *old, const gchar *new, gpointer data) | |
| 73 { | |
| 74 ViewDirList *vdl = data; | |
| 75 GtkTreeModel *store; | |
| 76 GtkTreeIter iter; | |
| 77 FileData *fd; | |
| 78 gchar *old_path; | |
| 79 gchar *new_path; | |
| 80 gchar *base; | |
| 81 | |
| 82 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdl->listview)); | |
| 83 if (!gtk_tree_model_get_iter(store, &iter, td->path)) return FALSE; | |
| 84 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1); | |
| 85 if (!fd) return FALSE; | |
| 86 | |
| 87 old_path = g_strdup(fd->path); | |
| 88 | |
| 89 base = remove_level_from_path(old_path); | |
| 90 new_path = concat_dir_and_file(base, new); | |
| 91 g_free(base); | |
| 92 | |
|
44
458e396d3f35
Wed May 18 19:36:49 2005 John Ellis <johne@verizon.net>
gqview
parents:
9
diff
changeset
|
93 if (file_util_rename_dir(old_path, new_path, vdl->listview)) |
| 9 | 94 { |
| 95 if (vdl->layout && strcmp(vdl->path, old_path) == 0) | |
| 96 { | |
| 97 layout_set_path(vdl->layout, new_path); | |
| 98 } | |
| 99 else | |
| 100 { | |
| 101 vdlist_refresh(vdl); | |
| 102 } | |
| 103 } | |
| 104 | |
| 105 g_free(old_path); | |
| 106 g_free(new_path); | |
| 107 return FALSE; | |
| 108 } | |
| 109 | |
| 110 static void vdlist_rename_by_row(ViewDirList *vdl, FileData *fd) | |
| 111 { | |
| 112 GtkTreeModel *store; | |
| 113 GtkTreePath *tpath; | |
| 114 GtkTreeIter iter; | |
| 115 | |
| 116 if (vdlist_find_row(vdl, fd, &iter) < 0) return; | |
| 117 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdl->listview)); | |
| 118 tpath = gtk_tree_model_get_path(store, &iter); | |
| 119 | |
| 120 tree_edit_by_path(GTK_TREE_VIEW(vdl->listview), tpath, 0, fd->name, | |
| 121 vdlist_rename_row_cb, vdl); | |
| 122 gtk_tree_path_free(tpath); | |
| 123 } | |
| 124 | |
| 125 static FileData *vdlist_row_by_path(ViewDirList *vdl, const gchar *path, gint *row) | |
| 126 { | |
| 127 GList *work; | |
| 128 gint n; | |
| 129 | |
| 130 if (!path) | |
| 131 { | |
| 132 if (row) *row = -1; | |
| 133 return NULL; | |
| 134 } | |
| 135 | |
| 136 n = 0; | |
| 137 work = vdl->list; | |
| 138 while (work) | |
| 139 { | |
| 140 FileData *fd = work->data; | |
| 141 if (strcmp(fd->path, path) == 0) | |
| 142 { | |
| 143 if (row) *row = n; | |
| 144 return fd; | |
| 145 } | |
| 146 work = work->next; | |
| 147 n++; | |
| 148 } | |
| 149 | |
| 150 if (row) *row = -1; | |
| 151 return NULL; | |
| 152 } | |
| 153 | |
| 154 static void vdlist_color_set(ViewDirList *vdl, FileData *fd, gint color_set) | |
| 155 { | |
| 156 GtkTreeModel *store; | |
| 157 GtkTreeIter iter; | |
| 158 | |
| 159 if (vdlist_find_row(vdl, fd, &iter) < 0) return; | |
| 160 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdl->listview)); | |
| 161 gtk_list_store_set(GTK_LIST_STORE(store), &iter, DIR_COLUMN_COLOR, color_set, -1); | |
| 162 } | |
| 163 | |
| 164 /* | |
| 165 *----------------------------------------------------------------------------- | |
| 166 * drop menu (from dnd) | |
| 167 *----------------------------------------------------------------------------- | |
| 168 */ | |
| 169 | |
| 170 static void vdlist_drop_menu_copy_cb(GtkWidget *widget, gpointer data) | |
| 171 { | |
| 172 ViewDirList *vdl = data; | |
| 173 const gchar *path; | |
| 174 GList *list; | |
| 175 | |
| 176 if (!vdl->drop_fd) return; | |
| 177 | |
| 178 path = vdl->drop_fd->path; | |
| 179 list = vdl->drop_list; | |
| 180 vdl->drop_list = NULL; | |
| 181 | |
| 182 file_util_copy_simple(list, path); | |
| 183 } | |
| 184 | |
| 185 static void vdlist_drop_menu_move_cb(GtkWidget *widget, gpointer data) | |
| 186 { | |
| 187 ViewDirList *vdl = data; | |
| 188 const gchar *path; | |
| 189 GList *list; | |
| 190 | |
| 191 if (!vdl->drop_fd) return; | |
| 192 | |
| 193 path = vdl->drop_fd->path; | |
| 194 list = vdl->drop_list; | |
| 195 | |
| 196 vdl->drop_list = NULL; | |
| 197 | |
| 198 file_util_move_simple(list, path); | |
| 199 } | |
| 200 | |
| 201 static GtkWidget *vdlist_drop_menu(ViewDirList *vdl, gint active) | |
| 202 { | |
| 203 GtkWidget *menu; | |
| 204 | |
| 205 menu = popup_menu_short_lived(); | |
| 206 g_signal_connect(G_OBJECT(menu), "destroy", | |
| 207 G_CALLBACK(vdlist_popup_destroy_cb), vdl); | |
| 208 | |
| 209 menu_item_add_stock_sensitive(menu, _("_Copy"), GTK_STOCK_COPY, active, | |
| 210 G_CALLBACK(vdlist_drop_menu_copy_cb), vdl); | |
| 211 menu_item_add_sensitive(menu, _("_Move"), active, G_CALLBACK(vdlist_drop_menu_move_cb), vdl); | |
| 212 | |
| 213 menu_item_add_divider(menu); | |
| 214 menu_item_add_stock(menu, _("Cancel"), GTK_STOCK_CANCEL, NULL, vdl); | |
| 215 | |
| 216 return menu; | |
| 217 } | |
| 218 | |
| 219 /* | |
| 220 *----------------------------------------------------------------------------- | |
| 221 * pop-up menu | |
| 222 *----------------------------------------------------------------------------- | |
| 223 */ | |
| 224 | |
| 225 static void vdlist_pop_menu_up_cb(GtkWidget *widget, gpointer data) | |
| 226 { | |
| 227 ViewDirList *vdl = data; | |
| 228 gchar *path; | |
| 229 | |
| 230 if (!vdl->path || strcmp(vdl->path, "/") == 0) return; | |
| 231 path = remove_level_from_path(vdl->path); | |
| 232 | |
| 233 if (vdl->select_func) | |
| 234 { | |
| 235 vdl->select_func(vdl, path, vdl->select_data); | |
| 236 } | |
| 237 | |
| 238 g_free(path); | |
| 239 } | |
| 240 | |
| 241 static void vdlist_pop_menu_slide_cb(GtkWidget *widget, gpointer data) | |
| 242 { | |
| 243 ViewDirList *vdl = data; | |
| 244 gchar *path; | |
| 245 | |
| 246 if (!vdl->layout || !vdl->click_fd) return; | |
| 247 | |
| 248 path = g_strdup(vdl->click_fd->path); | |
| 249 | |
| 250 layout_set_path(vdl->layout, path); | |
| 251 layout_select_none(vdl->layout); | |
| 252 layout_image_slideshow_stop(vdl->layout); | |
| 253 layout_image_slideshow_start(vdl->layout); | |
| 254 | |
| 255 g_free(path); | |
| 256 } | |
| 257 | |
| 258 static void vdlist_pop_menu_slide_rec_cb(GtkWidget *widget, gpointer data) | |
| 259 { | |
| 260 ViewDirList *vdl = data; | |
| 261 gchar *path; | |
| 262 GList *list; | |
| 263 | |
| 264 if (!vdl->layout || !vdl->click_fd) return; | |
| 265 | |
| 266 path = g_strdup(vdl->click_fd->path); | |
| 267 | |
| 268 list = path_list_recursive(path); | |
| 269 | |
| 270 layout_image_slideshow_stop(vdl->layout); | |
| 271 layout_image_slideshow_start_from_list(vdl->layout, list); | |
| 272 | |
| 273 g_free(path); | |
| 274 } | |
| 275 | |
| 276 static void vdlist_pop_menu_dupe(ViewDirList *vdl, gint recursive) | |
| 277 { | |
| 278 DupeWindow *dw; | |
| 279 const gchar *path; | |
| 280 GList *list = NULL; | |
| 281 | |
| 282 if (!vdl->click_fd) return; | |
| 283 path = vdl->click_fd->path; | |
| 284 | |
| 285 if (recursive) | |
| 286 { | |
| 287 list = g_list_append(list, g_strdup(path)); | |
| 288 } | |
| 289 else | |
| 290 { | |
| 291 path_list(path, &list, NULL); | |
| 292 list = path_list_filter(list, FALSE); | |
| 293 } | |
| 294 | |
| 295 dw = dupe_window_new(DUPE_MATCH_NAME); | |
| 296 dupe_window_add_files(dw, list, recursive); | |
| 297 | |
| 298 path_list_free(list); | |
| 299 } | |
| 300 | |
| 301 static void vdlist_pop_menu_dupe_cb(GtkWidget *widget, gpointer data) | |
| 302 { | |
| 303 ViewDirList *vdl = data; | |
| 304 vdlist_pop_menu_dupe(vdl, FALSE); | |
| 305 } | |
| 306 | |
| 307 static void vdlist_pop_menu_dupe_rec_cb(GtkWidget *widget, gpointer data) | |
| 308 { | |
| 309 ViewDirList *vdl = data; | |
| 310 vdlist_pop_menu_dupe(vdl, TRUE); | |
| 311 } | |
| 312 | |
| 313 static void vdlist_pop_menu_new_cb(GtkWidget *widget, gpointer data) | |
| 314 { | |
| 315 ViewDirList *vdl = data; | |
| 316 gchar *new_path; | |
| 317 gchar *buf; | |
| 318 | |
| 319 if (!vdl->path) return; | |
| 320 | |
| 321 buf = concat_dir_and_file(vdl->path, _("new_folder")); | |
| 322 new_path = unique_filename(buf, NULL, NULL, FALSE); | |
| 323 g_free(buf); | |
| 324 if (!new_path) return; | |
| 325 | |
| 326 if (!mkdir_utf8(new_path, 0755)) | |
| 327 { | |
| 328 gchar *text; | |
| 329 | |
| 330 text = g_strdup_printf(_("Unable to create folder:\n%s"), new_path); | |
| 331 file_util_warning_dialog(_("Error creating folder"), text, GTK_STOCK_DIALOG_ERROR, vdl->listview); | |
| 332 g_free(text); | |
| 333 } | |
| 334 else | |
| 335 { | |
| 336 FileData *fd; | |
| 337 | |
| 338 vdlist_refresh(vdl); | |
| 339 fd = vdlist_row_by_path(vdl, new_path, NULL); | |
| 340 | |
| 341 vdlist_rename_by_row(vdl, fd); | |
| 342 } | |
| 343 | |
| 344 g_free(new_path); | |
| 345 } | |
| 346 | |
| 347 static void vdlist_pop_menu_rename_cb(GtkWidget *widget, gpointer data) | |
| 348 { | |
| 349 ViewDirList *vdl = data; | |
| 350 | |
| 351 vdlist_rename_by_row(vdl, vdl->click_fd); | |
| 352 } | |
| 353 | |
|
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
354 static void vdlist_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
|
355 { |
|
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
356 ViewDirList *vdl = data; |
|
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
357 |
|
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
358 if (!vdl->click_fd) return; |
|
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
359 file_util_delete_dir(vdl->click_fd->path, vdl->widget); |
|
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
360 } |
|
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
361 |
| 9 | 362 static void vdlist_pop_menu_tree_cb(GtkWidget *widget, gpointer data) |
| 363 { | |
| 364 ViewDirList *vdl = data; | |
| 365 | |
| 366 if (vdl->layout) layout_views_set(vdl->layout, TRUE, vdl->layout->icon_view); | |
| 367 } | |
| 368 | |
| 369 static void vdlist_pop_menu_refresh_cb(GtkWidget *widget, gpointer data) | |
| 370 { | |
| 371 ViewDirList *vdl = data; | |
| 372 | |
| 373 if (vdl->layout) layout_refresh(vdl->layout); | |
| 374 } | |
| 375 | |
| 376 static GtkWidget *vdlist_pop_menu(ViewDirList *vdl, FileData *fd) | |
| 377 { | |
| 378 GtkWidget *menu; | |
| 379 gint active; | |
| 380 | |
| 381 active = (fd != NULL); | |
| 382 | |
| 383 menu = popup_menu_short_lived(); | |
| 384 g_signal_connect(G_OBJECT(menu), "destroy", | |
| 385 G_CALLBACK(vdlist_popup_destroy_cb), vdl); | |
| 386 | |
| 387 menu_item_add_stock_sensitive(menu, _("_Up to parent"), GTK_STOCK_GO_UP, | |
| 388 (vdl->path && strcmp(vdl->path, "/") != 0), | |
| 389 G_CALLBACK(vdlist_pop_menu_up_cb), vdl); | |
| 390 | |
| 391 menu_item_add_divider(menu); | |
| 392 menu_item_add_sensitive(menu, _("_Slideshow"), active, | |
| 393 G_CALLBACK(vdlist_pop_menu_slide_cb), vdl); | |
| 394 menu_item_add_sensitive(menu, _("Slideshow recursive"), active, | |
| 395 G_CALLBACK(vdlist_pop_menu_slide_rec_cb), vdl); | |
| 396 | |
| 397 menu_item_add_divider(menu); | |
| 398 menu_item_add_stock_sensitive(menu, _("Find _duplicates..."), GTK_STOCK_FIND, active, | |
| 399 G_CALLBACK(vdlist_pop_menu_dupe_cb), vdl); | |
| 400 menu_item_add_stock_sensitive(menu, _("Find duplicates recursive..."), GTK_STOCK_FIND, active, | |
| 401 G_CALLBACK(vdlist_pop_menu_dupe_rec_cb), vdl); | |
| 402 | |
| 403 menu_item_add_divider(menu); | |
| 404 | |
| 405 /* check using . (always row 0) */ | |
| 406 active = (vdl->path && access_file(vdl->path , W_OK | X_OK)); | |
| 407 menu_item_add_sensitive(menu, _("_New folder..."), active, | |
| 408 G_CALLBACK(vdlist_pop_menu_new_cb), vdl); | |
| 409 | |
| 410 /* ignore .. and . */ | |
| 411 active = (active && fd && | |
| 412 strcmp(fd->name, ".") != 0 && | |
| 413 strcmp(fd->name, "..") != 0 && | |
| 414 access_file(fd->path, W_OK | X_OK)); | |
| 415 menu_item_add_sensitive(menu, _("_Rename..."), active, | |
| 416 G_CALLBACK(vdlist_pop_menu_rename_cb), vdl); | |
|
112
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
417 menu_item_add_stock_sensitive(menu, _("_Delete..."), GTK_STOCK_DELETE, active, |
|
b15d4c18168f
Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents:
64
diff
changeset
|
418 G_CALLBACK(vdlist_pop_menu_delete_cb), vdl); |
| 9 | 419 |
| 420 menu_item_add_divider(menu); | |
| 421 menu_item_add_check(menu, _("View as _tree"), FALSE, | |
| 422 G_CALLBACK(vdlist_pop_menu_tree_cb), vdl); | |
| 423 menu_item_add_stock(menu, _("Re_fresh"), GTK_STOCK_REFRESH, | |
| 424 G_CALLBACK(vdlist_pop_menu_refresh_cb), vdl); | |
| 425 | |
| 426 return menu; | |
| 427 } | |
| 428 | |
| 429 static void vdlist_popup_destroy_cb(GtkWidget *widget, gpointer data) | |
| 430 { | |
| 431 ViewDirList *vdl = data; | |
| 432 | |
| 433 vdlist_color_set(vdl, vdl->click_fd, FALSE); | |
| 434 vdl->click_fd = NULL; | |
| 435 vdl->popup = NULL; | |
| 436 | |
| 437 vdlist_color_set(vdl, vdl->drop_fd, FALSE); | |
| 438 path_list_free(vdl->drop_list); | |
| 439 vdl->drop_list = NULL; | |
| 440 vdl->drop_fd = NULL; | |
| 441 } | |
| 442 | |
| 443 /* | |
| 444 *----------------------------------------------------------------------------- | |
| 445 * dnd | |
| 446 *----------------------------------------------------------------------------- | |
| 447 */ | |
| 448 | |
| 449 static GtkTargetEntry vdlist_dnd_drop_types[] = { | |
| 450 { "text/uri-list", 0, TARGET_URI_LIST } | |
| 451 }; | |
| 452 static gint vdlist_dnd_drop_types_count = 1; | |
| 453 | |
| 454 static void vdlist_dest_set(ViewDirList *vdl, gint enable) | |
| 455 { | |
| 456 if (enable) | |
| 457 { | |
| 458 gtk_drag_dest_set(vdl->listview, | |
| 459 GTK_DEST_DEFAULT_MOTION | GTK_DEST_DEFAULT_DROP, | |
| 460 vdlist_dnd_drop_types, vdlist_dnd_drop_types_count, | |
| 461 GDK_ACTION_MOVE | GDK_ACTION_COPY); | |
| 462 } | |
| 463 else | |
| 464 { | |
| 465 gtk_drag_dest_unset(vdl->listview); | |
| 466 } | |
| 467 } | |
| 468 | |
| 469 static void vdlist_dnd_get(GtkWidget *widget, GdkDragContext *context, | |
| 470 GtkSelectionData *selection_data, guint info, | |
| 471 guint time, gpointer data) | |
| 472 { | |
| 473 ViewDirList *vdl = data; | |
| 474 gchar *path; | |
| 475 GList *list; | |
| 476 gchar *text = NULL; | |
| 477 gint length = 0; | |
| 478 | |
| 479 if (!vdl->click_fd) return; | |
| 480 path = vdl->click_fd->path; | |
| 481 | |
| 482 switch (info) | |
| 483 { | |
| 484 case TARGET_URI_LIST: | |
| 485 case TARGET_TEXT_PLAIN: | |
| 486 list = g_list_prepend(NULL, path); | |
| 487 text = uri_text_from_list(list, &length, (info == TARGET_TEXT_PLAIN)); | |
| 488 g_list_free(list); | |
| 489 break; | |
| 490 } | |
| 491 if (text) | |
| 492 { | |
| 493 gtk_selection_data_set (selection_data, selection_data->target, | |
|
64
04ff0df3ad2f
Mon Aug 15 17:13:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
494 8, (guchar *)text, length); |
| 9 | 495 g_free(text); |
| 496 } | |
| 497 } | |
| 498 | |
| 499 static void vdlist_dnd_begin(GtkWidget *widget, GdkDragContext *context, gpointer data) | |
| 500 { | |
| 501 ViewDirList *vdl = data; | |
| 502 | |
| 503 vdlist_color_set(vdl, vdl->click_fd, TRUE); | |
| 504 vdlist_dest_set(vdl, FALSE); | |
| 505 } | |
| 506 | |
| 507 static void vdlist_dnd_end(GtkWidget *widget, GdkDragContext *context, gpointer data) | |
| 508 { | |
| 509 ViewDirList *vdl = data; | |
| 510 | |
| 511 vdlist_color_set(vdl, vdl->click_fd, FALSE); | |
| 512 | |
| 513 if (context->action == GDK_ACTION_MOVE) | |
| 514 { | |
| 515 vdlist_refresh(vdl); | |
| 516 } | |
| 517 vdlist_dest_set(vdl, TRUE); | |
| 518 } | |
| 519 | |
| 520 static void vdlist_dnd_drop_receive(GtkWidget *widget, | |
| 521 GdkDragContext *context, gint x, gint y, | |
| 522 GtkSelectionData *selection_data, guint info, | |
| 523 guint time, gpointer data) | |
| 524 { | |
| 525 ViewDirList *vdl = data; | |
| 526 GtkTreePath *tpath; | |
| 527 GtkTreeIter iter; | |
| 528 FileData *fd = NULL; | |
| 529 | |
| 530 vdl->click_fd = NULL; | |
| 531 | |
| 532 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), x, y, | |
| 533 &tpath, NULL, NULL, NULL)) | |
| 534 { | |
| 535 GtkTreeModel *store; | |
| 536 | |
| 537 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
| 538 gtk_tree_model_get_iter(store, &iter, tpath); | |
| 539 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1); | |
| 540 gtk_tree_path_free(tpath); | |
| 541 } | |
| 542 | |
| 543 if (!fd) return; | |
| 544 | |
| 545 if (info == TARGET_URI_LIST) | |
| 546 { | |
| 547 GList *list; | |
| 548 gint active; | |
| 549 | |
|
64
04ff0df3ad2f
Mon Aug 15 17:13:57 2005 John Ellis <johne@verizon.net>
gqview
parents:
44
diff
changeset
|
550 list = uri_list_from_text((gchar *)selection_data->data, TRUE); |
| 9 | 551 if (!list) return; |
| 552 | |
| 553 active = access_file(fd->path, W_OK | X_OK); | |
| 554 | |
| 555 vdlist_color_set(vdl, fd, TRUE); | |
| 556 vdl->popup = vdlist_drop_menu(vdl, active); | |
| 557 gtk_menu_popup(GTK_MENU(vdl->popup), NULL, NULL, NULL, NULL, 0, time); | |
| 558 | |
| 559 vdl->drop_fd = fd; | |
| 560 vdl->drop_list = list; | |
| 561 } | |
| 562 } | |
| 563 | |
| 564 #if 0 | |
| 565 static gint vdlist_get_row_visibility(ViewDirList *vdl, FileData *fd) | |
| 566 { | |
| 567 GtkTreeModel *store; | |
| 568 GtkTreeViewColumn *column; | |
| 569 GtkTreePath *tpath; | |
| 570 GtkTreeIter iter; | |
| 571 | |
| 572 GdkRectangle vrect; | |
| 573 GdkRectangle crect; | |
| 574 | |
| 575 if (!fd || vdlist_find_row(vdl, fd, &iter) < 0) return 0; | |
| 576 | |
| 577 column = gtk_tree_view_get_column(GTK_TREE_VIEW(vdl->listview), 0); | |
| 578 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdl->listview)); | |
| 579 tpath = gtk_tree_model_get_path(store, &iter); | |
| 580 | |
| 581 gtk_tree_view_get_visible_rect(GTK_TREE_VIEW(vdl->listview), &vrect); | |
| 582 gtk_tree_view_get_cell_area(GTK_TREE_VIEW(vdl->listview), tpath, column, &crect); | |
| 583 printf("window: %d + %d; cell: %d + %d\n", vrect.y, vrect.height, crect.y, crect.height); | |
| 584 gtk_tree_path_free(tpath); | |
| 585 | |
| 586 if (crect.y + crect.height < vrect.y) return -1; | |
| 587 if (crect.y > vrect.y + vrect.height) return 1; | |
| 588 return 0; | |
| 589 } | |
| 590 #endif | |
| 591 | |
| 592 static void vdlist_scroll_to_row(ViewDirList *vdl, FileData *fd, gfloat y_align) | |
| 593 { | |
| 594 GtkTreeIter iter; | |
| 595 | |
| 596 if (GTK_WIDGET_REALIZED(vdl->listview) && | |
| 597 vdlist_find_row(vdl, fd, &iter) >= 0) | |
| 598 { | |
| 599 GtkTreeModel *store; | |
| 600 GtkTreePath *tpath; | |
| 601 | |
| 602 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdl->listview)); | |
| 603 tpath = gtk_tree_model_get_path(store, &iter); | |
| 604 gtk_tree_view_scroll_to_cell(GTK_TREE_VIEW(vdl->listview), tpath, NULL, TRUE, y_align, 0.0); | |
| 605 gtk_tree_view_set_cursor(GTK_TREE_VIEW(vdl->listview), tpath, NULL, FALSE); | |
| 606 gtk_tree_path_free(tpath); | |
| 607 | |
| 608 if (!GTK_WIDGET_HAS_FOCUS(vdl->listview)) gtk_widget_grab_focus(vdl->listview); | |
| 609 } | |
| 610 } | |
| 611 | |
| 612 static void vdlist_drop_update(ViewDirList *vdl, gint x, gint y) | |
| 613 { | |
| 614 GtkTreePath *tpath; | |
| 615 GtkTreeIter iter; | |
| 616 FileData *fd = NULL; | |
| 617 | |
| 618 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(vdl->listview), x, y, | |
| 619 &tpath, NULL, NULL, NULL)) | |
| 620 { | |
| 621 GtkTreeModel *store; | |
| 622 | |
| 623 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdl->listview)); | |
| 624 gtk_tree_model_get_iter(store, &iter, tpath); | |
| 625 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1); | |
| 626 gtk_tree_path_free(tpath); | |
| 627 } | |
| 628 | |
| 629 if (fd != vdl->drop_fd) | |
| 630 { | |
| 631 vdlist_color_set(vdl, vdl->drop_fd, FALSE); | |
| 632 vdlist_color_set(vdl, fd, TRUE); | |
| 633 } | |
| 634 | |
| 635 vdl->drop_fd = fd; | |
| 636 } | |
| 637 | |
| 638 static void vdlist_dnd_drop_scroll_cancel(ViewDirList *vdl) | |
| 639 { | |
| 640 if (vdl->drop_scroll_id != -1) g_source_remove(vdl->drop_scroll_id); | |
| 641 vdl->drop_scroll_id = -1; | |
| 642 } | |
| 643 | |
| 644 static gint vdlist_auto_scroll_idle_cb(gpointer data) | |
| 645 { | |
| 646 ViewDirList *vdl = data; | |
| 647 | |
| 648 if (vdl->drop_fd) | |
| 649 { | |
| 650 GdkWindow *window; | |
| 651 gint x, y; | |
| 652 gint w, h; | |
| 653 | |
| 654 window = vdl->listview->window; | |
| 655 gdk_window_get_pointer(window, &x, &y, NULL); | |
| 656 gdk_drawable_get_size(window, &w, &h); | |
| 657 if (x >= 0 && x < w && y >= 0 && y < h) | |
| 658 { | |
| 659 vdlist_drop_update(vdl, x, y); | |
| 660 } | |
| 661 } | |
| 662 | |
| 663 vdl->drop_scroll_id = -1; | |
| 664 return FALSE; | |
| 665 } | |
| 666 | |
| 667 static gint vdlist_auto_scroll_notify_cb(GtkWidget *widget, gint x, gint y, gpointer data) | |
| 668 { | |
| 669 ViewDirList *vdl = data; | |
| 670 | |
| 671 if (!vdl->drop_fd || vdl->drop_list) return FALSE; | |
| 672 | |
| 673 if (vdl->drop_scroll_id == -1) vdl->drop_scroll_id = g_idle_add(vdlist_auto_scroll_idle_cb, vdl); | |
| 674 | |
| 675 return TRUE; | |
| 676 } | |
| 677 | |
| 678 static gint vdlist_dnd_drop_motion(GtkWidget *widget, GdkDragContext *context, | |
| 679 gint x, gint y, guint time, gpointer data) | |
| 680 { | |
| 681 ViewDirList *vdl = data; | |
| 682 | |
| 683 vdl->click_fd = NULL; | |
| 684 | |
| 685 if (gtk_drag_get_source_widget(context) == vdl->listview) | |
| 686 { | |
| 687 /* from same window */ | |
| 688 gdk_drag_status(context, 0, time); | |
| 689 return TRUE; | |
| 690 } | |
| 691 else | |
| 692 { | |
| 693 gdk_drag_status(context, context->suggested_action, time); | |
| 694 } | |
| 695 | |
| 696 vdlist_drop_update(vdl, x, y); | |
| 697 | |
| 698 if (vdl->drop_fd) | |
| 699 { | |
| 700 GtkAdjustment *adj = gtk_tree_view_get_vadjustment(GTK_TREE_VIEW(vdl->listview)); | |
| 701 widget_auto_scroll_start(vdl->listview, adj, -1, -1, vdlist_auto_scroll_notify_cb, vdl); | |
| 702 } | |
| 703 | |
| 704 return FALSE; | |
| 705 } | |
| 706 | |
| 707 static void vdlist_dnd_drop_leave(GtkWidget *widget, GdkDragContext *context, guint time, gpointer data) | |
| 708 { | |
| 709 ViewDirList *vdl = data; | |
| 710 | |
| 711 if (vdl->drop_fd != vdl->click_fd) vdlist_color_set(vdl, vdl->drop_fd, FALSE); | |
| 712 | |
| 713 vdl->drop_fd = NULL; | |
| 714 } | |
| 715 | |
| 716 static void vdlist_dnd_init(ViewDirList *vdl) | |
| 717 { | |
| 718 gtk_drag_source_set(vdl->listview, GDK_BUTTON1_MASK | GDK_BUTTON2_MASK, | |
| 719 dnd_file_drag_types, dnd_file_drag_types_count, | |
| 720 GDK_ACTION_COPY | GDK_ACTION_MOVE | GDK_ACTION_LINK); | |
| 721 g_signal_connect(G_OBJECT(vdl->listview), "drag_data_get", | |
| 722 G_CALLBACK(vdlist_dnd_get), vdl); | |
| 723 g_signal_connect(G_OBJECT(vdl->listview), "drag_begin", | |
| 724 G_CALLBACK(vdlist_dnd_begin), vdl); | |
| 725 g_signal_connect(G_OBJECT(vdl->listview), "drag_end", | |
| 726 G_CALLBACK(vdlist_dnd_end), vdl); | |
| 727 | |
| 728 vdlist_dest_set(vdl, TRUE); | |
| 729 g_signal_connect(G_OBJECT(vdl->listview), "drag_data_received", | |
| 730 G_CALLBACK(vdlist_dnd_drop_receive), vdl); | |
| 731 g_signal_connect(G_OBJECT(vdl->listview), "drag_motion", | |
| 732 G_CALLBACK(vdlist_dnd_drop_motion), vdl); | |
| 733 g_signal_connect(G_OBJECT(vdl->listview), "drag_leave", | |
| 734 G_CALLBACK(vdlist_dnd_drop_leave), vdl); | |
| 735 } | |
| 736 | |
| 737 /* | |
| 738 *----------------------------------------------------------------------------- | |
| 739 * main | |
| 740 *----------------------------------------------------------------------------- | |
| 741 */ | |
| 742 | |
| 743 static void vdlist_select_row(ViewDirList *vdl, FileData *fd) | |
| 744 { | |
| 745 if (fd && vdl->select_func) | |
| 746 { | |
| 747 gchar *path; | |
| 748 | |
| 749 path = g_strdup(fd->path); | |
| 750 vdl->select_func(vdl, path, vdl->select_data); | |
| 751 g_free(path); | |
| 752 } | |
| 753 } | |
| 754 | |
| 755 const gchar *vdlist_row_get_path(ViewDirList *vdl, gint row) | |
| 756 { | |
| 757 FileData *fd; | |
| 758 | |
| 759 fd = g_list_nth_data(vdl->list, row); | |
| 760 | |
| 761 if (fd) return fd->path; | |
| 762 | |
| 763 return NULL; | |
| 764 } | |
| 765 | |
| 766 static void vdlist_populate(ViewDirList *vdl) | |
| 767 { | |
| 768 GtkListStore *store; | |
| 769 GList *work; | |
| 770 | |
| 771 store = GTK_LIST_STORE(gtk_tree_view_get_model(GTK_TREE_VIEW(vdl->listview))); | |
| 772 gtk_list_store_clear(store); | |
| 773 | |
| 774 work = vdl->list; | |
| 775 while (work) | |
| 776 { | |
| 777 FileData *fd; | |
| 778 GtkTreeIter iter; | |
| 779 GdkPixbuf *pixbuf; | |
| 780 | |
| 781 fd = work->data; | |
| 782 | |
| 783 if (access_file(fd->path, R_OK | X_OK) && fd->name) | |
| 784 { | |
| 785 if (fd->name[0] == '.' && fd->name[1] == '\0') | |
| 786 { | |
| 787 pixbuf = vdl->pf->open; | |
| 788 } | |
| 789 else if (fd->name[0] == '.' && fd->name[1] == '.' && fd->name[2] == '\0') | |
| 790 { | |
| 791 pixbuf = vdl->pf->parent; | |
| 792 } | |
| 793 else | |
| 794 { | |
| 795 pixbuf = vdl->pf->close; | |
| 796 } | |
| 797 } | |
| 798 else | |
| 799 { | |
| 800 pixbuf = vdl->pf->deny; | |
| 801 } | |
| 802 | |
| 803 gtk_list_store_append(store, &iter); | |
| 804 gtk_list_store_set(store, &iter, | |
| 805 DIR_COLUMN_POINTER, fd, | |
| 806 DIR_COLUMN_ICON, pixbuf, | |
| 807 DIR_COLUMN_NAME, fd->name, -1); | |
| 808 | |
| 809 work = work->next; | |
| 810 } | |
| 811 | |
| 812 vdl->click_fd = NULL; | |
| 813 vdl->drop_fd = NULL; | |
| 814 } | |
| 815 | |
| 816 gint vdlist_set_path(ViewDirList *vdl, const gchar *path) | |
| 817 { | |
| 818 gint ret; | |
| 819 FileData *fd; | |
| 820 gchar *old_path = NULL; | |
| 821 | |
| 822 if (!path) return FALSE; | |
| 823 if (vdl->path && strcmp(path, vdl->path) == 0) return TRUE; | |
| 824 | |
| 825 if (vdl->path) | |
| 826 { | |
| 827 gchar *base; | |
| 828 | |
| 829 base = remove_level_from_path(vdl->path); | |
| 830 if (strcmp(base, path) == 0) | |
| 831 { | |
| 832 old_path = g_strdup(filename_from_path(vdl->path)); | |
| 833 } | |
| 834 g_free(base); | |
| 835 } | |
| 836 | |
| 837 g_free(vdl->path); | |
| 838 vdl->path = g_strdup(path); | |
| 839 | |
| 840 filelist_free(vdl->list); | |
| 841 vdl->list = NULL; | |
| 842 | |
| 843 ret = filelist_read(vdl->path, NULL, &vdl->list); | |
| 844 | |
| 845 vdl->list = filelist_sort(vdl->list, SORT_NAME, TRUE); | |
| 846 | |
| 847 /* add . and .. */ | |
| 848 | |
| 849 if (strcmp(vdl->path, "/") != 0) | |
| 850 { | |
| 851 fd = g_new0(FileData, 1); | |
| 852 fd->path = remove_level_from_path(vdl->path); | |
| 853 fd->name = ".."; | |
| 854 vdl->list = g_list_prepend(vdl->list, fd); | |
| 855 } | |
| 856 | |
| 857 fd = g_new0(FileData, 1); | |
| 858 fd->path = g_strdup(vdl->path); | |
| 859 fd->name = "."; | |
| 860 vdl->list = g_list_prepend(vdl->list, fd); | |
| 861 | |
| 862 vdlist_populate(vdl); | |
| 863 | |
| 864 if (old_path) | |
| 865 { | |
| 866 /* scroll to make last path visible */ | |
| 867 FileData *found = NULL; | |
| 868 GList *work; | |
| 869 | |
| 870 work = vdl->list; | |
| 871 while (work && !found) | |
| 872 { | |
| 873 FileData *fd = work->data; | |
| 874 if (strcmp(old_path, fd->name) == 0) found = fd; | |
| 875 work = work->next; | |
| 876 } | |
| 877 | |
| 878 if (found) vdlist_scroll_to_row(vdl, found, 0.5); | |
| 879 | |
| 880 g_free(old_path); | |
| 881 return ret; | |
| 882 } | |
| 883 | |
| 884 if (GTK_WIDGET_REALIZED(vdl->listview)) | |
| 885 { | |
| 886 gtk_tree_view_scroll_to_point(GTK_TREE_VIEW(vdl->listview), 0, 0); | |
| 887 } | |
| 888 | |
| 889 return ret; | |
| 890 } | |
| 891 | |
| 892 void vdlist_refresh(ViewDirList *vdl) | |
| 893 { | |
| 894 gchar *path; | |
| 895 | |
| 896 path = g_strdup(vdl->path); | |
| 897 vdl->path = NULL; | |
| 898 vdlist_set_path(vdl, path); | |
| 899 g_free(path); | |
| 900 } | |
| 901 | |
| 902 static void vdlist_menu_position_cb(GtkMenu *menu, gint *x, gint *y, gboolean *push_in, gpointer data) | |
| 903 { | |
| 904 ViewDirList *vdl = data; | |
| 905 GtkTreeModel *store; | |
| 906 GtkTreeIter iter; | |
| 907 GtkTreePath *tpath; | |
| 908 gint cw, ch; | |
| 909 | |
| 910 if (vdlist_find_row(vdl, vdl->click_fd, &iter) < 0) return; | |
| 911 store = gtk_tree_view_get_model(GTK_TREE_VIEW(vdl->listview)); | |
| 912 tpath = gtk_tree_model_get_path(store, &iter); | |
| 913 tree_view_get_cell_clamped(GTK_TREE_VIEW(vdl->listview), tpath, 0, TRUE, x, y, &cw, &ch); | |
| 914 gtk_tree_path_free(tpath); | |
| 915 *y += ch; | |
| 916 popup_menu_position_clamp(menu, x, y, 0); | |
| 917 } | |
| 918 | |
| 919 static gint vdlist_press_key_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) | |
| 920 { | |
| 921 ViewDirList *vdl = data; | |
| 922 GtkTreePath *tpath; | |
| 923 | |
| 924 if (event->keyval != GDK_Menu) return FALSE; | |
| 925 | |
| 926 gtk_tree_view_get_cursor(GTK_TREE_VIEW(vdl->listview), &tpath, NULL); | |
| 927 if (tpath) | |
| 928 { | |
| 929 GtkTreeModel *store; | |
| 930 GtkTreeIter iter; | |
| 931 | |
| 932 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
| 933 gtk_tree_model_get_iter(store, &iter, tpath); | |
| 934 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &vdl->click_fd, -1); | |
| 935 | |
| 936 gtk_tree_path_free(tpath); | |
| 937 } | |
| 938 else | |
| 939 { | |
| 940 vdl->click_fd = NULL; | |
| 941 } | |
| 942 | |
| 943 vdlist_color_set(vdl, vdl->click_fd, TRUE); | |
| 944 | |
| 945 vdl->popup = vdlist_pop_menu(vdl, vdl->click_fd); | |
| 946 | |
| 947 gtk_menu_popup(GTK_MENU(vdl->popup), NULL, NULL, vdlist_menu_position_cb, vdl, 0, GDK_CURRENT_TIME); | |
| 948 | |
| 949 return TRUE; | |
| 950 } | |
| 951 | |
| 952 static gint vdlist_press_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
| 953 { | |
| 954 ViewDirList *vdl = data; | |
| 955 GtkTreePath *tpath; | |
| 956 GtkTreeIter iter; | |
| 957 FileData *fd = NULL; | |
| 958 | |
| 959 if (gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | |
| 960 &tpath, NULL, NULL, NULL)) | |
| 961 { | |
| 962 GtkTreeModel *store; | |
| 963 | |
| 964 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
| 965 gtk_tree_model_get_iter(store, &iter, tpath); | |
| 966 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1); | |
| 967 gtk_tree_view_set_cursor(GTK_TREE_VIEW(widget), tpath, NULL, FALSE); | |
| 968 gtk_tree_path_free(tpath); | |
| 969 } | |
| 970 | |
| 971 vdl->click_fd = fd; | |
| 972 vdlist_color_set(vdl, vdl->click_fd, TRUE); | |
| 973 | |
| 974 if (bevent->button == 3) | |
| 975 { | |
| 976 vdl->popup = vdlist_pop_menu(vdl, vdl->click_fd); | |
| 977 gtk_menu_popup(GTK_MENU(vdl->popup), NULL, NULL, NULL, NULL, | |
| 978 bevent->button, bevent->time); | |
| 979 } | |
| 980 | |
| 981 return TRUE; | |
| 982 } | |
| 983 | |
| 984 static gint vdlist_release_cb(GtkWidget *widget, GdkEventButton *bevent, gpointer data) | |
| 985 { | |
| 986 ViewDirList *vdl = data; | |
| 987 GtkTreePath *tpath; | |
| 988 GtkTreeIter iter; | |
| 989 FileData *fd = NULL; | |
| 990 | |
| 991 vdlist_color_set(vdl, vdl->click_fd, FALSE); | |
| 992 | |
| 993 if (bevent->button != 1) return TRUE; | |
| 994 | |
| 995 if ((bevent->x != 0 || bevent->y != 0) && | |
| 996 gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(widget), bevent->x, bevent->y, | |
| 997 &tpath, NULL, NULL, NULL)) | |
| 998 { | |
| 999 GtkTreeModel *store; | |
| 1000 | |
| 1001 store = gtk_tree_view_get_model(GTK_TREE_VIEW(widget)); | |
| 1002 gtk_tree_model_get_iter(store, &iter, tpath); | |
| 1003 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1); | |
| 1004 gtk_tree_path_free(tpath); | |
| 1005 } | |
| 1006 | |
| 1007 if (fd && vdl->click_fd == fd) | |
| 1008 { | |
| 1009 vdlist_select_row(vdl, vdl->click_fd); | |
| 1010 } | |
| 1011 | |
| 1012 return TRUE; | |
| 1013 } | |
| 1014 | |
| 1015 static void vdlist_select_cb(GtkTreeView *tview, GtkTreePath *tpath, GtkTreeViewColumn *column, gpointer data) | |
| 1016 { | |
| 1017 ViewDirList *vdl = data; | |
| 1018 GtkTreeModel *store; | |
| 1019 GtkTreeIter iter; | |
| 1020 FileData *fd; | |
| 1021 | |
| 1022 store = gtk_tree_view_get_model(tview); | |
| 1023 gtk_tree_model_get_iter(store, &iter, tpath); | |
| 1024 gtk_tree_model_get(store, &iter, DIR_COLUMN_POINTER, &fd, -1); | |
| 1025 | |
| 1026 vdlist_select_row(vdl, fd); | |
| 1027 } | |
| 1028 | |
| 1029 static GdkColor *vdlist_color_shifted(GtkWidget *widget) | |
| 1030 { | |
| 1031 static GdkColor color; | |
| 1032 static GtkWidget *done = NULL; | |
| 1033 | |
| 1034 if (done != widget) | |
| 1035 { | |
| 1036 GtkStyle *style; | |
| 1037 | |
| 1038 style = gtk_widget_get_style(widget); | |
| 1039 memcpy(&color, &style->base[GTK_STATE_NORMAL], sizeof(color)); | |
| 1040 shift_color(&color, -1, 0); | |
| 1041 done = widget; | |
| 1042 } | |
| 1043 | |
| 1044 return &color; | |
| 1045 } | |
| 1046 | |
| 1047 static void vdlist_color_cb(GtkTreeViewColumn *tree_column, GtkCellRenderer *cell, | |
| 1048 GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data) | |
| 1049 { | |
| 1050 ViewDirList *vdl = data; | |
| 1051 gboolean set; | |
| 1052 | |
| 1053 gtk_tree_model_get(tree_model, iter, DIR_COLUMN_COLOR, &set, -1); | |
| 1054 g_object_set(G_OBJECT(cell), | |
| 1055 "cell-background-gdk", vdlist_color_shifted(vdl->listview), | |
| 1056 "cell-background-set", set, NULL); | |
| 1057 } | |
| 1058 | |
| 1059 static void vdlist_destroy_cb(GtkWidget *widget, gpointer data) | |
| 1060 { | |
| 1061 ViewDirList *vdl = data; | |
| 1062 | |
| 1063 if (vdl->popup) | |
| 1064 { | |
| 1065 g_signal_handlers_disconnect_matched(G_OBJECT(vdl->popup), G_SIGNAL_MATCH_DATA, | |
| 1066 0, 0, 0, NULL, vdl); | |
| 1067 gtk_widget_destroy(vdl->popup); | |
| 1068 } | |
| 1069 | |
| 1070 vdlist_dnd_drop_scroll_cancel(vdl); | |
| 1071 widget_auto_scroll_stop(vdl->listview); | |
| 1072 | |
| 1073 path_list_free(vdl->drop_list); | |
| 1074 | |
| 1075 folder_icons_free(vdl->pf); | |
| 1076 | |
| 1077 g_free(vdl->path); | |
| 1078 filelist_free(vdl->list); | |
| 1079 g_free(vdl); | |
| 1080 } | |
| 1081 | |
| 1082 ViewDirList *vdlist_new(const gchar *path) | |
| 1083 { | |
| 1084 ViewDirList *vdl; | |
| 1085 GtkListStore *store; | |
| 1086 GtkTreeSelection *selection; | |
| 1087 GtkTreeViewColumn *column; | |
| 1088 GtkCellRenderer *renderer; | |
| 1089 | |
| 1090 vdl = g_new0(ViewDirList, 1); | |
| 1091 | |
| 1092 vdl->path = NULL; | |
| 1093 vdl->list = NULL; | |
| 1094 vdl->click_fd = NULL; | |
| 1095 | |
| 1096 vdl->drop_fd = NULL; | |
| 1097 vdl->drop_list = NULL; | |
| 1098 | |
| 1099 vdl->drop_scroll_id = -1; | |
| 1100 | |
| 1101 vdl->popup = NULL; | |
| 1102 | |
| 1103 vdl->widget = gtk_scrolled_window_new(NULL, NULL); | |
| 1104 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(vdl->widget), GTK_SHADOW_IN); | |
| 1105 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(vdl->widget), | |
| 1106 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | |
| 1107 g_signal_connect(G_OBJECT(vdl->widget), "destroy", | |
| 1108 G_CALLBACK(vdlist_destroy_cb), vdl); | |
| 1109 | |
| 1110 store = gtk_list_store_new(4, G_TYPE_POINTER, GDK_TYPE_PIXBUF, G_TYPE_STRING, G_TYPE_BOOLEAN); | |
| 1111 vdl->listview = gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)); | |
| 1112 g_object_unref(store); | |
| 1113 | |
| 1114 gtk_tree_view_set_headers_visible(GTK_TREE_VIEW(vdl->listview), FALSE); | |
| 1115 gtk_tree_view_set_enable_search(GTK_TREE_VIEW(vdl->listview), FALSE); | |
| 1116 g_signal_connect(G_OBJECT(vdl->listview), "row_activated", | |
| 1117 | |
| 1118 G_CALLBACK(vdlist_select_cb), vdl); | |
| 1119 | |
| 1120 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(vdl->listview)); | |
| 1121 gtk_tree_selection_set_mode(selection, GTK_SELECTION_NONE); | |
| 1122 | |
| 1123 column = gtk_tree_view_column_new(); | |
| 1124 gtk_tree_view_column_set_sizing(column, GTK_TREE_VIEW_COLUMN_AUTOSIZE); | |
| 1125 | |
| 1126 renderer = gtk_cell_renderer_pixbuf_new(); | |
| 1127 gtk_tree_view_column_pack_start(column, renderer, FALSE); | |
| 1128 gtk_tree_view_column_add_attribute(column, renderer, "pixbuf", DIR_COLUMN_ICON); | |
| 1129 gtk_tree_view_column_set_cell_data_func(column, renderer, vdlist_color_cb, vdl, NULL); | |
| 1130 | |
| 1131 renderer = gtk_cell_renderer_text_new(); | |
| 1132 gtk_tree_view_column_pack_start(column, renderer, TRUE); | |
| 1133 gtk_tree_view_column_add_attribute(column, renderer, "text", DIR_COLUMN_NAME); | |
| 1134 gtk_tree_view_column_set_cell_data_func(column, renderer, vdlist_color_cb, vdl, NULL); | |
| 1135 | |
| 1136 gtk_tree_view_append_column(GTK_TREE_VIEW(vdl->listview), column); | |
| 1137 | |
| 1138 g_signal_connect(G_OBJECT(vdl->listview), "key_press_event", | |
| 1139 G_CALLBACK(vdlist_press_key_cb), vdl); | |
| 1140 gtk_container_add(GTK_CONTAINER(vdl->widget), vdl->listview); | |
| 1141 gtk_widget_show(vdl->listview); | |
| 1142 | |
| 1143 vdl->pf = folder_icons_new(); | |
| 1144 | |
| 1145 vdlist_dnd_init(vdl); | |
| 1146 | |
| 1147 g_signal_connect(G_OBJECT(vdl->listview), "button_press_event", | |
| 1148 G_CALLBACK(vdlist_press_cb), vdl); | |
| 1149 g_signal_connect(G_OBJECT(vdl->listview), "button_release_event", | |
| 1150 G_CALLBACK(vdlist_release_cb), vdl); | |
| 1151 | |
| 1152 if (path) vdlist_set_path(vdl, path); | |
| 1153 | |
| 1154 return vdl; | |
| 1155 } | |
| 1156 | |
| 1157 void vdlist_set_select_func(ViewDirList *vdl, | |
| 1158 void (*func)(ViewDirList *vdl, const gchar *path, gpointer data), gpointer data) | |
| 1159 { | |
| 1160 vdl->select_func = func; | |
| 1161 vdl->select_data = data; | |
| 1162 } | |
| 1163 | |
| 1164 void vdlist_set_layout(ViewDirList *vdl, LayoutWindow *layout) | |
| 1165 { | |
| 1166 vdl->layout = layout; | |
| 1167 } | |
| 1168 |
