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 glib.Str;
29 private import gobject.ObjectG;
30 private import gtk.Dialog;
31 private import gtk.FileChooserIF;
32 private import gtk.FileChooserT;
33 private import gtk.Widget;
34 private import gtk.Window;
35 private import gtk.c.functions;
36 public  import gtk.c.types;
37 
38 
39 /**
40  * `GtkFileChooserDialog` is a dialog suitable for use with
41  * “File Open” or “File Save” commands.
42  * 
43  * ![An example GtkFileChooserDialog](filechooser.png)
44  * 
45  * This widget works by putting a [class@Gtk.FileChooserWidget]
46  * inside a [class@Gtk.Dialog]. It exposes the [iface@Gtk.FileChooser]
47  * interface, so you can use all of the [iface@Gtk.FileChooser] functions
48  * on the file chooser dialog as well as those for [class@Gtk.Dialog].
49  * 
50  * Note that `GtkFileChooserDialog` does not have any methods of its
51  * own. Instead, you should use the functions that work on a
52  * [iface@Gtk.FileChooser].
53  * 
54  * If you want to integrate well with the platform you should use the
55  * [class@Gtk.FileChooserNative] API, which will use a platform-specific
56  * dialog if available and fall back to `GtkFileChooserDialog`
57  * otherwise.
58  * 
59  * ## Typical usage
60  * 
61  * In the simplest of cases, you can the following code to use
62  * `GtkFileChooserDialog` to select a file for opening:
63  * 
64  * ```c
65  * static void
66  * on_open_response (GtkDialog *dialog,
67  * int        response)
68  * {
69  * if (response == GTK_RESPONSE_ACCEPT)
70  * {
71  * GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog);
72  * 
73  * g_autoptr(GFile) file = gtk_file_chooser_get_file (chooser);
74  * 
75  * open_file (file);
76  * }
77  * 
78  * gtk_window_destroy (GTK_WINDOW (dialog));
79  * }
80  * 
81  * // ...
82  * GtkWidget *dialog;
83  * GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
84  * 
85  * dialog = gtk_file_chooser_dialog_new ("Open File",
86  * parent_window,
87  * action,
88  * _("_Cancel"),
89  * GTK_RESPONSE_CANCEL,
90  * _("_Open"),
91  * GTK_RESPONSE_ACCEPT,
92  * NULL);
93  * 
94  * gtk_widget_show (dialog);
95  * 
96  * g_signal_connect (dialog, "response",
97  * G_CALLBACK (on_open_response),
98  * NULL);
99  * ```
100  * 
101  * To use a dialog for saving, you can use this:
102  * 
103  * ```c
104  * static void
105  * on_save_response (GtkDialog *dialog,
106  * int        response)
107  * {
108  * if (response == GTK_RESPONSE_ACCEPT)
109  * {
110  * GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog);
111  * 
112  * g_autoptr(GFile) file = gtk_file_chooser_get_file (chooser);
113  * 
114  * save_to_file (file);
115  * }
116  * 
117  * gtk_window_destroy (GTK_WINDOW (dialog));
118  * }
119  * 
120  * // ...
121  * GtkWidget *dialog;
122  * GtkFileChooser *chooser;
123  * GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE;
124  * 
125  * dialog = gtk_file_chooser_dialog_new ("Save File",
126  * parent_window,
127  * action,
128  * _("_Cancel"),
129  * GTK_RESPONSE_CANCEL,
130  * _("_Save"),
131  * GTK_RESPONSE_ACCEPT,
132  * NULL);
133  * chooser = GTK_FILE_CHOOSER (dialog);
134  * 
135  * if (user_edited_a_new_document)
136  * gtk_file_chooser_set_current_name (chooser, _("Untitled document"));
137  * else
138  * gtk_file_chooser_set_file (chooser, existing_filename);
139  * 
140  * gtk_widget_show (dialog);
141  * 
142  * g_signal_connect (dialog, "response",
143  * G_CALLBACK (on_save_response),
144  * NULL);
145  * ```
146  * 
147  * ## Setting up a file chooser dialog
148  * 
149  * There are various cases in which you may need to use a `GtkFileChooserDialog`:
150  * 
151  * - To select a file for opening, use %GTK_FILE_CHOOSER_ACTION_OPEN.
152  * 
153  * - To save a file for the first time, use %GTK_FILE_CHOOSER_ACTION_SAVE,
154  * and suggest a name such as “Untitled” with
155  * [method@Gtk.FileChooser.set_current_name].
156  * 
157  * - To save a file under a different name, use %GTK_FILE_CHOOSER_ACTION_SAVE,
158  * and set the existing file with [method@Gtk.FileChooser.set_file].
159  * 
160  * - To choose a folder instead of a filem use %GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER.
161  * 
162  * In general, you should only cause the file chooser to show a specific
163  * folder when it is appropriate to use [method@Gtk,FileChooser.set_file],
164  * i.e. when you are doing a “Save As” command and you already have a file
165  * saved somewhere.
166  * 
167  * ## Response Codes
168  * 
169  * `GtkFileChooserDialog` inherits from [class@Gtk.Dialog], so buttons that
170  * go in its action area have response codes such as %GTK_RESPONSE_ACCEPT and
171  * %GTK_RESPONSE_CANCEL. For example, you could call
172  * [ctor@Gtk.FileChooserDialog.new] as follows:
173  * 
174  * ```c
175  * GtkWidget *dialog;
176  * GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
177  * 
178  * dialog = gtk_file_chooser_dialog_new ("Open File",
179  * parent_window,
180  * action,
181  * _("_Cancel"),
182  * GTK_RESPONSE_CANCEL,
183  * _("_Open"),
184  * GTK_RESPONSE_ACCEPT,
185  * NULL);
186  * ```
187  * 
188  * This will create buttons for “Cancel” and “Open” that use predefined
189  * response identifiers from [enum@Gtk.ResponseType].  For most dialog
190  * boxes you can use your own custom response codes rather than the
191  * ones in [enum@Gtk.ResponseType], but `GtkFileChooserDialog` assumes that
192  * its “accept”-type action, e.g. an “Open” or “Save” button,
193  * will have one of the following response codes:
194  * 
195  * - %GTK_RESPONSE_ACCEPT
196  * - %GTK_RESPONSE_OK
197  * - %GTK_RESPONSE_YES
198  * - %GTK_RESPONSE_APPLY
199  * 
200  * This is because `GtkFileChooserDialog` must intercept responses and switch
201  * to folders if appropriate, rather than letting the dialog terminate — the
202  * implementation uses these known response codes to know which responses can
203  * be blocked if appropriate.
204  * 
205  * To summarize, make sure you use a predefined response code
206  * when you use `GtkFileChooserDialog` to ensure proper operation.
207  */
208 public class FileChooserDialog : Dialog, FileChooserIF
209 {
210 	/** the main Gtk struct */
211 	protected GtkFileChooserDialog* gtkFileChooserDialog;
212 
213 	/** Get the main Gtk struct */
214 	public GtkFileChooserDialog* getFileChooserDialogStruct(bool transferOwnership = false)
215 	{
216 		if (transferOwnership)
217 			ownedRef = false;
218 		return gtkFileChooserDialog;
219 	}
220 
221 	/** the main Gtk struct as a void* */
222 	protected override void* getStruct()
223 	{
224 		return cast(void*)gtkFileChooserDialog;
225 	}
226 
227 	/**
228 	 * Sets our main struct and passes it to the parent class.
229 	 */
230 	public this (GtkFileChooserDialog* gtkFileChooserDialog, bool ownedRef = false)
231 	{
232 		this.gtkFileChooserDialog = gtkFileChooserDialog;
233 		super(cast(GtkDialog*)gtkFileChooserDialog, ownedRef);
234 	}
235 
236 	// add the FileChooser capabilities
237 	mixin FileChooserT!(GtkFileChooserDialog);
238 
239 	/**
240 	 * Creates a new FileChooserDialog. This function is analogous to
241 	 * gtk_dialog_new_with_buttons().
242 	 *
243 	 * Params:
244 	 *  title = Title of the dialog, or NULL
245 	 *  parent = Transient parent of the dialog, or NULL
246 	 *  action = Open or save mode for the dialog
247 	 *  buttonsText = text to go in the buttons
248 	 *  responses = response ID's for the buttons
249 	 * Throws: ConstructionException GTK+ fails to create the object.
250 	 */
251 	this(string title, Window parent, FileChooserAction action,  string[] buttonsText=null, ResponseType[] responses=null)
252 	{
253 		if ( buttonsText  is  null )
254 		{
255 			buttonsText ~= "OK";
256 			buttonsText ~= "Cancel";
257 		}
258 		if ( responses  is  null )
259 		{
260 			responses ~= ResponseType.OK;
261 			responses ~= ResponseType.CANCEL;
262 		}
263 
264 		auto __p = gtk_file_chooser_dialog_new(
265 			Str.toStringz(title),
266 			(parent is null) ? null : parent.getWindowStruct(),
267 			action,
268 			null,
269 			0);
270 
271 		if(__p is null)
272 		{
273 			throw new ConstructionException("null returned by gtk_file_chooser_dialog_new");
274 		}
275 
276 		this(cast(GtkFileChooserDialog*) __p);
277 
278 		addButtons(buttonsText, responses);
279 	}
280 
281 	/**
282 	 */
283 
284 	/** */
285 	public static GType getType()
286 	{
287 		return gtk_file_chooser_dialog_get_type();
288 	}
289 }