summaryrefslogtreecommitdiff
path: root/gtk/gtkfilechoosernative.c
diff options
context:
space:
mode:
authorEmmanuele Bassi <ebassi@gnome.org>2020-04-30 13:51:44 +0100
committerEmmanuele Bassi <ebassi@gnome.org>2020-05-12 13:15:19 +0100
commit3212b07cf15927a5c03c6e26923eacdebdb48d53 (patch)
tree796034d79d6b1fcb23eb392fd72a7967bc93c351 /gtk/gtkfilechoosernative.c
parentf573a1f3f2e841eeaa23cf771ee277cc34b8cb5b (diff)
downloadgtk+-3212b07cf15927a5c03c6e26923eacdebdb48d53.tar.gz
docs: Remove use of gtk_native_dialog_run() from examples
Use the "response" signal instead.
Diffstat (limited to 'gtk/gtkfilechoosernative.c')
-rw-r--r--gtk/gtkfilechoosernative.c118
1 files changed, 67 insertions, 51 deletions
diff --git a/gtk/gtkfilechoosernative.c b/gtk/gtkfilechoosernative.c
index 0abb9201ab..4b1c346abd 100644
--- a/gtk/gtkfilechoosernative.c
+++ b/gtk/gtkfilechoosernative.c
@@ -69,63 +69,79 @@
* In the simplest of cases, you can the following code to use
* #GtkFileChooserDialog to select a file for opening:
*
- * |[
- * GtkFileChooserNative *native;
- * GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
- * gint res;
- *
- * native = gtk_file_chooser_native_new ("Open File",
- * parent_window,
- * action,
- * "_Open",
- * "_Cancel");
- *
- * res = gtk_native_dialog_run (GTK_NATIVE_DIALOG (native));
- * if (res == GTK_RESPONSE_ACCEPT)
- * {
- * char *filename;
- * GtkFileChooser *chooser = GTK_FILE_CHOOSER (native);
- * filename = gtk_file_chooser_get_filename (chooser);
- * open_file (filename);
- * g_free (filename);
- * }
- *
- * g_object_unref (native);
+ * |[<!-- language="C" -->
+ * static void
+ * on_response (GtkNativeDialog *dialog,
+ * int response)
+ * {
+ * if (response == GTK_RESPONSE_ACCEPT)
+ * {
+ * GtkFileChooser *chooser = GTK_FILE_CHOOSER (native);
+ * GFile *file = gtk_file_chooser_get_file (chooser);
+ *
+ * open_file (file);
+ *
+ * g_object_unref (file);
+ * }
+ *
+ * g_object_unref (native);
+ * }
+ *
+ * // ...
+ * GtkFileChooserNative *native;
+ * GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
+ *
+ * native = gtk_file_chooser_native_new ("Open File",
+ * parent_window,
+ * action,
+ * "_Open",
+ * "_Cancel");
+ *
+ * g_signal_connect (native, "response", G_CALLBACK (on_response), NULL);
+ * gtk_native_dialog_show (GTK_NATIVE_DIALOG (native));
* ]|
*
* To use a dialog for saving, you can use this:
*
- * |[
- * GtkFileChooserNative *native;
- * GtkFileChooser *chooser;
- * GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE;
- * gint res;
- *
- * native = gtk_file_chooser_native_new ("Save File",
- * parent_window,
- * action,
- * "_Save",
- * "_Cancel");
- * chooser = GTK_FILE_CHOOSER (native);
- *
- * if (user_edited_a_new_document)
- * gtk_file_chooser_set_current_name (chooser,
+ * |[<!-- language="C" -->
+ * static void
+ * on_response (GtkNativeDialog *dialog,
+ * int response)
+ * {
+ * if (response == GTK_RESPONSE_ACCEPT)
+ * {
+ * GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog);
+ * GFile *file = gtk_file_chooser_get_file (chooser);
+ *
+ * save_to_file (file);
+ *
+ * g_object_unref (file);
+ * }
+ *
+ * g_object_unref (native);
+ * }
+ *
+ * // ...
+ * GtkFileChooserNative *native;
+ * GtkFileChooser *chooser;
+ * GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE;
+ *
+ * native = gtk_file_chooser_native_new ("Save File",
+ * parent_window,
+ * action,
+ * "_Save",
+ * "_Cancel");
+ * chooser = GTK_FILE_CHOOSER (native);
+ *
+ * if (user_edited_a_new_document)
+ * gtk_file_chooser_set_current_name (chooser,
* _("Untitled document"));
- * else
- * gtk_file_chooser_set_filename (chooser,
- * existing_filename);
+ * else
+ * gtk_file_chooser_set_filename (chooser,
+ * existing_filename);
*
- * res = gtk_native_dialog_run (GTK_NATIVE_DIALOG (native));
- * if (res == GTK_RESPONSE_ACCEPT)
- * {
- * char *filename;
- *
- * filename = gtk_file_chooser_get_filename (chooser);
- * save_to_file (filename);
- * g_free (filename);
- * }
- *
- * g_object_unref (native);
+ * g_signal_connect (native, "response", G_CALLBACK (on_response), NULL);
+ * gtk_native_dialog_show (GTK_NATIVE_DIALOG (native));
* ]|
*
* For more information on how to best set up a file dialog, see #GtkFileChooserDialog.