xed-file-dialog.c/h: Clean up code styling

This commit is contained in:
JosephMcc 2017-01-13 03:10:01 -08:00
parent 66800ca9a3
commit 9dc61e0df5
2 changed files with 307 additions and 357 deletions

View File

@ -50,17 +50,17 @@
#define XED_FILE_CHOOSER_DIALOG_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), XED_TYPE_FILE_CHOOSER_DIALOG, XedFileChooserDialogPrivate)) #define XED_FILE_CHOOSER_DIALOG_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), XED_TYPE_FILE_CHOOSER_DIALOG, XedFileChooserDialogPrivate))
#define ALL_FILES _("All Files") #define ALL_FILES _("All Files")
#define ALL_TEXT_FILES _("All Text Files") #define ALL_TEXT_FILES _("All Text Files")
struct _XedFileChooserDialogPrivate struct _XedFileChooserDialogPrivate
{ {
GtkWidget *option_menu; GtkWidget *option_menu;
GtkWidget *extra_widget; GtkWidget *extra_widget;
GtkWidget *newline_label; GtkWidget *newline_label;
GtkWidget *newline_combo; GtkWidget *newline_combo;
GtkListStore *newline_store; GtkListStore *newline_store;
}; };
G_DEFINE_TYPE(XedFileChooserDialog, xed_file_chooser_dialog, GTK_TYPE_FILE_CHOOSER_DIALOG) G_DEFINE_TYPE(XedFileChooserDialog, xed_file_chooser_dialog, GTK_TYPE_FILE_CHOOSER_DIALOG)
@ -68,56 +68,47 @@ G_DEFINE_TYPE(XedFileChooserDialog, xed_file_chooser_dialog, GTK_TYPE_FILE_CHOOS
static void static void
xed_file_chooser_dialog_class_init (XedFileChooserDialogClass *klass) xed_file_chooser_dialog_class_init (XedFileChooserDialogClass *klass)
{ {
GObjectClass *object_class = G_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
g_type_class_add_private (object_class, sizeof(XedFileChooserDialogPrivate)); g_type_class_add_private (object_class, sizeof(XedFileChooserDialogPrivate));
} }
static void static void
create_option_menu (XedFileChooserDialog *dialog) create_option_menu (XedFileChooserDialog *dialog)
{ {
GtkWidget *label; GtkWidget *label;
GtkWidget *menu; GtkWidget *menu;
label = gtk_label_new_with_mnemonic (_("C_haracter Encoding:")); label = gtk_label_new_with_mnemonic (_("C_haracter Encoding:"));
gtk_widget_set_halign (label, GTK_ALIGN_START); gtk_widget_set_halign (label, GTK_ALIGN_START);
menu = xed_encodings_combo_box_new ( menu = xed_encodings_combo_box_new (
gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)) == GTK_FILE_CHOOSER_ACTION_SAVE); gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)) == GTK_FILE_CHOOSER_ACTION_SAVE);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), menu); gtk_label_set_mnemonic_widget (GTK_LABEL (label), menu);
gtk_box_pack_start (GTK_BOX (dialog->priv->extra_widget), gtk_box_pack_start (GTK_BOX (dialog->priv->extra_widget), label, FALSE, TRUE, 0);
label, gtk_box_pack_start (GTK_BOX (dialog->priv->extra_widget), menu, TRUE, TRUE, 0);
FALSE,
TRUE,
0);
gtk_box_pack_start (GTK_BOX (dialog->priv->extra_widget), gtk_widget_show (label);
menu, gtk_widget_show (menu);
TRUE,
TRUE,
0);
gtk_widget_show (label); dialog->priv->option_menu = menu;
gtk_widget_show (menu);
dialog->priv->option_menu = menu;
} }
static void static void
update_newline_visibility (XedFileChooserDialog *dialog) update_newline_visibility (XedFileChooserDialog *dialog)
{ {
if (gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)) == GTK_FILE_CHOOSER_ACTION_SAVE) if (gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)) == GTK_FILE_CHOOSER_ACTION_SAVE)
{ {
gtk_widget_show (dialog->priv->newline_label); gtk_widget_show (dialog->priv->newline_label);
gtk_widget_show (dialog->priv->newline_combo); gtk_widget_show (dialog->priv->newline_combo);
} }
else else
{ {
gtk_widget_hide (dialog->priv->newline_label); gtk_widget_hide (dialog->priv->newline_label);
gtk_widget_hide (dialog->priv->newline_combo); gtk_widget_hide (dialog->priv->newline_combo);
} }
} }
static void static void
@ -127,325 +118,298 @@ newline_combo_append (GtkComboBox *combo,
const gchar *label, const gchar *label,
XedDocumentNewlineType newline_type) XedDocumentNewlineType newline_type)
{ {
gtk_list_store_append (store, iter); gtk_list_store_append (store, iter);
gtk_list_store_set (store, iter, 0, label, 1, newline_type, -1); gtk_list_store_set (store, iter, 0, label, 1, newline_type, -1);
if (newline_type == XED_DOCUMENT_NEWLINE_TYPE_DEFAULT) if (newline_type == XED_DOCUMENT_NEWLINE_TYPE_DEFAULT)
{ {
gtk_combo_box_set_active_iter (combo, iter); gtk_combo_box_set_active_iter (combo, iter);
} }
} }
static void static void
create_newline_combo (XedFileChooserDialog *dialog) create_newline_combo (XedFileChooserDialog *dialog)
{ {
GtkWidget *label, *combo; GtkWidget *label, *combo;
GtkListStore *store; GtkListStore *store;
GtkCellRenderer *renderer; GtkCellRenderer *renderer;
GtkTreeIter iter; GtkTreeIter iter;
label = gtk_label_new_with_mnemonic (_("L_ine Ending:")); label = gtk_label_new_with_mnemonic (_("L_ine Ending:"));
gtk_widget_set_halign (label, GTK_ALIGN_START); gtk_widget_set_halign (label, GTK_ALIGN_START);
store = gtk_list_store_new (2, G_TYPE_STRING, XED_TYPE_DOCUMENT_NEWLINE_TYPE); store = gtk_list_store_new (2, G_TYPE_STRING, XED_TYPE_DOCUMENT_NEWLINE_TYPE);
combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store)); combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
renderer = gtk_cell_renderer_text_new (); renderer = gtk_cell_renderer_text_new ();
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE);
renderer,
TRUE);
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo), gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo), renderer, "text", 0);
renderer,
"text",
0);
newline_combo_append (GTK_COMBO_BOX (combo), newline_combo_append (GTK_COMBO_BOX (combo), store, &iter, _("Unix/Linux"), XED_DOCUMENT_NEWLINE_TYPE_LF);
store, newline_combo_append (GTK_COMBO_BOX (combo), store, &iter, _("Mac OS Classic"), XED_DOCUMENT_NEWLINE_TYPE_CR);
&iter, newline_combo_append (GTK_COMBO_BOX (combo), store, &iter, _("Windows"), XED_DOCUMENT_NEWLINE_TYPE_CR_LF);
_("Unix/Linux"),
XED_DOCUMENT_NEWLINE_TYPE_LF);
newline_combo_append (GTK_COMBO_BOX (combo), gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
store,
&iter,
_("Mac OS Classic"),
XED_DOCUMENT_NEWLINE_TYPE_CR);
newline_combo_append (GTK_COMBO_BOX (combo), gtk_box_pack_start (GTK_BOX (dialog->priv->extra_widget), label, FALSE, TRUE, 0);
store, gtk_box_pack_start (GTK_BOX (dialog->priv->extra_widget), combo, TRUE, TRUE, 0);
&iter,
_("Windows"),
XED_DOCUMENT_NEWLINE_TYPE_CR_LF);
gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo); dialog->priv->newline_combo = combo;
dialog->priv->newline_label = label;
dialog->priv->newline_store = store;
gtk_box_pack_start (GTK_BOX (dialog->priv->extra_widget), update_newline_visibility (dialog);
label,
FALSE,
TRUE,
0);
gtk_box_pack_start (GTK_BOX (dialog->priv->extra_widget),
combo,
TRUE,
TRUE,
0);
dialog->priv->newline_combo = combo;
dialog->priv->newline_label = label;
dialog->priv->newline_store = store;
update_newline_visibility (dialog);
} }
static void static void
create_extra_widget (XedFileChooserDialog *dialog) create_extra_widget (XedFileChooserDialog *dialog)
{ {
dialog->priv->extra_widget = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6); dialog->priv->extra_widget = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 6);
gtk_widget_show (dialog->priv->extra_widget); gtk_widget_show (dialog->priv->extra_widget);
create_option_menu (dialog); create_option_menu (dialog);
create_newline_combo (dialog); create_newline_combo (dialog);
gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (dialog), gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (dialog), dialog->priv->extra_widget);
dialog->priv->extra_widget);
} }
static void static void
action_changed (XedFileChooserDialog *dialog, action_changed (XedFileChooserDialog *dialog,
GParamSpec *pspec, GParamSpec *pspec,
gpointer data) gpointer data)
{ {
GtkFileChooserAction action; GtkFileChooserAction action;
action = gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)); action = gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog));
switch (action) switch (action)
{ {
case GTK_FILE_CHOOSER_ACTION_OPEN: case GTK_FILE_CHOOSER_ACTION_OPEN:
g_object_set (dialog->priv->option_menu, g_object_set (dialog->priv->option_menu, "save_mode", FALSE, NULL);
"save_mode", FALSE, gtk_widget_show (dialog->priv->option_menu);
NULL); break;
gtk_widget_show (dialog->priv->option_menu); case GTK_FILE_CHOOSER_ACTION_SAVE:
break; g_object_set (dialog->priv->option_menu, "save_mode", TRUE, NULL);
case GTK_FILE_CHOOSER_ACTION_SAVE: gtk_widget_show (dialog->priv->option_menu);
g_object_set (dialog->priv->option_menu, break;
"save_mode", TRUE, default:
NULL); gtk_widget_hide (dialog->priv->option_menu);
gtk_widget_show (dialog->priv->option_menu); }
break;
default:
gtk_widget_hide (dialog->priv->option_menu);
}
update_newline_visibility (dialog); update_newline_visibility (dialog);
} }
static void static void
filter_changed (XedFileChooserDialog *dialog, filter_changed (XedFileChooserDialog *dialog,
GParamSpec *pspec, GParamSpec *pspec,
gpointer data) gpointer data)
{ {
GtkFileFilter *filter; GtkFileFilter *filter;
if (!xed_prefs_manager_active_file_filter_can_set ()) if (!xed_prefs_manager_active_file_filter_can_set ())
return; {
return;
}
filter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (dialog)); filter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (dialog));
if (filter != NULL) if (filter != NULL)
{ {
const gchar *name; const gchar *name;
gint id = 0; gint id = 0;
name = gtk_file_filter_get_name (filter); name = gtk_file_filter_get_name (filter);
g_return_if_fail (name != NULL); g_return_if_fail (name != NULL);
if (strcmp (name, ALL_TEXT_FILES) == 0) if (strcmp (name, ALL_TEXT_FILES) == 0)
id = 1; {
id = 1;
}
xed_debug_message (DEBUG_COMMANDS, "Active filter: %s (%d)", name, id); xed_debug_message (DEBUG_COMMANDS, "Active filter: %s (%d)", name, id);
xed_prefs_manager_set_active_file_filter (id); xed_prefs_manager_set_active_file_filter (id);
} }
} }
/* FIXME: use globs too - Paolo (Aug. 27, 2007) */ /* FIXME: use globs too - Paolo (Aug. 27, 2007) */
static gboolean static gboolean
all_text_files_filter (const GtkFileFilterInfo *filter_info, all_text_files_filter (const GtkFileFilterInfo *filter_info,
gpointer data) gpointer data)
{ {
static GSList *known_mime_types = NULL; static GSList *known_mime_types = NULL;
GSList *mime_types; GSList *mime_types;
if (known_mime_types == NULL) if (known_mime_types == NULL)
{ {
GtkSourceLanguageManager *lm; GtkSourceLanguageManager *lm;
const gchar * const *languages; const gchar * const *languages;
lm = xed_get_language_manager (); lm = xed_get_language_manager ();
languages = gtk_source_language_manager_get_language_ids (lm); languages = gtk_source_language_manager_get_language_ids (lm);
while ((languages != NULL) && (*languages != NULL)) while ((languages != NULL) && (*languages != NULL))
{ {
gchar **mime_types; gchar **mime_types;
gint i; gint i;
GtkSourceLanguage *lang; GtkSourceLanguage *lang;
lang = gtk_source_language_manager_get_language (lm, *languages); lang = gtk_source_language_manager_get_language (lm, *languages);
g_return_val_if_fail (GTK_SOURCE_IS_LANGUAGE (lang), FALSE); g_return_val_if_fail (GTK_SOURCE_IS_LANGUAGE (lang), FALSE);
++languages; ++languages;
mime_types = gtk_source_language_get_mime_types (lang); mime_types = gtk_source_language_get_mime_types (lang);
if (mime_types == NULL) if (mime_types == NULL)
continue; {
continue;
}
for (i = 0; mime_types[i] != NULL; i++) for (i = 0; mime_types[i] != NULL; i++)
{ {
if (!g_content_type_is_a (mime_types[i], "text/plain")) if (!g_content_type_is_a (mime_types[i], "text/plain"))
{ {
xed_debug_message (DEBUG_COMMANDS, xed_debug_message (DEBUG_COMMANDS,
"Mime-type %s is not related to text/plain", "Mime-type %s is not related to text/plain",
mime_types[i]); mime_types[i]);
known_mime_types = g_slist_prepend (known_mime_types, known_mime_types = g_slist_prepend (known_mime_types, g_strdup (mime_types[i]));
g_strdup (mime_types[i])); }
} }
}
g_strfreev (mime_types); g_strfreev (mime_types);
} }
/* known_mime_types always has "text/plain" as first item" */ /* known_mime_types always has "text/plain" as first item" */
known_mime_types = g_slist_prepend (known_mime_types, g_strdup ("text/plain")); known_mime_types = g_slist_prepend (known_mime_types, g_strdup ("text/plain"));
} }
/* known mime_types contains "text/plain" and then the list of mime-types unrelated to "text/plain" /* known mime_types contains "text/plain" and then the list of mime-types unrelated to "text/plain"
* that xed recognizes */ * that xed recognizes */
if (filter_info->mime_type == NULL) if (filter_info->mime_type == NULL)
return FALSE; {
return FALSE;
}
/* /*
* The filter is matching: * The filter is matching:
* - the mime-types beginning with "text/" * - the mime-types beginning with "text/"
* - the mime-types inheriting from a known mime-type (note the text/plain is * - the mime-types inheriting from a known mime-type (note the text/plain is
* the first known mime-type) * the first known mime-type)
*/ */
if (strncmp (filter_info->mime_type, "text/", 5) == 0) if (strncmp (filter_info->mime_type, "text/", 5) == 0)
return TRUE; {
return TRUE;
}
mime_types = known_mime_types; mime_types = known_mime_types;
while (mime_types != NULL) while (mime_types != NULL)
{ {
if (g_content_type_is_a (filter_info->mime_type, (const gchar*)mime_types->data)) if (g_content_type_is_a (filter_info->mime_type, (const gchar*)mime_types->data))
return TRUE; {
return TRUE;
}
mime_types = g_slist_next (mime_types); mime_types = g_slist_next (mime_types);
} }
return FALSE; return FALSE;
} }
static void static void
xed_file_chooser_dialog_init (XedFileChooserDialog *dialog) xed_file_chooser_dialog_init (XedFileChooserDialog *dialog)
{ {
dialog->priv = XED_FILE_CHOOSER_DIALOG_GET_PRIVATE (dialog); dialog->priv = XED_FILE_CHOOSER_DIALOG_GET_PRIVATE (dialog);
} }
static GtkWidget * static GtkWidget *
xed_file_chooser_dialog_new_valist (const gchar *title, xed_file_chooser_dialog_new_valist (const gchar *title,
GtkWindow *parent, GtkWindow *parent,
GtkFileChooserAction action, GtkFileChooserAction action,
const XedEncoding *encoding, const XedEncoding *encoding,
const gchar *first_button_text, const gchar *first_button_text,
va_list varargs) va_list varargs)
{ {
GtkWidget *result; GtkWidget *result;
const char *button_text = first_button_text; const char *button_text = first_button_text;
gint response_id; gint response_id;
GtkFileFilter *filter; GtkFileFilter *filter;
gint active_filter; gint active_filter;
g_return_val_if_fail (parent != NULL, NULL); g_return_val_if_fail (parent != NULL, NULL);
result = g_object_new (XED_TYPE_FILE_CHOOSER_DIALOG, result = g_object_new (XED_TYPE_FILE_CHOOSER_DIALOG,
"title", title, "title", title,
"local-only", FALSE, "local-only", FALSE,
"action", action, "action", action,
"select-multiple", action == GTK_FILE_CHOOSER_ACTION_OPEN, "select-multiple", action == GTK_FILE_CHOOSER_ACTION_OPEN,
NULL); NULL);
create_extra_widget (XED_FILE_CHOOSER_DIALOG (result)); create_extra_widget (XED_FILE_CHOOSER_DIALOG (result));
g_signal_connect (result, g_signal_connect (result, "notify::action",
"notify::action", G_CALLBACK (action_changed), NULL);
G_CALLBACK (action_changed),
NULL);
if (encoding != NULL) if (encoding != NULL)
xed_encodings_combo_box_set_selected_encoding ( {
XED_ENCODINGS_COMBO_BOX (XED_FILE_CHOOSER_DIALOG (result)->priv->option_menu), xed_encodings_combo_box_set_selected_encoding (
encoding); XED_ENCODINGS_COMBO_BOX (XED_FILE_CHOOSER_DIALOG (result)->priv->option_menu), encoding);
}
active_filter = xed_prefs_manager_get_active_file_filter (); active_filter = xed_prefs_manager_get_active_file_filter ();
xed_debug_message (DEBUG_COMMANDS, "Active filter: %d", active_filter); xed_debug_message (DEBUG_COMMANDS, "Active filter: %d", active_filter);
/* Filters */ /* Filters */
filter = gtk_file_filter_new (); filter = gtk_file_filter_new ();
gtk_file_filter_set_name (filter, ALL_FILES); gtk_file_filter_set_name (filter, ALL_FILES);
gtk_file_filter_add_pattern (filter, "*"); gtk_file_filter_add_pattern (filter, "*");
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (result), filter); gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (result), filter);
gtk_file_chooser_set_action (GTK_FILE_CHOOSER (result), action); gtk_file_chooser_set_action (GTK_FILE_CHOOSER (result), action);
if (active_filter != 1) if (active_filter != 1)
{ {
/* Make this filter the default */ /* Make this filter the default */
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (result), filter); gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (result), filter);
} }
filter = gtk_file_filter_new (); filter = gtk_file_filter_new ();
gtk_file_filter_set_name (filter, ALL_TEXT_FILES); gtk_file_filter_set_name (filter, ALL_TEXT_FILES);
gtk_file_filter_add_custom (filter, gtk_file_filter_add_custom (filter, GTK_FILE_FILTER_MIME_TYPE, all_text_files_filter, NULL, NULL);
GTK_FILE_FILTER_MIME_TYPE, gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (result), filter);
all_text_files_filter,
NULL,
NULL);
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (result), filter);
if (active_filter == 1) if (active_filter == 1)
{ {
/* Make this filter the default */ /* Make this filter the default */
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (result), filter); gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (result), filter);
} }
g_signal_connect (result, g_signal_connect (result, "notify::filter",
"notify::filter", G_CALLBACK (filter_changed), NULL);
G_CALLBACK (filter_changed),
NULL);
gtk_window_set_transient_for (GTK_WINDOW (result), parent); gtk_window_set_transient_for (GTK_WINDOW (result), parent);
gtk_window_set_destroy_with_parent (GTK_WINDOW (result), TRUE); gtk_window_set_destroy_with_parent (GTK_WINDOW (result), TRUE);
while (button_text) while (button_text)
{ {
response_id = va_arg (varargs, gint); response_id = va_arg (varargs, gint);
gtk_dialog_add_button (GTK_DIALOG (result), button_text, response_id); gtk_dialog_add_button (GTK_DIALOG (result), button_text, response_id);
if ((response_id == GTK_RESPONSE_OK) || if ((response_id == GTK_RESPONSE_OK) ||
(response_id == GTK_RESPONSE_ACCEPT) || (response_id == GTK_RESPONSE_ACCEPT) ||
(response_id == GTK_RESPONSE_YES) || (response_id == GTK_RESPONSE_YES) ||
(response_id == GTK_RESPONSE_APPLY)) (response_id == GTK_RESPONSE_APPLY))
gtk_dialog_set_default_response (GTK_DIALOG (result), response_id); {
gtk_dialog_set_default_response (GTK_DIALOG (result), response_id);
}
button_text = va_arg (varargs, const gchar *); button_text = va_arg (varargs, const gchar *);
} }
return result; return result;
} }
/** /**
@ -466,98 +430,87 @@ xed_file_chooser_dialog_new_valist (const gchar *title,
**/ **/
GtkWidget * GtkWidget *
xed_file_chooser_dialog_new (const gchar *title, xed_file_chooser_dialog_new (const gchar *title,
GtkWindow *parent, GtkWindow *parent,
GtkFileChooserAction action, GtkFileChooserAction action,
const XedEncoding *encoding, const XedEncoding *encoding,
const gchar *first_button_text, const gchar *first_button_text,
...) ...)
{ {
GtkWidget *result; GtkWidget *result;
va_list varargs; va_list varargs;
va_start (varargs, first_button_text); va_start (varargs, first_button_text);
result = xed_file_chooser_dialog_new_valist (title, parent, action, result = xed_file_chooser_dialog_new_valist (title, parent, action, encoding, first_button_text, varargs);
encoding, first_button_text, va_end (varargs);
varargs);
va_end (varargs);
return result; return result;
} }
void void
xed_file_chooser_dialog_set_encoding (XedFileChooserDialog *dialog, xed_file_chooser_dialog_set_encoding (XedFileChooserDialog *dialog,
const XedEncoding *encoding) const XedEncoding *encoding)
{ {
g_return_if_fail (XED_IS_FILE_CHOOSER_DIALOG (dialog)); g_return_if_fail (XED_IS_FILE_CHOOSER_DIALOG (dialog));
g_return_if_fail (XED_IS_ENCODINGS_COMBO_BOX (dialog->priv->option_menu)); g_return_if_fail (XED_IS_ENCODINGS_COMBO_BOX (dialog->priv->option_menu));
xed_encodings_combo_box_set_selected_encoding ( xed_encodings_combo_box_set_selected_encoding (XED_ENCODINGS_COMBO_BOX (dialog->priv->option_menu), encoding);
XED_ENCODINGS_COMBO_BOX (dialog->priv->option_menu),
encoding);
} }
const XedEncoding * const XedEncoding *
xed_file_chooser_dialog_get_encoding (XedFileChooserDialog *dialog) xed_file_chooser_dialog_get_encoding (XedFileChooserDialog *dialog)
{ {
g_return_val_if_fail (XED_IS_FILE_CHOOSER_DIALOG (dialog), NULL); g_return_val_if_fail (XED_IS_FILE_CHOOSER_DIALOG (dialog), NULL);
g_return_val_if_fail (XED_IS_ENCODINGS_COMBO_BOX (dialog->priv->option_menu), NULL); g_return_val_if_fail (XED_IS_ENCODINGS_COMBO_BOX (dialog->priv->option_menu), NULL);
g_return_val_if_fail ((gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)) == GTK_FILE_CHOOSER_ACTION_OPEN || g_return_val_if_fail ((gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)) == GTK_FILE_CHOOSER_ACTION_OPEN ||
gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)) == GTK_FILE_CHOOSER_ACTION_SAVE), NULL); gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)) == GTK_FILE_CHOOSER_ACTION_SAVE), NULL);
return xed_encodings_combo_box_get_selected_encoding ( return xed_encodings_combo_box_get_selected_encoding (XED_ENCODINGS_COMBO_BOX (dialog->priv->option_menu));
XED_ENCODINGS_COMBO_BOX (dialog->priv->option_menu));
} }
void void
xed_file_chooser_dialog_set_newline_type (XedFileChooserDialog *dialog, xed_file_chooser_dialog_set_newline_type (XedFileChooserDialog *dialog,
XedDocumentNewlineType newline_type) XedDocumentNewlineType newline_type)
{ {
GtkTreeIter iter; GtkTreeIter iter;
GtkTreeModel *model; GtkTreeModel *model;
g_return_if_fail (XED_IS_FILE_CHOOSER_DIALOG (dialog)); g_return_if_fail (XED_IS_FILE_CHOOSER_DIALOG (dialog));
g_return_if_fail (gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)) == GTK_FILE_CHOOSER_ACTION_SAVE); g_return_if_fail (gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)) == GTK_FILE_CHOOSER_ACTION_SAVE);
model = GTK_TREE_MODEL (dialog->priv->newline_store); model = GTK_TREE_MODEL (dialog->priv->newline_store);
if (!gtk_tree_model_get_iter_first (model, &iter)) if (!gtk_tree_model_get_iter_first (model, &iter))
{ {
return; return;
} }
do do
{ {
XedDocumentNewlineType nt; XedDocumentNewlineType nt;
gtk_tree_model_get (model, &iter, 1, &nt, -1); gtk_tree_model_get (model, &iter, 1, &nt, -1);
if (newline_type == nt) if (newline_type == nt)
{ {
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (dialog->priv->newline_combo), gtk_combo_box_set_active_iter (GTK_COMBO_BOX (dialog->priv->newline_combo), &iter);
&iter); break;
break; }
} } while (gtk_tree_model_iter_next (model, &iter));
} while (gtk_tree_model_iter_next (model, &iter));
} }
XedDocumentNewlineType XedDocumentNewlineType
xed_file_chooser_dialog_get_newline_type (XedFileChooserDialog *dialog) xed_file_chooser_dialog_get_newline_type (XedFileChooserDialog *dialog)
{ {
GtkTreeIter iter; GtkTreeIter iter;
XedDocumentNewlineType newline_type; XedDocumentNewlineType newline_type;
g_return_val_if_fail (XED_IS_FILE_CHOOSER_DIALOG (dialog), XED_DOCUMENT_NEWLINE_TYPE_DEFAULT); g_return_val_if_fail (XED_IS_FILE_CHOOSER_DIALOG (dialog), XED_DOCUMENT_NEWLINE_TYPE_DEFAULT);
g_return_val_if_fail (gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)) == GTK_FILE_CHOOSER_ACTION_SAVE, g_return_val_if_fail (gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)) == GTK_FILE_CHOOSER_ACTION_SAVE,
XED_DOCUMENT_NEWLINE_TYPE_DEFAULT); XED_DOCUMENT_NEWLINE_TYPE_DEFAULT);
gtk_combo_box_get_active_iter (GTK_COMBO_BOX (dialog->priv->newline_combo), gtk_combo_box_get_active_iter (GTK_COMBO_BOX (dialog->priv->newline_combo), &iter);
&iter);
gtk_tree_model_get (GTK_TREE_MODEL (dialog->priv->newline_store), gtk_tree_model_get (GTK_TREE_MODEL (dialog->priv->newline_store), &iter, 1, &newline_type, -1);
&iter,
1,
&newline_type,
-1);
return newline_type; return newline_type;
} }

