]> gitweb.factorcode.org Git - factor.git/blob - extra/file-picker/linux/linux.factor
9ad1138c75c1afc42a51393adda29fdf6615cf43
[factor.git] / extra / file-picker / linux / linux.factor
1 USING: alien.c-types alien.data alien.strings alien.syntax
2 destructors file-picker gobject-introspection.standard-types
3 gtk.ffi io.encodings.string io.encodings.utf8 kernel system ;
4 IN: file-picker.linux
5
6 <PRIVATE
7
8 LIBRARY: gtk
9
10 FUNCTION: GtkWidget* gtk_file_chooser_dialog_new (
11     gchar* title,
12     GtkWindow* parent,
13     GtkFileChooserAction action,
14     gchar* first_button_text,
15     gint* first_button_response,
16     gchar* second_button_text,
17     gint* second_button_response,
18     void* sentinel ) ;
19
20 : <gtk-file-chooser-dialog> ( title action -- dialog )
21     [
22         utf8 encode
23         f
24         GTK_FILE_CHOOSER_ACTION_OPEN
25         "Cancel" utf8 encode
26         GTK_RESPONSE_CANCEL int <ref>
27     ] [
28         utf8 encode
29         GTK_RESPONSE_ACCEPT int <ref>
30         f
31         gtk_file_chooser_dialog_new
32         &gtk_widget_destroy
33     ] bi* ;
34
35 : run-and-get-filename ( dialog -- path/f )
36     dup gtk_dialog_run GTK_RESPONSE_ACCEPT = [
37         gtk_file_chooser_get_filename alien>native-string
38     ] [
39         drop f
40     ] if ;
41
42 PRIVATE>
43
44 M: linux open-file-dialog
45     [
46         "Open File" "Open" <gtk-file-chooser-dialog>
47         run-and-get-filename
48     ] with-destructors ;
49
50 M: linux save-file-dialog
51     [
52         "Save File" "Save" <gtk-file-chooser-dialog>
53         dup t gtk_file_chooser_set_do_overwrite_confirmation
54         dup rot gtk_file_chooser_set_filename drop
55         run-and-get-filename
56     ] with-destructors ;