[gedit] Override the grab-focus signals.



commit f2ebdbe480670da0e264cdb96a5ffea6e7c7881b
Author: Ignacio Casal Quinteiro <icq gnome org>
Date:   Sun May 23 16:48:59 2010 +0200

    Override the grab-focus signals.
    
    When a notebook is focused the tab gets the focus, and when the
    tab gets the focus either the message area if exists grabs the
    focus of the view if the message area doesn't exists.

 gedit/gedit-notebook.c |   27 ++++++++++++++++++++-------
 gedit/gedit-tab.c      |   20 ++++++++++++++++++++
 gedit/gedit-window.c   |    8 +++-----
 3 files changed, 43 insertions(+), 12 deletions(-)
---
diff --git a/gedit/gedit-notebook.c b/gedit/gedit-notebook.c
index ee2412d..ea3dd29 100644
--- a/gedit/gedit-notebook.c
+++ b/gedit/gedit-notebook.c
@@ -126,14 +126,31 @@ gedit_notebook_destroy (GtkObject *object)
 }
 
 static void
+gedit_notebook_grab_focus (GtkWidget *widget)
+{
+	GtkNotebook *nb = GTK_NOTEBOOK (widget);
+	GtkWidget *tab;
+	gint current_page;
+
+	GTK_WIDGET_CLASS (gedit_notebook_parent_class)->grab_focus (widget);
+
+	current_page = gtk_notebook_get_current_page (nb);
+	tab = gtk_notebook_get_nth_page (nb, current_page);
+
+	gtk_widget_grab_focus (tab);
+}
+
+static void
 gedit_notebook_class_init (GeditNotebookClass *klass)
 {
 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
 	GtkObjectClass *gtkobject_class = GTK_OBJECT_CLASS (klass);
+	GtkWidgetClass *gtkwidget_class = GTK_WIDGET_CLASS (klass);
 	GtkNotebookClass *notebook_class = GTK_NOTEBOOK_CLASS (klass);
 
 	object_class->finalize = gedit_notebook_finalize;
 	gtkobject_class->destroy = gedit_notebook_destroy;
+	gtkwidget_class->grab_focus = gedit_notebook_grab_focus;
 	
 	notebook_class->change_current_page = gedit_notebook_change_current_page;
 
@@ -679,9 +696,8 @@ gedit_notebook_switch_page_cb (GtkNotebook     *notebook,
 	nb->priv->focused_pages = g_list_append (nb->priv->focused_pages,
 						 child);
 
-	/* give focus to the view */
-	view = gedit_tab_get_view (GEDIT_TAB (child));
-	gtk_widget_grab_focus (GTK_WIDGET (view));
+	/* give focus to the tab */
+	gtk_widget_grab_focus (child);
 }
 
 /*
@@ -894,15 +910,12 @@ gedit_notebook_add_tab (GeditNotebook *nb,
 
 	if (jump_to)
 	{
-		GeditView *view;
-		
 		gtk_notebook_set_current_page (GTK_NOTEBOOK (nb), position);
 		g_object_set_data (G_OBJECT (tab), 
 				   "jump_to",
 				   GINT_TO_POINTER (jump_to));
-		view = gedit_tab_get_view (tab);
 		
-		gtk_widget_grab_focus (GTK_WIDGET (view));
+		gtk_widget_grab_focus (GTK_WIDGET (tab));
 	}
 }
 
diff --git a/gedit/gedit-tab.c b/gedit/gedit-tab.c
index 95d9946..f5fa548 100644
--- a/gedit/gedit-tab.c
+++ b/gedit/gedit-tab.c
@@ -260,10 +260,28 @@ gedit_tab_finalize (GObject *object)
 	G_OBJECT_CLASS (gedit_tab_parent_class)->finalize (object);
 }
 
+static void
+gedit_tab_grab_focus (GtkWidget *widget)
+{
+	GeditTab *tab = GEDIT_TAB (widget);
+	
+	GTK_WIDGET_CLASS (gedit_tab_parent_class)->grab_focus (widget);
+	
+	if (tab->priv->message_area != NULL)
+	{
+		gtk_widget_grab_focus (tab->priv->message_area);
+	}
+	else
+	{
+		gtk_widget_grab_focus (GTK_WIDGET (gedit_tab_get_view (tab)));
+	}
+}
+
 static void 
 gedit_tab_class_init (GeditTabClass *klass)
 {
 	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	GtkWidgetClass *gtkwidget_class = GTK_WIDGET_CLASS (klass);
 
 	object_class->dispose = gedit_tab_dispose;
 	object_class->finalize = gedit_tab_finalize;
@@ -271,6 +289,8 @@ gedit_tab_class_init (GeditTabClass *klass)
 	object_class->get_property = gedit_tab_get_property;
 	object_class->set_property = gedit_tab_set_property;
 	
+	gtkwidget_class->grab_focus = gedit_tab_grab_focus;
+	
 	g_object_class_install_property (object_class,
 					 PROP_NAME,
 					 g_param_spec_string ("name",
diff --git a/gedit/gedit-window.c b/gedit/gedit-window.c
index fbb22db..d5c39ff 100644
--- a/gedit/gedit-window.c
+++ b/gedit/gedit-window.c
@@ -3802,8 +3802,7 @@ side_panel_visibility_changed (GtkWidget   *side_panel,
 	/* focus the document */
 	if (!visible && window->priv->active_tab != NULL)
 	{
-		gtk_widget_grab_focus (GTK_WIDGET (
-				gedit_tab_get_view (GEDIT_TAB (window->priv->active_tab))));
+		gtk_widget_grab_focus (window->priv->active_tab);
 	}
 }
 
@@ -3860,8 +3859,7 @@ bottom_panel_visibility_changed (GeditPanel  *bottom_panel,
 	/* focus the document */
 	if (!visible && window->priv->active_tab != NULL)
 	{
-		gtk_widget_grab_focus (GTK_WIDGET (
-				gedit_tab_get_view (GEDIT_TAB (window->priv->active_tab))));
+		gtk_widget_grab_focus (window->priv->active_tab);
 	}
 }
 
@@ -4638,7 +4636,7 @@ gedit_window_set_active_tab (GeditWindow *window,
 				       page_num);
 
 	/* Make sure to grab focus if the page didn't change */
-	gtk_widget_grab_focus (GTK_WIDGET (gedit_tab_get_view (tab)));
+	gtk_widget_grab_focus (GTK_WIDGET (tab));
 }
 
 /**



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