[gnome-screenshot] interactive-dialog: make it a full GtkApplicationWindow



commit c281928882026be59f8dd3294a0ed40dedbaf08b
Author: Jonh Wendell <jonh wendell intel com>
Date:   Thu Jul 4 16:53:31 2013 -0300

    interactive-dialog: make it a full GtkApplicationWindow
    
    this brings back the app menu and the WM close button.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=701952

 src/screenshot-application.c        |   32 +------------------
 src/screenshot-interactive-dialog.c |   58 ++++++++++++++++++++++++++--------
 src/screenshot-interactive-dialog.h |    4 ++-
 3 files changed, 48 insertions(+), 46 deletions(-)
---
diff --git a/src/screenshot-application.c b/src/screenshot-application.c
index c947d3a..98e5e69 100644
--- a/src/screenshot-application.c
+++ b/src/screenshot-application.c
@@ -741,39 +741,9 @@ screenshooter_init_stock_icons (void)
 }
 
 static void
-interactive_dialog_response_cb (GtkWidget *d,
-                                gint response,
-                                gpointer user_data)
-{
-  ScreenshotApplication *self = user_data;
-
-  if (response != GTK_RESPONSE_HELP)
-    gtk_widget_destroy (d);
-
-  switch (response)
-    {
-    case GTK_RESPONSE_DELETE_EVENT:
-      break;
-    case GTK_RESPONSE_OK:
-      screenshot_start (self);
-      break;
-    case GTK_RESPONSE_HELP:
-      screenshot_display_help (GTK_WINDOW (d));
-      break;
-    default:
-      g_assert_not_reached ();
-      break;
-    }
-}
-
-static void
 screenshot_show_interactive_dialog (ScreenshotApplication *self)
 {
-  GtkWidget *dialog;
-
-  dialog = screenshot_interactive_dialog_new ();
-  g_signal_connect (dialog, "response",
-                    G_CALLBACK (interactive_dialog_response_cb), self);
+  screenshot_interactive_dialog_new ((CaptureClickedCallback) screenshot_start, self);
 }
 
 static void
diff --git a/src/screenshot-interactive-dialog.c b/src/screenshot-interactive-dialog.c
index 9a52ba2..cb4f12d 100644
--- a/src/screenshot-interactive-dialog.c
+++ b/src/screenshot-interactive-dialog.c
@@ -130,6 +130,12 @@ interactive_dialog_key_press_cb (GtkWidget *widget,
       return TRUE;
     }
 
+  if (event->keyval == GDK_KEY_Escape)
+    {
+      gtk_widget_destroy (widget);
+      return TRUE;
+    }
+
   return FALSE;
 }
 
@@ -412,37 +418,49 @@ create_screenshot_frame (GtkWidget   *outer_vbox,
   gtk_widget_show (label);
 }
 
+typedef struct {
+  GtkWidget *widget;
+  CaptureClickedCallback callback;
+  gpointer user_data;
+} CaptureData;
+
+static void
+capure_button_clicked_cb (GtkButton *button, CaptureData *data)
+{
+  gtk_widget_destroy (data->widget);
+  data->callback (data->user_data);
+  g_free (data);
+}
 
 GtkWidget *
-screenshot_interactive_dialog_new (void)
+screenshot_interactive_dialog_new (CaptureClickedCallback f, gpointer user_data)
 {
   GtkWidget *dialog;
   GtkWidget *main_vbox;
-  GtkWidget *content_area;
+  GtkWidget *button_box;
+  GtkWidget *button;
   gboolean shows_app_menu;
   GtkSettings *settings;
+  CaptureData *data;
 
-  dialog = gtk_dialog_new ();
-  gtk_window_set_application (GTK_WINDOW (dialog), GTK_APPLICATION (g_application_get_default ()));
+  dialog = gtk_application_window_new (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));
-  gtk_box_set_spacing (GTK_BOX (content_area), 2);
 
   /* main container */
   main_vbox = gtk_box_new (GTK_ORIENTATION_VERTICAL, 18);
   gtk_container_set_border_width (GTK_CONTAINER (main_vbox), 5);
-  gtk_box_pack_start (GTK_BOX (content_area), main_vbox, TRUE, TRUE, 0);
-  gtk_widget_show (main_vbox);
+  gtk_container_add (GTK_CONTAINER (dialog), main_vbox);
 
   create_screenshot_frame (main_vbox, _("Take Screenshot"));
   create_effects_frame (main_vbox, _("Effects"));
 
-  gtk_dialog_add_button (GTK_DIALOG (dialog),
-                         _("Take _Screenshot"), GTK_RESPONSE_OK);
+  button_box = gtk_button_box_new (GTK_ORIENTATION_HORIZONTAL);
+  gtk_button_box_set_layout (GTK_BUTTON_BOX (button_box), GTK_BUTTONBOX_END);
+  gtk_container_add (GTK_CONTAINER (main_vbox), button_box);
 
   /* 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 (dialog)));
@@ -450,11 +468,23 @@ screenshot_interactive_dialog_new (void)
                 "gtk-shell-shows-app-menu", &shows_app_menu,
                 NULL);
   if (!shows_app_menu)
-    gtk_dialog_add_button (GTK_DIALOG (dialog),
-                           GTK_STOCK_HELP, GTK_RESPONSE_HELP);
-
-  gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK);
+    {
+      button = gtk_button_new_from_stock (GTK_STOCK_HELP);
+      g_signal_connect_swapped (button, "clicked", G_CALLBACK (screenshot_display_help), dialog);
+      gtk_container_add (GTK_CONTAINER (button_box),
+                         button);
+      gtk_button_box_set_child_secondary (GTK_BUTTON_BOX (button_box), button, TRUE);
+    }
 
+  button = gtk_button_new_with_mnemonic (_("Take _Screenshot"));
+  data = g_new (CaptureData, 1);
+  data->widget = dialog;
+  data->callback = f;
+  data->user_data = user_data;
+  g_signal_connect (button, "clicked", G_CALLBACK (capure_button_clicked_cb), data);
+  gtk_container_add (GTK_CONTAINER (button_box), button);
+  gtk_widget_set_can_default (button, TRUE);
+  gtk_widget_grab_default (button);
   g_signal_connect (dialog, "key-press-event",
                     G_CALLBACK (interactive_dialog_key_press_cb), 
                     NULL);
diff --git a/src/screenshot-interactive-dialog.h b/src/screenshot-interactive-dialog.h
index a77d1a1..137998c 100644
--- a/src/screenshot-interactive-dialog.h
+++ b/src/screenshot-interactive-dialog.h
@@ -25,6 +25,8 @@
 
 #include <gtk/gtk.h>
 
-GtkWidget *screenshot_interactive_dialog_new (void);
+typedef void (*CaptureClickedCallback) (gpointer *user_data);
+
+GtkWidget *screenshot_interactive_dialog_new (CaptureClickedCallback f, gpointer user_data);
 
 #endif /* __SCREENSHOT_INTERACTIVE_DIALOG_H__ */


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