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  * If you want to integrate well with the platform you should use the
49  * #GtkFileChooserNative API, which will use a platform-specific
50  * dialog if available and fall back to GtkFileChooserDialog
51  * otherwise.
52  * 
53  * ## Typical usage ## {#gtkfilechooser-typical-usage}
54  * 
55  * In the simplest of cases, you can the following code to use
56  * #GtkFileChooserDialog to select a file for opening:
57  * 
58  * |[
59  * GtkWidget *dialog;
60  * GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
61  * gint res;
62  * 
63  * dialog = gtk_file_chooser_dialog_new ("Open File",
64  * parent_window,
65  * action,
66  * _("_Cancel"),
67  * GTK_RESPONSE_CANCEL,
68  * _("_Open"),
69  * GTK_RESPONSE_ACCEPT,
70  * NULL);
71  * 
72  * res = gtk_dialog_run (GTK_DIALOG (dialog));
73  * if (res == GTK_RESPONSE_ACCEPT)
74  * {
75  * char *filename;
76  * GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog);
77  * filename = gtk_file_chooser_get_filename (chooser);
78  * open_file (filename);
79  * g_free (filename);
80  * }
81  * 
82  * gtk_widget_destroy (dialog);
83  * ]|
84  * 
85  * To use a dialog for saving, you can use this:
86  * 
87  * |[
88  * GtkWidget *dialog;
89  * GtkFileChooser *chooser;
90  * GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE;
91  * gint res;
92  * 
93  * dialog = gtk_file_chooser_dialog_new ("Save File",
94  * parent_window,
95  * action,
96  * _("_Cancel"),
97  * GTK_RESPONSE_CANCEL,
98  * _("_Save"),
99  * GTK_RESPONSE_ACCEPT,
100  * NULL);
101  * chooser = GTK_FILE_CHOOSER (dialog);
102  * 
103  * gtk_file_chooser_set_do_overwrite_confirmation (chooser, TRUE);
104  * 
105  * if (user_edited_a_new_document)
106  * gtk_file_chooser_set_current_name (chooser,
107  * _("Untitled document"));
108  * else
109  * gtk_file_chooser_set_filename (chooser,
110  * existing_filename);
111  * 
112  * res = gtk_dialog_run (GTK_DIALOG (dialog));
113  * if (res == GTK_RESPONSE_ACCEPT)
114  * {
115  * char *filename;
116  * 
117  * filename = gtk_file_chooser_get_filename (chooser);
118  * save_to_file (filename);
119  * g_free (filename);
120  * }
121  * 
122  * gtk_widget_destroy (dialog);
123  * ]|
124  * 
125  * ## Setting up a file chooser dialog ## {#gtkfilechooserdialog-setting-up}
126  * 
127  * There are various cases in which you may need to use a #GtkFileChooserDialog:
128  * 
129  * - To select a file for opening. Use #GTK_FILE_CHOOSER_ACTION_OPEN.
130  * 
131  * - To save a file for the first time. Use #GTK_FILE_CHOOSER_ACTION_SAVE,
132  * and suggest a name such as “Untitled” with gtk_file_chooser_set_current_name().
133  * 
134  * - To save a file under a different name. Use #GTK_FILE_CHOOSER_ACTION_SAVE,
135  * and set the existing filename with gtk_file_chooser_set_filename().
136  * 
137  * - To choose a folder instead of a file. Use #GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER.
138  * 
139  * Note that old versions of the file chooser’s documentation suggested
140  * using gtk_file_chooser_set_current_folder() in various
141  * situations, with the intention of letting the application
142  * suggest a reasonable default folder.  This is no longer
143  * considered to be a good policy, as now the file chooser is
144  * able to make good suggestions on its own.  In general, you
145  * should only cause the file chooser to show a specific folder
146  * when it is appropriate to use gtk_file_chooser_set_filename(),
147  * i.e. when you are doing a Save As command and you already
148  * have a file saved somewhere.
149  * 
150  * ## Response Codes ## {#gtkfilechooserdialog-responses}
151  * 
152  * #GtkFileChooserDialog inherits from #GtkDialog, so buttons that
153  * go in its action area have response codes such as
154  * #GTK_RESPONSE_ACCEPT and #GTK_RESPONSE_CANCEL.  For example, you
155  * could call gtk_file_chooser_dialog_new() as follows:
156  * 
157  * |[
158  * GtkWidget *dialog;
159  * GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
160  * 
161  * dialog = gtk_file_chooser_dialog_new ("Open File",
162  * parent_window,
163  * action,
164  * _("_Cancel"),
165  * GTK_RESPONSE_CANCEL,
166  * _("_Open"),
167  * GTK_RESPONSE_ACCEPT,
168  * NULL);
169  * ]|
170  * 
171  * This will create buttons for “Cancel” and “Open” that use stock
172  * response identifiers from #GtkResponseType.  For most dialog
173  * boxes you can use your own custom response codes rather than the
174  * ones in #GtkResponseType, but #GtkFileChooserDialog assumes that
175  * its “accept”-type action, e.g. an “Open” or “Save” button,
176  * will have one of the following response codes:
177  * 
178  * - #GTK_RESPONSE_ACCEPT
179  * - #GTK_RESPONSE_OK
180  * - #GTK_RESPONSE_YES
181  * - #GTK_RESPONSE_APPLY
182  * 
183  * This is because #GtkFileChooserDialog must intercept responses
184  * and switch to folders if appropriate, rather than letting the
185  * dialog terminate — the implementation uses these known
186  * response codes to know which responses can be blocked if
187  * appropriate.
188  * 
189  * To summarize, make sure you use a
190  * [stock response code][gtkfilechooserdialog-responses]
191  * when you use #GtkFileChooserDialog to ensure proper operation.
192  */
193 public class FileChooserDialog : Dialog, FileChooserIF
194 {
195 	/** the main Gtk struct */
196 	protected GtkFileChooserDialog* gtkFileChooserDialog;
197 
198 	/** Get the main Gtk struct */
199 	public GtkFileChooserDialog* getFileChooserDialogStruct()
200 	{
201 		return gtkFileChooserDialog;
202 	}
203 
204 	/** the main Gtk struct as a void* */
205 	protected override void* getStruct()
206 	{
207 		return cast(void*)gtkFileChooserDialog;
208 	}
209 
210 	protected override void setStruct(GObject* obj)
211 	{
212 		gtkFileChooserDialog = cast(GtkFileChooserDialog*)obj;
213 		super.setStruct(obj);
214 	}
215 
216 	/**
217 	 * Sets our main struct and passes it to the parent class.
218 	 */
219 	public this (GtkFileChooserDialog* gtkFileChooserDialog, bool ownedRef = false)
220 	{
221 		this.gtkFileChooserDialog = gtkFileChooserDialog;
222 		super(cast(GtkDialog*)gtkFileChooserDialog, ownedRef);
223 	}
224 
225 	// add the FileChooser capabilities
226 	mixin FileChooserT!(GtkFileChooserDialog);
227 
228 	/**
229 	 * Creates a new FileChooserDialog. This function is analogous to
230 	 * gtk_dialog_new_with_buttons().
231 	 * Since: 2.4
232 	 * Params:
233 	 *  title = Title of the dialog, or NULL
234 	 *  parent = Transient parent of the dialog, or NULL
235 	 *  action = Open or save mode for the dialog
236 	 *  buttonsText = text to go in the buttons
237 	 *  responses = response ID's for the buttons
238 	 * Throws: ConstructionException GTK+ fails to create the object.
239 	 */
240 	this(string title, Window parent, FileChooserAction action,  string[] buttonsText=null, ResponseType[] responses=null)
241 	{
242 		if ( buttonsText  is  null )
243 		{
244 			buttonsText ~= "OK";
245 			buttonsText ~= "Cancel";
246 		}
247 		if ( responses  is  null )
248 		{
249 			responses ~= ResponseType.OK;
250 			responses ~= ResponseType.CANCEL;
251 		}
252 		
253 		auto p = gtk_file_chooser_dialog_new(
254 			Str.toStringz(title),
255 			(parent is null) ? null : parent.getWindowStruct(),
256 			action,
257 			null,
258 			0);
259 		
260 		if(p is null)
261 		{
262 			throw new ConstructionException("null returned by gtk_file_chooser_dialog_new");
263 		}
264 		
265 		this(cast(GtkFileChooserDialog*) p);
266 		
267 		addButtons(buttonsText, responses);
268 	}
269 
270 	/**
271 	 */
272 
273 	/** */
274 	public static GType getType()
275 	{
276 		return gtk_file_chooser_dialog_get_type();
277 	}
278 }