[gedit] notebook: cosmetic changes
- From: Sébastien Wilmet <swilmet src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gedit] notebook: cosmetic changes
- Date: Wed, 10 Jun 2015 10:56:35 +0000 (UTC)
commit 8fe0690f9c0d773e4cd8df0cd27cd86fbf813b58
Author: Sébastien Wilmet <swilmet gnome org>
Date: Wed Jun 10 12:53:36 2015 +0200
notebook: cosmetic changes
- "notebook" is clearer than "nb".
- various other minor improvements
gedit/gedit-notebook.c | 225 +++++++++++++++++++++++++-----------------------
1 files changed, 118 insertions(+), 107 deletions(-)
---
diff --git a/gedit/gedit-notebook.c b/gedit/gedit-notebook.c
index 039f638..33f2104 100644
--- a/gedit/gedit-notebook.c
+++ b/gedit/gedit-notebook.c
@@ -24,7 +24,6 @@
* Copyright (C) 2002 Christophe Fergeau
* Copyright (C) 2003 Marco Pesenti Gritti
* Copyright (C) 2003, 2004 Christian Persch
- *
*/
#include "gedit-notebook.h"
@@ -65,14 +64,14 @@ gedit_notebook_finalize (GObject *object)
static void
gedit_notebook_grab_focus (GtkWidget *widget)
{
- GtkNotebook *nb = GTK_NOTEBOOK (widget);
- GtkWidget *tab;
+ GtkNotebook *notebook = GTK_NOTEBOOK (widget);
gint current_page;
+ GtkWidget *tab;
- current_page = gtk_notebook_get_current_page (nb);
- tab = gtk_notebook_get_nth_page (nb, current_page);
+ current_page = gtk_notebook_get_current_page (notebook);
+ tab = gtk_notebook_get_nth_page (notebook, current_page);
- if (tab)
+ if (tab != NULL)
{
gtk_widget_grab_focus (tab);
}
@@ -83,55 +82,60 @@ find_tab_num_at_pos (GtkNotebook *notebook,
gint screen_x,
gint screen_y)
{
- GtkNotebook *nb = GTK_NOTEBOOK (notebook);
GtkPositionType tab_pos;
- GtkWidget *page;
GtkAllocation tab_allocation;
- gint page_num = 0;
+ gint page_num;
- tab_pos = gtk_notebook_get_tab_pos (GTK_NOTEBOOK (notebook));
+ tab_pos = gtk_notebook_get_tab_pos (notebook);
- while ((page = gtk_notebook_get_nth_page (nb, page_num)))
+ for (page_num = 0; ; page_num++)
{
- GtkWidget *tab;
+ GtkWidget *page;
+ GtkWidget *tab_label;
gint max_x, max_y, x_root, y_root;
- tab = gtk_notebook_get_tab_label (nb, page);
- g_return_val_if_fail (tab != NULL, -1);
+ page = gtk_notebook_get_nth_page (notebook, page_num);
+
+ if (page == NULL)
+ {
+ break;
+ }
+
+ tab_label = gtk_notebook_get_tab_label (notebook, page);
+ g_return_val_if_fail (tab_label != NULL, -1);
- if (!gtk_widget_get_mapped (GTK_WIDGET (tab)))
+ if (!gtk_widget_get_mapped (tab_label))
{
- page_num++;
continue;
}
- gdk_window_get_origin (gtk_widget_get_window (tab), &x_root, &y_root);
+ gdk_window_get_origin (gtk_widget_get_window (tab_label), &x_root, &y_root);
- gtk_widget_get_allocation (tab, &tab_allocation);
+ gtk_widget_get_allocation (tab_label, &tab_allocation);
max_x = x_root + tab_allocation.x + tab_allocation.width;
max_y = y_root + tab_allocation.y + tab_allocation.height;
- if ((tab_pos == GTK_POS_TOP || tab_pos == GTK_POS_BOTTOM) && screen_x <= max_x)
+ if ((tab_pos == GTK_POS_TOP || tab_pos == GTK_POS_BOTTOM) &&
+ screen_x <= max_x)
{
return page_num;
}
- if ((tab_pos == GTK_POS_LEFT || tab_pos == GTK_POS_RIGHT) && screen_y <= max_y)
+ if ((tab_pos == GTK_POS_LEFT || tab_pos == GTK_POS_RIGHT) &&
+ screen_y <= max_y)
{
return page_num;
}
-
- page_num++;
}
return -1;
}
static gboolean
-gedit_notebook_button_press (GtkWidget *widget,
- GdkEventButton *event)
+gedit_notebook_button_press_event (GtkWidget *widget,
+ GdkEventButton *event)
{
- GtkNotebook *nb = GTK_NOTEBOOK (widget);
+ GtkNotebook *notebook = GTK_NOTEBOOK (widget);
if (event->type == GDK_BUTTON_PRESS &&
event->button == GDK_BUTTON_SECONDARY &&
@@ -139,16 +143,16 @@ gedit_notebook_button_press (GtkWidget *widget,
{
gint tab_clicked;
- tab_clicked = find_tab_num_at_pos (nb, event->x_root, event->y_root);
+ tab_clicked = find_tab_num_at_pos (notebook, event->x_root, event->y_root);
if (tab_clicked >= 0)
{
GtkWidget *tab;
- tab = gtk_notebook_get_nth_page (nb, tab_clicked);
+ tab = gtk_notebook_get_nth_page (notebook, tab_clicked);
g_signal_emit (G_OBJECT (widget), signals[SHOW_POPUP_MENU], 0, event, tab);
- return TRUE;
+ return GDK_EVENT_STOP;
}
}
@@ -163,14 +167,16 @@ static gboolean
gedit_notebook_change_current_page (GtkNotebook *notebook,
gint offset)
{
- gboolean wrap_around;
gint current;
current = gtk_notebook_get_current_page (notebook);
if (current != -1)
{
- current = current + offset;
+ gint target;
+ gboolean wrap_around;
+
+ target = current + offset;
g_object_get (gtk_widget_get_settings (GTK_WIDGET (notebook)),
"gtk-keynav-wrap-around", &wrap_around,
@@ -178,17 +184,17 @@ gedit_notebook_change_current_page (GtkNotebook *notebook,
if (wrap_around)
{
- if (current < 0)
+ if (target < 0)
{
- current = gtk_notebook_get_n_pages (notebook) - 1;
+ target = gtk_notebook_get_n_pages (notebook) - 1;
}
- else if (current >= gtk_notebook_get_n_pages (notebook))
+ else if (target >= gtk_notebook_get_n_pages (notebook))
{
- current = 0;
+ target = 0;
}
}
- gtk_notebook_set_current_page (notebook, current);
+ gtk_notebook_set_current_page (notebook, target);
}
else
{
@@ -203,26 +209,22 @@ gedit_notebook_switch_page (GtkNotebook *notebook,
GtkWidget *page,
guint page_num)
{
- GeditNotebook *nb = GEDIT_NOTEBOOK (notebook);
+ GeditNotebookPrivate *priv = GEDIT_NOTEBOOK (notebook)->priv;
- if (!nb->priv->ignore_focused_page_update)
+ if (!priv->ignore_focused_page_update)
{
- gint prev_page;
- GtkWidget *previous_page;
+ gint prev_page_num;
+ GtkWidget *prev_page;
- prev_page = gtk_notebook_get_current_page (notebook);
- previous_page = gtk_notebook_get_nth_page (notebook, prev_page);
+ prev_page_num = gtk_notebook_get_current_page (notebook);
+ prev_page = gtk_notebook_get_nth_page (notebook, prev_page_num);
/* Remove the old page, we dont want to grow unnecessarily
- * the list */
- if (nb->priv->focused_pages)
- {
- nb->priv->focused_pages =
- g_list_remove (nb->priv->focused_pages, previous_page);
- }
+ * the list.
+ */
+ priv->focused_pages = g_list_remove (priv->focused_pages, prev_page);
- nb->priv->focused_pages = g_list_append (nb->priv->focused_pages,
- previous_page);
+ priv->focused_pages = g_list_append (priv->focused_pages, prev_page);
}
GTK_NOTEBOOK_CLASS (gedit_notebook_parent_class)->switch_page (notebook, page, page_num);
@@ -239,7 +241,8 @@ on_tab_label_destroyed (GtkWidget *tab_label,
}
static void
-close_button_clicked_cb (GeditTabLabel *tab_label, GeditNotebook *notebook)
+close_button_clicked_cb (GeditTabLabel *tab_label,
+ GeditNotebook *notebook)
{
GeditTab *tab;
@@ -248,23 +251,23 @@ close_button_clicked_cb (GeditTabLabel *tab_label, GeditNotebook *notebook)
}
static void
-smart_tab_switching_on_closure (GeditNotebook *nb,
+smart_tab_switching_on_closure (GeditNotebook *notebook,
GeditTab *tab)
{
- if (nb->priv->focused_pages)
+ if (notebook->priv->focused_pages)
{
- GList *l;
+ GList *node;
GtkWidget *child;
gint page_num;
/* activate the last focused tab */
- l = g_list_last (nb->priv->focused_pages);
- child = GTK_WIDGET (l->data);
+ node = g_list_last (notebook->priv->focused_pages);
+ child = GTK_WIDGET (node->data);
- page_num = gtk_notebook_page_num (GTK_NOTEBOOK (nb),
+ page_num = gtk_notebook_page_num (GTK_NOTEBOOK (notebook),
child);
- gtk_notebook_set_current_page (GTK_NOTEBOOK (nb),
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook),
page_num);
}
}
@@ -284,9 +287,9 @@ gedit_notebook_page_removed (GtkNotebook *notebook,
GtkWidget *page,
guint page_num)
{
- GeditNotebook *nb = GEDIT_NOTEBOOK (notebook);
- gint curr;
+ GeditNotebookPrivate *priv = GEDIT_NOTEBOOK (notebook)->priv;
GtkWidget *tab_label;
+ gint current_page;
tab_label = get_tab_label (GEDIT_TAB (page));
@@ -295,20 +298,21 @@ gedit_notebook_page_removed (GtkNotebook *notebook,
g_signal_handlers_disconnect_by_func (tab_label,
G_CALLBACK (on_tab_label_destroyed),
page);
+
g_signal_handlers_disconnect_by_func (tab_label,
G_CALLBACK (close_button_clicked_cb),
- nb);
+ notebook);
}
/* Remove the page from the focused pages list */
- nb->priv->focused_pages = g_list_remove (nb->priv->focused_pages,
- page);
+ priv->focused_pages = g_list_remove (priv->focused_pages, page);
- curr = gtk_notebook_get_current_page (notebook);
+ current_page = gtk_notebook_get_current_page (notebook);
- if (page_num == curr)
+ if (page_num == current_page)
{
- smart_tab_switching_on_closure (nb, GEDIT_TAB (page));
+ smart_tab_switching_on_closure (GEDIT_NOTEBOOK (notebook),
+ GEDIT_TAB (page));
}
}
@@ -317,7 +321,6 @@ gedit_notebook_page_added (GtkNotebook *notebook,
GtkWidget *page,
guint page_num)
{
- GeditNotebook *nb = GEDIT_NOTEBOOK (notebook);
GtkWidget *tab_label;
tab_label = get_tab_label (GEDIT_TAB (page));
@@ -330,27 +333,29 @@ gedit_notebook_page_added (GtkNotebook *notebook,
g_signal_connect (tab_label,
"close-clicked",
G_CALLBACK (close_button_clicked_cb),
- nb);
+ notebook);
}
static void
gedit_notebook_remove (GtkContainer *container,
GtkWidget *widget)
{
- GeditNotebook *nb;
+ GeditNotebookPrivate *priv = GEDIT_NOTEBOOK (container)->priv;
/* This is where GtkNotebook will remove the page. By doing so, it
- will also switch to a new page, messing up our focus list. So we
- set a flag here to ignore the switch temporarily */
-
- nb = GEDIT_NOTEBOOK (container);
+ * will also switch to a new page, messing up our focus list. So we
+ * set a flag here to ignore the switch temporarily.
+ */
- nb->priv->ignore_focused_page_update = TRUE;
+ priv->ignore_focused_page_update = TRUE;
- GTK_CONTAINER_CLASS (gedit_notebook_parent_class)->remove (container,
- widget);
+ if (GTK_CONTAINER_CLASS (gedit_notebook_parent_class)->remove != NULL)
+ {
+ GTK_CONTAINER_CLASS (gedit_notebook_parent_class)->remove (container,
+ widget);
+ }
- nb->priv->ignore_focused_page_update = FALSE;
+ priv->ignore_focused_page_update = FALSE;
}
static gboolean
@@ -361,7 +366,7 @@ gedit_notebook_change_to_page (GeditNotebook *notebook,
n_pages = gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook));
- if (page_num > n_pages - 1)
+ if (page_num >= n_pages)
{
return FALSE;
}
@@ -376,24 +381,24 @@ static void
gedit_notebook_class_init (GeditNotebookClass *klass)
{
GObjectClass *object_class = G_OBJECT_CLASS (klass);
- GtkWidgetClass *gtkwidget_class = GTK_WIDGET_CLASS (klass);
- GtkNotebookClass *notebook_class = GTK_NOTEBOOK_CLASS (klass);
+ GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
GtkContainerClass *container_class = GTK_CONTAINER_CLASS (klass);
+ GtkNotebookClass *notebook_class = GTK_NOTEBOOK_CLASS (klass);
GtkBindingSet *binding_set;
gint i;
object_class->finalize = gedit_notebook_finalize;
- gtkwidget_class->grab_focus = gedit_notebook_grab_focus;
- gtkwidget_class->button_press_event = gedit_notebook_button_press;
+ widget_class->grab_focus = gedit_notebook_grab_focus;
+ widget_class->button_press_event = gedit_notebook_button_press_event;
+
+ container_class->remove = gedit_notebook_remove;
notebook_class->change_current_page = gedit_notebook_change_current_page;
notebook_class->switch_page = gedit_notebook_switch_page;
notebook_class->page_removed = gedit_notebook_page_removed;
notebook_class->page_added = gedit_notebook_page_added;
- container_class->remove = gedit_notebook_remove;
-
klass->change_to_page = gedit_notebook_change_to_page;
signals[TAB_CLOSE_REQUEST] =
@@ -418,6 +423,7 @@ gedit_notebook_class_init (GeditNotebookClass *klass)
2,
GDK_TYPE_EVENT | G_SIGNAL_TYPE_STATIC_SCOPE,
GEDIT_TYPE_TAB);
+
signals[CHANGE_TO_PAGE] =
g_signal_new ("change-to-page",
G_TYPE_FROM_CLASS (object_class),
@@ -465,8 +471,7 @@ gedit_notebook_init (GeditNotebook *notebook)
}
static GtkWidget *
-create_tab_label (GeditNotebook *nb,
- GeditTab *tab)
+create_tab_label (GeditTab *tab)
{
GtkWidget *tab_label;
@@ -479,48 +484,51 @@ create_tab_label (GeditNotebook *nb,
/**
* gedit_notebook_add_tab:
- * @nb: a #GeditNotebook
+ * @notebook: a #GeditNotebook
* @tab: a #GeditTab
* @position: the position where the @tab should be added
* @jump_to: %TRUE to set the @tab as active
*
- * Adds the specified @tab to the @nb.
+ * Adds the specified @tab to the @notebook.
*/
void
-gedit_notebook_add_tab (GeditNotebook *nb,
+gedit_notebook_add_tab (GeditNotebook *notebook,
GeditTab *tab,
gint position,
gboolean jump_to)
{
GtkWidget *tab_label;
- g_return_if_fail (GEDIT_IS_NOTEBOOK (nb));
+ g_return_if_fail (GEDIT_IS_NOTEBOOK (notebook));
g_return_if_fail (GEDIT_IS_TAB (tab));
- tab_label = create_tab_label (nb, tab);
+ tab_label = create_tab_label (tab);
- gtk_notebook_insert_page (GTK_NOTEBOOK (nb),
+ gtk_notebook_insert_page (GTK_NOTEBOOK (notebook),
GTK_WIDGET (tab),
tab_label,
position);
- gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (nb),
+
+ gtk_notebook_set_tab_reorderable (GTK_NOTEBOOK (notebook),
GTK_WIDGET (tab),
TRUE);
- gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (nb),
+
+ gtk_notebook_set_tab_detachable (GTK_NOTEBOOK (notebook),
GTK_WIDGET (tab),
TRUE);
- gtk_container_child_set (GTK_CONTAINER (nb),
+
+ gtk_container_child_set (GTK_CONTAINER (notebook),
GTK_WIDGET (tab),
"tab-expand", TRUE,
NULL);
/* The signal handler may have reordered the tabs */
- position = gtk_notebook_page_num (GTK_NOTEBOOK (nb),
+ position = gtk_notebook_page_num (GTK_NOTEBOOK (notebook),
GTK_WIDGET (tab));
if (jump_to)
{
- gtk_notebook_set_current_page (GTK_NOTEBOOK (nb), position);
+ gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), position);
gtk_widget_grab_focus (GTK_WIDGET (tab));
}
}
@@ -533,7 +541,7 @@ gedit_notebook_add_tab (GeditNotebook *nb,
* @dest_position: the position for @tab
*
* Moves @tab from @src to @dest.
- * If dest_position is greater than or equal to the number of tabs
+ * If @dest_position is greater than or equal to the number of tabs
* of the destination nootebook or negative, tab will be moved to the
* end of the tabs.
*/
@@ -557,26 +565,29 @@ gedit_notebook_move_tab (GeditNotebook *src,
/**
* gedit_notebook_remove_all_tabs:
- * @nb: a #GeditNotebook
+ * @notebook: a #GeditNotebook
*
- * Removes all #GeditTab from @nb.
+ * Removes all #GeditTab from @notebook.
*/
void
-gedit_notebook_remove_all_tabs (GeditNotebook *nb)
+gedit_notebook_remove_all_tabs (GeditNotebook *notebook)
{
- GList *tabs, *t;
+ GList *tabs;
+ GList *t;
- g_return_if_fail (GEDIT_IS_NOTEBOOK (nb));
+ g_return_if_fail (GEDIT_IS_NOTEBOOK (notebook));
- g_list_free (nb->priv->focused_pages);
- nb->priv->focused_pages = NULL;
+ g_list_free (notebook->priv->focused_pages);
+ notebook->priv->focused_pages = NULL;
/* Remove tabs in reverse order since it is faster
- * due to how gtknotebook works */
- tabs = gtk_container_get_children (GTK_CONTAINER (nb));
+ * due to how GtkNotebook works.
+ */
+ tabs = gtk_container_get_children (GTK_CONTAINER (notebook));
for (t = g_list_last (tabs); t != NULL; t = t->prev)
{
- gtk_container_remove (GTK_CONTAINER (nb), GTK_WIDGET (t->data));
+ GtkWidget *tab = t->data;
+ gtk_container_remove (GTK_CONTAINER (notebook), tab);
}
g_list_free (tabs);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]