[gnome-screenshot] dialog: don't use additional GtkApplicationWindows



commit 05b486421a8003448ec77eda3b152eed8811f4ca
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Fri Apr 5 16:55:27 2013 -0400

    dialog: don't use additional GtkApplicationWindows
    
    Just associate the dialog toplevels with the application instead. This
    makes key activation working again.

 src/screenshot-application.c        |    6 +++---
 src/screenshot-dialog.c             |   31 ++++++++-----------------------
 src/screenshot-dialog.h             |    1 -
 src/screenshot-interactive-dialog.c |   29 +++++++----------------------
 4 files changed, 18 insertions(+), 49 deletions(-)
---
diff --git a/src/screenshot-application.c b/src/screenshot-application.c
index 95aa284..89c03b4 100644
--- a/src/screenshot-application.c
+++ b/src/screenshot-application.c
@@ -116,7 +116,7 @@ save_pixbuf_handle_success (ScreenshotApplication *self)
       ScreenshotDialog *dialog = self->priv->dialog;
 
       save_folder_to_settings (self);
-      gtk_widget_destroy (dialog->window);
+      gtk_widget_destroy (dialog->dialog);
     }
   else
     {
@@ -144,7 +144,7 @@ save_pixbuf_handle_error (ScreenshotApplication *self,
                                            file_name, folder_name);
           gint response;
                                              
-          response = screenshot_show_dialog (GTK_WINDOW (dialog->window),
+          response = screenshot_show_dialog (GTK_WINDOW (dialog->dialog),
                                              GTK_MESSAGE_WARNING,
                                              GTK_BUTTONS_YES_NO,
                                              _("Overwrite existing file?"),
@@ -165,7 +165,7 @@ save_pixbuf_handle_error (ScreenshotApplication *self,
         }
       else
         {
-          screenshot_show_dialog (GTK_WINDOW (dialog->window),
+          screenshot_show_dialog (GTK_WINDOW (dialog->dialog),
                                   GTK_MESSAGE_ERROR,
                                   GTK_BUTTONS_OK,
                                   _("Unable to capture a screenshot"),
diff --git a/src/screenshot-dialog.c b/src/screenshot-dialog.c
index 5c9cdbd..d1edddb 100644
--- a/src/screenshot-dialog.c
+++ b/src/screenshot-dialog.c
@@ -118,14 +118,6 @@ drag_begin (GtkWidget        *widget,
                            dialog->drag_x, dialog->drag_y);
 }
 
-static void
-dialog_destroy_cb (GtkWidget *widget,
-                   gpointer user_data)
-{
-  ScreenshotDialog *dialog = user_data;
-  gtk_widget_destroy (dialog->window);
-}
-
 ScreenshotDialog *
 screenshot_dialog_new (GdkPixbuf *screenshot,
                       char      *initial_uri)
@@ -165,19 +157,12 @@ screenshot_dialog_new (GdkPixbuf *screenshot,
   width /= 5;
   height /= 5;
 
-  dialog->window =
-    gtk_application_window_new (GTK_APPLICATION (g_application_get_default ()));
-  gtk_application_window_set_show_menubar (GTK_APPLICATION_WINDOW (dialog->window), FALSE);
-  gtk_window_set_resizable (GTK_WINDOW (dialog->window), FALSE);
-  gtk_window_set_title (GTK_WINDOW (dialog->window), _("Save Screenshot"));
-  gtk_window_set_position (GTK_WINDOW (dialog->window), GTK_WIN_POS_CENTER);
-  gtk_widget_realize (dialog->window);
-
   dialog->dialog = GTK_WIDGET (gtk_builder_get_object (ui, "toplevel"));
-  gtk_widget_set_parent_window (dialog->dialog, gtk_widget_get_window (dialog->window));
-  gtk_container_add (GTK_CONTAINER (dialog->window), dialog->dialog);
-  g_signal_connect (dialog->dialog, "destroy",
-                    G_CALLBACK (dialog_destroy_cb), dialog);
+  gtk_window_set_application (GTK_WINDOW (dialog->dialog), GTK_APPLICATION (g_application_get_default ()));
+  gtk_window_set_resizable (GTK_WINDOW (dialog->dialog), FALSE);
+  gtk_window_set_title (GTK_WINDOW (dialog->dialog), _("Save Screenshot"));
+  gtk_window_set_position (GTK_WINDOW (dialog->dialog), GTK_WIN_POS_CENTER);
+  gtk_widget_realize (dialog->dialog);
 
   aspect_frame = GTK_WIDGET (gtk_builder_get_object (ui, "aspect_frame"));
   preview_darea = GTK_WIDGET (gtk_builder_get_object (ui, "preview_darea"));
@@ -219,7 +204,7 @@ screenshot_dialog_new (GdkPixbuf *screenshot,
   g_signal_connect (G_OBJECT (preview_darea), "drag_data_get",
                    G_CALLBACK (drag_data_get), dialog);
 
-  gtk_widget_show_all (dialog->window);
+  gtk_widget_show_all (dialog->dialog);
 
   /* select the name of the file but leave out the extension if there's any;
    * the dialog must be realized for select_region to work
@@ -294,7 +279,7 @@ screenshot_dialog_set_busy (ScreenshotDialog *dialog,
 {
   GdkWindow *window;
 
-  window = gtk_widget_get_window (dialog->window);
+  window = gtk_widget_get_window (dialog->dialog);
 
   if (busy)
     {
@@ -309,7 +294,7 @@ screenshot_dialog_set_busy (ScreenshotDialog *dialog,
       gdk_window_set_cursor (window, NULL);
     }
 
-  gtk_widget_set_sensitive (dialog->window, ! busy);
+  gtk_widget_set_sensitive (dialog->dialog, ! busy);
 
   gdk_flush ();
 }
diff --git a/src/screenshot-dialog.h b/src/screenshot-dialog.h
index c47453b..7e45891 100644
--- a/src/screenshot-dialog.h
+++ b/src/screenshot-dialog.h
@@ -26,7 +26,6 @@ typedef struct {
   GdkPixbuf *screenshot;
   GdkPixbuf *preview_image;
 
-  GtkWidget *window;
   GtkWidget *dialog;
   GtkWidget *save_widget;
   GtkWidget *filename_entry;
diff --git a/src/screenshot-interactive-dialog.c b/src/screenshot-interactive-dialog.c
index 75eb249..9a52ba2 100644
--- a/src/screenshot-interactive-dialog.c
+++ b/src/screenshot-interactive-dialog.c
@@ -412,33 +412,21 @@ create_screenshot_frame (GtkWidget   *outer_vbox,
   gtk_widget_show (label);
 }
 
-static void
-interactive_dialog_destroy_cb (GtkWidget *widget,
-                               gpointer user_data)
-{
-  GtkWidget *window = user_data;
-  gtk_widget_destroy (window);
-}
 
 GtkWidget *
 screenshot_interactive_dialog_new (void)
 {
-  GtkWidget *window, *dialog;
+  GtkWidget *dialog;
   GtkWidget *main_vbox;
   GtkWidget *content_area;
   gboolean shows_app_menu;
   GtkSettings *settings;
 
-  window = gtk_application_window_new (GTK_APPLICATION (g_application_get_default ()));
-  gtk_application_window_set_show_menubar (GTK_APPLICATION_WINDOW (window), FALSE);
-  gtk_window_set_resizable (GTK_WINDOW (window), FALSE);
-  gtk_window_set_title (GTK_WINDOW (window), _("Take Screenshot"));
-  gtk_window_set_position (GTK_WINDOW (window), GTK_WIN_POS_CENTER);
-  gtk_widget_realize (window);
-
   dialog = gtk_dialog_new ();
-  gtk_widget_set_parent_window (dialog, gtk_widget_get_window (window));
-  gtk_container_add (GTK_CONTAINER (window), dialog);
+  gtk_window_set_application (GTK_WINDOW (dialog), GTK_APPLICATION (g_application_get_default ()));
+  gtk_window_set_resizable (GTK_WINDOW (dialog), FALSE);
+  gtk_window_set_title (GTK_WINDOW (dialog), _("Take Screenshot"));
+  gtk_window_set_position (GTK_WINDOW (dialog), GTK_WIN_POS_CENTER);
 
   gtk_container_set_border_width (GTK_CONTAINER (dialog), 5);
   content_area = gtk_dialog_get_content_area (GTK_DIALOG (dialog));
@@ -457,7 +445,7 @@ screenshot_interactive_dialog_new (void)
                          _("Take _Screenshot"), GTK_RESPONSE_OK);
 
   /* add help as a dialog button if we're not showing the application menu */
-  settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (window)));
+  settings = gtk_settings_get_for_screen (gtk_widget_get_screen (GTK_WIDGET (dialog)));
   g_object_get (settings,
                 "gtk-shell-shows-app-menu", &shows_app_menu,
                 NULL);
@@ -470,11 +458,8 @@ screenshot_interactive_dialog_new (void)
   g_signal_connect (dialog, "key-press-event",
                     G_CALLBACK (interactive_dialog_key_press_cb), 
                     NULL);
-  g_signal_connect (dialog, "destroy",
-                    G_CALLBACK (interactive_dialog_destroy_cb),
-                    window);
 
-  gtk_widget_show_all (window);
+  gtk_widget_show_all (dialog);
 
   return dialog;
 }


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