1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module gtk.FileChooserDialog;
26 
27 private import glib.ConstructionException;
28 private import gtk.Dialog;
29 private import gtk.FileChooserIF;
30 private import gtk.FileChooserT;
31 private import gtk.Window;
32 private import gtkc.gtk;
33 public  import gtkc.gtktypes;
34 
35 
36 /**
37  * #GtkFileChooserDialog is a dialog box suitable for use with
38  * “File/Open” or “File/Save as” commands.  This widget works by
39  * putting a #GtkFileChooserWidget inside a #GtkDialog.  It exposes
40  * the #GtkFileChooser interface, so you can use all of the
41  * #GtkFileChooser functions on the file chooser dialog as well as
42  * those for #GtkDialog.
43  * 
44  * Note that #GtkFileChooserDialog does not have any methods of its
45  * own.  Instead, you should use the functions that work on a
46  * #GtkFileChooser.
47  * 
48  * ## Typical usage ## {#gtkfilechooser-typical-usage}
49  * 
50  * In the simplest of cases, you can the following code to use
51  * #GtkFileChooserDialog to select a file for opening:
52  * 
53  * |[
54  * GtkWidget *dialog;
55  * GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
56  * gint res;
57  * 
58  * dialog = gtk_file_chooser_dialog_new ("Open File",
59  * parent_window,
60  * action,
61  * _("_Cancel"),
62  * GTK_RESPONSE_CANCEL,
63  * _("_Open"),
64  * GTK_RESPONSE_ACCEPT,
65  * NULL);
66  * 
67  * res = gtk_dialog_run (GTK_DIALOG (dialog));
68  * if (res == GTK_RESPONSE_ACCEPT)
69  * {
70  * char *filename;
71  * GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog);
72  * filename = gtk_file_chooser_get_filename (chooser);
73  * open_file (filename);
74  * g_free (filename);
75  * }
76  * 
77  * gtk_widget_destroy (dialog);
78  * ]|
79  * 
80  * To use a dialog for saving, you can use this:
81  * 
82  * |[
83  * GtkWidget *dialog;
84  * GtkFileChooser *chooser;
85  * GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE;
86  * gint res;
87  * 
88  * dialog = gtk_file_chooser_dialog_new ("Save File",
89  * parent_window,
90  * action,
91  * _("_Cancel"),
92  * GTK_RESPONSE_CANCEL,
93  * _("_Save"),
94  * GTK_RESPONSE_ACCEPT,
95  * NULL);
96  * chooser = GTK_FILE_CHOOSER (dialog);
97  * 
98  * gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE);
99  * 
100  * if (user_edited_a_new_document)
101  * gtk_file_chooser_set_current_name (chooser,
102  * _("Untitled document"));
103  * else
104  * gtk_file_chooser_set_filename (chooser,
105  * existing_filename);
106  * 
107  * res = gtk_dialog_run (GTK_DIALOG (dialog));
108  * if (res == GTK_RESPONSE_ACCEPT)
109  * {
110  * char *filename;
111  * 
112  * filename = gtk_file_chooser_get_filename (chooser);
113  * save_to_file (filename);
114  * g_free (filename);
115  * }
116  * 
117  * gtk_widget_destroy (dialog);
118  * ]|
119  * 
120  * ## Setting up a file chooser dialog ## {#gtkfilechooserdialog-setting-up}
121  * 
122  * There are various cases in which you may need to use a #GtkFileChooserDialog:
123  * 
124  * - To select a file for opening. Use #GTK_FILE_CHOOSER_ACTION_OPEN.
125  * 
126  * - To save a file for the first time. Use #GTK_FILE_CHOOSER_ACTION_SAVE,
127  * and suggest a name such as “Untitled” with gtk_file_chooser_set_current_name().
128  * 
129  * - To save a file under a different name. Use #GTK_FILE_CHOOSER_ACTION_SAVE,
130  * and set the existing filename with gtk_file_chooser_set_filename().
131  * 
132  * - To choose a folder instead of a file. Use #GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER.
133  * 
134  * Note that old versions of the file chooser’s documentation suggested
135  * using gtk_file_chooser_set_current_folder() in various
136  * situations, with the intention of letting the application
137  * suggest a reasonable default folder.  This is no longer
138  * considered to be a good policy, as now the file chooser is
139  * able to make good suggestions on its own.  In general, you
140  * should only cause the file chooser to show a specific folder
141  * when it is appropriate to use gtk_file_chooser_set_filename(),
142  * i.e. when you are doing a Save As command and you already
143  * have a file saved somewhere.
144  * 
145  * ## Response Codes ## {#gtkfilechooserdialog-responses}
146  * 
147  * #GtkFileChooserDialog inherits from #GtkDialog, so buttons that
148  * go in its action area have response codes such as
149  * #GTK_RESPONSE_ACCEPT and #GTK_RESPONSE_CANCEL.  For example, you
150  * could call gtk_file_chooser_dialog_new() as follows:
151  * 
152  * |[
153  * GtkWidget *dialog;
154  * GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
155  * 
156  * dialog = gtk_file_chooser_dialog_new ("Open File",
157  * parent_window,
158  * action,
159  * _("_Cancel"),
160  * GTK_RESPONSE_CANCEL,
161  * _("_Open"),
162  * GTK_RESPONSE_ACCEPT,
163  * NULL);
164  * ]|
165  * 
166  * This will create buttons for “Cancel” and “Open” that use stock
167  * response identifiers from #GtkResponseType.  For most dialog
168  * boxes you can use your own custom response codes rather than the
169  * ones in #GtkResponseType, but #GtkFileChooserDialog assumes that
170  * its “accept”-type action, e.g. an “Open” or “Save” button,
171  * will have one of the following response codes:
172  * 
173  * - #GTK_RESPONSE_ACCEPT
174  * - #GTK_RESPONSE_OK
175  * - #GTK_RESPONSE_YES
176  * - #GTK_RESPONSE_APPLY
177  * 
178  * This is because #GtkFileChooserDialog must intercept responses
179  * and switch to folders if appropriate, rather than letting the
180  * dialog terminate — the implementation uses these known
181  * response codes to know which responses can be blocked if
182  * appropriate.
183  * 
184  * To summarize, make sure you use a
185  * [stock response code][gtkfilechooserdialog-responses]
186  * when you use #GtkFileChooserDialog to ensure proper operation.
187  */
188 public class FileChooserDialog : Dialog, FileChooserIF
189 {
190 	/** the main Gtk struct */
191 	protected GtkFileChooserDialog* gtkFileChooserDialog;
192 
193 	/** Get the main Gtk struct */
194 	public GtkFileChooserDialog* getFileChooserDialogStruct()
195 	{
196 		return gtkFileChooserDialog;
197 	}
198 
199 	/** the main Gtk struct as a void* */
200 	protected override void* getStruct()
201 	{
202 		return cast(void*)gtkFileChooserDialog;
203 	}
204 
205 	protected override void setStruct(GObject* obj)
206 	{
207 		gtkFileChooserDialog = cast(GtkFileChooserDialog*)obj;
208 		super.setStruct(obj);
209 	}
210 
211 	/**
212 	 * Sets our main struct and passes it to the parent class.
213 	 */
214 	public this (GtkFileChooserDialog* gtkFileChooserDialog, bool ownedRef = false)
215 	{
216 		this.gtkFileChooserDialog = gtkFileChooserDialog;
217 		super(cast(GtkDialog*)gtkFileChooserDialog, ownedRef);
218 	}
219 
220 	// add the FileChooser capabilities
221 	mixin FileChooserT!(GtkFileChooserDialog);
222 
223 	/**
224 	 * Creates a new FileChooserDialog. This function is analogous to
225 	 * gtk_dialog_new_with_buttons().
226 	 * Since: 2.4
227 	 * Params:
228 	 *  title = Title of the dialog, or NULL
229 	 *  parent = Transient parent of the dialog, or NULL
230 	 *  action = Open or save mode for the dialog
231 	 *  buttonsText = text to go in the buttons
232 	 *  responses = response ID's for the buttons
233 	 * Throws: ConstructionException GTK+ fails to create the object.
234 	 */
235 	this(string title, Window parent, FileChooserAction action,  string[] buttonsText=null, ResponseType[] responses=null)
236 	{
237 		if ( buttonsText  is  null )
238 		{
239 			buttonsText ~= "OK";
240 			buttonsText ~= "Cancel";
241 		}
242 		if ( responses  is  null )
243 		{
244 			responses ~= ResponseType.OK;
245 			responses ~= ResponseType.CANCEL;
246 		}
247 		
248 		auto p = gtk_file_chooser_dialog_new(
249 			Str.toStringz(title),
250 			(parent is null) ? null : parent.getWindowStruct(),
251 			action,
252 			null,
253 			0);
254 		
255 		if(p is null)
256 		{
257 			throw new ConstructionException("null returned by gtk_file_chooser_dialog_new");
258 		}
259 		
260 		this(cast(GtkFileChooserDialog*) p);
261 		
262 		addButtons(buttonsText, responses);
263 	}
264 
265 	/**
266 	 */
267 
268 	public static GType getType()
269 	{
270 		return gtk_file_chooser_dialog_get_type();
271 	}
272 }