PsppireDataEditor: focus the datum entry widget when F2 is pressed
authorJohn Darrington <john@darrington.wattle.id.au>
Wed, 6 Sep 2017 06:53:54 +0000 (08:53 +0200)
committerJohn Darrington <john@darrington.wattle.id.au>
Wed, 6 Sep 2017 06:53:54 +0000 (08:53 +0200)
src/ui/gui/psppire-data-editor.c

index a3431349b186ecb4749c1d18859f7db7fc56ff72..d8c5cbf3a4541b0b8eec035e72535ceee198bbd8 100644 (file)
@@ -227,6 +227,20 @@ psppire_data_editor_set_focus_child (GtkContainer *container,
   GTK_CONTAINER_CLASS (parent_class)->set_focus_child (container, widget);
 }
 
+
+static gboolean
+on_key_press (GtkWidget *w, GdkEventKey *e)
+{
+  PsppireDataEditor *de = PSPPIRE_DATA_EDITOR (w);
+  if (e->keyval == GDK_KEY_F2 &&
+      PSPPIRE_DATA_EDITOR_DATA_VIEW == gtk_notebook_get_current_page (GTK_NOTEBOOK (de)))
+    {
+      gtk_widget_grab_focus (de->datum_entry);
+    }
+
+  return FALSE;
+}
+
 static void
 psppire_data_editor_class_init (PsppireDataEditorClass *klass)
 {
@@ -238,6 +252,7 @@ psppire_data_editor_class_init (PsppireDataEditorClass *klass)
   GObjectClass *object_class = G_OBJECT_CLASS (klass);
   GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
   GtkNotebookClass *notebook_class = GTK_NOTEBOOK_CLASS (klass);
+  GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
 
   parent_class = g_type_class_peek_parent (klass);
 
@@ -246,8 +261,8 @@ psppire_data_editor_class_init (PsppireDataEditorClass *klass)
   object_class->get_property = psppire_data_editor_get_property;
 
   container_class->set_focus_child = psppire_data_editor_set_focus_child;
-
   notebook_class->switch_page = psppire_data_editor_switch_page;
+  widget_class->key_press_event = on_key_press;
 
   data_store_spec =
     g_param_spec_pointer ("data-store",
@@ -524,6 +539,8 @@ psppire_data_editor_init (PsppireDataEditor *de)
       g_free (fontname);
       set_font_recursively (GTK_WIDGET (de), de->font);
     }
+
+  gtk_widget_add_events (GTK_WIDGET (de), GDK_KEY_PRESS_MASK);
 }
 
 GtkWidget*