[nautilus/wip/gbsneto/cleanups: 4/5] project: simplify focus chain
- From: Georges Basile Stavracas Neto <gbsneto src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/gbsneto/cleanups: 4/5] project: simplify focus chain
- Date: Fri, 31 Jul 2015 15:46:37 +0000 (UTC)
commit ead1970bce544ffa4a8eba3dc0c71eb594c6c2c3
Author: Georges Basile Stavracas Neto <georges stavracas gmail com>
Date: Wed Jul 29 18:07:24 2015 -0300
project: simplify focus chain
Nautilus classes add custom methods to grab the focus
differently according to the class.
The problem with this approach, however, is that we end
up with more code coupling, since it's necessary to include
more headers to use the custom grab methods.
To fix that, make classes override GtkWidget::grab_focus
method and remove the custom methods, so widgets can simply
call gtk_widget_grab_focus.
src/nautilus-query-editor.c | 2 +-
src/nautilus-toolbar.c | 8 +-------
src/nautilus-view.c | 11 +++++++++--
src/nautilus-view.h | 1 -
src/nautilus-window-slot.c | 23 ++++++++++++++++++++++-
src/nautilus-window.c | 24 ++++++++++--------------
src/nautilus-window.h | 1 -
7 files changed, 43 insertions(+), 27 deletions(-)
---
diff --git a/src/nautilus-query-editor.c b/src/nautilus-query-editor.c
index 0e07bb2..ccdb55b 100644
--- a/src/nautilus-query-editor.c
+++ b/src/nautilus-query-editor.c
@@ -903,7 +903,7 @@ entry_key_press_event_cb (GtkWidget *widget,
NautilusQueryEditor *editor)
{
if (event->keyval == GDK_KEY_Down) {
- nautilus_window_grab_focus (NAUTILUS_WINDOW (gtk_widget_get_toplevel (GTK_WIDGET (widget))));
+ gtk_widget_grab_focus (gtk_widget_get_toplevel (GTK_WIDGET (widget)));
}
return FALSE;
}
diff --git a/src/nautilus-toolbar.c b/src/nautilus-toolbar.c
index 5d67c83..3e33d28 100644
--- a/src/nautilus-toolbar.c
+++ b/src/nautilus-toolbar.c
@@ -426,13 +426,7 @@ static void
view_menu_popover_closed (GtkPopover *popover,
NautilusToolbar *self)
{
- NautilusWindowSlot *slot;
- NautilusView *view;
-
- slot = nautilus_window_get_active_slot (self->priv->window);
- view = nautilus_window_slot_get_current_view (slot);
-
- nautilus_view_grab_focus (view);
+ gtk_widget_grab_focus (GTK_WIDGET (self->priv->window));
}
static gboolean
diff --git a/src/nautilus-view.c b/src/nautilus-view.c
index 53dddc2..d2dd51b 100644
--- a/src/nautilus-view.c
+++ b/src/nautilus-view.c
@@ -2697,12 +2697,18 @@ slot_inactive (NautilusWindowSlot *slot,
remove_update_context_menus_timeout_callback (view);
}
-void
-nautilus_view_grab_focus (NautilusView *view)
+static void
+nautilus_view_grab_focus (GtkWidget *widget)
{
/* focus the child of the scrolled window if it exists */
+ NautilusView *view;
GtkWidget *child;
+
+ view = NAUTILUS_VIEW (widget);
child = gtk_bin_get_child (GTK_BIN (view->details->scrolled_window));
+
+ GTK_WIDGET_CLASS (nautilus_view_parent_class)->grab_focus (widget);
+
if (child) {
gtk_widget_grab_focus (GTK_WIDGET (child));
}
@@ -7744,6 +7750,7 @@ nautilus_view_class_init (NautilusViewClass *klass)
widget_class->destroy = nautilus_view_destroy;
widget_class->scroll_event = nautilus_view_scroll_event;
widget_class->parent_set = nautilus_view_parent_set;
+ widget_class->grab_focus = nautilus_view_grab_focus;
g_type_class_add_private (klass, sizeof (NautilusViewDetails));
diff --git a/src/nautilus-view.h b/src/nautilus-view.h
index 95770f7..5bd42d9 100644
--- a/src/nautilus-view.h
+++ b/src/nautilus-view.h
@@ -380,7 +380,6 @@ gboolean nautilus_view_can_zoom_out (NautilusView *v
void nautilus_view_pop_up_pathbar_context_menu (NautilusView *view,
GdkEventButton *event,
const char *location);
-void nautilus_view_grab_focus (NautilusView *view);
void nautilus_view_update_menus (NautilusView *view);
void nautilus_view_update_context_menus (NautilusView *view);
diff --git a/src/nautilus-window-slot.c b/src/nautilus-window-slot.c
index 7c1daf9..f87b14b 100644
--- a/src/nautilus-window-slot.c
+++ b/src/nautilus-window-slot.c
@@ -385,7 +385,7 @@ nautilus_window_slot_set_search_visible (NautilusWindowSlot *slot,
}
if (active_slot) {
- nautilus_window_grab_focus (slot->details->window);
+ gtk_widget_grab_focus (GTK_WIDGET (slot->details->window));
}
/* Now hide the editor and clear its state */
@@ -2376,9 +2376,28 @@ nautilus_window_slot_dispose (GObject *object)
}
static void
+nautilus_window_slot_grab_focus (GtkWidget *widget)
+{
+ NautilusWindowSlot *slot;
+
+ slot = NAUTILUS_WINDOW_SLOT (widget);
+
+ GTK_WIDGET_CLASS (nautilus_window_slot_parent_class)->grab_focus (widget);
+
+ if (slot->details->search_visible) {
+ gtk_widget_grab_focus (GTK_WIDGET (slot->details->query_editor));
+ } else if (slot->details->content_view) {
+ gtk_widget_grab_focus (GTK_WIDGET (slot->details->content_view));
+ } else if (slot->details->new_content_view) {
+ gtk_widget_grab_focus (GTK_WIDGET (slot->details->new_content_view));
+ }
+}
+
+static void
nautilus_window_slot_class_init (NautilusWindowSlotClass *klass)
{
GObjectClass *oclass = G_OBJECT_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
klass->active = real_active;
klass->inactive = real_inactive;
@@ -2388,6 +2407,8 @@ nautilus_window_slot_class_init (NautilusWindowSlotClass *klass)
oclass->set_property = nautilus_window_slot_set_property;
oclass->get_property = nautilus_window_slot_get_property;
+ widget_class->grab_focus = nautilus_window_slot_grab_focus;
+
signals[ACTIVE] =
g_signal_new ("active",
G_TYPE_FROM_CLASS (klass),
diff --git a/src/nautilus-window.c b/src/nautilus-window.c
index e3c3f25..1b8d9d0 100644
--- a/src/nautilus-window.c
+++ b/src/nautilus-window.c
@@ -590,17 +590,17 @@ remember_focus_widget (NautilusWindow *window)
}
}
-void
-nautilus_window_grab_focus (NautilusWindow *window)
+static void
+nautilus_window_grab_focus (GtkWidget *widget)
{
NautilusWindowSlot *slot;
- NautilusView *view;
- slot = nautilus_window_get_active_slot (window);
- view = nautilus_window_slot_get_view (slot);
+ slot = nautilus_window_get_active_slot (NAUTILUS_WINDOW (widget));
- if (view) {
- nautilus_view_grab_focus (view);
+ GTK_WIDGET_CLASS (nautilus_window_parent_class)->grab_focus (widget);
+
+ if (slot) {
+ gtk_widget_grab_focus (GTK_WIDGET (slot));
}
}
@@ -608,12 +608,7 @@ static void
restore_focus_widget (NautilusWindow *window)
{
if (window->priv->last_focus_widget != NULL) {
- if (NAUTILUS_IS_VIEW (window->priv->last_focus_widget)) {
- nautilus_view_grab_focus (NAUTILUS_VIEW (window->priv->last_focus_widget));
- } else {
- gtk_widget_grab_focus (window->priv->last_focus_widget);
- }
-
+ gtk_widget_grab_focus (window->priv->last_focus_widget);
unset_focus_widget (window);
}
}
@@ -2285,7 +2280,7 @@ nautilus_window_view_visible (NautilusWindow *window,
nautilus_window_slot_update_title (slot);
}
- nautilus_window_grab_focus (window);
+ gtk_widget_grab_focus (GTK_WIDGET (window));
/* All slots, show window */
gtk_widget_show (GTK_WIDGET (window));
@@ -2623,6 +2618,7 @@ nautilus_window_class_init (NautilusWindowClass *class)
wclass->window_state_event = nautilus_window_state_event;
wclass->button_press_event = nautilus_window_button_press_event;
wclass->delete_event = nautilus_window_delete_event;
+ wclass->grab_focus = nautilus_window_grab_focus;
class->close = real_window_close;
diff --git a/src/nautilus-window.h b/src/nautilus-window.h
index 4b16bf7..ed102d8 100644
--- a/src/nautilus-window.h
+++ b/src/nautilus-window.h
@@ -122,7 +122,6 @@ void nautilus_window_slot_close (NautilusWindow *wind
NautilusWindowSlot *slot);
void nautilus_window_sync_location_widgets (NautilusWindow *window);
-void nautilus_window_grab_focus (NautilusWindow *window);
void nautilus_window_hide_sidebar (NautilusWindow *window);
void nautilus_window_show_sidebar (NautilusWindow *window);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]