[gthumb] fixed focusing of the thumbnail list



commit 0fab5bb0276ce26c221fe6170908e73cba0f8530
Author: Paolo Bacchilega <paobac src gnome org>
Date:   Fri Apr 13 00:29:30 2012 +0200

    fixed focusing of the thumbnail list
    
    do not focus the grid view if it is not realized yet

 gthumb/gth-browser.c       |    6 ++++--
 gthumb/gth-dumb-notebook.c |   35 ++++++++++++++++++++++++++++++++++-
 gthumb/gth-empty-list.c    |   16 +++++++++++++---
 gthumb/gth-file-list.c     |   10 ++++++++++
 4 files changed, 61 insertions(+), 6 deletions(-)
---
diff --git a/gthumb/gth-browser.c b/gthumb/gth-browser.c
index 1b0c81b..c1272a8 100644
--- a/gthumb/gth-browser.c
+++ b/gthumb/gth-browser.c
@@ -1656,6 +1656,9 @@ load_data_continue (LoadData *load_data,
 		gth_file_list_set_filter (GTH_FILE_LIST (browser->priv->thumbnail_list), filter);
 		gth_file_list_set_files (GTH_FILE_LIST (browser->priv->thumbnail_list), files);
 		g_object_unref (filter);
+
+		if (gth_window_get_current_page (GTH_WINDOW (browser)) == GTH_BROWSER_PAGE_BROWSER)
+			gtk_widget_grab_focus (browser->priv->file_list);
 	}
 
 	if (load_data->file_to_select != NULL)
