[gtk+/wip/tingping/remove-dialog-run: 2/6] gtkfilechoosernative: Avoid gtk_native_dialog_run() in examples
- From: Patrick Griffis <pgriffis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/tingping/remove-dialog-run: 2/6] gtkfilechoosernative: Avoid gtk_native_dialog_run() in examples
- Date: Fri, 2 Jun 2017 23:10:44 +0000 (UTC)
commit 84d9bacd2905d29ed73ee2e0455ffd10abfa9ed2
Author: Patrick Griffis <tingping tingping se>
Date: Fri Jun 2 17:07:20 2017 -0400
gtkfilechoosernative: Avoid gtk_native_dialog_run() in examples
gtk/gtkfilechoosernative.c | 58 +++++++++++++++++++++++++++----------------
1 files changed, 36 insertions(+), 22 deletions(-)
---
diff --git a/gtk/gtkfilechoosernative.c b/gtk/gtkfilechoosernative.c
index a6a75f8..f68b95d 100644
--- a/gtk/gtkfilechoosernative.c
+++ b/gtk/gtkfilechoosernative.c
@@ -67,6 +67,22 @@
* #GtkFileChooserDialog to select a file for opening:
*
* |[
+ * static void
+ * on_response (GtkNativeDialog *dialog, guint response, gpointer user_data)
+ * {
+ * if (res == GTK_RESPONSE_ACCEPT)
+ * {
+ * char *filename;
+ * GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog);
+ * filename = gtk_file_chooser_get_filename (chooser);
+ * open_file (filename);
+ * g_free (filename);
+ * }
+ * g_object_unref (dialog);
+ * }
+ *
+ * ...
+ *
* GtkFileChooserNative *native;
* GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_OPEN;
* gint res;
@@ -77,22 +93,29 @@
* "_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);
+ * 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:
*
* |[
+ * static void
+ * on_response (GtkNativeDialog *dialog, guint response, gpointer user_data)
+ * {
+ * if (res == GTK_RESPONSE_ACCEPT)
+ * {
+ * char *filename;
+ * GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog);
+ * filename = gtk_file_chooser_get_filename (chooser);
+ * save_to_file (filename);
+ * g_free (filename);
+ * }
+ * g_object_unref (dialog);
+ * }
+ *
+ * ...
+ *
* GtkFileChooserNative *native;
* GtkFileChooser *chooser;
* GtkFileChooserAction action = GTK_FILE_CHOOSER_ACTION_SAVE;
@@ -114,17 +137,8 @@
* 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]