gEDA-dev: [PATCH] Remove code that tracks escape key presses in dialogs (bug 1710818).

Ivan Stankovic ivan.stankovic at fer.hr
Mon Jun 11 08:52:10 EDT 2007


Since GTK takes care of escape key presses, this code
is not needed.
---
 gschem/include/x_multiattrib.h |    5 ----
 gschem/src/x_compselect.c      |   39 ------------------------------
 gschem/src/x_multiattrib.c     |   35 ++------------------------
 gschem/src/x_print.c           |   52 ++++-----------------------------------
 4 files changed, 9 insertions(+), 122 deletions(-)

diff --git a/gschem/include/x_multiattrib.h b/gschem/include/x_multiattrib.h
index 2fe2684..e53f06e 100644
--- a/gschem/include/x_multiattrib.h
+++ b/gschem/include/x_multiattrib.h
@@ -26,11 +26,6 @@
  * Multiattrib
  */
 
-typedef enum {
-  MULTIATTRIB_RESPONSE_CLOSE  = 1
-} MultiattribResponseType;
-
-
 #define TYPE_MULTIATTRIB         (multiattrib_get_type())
 #define MULTIATTRIB(obj)         (G_TYPE_CHECK_INSTANCE_CAST ((obj), TYPE_MULTIATTRIB, Multiattrib))
 #define MULTIATTRIB_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), TYPE_MULTIATTRIB, MultiattribClass))
diff --git a/gschem/src/x_compselect.c b/gschem/src/x_compselect.c
index ccf9e4b..bfce626 100644
--- a/gschem/src/x_compselect.c
+++ b/gschem/src/x_compselect.c
@@ -352,38 +352,6 @@ compselect_model_filter_visible_func (GtkTreeModel *model,
   return ret;
 }
 
