Mercurial > geeqie.yaz
annotate src/ui_utildlg.c @ 1094:42b5543ab965
Remove reference to numbered section.
author | zas_ |
---|---|
date | Thu, 06 Nov 2008 23:49:31 +0000 |
parents | 1646720364cf |
children | 0bea79d87065 |
rev | line source |
---|---|
9 | 1 /* |
2 * (SLIK) SimpLIstic sKin functions | |
3 * (C) 2004 John Ellis | |
475 | 4 * Copyright (C) 2008 The Geeqie Team |
9 | 5 * |
6 * Author: John Ellis | |
7 * | |
8 * This software is released under the GNU General Public License (GNU GPL). | |
9 * Please read the included file COPYING for more information. | |
10 * This software comes with no warranty of any kind, use at your own risk! | |
11 */ | |
12 | |
13 #ifdef HAVE_CONFIG_H | |
14 # include "config.h" | |
15 #endif | |
16 #include "intl.h" | |
17 | |
18 #include <stdio.h> | |
19 #include <stdlib.h> | |
20 #include <string.h> | |
21 #include <sys/types.h> | |
22 #include <gtk/gtk.h> | |
23 | |
24 #include <gdk/gdkkeysyms.h> /* for keyboard values */ | |
25 | |
281 | 26 #include "main.h" |
9 | 27 #include "ui_utildlg.h" |
28 | |
586 | 29 #include "filedata.h" |
9 | 30 #include "ui_fileops.h" |
31 #include "ui_misc.h" | |
32 #include "ui_pathsel.h" | |
33 #include "ui_tabcomp.h" | |
648
e34c1002e553
Move some functions from main.[ch] to new window.[ch].
zas_
parents:
586
diff
changeset
|
34 #include "window.h" |
9 | 35 |
36 /* | |
37 *----------------------------------------------------------------------------- | |
38 * generic dialog | |
39 *----------------------------------------------------------------------------- | |
442 | 40 */ |
9 | 41 |
42 void generic_dialog_close(GenericDialog *gd) | |
43 { | |
44 gtk_widget_destroy(gd->dialog); | |
45 g_free(gd); | |
46 } | |
47 | |
48 static void generic_dialog_click_cb(GtkWidget *widget, gpointer data) | |
49 { | |
50 GenericDialog *gd = data; | |
51 void (*func)(GenericDialog *, gpointer); | |
52 gint auto_close; | |
53 | |
54 func = g_object_get_data(G_OBJECT(widget), "dialog_function"); | |
55 auto_close = gd->auto_close; | |
56 | |
57 if (func) func(gd, gd->data); | |
58 if (auto_close) generic_dialog_close(gd); | |
59 } | |
60 | |
61 static gint generic_dialog_default_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) | |
62 { | |
63 GenericDialog *gd = data; | |
64 | |
65 if (event->keyval == GDK_Return && GTK_WIDGET_HAS_FOCUS(widget) | |
66 && gd->default_cb) | |
67 { | |
68 gint auto_close; | |
69 | |
70 auto_close = gd->auto_close; | |
71 gd->default_cb(gd, gd->data); | |
72 if (auto_close) generic_dialog_close(gd); | |
73 | |
74 return TRUE; | |
75 } | |
76 return FALSE; | |
77 } | |
78 | |
79 void generic_dialog_attach_default(GenericDialog *gd, GtkWidget *widget) | |
80 { | |
81 if (!gd || !widget) return; | |
82 g_signal_connect(G_OBJECT(widget), "key_press_event", | |
83 G_CALLBACK(generic_dialog_default_key_press_cb), gd); | |
84 } | |
85 | |
86 static gint generic_dialog_key_press_cb(GtkWidget *widget, GdkEventKey *event, gpointer data) | |
87 { | |
88 GenericDialog *gd = data; | |
89 | |
90 if (event->keyval == GDK_Escape) | |
91 { | |
92 if (gd->cancel_cb) gd->cancel_cb(gd, gd->data); | |
93 if (gd->auto_close) generic_dialog_click_cb(widget, data); | |
94 return TRUE; | |
95 } | |
96 return FALSE; | |
97 } | |
98 | |
99 static gint generic_dialog_delete_cb(GtkWidget *w, GdkEventAny *event, gpointer data) | |
100 { | |
101 GenericDialog *gd = data; | |
102 gint auto_close; | |
103 | |
104 auto_close = gd->auto_close; | |
105 | |
106 if (gd->cancel_cb) gd->cancel_cb(gd, gd->data); | |
107 if (auto_close) generic_dialog_close(gd); | |
108 | |
109 return TRUE; | |
110 } | |
111 | |
112 static void generic_dialog_show_cb(GtkWidget *widget, gpointer data) | |
113 { | |
114 GenericDialog *gd = data; | |
115 if (gd->cancel_button) | |
442 | 116 { |
9 | 117 gtk_box_reorder_child(GTK_BOX(gd->hbox), gd->cancel_button, -1); |
118 } | |
119 | |
120 g_signal_handlers_disconnect_by_func(G_OBJECT(widget), | |
121 G_CALLBACK(generic_dialog_show_cb), gd); | |
122 } | |
123 | |
124 gint generic_dialog_get_alternative_button_order(GtkWidget *widget) | |
125 { | |
126 GtkSettings *settings; | |
127 GObjectClass *klass; | |
128 gint alternative_order = FALSE; | |
129 | |
130 settings = gtk_settings_get_for_screen(gtk_widget_get_screen(widget)); | |
131 klass = G_OBJECT_CLASS(GTK_SETTINGS_GET_CLASS(settings)); | |
132 if (g_object_class_find_property(klass, "gtk-alternative-button-order")) | |
133 { | |
134 g_object_get(settings, "gtk-alternative-button-order", &alternative_order, NULL); | |
135 } | |
136 | |
137 return alternative_order; | |
138 } | |
139 | |
140 GtkWidget *generic_dialog_add_button(GenericDialog *gd, const gchar *stock_id, const gchar *text, | |
141 void (*func_cb)(GenericDialog *, gpointer), gint is_default) | |
142 { | |
143 GtkWidget *button; | |
144 gint alternative_order; | |
145 | |
146 button = pref_button_new(NULL, stock_id, text, FALSE, | |
147 G_CALLBACK(generic_dialog_click_cb), gd); | |
148 | |
512
f9bf33be53ff
Remove whitespace between function name and first parenthesis for the sake of consistency.
zas_
parents:
475
diff
changeset
|
149 GTK_WIDGET_SET_FLAGS(button, GTK_CAN_DEFAULT); |
9 | 150 g_object_set_data(G_OBJECT(button), "dialog_function", func_cb); |
151 | |
152 gtk_container_add(GTK_CONTAINER(gd->hbox), button); | |
153 | |
154 alternative_order = generic_dialog_get_alternative_button_order(gd->hbox); | |
155 | |
156 if (is_default) | |
157 { | |
158 gtk_widget_grab_default(button); | |
159 gtk_widget_grab_focus(button); | |
160 gd->default_cb = func_cb; | |
161 | |
162 if (!alternative_order) gtk_box_reorder_child(GTK_BOX(gd->hbox), button, -1); | |
163 } | |
164 else | |
165 { | |
166 if (!alternative_order) gtk_box_reorder_child(GTK_BOX(gd->hbox), button, 0); | |
167 } | |
168 | |
169 gtk_widget_show(button); | |
170 | |
171 return button; | |
172 } | |
173 | |
174 GtkWidget *generic_dialog_add_message(GenericDialog *gd, const gchar *icon_stock_id, | |
175 const gchar *heading, const gchar *text) | |
176 { | |
177 GtkWidget *hbox; | |
178 GtkWidget *vbox; | |
179 GtkWidget *label; | |
180 | |
181 hbox = pref_box_new(gd->vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE); | |
182 if (icon_stock_id) | |
183 { | |
184 GtkWidget *image; | |
185 | |
186 image = gtk_image_new_from_stock(icon_stock_id, GTK_ICON_SIZE_DIALOG); | |
187 gtk_misc_set_alignment(GTK_MISC(image), 0.5, 0.0); | |
188 gtk_box_pack_start(GTK_BOX(hbox), image, FALSE, FALSE, 0); | |
189 gtk_widget_show(image); | |
190 } | |
191 | |
192 vbox = pref_box_new(hbox, TRUE, GTK_ORIENTATION_VERTICAL, PREF_PAD_SPACE); | |
193 if (heading) | |
194 { | |
195 label = pref_label_new(vbox, heading); | |
196 pref_label_bold(label, TRUE, TRUE); | |
197 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); | |
198 } | |
199 if (text) | |
200 { | |
201 label = pref_label_new(vbox, text); | |
202 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5); | |
15
3263965d5f9e
##### Note: GQview CVS on sourceforge is not always up to date, please use #####
gqview
parents:
9
diff
changeset
|
203 gtk_label_set_line_wrap(GTK_LABEL(label), TRUE); |
9 | 204 } |
205 | |
206 return vbox; | |
207 } | |
208 | |
209 static void generic_dialog_setup(GenericDialog *gd, | |
210 const gchar *title, | |
211 const gchar *wmclass, const gchar *wmsubclass, | |
212 GtkWidget *parent, gint auto_close, | |
213 void (*cancel_cb)(GenericDialog *, gpointer), gpointer data) | |
214 { | |
215 GtkWidget *vbox; | |
216 | |
217 gd->auto_close = auto_close; | |
218 gd->data = data; | |
219 gd->cancel_cb = cancel_cb; | |
220 | |
289
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
281
diff
changeset
|
221 gd->dialog = window_new(GTK_WINDOW_TOPLEVEL, wmsubclass, NULL, NULL, title); |
9 | 222 gtk_window_set_type_hint(GTK_WINDOW(gd->dialog), GDK_WINDOW_TYPE_HINT_DIALOG); |
289
6a7298988a7a
Simplify and unify gtk_window creation with the help of
zas_
parents:
281
diff
changeset
|
223 |
9 | 224 if (parent) |
225 { | |
226 GtkWindow *window = NULL; | |
227 | |
228 if (GTK_IS_WINDOW(parent)) | |
229 { | |
230 window = GTK_WINDOW(parent); | |
231 } | |
232 else | |
233 { | |
234 GtkWidget *top; | |
235 | |
236 top = gtk_widget_get_toplevel(parent); | |
237 if (GTK_IS_WINDOW(top) && GTK_WIDGET_TOPLEVEL(top)) window = GTK_WINDOW(top); | |
238 } | |
239 | |
240 if (window) gtk_window_set_transient_for(GTK_WINDOW(gd->dialog), window); | |
241 } | |
242 | |
243 g_signal_connect(G_OBJECT(gd->dialog), "delete_event", | |
244 G_CALLBACK(generic_dialog_delete_cb), gd); | |
245 g_signal_connect(G_OBJECT(gd->dialog), "key_press_event", | |
246 G_CALLBACK(generic_dialog_key_press_cb), gd); | |
247 | |
248 gtk_window_set_resizable(GTK_WINDOW(gd->dialog), TRUE); | |
249 gtk_container_set_border_width(GTK_CONTAINER(gd->dialog), PREF_PAD_BORDER); | |
250 | |
251 vbox = gtk_vbox_new(FALSE, PREF_PAD_BUTTON_SPACE); | |
252 gtk_container_add(GTK_CONTAINER(gd->dialog), vbox); | |
253 gtk_widget_show(vbox); | |
254 | |
255 gd->vbox = gtk_vbox_new(FALSE, PREF_PAD_GAP); | |
256 gtk_box_pack_start(GTK_BOX(vbox), gd->vbox, TRUE, TRUE, 0); | |
257 gtk_widget_show(gd->vbox); | |
258 | |
259 gd->hbox = gtk_hbutton_box_new(); | |
260 gtk_button_box_set_layout(GTK_BUTTON_BOX(gd->hbox), GTK_BUTTONBOX_END); | |
261 gtk_box_set_spacing(GTK_BOX(gd->hbox), PREF_PAD_BUTTON_GAP); | |
262 gtk_box_pack_start(GTK_BOX(vbox), gd->hbox, FALSE, FALSE, 0); | |
263 gtk_widget_show(gd->hbox); | |
264 | |
265 if (gd->cancel_cb) | |
442 | 266 { |
9 | 267 gd->cancel_button = generic_dialog_add_button(gd, GTK_STOCK_CANCEL, NULL, gd->cancel_cb, TRUE); |
268 } | |
269 else | |
270 { | |
271 gd->cancel_button = NULL; | |
272 } | |
273 | |
274 if (generic_dialog_get_alternative_button_order(gd->hbox)) | |
275 { | |
276 g_signal_connect(G_OBJECT(gd->dialog), "show", | |
277 G_CALLBACK(generic_dialog_show_cb), gd); | |
278 } | |
279 | |
280 gd->default_cb = NULL; | |
281 } | |
282 | |
283 GenericDialog *generic_dialog_new(const gchar *title, | |
284 const gchar *wmclass, const gchar *wmsubclass, | |
285 GtkWidget *parent, gint auto_close, | |
286 void (*cancel_cb)(GenericDialog *, gpointer), gpointer data) | |
287 { | |
288 GenericDialog *gd; | |
289 | |
290 gd = g_new0(GenericDialog, 1); | |
291 generic_dialog_setup(gd, title, wmclass, wmsubclass, | |
292 parent, auto_close, cancel_cb, data); | |
293 return gd; | |
294 } | |
295 /* | |
296 *----------------------------------------------------------------------------- | |
297 * simple warning dialog | |
298 *----------------------------------------------------------------------------- | |
442 | 299 */ |
9 | 300 |
301 static void warning_dialog_ok_cb(GenericDialog *gd, gpointer data) | |
302 { | |
303 /* no op */ | |
304 } | |
305 | |
306 GenericDialog *warning_dialog(const gchar *heading, const gchar *text, | |
307 const gchar *icon_stock_id, GtkWidget *parent) | |
308 { | |
309 GenericDialog *gd; | |
310 | |
254
9faf34f047b1
Make the wmclass value unique among the code by defining
zas_
parents:
232
diff
changeset
|
311 gd = generic_dialog_new(heading, GQ_WMCLASS, "warning", parent, TRUE, NULL, NULL); |
9 | 312 generic_dialog_add_button(gd, GTK_STOCK_OK, NULL, warning_dialog_ok_cb, TRUE); |
313 | |
314 generic_dialog_add_message(gd, icon_stock_id, heading, text); | |
315 | |
316 gtk_widget_show(gd->dialog); | |
317 | |
318 return gd; | |
319 } | |
320 | |
321 /* | |
322 *----------------------------------------------------------------------------- | |
323 * generic file ops dialog routines | |
324 *----------------------------------------------------------------------------- | |
442 | 325 */ |
9 | 326 |
138 | 327 void file_dialog_close(FileDialog *fdlg) |
9 | 328 { |
138 | 329 file_data_unref(fdlg->source_fd); |
330 g_free(fdlg->dest_path); | |
331 if (fdlg->source_list) filelist_free(fdlg->source_list); | |
9 | 332 |
138 | 333 generic_dialog_close(GENERIC_DIALOG(fdlg)); |
9 | 334 } |
335 | |
336 FileDialog *file_dialog_new(const gchar *title, | |
337 const gchar *wmclass, const gchar *wmsubclass, | |
338 GtkWidget *parent, | |
339 void (*cancel_cb)(FileDialog *, gpointer), gpointer data) | |
340 { | |
138 | 341 FileDialog *fdlg = NULL; |
9 | 342 |
138 | 343 fdlg = g_new0(FileDialog, 1); |
9 | 344 |
138 | 345 generic_dialog_setup(GENERIC_DIALOG(fdlg), title, |
9 | 346 wmclass, wmsubclass, parent, FALSE, |
1002 | 347 (gpointer)cancel_cb, data); |
9 | 348 |
138 | 349 return fdlg; |
9 | 350 } |
351 | |
138 | 352 GtkWidget *file_dialog_add_button(FileDialog *fdlg, const gchar *stock_id, const gchar *text, |
9 | 353 void (*func_cb)(FileDialog *, gpointer), gint is_default) |
354 { | |
138 | 355 return generic_dialog_add_button(GENERIC_DIALOG(fdlg), stock_id, text, |
1002 | 356 (gpointer)func_cb, is_default); |
9 | 357 } |
358 | |
359 static void file_dialog_entry_cb(GtkWidget *widget, gpointer data) | |
360 { | |
138 | 361 FileDialog *fdlg = data; |
362 g_free(fdlg->dest_path); | |
363 fdlg->dest_path = remove_trailing_slash(gtk_entry_get_text(GTK_ENTRY(fdlg->entry))); | |
9 | 364 } |
365 | |
366 static void file_dialog_entry_enter_cb(const gchar *path, gpointer data) | |
367 { | |
368 GenericDialog *gd = data; | |
369 | |
370 file_dialog_entry_cb(NULL, data); | |
371 | |
372 if (gd->default_cb) gd->default_cb(gd, gd->data); | |
373 } | |
374 | |
138 | 375 void file_dialog_add_path_widgets(FileDialog *fdlg, const gchar *default_path, const gchar *path, |
9 | 376 const gchar *history_key, const gchar *filter, const gchar *filter_desc) |
377 { | |
378 GtkWidget *tabcomp; | |
379 GtkWidget *list; | |
380 | |
138 | 381 if (fdlg->entry) return; |
9 | 382 |
138 | 383 tabcomp = tab_completion_new_with_history(&fdlg->entry, NULL, |
384 history_key, -1, file_dialog_entry_enter_cb, fdlg); | |
385 gtk_box_pack_end(GTK_BOX(GENERIC_DIALOG(fdlg)->vbox), tabcomp, FALSE, FALSE, 0); | |
386 generic_dialog_attach_default(GENERIC_DIALOG(fdlg), fdlg->entry); | |
9 | 387 gtk_widget_show(tabcomp); |
388 | |
726 | 389 if (path && path[0] == G_DIR_SEPARATOR) |
9 | 390 { |
138 | 391 fdlg->dest_path = g_strdup(path); |
9 | 392 } |
393 else | |
394 { | |
395 const gchar *base; | |
396 | |
138 | 397 base = tab_completion_set_to_last_history(fdlg->entry); |
9 | 398 |
399 if (!base) base = default_path; | |
400 if (!base) base = homedir(); | |
401 | |
402 if (path) | |
403 { | |
702
e07895754e65
Drop concat_dir_and_file() and use g_build_filename() instead.
zas_
parents:
648
diff
changeset
|
404 fdlg->dest_path = g_build_filename(base, path, NULL); |
9 | 405 } |
406 else | |
407 { | |
138 | 408 fdlg->dest_path = g_strdup(base); |
9 | 409 } |
410 } | |
411 | |
138 | 412 list = path_selection_new_with_files(fdlg->entry, fdlg->dest_path, filter, filter_desc); |
413 path_selection_add_select_func(fdlg->entry, file_dialog_entry_enter_cb, fdlg); | |
414 gtk_box_pack_end(GTK_BOX(GENERIC_DIALOG(fdlg)->vbox), list, TRUE, TRUE, 0); | |
9 | 415 gtk_widget_show(list); |
416 | |
138 | 417 gtk_widget_grab_focus(fdlg->entry); |
418 if (fdlg->dest_path) | |
9 | 419 { |
138 | 420 gtk_entry_set_text(GTK_ENTRY(fdlg->entry), fdlg->dest_path); |
421 gtk_editable_set_position(GTK_EDITABLE(fdlg->entry), strlen(fdlg->dest_path)); | |
9 | 422 } |
423 | |
138 | 424 g_signal_connect(G_OBJECT(fdlg->entry), "changed", |
425 G_CALLBACK(file_dialog_entry_cb), fdlg); | |
9 | 426 } |
427 | |
138 | 428 void file_dialog_add_filter(FileDialog *fdlg, const gchar *filter, const gchar *filter_desc, gint set) |
9 | 429 { |
138 | 430 if (!fdlg->entry) return; |
431 path_selection_add_filter(fdlg->entry, filter, filter_desc, set); | |
9 | 432 } |
433 | |
138 | 434 void file_dialog_clear_filter(FileDialog *fdlg) |
9 | 435 { |
138 | 436 if (!fdlg->entry) return; |
437 path_selection_clear_filter(fdlg->entry); | |
9 | 438 } |
439 | |
138 | 440 void file_dialog_sync_history(FileDialog *fdlg, gint dir_only) |
9 | 441 { |
138 | 442 if (!fdlg->dest_path) return; |
9 | 443 |
444 if (!dir_only || | |
138 | 445 (dir_only && isdir(fdlg->dest_path)) ) |
9 | 446 { |
138 | 447 tab_completion_append_to_history(fdlg->entry, fdlg->dest_path); |
9 | 448 } |
449 else | |
450 { | |
138 | 451 gchar *buf = remove_level_from_path(fdlg->dest_path); |
452 tab_completion_append_to_history(fdlg->entry, buf); | |
9 | 453 g_free(buf); |
454 } | |
455 } | |
1055
1646720364cf
Adding a vim modeline to all files - patch by Klaus Ethgen
nadvornik
parents:
1002
diff
changeset
|
456 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */ |