[gtkglarea] examples/viewlw.c: Use GtkFileChooser instead deprecated GtkFileSelection



commit ab0313895b2c693b2df6634351ca70670ff6b6b0
Author: Javier Jardón <javier jardon codethink co uk>
Date:   Thu Mar 20 12:33:26 2014 +0000

    examples/viewlw.c: Use GtkFileChooser instead deprecated GtkFileSelection

 examples/viewlw.c |   47 +++++++++++++++++++++++++++++++----------------
 1 files changed, 31 insertions(+), 16 deletions(-)
---
diff --git a/examples/viewlw.c b/examples/viewlw.c
index 4abe6ef..addebe0 100644
--- a/examples/viewlw.c
+++ b/examples/viewlw.c
@@ -357,10 +357,6 @@ gint show_lwobject(char const *lwobject_name)
                     G_CALLBACK(window_destroy), NULL);
   window_count++;
 
-  /* destroy this window when exiting from gtk_main() */
-  gtk_quit_add_destroy(1, GTK_OBJECT(window));
-
-
   /* put glarea into window and show it all */
   gtk_container_add(GTK_CONTAINER(window), glarea);
 
@@ -370,25 +366,44 @@ gint show_lwobject(char const *lwobject_name)
   return TRUE;
 }
 
+void filew_ok (GtkDialog *dialog)
+{
+  GtkFileChooser *chooser = GTK_FILE_CHOOSER (dialog);
+  gchar *filename = gtk_file_chooser_get_filename (chooser);
 
+  if (show_lwobject (filename) == TRUE)
+    gtk_widget_destroy (GTK_WIDGET (dialog));
 
-gint filew_ok(GtkWidget *widget, GtkWidget *filew)
-{
-  if (show_lwobject(gtk_file_selection_get_filename(GTK_FILE_SELECTION(filew))) == TRUE)
-    gtk_widget_destroy(filew);
-  return TRUE;
+  g_free (filename);
 }
 
-void select_lwobject()
+void response_cb (GtkDialog *dialog, gint response_id, gpointer user_data)
 {
-  GtkWidget *filew = gtk_file_selection_new("Select LightWave 3D object");
-
-  g_signal_connect (G_OBJECT(GTK_FILE_SELECTION (filew)->ok_button), "clicked",
-                    G_CALLBACK(filew_ok), filew);
+  switch (response_id)
+  {
+    case GTK_RESPONSE_ACCEPT:
+      filew_ok (dialog);
+      break;
+    case GTK_RESPONSE_CANCEL:
+      gtk_widget_destroy (GTK_WIDGET (dialog));
+      break;
+    default:
+      break;
+  }
 
-  g_signal_connect_swapped (G_OBJECT(GTK_FILE_SELECTION(filew)->cancel_button), "clicked",
-                            G_CALLBACK(gtk_widget_destroy), filew);
+  gtk_widget_destroy (GTK_WIDGET (dialog));
+}
 
+void select_lwobject()
+{
+  GtkWidget *filew = gtk_file_chooser_dialog_new ("Select LightWave 3D object",
+                                                  NULL,
+                                                  GTK_FILE_CHOOSER_ACTION_OPEN,
+                                                  "_Cancel", GTK_RESPONSE_CANCEL,
+                                                  "_Open", GTK_RESPONSE_ACCEPT,
+                                                  NULL);
+
+  g_signal_connect (G_OBJECT(filew), "response", G_CALLBACK (response_cb), NULL);
   g_signal_connect (G_OBJECT(filew), "destroy",
                     G_CALLBACK(window_destroy), NULL);
   window_count++;


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]