-/*! \brief Handles a key press on the dialog.
- *  \par Function Description
- *  This is the callback function that is connected to the key press
- *  event of the dialog.
- *
- *  If the user pressed the Escape key, the close response is emitted
- *  requesting the dialog to be deleted.
- *
- *  If any other key is pressed the event is further propagated.
- *
- *  \param [in] widget    The component selection dialog.
- *  \param [in] event     The event structure for key pressed.
- *  \param [in] user_data NULL.
- *  \returns TRUE to stop other handlers from being invoked, FALSE
- *           otherwise.
- */
-static gboolean
-compselect_callback_dialog_key_press_event (GtkWidget   *widget,
-                                            GdkEventKey *event,
-                                            gpointer     user_data)
-{
-  switch (event->keyval) {
-      case GDK_Escape:
-        /* user pressed escape key, request close of the dialog */
-        gtk_dialog_response (GTK_DIALOG (widget), GTK_RESPONSE_CLOSE);
-        return TRUE;
-  }
-  
-  /* returns FALSE to propagate event further */
-  return FALSE;
-}
-
 /*! \brief Handles changes in the treeview selection.
  *  \par Function Description
  *  This is the callback function that is called every time the user
@@ -711,13 +679,6 @@ compselect_init (Compselect *compselect)
                 "homogeneous", FALSE,
                 NULL);
 
-  /* connect dialog to key press event */
-  g_signal_connect (compselect,
-                    "key_press_event",
-                    G_CALLBACK (compselect_callback_dialog_key_press_event),
-                    NULL);
-
-  
   /* horizontal box selection and preview */
   hbox = GTK_WIDGET (g_object_new (GTK_TYPE_HBOX,
                                    /* GtkBox */
diff --git a/gschem/src/x_multiattrib.c b/gschem/src/x_multiattrib.c
index 97caddb..46f4844 100644
--- a/gschem/src/x_multiattrib.c
+++ b/gschem/src/x_multiattrib.c
@@ -68,9 +68,9 @@ void x_multiattrib_open (TOPLEVEL *toplevel, OBJECT *object)
   multiattrib_update (MULTIATTRIB(dialog));
   gtk_widget_show (dialog);
   switch (gtk_dialog_run ((GtkDialog*)dialog)) {
-      case MULTIATTRIB_RESPONSE_CLOSE:
+      case GTK_RESPONSE_CLOSE:
       case GTK_RESPONSE_DELETE_EVENT:
-        /* resets state and update message in toolbar */
+        /* reset state and update message in toolbar */
         i_set_state (toplevel, SELECT);
         i_update_toolbar (toplevel);
         break;
@@ -1008,29 +1008,6 @@ static void multiattrib_callback_popup_delete(GtkMenuItem *menuitem,
   
 }
 
-
-/*! \todo Finish function documentation
- *  \brief
- *  \par Function Description
- *
- */
-static gboolean multiattrib_callback_dialog_key_pressed(GtkWidget *widget,
-							GdkEventKey *event,
-							gpointer user_data)
-{
-  Multiattrib *multiattrib = (Multiattrib*)widget;
-  gboolean retval = FALSE;
-
-  /* close the dialog if the Escape key is pressed */
-  if (event->keyval == GDK_Escape) {
-    gtk_dialog_response ((GtkDialog*)multiattrib,
-                         MULTIATTRIB_RESPONSE_CLOSE);
-    retval = TRUE;
-  }
-
-  return retval;
-}
-
 /*! \todo Finish function documentation
  *  \brief
  *  \par Function Description
@@ -1316,12 +1293,6 @@ static void multiattrib_init(Multiattrib *multiattrib)
 
   multiattrib->object   = NULL;
 
-  /* connect to the key-press-event of dialog */
-  g_signal_connect (multiattrib,
-                    "key-press-event",
-                    G_CALLBACK (multiattrib_callback_dialog_key_pressed),
-                    multiattrib);
-  
   /* create the attribute list frame */
   frame = GTK_WIDGET (g_object_new (GTK_TYPE_FRAME,
 				    /* GtkFrame */
@@ -1587,7 +1558,7 @@ static void multiattrib_init(Multiattrib *multiattrib)
   
   /* now add the close button to the action area */
   gtk_dialog_add_button (GTK_DIALOG (multiattrib),
-                         GTK_STOCK_CLOSE,   MULTIATTRIB_RESPONSE_CLOSE);
+                         GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE);
   
 }
 
diff --git a/gschem/src/x_print.c b/gschem/src/x_print.c
index dc0ca58..ca311ce 100644
--- a/gschem/src/x_print.c
+++ b/gschem/src/x_print.c
@@ -49,9 +49,6 @@ enum
 
 /* Private functions */
 
-static gboolean print_dialog_action_keypress (GtkWidget * widget,
-                                             GdkEventKey * event,
-                                             PrintDialog * dialog);
 static void print_dialog_action_radio_toggled (GtkWidget * w,
                                               PrintDialog * dialog);
 
@@ -122,40 +119,6 @@ print_dialog_action_choosefile (GtkWidget * w, PrintDialog * dialog)
 }
 
 /*!
- *  \brief Handle keypress events caught by the print dialog.
-  *
- *  \par Private callback function, should not be called by any code
- *  outside x_print.c
- */
-static gboolean
-print_dialog_action_keypress (GtkWidget * widget, GdkEventKey * event,
-                              PrintDialog * dialog)
-{
-  char *key_name;
-
-  key_name = gdk_keyval_name (event->keyval);
-  if ( key_name == NULL ) return FALSE;
-
-  if (widget == GTK_WIDGET (dialog))
-    {
-      if (strcmp (key_name, "Escape") == 0)
-        {
-          gtk_dialog_response (GTK_DIALOG (dialog),
-                               GTK_RESPONSE_REJECT);
-          return TRUE;
-        }
-      if (strcmp (key_name, "Return") == 0)
-        {
-          gtk_dialog_response (GTK_DIALOG (dialog),
-                               GTK_RESPONSE_ACCEPT);
-          return TRUE;
-        }
-    }
-
-  return FALSE;
-}
-
-/*!
  *  \brief Create, initialize and populate a combobox for selecting
  *  what paper size to print to.
  *  \par Private function, should not be
@@ -311,6 +274,7 @@ print_dialog_init (PrintDialog * dialog)
   GtkWidget *frame;
   GtkWidget *settingstable, *desttable;
   GtkWidget *label;
+  GtkWidget *print_button;
 
   /* Initialize properties */
   g_object_set (G_OBJECT (dialog),
@@ -318,11 +282,6 @@ print_dialog_init (PrintDialog * dialog)
 		"title", _("Print..."),
 		"modal", TRUE, "destroy-with-parent", TRUE, NULL);
 
-  /* Connect key-press event */
-  g_signal_connect (dialog,
-		    "key_press_event",
-		    GTK_SIGNAL_FUNC (print_dialog_action_keypress), dialog);
-
   /* Setup hbox for two main panes */
   box = gtk_vbox_new (FALSE, 2);
   gtk_container_add (GTK_CONTAINER (GTK_DIALOG (dialog)->vbox), box);
@@ -431,10 +390,11 @@ print_dialog_init (PrintDialog * dialog)
 		    1, 3, 1, 2, GTK_EXPAND | GTK_FILL, 0, 0, 0);
 
   /* Add "Cancel" and "Print" buttons */
-  gtk_dialog_add_buttons (GTK_DIALOG (dialog),
-			  GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
-			  GTK_STOCK_PRINT, GTK_RESPONSE_ACCEPT,
-			  NULL);
+  gtk_dialog_add_button (GTK_DIALOG (dialog),
+		  GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT);
+  print_button = gtk_dialog_add_button (GTK_DIALOG (dialog),
+		  GTK_STOCK_PRINT, GTK_RESPONSE_ACCEPT);
+  gtk_widget_grab_focus(print_button);
 
 #if GTK_CHECK_VERSION (2,6,0)
   /* Set the alternative button order (ok, cancel, help) for other systems */
-- 
1.5.2.1



More information about the geda-dev mailing list