xed-documents-panel: Cleanup code styling

This commit is contained in:
JosephMcc 2016-12-12 02:12:16 -08:00
parent 21f524a7b3
commit 76ce469bfa
1 changed files with 488 additions and 565 deletions

View File

@ -92,23 +92,18 @@ tab_get_name (XedTab *tab)
{
if (xed_document_get_readonly (doc))
{
tab_name = g_markup_printf_escaped ("<i>%s</i> [<i>%s</i>]",
docname,
_("Read-Only"));
tab_name = g_markup_printf_escaped ("<i>%s</i> [<i>%s</i>]", docname, _("Read-Only"));
}
else
{
tab_name = g_markup_printf_escaped ("<i>%s</i>",
docname);
tab_name = g_markup_printf_escaped ("<i>%s</i>", docname);
}
}
else
{
if (xed_document_get_readonly (doc))
{
tab_name = g_markup_printf_escaped ("%s [<i>%s</i>]",
docname,
_("Read-Only"));
tab_name = g_markup_printf_escaped ("%s [<i>%s</i>]", docname, _("Read-Only"));
}
else
{
@ -123,20 +118,19 @@ tab_get_name (XedTab *tab)
}
static void
get_iter_from_tab (XedDocumentsPanel *panel, XedTab *tab, GtkTreeIter *iter)
get_iter_from_tab (XedDocumentsPanel *panel,
XedTab *tab,
GtkTreeIter *iter)
{
gint num;
GtkWidget *nb;
GtkTreePath *path;
nb = _xed_window_get_notebook (panel->priv->window);
num = gtk_notebook_page_num (GTK_NOTEBOOK (nb),
GTK_WIDGET (tab));
num = gtk_notebook_page_num (GTK_NOTEBOOK (nb), GTK_WIDGET (tab));
path = gtk_tree_path_new_from_indices (num, -1);
gtk_tree_model_get_iter (panel->priv->model,
iter,
path);
gtk_tree_model_get_iter (panel->priv->model, iter, path);
gtk_tree_path_free (path);
}
@ -154,11 +148,9 @@ window_active_tab_changed (XedWindow *window,
get_iter_from_tab (panel, tab, &iter);
if (gtk_list_store_iter_is_valid (GTK_LIST_STORE (panel->priv->model),
&iter))
if (gtk_list_store_iter_is_valid (GTK_LIST_STORE (panel->priv->model), &iter))
{
selection = gtk_tree_view_get_selection (
GTK_TREE_VIEW (panel->priv->treeview));
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (panel->priv->treeview));
gtk_tree_selection_select_iter (selection, &iter);
}
@ -202,8 +194,7 @@ refresh_list (XedDocumentsPanel *panel)
/* Add a new row to the model */
gtk_list_store_append (list_store, &iter);
gtk_list_store_set (list_store,
&iter,
gtk_list_store_set (list_store, &iter,
PIXBUF_COLUMN, pixbuf,
NAME_COLUMN, name,
TAB_COLUMN, l->data,
@ -211,14 +202,15 @@ refresh_list (XedDocumentsPanel *panel)
g_free (name);
if (pixbuf != NULL)
{
g_object_unref (pixbuf);
}
if (l->data == active_tab)
{
GtkTreeSelection *selection;
selection = gtk_tree_view_get_selection (
GTK_TREE_VIEW (panel->priv->treeview));
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (panel->priv->treeview));
gtk_tree_selection_select_iter (selection, &iter);
}
@ -245,8 +237,7 @@ sync_name_and_icon (XedTab *tab,
name = tab_get_name (tab);
pixbuf = _xed_tab_get_icon (tab);
gtk_list_store_set (GTK_LIST_STORE (panel->priv->model),
&iter,
gtk_list_store_set (GTK_LIST_STORE (panel->priv->model), &iter,
PIXBUF_COLUMN, pixbuf,
NAME_COLUMN, name,
TAB_COLUMN, tab,
@ -254,23 +245,27 @@ sync_name_and_icon (XedTab *tab,
g_free (name);
if (pixbuf != NULL)
{
g_object_unref (pixbuf);
}
}
static void
window_tab_removed (XedWindow *window,
XedTab *tab,
XedDocumentsPanel *panel)
{
g_signal_handlers_disconnect_by_func (tab,
G_CALLBACK (sync_name_and_icon),
panel);
g_signal_handlers_disconnect_by_func (tab, G_CALLBACK (sync_name_and_icon), panel);
if (_xed_window_is_removing_tabs (window))
{
gtk_list_store_clear (GTK_LIST_STORE (panel->priv->model));
}
else
{
refresh_list (panel);
}
}
static void
window_tab_added (XedWindow *window,
@ -282,33 +277,22 @@ window_tab_added (XedWindow *window,
GdkPixbuf *pixbuf;
gchar *name;
g_signal_connect (tab,
"notify::name",
G_CALLBACK (sync_name_and_icon),
panel);
g_signal_connect (tab,
"notify::state",
G_CALLBACK (sync_name_and_icon),
panel);
g_signal_connect (tab, "notify::name", G_CALLBACK (sync_name_and_icon), panel);
g_signal_connect (tab, "notify::state", G_CALLBACK (sync_name_and_icon), panel);
get_iter_from_tab (panel, tab, &sibling);
panel->priv->adding_tab = TRUE;
if (gtk_list_store_iter_is_valid (GTK_LIST_STORE (panel->priv->model),
&sibling))
if (gtk_list_store_iter_is_valid (GTK_LIST_STORE (panel->priv->model), &sibling))
{
gtk_list_store_insert_after (GTK_LIST_STORE (panel->priv->model),
&iter,
&sibling);
gtk_list_store_insert_after (GTK_LIST_STORE (panel->priv->model), &iter, &sibling);
}
else
{
XedTab *active_tab;
gtk_list_store_append (GTK_LIST_STORE (panel->priv->model),
&iter);
gtk_list_store_append (GTK_LIST_STORE (panel->priv->model), &iter);
active_tab = xed_window_get_active_tab (panel->priv->window);
@ -316,9 +300,7 @@ window_tab_added (XedWindow *window,
{
GtkTreeSelection *selection;
selection = gtk_tree_view_get_selection (
GTK_TREE_VIEW (panel->priv->treeview));
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (panel->priv->treeview));
gtk_tree_selection_select_iter (selection, &iter);
}
}
@ -326,8 +308,7 @@ window_tab_added (XedWindow *window,
name = tab_get_name (tab);
pixbuf = _xed_tab_get_icon (tab);
gtk_list_store_set (GTK_LIST_STORE (panel->priv->model),
&iter,
gtk_list_store_set (GTK_LIST_STORE (panel->priv->model), &iter,
PIXBUF_COLUMN, pixbuf,
NAME_COLUMN, name,
TAB_COLUMN, tab,
@ -335,7 +316,9 @@ window_tab_added (XedWindow *window,
g_free (name);
if (pixbuf != NULL)
{
g_object_unref (pixbuf);
}
panel->priv->adding_tab = FALSE;
}
@ -345,7 +328,9 @@ window_tabs_reordered (XedWindow *window,
XedDocumentsPanel *panel)
{
if (panel->priv->is_reodering)
{
return;
}
refresh_list (panel);
}
@ -359,22 +344,10 @@ set_window (XedDocumentsPanel *panel,
panel->priv->window = g_object_ref (window);
g_signal_connect (window,
"tab_added",
G_CALLBACK (window_tab_added),
panel);
g_signal_connect (window,
"tab_removed",
G_CALLBACK (window_tab_removed),
panel);
g_signal_connect (window,
"tabs_reordered",
G_CALLBACK (window_tabs_reordered),
panel);
g_signal_connect (window,
"active_tab_changed",
G_CALLBACK (window_active_tab_changed),
panel);
g_signal_connect (window, "tab_added", G_CALLBACK (window_tab_added), panel);
g_signal_connect (window, "tab_removed", G_CALLBACK (window_tab_removed), panel);
g_signal_connect (window, "tabs_reordered", G_CALLBACK (window_tabs_reordered), panel);
g_signal_connect (window, "active_tab_changed", G_CALLBACK (window_active_tab_changed), panel);
}
static void
@ -385,21 +358,17 @@ treeview_cursor_changed (GtkTreeView *view,
GtkTreeSelection *selection;
gpointer tab;
selection = gtk_tree_view_get_selection (
GTK_TREE_VIEW (panel->priv->treeview));
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (panel->priv->treeview));
if (gtk_tree_selection_get_selected (selection, NULL, &iter))
{
gtk_tree_model_get (panel->priv->model,
&iter,
TAB_COLUMN,
&tab,
gtk_tree_model_get (panel->priv->model, &iter,
TAB_COLUMN, &tab,
-1);
if (xed_window_get_active_tab (panel->priv->window) != tab)
{
xed_window_set_active_tab (panel->priv->window,
XED_TAB (tab));
xed_window_set_active_tab (panel->priv->window, XED_TAB (tab));
}
}
}
@ -417,7 +386,6 @@ xed_documents_panel_set_property (GObject *object,
case PROP_WINDOW:
set_window (panel, g_value_get_object (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@ -435,8 +403,7 @@ xed_documents_panel_get_property (GObject *object,
switch (prop_id)
{
case PROP_WINDOW:
g_value_set_object (value,
XED_DOCUMENTS_PANEL_GET_PRIVATE (panel)->window);
g_value_set_object (value, XED_DOCUMENTS_PANEL_GET_PRIVATE (panel)->window);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
@ -526,10 +493,7 @@ menu_position (GtkMenu *menu,
path = get_current_path (panel);
gtk_tree_view_get_cell_area (GTK_TREE_VIEW (w),
path,
NULL,
&rect);
gtk_tree_view_get_cell_area (GTK_TREE_VIEW (w), path, NULL, &rect);
wx = rect.x;
wy = rect.y;
@ -561,29 +525,20 @@ show_popup_menu (XedDocumentsPanel *panel,
{
GtkWidget *menu;
menu = gtk_ui_manager_get_widget (xed_window_get_ui_manager (panel->priv->window),
"/NotebookPopup");
menu = gtk_ui_manager_get_widget (xed_window_get_ui_manager (panel->priv->window), "/NotebookPopup");
g_return_val_if_fail (menu != NULL, FALSE);
if (event != NULL)
{
gtk_menu_popup (GTK_MENU (menu),
NULL,
NULL,
NULL,
NULL,
event->button,
event->time);
gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
NULL, NULL,
event->button, event->time);
}
else
{
gtk_menu_popup (GTK_MENU (menu),
NULL,
NULL,
(GtkMenuPositionFunc) menu_position,
panel,
0,
gtk_get_current_event_time ());
gtk_menu_popup (GTK_MENU (menu), NULL, NULL,
(GtkMenuPositionFunc) menu_position, panel,
0, gtk_get_current_event_time ());
gtk_menu_shell_select_first (GTK_MENU_SHELL (menu), FALSE);
}
@ -604,18 +559,12 @@ panel_button_press_event (GtkTreeView *treeview,
{
/* Change the cursor position */
if (gtk_tree_view_get_path_at_pos (treeview,
event->x,
event->y,
&path,
NULL,
NULL,
NULL))
event->x, event->y,
&path, NULL,
NULL, NULL))
{
gtk_tree_view_set_cursor (treeview,
path,
NULL,
FALSE);
gtk_tree_view_set_cursor (treeview, path, NULL, FALSE);
gtk_tree_path_free (path);
@ -669,25 +618,19 @@ treeview_query_tooltip (GtkWidget *widget,
{
gint bin_x, bin_y;
gtk_tree_view_convert_widget_to_bin_window_coords (tree_view,
x, y,
&bin_x, &bin_y);
gtk_tree_view_convert_widget_to_bin_window_coords (tree_view, x, y, &bin_x, &bin_y);
if (!gtk_tree_view_get_path_at_pos (tree_view,
bin_x, bin_y,
&path,
NULL, NULL, NULL))
&path, NULL,
NULL, NULL))
{
return FALSE;
}
}
gtk_tree_model_get_iter (model, &iter, path);
gtk_tree_model_get (model,
&iter,
TAB_COLUMN,
&tab,
-1);
gtk_tree_model_get (model, &iter, TAB_COLUMN, &tab, -1);
tip = _xed_tab_get_tooltips (XED_TAB (tab));
gtk_tooltip_set_markup (tooltip, tip);
@ -711,7 +654,9 @@ treeview_row_inserted (GtkTreeModel *tree_model,
gint new_position;
if (panel->priv->adding_tab)
{
return;
}
tab = xed_window_get_active_tab (panel->priv->window);
g_return_if_fail (tab != NULL);
@ -725,14 +670,13 @@ treeview_row_inserted (GtkTreeModel *tree_model,
nb = _xed_window_get_notebook (panel->priv->window);
new_position = indeces[0];
old_position = gtk_notebook_page_num (GTK_NOTEBOOK (nb),
GTK_WIDGET (tab));
old_position = gtk_notebook_page_num (GTK_NOTEBOOK (nb), GTK_WIDGET (tab));
if (new_position > old_position)
{
new_position = MAX (0, new_position - 1);
}
xed_notebook_reorder_tab (XED_NOTEBOOK (nb),
tab,
new_position);
xed_notebook_reorder_tab (XED_NOTEBOOK (nb), tab, new_position);
panel->priv->is_reodering = FALSE;
}
@ -750,16 +694,13 @@ xed_documents_panel_init (XedDocumentsPanel *panel)
panel->priv->adding_tab = FALSE;
panel->priv->is_reodering = FALSE;
gtk_orientable_set_orientation (GTK_ORIENTABLE (panel),
GTK_ORIENTATION_VERTICAL);
gtk_orientable_set_orientation (GTK_ORIENTABLE (panel), GTK_ORIENTATION_VERTICAL);
/* Create the scrolled window */
sw = gtk_scrolled_window_new (NULL, NULL);
g_return_if_fail (sw != NULL);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw),
GTK_POLICY_AUTOMATIC,
GTK_POLICY_AUTOMATIC);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
gtk_widget_show (sw);
gtk_box_pack_start (GTK_BOX (panel), sw, TRUE, TRUE, 0);
@ -790,35 +731,17 @@ xed_documents_panel_init (XedDocumentsPanel *panel)
gtk_tree_view_column_pack_start (column, cell, TRUE);
gtk_tree_view_column_add_attribute (column, cell, "markup", NAME_COLUMN);
gtk_tree_view_append_column (GTK_TREE_VIEW (panel->priv->treeview),
column);
gtk_tree_view_append_column (GTK_TREE_VIEW (panel->priv->treeview), column);
selection = gtk_tree_view_get_selection (
GTK_TREE_VIEW (panel->priv->treeview));
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (panel->priv->treeview));
gtk_tree_selection_set_mode (selection, GTK_SELECTION_SINGLE);
g_signal_connect (panel->priv->treeview,
"cursor_changed",
G_CALLBACK (treeview_cursor_changed),
panel);
g_signal_connect (panel->priv->treeview,
"button-press-event",
G_CALLBACK (panel_button_press_event),
panel);
g_signal_connect (panel->priv->treeview,
"popup-menu",
G_CALLBACK (panel_popup_menu),
panel);
g_signal_connect (panel->priv->treeview,
"query-tooltip",
G_CALLBACK (treeview_query_tooltip),
NULL);
g_signal_connect (panel->priv->model,
"row-inserted",
G_CALLBACK (treeview_row_inserted),
panel);
g_signal_connect (panel->priv->treeview, "cursor_changed", G_CALLBACK (treeview_cursor_changed), panel);
g_signal_connect (panel->priv->treeview, "button-press-event", G_CALLBACK (panel_button_press_event), panel);
g_signal_connect (panel->priv->treeview, "popup-menu", G_CALLBACK (panel_popup_menu), panel);
g_signal_connect (panel->priv->treeview, "query-tooltip", G_CALLBACK (treeview_query_tooltip), NULL);
g_signal_connect (panel->priv->model, "row-inserted", G_CALLBACK (treeview_row_inserted), panel);
}
GtkWidget *