diff options
-rw-r--r-- | ChangeLog | 51 | ||||
-rw-r--r-- | src/nautilus-complex-search-bar.c | 33 | ||||
-rw-r--r-- | src/nautilus-navigation-bar.c | 27 | ||||
-rw-r--r-- | src/nautilus-navigation-bar.h | 2 | ||||
-rw-r--r-- | src/nautilus-simple-search-bar.c | 13 | ||||
-rw-r--r-- | src/nautilus-switchable-navigation-bar.c | 60 | ||||
-rw-r--r-- | src/nautilus-switchable-navigation-bar.h | 8 | ||||
-rw-r--r-- | src/nautilus-switchable-search-bar.c | 25 |
8 files changed, 194 insertions, 25 deletions
@@ -1,3 +1,54 @@ +2000-09-12 John Sullivan <sullivan@eazel.com> + + Fixed bug 2668 (Switching to Search mode should move the + focus to the search text field). + + * src/nautilus-navigation-bar.h: Added signal and public + function for nautilus_navigation_bar_activate. + * src/nautilus-navigation-bar.c: + (nautilus_navigation_bar_initialize_class): Wire up + activate signal; default function is NULL. + (nautilus_navigation_bar_activate): New function, emits + signal. + + * src/nautilus-switchable-navigation-bar.h: + * src/nautilus-switchable-navigation-bar.c: + Defined a NautilusSwitchableNavigationBarDetails struct, + and moved implementation details into it. Set the types + of the fields in this struct to reflect actual needs, + instead of using GtkWidget and casting up to other + classes. + (nautilus_switchable_navigation_bar_initialize): Create + details struct. + (nautilus_switchable_navigation_bar_destroy): New function, + free details struct. + (nautilus_switchable_navigation_bar_initialize_class): + Wire up destroy handler. + (nautilus_switchable_navigation_bar_set_mode): Call + nautilus_navigation_bar_activate on switched-to bar. + (nautilus_switchable_navigation_bar_get_mode), + (nautilus_switchable_navigation_bar_get_location), + (nautilus_switchable_navigation_bar_set_location): Updated + to use bar->details. + + * src/nautilus-switchable-search-bar.c: + (nautilus_switchable_search_bar_initialize_class): + Wire up activate signal to real_activate. + (real_activate): Call nautilus_navigation_bar_activate + on the current search bar. + + * src/nautilus-simple-search-bar.c: + (nautilus_simple_search_bar_initialize_class): Wire up + activate signal to real_activate. + (real_activate): Set focus to text field. + + * src/nautilus-complex-search-bar.c: + (nautilus_complex_search_bar_initialize_class): Wire up + activate signal to real_activate. + (get_first_text_field): New helper function to find the + first text field in a search criterion (or NULL). + (real_activate): Set focus to first text field. + 2000-09-11 Pavel Cisler <pavel@eazel.com> * libnautilus-extensions/nautilus-directory-notify.h: diff --git a/src/nautilus-complex-search-bar.c b/src/nautilus-complex-search-bar.c index f1a31cc2d..f526e0f5f 100644 --- a/src/nautilus-complex-search-bar.c +++ b/src/nautilus-complex-search-bar.c @@ -53,6 +53,7 @@ struct NautilusComplexSearchBarDetails { }; +static void real_activate (NautilusNavigationBar *bar); static char *nautilus_complex_search_bar_get_location (NautilusNavigationBar *bar); static void nautilus_complex_search_bar_set_location (NautilusNavigationBar *bar, const char *location); @@ -149,6 +150,7 @@ nautilus_complex_search_bar_initialize_class (NautilusComplexSearchBarClass *kla { GTK_OBJECT_CLASS (klass)->destroy = nautilus_complex_search_bar_destroy; + NAUTILUS_NAVIGATION_BAR_CLASS (klass)->activate = real_activate; NAUTILUS_NAVIGATION_BAR_CLASS (klass)->get_location = nautilus_complex_search_bar_get_location; NAUTILUS_NAVIGATION_BAR_CLASS (klass)->set_location = nautilus_complex_search_bar_set_location; } @@ -262,6 +264,37 @@ nautilus_complex_search_bar_destroy (GtkObject *object) NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object)); } +static GtkWidget * +get_first_text_field (NautilusComplexSearchBar *bar) +{ + GSList *node; + NautilusSearchBarCriterion *criterion; + + for (node = bar->details->search_criteria; node != NULL; node = node->next) { + criterion = NAUTILUS_SEARCH_BAR_CRITERION (node->data); + if (criterion->details->use_value_entry) { + return GTK_WIDGET (criterion->details->value_entry); + } + } + + return NULL; +} + +static void +real_activate (NautilusNavigationBar *navigation_bar) +{ + NautilusComplexSearchBar *bar; + GtkWidget *initial_focus_widget; + + bar = NAUTILUS_COMPLEX_SEARCH_BAR (navigation_bar); + + /* Put the keyboard focus in a text field when switching to search mode */ + initial_focus_widget = get_first_text_field (bar); + if (initial_focus_widget != NULL) { + gtk_widget_grab_focus (initial_focus_widget); + } +} + /* returned string should be g_freed by the caller */ static char * nautilus_complex_search_bar_get_location (NautilusNavigationBar *navigation_bar) diff --git a/src/nautilus-navigation-bar.c b/src/nautilus-navigation-bar.c index 533804f2d..69cdf397c 100644 --- a/src/nautilus-navigation-bar.c +++ b/src/nautilus-navigation-bar.c @@ -37,6 +37,7 @@ #include <libnautilus-extensions/nautilus-gtk-macros.h> enum { + ACTIVATE, LOCATION_CHANGED, LAST_SIGNAL }; @@ -57,6 +58,15 @@ nautilus_navigation_bar_initialize_class (NautilusNavigationBarClass *klass) object_class = GTK_OBJECT_CLASS (klass); + signals[ACTIVATE] + = gtk_signal_new ("activate", + GTK_RUN_FIRST, + object_class->type, + GTK_SIGNAL_OFFSET (NautilusNavigationBarClass, + activate), + gtk_marshal_NONE__NONE, + GTK_TYPE_NONE, 0); + signals[LOCATION_CHANGED] = gtk_signal_new ("location_changed", GTK_RUN_FIRST, @@ -68,6 +78,8 @@ nautilus_navigation_bar_initialize_class (NautilusNavigationBarClass *klass) gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); + klass->activate = NULL; + NAUTILUS_ASSIGN_MUST_OVERRIDE_SIGNAL (klass, nautilus_navigation_bar, get_location); NAUTILUS_ASSIGN_MUST_OVERRIDE_SIGNAL (klass, nautilus_navigation_bar, set_location); } @@ -78,6 +90,21 @@ nautilus_navigation_bar_initialize (NautilusNavigationBar *bar) } /** + * nautilus_navigation_bar_activate + * + * Change the navigation bar to an active state. + * + * @bar: A NautilusNavigationBar. + */ +void +nautilus_navigation_bar_activate (NautilusNavigationBar *bar) +{ + g_return_if_fail (NAUTILUS_IS_NAVIGATION_BAR (bar)); + + gtk_signal_emit (GTK_OBJECT (bar), signals[ACTIVATE]); +} + +/** * nautilus_navigation_bar_get_location * * Return the location displayed in the navigation bar. diff --git a/src/nautilus-navigation-bar.h b/src/nautilus-navigation-bar.h index eaf0beb3a..232473767 100644 --- a/src/nautilus-navigation-bar.h +++ b/src/nautilus-navigation-bar.h @@ -51,6 +51,7 @@ typedef struct { const char *location); /* virtual methods */ + void (* activate) (NautilusNavigationBar *bar); char * (* get_location) (NautilusNavigationBar *bar); void (* set_location) (NautilusNavigationBar *bar, const char *location); @@ -58,6 +59,7 @@ typedef struct { } NautilusNavigationBarClass; GtkType nautilus_navigation_bar_get_type (void); +void nautilus_navigation_bar_activate (NautilusNavigationBar *bar); char * nautilus_navigation_bar_get_location (NautilusNavigationBar *bar); void nautilus_navigation_bar_set_location (NautilusNavigationBar *bar, const char *location); diff --git a/src/nautilus-simple-search-bar.c b/src/nautilus-simple-search-bar.c index cf58e4a64..abb4b0074 100644 --- a/src/nautilus-simple-search-bar.c +++ b/src/nautilus-simple-search-bar.c @@ -42,6 +42,7 @@ struct NautilusSimpleSearchBarDetails { GtkWidget *find_button; }; +static void real_activate (NautilusNavigationBar *bar); static char * nautilus_simple_search_bar_get_location (NautilusNavigationBar *bar); static void nautilus_simple_search_bar_set_location (NautilusNavigationBar *bar, const char *location); @@ -62,6 +63,7 @@ nautilus_simple_search_bar_initialize_class (NautilusSimpleSearchBarClass *klass { GTK_OBJECT_CLASS (klass)->destroy = nautilus_simple_search_bar_destroy; + NAUTILUS_NAVIGATION_BAR_CLASS (klass)->activate = real_activate; NAUTILUS_NAVIGATION_BAR_CLASS (klass)->get_location = nautilus_simple_search_bar_get_location; NAUTILUS_NAVIGATION_BAR_CLASS (klass)->set_location = nautilus_simple_search_bar_set_location; } @@ -143,6 +145,17 @@ nautilus_simple_search_bar_new (void) } static void +real_activate (NautilusNavigationBar *navigation_bar) +{ + NautilusSimpleSearchBar *bar; + + bar = NAUTILUS_SIMPLE_SEARCH_BAR (navigation_bar); + + /* Put the keyboard focus in the text field when switching to search mode */ + gtk_widget_grab_focus (GTK_WIDGET (bar->details->entry)); +} + +static void nautilus_simple_search_bar_set_location (NautilusNavigationBar *navigation_bar, const char *location) { diff --git a/src/nautilus-switchable-navigation-bar.c b/src/nautilus-switchable-navigation-bar.c index 7345a803a..e4b8c8bce 100644 --- a/src/nautilus-switchable-navigation-bar.c +++ b/src/nautilus-switchable-navigation-bar.c @@ -41,6 +41,13 @@ #include <libnautilus-extensions/nautilus-string.h> #include <stdio.h> +struct NautilusSwitchableNavigationBarDetails { + NautilusSwitchableNavigationBarMode mode; + + NautilusLocationBar *location_bar; + NautilusSwitchableSearchBar *search_bar; +}; + enum { MODE_CHANGED, LAST_SIGNAL @@ -53,6 +60,7 @@ static void nautilus_switchable_navigation_bar_set_location (NautilusNaviga const char *location); static void nautilus_switchable_navigation_bar_initialize_class (NautilusSwitchableNavigationBarClass *class); static void nautilus_switchable_navigation_bar_initialize (NautilusSwitchableNavigationBar *bar); +static void nautilus_switchable_navigation_bar_destroy (GtkObject *object); NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusSwitchableNavigationBar, nautilus_switchable_navigation_bar, @@ -65,6 +73,7 @@ nautilus_switchable_navigation_bar_initialize_class (NautilusSwitchableNavigatio NautilusNavigationBarClass *navigation_bar_class; object_class = GTK_OBJECT_CLASS (klass); + navigation_bar_class = NAUTILUS_NAVIGATION_BAR_CLASS (klass); signals[MODE_CHANGED] = gtk_signal_new ("mode_changed", @@ -77,7 +86,7 @@ nautilus_switchable_navigation_bar_initialize_class (NautilusSwitchableNavigatio gtk_object_class_add_signals (object_class, signals, LAST_SIGNAL); - navigation_bar_class = NAUTILUS_NAVIGATION_BAR_CLASS (klass); + object_class->destroy = nautilus_switchable_navigation_bar_destroy; navigation_bar_class->get_location = nautilus_switchable_navigation_bar_get_location; navigation_bar_class->set_location = nautilus_switchable_navigation_bar_set_location; @@ -88,29 +97,38 @@ nautilus_switchable_navigation_bar_initialize (NautilusSwitchableNavigationBar * { GtkWidget *hbox; + bar->details = g_new0 (NautilusSwitchableNavigationBarDetails, 1); + hbox = gtk_hbox_new (0, FALSE); - bar->location_bar = nautilus_location_bar_new (); - bar->search_bar = nautilus_switchable_search_bar_new (); + bar->details->location_bar = NAUTILUS_LOCATION_BAR (nautilus_location_bar_new ()); + bar->details->search_bar = NAUTILUS_SWITCHABLE_SEARCH_BAR (nautilus_switchable_search_bar_new ()); - gtk_signal_connect_object (GTK_OBJECT (bar->location_bar), + gtk_signal_connect_object (GTK_OBJECT (bar->details->location_bar), "location_changed", nautilus_navigation_bar_location_changed, GTK_OBJECT (bar)); - gtk_signal_connect_object (GTK_OBJECT (bar->search_bar), + gtk_signal_connect_object (GTK_OBJECT (bar->details->search_bar), "location_changed", nautilus_navigation_bar_location_changed, GTK_OBJECT (bar)); - gtk_box_pack_start (GTK_BOX (hbox), bar->location_bar, TRUE, TRUE, + gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (bar->details->location_bar), TRUE, TRUE, 0); - gtk_box_pack_start (GTK_BOX (hbox), bar->search_bar, TRUE, TRUE, + gtk_box_pack_start (GTK_BOX (hbox), GTK_WIDGET (bar->details->search_bar), TRUE, TRUE, 0); - gtk_widget_show (GTK_WIDGET (bar->location_bar)); + gtk_widget_show (GTK_WIDGET (bar->details->location_bar)); gtk_widget_show (GTK_WIDGET (hbox)); gtk_container_add (GTK_CONTAINER (bar), hbox); } +static void +nautilus_switchable_navigation_bar_destroy (GtkObject *object) +{ + g_free (NAUTILUS_SWITCHABLE_NAVIGATION_BAR (object)->details); + NAUTILUS_CALL_PARENT_CLASS (GTK_OBJECT_CLASS, destroy, (object)); +} + GtkWidget * nautilus_switchable_navigation_bar_new (void) { @@ -120,31 +138,33 @@ nautilus_switchable_navigation_bar_new (void) NautilusSwitchableNavigationBarMode nautilus_switchable_navigation_bar_get_mode (NautilusSwitchableNavigationBar *bar) { - return bar->mode; + return bar->details->mode; } void nautilus_switchable_navigation_bar_set_mode (NautilusSwitchableNavigationBar *bar, NautilusSwitchableNavigationBarMode mode) { - if (bar->mode == mode) { + if (bar->details->mode == mode) { return; } switch (mode) { case NAUTILUS_SWITCHABLE_NAVIGATION_BAR_MODE_LOCATION: - gtk_widget_show (bar->location_bar); - gtk_widget_hide (bar->search_bar); + gtk_widget_show (GTK_WIDGET (bar->details->location_bar)); + nautilus_navigation_bar_activate (NAUTILUS_NAVIGATION_BAR (bar->details->location_bar)); + gtk_widget_hide (GTK_WIDGET (bar->details->search_bar)); break; case NAUTILUS_SWITCHABLE_NAVIGATION_BAR_MODE_SEARCH: - gtk_widget_show (bar->search_bar); - gtk_widget_hide (bar->location_bar); + gtk_widget_show (GTK_WIDGET (bar->details->search_bar)); + nautilus_navigation_bar_activate (NAUTILUS_NAVIGATION_BAR (bar->details->search_bar)); + gtk_widget_hide (GTK_WIDGET (bar->details->location_bar)); break; default: g_return_if_fail (mode && 0); } - bar->mode = mode; + bar->details->mode = mode; gtk_signal_emit (GTK_OBJECT (bar), signals[MODE_CHANGED], mode); } @@ -155,11 +175,11 @@ nautilus_switchable_navigation_bar_get_location (NautilusNavigationBar *navigati bar = NAUTILUS_SWITCHABLE_NAVIGATION_BAR (navigation_bar); - switch (bar->mode) { + switch (bar->details->mode) { case NAUTILUS_SWITCHABLE_NAVIGATION_BAR_MODE_LOCATION: - return nautilus_navigation_bar_get_location (NAUTILUS_NAVIGATION_BAR (bar->location_bar)); + return nautilus_navigation_bar_get_location (NAUTILUS_NAVIGATION_BAR (bar->details->location_bar)); case NAUTILUS_SWITCHABLE_NAVIGATION_BAR_MODE_SEARCH: - return nautilus_navigation_bar_get_location (NAUTILUS_NAVIGATION_BAR (bar->search_bar)); + return nautilus_navigation_bar_get_location (NAUTILUS_NAVIGATION_BAR (bar->details->search_bar)); default: g_assert_not_reached (); return NULL; @@ -177,9 +197,9 @@ nautilus_switchable_navigation_bar_set_location (NautilusNavigationBar *navigati /* Set location for both bars so if we switch things will * still look OK. */ - nautilus_navigation_bar_set_location (NAUTILUS_NAVIGATION_BAR (bar->location_bar), + nautilus_navigation_bar_set_location (NAUTILUS_NAVIGATION_BAR (bar->details->location_bar), location); - nautilus_navigation_bar_set_location (NAUTILUS_NAVIGATION_BAR (bar->search_bar), + nautilus_navigation_bar_set_location (NAUTILUS_NAVIGATION_BAR (bar->details->search_bar), location); /* Toggle the search button on and off appropriately */ diff --git a/src/nautilus-switchable-navigation-bar.h b/src/nautilus-switchable-navigation-bar.h index bf0cb2a03..46b4b3fd1 100644 --- a/src/nautilus-switchable-navigation-bar.h +++ b/src/nautilus-switchable-navigation-bar.h @@ -43,6 +43,8 @@ #define NAUTILUS_IS_SWITCHABLE_NAVIGATION_BAR(obj) \ GTK_CHECK_TYPE (obj, NAUTILUS_TYPE_SWITCHABLE_NAVIGATION_BAR) +typedef struct NautilusSwitchableNavigationBarDetails NautilusSwitchableNavigationBarDetails; + typedef enum { NAUTILUS_SWITCHABLE_NAVIGATION_BAR_MODE_LOCATION, NAUTILUS_SWITCHABLE_NAVIGATION_BAR_MODE_SEARCH @@ -51,11 +53,7 @@ typedef enum { typedef struct NautilusSwitchableNavigationBar { NautilusNavigationBar parent; - - NautilusSwitchableNavigationBarMode mode; - - GtkWidget *location_bar; - GtkWidget *search_bar; + NautilusSwitchableNavigationBarDetails *details; } NautilusSwitchableNavigationBar; typedef struct { diff --git a/src/nautilus-switchable-search-bar.c b/src/nautilus-switchable-search-bar.c index 21e59d321..f3360a17a 100644 --- a/src/nautilus-switchable-search-bar.c +++ b/src/nautilus-switchable-search-bar.c @@ -40,6 +40,7 @@ #include <libnautilus-extensions/nautilus-global-preferences.h> #include <libnautilus-extensions/nautilus-gtk-macros.h> +static void real_activate (NautilusNavigationBar *bar); static void nautilus_switchable_search_bar_set_location (NautilusNavigationBar *bar, const char *location); static char * nautilus_switchable_search_bar_get_location (NautilusNavigationBar *bar); @@ -59,6 +60,7 @@ NAUTILUS_DEFINE_CLASS_BOILERPLATE (NautilusSwitchableSearchBar, static void nautilus_switchable_search_bar_initialize_class (NautilusSwitchableSearchBarClass *klass) { + NAUTILUS_NAVIGATION_BAR_CLASS (klass)->activate = real_activate; NAUTILUS_NAVIGATION_BAR_CLASS (klass)->get_location = nautilus_switchable_search_bar_get_location; NAUTILUS_NAVIGATION_BAR_CLASS (klass)->set_location = nautilus_switchable_search_bar_set_location; @@ -153,6 +155,29 @@ nautilus_switchable_search_bar_new (void) return gtk_widget_new (nautilus_switchable_search_bar_get_type (), NULL); } +static void +real_activate (NautilusNavigationBar *navigation_bar) +{ + NautilusSwitchableSearchBar *bar; + NautilusNavigationBar *bar_to_activate; + + bar = NAUTILUS_SWITCHABLE_SEARCH_BAR (navigation_bar); + + switch (bar->mode) { + case NAUTILUS_SIMPLE_SEARCH_BAR: + bar_to_activate = NAUTILUS_NAVIGATION_BAR (bar->simple_search_bar); + break; + case NAUTILUS_COMPLEX_SEARCH_BAR: + bar_to_activate = NAUTILUS_NAVIGATION_BAR (bar->complex_search_bar); + break; + default: + g_assert_not_reached(); + } + + g_assert (bar_to_activate != NULL); + nautilus_navigation_bar_activate (bar_to_activate); +} + void nautilus_switchable_search_bar_set_mode (NautilusSwitchableSearchBar *bar, NautilusSearchBarMode mode) |