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