@@ -2449,7 +2452,7 @@ _gth_browser_real_set_current_page (GthWindow *window,
 	/* set the focus */
 
 	if (page == GTH_BROWSER_PAGE_BROWSER)
-		gtk_widget_grab_focus (gth_browser_get_file_list_view (browser));
+		gtk_widget_grab_focus (browser->priv->file_list);
 	else if (page == GTH_BROWSER_PAGE_VIEWER)
 		_gth_browser_make_file_visible (browser, browser->priv->current_file);
 
@@ -3730,7 +3733,6 @@ _gth_browser_construct_step2 (gpointer user_data)
 
 	_gth_browser_update_entry_point_list (browser);
 	_gth_browser_monitor_entry_points (browser);
-	gtk_widget_grab_focus (gth_browser_get_file_list_view (browser));
 
 	gth_hook_invoke ("gth-browser-construct-idle-callback", browser);
 
diff --git a/gthumb/gth-dumb-notebook.c b/gthumb/gth-dumb-notebook.c
index dc76896..4a8ec18 100644
--- a/gthumb/gth-dumb-notebook.c
+++ b/gthumb/gth-dumb-notebook.c
@@ -211,6 +211,32 @@ gth_dumb_notebook_draw (GtkWidget *widget,
 
 
 static void
+_gth_dumb_notebook_grab_focus_child (GthDumbNotebook *notebook)
+{
+	GtkWidget *child;
+
+	child = notebook->priv->current;
+	if (child == NULL)
+		return;
+
+	if (GTK_IS_SCROLLED_WINDOW (notebook->priv->current)) {
+		GList *list = gtk_container_get_children (GTK_CONTAINER (notebook->priv->current));
+		if (list != NULL)
+			child = list->data;
+	}
+
+	gtk_widget_grab_focus (child);
+}
+
+
+static void
+gth_dumb_notebook_grab_focus (GtkWidget *widget)
+{
+	_gth_dumb_notebook_grab_focus_child (GTH_DUMB_NOTEBOOK (widget));
+}
+
+
+static void
 gth_dumb_notebook_add (GtkContainer *container,
 		       GtkWidget    *child)
 {
@@ -300,6 +326,7 @@ gth_dumb_notebook_class_init (GthDumbNotebookClass *klass)
 	widget_class->get_preferred_height_for_width = gth_dumb_notebook_get_preferred_height_for_width;
 	widget_class->size_allocate = gth_dumb_notebook_size_allocate;
 	widget_class->draw = gth_dumb_notebook_draw;
+	widget_class->grab_focus = gth_dumb_notebook_grab_focus;
 
 	container_class = GTK_CONTAINER_CLASS (klass);
 	container_class->add = gth_dumb_notebook_add;
@@ -313,6 +340,7 @@ static void
 gth_dumb_notebook_init (GthDumbNotebook *notebook) 
 {
 	gtk_widget_set_has_window (GTK_WIDGET (notebook), FALSE);
+	gtk_widget_set_can_focus (GTK_WIDGET (notebook), TRUE);
 	
 	notebook->priv = g_new0 (GthDumbNotebookPrivate, 1);
 	notebook->priv->n_children = 0;	
@@ -331,18 +359,23 @@ void
 gth_dumb_notebook_show_child (GthDumbNotebook *notebook,
 			      int              pos)
 {
-	GList *link;
+	GList    *link;
+	gboolean  current_is_focus;
 	
 	link = g_list_nth (notebook->priv->children, pos);
 	if (link == NULL)
 		return;
 
+	current_is_focus = (notebook->priv->current != NULL) && gtk_widget_has_focus (notebook->priv->current);
+
 	if (notebook->priv->current != link->data)
 		gtk_widget_set_child_visible (notebook->priv->current, FALSE);
 
 	notebook->priv->current_pos = pos;
 	notebook->priv->current = link->data;
 	gtk_widget_set_child_visible (notebook->priv->current, TRUE);
+	if (current_is_focus)
+		_gth_dumb_notebook_grab_focus_child (notebook);
 
 	gtk_widget_queue_resize (GTK_WIDGET (notebook));
 }
diff --git a/gthumb/gth-empty-list.c b/gthumb/gth-empty-list.c
index f7e8cc0..8e97d8d 100644
--- a/gthumb/gth-empty-list.c
+++ b/gthumb/gth-empty-list.c
@@ -238,6 +238,16 @@ gth_empty_list_draw (GtkWidget *widget,
 }
 
 
+static gboolean
+gth_empty_list_button_press (GtkWidget      *widget,
+			     GdkEventButton *event)
+{
+	if (! gtk_widget_has_focus (widget))
+		gtk_widget_grab_focus (widget);
+	return TRUE;
+}
+
+
 static void 
 gth_empty_list_class_init (GthEmptyListClass *klass) 
 {
@@ -258,7 +268,8 @@ gth_empty_list_class_init (GthEmptyListClass *klass)
 	widget_class->unmap = gth_empty_list_unmap;
 	widget_class->size_allocate = gth_empty_list_size_allocate;
 	widget_class->draw = gth_empty_list_draw;
-	
+	widget_class->button_press_event = gth_empty_list_button_press;
+
 	/* properties */
 	
 	g_object_class_install_property (object_class,
@@ -277,6 +288,7 @@ gth_empty_list_init (GthEmptyList *self)
 	GtkStyleContext *style_context;
 
 	gtk_widget_set_has_window (GTK_WIDGET (self), TRUE);
+	gtk_widget_set_can_focus (GTK_WIDGET (self), TRUE);
 
 	self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self, GTH_TYPE_EMPTY_LIST, GthEmptyListPrivate);
 	self->priv->layout = NULL;
@@ -285,8 +297,6 @@ gth_empty_list_init (GthEmptyList *self)
 	style_context = gtk_widget_get_style_context (GTK_WIDGET (self));
 	gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_VIEW);
 	gtk_style_context_add_class (style_context, GTK_STYLE_CLASS_FRAME);
-
-	gtk_widget_set_can_focus (GTK_WIDGET (self), FALSE);
 }
 
 
diff --git a/gthumb/gth-file-list.c b/gthumb/gth-file-list.c
index 2eec4ee..1666dbe 100644
--- a/gthumb/gth-file-list.c
+++ b/gthumb/gth-file-list.c
@@ -354,6 +354,15 @@ gth_file_list_get_preferred_height (GtkWidget *widget,
 
 
 static void
+gth_file_list_grab_focus (GtkWidget *widget)
+{
+	GthFileList *file_list = GTH_FILE_LIST (widget);
+
+	gtk_widget_grab_focus (file_list->priv->notebook);
+}
+
+
+static void
 gth_file_list_class_init (GthFileListClass *class)
 {
 	GObjectClass   *object_class;
@@ -366,6 +375,7 @@ gth_file_list_class_init (GthFileListClass *class)
 	widget_class->get_request_mode = gth_file_list_get_request_mode;
 	widget_class->get_preferred_width = gth_file_list_get_preferred_width;
 	widget_class->get_preferred_height = gth_file_list_get_preferred_height;
+	widget_class->grab_focus = gth_file_list_grab_focus;
 }
 
 



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