View File

@ -2,7 +2,7 @@
* xed-file-chooser-dialog.h * xed-file-chooser-dialog.h
* This file is part of xed * This file is part of xed
* *
* Copyright (C) 2005 - Paolo Maggi * Copyright (C) 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, 2005. See the AUTHORS file for a * Modified by the xed Team, 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$
*/ */
@ -46,43 +46,40 @@ G_BEGIN_DECLS
#define XED_IS_FILE_CHOOSER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_FILE_CHOOSER_DIALOG)) #define XED_IS_FILE_CHOOSER_DIALOG_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), XED_TYPE_FILE_CHOOSER_DIALOG))
#define XED_FILE_CHOOSER_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XED_TYPE_FILE_CHOOSER_DIALOG, XedFileChooserDialogClass)) #define XED_FILE_CHOOSER_DIALOG_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), XED_TYPE_FILE_CHOOSER_DIALOG, XedFileChooserDialogClass))
typedef struct _XedFileChooserDialog XedFileChooserDialog; typedef struct _XedFileChooserDialog XedFileChooserDialog;
typedef struct _XedFileChooserDialogClass XedFileChooserDialogClass;
typedef struct _XedFileChooserDialogPrivate XedFileChooserDialogPrivate; typedef struct _XedFileChooserDialogPrivate XedFileChooserDialogPrivate;
typedef struct _XedFileChooserDialogClass XedFileChooserDialogClass;
struct _XedFileChooserDialogClass
{
GtkFileChooserDialogClass parent_class;
};
struct _XedFileChooserDialog struct _XedFileChooserDialog
{ {
GtkFileChooserDialog parent_instance; GtkFileChooserDialog parent_instance;
XedFileChooserDialogPrivate *priv; XedFileChooserDialogPrivate *priv;
}; };
GType xed_file_chooser_dialog_get_type (void) G_GNUC_CONST; struct _XedFileChooserDialogClass
{
GtkFileChooserDialogClass parent_class;
};
GtkWidget *xed_file_chooser_dialog_new (const gchar *title, GType xed_file_chooser_dialog_get_type (void) G_GNUC_CONST;
GtkWindow *parent,
GtkFileChooserAction action,
const XedEncoding *encoding,
const gchar *first_button_text,
...);
void xed_file_chooser_dialog_set_encoding (XedFileChooserDialog *dialog, GtkWidget *xed_file_chooser_dialog_new (const gchar *title,
const XedEncoding *encoding); GtkWindow *parent,
GtkFileChooserAction action,
const XedEncoding *encoding,
const gchar *first_button_text,
...);
const XedEncoding void xed_file_chooser_dialog_set_encoding (XedFileChooserDialog *dialog,
*xed_file_chooser_dialog_get_encoding (XedFileChooserDialog *dialog); const XedEncoding *encoding);
void xed_file_chooser_dialog_set_newline_type (XedFileChooserDialog *dialog, const XedEncoding *xed_file_chooser_dialog_get_encoding (XedFileChooserDialog *dialog);
XedDocumentNewlineType newline_type);
XedDocumentNewlineType void xed_file_chooser_dialog_set_newline_type (XedFileChooserDialog *dialog,
xed_file_chooser_dialog_get_newline_type (XedFileChooserDialog *dialog); XedDocumentNewlineType newline_type);
XedDocumentNewlineType xed_file_chooser_dialog_get_newline_type (XedFileChooserDialog *dialog);
G_END_DECLS G_END_DECLS