1
  
2
  
3
  
4
  
5
  
6
  
7
  
8
  
9
  
10
  
11
  
12
  
13
  
14
  
15
  
16
  
17
  
18
  
19
  
20
  
21
  
22
  
23
  
24
  
25
  
26
  
27
  
28
  
29
  
30
  
31
  
32
  
33
  
34
  
35
  
36
  
37
  
38
  
39
  
40
  
41
  
42
  
43
  
44
  
45
  
46
  
47
  
48
  
49
  
50
  
51
  
52
  
53
  
54
  
55
  
56
  
57
  
58
  
59
  
60
  
61
  
62
  
63
  
64
  
65
  
66
  
67
  
68
  
69
  
70
  
71
  
72
  
73
  
74
  
75
  
76
  
77
  
78
  
79
  
80
  
81
  
82
  
83
  
84
  
85
  
86
  
87
  
88
  
89
  
90
  
91
  
92
  
93
  
94
  
95
  
96
  
97
  
98
  
99
  
100
  
101
  
102
  
103
  
104
  
105
  
106
  
107
  
108
  
109
  
110
  
111
  
112
  
113
  
114
  
115
  
116
  
117
  
118
  
119
  
120
  
121
  
122
  
123
  
124
  
125
  
126
  
127
  
128
  
129
  
130
  
131
  
132
  
133
  
134
  
135
  
136
  
137
  
138
  
139
  
140
  
141
  
142
  
143
  
144
  
145
  
146
  
147
  
148
  
149
  
150
  
151
  
152
  
153
  
154
  
155
  
156
  
157
  
158
  
159
  
160
  
161
  
162
  
163
  
164
  
165
  
166
  
167
  
168
  
169
  
170
  
171
  
172
  
173
  
174
  
175
  
176
  
177
  
178
  
179
  
180
  
/* -*- C -*- */ 
require gtk24; 
 
class GTK2.FileChooserDialog; 
inherit GTK2.Dialog; 
inherit GTK2.FileChooser; 
 
//! GtkFileChooserDialog should be used to retrieve file or directory names 
//! from the user. It will create a new dialog window containing a 
//! directory list, and a file list corresponding to the current 
//! working directory. The filesystem can be navigated using the 
//! directory list, the drop-down history menu, or the TAB key can be 
//! used to navigate using filename completion common in text based 
//! editors such as emacs and jed. 
//! <p> 
//! The default filename can be set using set_filename() and the 
//! selected filename retrieved using get_filename(). 
//! </p><p> 
//! Use complete() to display files that match a given pattern. This 
//! can be used for example, to show only *.txt files, or only files 
//! beginning with gtk*. 
//! </p><p> 
//! Simple file operations; create directory, delete file, and rename 
//! file, are available from buttons at the top of the dialog. These 
//! can be hidden using hide_fileop_buttons() and shown again using 
//! show_fileop_buttons(). 
//! </p><p> 
//! TIMG: GTK2.FileChooserDialog("File selector", 0, GTK2.FILE_CHOOSER_ACTION_OPEN, ({(["text":"Transmogrify", "id":17]), (["text":"Never mind", "id":42])})) 
//! </p> 
 
