xed-file-dialog.c/h: Clean up code styling
This commit is contained in:
parent
66800ca9a3
commit
9dc61e0df5
|
@ -87,17 +87,8 @@ create_option_menu (XedFileChooserDialog *dialog)
|
|||
|
||||
gtk_label_set_mnemonic_widget (GTK_LABEL (label), menu);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (dialog->priv->extra_widget),
|
||||
label,
|
||||
FALSE,
|
||||
TRUE,
|
||||
0);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (dialog->priv->extra_widget),
|
||||
menu,
|
||||
TRUE,
|
||||
TRUE,
|
||||
0);
|
||||
gtk_box_pack_start (GTK_BOX (dialog->priv->extra_widget), label, FALSE, TRUE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (dialog->priv->extra_widget), menu, TRUE, TRUE, 0);
|
||||
|
||||
gtk_widget_show (label);
|
||||
gtk_widget_show (menu);
|
||||
|
@ -151,46 +142,18 @@ create_newline_combo (XedFileChooserDialog *dialog)
|
|||
combo = gtk_combo_box_new_with_model (GTK_TREE_MODEL (store));
|
||||
renderer = gtk_cell_renderer_text_new ();
|
||||
|
||||
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo),
|
||||
renderer,
|
||||
TRUE);
|
||||
gtk_cell_layout_pack_start (GTK_CELL_LAYOUT (combo), renderer, TRUE);
|
||||
|
||||
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo),
|
||||
renderer,
|
||||
"text",
|
||||
0);
|
||||
gtk_cell_layout_add_attribute (GTK_CELL_LAYOUT (combo), renderer, "text", 0);
|
||||
|
||||
newline_combo_append (GTK_COMBO_BOX (combo),
|
||||
store,
|
||||
&iter,
|
||||
_("Unix/Linux"),
|
||||
XED_DOCUMENT_NEWLINE_TYPE_LF);
|
||||
|
||||
newline_combo_append (GTK_COMBO_BOX (combo),
|
||||
store,
|
||||
&iter,
|
||||
_("Mac OS Classic"),
|
||||
XED_DOCUMENT_NEWLINE_TYPE_CR);
|
||||
|
||||
newline_combo_append (GTK_COMBO_BOX (combo),
|
||||
store,
|
||||
&iter,
|
||||
_("Windows"),
|
||||
XED_DOCUMENT_NEWLINE_TYPE_CR_LF);
|
||||
newline_combo_append (GTK_COMBO_BOX (combo), store, &iter, _("Unix/Linux"), XED_DOCUMENT_NEWLINE_TYPE_LF);
|
||||
newline_combo_append (GTK_COMBO_BOX (combo), store, &iter, _("Mac OS Classic"), XED_DOCUMENT_NEWLINE_TYPE_CR);
|
||||
newline_combo_append (GTK_COMBO_BOX (combo), store, &iter, _("Windows"), XED_DOCUMENT_NEWLINE_TYPE_CR_LF);
|
||||
|
||||
gtk_label_set_mnemonic_widget (GTK_LABEL (label), combo);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (dialog->priv->extra_widget),
|
||||
label,
|
||||
FALSE,
|
||||
TRUE,
|
||||
0);
|
||||
|
||||
gtk_box_pack_start (GTK_BOX (dialog->priv->extra_widget),
|
||||
combo,
|
||||
TRUE,
|
||||
TRUE,
|
||||
0);
|
||||
gtk_box_pack_start (GTK_BOX (dialog->priv->extra_widget), 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;
|
||||
|
@ -209,8 +172,7 @@ create_extra_widget (XedFileChooserDialog *dialog)
|
|||
create_option_menu (dialog);
|
||||
create_newline_combo (dialog);
|
||||
|
||||
gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (dialog),
|
||||
dialog->priv->extra_widget);
|
||||
gtk_file_chooser_set_extra_widget (GTK_FILE_CHOOSER (dialog), dialog->priv->extra_widget);
|
||||
|
||||
}
|
||||
|
||||
|
@ -226,15 +188,11 @@ action_changed (XedFileChooserDialog *dialog,
|
|||
switch (action)
|
||||
{
|
||||
case GTK_FILE_CHOOSER_ACTION_OPEN:
|
||||
g_object_set (dialog->priv->option_menu,
|
||||
"save_mode", FALSE,
|
||||
NULL);
|
||||
g_object_set (dialog->priv->option_menu, "save_mode", FALSE, NULL);
|
||||
gtk_widget_show (dialog->priv->option_menu);
|
||||
break;
|
||||
case GTK_FILE_CHOOSER_ACTION_SAVE:
|
||||
g_object_set (dialog->priv->option_menu,
|
||||
"save_mode", TRUE,
|
||||
NULL);
|
||||
g_object_set (dialog->priv->option_menu, "save_mode", TRUE, NULL);
|
||||
gtk_widget_show (dialog->priv->option_menu);
|
||||
break;
|
||||
default:
|
||||
|
@ -252,7 +210,9 @@ filter_changed (XedFileChooserDialog *dialog,
|
|||
GtkFileFilter *filter;
|
||||
|
||||
if (!xed_prefs_manager_active_file_filter_can_set ())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
filter = gtk_file_chooser_get_filter (GTK_FILE_CHOOSER (dialog));
|
||||
if (filter != NULL)
|
||||
|
@ -264,7 +224,9 @@ filter_changed (XedFileChooserDialog *dialog,
|
|||
g_return_if_fail (name != NULL);
|
||||
|
||||
if (strcmp (name, ALL_TEXT_FILES) == 0)
|
||||
{
|
||||
id = 1;
|
||||
}
|
||||
|
||||
xed_debug_message (DEBUG_COMMANDS, "Active filter: %s (%d)", name, id);
|
||||
|
||||
|
@ -300,7 +262,9 @@ all_text_files_filter (const GtkFileFilterInfo *filter_info,
|
|||
|
||||
mime_types = gtk_source_language_get_mime_types (lang);
|
||||
if (mime_types == NULL)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for (i = 0; mime_types[i] != NULL; i++)
|
||||
{
|
||||
|
@ -310,8 +274,7 @@ all_text_files_filter (const GtkFileFilterInfo *filter_info,
|
|||
"Mime-type %s is not related to text/plain",
|
||||
mime_types[i]);
|
||||
|
||||
known_mime_types = g_slist_prepend (known_mime_types,
|
||||
g_strdup (mime_types[i]));
|
||||
known_mime_types = g_slist_prepend (known_mime_types, g_strdup (mime_types[i]));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -326,7 +289,9 @@ all_text_files_filter (const GtkFileFilterInfo *filter_info,
|
|||
* that xed recognizes */
|
||||
|
||||
if (filter_info->mime_type == NULL)
|
||||
{
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* The filter is matching:
|
||||
|
@ -336,13 +301,17 @@ all_text_files_filter (const GtkFileFilterInfo *filter_info,
|
|||
*/
|
||||
|
||||
if (strncmp (filter_info->mime_type, "text/", 5) == 0)
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
mime_types = known_mime_types;
|
||||
while (mime_types != NULL)
|
||||
{
|
||||
if (g_content_type_is_a (filter_info->mime_type, (const gchar*)mime_types->data))
|
||||
{
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
mime_types = g_slist_next (mime_types);
|
||||
}
|
||||
|
@ -381,15 +350,14 @@ xed_file_chooser_dialog_new_valist (const gchar *title,
|
|||
|
||||
create_extra_widget (XED_FILE_CHOOSER_DIALOG (result));
|
||||
|
||||
g_signal_connect (result,
|
||||
"notify::action",
|
||||
G_CALLBACK (action_changed),
|
||||
NULL);
|
||||
g_signal_connect (result, "notify::action",
|
||||
G_CALLBACK (action_changed), NULL);
|
||||
|
||||
if (encoding != NULL)
|
||||
{
|
||||
xed_encodings_combo_box_set_selected_encoding (
|
||||
XED_ENCODINGS_COMBO_BOX (XED_FILE_CHOOSER_DIALOG (result)->priv->option_menu),
|
||||
encoding);
|
||||
XED_ENCODINGS_COMBO_BOX (XED_FILE_CHOOSER_DIALOG (result)->priv->option_menu), encoding);
|
||||
}
|
||||
|
||||
active_filter = xed_prefs_manager_get_active_file_filter ();
|
||||
xed_debug_message (DEBUG_COMMANDS, "Active filter: %d", active_filter);
|
||||
|
@ -410,11 +378,7 @@ xed_file_chooser_dialog_new_valist (const gchar *title,
|
|||
|
||||
filter = gtk_file_filter_new ();
|
||||
gtk_file_filter_set_name (filter, ALL_TEXT_FILES);
|
||||
gtk_file_filter_add_custom (filter,
|
||||
GTK_FILE_FILTER_MIME_TYPE,
|
||||
all_text_files_filter,
|
||||
NULL,
|
||||
NULL);
|
||||
gtk_file_filter_add_custom (filter, GTK_FILE_FILTER_MIME_TYPE, all_text_files_filter, NULL, NULL);
|
||||
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (result), filter);
|
||||
|
||||
if (active_filter == 1)
|
||||
|
@ -423,10 +387,8 @@ xed_file_chooser_dialog_new_valist (const gchar *title,
|
|||
gtk_file_chooser_set_filter (GTK_FILE_CHOOSER (result), filter);
|
||||
}
|
||||
|
||||
g_signal_connect (result,
|
||||
"notify::filter",
|
||||
G_CALLBACK (filter_changed),
|
||||
NULL);
|
||||
g_signal_connect (result, "notify::filter",
|
||||
G_CALLBACK (filter_changed), NULL);
|
||||
|
||||
gtk_window_set_transient_for (GTK_WINDOW (result), parent);
|
||||
gtk_window_set_destroy_with_parent (GTK_WINDOW (result), TRUE);
|
||||
|
@ -440,7 +402,9 @@ xed_file_chooser_dialog_new_valist (const gchar *title,
|
|||
(response_id == GTK_RESPONSE_ACCEPT) ||
|
||||
(response_id == GTK_RESPONSE_YES) ||
|
||||
(response_id == GTK_RESPONSE_APPLY))
|
||||
{
|
||||
gtk_dialog_set_default_response (GTK_DIALOG (result), response_id);
|
||||
}
|
||||
|
||||
button_text = va_arg (varargs, const gchar *);
|
||||
}
|
||||
|
@ -476,9 +440,7 @@ xed_file_chooser_dialog_new (const gchar *title,
|
|||
va_list varargs;
|
||||
|
||||
va_start (varargs, first_button_text);
|
||||
result = xed_file_chooser_dialog_new_valist (title, parent, action,
|
||||
encoding, first_button_text,
|
||||
varargs);
|
||||
result = xed_file_chooser_dialog_new_valist (title, parent, action, encoding, first_button_text, varargs);
|
||||
va_end (varargs);
|
||||
|
||||
return result;
|
||||
|
@ -491,9 +453,7 @@ xed_file_chooser_dialog_set_encoding (XedFileChooserDialog *dialog,
|
|||
g_return_if_fail (XED_IS_FILE_CHOOSER_DIALOG (dialog));
|
||||
g_return_if_fail (XED_IS_ENCODINGS_COMBO_BOX (dialog->priv->option_menu));
|
||||
|
||||
xed_encodings_combo_box_set_selected_encoding (
|
||||
XED_ENCODINGS_COMBO_BOX (dialog->priv->option_menu),
|
||||
encoding);
|
||||
xed_encodings_combo_box_set_selected_encoding (XED_ENCODINGS_COMBO_BOX (dialog->priv->option_menu), encoding);
|
||||
}
|
||||
|
||||
const XedEncoding *
|
||||
|
@ -504,8 +464,7 @@ xed_file_chooser_dialog_get_encoding (XedFileChooserDialog *dialog)
|
|||
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);
|
||||
|
||||
return xed_encodings_combo_box_get_selected_encoding (
|
||||
XED_ENCODINGS_COMBO_BOX (dialog->priv->option_menu));
|
||||
return xed_encodings_combo_box_get_selected_encoding (XED_ENCODINGS_COMBO_BOX (dialog->priv->option_menu));
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -533,8 +492,7 @@ xed_file_chooser_dialog_set_newline_type (XedFileChooserDialog *dialog,
|
|||
|
||||
if (newline_type == nt)
|
||||
{
|
||||
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (dialog->priv->newline_combo),
|
||||
&iter);
|
||||
gtk_combo_box_set_active_iter (GTK_COMBO_BOX (dialog->priv->newline_combo), &iter);
|
||||
break;
|
||||
}
|
||||
} while (gtk_tree_model_iter_next (model, &iter));
|
||||
|
@ -550,14 +508,9 @@ xed_file_chooser_dialog_get_newline_type (XedFileChooserDialog *dialog)
|
|||
g_return_val_if_fail (gtk_file_chooser_get_action (GTK_FILE_CHOOSER (dialog)) == GTK_FILE_CHOOSER_ACTION_SAVE,
|
||||
XED_DOCUMENT_NEWLINE_TYPE_DEFAULT);
|
||||
|
||||
gtk_combo_box_get_active_iter (GTK_COMBO_BOX (dialog->priv->newline_combo),
|
||||
&iter);
|
||||
gtk_combo_box_get_active_iter (GTK_COMBO_BOX (dialog->priv->newline_combo), &iter);
|
||||
|
||||
gtk_tree_model_get (GTK_TREE_MODEL (dialog->priv->newline_store),
|
||||
&iter,
|
||||
1,
|
||||
&newline_type,
|
||||
-1);
|
||||
gtk_tree_model_get (GTK_TREE_MODEL (dialog->priv->newline_store), &iter, 1, &newline_type, -1);
|
||||
|
||||
return newline_type;
|
||||
}
|
||||
|
|
|
@ -47,14 +47,8 @@ G_BEGIN_DECLS
|
|||
#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 _XedFileChooserDialogClass XedFileChooserDialogClass;
|
||||
|
||||
typedef struct _XedFileChooserDialogPrivate XedFileChooserDialogPrivate;
|
||||
|
||||
struct _XedFileChooserDialogClass
|
||||
{
|
||||
GtkFileChooserDialogClass parent_class;
|
||||
};
|
||||
typedef struct _XedFileChooserDialogClass XedFileChooserDialogClass;
|
||||
|
||||
struct _XedFileChooserDialog
|
||||
{
|
||||
|
@ -63,6 +57,11 @@ struct _XedFileChooserDialog
|
|||
XedFileChooserDialogPrivate *priv;
|
||||
};
|
||||
|
||||
struct _XedFileChooserDialogClass
|
||||
{
|
||||
GtkFileChooserDialogClass parent_class;
|
||||
};
|
||||
|
||||
GType xed_file_chooser_dialog_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GtkWidget *xed_file_chooser_dialog_new (const gchar *title,
|
||||
|
@ -75,14 +74,12 @@ GtkWidget *xed_file_chooser_dialog_new (const gchar *title,
|
|||
void xed_file_chooser_dialog_set_encoding (XedFileChooserDialog *dialog,
|
||||
const XedEncoding *encoding);
|
||||
|
||||
const XedEncoding
|
||||
*xed_file_chooser_dialog_get_encoding (XedFileChooserDialog *dialog);
|
||||
const XedEncoding *xed_file_chooser_dialog_get_encoding (XedFileChooserDialog *dialog);
|
||||
|
||||
void xed_file_chooser_dialog_set_newline_type (XedFileChooserDialog *dialog,
|
||||
XedDocumentNewlineType newline_type);
|
||||
|
||||
XedDocumentNewlineType
|
||||
xed_file_chooser_dialog_get_newline_type (XedFileChooserDialog *dialog);
|
||||
XedDocumentNewlineType xed_file_chooser_dialog_get_newline_type (XedFileChooserDialog *dialog);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
Loading…
Reference in New Issue