alternative to assert
[gtkD.git] / src / gtk / FileChooserDialog.d
blob9aff06380bd9d3ab030fcf7cd8aeb8a0d2479cd2
1 /*
2 * This file is part of duit.
4 * duit is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation; either version 2.1 of the License, or
7 * (at your option) any later version.
9 * duit is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with duit; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 // generated automatically - do not change
20 // find conversion definition on APILookup.txt
21 // implement new conversion functionalities on the wrap.utils pakage
24 * Conversion parameters:
25 * inFile = GtkFileChooserDialog.html
26 * outPack = gtk
27 * outFile = FileChooserDialog
28 * strct = GtkFileChooserDialog
29 * realStrct=
30 * ctorStrct=
31 * clss = FileChooserDialog
32 * interf =
33 * class Code: Yes
34 * interface Code: No
35 * template for:
36 * extend =
37 * implements:
38 * prefixes:
39 * - gtk_file_chooser_dialog_
40 * - gtk_
41 * omit structs:
42 * omit prefixes:
43 * omit code:
44 * - gtk_file_chooser_dialog_new
45 * - gtk_file_chooser_dialog_new_with_backend
46 * imports:
47 * - glib.Str
48 * - gtk.Window
49 * - glib.ListSG;
50 * - gtk.Widget;
51 * - gtk.FileFilter;
52 * - gtk.FileChooser;
53 * - glib.Str
54 * structWrap:
55 * - GtkWindow* -> Window
56 * local aliases:
59 module gtk.FileChooserDialog;
61 private import gtk.gtktypes;
63 private import lib.gtk;
65 private import glib.Str;
66 private import gtk.Window;
67 private import glib.ListSG;;
68 private import gtk.Widget;;
69 private import gtk.FileFilter;;
70 private import gtk.FileChooser;;
71 private import glib.Str;
73 /**
74 * Description
75 * GtkFileChooserDialog is a dialog box suitable for use with
76 * "File/Open" or "File/Save as" commands. This widget works by
77 * putting a GtkFileChooserWidget inside a GtkDialog. It exposes
78 * the GtkFileChooserIface interface, so you can use all of the
79 * GtkFileChooser functions on the file chooser dialog as well as
80 * those for GtkDialog.
81 * Note that GtkFileChooserDialog does not have any methods of its
82 * own. Instead, you should use the functions that work on a
83 * GtkFileChooser.
84 * Example7.Typical usage
85 * In the simplest of cases, you can the following code to use
86 * GtkFileChooserDialog to select a file for opening:
87 * GtkWidget *dialog;
88 * dialog = gtk_file_chooser_dialog_new ("Open File",
89 * parent_window,
90 * GTK_FILE_CHOOSER_ACTION_OPEN,
91 * GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
92 * GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
93 * NULL);
94 * if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
95 * {
96 * char *filename;
97 * filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
98 * open_file (filename);
99 * g_free (filename);
101 * gtk_widget_destroy (dialog);
102 * To use a dialog for saving, you can use this:
103 * GtkWidget *dialog;
104 * dialog = gtk_file_chooser_dialog_new ("Save File",
105 * parent_window,
106 * GTK_FILE_CHOOSER_ACTION_SAVE,
107 * GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
108 * GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
109 * NULL);
110 * gtk_file_chooser_set_do_overwrite_confirmation (GTK_FILE_CHOOSER (dialog), TRUE);
111 * if (user_edited_a_new_document)
113 * gtk_file_chooser_set_current_folder (GTK_FILE_CHOOSER (dialog), default_folder_for_saving);
114 * gtk_file_chooser_set_current_name (GTK_FILE_CHOOSER (dialog), "Untitled document");
116 * else
117 * gtk_file_chooser_set_filename (GTK_FILE_CHOOSER (dialog), filename_for_existing_document);
118 * if (gtk_dialog_run (GTK_DIALOG (dialog)) == GTK_RESPONSE_ACCEPT)
120 * char *filename;
121 * filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (dialog));
122 * save_to_file (filename);
123 * g_free (filename);
125 * gtk_widget_destroy (dialog);
126 * Response Codes
127 * GtkFileChooserDialog inherits from GtkDialog, so buttons that
128 * go in its action area have response codes such as
129 * GTK_RESPONSE_ACCEPT and GTK_RESPONSE_CANCEL. For example, you
130 * could call gtk_file_chooser_dialog_new() as follows:
131 * GtkWidget *dialog;
132 * dialog = gtk_file_chooser_dialog_new ("Open File",
133 * parent_window,
134 * GTK_FILE_CHOOSER_ACTION_OPEN,
135 * GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
136 * GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
137 * NULL);
138 * This will create buttons for "Cancel" and "Open" that use stock
139 * response identifiers from GtkResponseType. For most dialog
140 * boxes you can use your own custom response codes rather than the
141 * ones in GtkResponseType, but GtkFileChooserDialog assumes that
142 * its "accept"-type action, e.g. an "Open" or "Save" button,
143 * will have one of the following response
144 * codes:
145 * GTK_RESPONSE_ACCEPT
146 * GTK_RESPONSE_OK
147 * GTK_RESPONSE_YES
148 * GTK_RESPONSE_APPLY
149 * This is because GtkFileChooserDialog must intercept responses
150 * and switch to folders if appropriate, rather than letting the
151 * dialog terminate the implementation uses these known
152 * response codes to know which responses can be blocked if
153 * appropriate.
154 * Note
155 * To summarize, make sure you use a stock response
156 * code when you use GtkFileChooserDialog to ensure
157 * proper operation.
159 private import gtk.Dialog;
160 public class FileChooserDialog : Dialog
163 /** the main Gtk struct */
164 protected GtkFileChooserDialog* gtkFileChooserDialog;
167 public GtkFileChooserDialog* getFileChooserDialogStruct()
169 return gtkFileChooserDialog;
173 /** the main Gtk struct as a void* */
174 protected void* getStruct()
176 return cast(void*)gtkFileChooserDialog;
180 * Sets our main struct and passes it to the parent class
182 public this (GtkFileChooserDialog* gtkFileChooserDialog)
184 super(cast(GtkDialog*)gtkFileChooserDialog);
185 this.gtkFileChooserDialog = gtkFileChooserDialog;
188 private FileChooser fileChooser;
190 public FileChooser getFileChooser()
192 if ( fileChooser is null )
194 fileChooser = new FileChooser(cast(GtkFileChooser*)getFileChooserDialogStruct());
196 return fileChooser;
200 * Creates a new GtkFileChooserDialog. This function is analogous to
201 * gtk_dialog_new_with_buttons().
202 * title:
203 * Title of the dialog, or NULL
204 * parent:
205 * Transient parent of the dialog, or NULL
206 * action:
207 * Open or save mode for the dialog
208 * first_button_text:
209 * stock ID or text to go in the first button, or NULL
210 * ...:
211 * response ID for the first button, then additional (button, id) pairs, ending with NULL
212 * Returns:
213 * a new GtkFileChooserDialog
214 * Since 2.4
216 this(char[] title, Window parent, FileChooserAction action, char[][] buttonsText=null, ResponseType[] responses=null)
218 if ( buttonsText is null )
220 buttonsText ~= "OK";
221 buttonsText ~= "Cancel";
223 if ( responses is null )
225 responses ~= ResponseType.GTK_RESPONSE_OK;
226 responses ~= ResponseType.GTK_RESPONSE_CANCEL;
229 this(
230 cast(GtkFileChooserDialog*)gtk_file_chooser_dialog_new(
231 Str.toStringz(title),
232 parent.getWindowStruct(),
233 action,
234 null,
235 0));
236 addButtons(buttonsText, responses);
240 * Creates a new GtkFileChooserDialog with a specified backend. This is
241 * especially useful if you use gtk_file_chooser_set_local_only() to allow
242 * non-local files and you use a more expressive vfs, such as gnome-vfs,
243 * to load files.
244 * title:
245 * Title of the dialog, or NULL
246 * parent:
247 * Transient parent of the dialog, or NULL
248 * action:
249 * Open or save mode for the dialog
250 * backend:
251 * The name of the specific filesystem backend to use.
252 * first_button_text:
253 * stock ID or text to go in the first button, or NULL
254 * ...:
255 * response ID for the first button, then additional (button, id) pairs, ending with NULL
256 * Returns:
257 * a new GtkFileChooserDialog
258 * Since 2.4
259 * See Also
260 * GtkFileChooser, GtkDialog
262 public this (char[] title, Window parent, GtkFileChooserAction action, char[] backend, char[][] buttonsText=null, ResponseType[] responses=null)
264 // GtkWidget* gtk_file_chooser_dialog_new_with_backend (const gchar *title, GtkWindow *parent, GtkFileChooserAction action, const gchar *backend, const gchar *first_button_text, ...);
265 this(
266 cast(GtkFileChooserDialog*)gtk_file_chooser_dialog_new_with_backend(
267 Str.toStringz(title),
268 parent.getWindowStruct(),
269 action,
270 Str.toStringz(backend),
271 null,
274 if ( buttonsText is null )
276 buttonsText ~= "OK";
277 buttonsText ~= "Cancel";
279 if ( responses is null )
281 responses ~= ResponseType.GTK_RESPONSE_OK;
282 responses ~= ResponseType.GTK_RESPONSE_CANCEL;
285 addButtons(buttonsText, responses);
288 // this(char[] title, Window parent, FileChooserAction action, StockID[] buttons=null, ResponseType[] responses=null)
289 // {
290 // if ( buttons is null )
291 // {
292 // buttons ~= STOCK_OK;
293 // buttons ~= STOCK_CANCEL;
294 // }
295 // if ( responses is null )
296 // {
297 // responses ~= ResponseType.GTK_RESPONSE_OK;
298 // responses ~= ResponseType.GTK_RESPONSE_CANCEL;
299 // }
301 // this(gtk_file_chooser_dialog_new(
302 // title.toStringz(),
303 // parent.getWindowStruct(),
304 // action,
305 // null,
306 // 0));
307 // addButtons(buttons, responses);
308 // }