/* 
void create(string title, int|GTK2.Window parent, int mode, 
            array(array(string:int)) buttons) 
//! Creates a new File Chooser Dialog box. 
//! Title is the title of the window.  May be empty or 0 for no title. 
//! Parent is the transient parent.  May be 0 for none. 
//! Mode is wither this is open or save mode.  See 
//! GTK2.FileChooser.set_action() for modes. 
{ 
  GPtrArray *gpa; 
  struct array *a; 
  char *s1; 
  INT_TYPE mm,xx; 
  struct object *o; 
  int i; 
 
  if (TYPEOF(Pike_sp[2-1-args]) == PIKE_T_INT) 
    get_all_args(NULL,args,"%s%i%i%a",&s1,&xx,&mm,&a); 
  else 
    get_all_args(NULL,args,"%s%O%i%a",&s1,&o,&mm,&a);  
  gpa=g_ptr_array_new(); 
  if (TYPEOF(Pike_sp[4-1-args]) != PIKE_T_ARRAY) 
    Pike_error("Wrong type of argument 4.\n"); 
  a=Pike_sp[4-1-args].u.array; 
  if (a->size>5) 
    Pike_error("Too many buttons.\n"); 
  for (i=0; i<a->size; i++) { 
    struct array *b; 
    gchar *s2; 
    INT_TYPE *m1; 
    if (TYPEOF(ITEM(a)[i]) != PIKE_T_ARRAY) 
      continue; 
    b=(ITEM(a)+i)->u.array; 
    if (TYPEOF(*ITEM(b)) != PIKE_T_STRING || TYPEOF(ITEM(b)[1]) != PIKE_T_INT) 
      continue; 
    s2=PGTK_GETSTR(ITEM(b)); 
    g_ptr_array_add(gpa,s2); 
    m1=g_malloc(sizeof(INT_TYPE)); 
    if (m1==NULL) 
      SIMPLE_OUT_OF_MEMORY_ERROR("create",sizeof(INT_TYPE)); 
    *m1=PGTK_GETINT(ITEM(b)+1); 
    g_ptr_array_add(gpa,m1); 
  } 
  switch (a->size) { 
    case 0: 
      Pike_error("Not enough buttons.\n"); 
    case 1: 
      THIS->obj=(void *)gtk_file_chooser_dialog_new(s1, 
        (TYPEOF(Pike_sp[2-1-args]) == PIKE_T_INT)?0:GTK_WINDOW(get_gobject(o)), 
        mm, 
        (gchar *)g_ptr_array_index(gpa,0),*(int *)g_ptr_array_index(gpa,1), 
        NULL); 
      break; 
    case 2: 
      THIS->obj=(void *)gtk_file_chooser_dialog_new(s1, 
        (TYPEOF(Pike_sp[2-1-args]) == PIKE_T_INT)?0:GTK_WINDOW(get_gobject(o)), 
        mm, 
        (gchar *)g_ptr_array_index(gpa,0),*(int *)g_ptr_array_index(gpa,1), 
        (gchar *)g_ptr_array_index(gpa,2),*(int *)g_ptr_array_index(gpa,3), 
        NULL); 
      break; 
    case 3: 
      THIS->obj=(void *)gtk_file_chooser_dialog_new(s1, 
        (TYPEOF(Pike_sp[2-1-args]) == PIKE_T_INT)?0:GTK_WINDOW(get_gobject(o)), 
        mm, 
        (gchar *)g_ptr_array_index(gpa,0),*(int *)g_ptr_array_index(gpa,1), 
        (gchar *)g_ptr_array_index(gpa,2),*(int *)g_ptr_array_index(gpa,3), 
        (gchar *)g_ptr_array_index(gpa,4),*(int *)g_ptr_array_index(gpa,5), 
        NULL); 
      break; 
    case 4: 
      THIS->obj=(void *)gtk_file_chooser_dialog_new(s1, 
        (TYPEOF(Pike_sp[2-1-args]) == PIKE_T_INT)?0:GTK_WINDOW(get_gobject(o)), 
        mm, 
        (gchar *)g_ptr_array_index(gpa,0),*(int *)g_ptr_array_index(gpa,1), 
        (gchar *)g_ptr_array_index(gpa,2),*(int *)g_ptr_array_index(gpa,3), 
        (gchar *)g_ptr_array_index(gpa,4),*(int *)g_ptr_array_index(gpa,5), 
        (gchar *)g_ptr_array_index(gpa,6),*(int *)g_ptr_array_index(gpa,7), 
        NULL); 
      break; 
    case 5: 
      THIS->obj=(void *)gtk_file_chooser_dialog_new(s1, 
        (TYPEOF(Pike_sp[2-1-args]) == PIKE_T_INT)?0:GTK_WINDOW(get_gobject(o)), 
        mm, 
        (gchar *)g_ptr_array_index(gpa,0),*(int *)g_ptr_array_index(gpa,1), 
        (gchar *)g_ptr_array_index(gpa,2),*(int *)g_ptr_array_index(gpa,3), 
        (gchar *)g_ptr_array_index(gpa,4),*(int *)g_ptr_array_index(gpa,5), 
        (gchar *)g_ptr_array_index(gpa,6),*(int *)g_ptr_array_index(gpa,7), 
        (gchar *)g_ptr_array_index(gpa,8),*(int *)g_ptr_array_index(gpa,9), 
        NULL); 
      break; 
    default: 
      Pike_error("Invalid number of buttons.\n"); 
  } 
  g_ptr_array_free(gpa,1); 
  pgtk2_pop_n_elems(args); 
} 
*/ 
 
void create(string title, GTK2.Window parent, int mode, 
            array(mapping(string:int)) buttons) 
//! Creates a new file selection dialog box. By default it will list 
//! the files in the current working directory. Operation buttons 
//! allowing the user to create a directory, delete files, and rename 
//! files will also be present by default. 
{ 
  pgtk2_verify_not_inited(); 
  pgtk2_verify_setup(); 
  { 
    struct pike_string *title; 
    INT_TYPE mode; 
    struct object *o1; 
    struct array *a; 
    int i; 
    GtkWidget *gf; 
 
    get_all_args(NULL,args,"%t%O%i%A",&title,&o1,&mode,&a); 
    ref_push_string(title); 
    f_string_to_utf8(1); 
    gf=gtk_file_chooser_dialog_new(CGSTR0(Pike_sp[-1].u.string), 
                                   GTK_WINDOW(get_gobject(o1)), 
                                   mode,NULL,NULL); 
    pop_stack(); 
    THIS->obj=G_OBJECT(gf); 
    if (a) { 
      for (i=0; i<a->size; i++) { 
        char *text; 
        int response_id = 0; 
        struct svalue *sv; 
        struct mapping *m; 
        if (TYPEOF(ITEM(a)[i]) != PIKE_T_MAPPING) 
          continue; 
        m=(ITEM(a)+i)->u.mapping; 
        sv=low_mapping_string_lookup(m,_STR("text")); 
        if (sv==NULL) 
          continue; 
        text=(char *)STR0(sv->u.string);  
        sv=low_mapping_string_lookup(m,_STR("id")); 
        if (sv) 
          response_id=PGTK_GETINT(sv); 
        gtk_dialog_add_button(GTK_DIALOG(THIS->obj),text,response_id); 
      } 
    } 
    pgtk2_pop_n_elems(args); 
  } 
  pgtk2__init_this_object(); 
} 
 
endrequire;