xed-panel: Clean up code formatting

This commit is contained in:
JosephMcc 2016-12-12 14:59:49 -08:00
parent d091965175
commit 6893642b16
1 changed files with 492 additions and 558 deletions

View File

@ -64,13 +64,15 @@ struct _XedPanelItem
};
/* Properties */
enum {
enum
{
PROP_0,
PROP_ORIENTATION
};
/* Signals */
enum {
enum
{
ITEM_ADDED,
ITEM_REMOVED,
CLOSE,
@ -85,13 +87,15 @@ static GObject *xed_panel_constructor (GType type,
GObjectConstructParam *construct_properties);
G_DEFINE_TYPE(XedPanel, xed_panel, GTK_TYPE_BOX)
G_DEFINE_TYPE (XedPanel, xed_panel, GTK_TYPE_BOX)
static void
xed_panel_finalize (GObject *obj)
{
if (G_OBJECT_CLASS (xed_panel_parent_class)->finalize)
{
(*G_OBJECT_CLASS (xed_panel_parent_class)->finalize) (obj);
}
}
static void
@ -148,8 +152,10 @@ xed_panel_focus_document (XedPanel *panel)
view = xed_window_get_active_view (XED_WINDOW (toplevel));
if (view != NULL)
{
gtk_widget_grab_focus (GTK_WIDGET (view));
}
}
}
static void
@ -161,10 +167,11 @@ xed_panel_grab_focus (GtkWidget *w)
n = gtk_notebook_get_current_page (GTK_NOTEBOOK (panel->priv->notebook));
if (n == -1)
{
return;
}
tab = gtk_notebook_get_nth_page (GTK_NOTEBOOK (panel->priv->notebook),
n);
tab = gtk_notebook_get_nth_page (GTK_NOTEBOOK (panel->priv->notebook), n);
g_return_if_fail (tab != NULL);
gtk_widget_grab_focus (tab);
@ -311,9 +318,7 @@ set_gtk_image_from_gtk_image (GtkImage *image,
}
break;
default:
gtk_image_set_from_stock (image,
GTK_STOCK_FILE,
GTK_ICON_SIZE_MENU);
gtk_image_set_from_stock (image, GTK_STOCK_FILE, GTK_ICON_SIZE_MENU);
}
}
@ -322,24 +327,20 @@ sync_title (XedPanel *panel,
XedPanelItem *item)
{
if (panel->priv->orientation != GTK_ORIENTATION_VERTICAL)
{
return;
}
if (item != NULL)
{
gtk_label_set_text (GTK_LABEL (panel->priv->title_label),
item->name);
gtk_label_set_text (GTK_LABEL (panel->priv->title_label), item->name);
set_gtk_image_from_gtk_image (GTK_IMAGE (panel->priv->title_image),
GTK_IMAGE (item->icon));
set_gtk_image_from_gtk_image (GTK_IMAGE (panel->priv->title_image), GTK_IMAGE (item->icon));
}
else
{
gtk_label_set_text (GTK_LABEL (panel->priv->title_label),
_("Empty"));
gtk_image_set_from_stock (GTK_IMAGE (panel->priv->title_image),
GTK_STOCK_FILE,
GTK_ICON_SIZE_MENU);
gtk_label_set_text (GTK_LABEL (panel->priv->title_label), _("Empty"));
gtk_image_set_from_stock (GTK_IMAGE (panel->priv->title_image), GTK_STOCK_FILE, GTK_ICON_SIZE_MENU);
}
}
@ -355,8 +356,7 @@ notebook_page_changed (GtkNotebook *notebook,
item = gtk_notebook_get_nth_page (notebook, page_num);
g_return_if_fail (item != NULL);
data = (XedPanelItem *)g_object_get_data (G_OBJECT (item),
PANEL_ITEM_KEY);
data = (XedPanelItem *)g_object_get_data (G_OBJECT (item), PANEL_ITEM_KEY);
g_return_if_fail (data != NULL);
sync_title (panel, data);
@ -374,7 +374,9 @@ panel_show (XedPanel *panel,
page = gtk_notebook_get_current_page (nb);
if (page != -1)
{
notebook_page_changed (nb, NULL, page, panel);
}
}
static void
@ -382,8 +384,7 @@ xed_panel_init (XedPanel *panel)
{
panel->priv = XED_PANEL_GET_PRIVATE (panel);
gtk_orientable_set_orientation (GTK_ORIENTABLE (panel),
GTK_ORIENTATION_VERTICAL);
gtk_orientable_set_orientation (GTK_ORIENTABLE (panel), GTK_ORIENTATION_VERTICAL);
}
static void
@ -399,13 +400,8 @@ create_close_button (XedPanel *panel)
GtkWidget *button;
button = xed_close_button_new ();
gtk_widget_set_tooltip_text (button, _("Hide panel"));
g_signal_connect (button,
"clicked",
G_CALLBACK (close_button_clicked_cb),
panel);
g_signal_connect (button, "clicked", G_CALLBACK (close_button_clicked_cb), panel);
return button;
}
@ -416,18 +412,13 @@ build_notebook_for_panel (XedPanel *panel)
/* Create the panel notebook */
panel->priv->notebook = gtk_notebook_new ();
gtk_notebook_set_tab_pos (GTK_NOTEBOOK (panel->priv->notebook),
GTK_POS_BOTTOM);
gtk_notebook_set_scrollable (GTK_NOTEBOOK (panel->priv->notebook),
TRUE);
gtk_notebook_set_tab_pos (GTK_NOTEBOOK (panel->priv->notebook), GTK_POS_BOTTOM);
gtk_notebook_set_scrollable (GTK_NOTEBOOK (panel->priv->notebook), TRUE);
gtk_notebook_popup_enable (GTK_NOTEBOOK (panel->priv->notebook));
gtk_widget_show (GTK_WIDGET (panel->priv->notebook));
g_signal_connect (panel->priv->notebook,
"switch-page",
G_CALLBACK (notebook_page_changed),
panel);
g_signal_connect (panel->priv->notebook, "switch-page", G_CALLBACK (notebook_page_changed), panel);
}
static void
@ -438,38 +429,19 @@ build_horizontal_panel (XedPanel *panel)
GtkWidget *close_button;
box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_pack_start (GTK_BOX (box),
panel->priv->notebook,
TRUE,
TRUE,
0);
gtk_box_pack_start (GTK_BOX (box), panel->priv->notebook, TRUE, TRUE, 0);
/* Toolbar, close button and first separator */
sidebar = gtk_box_new(GTK_ORIENTATION_VERTICAL, 6);
gtk_container_set_border_width (GTK_CONTAINER (sidebar), 4);
gtk_box_pack_start (GTK_BOX (box),
sidebar,
FALSE,
FALSE,
0);
gtk_box_pack_start (GTK_BOX (box), sidebar, FALSE, FALSE, 0);
close_button = create_close_button (panel);
gtk_box_pack_start (GTK_BOX (sidebar),
close_button,
FALSE,
FALSE,
0);
gtk_box_pack_start (GTK_BOX (sidebar), close_button, FALSE, FALSE, 0);
gtk_widget_show_all (box);
gtk_box_pack_start (GTK_BOX (panel),
box,
TRUE,
TRUE,
0);
gtk_box_pack_start (GTK_BOX (panel), box, TRUE, TRUE, 0);
}
static void
@ -487,55 +459,25 @@ build_vertical_panel (XedPanel *panel)
gtk_box_pack_start (GTK_BOX (panel), title_hbox, FALSE, FALSE, 0);
icon_name_hbox = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 0);
gtk_box_pack_start (GTK_BOX (title_hbox),
icon_name_hbox,
TRUE,
TRUE,
0);
gtk_box_pack_start (GTK_BOX (title_hbox), icon_name_hbox, TRUE, TRUE, 0);
panel->priv->title_image =
gtk_image_new_from_stock (GTK_STOCK_FILE,
GTK_ICON_SIZE_MENU);
gtk_box_pack_start (GTK_BOX (icon_name_hbox),
panel->priv->title_image,
FALSE,
TRUE,
0);
panel->priv->title_image = gtk_image_new_from_stock (GTK_STOCK_FILE, GTK_ICON_SIZE_MENU);
gtk_box_pack_start (GTK_BOX (icon_name_hbox), panel->priv->title_image, FALSE, TRUE, 0);
dummy_label = gtk_label_new (" ");
gtk_box_pack_start (GTK_BOX (icon_name_hbox),
dummy_label,
FALSE,
FALSE,
0);
gtk_box_pack_start (GTK_BOX (icon_name_hbox), dummy_label, FALSE, FALSE, 0);
panel->priv->title_label = gtk_label_new (_("Empty"));
gtk_misc_set_alignment (GTK_MISC (panel->priv->title_label), 0, 0.5);
gtk_label_set_ellipsize(GTK_LABEL (panel->priv->title_label), PANGO_ELLIPSIZE_END);
gtk_box_pack_start (GTK_BOX (icon_name_hbox),
panel->priv->title_label,
TRUE,
TRUE,
0);
gtk_box_pack_start (GTK_BOX (icon_name_hbox), panel->priv->title_label, TRUE, TRUE, 0);
close_button = create_close_button (panel);
gtk_box_pack_start (GTK_BOX (title_hbox),
close_button,
FALSE,
FALSE,
0);
gtk_box_pack_start (GTK_BOX (title_hbox), close_button, FALSE, FALSE, 0);
gtk_widget_show_all (title_hbox);
gtk_box_pack_start (GTK_BOX (panel),
panel->priv->notebook,
TRUE,
TRUE,
0);
gtk_box_pack_start (GTK_BOX (panel), panel->priv->notebook, TRUE, TRUE, 0);
}
static GObject *
@ -547,24 +489,22 @@ xed_panel_constructor (GType type,
/* Invoke parent constructor. */
XedPanelClass *klass = XED_PANEL_CLASS (g_type_class_peek (XED_TYPE_PANEL));
GObjectClass *parent_class = G_OBJECT_CLASS (g_type_class_peek_parent (klass));
GObject *obj = parent_class->constructor (type,
n_construct_properties,
construct_properties);
GObject *obj = parent_class->constructor (type, n_construct_properties, construct_properties);
/* Build the panel, now that we know the orientation
(_init has been called previously) */
/* Build the panel, now that we know the orientation (_init has been called previously) */
XedPanel *panel = XED_PANEL (obj);
build_notebook_for_panel (panel);
if (panel->priv->orientation == GTK_ORIENTATION_HORIZONTAL)
{
build_horizontal_panel (panel);
}
else
{
build_vertical_panel (panel);
}
g_signal_connect (panel,
"show",
G_CALLBACK (panel_show),
NULL);
g_signal_connect (panel, "show", G_CALLBACK (panel_show), NULL);
return obj;
}
@ -591,7 +531,9 @@ build_tab_label (XedPanel *panel,
const gchar *name,
GtkWidget *icon)
{
GtkWidget *hbox, *label_hbox, *label_ebox;
GtkWidget *hbox;
GtkWidget *label_hbox;
GtkWidget *label_ebox;
GtkWidget *label;
/* set hbox spacing and label padding (see below) so that there's an
@ -624,7 +566,9 @@ build_tab_label (XedPanel *panel,
gtk_widget_show_all (hbox);
if (panel->priv->orientation == GTK_ORIENTATION_VERTICAL)
{
gtk_widget_hide(label);
}
g_object_set_data (G_OBJECT (item), "label", label);
g_object_set_data (G_OBJECT (item), "hbox", hbox);
@ -664,8 +608,7 @@ xed_panel_add_item (XedPanel *panel,
if (image == NULL)
{
/* default to empty */
data->icon = gtk_image_new_from_stock (GTK_STOCK_FILE,
GTK_ICON_SIZE_MENU);
data->icon = gtk_image_new_from_stock (GTK_STOCK_FILE, GTK_ICON_SIZE_MENU);
}
else
{
@ -675,9 +618,7 @@ xed_panel_add_item (XedPanel *panel,
gtk_icon_size_lookup (GTK_ICON_SIZE_MENU, &w, &h);
gtk_widget_set_size_request (data->icon, w, h);
g_object_set_data (G_OBJECT (item),
PANEL_ITEM_KEY,
data);
g_object_set_data (G_OBJECT (item), PANEL_ITEM_KEY, data);
tab_label = build_tab_label (panel, item, data->name, data->icon);
@ -686,12 +627,11 @@ xed_panel_add_item (XedPanel *panel,
gtk_misc_set_alignment (GTK_MISC (menu_label), 0.0, 0.5);
if (!gtk_widget_get_visible (item))
{
gtk_widget_show (item);
}
gtk_notebook_append_page_menu (GTK_NOTEBOOK (panel->priv->notebook),
item,
tab_label,
menu_label);
gtk_notebook_append_page_menu (GTK_NOTEBOOK (panel->priv->notebook), item, tab_label, menu_label);
g_signal_emit (G_OBJECT (panel), signals[ITEM_ADDED], 0, item);
}
@ -715,8 +655,7 @@ xed_panel_add_item_with_stock_icon (XedPanel *panel,
if (stock_id != NULL)
{
icon = gtk_image_new_from_stock (stock_id,
GTK_ICON_SIZE_MENU);
icon = gtk_image_new_from_stock (stock_id, GTK_ICON_SIZE_MENU);
}
xed_panel_add_item (panel, item, name, icon);
@ -742,32 +681,31 @@ xed_panel_remove_item (XedPanel *panel,
g_return_val_if_fail (XED_IS_PANEL (panel), FALSE);
g_return_val_if_fail (GTK_IS_WIDGET (item), FALSE);
page_num = gtk_notebook_page_num (GTK_NOTEBOOK (panel->priv->notebook),
item);
page_num = gtk_notebook_page_num (GTK_NOTEBOOK (panel->priv->notebook), item);
if (page_num == -1)
{
return FALSE;
}
data = (XedPanelItem *)g_object_get_data (G_OBJECT (item),
PANEL_ITEM_KEY);
data = (XedPanelItem *)g_object_get_data (G_OBJECT (item), PANEL_ITEM_KEY);
g_return_val_if_fail (data != NULL, FALSE);
g_free (data->name);
g_free (data);
g_object_set_data (G_OBJECT (item),
PANEL_ITEM_KEY,
NULL);
g_object_set_data (G_OBJECT (item), PANEL_ITEM_KEY, NULL);
/* ref the item to keep it alive during signal emission */
g_object_ref (G_OBJECT (item));
gtk_notebook_remove_page (GTK_NOTEBOOK (panel->priv->notebook),
page_num);
gtk_notebook_remove_page (GTK_NOTEBOOK (panel->priv->notebook), page_num);
/* if we removed all the pages, reset the title */
if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (panel->priv->notebook)) == 0)
{
sync_title (panel, NULL);
}
g_signal_emit (G_OBJECT (panel), signals[ITEM_REMOVED], 0, item);
@ -794,14 +732,14 @@ xed_panel_activate_item (XedPanel *panel,
g_return_val_if_fail (XED_IS_PANEL (panel), FALSE);
g_return_val_if_fail (GTK_IS_WIDGET (item), FALSE);
page_num = gtk_notebook_page_num (GTK_NOTEBOOK (panel->priv->notebook),
item);
page_num = gtk_notebook_page_num (GTK_NOTEBOOK (panel->priv->notebook), item);
if (page_num == -1)
{
return FALSE;
}
gtk_notebook_set_current_page (GTK_NOTEBOOK (panel->priv->notebook),
page_num);
gtk_notebook_set_current_page (GTK_NOTEBOOK (panel->priv->notebook), page_num);
return TRUE;
}
@ -825,14 +763,14 @@ xed_panel_item_is_active (XedPanel *panel,
g_return_val_if_fail (XED_IS_PANEL (panel), FALSE);
g_return_val_if_fail (GTK_IS_WIDGET (item), FALSE);
page_num = gtk_notebook_page_num (GTK_NOTEBOOK (panel->priv->notebook),
item);
page_num = gtk_notebook_page_num (GTK_NOTEBOOK (panel->priv->notebook), item);
if (page_num == -1)
{
return FALSE;
}
cur_page = gtk_notebook_get_current_page (
GTK_NOTEBOOK (panel->priv->notebook));
cur_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (panel->priv->notebook));
return (page_num == cur_page);
}
@ -878,14 +816,13 @@ _xed_panel_get_active_item_id (XedPanel *panel)
g_return_val_if_fail (XED_IS_PANEL (panel), 0);
cur_page = gtk_notebook_get_current_page (
GTK_NOTEBOOK (panel->priv->notebook));
cur_page = gtk_notebook_get_current_page (GTK_NOTEBOOK (panel->priv->notebook));
if (cur_page == -1)
{
return 0;
}
item = gtk_notebook_get_nth_page (
GTK_NOTEBOOK (panel->priv->notebook),
cur_page);
item = gtk_notebook_get_nth_page (GTK_NOTEBOOK (panel->priv->notebook), cur_page);
/* FIXME: for now we use as the hash of the name as id.
* However the name is not guaranteed to be unique and
@ -894,8 +831,7 @@ _xed_panel_get_active_item_id (XedPanel *panel)
* ad hoc id argument.
*/
data = (XedPanelItem *)g_object_get_data (G_OBJECT (item),
PANEL_ITEM_KEY);
data = (XedPanelItem *)g_object_get_data (G_OBJECT (item), PANEL_ITEM_KEY);
g_return_val_if_fail (data != NULL, 0);
return g_str_hash (data->name);
@ -910,27 +846,25 @@ _xed_panel_set_active_item_by_id (XedPanel *panel,
g_return_if_fail (XED_IS_PANEL (panel));
if (id == 0)
{
return;
}
n = gtk_notebook_get_n_pages (
GTK_NOTEBOOK (panel->priv->notebook));
n = gtk_notebook_get_n_pages (GTK_NOTEBOOK (panel->priv->notebook));
for (i = 0; i < n; i++)
{
GtkWidget *item;
XedPanelItem *data;
item = gtk_notebook_get_nth_page (
GTK_NOTEBOOK (panel->priv->notebook), i);
item = gtk_notebook_get_nth_page (GTK_NOTEBOOK (panel->priv->notebook), i);
data = (XedPanelItem *)g_object_get_data (G_OBJECT (item),
PANEL_ITEM_KEY);
data = (XedPanelItem *)g_object_get_data (G_OBJECT (item), PANEL_ITEM_KEY);
g_return_if_fail (data != NULL);
if (g_str_hash (data->name) == id)
{
gtk_notebook_set_current_page (
GTK_NOTEBOOK (panel->priv->notebook), i);
gtk_notebook_set_current_page (GTK_NOTEBOOK (panel->priv->notebook), i);
return;
}