xed-encodings-combo-box: Clean up code styling
This commit is contained in:
parent
f1c1e6c689
commit
71306fa224
|
@ -176,9 +176,7 @@ add_or_remove (XedEncodingsComboBox *menu,
|
||||||
|
|
||||||
if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (menu), &iter))
|
if (gtk_combo_box_get_active_iter (GTK_COMBO_BOX (menu), &iter))
|
||||||
{
|
{
|
||||||
gtk_tree_model_get (model, &iter,
|
gtk_tree_model_get (model, &iter, ADD_COLUMN, &add_item, -1);
|
||||||
ADD_COLUMN, &add_item,
|
|
||||||
-1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!add_item)
|
if (!add_item)
|
||||||
|
@ -192,11 +190,12 @@ add_or_remove (XedEncodingsComboBox *menu,
|
||||||
GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (menu));
|
GtkWidget *toplevel = gtk_widget_get_toplevel (GTK_WIDGET (menu));
|
||||||
|
|
||||||
if (!gtk_widget_is_toplevel (toplevel))
|
if (!gtk_widget_is_toplevel (toplevel))
|
||||||
|
{
|
||||||
toplevel = NULL;
|
toplevel = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
g_signal_handler_block (menu, menu->priv->changed_id);
|
g_signal_handler_block (menu, menu->priv->changed_id);
|
||||||
gtk_combo_box_set_active (GTK_COMBO_BOX (menu),
|
gtk_combo_box_set_active (GTK_COMBO_BOX (menu), menu->priv->activated_item);
|
||||||
menu->priv->activated_item);
|
|
||||||
g_signal_handler_unblock (menu, menu->priv->changed_id);
|
g_signal_handler_unblock (menu, menu->priv->changed_id);
|
||||||
|
|
||||||
dialog = xed_encodings_dialog_new();
|
dialog = xed_encodings_dialog_new();
|
||||||
|
@ -205,34 +204,30 @@ add_or_remove (XedEncodingsComboBox *menu,
|
||||||
{
|
{
|
||||||
GtkWindowGroup *wg;
|
GtkWindowGroup *wg;
|
||||||
|
|
||||||
gtk_window_set_transient_for (GTK_WINDOW (dialog),
|
gtk_window_set_transient_for (GTK_WINDOW (dialog), GTK_WINDOW (toplevel));
|
||||||
GTK_WINDOW (toplevel));
|
|
||||||
|
|
||||||
wg = gtk_window_get_group (GTK_WINDOW (toplevel));
|
wg = gtk_window_get_group (GTK_WINDOW (toplevel));
|
||||||
if (wg == NULL)
|
if (wg == NULL)
|
||||||
{
|
{
|
||||||
wg = gtk_window_group_new ();
|
wg = gtk_window_group_new ();
|
||||||
gtk_window_group_add_window (wg,
|
gtk_window_group_add_window (wg, GTK_WINDOW (toplevel));
|
||||||
GTK_WINDOW (toplevel));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_window_group_add_window (wg,
|
gtk_window_group_add_window (wg, GTK_WINDOW (dialog));
|
||||||
GTK_WINDOW (dialog));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
gtk_window_set_modal (GTK_WINDOW (dialog), TRUE);
|
||||||
|
|
||||||
g_signal_connect (dialog,
|
g_signal_connect (dialog, "response", G_CALLBACK (dialog_response_cb), menu);
|
||||||
"response",
|
|
||||||
G_CALLBACK (dialog_response_cb),
|
|
||||||
menu);
|
|
||||||
|
|
||||||
gtk_widget_show (dialog);
|
gtk_widget_show (dialog);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static gboolean
|
static gboolean
|
||||||
separator_func (GtkTreeModel *model, GtkTreeIter *iter, gpointer data)
|
separator_func (GtkTreeModel *model,
|
||||||
|
GtkTreeIter *iter,
|
||||||
|
gpointer data)
|
||||||
{
|
{
|
||||||
gchar *str;
|
gchar *str;
|
||||||
gboolean ret;
|
gboolean ret;
|
||||||
|
@ -259,8 +254,7 @@ update_menu (XedEncodingsComboBox *menu)
|
||||||
/* Unset the previous model */
|
/* Unset the previous model */
|
||||||
g_signal_handler_block (menu, menu->priv->changed_id);
|
g_signal_handler_block (menu, menu->priv->changed_id);
|
||||||
gtk_list_store_clear (store);
|
gtk_list_store_clear (store);
|
||||||
gtk_combo_box_set_model (GTK_COMBO_BOX (menu),
|
gtk_combo_box_set_model (GTK_COMBO_BOX (menu), NULL);
|
||||||
NULL);
|
|
||||||
|
|
||||||
utf8_encoding = xed_encoding_get_utf8 ();
|
utf8_encoding = xed_encoding_get_utf8 ();
|
||||||
current_encoding = xed_encoding_get_current ();
|
current_encoding = xed_encoding_get_current ();
|
||||||
|
@ -283,10 +277,13 @@ update_menu (XedEncodingsComboBox *menu)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (current_encoding != utf8_encoding)
|
if (current_encoding != utf8_encoding)
|
||||||
|
{
|
||||||
str = xed_encoding_to_string (utf8_encoding);
|
str = xed_encoding_to_string (utf8_encoding);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
str = g_strdup_printf (_("Current Locale (%s)"),
|
{
|
||||||
xed_encoding_get_charset (utf8_encoding));
|
str = g_strdup_printf (_("Current Locale (%s)"), xed_encoding_get_charset (utf8_encoding));
|
||||||
|
}
|
||||||
|
|
||||||
gtk_list_store_append (store, &iter);
|
gtk_list_store_append (store, &iter);
|
||||||
gtk_list_store_set (store, &iter,
|
gtk_list_store_set (store, &iter,
|
||||||
|
@ -297,11 +294,9 @@ update_menu (XedEncodingsComboBox *menu)
|
||||||
|
|
||||||
g_free (str);
|
g_free (str);
|
||||||
|
|
||||||
if ((utf8_encoding != current_encoding) &&
|
if ((utf8_encoding != current_encoding) && (current_encoding != NULL))
|
||||||
(current_encoding != NULL))
|
|
||||||
{
|
{
|
||||||
str = g_strdup_printf (_("Current Locale (%s)"),
|
str = g_strdup_printf (_("Current Locale (%s)"), xed_encoding_get_charset (current_encoding));
|
||||||
xed_encoding_get_charset (current_encoding));
|
|
||||||
|
|
||||||
gtk_list_store_append (store, &iter);
|
gtk_list_store_append (store, &iter);
|
||||||
gtk_list_store_set (store, &iter,
|
gtk_list_store_set (store, &iter,
|
||||||
|
@ -319,9 +314,7 @@ update_menu (XedEncodingsComboBox *menu)
|
||||||
{
|
{
|
||||||
const XedEncoding *enc = (const XedEncoding *)l->data;
|
const XedEncoding *enc = (const XedEncoding *)l->data;
|
||||||
|
|
||||||
if ((enc != current_encoding) &&
|
if ((enc != current_encoding) && (enc != utf8_encoding) && (enc != NULL))
|
||||||
(enc != utf8_encoding) &&
|
|
||||||
(enc != NULL))
|
|
||||||
{
|
{
|
||||||
str = xed_encoding_to_string (enc);
|
str = xed_encoding_to_string (enc);
|
||||||
|
|
||||||
|
@ -357,8 +350,7 @@ update_menu (XedEncodingsComboBox *menu)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* set the model back */
|
/* set the model back */
|
||||||
gtk_combo_box_set_model (GTK_COMBO_BOX (menu),
|
gtk_combo_box_set_model (GTK_COMBO_BOX (menu), GTK_TREE_MODEL (menu->priv->store));
|
||||||
GTK_TREE_MODEL (menu->priv->store));
|
|
||||||
gtk_combo_box_set_active (GTK_COMBO_BOX (menu), 0);
|
gtk_combo_box_set_active (GTK_COMBO_BOX (menu), 0);
|
||||||
|
|
||||||
g_signal_handler_unblock (menu, menu->priv->changed_id);
|
g_signal_handler_unblock (menu, menu->priv->changed_id);
|
||||||
|
@ -371,15 +363,11 @@ xed_encodings_combo_box_init (XedEncodingsComboBox *menu)
|
||||||
|
|
||||||
menu->priv = XED_ENCODINGS_COMBO_BOX_GET_PRIVATE (menu);
|
menu->priv = XED_ENCODINGS_COMBO_BOX_GET_PRIVATE (menu);
|
||||||
|
|
||||||
menu->priv->store = gtk_list_store_new (N_COLUMNS,
|
menu->priv->store = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_BOOLEAN);
|
||||||
G_TYPE_STRING,
|
|
||||||
G_TYPE_POINTER,
|
|
||||||
G_TYPE_BOOLEAN);
|
|
||||||
|
|
||||||
/* Setup up the cells */
|
/* Setup up the cells */
|
||||||
text_renderer = gtk_cell_renderer_text_new ();
|
text_renderer = gtk_cell_renderer_text_new ();
|
||||||
gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (menu),
|
gtk_cell_layout_pack_end (GTK_CELL_LAYOUT (menu), text_renderer, TRUE);
|
||||||
text_renderer, TRUE);
|
|
||||||
|
|
||||||
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (menu),
|
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT (menu),
|
||||||
text_renderer,
|
text_renderer,
|
||||||
|
@ -387,13 +375,9 @@ xed_encodings_combo_box_init (XedEncodingsComboBox *menu)
|
||||||
NAME_COLUMN,
|
NAME_COLUMN,
|
||||||
NULL);
|
NULL);
|
||||||
|
|
||||||
gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (menu),
|
gtk_combo_box_set_row_separator_func (GTK_COMBO_BOX (menu), separator_func, NULL, NULL);
|
||||||
separator_func, NULL,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
menu->priv->changed_id = g_signal_connect (menu, "changed",
|
menu->priv->changed_id = g_signal_connect (menu, "changed", G_CALLBACK (add_or_remove), menu->priv->store);
|
||||||
G_CALLBACK (add_or_remove),
|
|
||||||
menu->priv->store);
|
|
||||||
|
|
||||||
update_menu (menu);
|
update_menu (menu);
|
||||||
}
|
}
|
||||||
|
@ -420,9 +404,7 @@ xed_encodings_combo_box_get_selected_encoding (XedEncodingsComboBox *menu)
|
||||||
|
|
||||||
model = gtk_combo_box_get_model (GTK_COMBO_BOX (menu));
|
model = gtk_combo_box_get_model (GTK_COMBO_BOX (menu));
|
||||||
|
|
||||||
gtk_tree_model_get (model, &iter,
|
gtk_tree_model_get (model, &iter, ENCODING_COLUMN, &ret, -1);
|
||||||
ENCODING_COLUMN, &ret,
|
|
||||||
-1);
|
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -452,14 +434,11 @@ xed_encodings_combo_box_set_selected_encoding (XedEncodingsComboBox *menu,
|
||||||
{
|
{
|
||||||
const XedEncoding *enc;
|
const XedEncoding *enc;
|
||||||
|
|
||||||
gtk_tree_model_get (model, &iter,
|
gtk_tree_model_get (model, &iter, ENCODING_COLUMN, &enc, -1);
|
||||||
ENCODING_COLUMN, &enc,
|
|
||||||
-1);
|
|
||||||
|
|
||||||
if (enc == encoding)
|
if (enc == encoding)
|
||||||
{
|
{
|
||||||
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (menu),
|
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (menu), &iter);
|
||||||
&iter);
|
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue