[gthumb] find: focus the first rule when opening the dialog



commit b1ea99379a9d0afe032dd63a57c012bd79cea943
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Sun Jan 3 14:57:43 2016 +0100

    find: focus the first rule when opening the dialog

 extensions/search/actions.c                  |    1 +
 extensions/search/gth-search-editor-dialog.c |    7 ++++++
 extensions/search/gth-search-editor-dialog.h |    6 +++-
 extensions/search/gth-search-editor.c        |   13 ++++++++++++
 extensions/search/gth-search-editor.h        |    2 +
 gthumb/gth-test-category.c                   |   11 ++++++++++
 gthumb/gth-test-selector.c                   |   12 ++++++++++-
 gthumb/gth-test-selector.h                   |    3 +-
 gthumb/gth-test-simple.c                     |   28 ++++++++++++++++++++++++++
 gthumb/gth-test.c                            |   15 +++++++++++++
 gthumb/gth-test.h                            |    2 +
 gthumb/gth-time-selector.c                   |    8 +++++++
 gthumb/gth-time-selector.h                   |    1 +
 13 files changed, 105 insertions(+), 4 deletions(-)
---
diff --git a/extensions/search/actions.c b/extensions/search/actions.c
index 6ffa488..8f85bf5 100644
--- a/extensions/search/actions.c
+++ b/extensions/search/actions.c
@@ -89,6 +89,7 @@ gth_browser_activate_find (GSimpleAction *action,
 
        gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
        gtk_window_present (GTK_WINDOW (dialog));
+       gth_search_editor_dialog_focus_first_rule (GTH_SEARCH_EDITOR_DIALOG (dialog));
 
        g_object_unref (search);
 }
