[nautilus] window: fix behavior of the Search action
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] window: fix behavior of the Search action
- Date: Mon, 21 Feb 2011 00:15:52 +0000 (UTC)
commit 322a3d0094082a32d357d0358174025c296a46dd
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Sun Feb 20 19:13:44 2011 -0500
window: fix behavior of the Search action
Make the toolbar button active state consistent with the menu, and
simplify the code handling it a bunch.
src/nautilus-shell-ui.xml | 2 +-
src/nautilus-window-menus.c | 93 +------------------
src/nautilus-window-pane.c | 205 ++++++++++++++++++++++++++++++++++---------
src/nautilus-window-pane.h | 7 +-
src/nautilus-window.c | 103 ----------------------
src/nautilus-window.h | 5 -
6 files changed, 173 insertions(+), 242 deletions(-)
---
diff --git a/src/nautilus-shell-ui.xml b/src/nautilus-shell-ui.xml
index ea843e6..0f3c8e2 100644
--- a/src/nautilus-shell-ui.xml
+++ b/src/nautilus-shell-ui.xml
@@ -1,5 +1,5 @@
<ui>
-<accelerator action="ShowSearch"/>
+<accelerator action="Search"/>
<accelerator action="SplitViewNextPane"/>
<accelerator action="TabsPrevious"/>
<accelerator action="TabsNext"/>
diff --git a/src/nautilus-window-menus.c b/src/nautilus-window-menus.c
index 62e3202..bffc409 100644
--- a/src/nautilus-window-menus.c
+++ b/src/nautilus-window-menus.c
@@ -855,84 +855,6 @@ action_go_to_location_callback (GtkAction *action,
nautilus_window_prompt_for_location (window, NULL);
}
-/* The ctrl-f Keyboard shortcut always enables, rather than toggles
- the search mode */
-static void
-action_show_search_callback (GtkAction *action,
- gpointer user_data)
-{
- GtkAction *search_action;
- NautilusWindow *window;
-
- window = NAUTILUS_WINDOW (user_data);
-
- search_action =
- gtk_action_group_get_action (window->details->main_action_group,
- NAUTILUS_ACTION_SEARCH);
-
- if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (search_action))) {
- /* Already visible, just show it */
- nautilus_window_show_search (window);
- } else {
- /* Otherwise, enable */
- gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (search_action),
- TRUE);
- }
-}
-
-static void
-action_show_hide_search_callback (GtkAction *action,
- gpointer user_data)
-{
- NautilusWindow *window;
-
- /* This is used when toggling the action for updating the UI
- state only, not actually activating the action */
- if (g_object_get_data (G_OBJECT (action), "blocked") != NULL) {
- return;
- }
-
- window = NAUTILUS_WINDOW (user_data);
-
- if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
- nautilus_window_show_search (window);
- } else {
- NautilusWindowSlot *slot;
- GFile *location = NULL;
-
- slot = NAUTILUS_WINDOW (window)->details->active_pane->active_slot;
-
- /* Use the location bar as the return location */
- if (slot->query_editor == NULL){
- location = nautilus_window_slot_get_location (slot);
- /* Use the search location as the return location */
- } else {
- NautilusQuery *query;
- char *uri;
-
- query = nautilus_query_editor_get_query (slot->query_editor);
- if (query != NULL) {
- uri = nautilus_query_get_location (query);
- if (uri != NULL) {
- location = g_file_new_for_uri (uri);
- g_free (uri);
- }
- g_object_unref (query);
- }
- }
-
- /* Last try: use the home directory as the return location */
- if (location == NULL) {
- location = g_file_new_for_path (g_get_home_dir ());
- }
-
- nautilus_window_go_to (NAUTILUS_WINDOW (window), location);
- g_object_unref (location);
-
- nautilus_window_hide_search (window);
- }
-}
-
static void
action_tabs_previous_callback (GtkAction *action,
gpointer user_data)
@@ -1146,9 +1068,6 @@ static const GtkActionEntry main_entries[] = {
{ "TabsMoveRight", NULL, N_("Move Tab _Right"), "<shift><control>Page_Down",
N_("Move current tab to right"),
G_CALLBACK (action_tabs_move_right_callback) },
- { "ShowSearch", NULL, N_("S_how Search"), "<control>f",
- N_("Show search"),
- G_CALLBACK (action_show_search_callback) },
{ "Sidebar List", NULL, N_("Sidebar") }
};
@@ -1174,10 +1093,9 @@ static const GtkToggleActionEntry main_toggle_entries[] = {
NULL,
/* is_active */ TRUE },
/* name, stock id */ { "Search", "edit-find-symbolic",
- /* label, accelerator */ N_("_Search for Files..."),
- /* Accelerator is in ShowSearch */"",
+ /* label, accelerator */ N_("_Search for Files..."), "<control>f",
/* tooltip */ N_("Search documents and folders by name"),
- G_CALLBACK (action_show_hide_search_callback),
+ NULL,
/* is_active */ FALSE },
/* name, stock id */ { NAUTILUS_ACTION_SHOW_HIDE_EXTRA_PANE, NULL,
/* label, accelerator */ N_("E_xtra Pane"), "F3",
@@ -1235,12 +1153,10 @@ nautilus_window_create_toolbar_action_group (NautilusWindow *window)
g_object_unref (action);
action = GTK_ACTION
- (gtk_toggle_action_new ("Search",
+ (gtk_toggle_action_new (NAUTILUS_ACTION_SEARCH,
_("Search"),
_("Search documents and folders by name"),
NULL));
- g_signal_connect (action, "activate",
- G_CALLBACK (action_show_hide_search_callback), window);
gtk_action_group_add_action (action_group, action);
gtk_action_set_icon_name (GTK_ACTION (action), "edit-find-symbolic");
gtk_action_set_is_important (GTK_ACTION (action), TRUE);
@@ -1291,7 +1207,8 @@ nautilus_window_initialize_actions (NautilusWindow *window)
{
GtkActionGroup *action_group;
const gchar *nav_state_actions[] = {
- NAUTILUS_ACTION_BACK, NAUTILUS_ACTION_FORWARD, NULL
+ NAUTILUS_ACTION_BACK, NAUTILUS_ACTION_FORWARD,
+ NAUTILUS_ACTION_SEARCH, NULL
};
action_group = window->details->main_action_group;
diff --git a/src/nautilus-window-pane.c b/src/nautilus-window-pane.c
index c9ff6d0..216bf32 100644
--- a/src/nautilus-window-pane.c
+++ b/src/nautilus-window-pane.c
@@ -26,13 +26,15 @@
*
*/
+#include "nautilus-window-pane.h"
+
+#include "nautilus-actions.h"
#include "nautilus-clipboard.h"
#include "nautilus-location-bar.h"
#include "nautilus-notebook.h"
#include "nautilus-pathbar.h"
#include "nautilus-toolbar.h"
#include "nautilus-window-manage-views.h"
-#include "nautilus-window-pane.h"
#include "nautilus-window-private.h"
#include <libnautilus-private/nautilus-global-preferences.h>
@@ -41,6 +43,61 @@
G_DEFINE_TYPE (NautilusWindowPane, nautilus_window_pane,
G_TYPE_OBJECT)
+static gboolean
+widget_is_in_temporary_bars (GtkWidget *widget,
+ NautilusWindowPane *pane)
+{
+ gboolean res = FALSE;
+
+ if ((gtk_widget_get_ancestor (widget, NAUTILUS_TYPE_LOCATION_BAR) != NULL &&
+ pane->temporary_navigation_bar) ||
+ (gtk_widget_get_ancestor (widget, NAUTILUS_TYPE_SEARCH_BAR) != NULL &&
+ pane->temporary_search_bar))
+ res = TRUE;
+
+ return res;
+}
+
+static void
+unset_focus_widget (NautilusWindowPane *pane)
+{
+ if (pane->last_focus_widget != NULL) {
+ g_object_remove_weak_pointer (G_OBJECT (pane->last_focus_widget),
+ (gpointer *) &pane->last_focus_widget);
+ pane->last_focus_widget = NULL;
+ }
+}
+
+static void
+remember_focus_widget (NautilusWindowPane *pane)
+{
+ GtkWidget *focus_widget;
+
+ focus_widget = gtk_window_get_focus (GTK_WINDOW (pane->window));
+ if (focus_widget != NULL &&
+ !widget_is_in_temporary_bars (focus_widget, pane)) {
+ unset_focus_widget (pane);
+
+ pane->last_focus_widget = focus_widget;
+ g_object_add_weak_pointer (G_OBJECT (focus_widget),
+ (gpointer *) &(pane->last_focus_widget));
+ }
+}
+
+static void
+restore_focus_widget (NautilusWindowPane *pane)
+{
+ if (pane->last_focus_widget != NULL) {
+ if (NAUTILUS_IS_VIEW (pane->last_focus_widget)) {
+ nautilus_view_grab_focus (NAUTILUS_VIEW (pane->last_focus_widget));
+ } else {
+ gtk_widget_grab_focus (pane->last_focus_widget);
+ }
+
+ unset_focus_widget (pane);
+ }
+}
+
static inline NautilusWindowSlot *
get_first_inactive_slot (NautilusWindowPane *pane)
{
@@ -150,10 +207,12 @@ static void
search_bar_cancel_callback (GtkWidget *widget,
NautilusWindowPane *pane)
{
- nautilus_toolbar_set_show_search_bar (NAUTILUS_TOOLBAR (pane->tool_bar), FALSE);
+ GtkAction *search;
- nautilus_window_pane_hide_search_bar (pane);
- nautilus_window_restore_focus_widget (pane->window);
+ search = gtk_action_group_get_action (pane->action_group,
+ NAUTILUS_ACTION_SEARCH);
+
+ gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (search), FALSE);
}
static void
@@ -163,7 +222,39 @@ navigation_bar_cancel_callback (GtkWidget *widget,
nautilus_toolbar_set_show_location_entry (NAUTILUS_TOOLBAR (pane->tool_bar), FALSE);
nautilus_window_pane_hide_temporary_bars (pane);
- nautilus_window_restore_focus_widget (pane->window);
+ restore_focus_widget (pane);
+}
+
+static void
+nautilus_window_pane_ensure_search_bar (NautilusWindowPane *pane)
+{
+ remember_focus_widget (pane);
+
+ nautilus_toolbar_set_show_search_bar (NAUTILUS_TOOLBAR (pane->tool_bar), TRUE);
+
+ if (!g_settings_get_boolean (nautilus_window_state,
+ NAUTILUS_WINDOW_STATE_START_WITH_TOOLBAR)) {
+ nautilus_toolbar_set_show_main_bar (NAUTILUS_TOOLBAR (pane->tool_bar), FALSE);
+ gtk_widget_show (pane->tool_bar);
+ nautilus_search_bar_clear (NAUTILUS_SEARCH_BAR (pane->search_bar));
+
+ pane->temporary_search_bar = TRUE;
+ }
+
+ nautilus_search_bar_grab_focus (NAUTILUS_SEARCH_BAR (pane->search_bar));
+}
+
+static void
+nautilus_window_pane_hide_search_bar (NautilusWindowPane *pane)
+{
+ nautilus_toolbar_set_show_search_bar (NAUTILUS_TOOLBAR (pane->tool_bar), FALSE);
+ restore_focus_widget (pane);
+
+ if (pane->temporary_search_bar) {
+ pane->temporary_search_bar = FALSE;
+
+ gtk_widget_hide (pane->tool_bar);
+ }
}
static void
@@ -177,7 +268,7 @@ navigation_bar_location_changed_callback (GtkWidget *widget,
nautilus_window_pane_hide_search_bar (pane);
nautilus_window_pane_hide_temporary_bars (pane);
- nautilus_window_restore_focus_widget (pane->window);
+ restore_focus_widget (pane);
location = g_file_new_for_uri (uri);
nautilus_window_slot_go_to (pane->active_slot, location, FALSE);
@@ -509,6 +600,63 @@ real_set_active (NautilusWindowPane *pane,
}
static void
+action_show_hide_search_callback (GtkAction *action,
+ gpointer user_data)
+{
+ NautilusWindowPane *pane = user_data;
+ NautilusWindow *window = pane->window;
+
+ if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action))) {
+ nautilus_window_pane_ensure_search_bar (pane);
+ } else {
+ NautilusWindowSlot *slot;
+ GFile *location = NULL;
+
+ slot = pane->active_slot;
+
+ /* Use the location bar as the return location */
+ if (slot->query_editor == NULL){
+ location = nautilus_window_slot_get_location (slot);
+ /* Use the search location as the return location */
+ } else {
+ NautilusQuery *query;
+ char *uri;
+
+ query = nautilus_query_editor_get_query (slot->query_editor);
+ if (query != NULL) {
+ uri = nautilus_query_get_location (query);
+ if (uri != NULL) {
+ location = g_file_new_for_uri (uri);
+ g_free (uri);
+ }
+ g_object_unref (query);
+ }
+ }
+
+ /* Last try: use the home directory as the return location */
+ if (location == NULL) {
+ location = g_file_new_for_path (g_get_home_dir ());
+ }
+
+ nautilus_window_go_to (window, location);
+ g_object_unref (location);
+
+ nautilus_window_pane_hide_search_bar (pane);
+ }
+}
+
+static void
+setup_search_action (NautilusWindowPane *pane)
+{
+ GtkActionGroup *group = pane->action_group;
+ GtkAction *action;
+
+ action = gtk_action_group_get_action (group, NAUTILUS_ACTION_SEARCH);
+ g_signal_connect (action, "activate",
+ G_CALLBACK (action_show_hide_search_callback), pane);
+}
+
+static void
nautilus_window_pane_setup (NautilusWindowPane *pane)
{
GtkSizeGroup *header_size_group;
@@ -525,6 +673,8 @@ nautilus_window_pane_setup (NautilusWindowPane *pane)
pane->tool_bar = nautilus_toolbar_new (action_group);
pane->action_group = action_group;
+ setup_search_action (pane);
+
gtk_box_pack_start (GTK_BOX (pane->widget),
pane->tool_bar,
FALSE, FALSE, 0);
@@ -609,6 +759,8 @@ nautilus_window_pane_dispose (GObject *object)
{
NautilusWindowPane *pane = NAUTILUS_WINDOW_PANE (object);
+ unset_focus_widget (pane);
+
pane->window = NULL;
gtk_widget_destroy (pane->widget);
g_clear_object (&pane->action_group);
@@ -719,9 +871,9 @@ nautilus_window_pane_sync_location_widgets (NautilusWindowPane *pane)
/* Check if the back and forward buttons need enabling or disabling. */
active_slot = pane->window->details->active_pane->active_slot;
nautilus_window_allow_back (pane->window,
- active_slot->back_list != NULL);
+ active_slot->back_list != NULL);
nautilus_window_allow_forward (pane->window,
- active_slot->forward_list != NULL);
+ active_slot->forward_list != NULL);
}
}
@@ -745,7 +897,7 @@ nautilus_window_pane_sync_search_widgets (NautilusWindowPane *pane)
nautilus_toolbar_set_show_search_bar (NAUTILUS_TOOLBAR (pane->tool_bar), TRUE);
pane->temporary_search_bar = FALSE;
} else {
- nautilus_toolbar_set_show_search_bar (NAUTILUS_TOOLBAR (pane->tool_bar), FALSE);
+ search_bar_cancel_callback (pane->search_bar, pane);
}
nautilus_directory_unref (directory);
@@ -798,24 +950,10 @@ nautilus_window_pane_grab_focus (NautilusWindowPane *pane)
}
void
-nautilus_window_pane_hide_search_bar (NautilusWindowPane *pane)
-{
- nautilus_toolbar_set_show_search_bar (NAUTILUS_TOOLBAR (pane->tool_bar), FALSE);
-
- if (pane->temporary_search_bar) {
- NautilusWindow *window;
-
- window = pane->window;
- nautilus_window_set_search_button (window, FALSE);
- pane->temporary_search_bar = FALSE;
-
- gtk_widget_hide (pane->tool_bar);
- }
-}
-
-void
nautilus_window_pane_ensure_location_bar (NautilusWindowPane *pane)
{
+ remember_focus_widget (pane);
+
nautilus_toolbar_set_show_main_bar (NAUTILUS_TOOLBAR (pane->tool_bar), TRUE);
nautilus_toolbar_set_show_location_entry (NAUTILUS_TOOLBAR (pane->tool_bar), TRUE);
@@ -830,23 +968,6 @@ nautilus_window_pane_ensure_location_bar (NautilusWindowPane *pane)
}
void
-nautilus_window_pane_ensure_search_bar (NautilusWindowPane *pane)
-{
- nautilus_toolbar_set_show_search_bar (NAUTILUS_TOOLBAR (pane->tool_bar), TRUE);
-
- if (!g_settings_get_boolean (nautilus_window_state,
- NAUTILUS_WINDOW_STATE_START_WITH_TOOLBAR)) {
- nautilus_toolbar_set_show_main_bar (NAUTILUS_TOOLBAR (pane->tool_bar), FALSE);
- gtk_widget_show (pane->tool_bar);
- nautilus_search_bar_clear (NAUTILUS_SEARCH_BAR (pane->search_bar));
-
- pane->temporary_search_bar = TRUE;
- }
-
- nautilus_search_bar_grab_focus (NAUTILUS_SEARCH_BAR (pane->search_bar));
-}
-
-void
nautilus_window_pane_add_slot_in_tab (NautilusWindowPane *pane,
NautilusWindowSlot *slot,
NautilusWindowOpenSlotFlags flags)
diff --git a/src/nautilus-window-pane.h b/src/nautilus-window-pane.h
index 32e15ab..bf14a40 100644
--- a/src/nautilus-window-pane.h
+++ b/src/nautilus-window-pane.h
@@ -27,8 +27,9 @@
#include <glib-object.h>
+#include "nautilus-window.h"
+
#include <libnautilus-private/nautilus-icon-info.h>
-#include "nautilus-window-types.h"
#define NAUTILUS_TYPE_WINDOW_PANE (nautilus_window_pane_get_type())
#define NAUTILUS_WINDOW_PANE_CLASS(k) (G_TYPE_CHECK_CLASS_CAST((k), NAUTILUS_TYPE_WINDOW_PANE, NautilusWindowPaneClass))
@@ -81,6 +82,8 @@ struct _NautilusWindowPane {
GtkWidget *notebook;
GtkActionGroup *action_group;
+
+ GtkWidget *last_focus_widget;
};
GType nautilus_window_pane_get_type (void);
@@ -100,8 +103,6 @@ void nautilus_window_pane_grab_focus (NautilusWindowPane *pane);
/* bars */
void nautilus_window_pane_ensure_location_bar (NautilusWindowPane *pane);
-void nautilus_window_pane_ensure_search_bar (NautilusWindowPane *pane);
-void nautilus_window_pane_hide_search_bar (NautilusWindowPane *pane);
/* notebook */
void nautilus_window_pane_add_slot_in_tab (NautilusWindowPane *pane,
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index cd15c70..177af13 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -319,53 +319,6 @@ nautilus_window_sync_allow_stop (NautilusWindow *window,
}
}
-static gboolean
-nautilus_window_is_in_temporary_bars (GtkWidget *widget,
- NautilusWindow *window)
-{
- GList *walk;
- gboolean is_in_any = FALSE;
- NautilusWindowPane *pane;
-
- for (walk = window->details->panes; walk; walk = walk->next) {
- pane = walk->data;
-
- if ((gtk_widget_get_ancestor (widget, NAUTILUS_TYPE_LOCATION_BAR) != NULL &&
- pane->temporary_navigation_bar) ||
- (gtk_widget_get_ancestor (widget, NAUTILUS_TYPE_SEARCH_BAR) != NULL &&
- pane->temporary_search_bar))
- is_in_any = TRUE;
- }
-
- return is_in_any;
-}
-
-static void
-nautilus_window_unset_focus_widget (NautilusWindow *window)
-{
- if (window->details->last_focus_widget != NULL) {
- g_object_remove_weak_pointer (G_OBJECT (window->details->last_focus_widget),
- (gpointer *) &window->details->last_focus_widget);
- window->details->last_focus_widget = NULL;
- }
-}
-
-static void
-remember_focus_widget (NautilusWindow *window)
-{
- GtkWidget *focus_widget;
-
- focus_widget = gtk_window_get_focus (GTK_WINDOW (window));
- if (focus_widget != NULL &&
- !nautilus_window_is_in_temporary_bars (focus_widget, window)) {
- nautilus_window_unset_focus_widget (window);
-
- window->details->last_focus_widget = focus_widget;
- g_object_add_weak_pointer (G_OBJECT (focus_widget),
- (gpointer *) &(window->details->last_focus_widget));
- }
-}
-
void
nautilus_window_prompt_for_location (NautilusWindow *window,
const char *initial)
@@ -374,8 +327,6 @@ nautilus_window_prompt_for_location (NautilusWindow *window,
g_return_if_fail (NAUTILUS_IS_WINDOW (window));
- remember_focus_widget (window);
-
pane = window->details->active_pane;
nautilus_window_pane_ensure_location_bar (pane);
@@ -762,8 +713,6 @@ nautilus_window_destroy (GtkWidget *object)
window = NAUTILUS_WINDOW (object);
- nautilus_window_unset_focus_widget (window);
-
window->details->content_paned = NULL;
window->details->split_view_hpane = NULL;
@@ -2054,63 +2003,11 @@ use_extra_mouse_buttons_changed (gpointer callback_data)
mouse_extra_buttons = g_settings_get_boolean (nautilus_preferences, NAUTILUS_PREFERENCES_MOUSE_USE_EXTRA_BUTTONS);
}
-void
-nautilus_window_restore_focus_widget (NautilusWindow *window)
-{
- if (window->details->last_focus_widget != NULL) {
- if (NAUTILUS_IS_VIEW (window->details->last_focus_widget)) {
- nautilus_view_grab_focus (NAUTILUS_VIEW (window->details->last_focus_widget));
- } else {
- gtk_widget_grab_focus (window->details->last_focus_widget);
- }
-
- nautilus_window_unset_focus_widget (window);
- }
-}
/*
* Main API
*/
-void
-nautilus_window_show_search (NautilusWindow *window)
-{
- NautilusWindowPane *pane;
-
- remember_focus_widget (window);
-
- pane = window->details->active_pane;
-
- nautilus_window_pane_ensure_search_bar (pane);
-}
-
-void
-nautilus_window_hide_search (NautilusWindow *window)
-{
- NautilusWindowPane *pane = window->details->active_pane;
-
- nautilus_window_pane_hide_search_bar (pane);
- nautilus_window_restore_focus_widget (window);
-}
-
-/* This updates the UI state of the search button, but does not
- in itself trigger a search action */
-void
-nautilus_window_set_search_button (NautilusWindow *window,
- gboolean state)
-{
- GtkAction *action;
-
- action = gtk_action_group_get_action (window->details->main_action_group,
- "Search");
-
- /* Block callback so we don't activate the action and thus focus the
- search entry */
- g_object_set_data (G_OBJECT (action), "blocked", GINT_TO_POINTER (1));
- gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), state);
- g_object_set_data (G_OBJECT (action), "blocked", NULL);
-}
-
static void
nautilus_window_init (NautilusWindow *window)
{
diff --git a/src/nautilus-window.h b/src/nautilus-window.h
index b6f8aaf..7d3fd25 100644
--- a/src/nautilus-window.h
+++ b/src/nautilus-window.h
@@ -163,11 +163,6 @@ void nautilus_window_back_or_forward (NautilusWindow *window,
gboolean back,
guint distance,
gboolean new_tab);
-void nautilus_window_show_search (NautilusWindow *window);
-void nautilus_window_hide_search (NautilusWindow *window);
-void nautilus_window_set_search_button (NautilusWindow *window,
- gboolean state);
-void nautilus_window_restore_focus_widget (NautilusWindow *window);
void nautilus_window_split_view_on (NautilusWindow *window);
void nautilus_window_split_view_off (NautilusWindow *window);
gboolean nautilus_window_split_view_showing (NautilusWindow *window);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]