xed-notebook.c: Clean up the code formatting

This commit is contained in:
JosephMcc 2016-12-31 16:33:21 -08:00
parent 33f6b71eda
commit d80329db5c
1 changed files with 542 additions and 596 deletions

View File

@ -109,8 +109,7 @@ xed_notebook_dispose (GObject *object)
for (l = children; l != NULL; l = g_list_next (l)) for (l = children; l != NULL; l = g_list_next (l))
{ {
xed_notebook_remove_tab (notebook, xed_notebook_remove_tab (notebook, XED_TAB (l->data));
XED_TAB (l->data));
} }
g_list_free (children); g_list_free (children);
@ -185,7 +184,8 @@ xed_notebook_class_init (XedNotebookClass *klass)
} }
static XedNotebook * static XedNotebook *
find_notebook_at_pointer (gint abs_x, gint abs_y) find_notebook_at_pointer (gint abs_x,
gint abs_y)
{ {
GdkWindow *win_at_pointer; GdkWindow *win_at_pointer;
GdkWindow *toplevel_win; GdkWindow *toplevel_win;
@ -206,11 +206,9 @@ find_notebook_at_pointer (gint abs_x, gint abs_y)
gdk_window_get_user_data (toplevel_win, &toplevel); gdk_window_get_user_data (toplevel_win, &toplevel);
/* toplevel should be an XedWindow */ /* toplevel should be an XedWindow */
if ((toplevel != NULL) && if ((toplevel != NULL) && XED_IS_WINDOW (toplevel))
XED_IS_WINDOW (toplevel))
{ {
return XED_NOTEBOOK (_xed_window_get_notebook return XED_NOTEBOOK (_xed_window_get_notebook (XED_WINDOW (toplevel)));
(XED_WINDOW (toplevel)));
} }
/* We are outside all windows containing a notebook */ /* We are outside all windows containing a notebook */
@ -267,8 +265,7 @@ find_tab_num_at_pos (XedNotebook *notebook,
continue; continue;
} }
gdk_window_get_origin (GDK_WINDOW (gtk_widget_get_window (tab)), gdk_window_get_origin (GDK_WINDOW (gtk_widget_get_window (tab)), &x_root, &y_root);
&x_root, &y_root);
gtk_widget_get_allocation(tab, &allocation); gtk_widget_get_allocation(tab, &allocation);
@ -375,21 +372,18 @@ xed_notebook_reorder_tab (XedNotebook *src,
g_return_if_fail (XED_IS_NOTEBOOK (src)); g_return_if_fail (XED_IS_NOTEBOOK (src));
g_return_if_fail (XED_IS_TAB (tab)); g_return_if_fail (XED_IS_TAB (tab));
old_position = gtk_notebook_page_num (GTK_NOTEBOOK (src), old_position = gtk_notebook_page_num (GTK_NOTEBOOK (src), GTK_WIDGET (tab));
GTK_WIDGET (tab));
if (old_position == dest_position) if (old_position == dest_position)
{
return; return;
}
gtk_notebook_reorder_child (GTK_NOTEBOOK (src), gtk_notebook_reorder_child (GTK_NOTEBOOK (src), GTK_WIDGET (tab), dest_position);
GTK_WIDGET (tab),
dest_position);
if (!src->priv->drag_in_progress) if (!src->priv->drag_in_progress)
{ {
g_signal_emit (G_OBJECT (src), g_signal_emit (G_OBJECT (src), signals[TABS_REORDERED], 0);
signals[TABS_REORDERED],
0);
} }
} }
@ -402,7 +396,9 @@ drag_start (XedNotebook *notebook,
/* get a new cursor, if necessary */ /* get a new cursor, if necessary */
/* FIXME multi-head */ /* FIXME multi-head */
if (cursor == NULL) if (cursor == NULL)
{
cursor = gdk_cursor_new (GDK_FLEUR); cursor = gdk_cursor_new (GDK_FLEUR);
}
/* grab the pointer */ /* grab the pointer */
gtk_grab_add (GTK_WIDGET (notebook)); gtk_grab_add (GTK_WIDGET (notebook));
@ -424,16 +420,13 @@ drag_stop (XedNotebook *notebook)
{ {
if (notebook->priv->drag_in_progress) if (notebook->priv->drag_in_progress)
{ {
g_signal_emit (G_OBJECT (notebook), g_signal_emit (G_OBJECT (notebook), signals[TABS_REORDERED], 0);
signals[TABS_REORDERED],
0);
} }
notebook->priv->drag_in_progress = FALSE; notebook->priv->drag_in_progress = FALSE;
if (notebook->priv->motion_notify_handler_id != 0) if (notebook->priv->motion_notify_handler_id != 0)
{ {
g_signal_handler_disconnect (G_OBJECT (notebook), g_signal_handler_disconnect (G_OBJECT (notebook), notebook->priv->motion_notify_handler_id);
notebook->priv->motion_notify_handler_id);
notebook->priv->motion_notify_handler_id = 0; notebook->priv->motion_notify_handler_id = 0;
} }
} }
@ -453,12 +446,8 @@ move_current_tab (XedNotebook *notebook,
{ {
GtkWidget *cur_tab; GtkWidget *cur_tab;
cur_tab = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), cur_tab = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), cur_page_num);
cur_page_num); xed_notebook_reorder_tab (XED_NOTEBOOK (notebook), XED_TAB (cur_tab), dest_position);
xed_notebook_reorder_tab (XED_NOTEBOOK (notebook),
XED_TAB (cur_tab),
dest_position);
} }
} }
@ -474,7 +463,9 @@ motion_notify_cb (XedNotebook *notebook,
if (notebook->priv->drag_in_progress == FALSE) if (notebook->priv->drag_in_progress == FALSE)
{ {
if (notebook->priv->tab_drag_and_drop_enabled == FALSE) if (notebook->priv->tab_drag_and_drop_enabled == FALSE)
{
return FALSE; return FALSE;
}
if (gtk_drag_check_threshold (GTK_WIDGET (notebook), if (gtk_drag_check_threshold (GTK_WIDGET (notebook),
notebook->priv->x_start, notebook->priv->x_start,
@ -489,19 +480,13 @@ motion_notify_cb (XedNotebook *notebook,
return FALSE; return FALSE;
} }
result = find_notebook_and_tab_at_pos ((gint)event->x_root, result = find_notebook_and_tab_at_pos ((gint)event->x_root, (gint)event->y_root, &dest, &page_num);
(gint)event->y_root,
&dest,
&page_num);
if (result != NOT_IN_APP_WINDOWS) if (result != NOT_IN_APP_WINDOWS)
{ {
if (dest != notebook) if (dest != notebook)
{ {
move_current_tab_to_another_notebook (notebook, move_current_tab_to_another_notebook (notebook, dest, event, page_num);
dest,
event,
page_num);
} }
else else
{ {
@ -531,8 +516,7 @@ move_current_tab_to_another_notebook (XedNotebook *src,
g_return_if_fail (dest != src); g_return_if_fail (dest != src);
cur_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (src)); cur_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (src));
tab = XED_TAB (gtk_notebook_get_nth_page (GTK_NOTEBOOK (src), tab = XED_TAB (gtk_notebook_get_nth_page (GTK_NOTEBOOK (src), cur_page));
cur_page));
/* stop drag in origin window */ /* stop drag in origin window */
/* ungrab the pointer if it's grabbed */ /* ungrab the pointer if it's grabbed */
@ -546,11 +530,8 @@ move_current_tab_to_another_notebook (XedNotebook *src,
xed_notebook_move_tab (src, dest, tab, dest_position); xed_notebook_move_tab (src, dest, tab, dest_position);
/* start drag handling in dest notebook */ /* start drag handling in dest notebook */
dest->priv->motion_notify_handler_id = dest->priv->motion_notify_handler_id = g_signal_connect (G_OBJECT (dest), "motion-notify-event",
g_signal_connect (G_OBJECT (dest), G_CALLBACK (motion_notify_cb), NULL);
"motion-notify-event",
G_CALLBACK (motion_notify_cb),
NULL);
drag_start (dest, event->time); drag_start (dest, event->time);
} }
@ -566,18 +547,14 @@ button_release_cb (XedNotebook *notebook,
GtkWidget *cur_page; GtkWidget *cur_page;
cur_page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook)); cur_page_num = gtk_notebook_get_current_page (GTK_NOTEBOOK (notebook));
cur_page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), cur_page = gtk_notebook_get_nth_page (GTK_NOTEBOOK (notebook), cur_page_num);
cur_page_num);
/* CHECK: I don't follow the code here -- Paolo */ /* CHECK: I don't follow the code here -- Paolo */
if (!is_in_notebook_window (notebook, event->x_root, event->y_root) && if (!is_in_notebook_window (notebook, event->x_root, event->y_root) &&
(gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)) > 1)) (gtk_notebook_get_n_pages (GTK_NOTEBOOK (notebook)) > 1))
{ {
/* Tab was detached */ /* Tab was detached */
g_signal_emit (G_OBJECT (notebook), g_signal_emit (G_OBJECT (notebook), signals[TAB_DETACHED], 0, cur_page);
signals[TAB_DETACHED],
0,
cur_page);
} }
/* ungrab the pointer if it's grabbed */ /* ungrab the pointer if it's grabbed */
@ -602,27 +579,21 @@ button_press_cb (XedNotebook *notebook,
gint tab_clicked; gint tab_clicked;
if (notebook->priv->drag_in_progress) if (notebook->priv->drag_in_progress)
{
return TRUE; return TRUE;
}
tab_clicked = find_tab_num_at_pos (notebook, tab_clicked = find_tab_num_at_pos (notebook, event->x_root, event->y_root);
event->x_root,
event->y_root);
if ((event->button == 1) && if ((event->button == 1) && (event->type == GDK_BUTTON_PRESS) && (tab_clicked >= 0))
(event->type == GDK_BUTTON_PRESS) &&
(tab_clicked >= 0))
{ {
notebook->priv->x_start = event->x_root; notebook->priv->x_start = event->x_root;
notebook->priv->y_start = event->y_root; notebook->priv->y_start = event->y_root;
notebook->priv->motion_notify_handler_id = notebook->priv->motion_notify_handler_id = g_signal_connect (G_OBJECT (notebook), "motion-notify-event",
g_signal_connect (G_OBJECT (notebook), G_CALLBACK (motion_notify_cb), NULL);
"motion-notify-event",
G_CALLBACK (motion_notify_cb),
NULL);
} }
else if ((event->type == GDK_BUTTON_PRESS) && else if ((event->type == GDK_BUTTON_PRESS) && (event->button == 3 || event->button == 2))
(event->button == 3 || event->button == 2))
{ {
if (tab_clicked == -1) if (tab_clicked == -1)
{ {
@ -636,8 +607,7 @@ button_press_cb (XedNotebook *notebook,
else else
{ {
/* Switch to the page the mouse is over, but don't consume the event */ /* Switch to the page the mouse is over, but don't consume the event */
gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), gtk_notebook_set_current_page (GTK_NOTEBOOK (notebook), tab_clicked);
tab_clicked);
} }
} }
@ -709,12 +679,10 @@ xed_notebook_switch_page_cb (GtkNotebook *notebook,
* the list */ * the list */
if (nb->priv->focused_pages) if (nb->priv->focused_pages)
{ {
nb->priv->focused_pages = nb->priv->focused_pages = g_list_remove (nb->priv->focused_pages, child);
g_list_remove (nb->priv->focused_pages, child);
} }
nb->priv->focused_pages = g_list_append (nb->priv->focused_pages, nb->priv->focused_pages = g_list_append (nb->priv->focused_pages, child);
child);
/* give focus to the view */ /* give focus to the view */
view = xed_tab_get_view (XED_TAB (child)); view = xed_tab_get_view (XED_TAB (child));
@ -756,21 +724,14 @@ xed_notebook_init (XedNotebook *notebook)
notebook->priv->always_show_tabs = TRUE; notebook->priv->always_show_tabs = TRUE;
g_signal_connect (notebook, g_signal_connect (notebook, "button-press-event",
"button-press-event", (GCallback)button_press_cb, NULL);
(GCallback)button_press_cb, g_signal_connect (notebook, "button-release-event",
NULL); (GCallback)button_release_cb, NULL);
g_signal_connect (notebook, gtk_widget_add_events (GTK_WIDGET (notebook), GDK_BUTTON1_MOTION_MASK);
"button-release-event",
(GCallback)button_release_cb,
NULL);
gtk_widget_add_events (GTK_WIDGET (notebook),
GDK_BUTTON1_MOTION_MASK);
g_signal_connect_after (G_OBJECT (notebook), g_signal_connect_after (G_OBJECT (notebook), "switch_page",
"switch_page", G_CALLBACK (xed_notebook_switch_page_cb), NULL);
G_CALLBACK (xed_notebook_switch_page_cb),
NULL);
gtk_widget_add_events (GTK_WIDGET (notebook), GDK_SCROLL_MASK); gtk_widget_add_events (GTK_WIDGET (notebook), GDK_SCROLL_MASK);
g_signal_connect (notebook, "scroll-event", g_signal_connect (notebook, "scroll-event",
@ -805,8 +766,7 @@ xed_notebook_change_current_page (GtkNotebook *notebook,
current = current + offset; current = current + offset;
g_object_get (gtk_widget_get_settings (GTK_WIDGET (notebook)), g_object_get (gtk_widget_get_settings (GTK_WIDGET (notebook)),
"gtk-keynav-wrap-around", &wrap_around, "gtk-keynav-wrap-around", &wrap_around, NULL);
NULL);
if (wrap_around) if (wrap_around)
{ {
@ -831,7 +791,8 @@ xed_notebook_change_current_page (GtkNotebook *notebook,
} }
static void static void
close_button_clicked_cb (XedTabLabel *tab_label, XedNotebook *notebook) close_button_clicked_cb (XedTabLabel *tab_label,
XedNotebook *notebook)
{ {
XedTab *tab; XedTab *tab;
@ -847,10 +808,8 @@ create_tab_label (XedNotebook *nb,
tab_label = xed_tab_label_new (tab); tab_label = xed_tab_label_new (tab);
g_signal_connect (tab_label, g_signal_connect (tab_label, "close-clicked",
"close-clicked", G_CALLBACK (close_button_clicked_cb), nb);
G_CALLBACK (close_button_clicked_cb),
nb);
g_object_set_data (G_OBJECT (tab), "tab-label", tab_label); g_object_set_data (G_OBJECT (tab), "tab-label", tab_label);
@ -876,9 +835,7 @@ remove_tab_label (XedNotebook *nb,
tab_label = get_tab_label (tab); tab_label = get_tab_label (tab);
g_signal_handlers_disconnect_by_func (tab_label, g_signal_handlers_disconnect_by_func (tab_label, G_CALLBACK (close_button_clicked_cb), nb);
G_CALLBACK (close_button_clicked_cb),
nb);
g_object_set_data (G_OBJECT (tab), "tab-label", NULL); g_object_set_data (G_OBJECT (tab), "tab-label", NULL);
} }
@ -922,26 +879,20 @@ xed_notebook_add_tab (XedNotebook *nb,
g_return_if_fail (XED_IS_TAB (tab)); g_return_if_fail (XED_IS_TAB (tab));
tab_label = create_tab_label (nb, tab); tab_label = create_tab_label (nb, tab);
gtk_notebook_insert_page (GTK_NOTEBOOK (nb), gtk_notebook_insert_page (GTK_NOTEBOOK (nb), GTK_WIDGET (tab), tab_label, position);
GTK_WIDGET (tab),
tab_label,
position);
update_tabs_visibility (nb, TRUE); update_tabs_visibility (nb, TRUE);
g_signal_emit (G_OBJECT (nb), signals[TAB_ADDED], 0, tab); g_signal_emit (G_OBJECT (nb), signals[TAB_ADDED], 0, tab);
/* The signal handler may have reordered the tabs */ /* The signal handler may have reordered the tabs */
position = gtk_notebook_page_num (GTK_NOTEBOOK (nb), position = gtk_notebook_page_num (GTK_NOTEBOOK (nb), GTK_WIDGET (tab));
GTK_WIDGET (tab));
if (jump_to) if (jump_to)
{ {
XedView *view; XedView *view;
gtk_notebook_set_current_page (GTK_NOTEBOOK (nb), position); gtk_notebook_set_current_page (GTK_NOTEBOOK (nb), position);
g_object_set_data (G_OBJECT (tab), g_object_set_data (G_OBJECT (tab), "jump_to", GINT_TO_POINTER (jump_to));
"jump_to",
GINT_TO_POINTER (jump_to));
view = xed_tab_get_view (tab); view = xed_tab_get_view (tab);
gtk_widget_grab_focus (GTK_WIDGET (view)); gtk_widget_grab_focus (GTK_WIDGET (view));
@ -954,8 +905,7 @@ smart_tab_switching_on_closure (XedNotebook *nb,
{ {
gboolean jump_to; gboolean jump_to;
jump_to = GPOINTER_TO_INT (g_object_get_data jump_to = GPOINTER_TO_INT (g_object_get_data (G_OBJECT (tab), "jump_to"));
(G_OBJECT (tab), "jump_to"));
if (!jump_to || !nb->priv->focused_pages) if (!jump_to || !nb->priv->focused_pages)
{ {
@ -970,10 +920,8 @@ smart_tab_switching_on_closure (XedNotebook *nb,
/* activate the last focused tab */ /* activate the last focused tab */
l = g_list_last (nb->priv->focused_pages); l = g_list_last (nb->priv->focused_pages);
child = GTK_WIDGET (l->data); child = GTK_WIDGET (l->data);
page_num = gtk_notebook_page_num (GTK_NOTEBOOK (nb), page_num = gtk_notebook_page_num (GTK_NOTEBOOK (nb), child);
child); gtk_notebook_set_current_page (GTK_NOTEBOOK (nb), page_num);
gtk_notebook_set_current_page (GTK_NOTEBOOK (nb),
page_num);
} }
} }
@ -1016,8 +964,7 @@ xed_notebook_remove_tab (XedNotebook *nb,
g_return_if_fail (XED_IS_TAB (tab)); g_return_if_fail (XED_IS_TAB (tab));
/* Remove the page from the focused pages list */ /* Remove the page from the focused pages list */
nb->priv->focused_pages = g_list_remove (nb->priv->focused_pages, nb->priv->focused_pages = g_list_remove (nb->priv->focused_pages, tab);
tab);
position = gtk_notebook_page_num (GTK_NOTEBOOK (nb), GTK_WIDGET (tab)); position = gtk_notebook_page_num (GTK_NOTEBOOK (nb), GTK_WIDGET (tab));
curr = gtk_notebook_get_current_page (GTK_NOTEBOOK (nb)); curr = gtk_notebook_get_current_page (GTK_NOTEBOOK (nb));
@ -1044,9 +991,7 @@ xed_notebook_remove_all_tabs (XedNotebook *nb)
g_list_free (nb->priv->focused_pages); g_list_free (nb->priv->focused_pages);
nb->priv->focused_pages = NULL; nb->priv->focused_pages = NULL;
gtk_container_foreach (GTK_CONTAINER (nb), gtk_container_foreach (GTK_CONTAINER (nb), (GtkCallback)remove_tab, nb);
(GtkCallback)remove_tab,
nb);
} }
static void static void
@ -1057,8 +1002,7 @@ set_close_buttons_sensitivity (XedTab *tab,
tab_label = get_tab_label (tab); tab_label = get_tab_label (tab);
xed_tab_label_set_close_button_sensitive (XED_TAB_LABEL (tab_label), xed_tab_label_set_close_button_sensitive (XED_TAB_LABEL (tab_label), nb->priv->close_buttons_sensitive);
nb->priv->close_buttons_sensitive);
} }
/** /**
@ -1077,13 +1021,13 @@ xed_notebook_set_close_buttons_sensitive (XedNotebook *nb,
sensitive = (sensitive != FALSE); sensitive = (sensitive != FALSE);
if (sensitive == nb->priv->close_buttons_sensitive) if (sensitive == nb->priv->close_buttons_sensitive)
{
return; return;
}
nb->priv->close_buttons_sensitive = sensitive; nb->priv->close_buttons_sensitive = sensitive;
gtk_container_foreach (GTK_CONTAINER (nb), gtk_container_foreach (GTK_CONTAINER (nb), (GtkCallback)set_close_buttons_sensitivity, nb);
(GtkCallback)set_close_buttons_sensitivity,
nb);
} }
/** /**
@ -1118,7 +1062,9 @@ xed_notebook_set_tab_drag_and_drop_enabled (XedNotebook *nb,
enable = (enable != FALSE); enable = (enable != FALSE);
if (enable == nb->priv->tab_drag_and_drop_enabled) if (enable == nb->priv->tab_drag_and_drop_enabled)
{
return; return;
}
nb->priv->tab_drag_and_drop_enabled = enable; nb->priv->tab_drag_and_drop_enabled = enable;
} }