diff --git a/extensions/search/gth-search-editor-dialog.c b/extensions/search/gth-search-editor-dialog.c
index 346464e..e3ab7a1 100644
--- a/extensions/search/gth-search-editor-dialog.c
+++ b/extensions/search/gth-search-editor-dialog.c
@@ -122,3 +122,10 @@ gth_search_editor_dialog_get_search (GthSearchEditorDialog  *self,
 {
        return gth_search_editor_get_search (GTH_SEARCH_EDITOR (self->priv->search_editor), error);
 }
+
+
+void
+gth_search_editor_dialog_focus_first_rule (GthSearchEditorDialog *self)
+{
+       gth_search_editor_focus_first_rule (GTH_SEARCH_EDITOR (self->priv->search_editor));
+}
diff --git a/extensions/search/gth-search-editor-dialog.h b/extensions/search/gth-search-editor-dialog.h
index 7ea7814..f8cdd80 100644
--- a/extensions/search/gth-search-editor-dialog.h
+++ b/extensions/search/gth-search-editor-dialog.h
@@ -47,11 +47,13 @@ struct _GthSearchEditorDialogClass {
 
 GType       gth_search_editor_dialog_get_type   (void);
 GtkWidget * gth_search_editor_dialog_new        (const char             *title,
-                                                GthSearch              *search, 
+                                                GthSearch              *search,
                                                 GtkWindow              *parent);
-void        gth_search_editor_dialog_set_search (GthSearchEditorDialog  *self, 
+void        gth_search_editor_dialog_set_search (GthSearchEditorDialog  *self,
                                                 GthSearch              *search);
 GthSearch * gth_search_editor_dialog_get_search (GthSearchEditorDialog  *self,
                                                 GError                **error);
+void        gth_search_editor_dialog_focus_first_rule
+                                               (GthSearchEditorDialog  *self);
 
 #endif /* GTH_SEARCH_EDITOR_DIALOG_H */
diff --git a/extensions/search/gth-search-editor.c b/extensions/search/gth-search-editor.c
index 18698b0..7cc1963 100644
--- a/extensions/search/gth-search-editor.c
+++ b/extensions/search/gth-search-editor.c
@@ -288,3 +288,16 @@ gth_search_editor_get_search (GthSearchEditor  *self,
 
        return search;
 }
+
+
+void
+gth_search_editor_focus_first_rule (GthSearchEditor *self)
+{
+       GList *test_selectors;
+
+       test_selectors = gtk_container_get_children (GTK_CONTAINER (GET_WIDGET ("tests_box")));
+       if (test_selectors == NULL)
+               return;
+
+       gth_test_selector_focus (GTH_TEST_SELECTOR (test_selectors->data));
+}
diff --git a/extensions/search/gth-search-editor.h b/extensions/search/gth-search-editor.h
index 5759b9f..c559dcc 100644
--- a/extensions/search/gth-search-editor.h
+++ b/extensions/search/gth-search-editor.h
@@ -51,5 +51,7 @@ void        gth_search_editor_set_search (GthSearchEditor  *self,
                                          GthSearch        *search);
 GthSearch * gth_search_editor_get_search (GthSearchEditor  *self,
                                          GError          **error);
+void        gth_search_editor_focus_first_rule
+                                        (GthSearchEditor  *self);
 
 #endif /* GTH_SEARCH_EDITOR_H */
diff --git a/gthumb/gth-test-category.c b/gthumb/gth-test-category.c
index 8c50904..e9e6c3c 100644
--- a/gthumb/gth-test-category.c
+++ b/gthumb/gth-test-category.c
@@ -412,6 +412,16 @@ gth_test_category_real_update_from_control (GthTest  *base,
 }
 
 
+static void
+gth_test_category_real_focus_control (GthTest *base)
+{
+       GthTestCategory *self;
+
+       self = GTH_TEST_CATEGORY (base);
+       gtk_widget_grab_focus (self->priv->text_entry);
+}
+
+
 static GObject *
 gth_test_category_real_duplicate (GthDuplicable *duplicable)
 {
@@ -444,6 +454,7 @@ gth_test_category_class_init (GthTestCategoryClass *class)
        test_class = (GthTestClass *) class;
        test_class->create_control = gth_test_category_real_create_control;
        test_class->update_from_control = gth_test_category_real_update_from_control;
+       test_class->focus_control = gth_test_category_real_focus_control;
        test_class->match = gth_test_category_real_match;
 }
 
diff --git a/gthumb/gth-test-selector.c b/gthumb/gth-test-selector.c
index 69273d4..04953d1 100644
--- a/gthumb/gth-test-selector.c
+++ b/gthumb/gth-test-selector.c
@@ -132,6 +132,8 @@ test_combo_box_changed_cb (GtkComboBox     *scope_combo_box,
 
                test = gth_main_get_registered_object (GTH_TYPE_TEST, test_name);
                gth_test_selector_set_test (self, test);
+               gth_test_selector_focus (self);
+
                g_object_unref (test);
        }
 }
@@ -197,7 +199,7 @@ gth_test_selector_construct (GthTestSelector *self,
        GList           *scan;
 
        gtk_box_set_spacing (GTK_BOX (self), 6);
-       gtk_container_set_border_width (GTK_CONTAINER (self), 2);
+       gtk_container_set_border_width (GTK_CONTAINER (self), 0);
 
        /* scope combo box */
 
@@ -399,3 +401,11 @@ gth_test_selector_can_remove (GthTestSelector *self,
 {
        gtk_widget_set_sensitive (self->priv->remove_button, value);
 }
+
+
+void
+gth_test_selector_focus (GthTestSelector *self)
+{
+       if (self->priv->test != NULL)
+               gth_test_focus_control (self->priv->test);
+}
diff --git a/gthumb/gth-test-selector.h b/gthumb/gth-test-selector.h
index db6c086..177785d 100644
--- a/gthumb/gth-test-selector.h
+++ b/gthumb/gth-test-selector.h
@@ -45,7 +45,7 @@ struct _GthTestSelector {
 
 struct _GthTestSelectorClass {
        GtkBoxClass parent_class;
-       
+
        void (*add_test)    (GthTestSelector *selector);
        void (*remove_test) (GthTestSelector *selector);
 };
@@ -59,6 +59,7 @@ GthTest *   gth_test_selector_get_test      (GthTestSelector  *selector,
                                             GError          **error);
 void        gth_test_selector_can_remove    (GthTestSelector  *selector,
                                             gboolean          value);
+void        gth_test_selector_focus         (GthTestSelector  *self);
 
 G_END_DECLS
 
diff --git a/gthumb/gth-test-simple.c b/gthumb/gth-test-simple.c
index 13e9919..b9b6d99 100644
--- a/gthumb/gth-test-simple.c
+++ b/gthumb/gth-test-simple.c
@@ -996,6 +996,33 @@ gth_test_simple_real_update_from_control (GthTest  *base,
 }
 
 
+static void
+gth_test_simple_real_focus_control (GthTest *base)
+{
+       GthTestSimple *self;
+
+       self = GTH_TEST_SIMPLE (base);
+
+       switch (self->priv->data_type) {
+       case GTH_TEST_DATA_TYPE_INT:
+               gtk_widget_grab_focus (self->priv->spinbutton);
+               break;
+
+       case GTH_TEST_DATA_TYPE_STRING:
+       case GTH_TEST_DATA_TYPE_SIZE:
+               gtk_widget_grab_focus (self->priv->text_entry);
+               break;
+
+       case GTH_TEST_DATA_TYPE_DATE:
+               gth_time_selector_focus (GTH_TIME_SELECTOR (self->priv->time_selector));
+               break;
+
+       default:
+               break;
+       }
+}
+
+
 static GObject *
 gth_test_simple_real_duplicate (GthDuplicable *duplicable)
 {
@@ -1155,6 +1182,7 @@ gth_test_simple_class_init (GthTestSimpleClass *class)
        test_class = (GthTestClass *) class;
        test_class->create_control = gth_test_simple_real_create_control;
        test_class->update_from_control = gth_test_simple_real_update_from_control;
+       test_class->focus_control = gth_test_simple_real_focus_control;
        test_class->match = gth_test_simple_real_match;
 
        /* properties */
diff --git a/gthumb/gth-test.c b/gthumb/gth-test.c
index 505fd13..2900eab 100644
--- a/gthumb/gth-test.c
+++ b/gthumb/gth-test.c
@@ -111,6 +111,13 @@ base_update_from_control (GthTest   *self,
 }
 
 
+static void
+base_focus_control (GthTest *self)
+{
+       /* void */
+}
+
+
 static GthMatch
 base_match (GthTest     *self,
            GthFileData *fdata)
@@ -270,6 +277,7 @@ gth_test_class_init (GthTestClass *klass)
        klass->get_attributes = base_get_attributes;
        klass->create_control = base_create_control;
        klass->update_from_control = base_update_from_control;
+       klass->focus_control = base_focus_control;
        klass->match = base_match;
        klass->set_file_list = base_set_file_list;
        klass->get_next = base_get_next;
@@ -389,6 +397,13 @@ gth_test_update_from_control (GthTest   *self,
 
 
 void
+gth_test_focus_control (GthTest *self)
+{
+       GTH_TEST_GET_CLASS (self)->focus_control (self);
+}
+
+
+void
 gth_test_changed (GthTest *self)
 {
        g_signal_emit (self, gth_test_signals[CHANGED], 0);
diff --git a/gthumb/gth-test.h b/gthumb/gth-test.h
index bd69472..2f29558 100644
--- a/gthumb/gth-test.h
+++ b/gthumb/gth-test.h
@@ -86,6 +86,7 @@ struct _GthTestClass {
        GtkWidget *   (*create_control)       (GthTest     *test);
        gboolean      (*update_from_control)  (GthTest     *test,
                                               GError     **error);
+       void          (*focus_control)        (GthTest     *test);
        GthMatch      (*match)                (GthTest     *test,
                                               GthFileData *fdata);
        void          (*set_file_list)        (GthTest     *test,
@@ -104,6 +105,7 @@ const char *  gth_test_get_attributes      (GthTest      *test);
 GtkWidget *   gth_test_create_control      (GthTest      *test);
 gboolean      gth_test_update_from_control (GthTest      *test,
                                            GError      **error);
+void          gth_test_focus_control       (GthTest      *test);
 void          gth_test_changed             (GthTest      *test);
 GthMatch      gth_test_match               (GthTest      *test,
                                            GthFileData  *fdata);
diff --git a/gthumb/gth-time-selector.c b/gthumb/gth-time-selector.c
index dead77a..1819904 100644
--- a/gthumb/gth-time-selector.c
+++ b/gthumb/gth-time-selector.c
@@ -105,6 +105,7 @@ gth_time_selector_class_init (GthTimeSelectorClass *class)
 
        widget_class = (GtkWidgetClass *) class;
        widget_class->unmap = gth_time_selector_unmap;
+       widget_class->focus = gth_time_selector_focus;
 
        gth_time_selector_signals[CHANGED] =
                g_signal_new ("changed",
@@ -745,3 +746,10 @@ gth_time_selector_get_value (GthTimeSelector *self,
        else
                gth_time_clear (date_time->time);
 }
+
+
+void
+gth_time_selector_focus (GthTimeSelector *self)
+{
+       gtk_widget_grab_focus (self->priv->date_entry);
+}
diff --git a/gthumb/gth-time-selector.h b/gthumb/gth-time-selector.h
index c531301..3b94f34 100644
--- a/gthumb/gth-time-selector.h
+++ b/gthumb/gth-time-selector.h
@@ -64,6 +64,7 @@ void          gth_time_selector_set_exif_date  (GthTimeSelector *self,
                                                const char      *exif_date);
 void          gth_time_selector_get_value      (GthTimeSelector *self,
                                                GthDateTime     *date_time);
+void          gth_time_selector_focus          (GthTimeSelector *self);
 
 G_END_DECLS
 


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