xed-encodings-dialog: Clean up code styling
This commit is contained in:
parent
41162911b2
commit
c801604a2c
|
@ -2,7 +2,7 @@
|
||||||
* xed-encodings-dialog.c
|
* xed-encodings-dialog.c
|
||||||
* This file is part of xed
|
* This file is part of xed
|
||||||
*
|
*
|
||||||
* Copyright (C) 2002-2005 Paolo Maggi
|
* Copyright (C) 2002-2005 Paolo Maggi
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
@ -16,14 +16,14 @@
|
||||||
*
|
*
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program; if not, write to the Free Software
|
* along with this program; if not, write to the Free Software
|
||||||
* Foundation, Inc., 51 Franklin St, Fifth Floor,
|
* Foundation, Inc., 51 Franklin St, Fifth Floor,
|
||||||
* Boston, MA 02110-1301, USA.
|
* Boston, MA 02110-1301, USA.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Modified by the xed Team, 2002-2005. See the AUTHORS file for a
|
* Modified by the xed Team, 2002-2005. See the AUTHORS file for a
|
||||||
* list of people on the xed Team.
|
* list of people on the xed Team.
|
||||||
* See the ChangeLog files for a list of changes.
|
* See the ChangeLog files for a list of changes.
|
||||||
*
|
*
|
||||||
* $Id$
|
* $Id$
|
||||||
*/
|
*/
|
||||||
|
@ -47,19 +47,19 @@
|
||||||
#include "xed-dirs.h"
|
#include "xed-dirs.h"
|
||||||
|
|
||||||
#define XED_ENCODINGS_DIALOG_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \
|
#define XED_ENCODINGS_DIALOG_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), \
|
||||||
XED_TYPE_ENCODINGS_DIALOG, \
|
XED_TYPE_ENCODINGS_DIALOG, \
|
||||||
XedEncodingsDialogPrivate))
|
XedEncodingsDialogPrivate))
|
||||||
|
|
||||||
struct _XedEncodingsDialogPrivate
|
struct _XedEncodingsDialogPrivate
|
||||||
{
|
{
|
||||||
GtkListStore *available_liststore;
|
GtkListStore *available_liststore;
|
||||||
GtkListStore *displayed_liststore;
|
GtkListStore *displayed_liststore;
|
||||||
GtkWidget *available_treeview;
|
GtkWidget *available_treeview;
|
||||||
GtkWidget *displayed_treeview;
|
GtkWidget *displayed_treeview;
|
||||||
GtkWidget *add_button;
|
GtkWidget *add_button;
|
||||||
GtkWidget *remove_button;
|
GtkWidget *remove_button;
|
||||||
|
|
||||||
GSList *show_in_menu_list;
|
GSList *show_in_menu_list;
|
||||||
};
|
};
|
||||||
|
|
||||||
G_DEFINE_TYPE(XedEncodingsDialog, xed_encodings_dialog, GTK_TYPE_DIALOG)
|
G_DEFINE_TYPE(XedEncodingsDialog, xed_encodings_dialog, GTK_TYPE_DIALOG)
|
||||||
|
@ -67,432 +67,375 @@ G_DEFINE_TYPE(XedEncodingsDialog, xed_encodings_dialog, GTK_TYPE_DIALOG)
|
||||||
static void
|
static void
|
||||||
xed_encodings_dialog_finalize (GObject *object)
|
xed_encodings_dialog_finalize (GObject *object)
|
||||||
{
|
{
|
||||||
XedEncodingsDialogPrivate *priv = XED_ENCODINGS_DIALOG (object)->priv;
|
XedEncodingsDialogPrivate *priv = XED_ENCODINGS_DIALOG (object)->priv;
|
||||||
|
|
||||||
g_slist_free (priv->show_in_menu_list);
|
g_slist_free (priv->show_in_menu_list);
|
||||||
|
|
||||||
G_OBJECT_CLASS (xed_encodings_dialog_parent_class)->finalize (object);
|
G_OBJECT_CLASS (xed_encodings_dialog_parent_class)->finalize (object);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
xed_encodings_dialog_class_init (XedEncodingsDialogClass *klass)
|
xed_encodings_dialog_class_init (XedEncodingsDialogClass *klass)
|
||||||
{
|
{
|
||||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||||
|
|
||||||
object_class->finalize = xed_encodings_dialog_finalize;
|
object_class->finalize = xed_encodings_dialog_finalize;
|
||||||
|
|
||||||
g_type_class_add_private (object_class, sizeof (XedEncodingsDialogPrivate));
|
g_type_class_add_private (object_class, sizeof (XedEncodingsDialogPrivate));
|
||||||
}
|
}
|
||||||
|
|
||||||
enum {
|
enum
|
||||||
COLUMN_NAME,
|
{
|
||||||
COLUMN_CHARSET,
|
COLUMN_NAME,
|
||||||
N_COLUMNS
|
COLUMN_CHARSET,
|
||||||
|
N_COLUMNS
|
||||||
};
|
};
|
||||||
|
|
||||||
static void
|
static void
|
||||||
count_selected_items_func (GtkTreeModel *model,
|
count_selected_items_func (GtkTreeModel *model,
|
||||||
GtkTreePath *path,
|
GtkTreePath *path,
|
||||||
GtkTreeIter *iter,
|
GtkTreeIter *iter,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
{
|
{
|
||||||
int *count = data;
|
int *count = data;
|
||||||
|
|
||||||
*count += 1;
|
*count += 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
available_selection_changed_callback (GtkTreeSelection *selection,
|
available_selection_changed_callback (GtkTreeSelection *selection,
|
||||||
XedEncodingsDialog *dialogs)
|
XedEncodingsDialog *dialogs)
|
||||||
{
|
{
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
gtk_tree_selection_selected_foreach (selection,
|
gtk_tree_selection_selected_foreach (selection, count_selected_items_func, &count);
|
||||||
count_selected_items_func,
|
|
||||||
&count);
|
|
||||||
|
|
||||||
gtk_widget_set_sensitive (dialogs->priv->add_button, count > 0);
|
gtk_widget_set_sensitive (dialogs->priv->add_button, count > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
displayed_selection_changed_callback (GtkTreeSelection *selection,
|
displayed_selection_changed_callback (GtkTreeSelection *selection,
|
||||||
XedEncodingsDialog *dialogs)
|
XedEncodingsDialog *dialogs)
|
||||||
{
|
{
|
||||||
int count;
|
int count;
|
||||||
|
|
||||||
count = 0;
|
count = 0;
|
||||||
gtk_tree_selection_selected_foreach (selection,
|
gtk_tree_selection_selected_foreach (selection, count_selected_items_func, &count);
|
||||||
count_selected_items_func,
|
|
||||||
&count);
|
|
||||||
|
|
||||||
gtk_widget_set_sensitive (dialogs->priv->remove_button, count > 0);
|
gtk_widget_set_sensitive (dialogs->priv->remove_button, count > 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
get_selected_encodings_func (GtkTreeModel *model,
|
get_selected_encodings_func (GtkTreeModel *model,
|
||||||
GtkTreePath *path,
|
GtkTreePath *path,
|
||||||
GtkTreeIter *iter,
|
GtkTreeIter *iter,
|
||||||
gpointer data)
|
gpointer data)
|
||||||
{
|
{
|
||||||
GSList **list = data;
|
GSList **list = data;
|
||||||
gchar *charset;
|
gchar *charset;
|
||||||
const XedEncoding *enc;
|
const XedEncoding *enc;
|
||||||
|
|
||||||
charset = NULL;
|
charset = NULL;
|
||||||
gtk_tree_model_get (model, iter, COLUMN_CHARSET, &charset, -1);
|
gtk_tree_model_get (model, iter, COLUMN_CHARSET, &charset, -1);
|
||||||
|
|
||||||
enc = xed_encoding_get_from_charset (charset);
|
enc = xed_encoding_get_from_charset (charset);
|
||||||
g_free (charset);
|
g_free (charset);
|
||||||
|
|
||||||
*list = g_slist_prepend (*list, (gpointer)enc);
|
*list = g_slist_prepend (*list, (gpointer)enc);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
update_shown_in_menu_tree_model (GtkListStore *store,
|
update_shown_in_menu_tree_model (GtkListStore *store,
|
||||||
GSList *list)
|
GSList *list)
|
||||||
{
|
{
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
|
|
||||||
gtk_list_store_clear (store);
|
gtk_list_store_clear (store);
|
||||||
|
|
||||||
while (list != NULL)
|
while (list != NULL)
|
||||||
{
|
{
|
||||||
const XedEncoding *enc;
|
const XedEncoding *enc;
|
||||||
|
|
||||||
enc = (const XedEncoding*) list->data;
|
enc = (const XedEncoding*) list->data;
|
||||||
|
|
||||||
gtk_list_store_append (store, &iter);
|
gtk_list_store_append (store, &iter);
|
||||||
gtk_list_store_set (store, &iter,
|
gtk_list_store_set (store, &iter,
|
||||||
COLUMN_CHARSET,
|
COLUMN_CHARSET, xed_encoding_get_charset (enc),
|
||||||
xed_encoding_get_charset (enc),
|
COLUMN_NAME, xed_encoding_get_name (enc),
|
||||||
COLUMN_NAME,
|
-1);
|
||||||
xed_encoding_get_name (enc), -1);
|
|
||||||
|
|
||||||
list = g_slist_next (list);
|
list = g_slist_next (list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
add_button_clicked_callback (GtkWidget *button,
|
add_button_clicked_callback (GtkWidget *button,
|
||||||
XedEncodingsDialog *dialog)
|
XedEncodingsDialog *dialog)
|
||||||
{
|
{
|
||||||
GtkTreeSelection *selection;
|
GtkTreeSelection *selection;
|
||||||
GSList *encodings;
|
GSList *encodings;
|
||||||
GSList *tmp;
|
GSList *tmp;
|
||||||
|
|
||||||
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->priv->available_treeview));
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->priv->available_treeview));
|
||||||
|
|
||||||
encodings = NULL;
|
encodings = NULL;
|
||||||
gtk_tree_selection_selected_foreach (selection,
|
gtk_tree_selection_selected_foreach (selection, get_selected_encodings_func, &encodings);
|
||||||
get_selected_encodings_func,
|
|
||||||
&encodings);
|
|
||||||
|
|
||||||
tmp = encodings;
|
tmp = encodings;
|
||||||
while (tmp != NULL)
|
while (tmp != NULL)
|
||||||
{
|
{
|
||||||
if (g_slist_find (dialog->priv->show_in_menu_list, tmp->data) == NULL)
|
if (g_slist_find (dialog->priv->show_in_menu_list, tmp->data) == NULL)
|
||||||
dialog->priv->show_in_menu_list = g_slist_prepend (dialog->priv->show_in_menu_list,
|
dialog->priv->show_in_menu_list = g_slist_prepend (dialog->priv->show_in_menu_list, tmp->data);
|
||||||
tmp->data);
|
|
||||||
|
|
||||||
tmp = g_slist_next (tmp);
|
tmp = g_slist_next (tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_slist_free (encodings);
|
g_slist_free (encodings);
|
||||||
|
|
||||||
update_shown_in_menu_tree_model (GTK_LIST_STORE (dialog->priv->displayed_liststore),
|
update_shown_in_menu_tree_model (GTK_LIST_STORE (dialog->priv->displayed_liststore),
|
||||||
dialog->priv->show_in_menu_list);
|
dialog->priv->show_in_menu_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
remove_button_clicked_callback (GtkWidget *button,
|
remove_button_clicked_callback (GtkWidget *button,
|
||||||
XedEncodingsDialog *dialog)
|
XedEncodingsDialog *dialog)
|
||||||
{
|
{
|
||||||
GtkTreeSelection *selection;
|
GtkTreeSelection *selection;
|
||||||
GSList *encodings;
|
GSList *encodings;
|
||||||
GSList *tmp;
|
GSList *tmp;
|
||||||
|
|
||||||
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->priv->displayed_treeview));
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dialog->priv->displayed_treeview));
|
||||||
|
|
||||||
encodings = NULL;
|
encodings = NULL;
|
||||||
gtk_tree_selection_selected_foreach (selection,
|
gtk_tree_selection_selected_foreach (selection, get_selected_encodings_func, &encodings);
|
||||||
get_selected_encodings_func,
|
|
||||||
&encodings);
|
|
||||||
|
|
||||||
tmp = encodings;
|
tmp = encodings;
|
||||||
while (tmp != NULL)
|
while (tmp != NULL)
|
||||||
{
|
{
|
||||||
dialog->priv->show_in_menu_list = g_slist_remove (dialog->priv->show_in_menu_list,
|
dialog->priv->show_in_menu_list = g_slist_remove (dialog->priv->show_in_menu_list, tmp->data);
|
||||||
tmp->data);
|
|
||||||
|
|
||||||
tmp = g_slist_next (tmp);
|
tmp = g_slist_next (tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_slist_free (encodings);
|
g_slist_free (encodings);
|
||||||
|
|
||||||
update_shown_in_menu_tree_model (GTK_LIST_STORE (dialog->priv->displayed_liststore),
|
update_shown_in_menu_tree_model (GTK_LIST_STORE (dialog->priv->displayed_liststore),
|
||||||
dialog->priv->show_in_menu_list);
|
dialog->priv->show_in_menu_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
init_shown_in_menu_tree_model (XedEncodingsDialog *dialog)
|
init_shown_in_menu_tree_model (XedEncodingsDialog *dialog)
|
||||||
{
|
{
|
||||||
GtkTreeIter iter;
|
GtkTreeIter iter;
|
||||||
GSList *list, *tmp;
|
GSList *list, *tmp;
|
||||||
|
|
||||||
/* add data to the list store */
|
/* add data to the list store */
|
||||||
list = xed_prefs_manager_get_shown_in_menu_encodings ();
|
list = xed_prefs_manager_get_shown_in_menu_encodings ();
|
||||||
|
|
||||||
tmp = list;
|
tmp = list;
|
||||||
|
|
||||||
while (tmp != NULL)
|
while (tmp != NULL)
|
||||||
{
|
{
|
||||||
const XedEncoding *enc;
|
const XedEncoding *enc;
|
||||||
|
|
||||||
enc = (const XedEncoding *) tmp->data;
|
enc = (const XedEncoding *) tmp->data;
|
||||||
|
|
||||||
dialog->priv->show_in_menu_list = g_slist_prepend (dialog->priv->show_in_menu_list,
|
dialog->priv->show_in_menu_list = g_slist_prepend (dialog->priv->show_in_menu_list, tmp->data);
|
||||||
tmp->data);
|
|
||||||
|
|
||||||
gtk_list_store_append (dialog->priv->displayed_liststore,
|
gtk_list_store_append (dialog->priv->displayed_liststore, &iter);
|
||||||
&iter);
|
gtk_list_store_set (dialog->priv->displayed_liststore, &iter,
|
||||||
gtk_list_store_set (dialog->priv->displayed_liststore,
|
COLUMN_CHARSET, xed_encoding_get_charset (enc),
|
||||||
&iter,
|
COLUMN_NAME, xed_encoding_get_name (enc),
|
||||||
COLUMN_CHARSET,
|
-1);
|
||||||
xed_encoding_get_charset (enc),
|
|
||||||
COLUMN_NAME,
|
|
||||||
xed_encoding_get_name (enc), -1);
|
|
||||||
|
|
||||||
tmp = g_slist_next (tmp);
|
tmp = g_slist_next (tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_slist_free (list);
|
g_slist_free (list);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
response_handler (GtkDialog *dialog,
|
response_handler (GtkDialog *dialog,
|
||||||
gint response_id,
|
gint response_id,
|
||||||
XedEncodingsDialog *dlg)
|
XedEncodingsDialog *dlg)
|
||||||
{
|
{
|
||||||
if (response_id == GTK_RESPONSE_HELP)
|
if (response_id == GTK_RESPONSE_HELP)
|
||||||
{
|
{
|
||||||
xed_help_display (GTK_WINDOW (dialog), "xed", NULL);
|
xed_help_display (GTK_WINDOW (dialog), "xed", NULL);
|
||||||
g_signal_stop_emission_by_name (dialog, "response");
|
g_signal_stop_emission_by_name (dialog, "response");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (response_id == GTK_RESPONSE_OK)
|
if (response_id == GTK_RESPONSE_OK)
|
||||||
{
|
{
|
||||||
g_return_if_fail (xed_prefs_manager_shown_in_menu_encodings_can_set ());
|
g_return_if_fail (xed_prefs_manager_shown_in_menu_encodings_can_set ());
|
||||||
xed_prefs_manager_set_shown_in_menu_encodings (dlg->priv->show_in_menu_list);
|
xed_prefs_manager_set_shown_in_menu_encodings (dlg->priv->show_in_menu_list);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
xed_encodings_dialog_init (XedEncodingsDialog *dlg)
|
xed_encodings_dialog_init (XedEncodingsDialog *dlg)
|
||||||
{
|
{
|
||||||
GtkWidget *content;
|
GtkWidget *content;
|
||||||
GtkCellRenderer *cell_renderer;
|
GtkCellRenderer *cell_renderer;
|
||||||
GtkTreeModel *sort_model;
|
GtkTreeModel *sort_model;
|
||||||
GtkTreeViewColumn *column;
|
GtkTreeViewColumn *column;
|
||||||
GtkTreeIter parent_iter;
|
GtkTreeIter parent_iter;
|
||||||
GtkTreeSelection *selection;
|
GtkTreeSelection *selection;
|
||||||
const XedEncoding *enc;
|
const XedEncoding *enc;
|
||||||
GtkWidget *error_widget;
|
GtkWidget *error_widget;
|
||||||
int i;
|
int i;
|
||||||
gboolean ret;
|
gboolean ret;
|
||||||
gchar *file;
|
gchar *file;
|
||||||
gchar *root_objects[] = {
|
gchar *root_objects[] = {
|
||||||
"encodings-dialog-contents",
|
"encodings-dialog-contents",
|
||||||
NULL
|
NULL
|
||||||
};
|
};
|
||||||
|
|
||||||
dlg->priv = XED_ENCODINGS_DIALOG_GET_PRIVATE (dlg);
|
dlg->priv = XED_ENCODINGS_DIALOG_GET_PRIVATE (dlg);
|
||||||
|
|
||||||
gtk_dialog_add_buttons (GTK_DIALOG (dlg),
|
|
||||||
GTK_STOCK_CANCEL,
|
|
||||||
GTK_RESPONSE_CANCEL,
|
|
||||||
GTK_STOCK_OK,
|
|
||||||
GTK_RESPONSE_OK,
|
|
||||||
GTK_STOCK_HELP,
|
|
||||||
GTK_RESPONSE_HELP,
|
|
||||||
NULL);
|
|
||||||
|
|
||||||
gtk_window_set_title (GTK_WINDOW (dlg), _("Character Encodings"));
|
gtk_dialog_add_buttons (GTK_DIALOG (dlg),
|
||||||
gtk_window_set_default_size (GTK_WINDOW (dlg), 650, 400);
|
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
|
||||||
|
GTK_STOCK_OK, GTK_RESPONSE_OK,
|
||||||
/* HIG defaults */
|
GTK_STOCK_HELP, GTK_RESPONSE_HELP,
|
||||||
gtk_container_set_border_width (GTK_CONTAINER (dlg), 5);
|
NULL);
|
||||||
gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))),
|
|
||||||
2); /* 2 * 5 + 2 = 12 */
|
|
||||||
gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dlg))),
|
|
||||||
5);
|
|
||||||
gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dlg))), 6);
|
|
||||||
|
|
||||||
gtk_dialog_set_default_response (GTK_DIALOG (dlg),
|
gtk_window_set_title (GTK_WINDOW (dlg), _("Character Encodings"));
|
||||||
GTK_RESPONSE_OK);
|
gtk_window_set_default_size (GTK_WINDOW (dlg), 650, 400);
|
||||||
|
|
||||||
g_signal_connect (dlg,
|
/* HIG defaults */
|
||||||
"response",
|
gtk_container_set_border_width (GTK_CONTAINER (dlg), 5);
|
||||||
G_CALLBACK (response_handler),
|
gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), 2); /* 2 * 5 + 2 = 12 */
|
||||||
dlg);
|
gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_action_area (GTK_DIALOG (dlg))), 5);
|
||||||
|
gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_action_area (GTK_DIALOG (dlg))), 6);
|
||||||
|
|
||||||
file = xed_dirs_get_ui_file ("xed-encodings-dialog.ui");
|
gtk_dialog_set_default_response (GTK_DIALOG (dlg), GTK_RESPONSE_OK);
|
||||||
ret = xed_utils_get_ui_objects (file,
|
|
||||||
root_objects,
|
|
||||||
&error_widget,
|
|
||||||
"encodings-dialog-contents", &content,
|
|
||||||
"add-button", &dlg->priv->add_button,
|
|
||||||
"remove-button", &dlg->priv->remove_button,
|
|
||||||
"available-treeview", &dlg->priv->available_treeview,
|
|
||||||
"displayed-treeview", &dlg->priv->displayed_treeview,
|
|
||||||
NULL);
|
|
||||||
g_free (file);
|
|
||||||
|
|
||||||
if (!ret)
|
g_signal_connect (dlg, "response", G_CALLBACK (response_handler), dlg);
|
||||||
{
|
|
||||||
gtk_widget_show (error_widget);
|
|
||||||
|
|
||||||
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))),
|
file = xed_dirs_get_ui_file ("xed-encodings-dialog.ui");
|
||||||
error_widget,
|
ret = xed_utils_get_ui_objects (file,
|
||||||
TRUE, TRUE, 0);
|
root_objects,
|
||||||
gtk_container_set_border_width (GTK_CONTAINER (error_widget), 5);
|
&error_widget,
|
||||||
|
"encodings-dialog-contents", &content,
|
||||||
|
"add-button", &dlg->priv->add_button,
|
||||||
|
"remove-button", &dlg->priv->remove_button,
|
||||||
|
"available-treeview", &dlg->priv->available_treeview,
|
||||||
|
"displayed-treeview", &dlg->priv->displayed_treeview,
|
||||||
|
NULL);
|
||||||
|
g_free (file);
|
||||||
|
|
||||||
return;
|
if (!ret)
|
||||||
}
|
{
|
||||||
|
gtk_widget_show (error_widget);
|
||||||
|
|
||||||
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))),
|
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), error_widget, TRUE, TRUE, 0);
|
||||||
content, TRUE, TRUE, 0);
|
gtk_container_set_border_width (GTK_CONTAINER (error_widget), 5);
|
||||||
g_object_unref (content);
|
|
||||||
gtk_container_set_border_width (GTK_CONTAINER (content), 5);
|
|
||||||
|
|
||||||
g_signal_connect (dlg->priv->add_button,
|
return;
|
||||||
"clicked",
|
}
|
||||||
G_CALLBACK (add_button_clicked_callback),
|
|
||||||
dlg);
|
|
||||||
g_signal_connect (dlg->priv->remove_button,
|
|
||||||
"clicked",
|
|
||||||
G_CALLBACK (remove_button_clicked_callback),
|
|
||||||
dlg);
|
|
||||||
|
|
||||||
/* Tree view of available encodings */
|
gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dlg))), content, TRUE, TRUE, 0);
|
||||||
dlg->priv->available_liststore = gtk_list_store_new (N_COLUMNS,
|
g_object_unref (content);
|
||||||
G_TYPE_STRING,
|
gtk_container_set_border_width (GTK_CONTAINER (content), 5);
|
||||||
G_TYPE_STRING);
|
|
||||||
|
|
||||||
cell_renderer = gtk_cell_renderer_text_new ();
|
g_signal_connect (dlg->priv->add_button, "clicked", G_CALLBACK (add_button_clicked_callback), dlg);
|
||||||
column = gtk_tree_view_column_new_with_attributes (_("_Description"),
|
g_signal_connect (dlg->priv->remove_button, "clicked", G_CALLBACK (remove_button_clicked_callback), dlg);
|
||||||
cell_renderer,
|
|
||||||
"text", COLUMN_NAME,
|
|
||||||
NULL);
|
|
||||||
gtk_tree_view_append_column (GTK_TREE_VIEW (dlg->priv->available_treeview),
|
|
||||||
column);
|
|
||||||
gtk_tree_view_column_set_sort_column_id (column, COLUMN_NAME);
|
|
||||||
|
|
||||||
cell_renderer = gtk_cell_renderer_text_new ();
|
/* Tree view of available encodings */
|
||||||
column = gtk_tree_view_column_new_with_attributes (_("_Encoding"),
|
dlg->priv->available_liststore = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING);
|
||||||
cell_renderer,
|
|
||||||
"text",
|
|
||||||
COLUMN_CHARSET,
|
|
||||||
NULL);
|
|
||||||
gtk_tree_view_append_column (GTK_TREE_VIEW (dlg->priv->available_treeview),
|
|
||||||
column);
|
|
||||||
gtk_tree_view_column_set_sort_column_id (column, COLUMN_CHARSET);
|
|
||||||
|
|
||||||
/* Add the data */
|
cell_renderer = gtk_cell_renderer_text_new ();
|
||||||
i = 0;
|
column = gtk_tree_view_column_new_with_attributes (_("_Description"),
|
||||||
while ((enc = xed_encoding_get_from_index (i)) != NULL)
|
cell_renderer,
|
||||||
{
|
"text", COLUMN_NAME,
|
||||||
gtk_list_store_append (dlg->priv->available_liststore,
|
NULL);
|
||||||
&parent_iter);
|
gtk_tree_view_append_column (GTK_TREE_VIEW (dlg->priv->available_treeview), column);
|
||||||
gtk_list_store_set (dlg->priv->available_liststore,
|
gtk_tree_view_column_set_sort_column_id (column, COLUMN_NAME);
|
||||||
&parent_iter,
|
|
||||||
COLUMN_CHARSET,
|
|
||||||
xed_encoding_get_charset (enc),
|
|
||||||
COLUMN_NAME,
|
|
||||||
xed_encoding_get_name (enc), -1);
|
|
||||||
|
|
||||||
++i;
|
cell_renderer = gtk_cell_renderer_text_new ();
|
||||||
}
|
column = gtk_tree_view_column_new_with_attributes (_("_Encoding"),
|
||||||
|
cell_renderer,
|
||||||
|
"text",
|
||||||
|
COLUMN_CHARSET,
|
||||||
|
NULL);
|
||||||
|
gtk_tree_view_append_column (GTK_TREE_VIEW (dlg->priv->available_treeview), column);
|
||||||
|
gtk_tree_view_column_set_sort_column_id (column, COLUMN_CHARSET);
|
||||||
|
|
||||||
/* Sort model */
|
/* Add the data */
|
||||||
sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (dlg->priv->available_liststore));
|
i = 0;
|
||||||
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_model),
|
while ((enc = xed_encoding_get_from_index (i)) != NULL)
|
||||||
COLUMN_NAME,
|
{
|
||||||
GTK_SORT_ASCENDING);
|
gtk_list_store_append (dlg->priv->available_liststore, &parent_iter);
|
||||||
|
gtk_list_store_set (dlg->priv->available_liststore, &parent_iter,
|
||||||
|
COLUMN_CHARSET, xed_encoding_get_charset (enc),
|
||||||
|
COLUMN_NAME, xed_encoding_get_name (enc),
|
||||||
|
-1);
|
||||||
|
|
||||||
gtk_tree_view_set_model (GTK_TREE_VIEW (dlg->priv->available_treeview),
|
++i;
|
||||||
sort_model);
|
}
|
||||||
g_object_unref (G_OBJECT (dlg->priv->available_liststore));
|
|
||||||
g_object_unref (G_OBJECT (sort_model));
|
|
||||||
|
|
||||||
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dlg->priv->available_treeview));
|
/* Sort model */
|
||||||
gtk_tree_selection_set_mode (GTK_TREE_SELECTION (selection),
|
sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (dlg->priv->available_liststore));
|
||||||
GTK_SELECTION_MULTIPLE);
|
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_model), COLUMN_NAME, GTK_SORT_ASCENDING);
|
||||||
|
|
||||||
available_selection_changed_callback (selection, dlg);
|
gtk_tree_view_set_model (GTK_TREE_VIEW (dlg->priv->available_treeview), sort_model);
|
||||||
g_signal_connect (selection,
|
g_object_unref (G_OBJECT (dlg->priv->available_liststore));
|
||||||
"changed",
|
g_object_unref (G_OBJECT (sort_model));
|
||||||
G_CALLBACK (available_selection_changed_callback),
|
|
||||||
dlg);
|
|
||||||
|
|
||||||
/* Tree view of selected encodings */
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dlg->priv->available_treeview));
|
||||||
dlg->priv->displayed_liststore = gtk_list_store_new (N_COLUMNS,
|
gtk_tree_selection_set_mode (GTK_TREE_SELECTION (selection), GTK_SELECTION_MULTIPLE);
|
||||||
G_TYPE_STRING,
|
|
||||||
G_TYPE_STRING);
|
|
||||||
|
|
||||||
cell_renderer = gtk_cell_renderer_text_new ();
|
available_selection_changed_callback (selection, dlg);
|
||||||
column = gtk_tree_view_column_new_with_attributes (_("_Description"),
|
g_signal_connect (selection, "changed", G_CALLBACK (available_selection_changed_callback), dlg);
|
||||||
cell_renderer,
|
|
||||||
"text", COLUMN_NAME,
|
|
||||||
NULL);
|
|
||||||
gtk_tree_view_append_column (GTK_TREE_VIEW (dlg->priv->displayed_treeview),
|
|
||||||
column);
|
|
||||||
gtk_tree_view_column_set_sort_column_id (column, COLUMN_NAME);
|
|
||||||
|
|
||||||
cell_renderer = gtk_cell_renderer_text_new ();
|
/* Tree view of selected encodings */
|
||||||
column = gtk_tree_view_column_new_with_attributes (_("_Encoding"),
|
dlg->priv->displayed_liststore = gtk_list_store_new (N_COLUMNS, G_TYPE_STRING, G_TYPE_STRING);
|
||||||
cell_renderer,
|
|
||||||
"text",
|
|
||||||
COLUMN_CHARSET,
|
|
||||||
NULL);
|
|
||||||
gtk_tree_view_append_column (GTK_TREE_VIEW (dlg->priv->displayed_treeview),
|
|
||||||
column);
|
|
||||||
gtk_tree_view_column_set_sort_column_id (column, COLUMN_CHARSET);
|
|
||||||
|
|
||||||
/* Add the data */
|
cell_renderer = gtk_cell_renderer_text_new ();
|
||||||
init_shown_in_menu_tree_model (dlg);
|
column = gtk_tree_view_column_new_with_attributes (_("_Description"),
|
||||||
|
cell_renderer,
|
||||||
|
"text", COLUMN_NAME,
|
||||||
|
NULL);
|
||||||
|
gtk_tree_view_append_column (GTK_TREE_VIEW (dlg->priv->displayed_treeview), column);
|
||||||
|
gtk_tree_view_column_set_sort_column_id (column, COLUMN_NAME);
|
||||||
|
|
||||||
/* Sort model */
|
cell_renderer = gtk_cell_renderer_text_new ();
|
||||||
sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (dlg->priv->displayed_liststore));
|
column = gtk_tree_view_column_new_with_attributes (_("_Encoding"),
|
||||||
|
cell_renderer,
|
||||||
|
"text",
|
||||||
|
COLUMN_CHARSET,
|
||||||
|
NULL);
|
||||||
|
gtk_tree_view_append_column (GTK_TREE_VIEW (dlg->priv->displayed_treeview), column);
|
||||||
|
gtk_tree_view_column_set_sort_column_id (column, COLUMN_CHARSET);
|
||||||
|
|
||||||
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE
|
/* Add the data */
|
||||||
(sort_model), COLUMN_NAME,
|
init_shown_in_menu_tree_model (dlg);
|
||||||
GTK_SORT_ASCENDING);
|
|
||||||
|
|
||||||
gtk_tree_view_set_model (GTK_TREE_VIEW (dlg->priv->displayed_treeview),
|
/* Sort model */
|
||||||
sort_model);
|
sort_model = gtk_tree_model_sort_new_with_model (GTK_TREE_MODEL (dlg->priv->displayed_liststore));
|
||||||
g_object_unref (G_OBJECT (sort_model));
|
|
||||||
g_object_unref (G_OBJECT (dlg->priv->displayed_liststore));
|
|
||||||
|
|
||||||
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dlg->priv->displayed_treeview));
|
gtk_tree_sortable_set_sort_column_id (GTK_TREE_SORTABLE (sort_model), COLUMN_NAME, GTK_SORT_ASCENDING);
|
||||||
gtk_tree_selection_set_mode (GTK_TREE_SELECTION (selection),
|
|
||||||
GTK_SELECTION_MULTIPLE);
|
|
||||||
|
|
||||||
displayed_selection_changed_callback (selection, dlg);
|
gtk_tree_view_set_model (GTK_TREE_VIEW (dlg->priv->displayed_treeview), sort_model);
|
||||||
g_signal_connect (selection,
|
g_object_unref (G_OBJECT (sort_model));
|
||||||
"changed",
|
g_object_unref (G_OBJECT (dlg->priv->displayed_liststore));
|
||||||
G_CALLBACK (displayed_selection_changed_callback),
|
|
||||||
dlg);
|
selection = gtk_tree_view_get_selection (GTK_TREE_VIEW (dlg->priv->displayed_treeview));
|
||||||
|
gtk_tree_selection_set_mode (GTK_TREE_SELECTION (selection), GTK_SELECTION_MULTIPLE);
|
||||||
|
|
||||||
|
displayed_selection_changed_callback (selection, dlg);
|
||||||
|
g_signal_connect (selection, "changed", G_CALLBACK (displayed_selection_changed_callback), dlg);
|
||||||
}
|
}
|
||||||
|
|
||||||
GtkWidget *
|
GtkWidget *
|
||||||
xed_encodings_dialog_new (void)
|
xed_encodings_dialog_new (void)
|
||||||
{
|
{
|
||||||
GtkWidget *dlg;
|
GtkWidget *dlg;
|
||||||
|
|
||||||
dlg = GTK_WIDGET (g_object_new (XED_TYPE_ENCODINGS_DIALOG, NULL));
|
dlg = GTK_WIDGET (g_object_new (XED_TYPE_ENCODINGS_DIALOG, NULL));
|
||||||
|
|
||||||
return dlg;
|
return dlg;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue