[gtk/ebassi/run-dialog-run: 3/7] docs: Remove use of gtk_native_dialog_run() from examples
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/ebassi/run-dialog-run: 3/7] docs: Remove use of gtk_native_dialog_run() from examples
- Date: Thu, 30 Apr 2020 15:01:10 +0000 (UTC)
commit d7ccc177c92e85b0cd576130e9af9ae680a60642
Author: Emmanuele Bassi <ebassi gnome org>
Date: Thu Apr 30 13:51:44 2020 +0100
docs: Remove use of gtk_native_dialog_run() from examples
Use the "response" signal instead.
gtk/gtkfilechoosernative.c | 118 +++++++++++++++++++++++++--------------------
1 file changed, 67 insertions(+), 51 deletions(-)
---
diff --git a/gtk/gtkfilechoosernative.c b/gtk/gtkfilechoosernative.c
index 184f6d268f7..653221b4868 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.
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]