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_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),
|
|
||||||
menu,
|
|
||||||
TRUE,
|
|
||||||
TRUE,
|
|
||||||
0);
|
|
||||||
|
|
||||||
gtk_widget_show (label);
|
gtk_widget_show (label);
|
||||||
gtk_widget_show (menu);
|
gtk_widget_show (menu);
|
||||||
|
@ -151,46 +142,18 @@ create_newline_combo (XedFileChooserDialog *dialog)
|
||||||
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),
|
|
||||||
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_label_set_mnemonic_widget (GTK_LABEL (label), combo);
|
||||||
|
|
||||||
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), combo, TRUE, TRUE, 0);
|
||||||
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_combo = combo;
|
||||||
dialog->priv->newline_label = label;
|
dialog->priv->newline_label = label;
|
||||||
|
@ -209,8 +172,7 @@ create_extra_widget (XedFileChooserDialog *dialog)
|
||||||
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);
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -226,15 +188,11 @@ action_changed (XedFileChooserDialog *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,
|
|
||||||
NULL);
|
|
||||||
gtk_widget_show (dialog->priv->option_menu);
|
gtk_widget_show (dialog->priv->option_menu);
|
||||||
break;
|
break;
|
||||||
case GTK_FILE_CHOOSER_ACTION_SAVE:
|
case GTK_FILE_CHOOSER_ACTION_SAVE:
|
||||||
g_object_set (dialog->priv->option_menu,
|
g_object_set (dialog->priv->option_menu, "save_mode", TRUE, NULL);
|
||||||
"save_mode", TRUE,
|
|
||||||
NULL);
|
|
||||||
gtk_widget_show (dialog->priv->option_menu);
|
gtk_widget_show (dialog->priv->option_menu);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -252,7 +210,9 @@ filter_changed (XedFileChooserDialog *dialog,
|
||||||
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)
|
||||||
|
@ -264,7 +224,9 @@ filter_changed (XedFileChooserDialog *dialog,
|
||||||
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);
|
||||||
|
|
||||||
|
@ -300,7 +262,9 @@ all_text_files_filter (const GtkFileFilterInfo *filter_info,
|
||||||
|
|
||||||
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++)
|
||||||
{
|
{
|
||||||
|
@ -310,8 +274,7 @@ all_text_files_filter (const GtkFileFilterInfo *filter_info,
|
||||||
"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]));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -326,7 +289,9 @@ all_text_files_filter (const GtkFileFilterInfo *filter_info,
|
||||||
* 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:
|
||||||
|
@ -336,13 +301,17 @@ all_text_files_filter (const GtkFileFilterInfo *filter_info,
|
||||||
*/
|
*/
|
||||||
|
|
||||||
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);
|
||||||
}
|
}
|
||||||
|
@ -381,15 +350,14 @@ xed_file_chooser_dialog_new_valist (const gchar *title,
|
||||||
|
|
||||||
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_set_selected_encoding (
|
||||||
XED_ENCODINGS_COMBO_BOX (XED_FILE_CHOOSER_DIALOG (result)->priv->option_menu),
|
XED_ENCODINGS_COMBO_BOX (XED_FILE_CHOOSER_DIALOG (result)->priv->option_menu), encoding);
|
||||||
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);
|
||||||
|
@ -410,11 +378,7 @@ xed_file_chooser_dialog_new_valist (const gchar *title,
|
||||||
|
|
||||||
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,
|
|
||||||
all_text_files_filter,
|
|
||||||
NULL,
|
|
||||||
NULL);
|
|
||||||
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (result), filter);
|
gtk_file_chooser_add_filter (GTK_FILE_CHOOSER (result), filter);
|
||||||
|
|
||||||
if (active_filter == 1)
|
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);
|
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);
|
||||||
|
@ -440,7 +402,9 @@ xed_file_chooser_dialog_new_valist (const gchar *title,
|
||||||
(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 *);
|
||||||
}
|
}
|
||||||
|
@ -476,9 +440,7 @@ xed_file_chooser_dialog_new (const gchar *title,
|
||||||
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,
|
|
||||||
varargs);
|
|
||||||
va_end (varargs);
|
va_end (varargs);
|
||||||
|
|
||||||
return result;
|
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_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 *
|
||||||
|
@ -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 ||
|
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
|
||||||
|
@ -533,8 +492,7 @@ xed_file_chooser_dialog_set_newline_type (XedFileChooserDialog *dialog,
|
||||||
|
|
||||||
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));
|
||||||
|
@ -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,
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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))
|
#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
|
||||||
{
|
{
|
||||||
|
@ -63,6 +57,11 @@ struct _XedFileChooserDialog
|
||||||
XedFileChooserDialogPrivate *priv;
|
XedFileChooserDialogPrivate *priv;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct _XedFileChooserDialogClass
|
||||||
|
{
|
||||||
|
GtkFileChooserDialogClass parent_class;
|
||||||
|
};
|
||||||
|
|
||||||
GType xed_file_chooser_dialog_get_type (void) G_GNUC_CONST;
|
GType xed_file_chooser_dialog_get_type (void) G_GNUC_CONST;
|
||||||
|
|
||||||
GtkWidget *xed_file_chooser_dialog_new (const gchar *title,
|
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,
|
void xed_file_chooser_dialog_set_encoding (XedFileChooserDialog *dialog,
|
||||||
const XedEncoding *encoding);
|
const XedEncoding *encoding);
|
||||||
|
|
||||||
const XedEncoding
|
const XedEncoding *xed_file_chooser_dialog_get_encoding (XedFileChooserDialog *dialog);
|
||||||
*xed_file_chooser_dialog_get_encoding (XedFileChooserDialog *dialog);
|
|
||||||
|
|
||||||
void xed_file_chooser_dialog_set_newline_type (XedFileChooserDialog *dialog,
|
void xed_file_chooser_dialog_set_newline_type (XedFileChooserDialog *dialog,
|
||||||
XedDocumentNewlineType newline_type);
|
XedDocumentNewlineType newline_type);
|
||||||
|
|
||||||
XedDocumentNewlineType
|
XedDocumentNewlineType xed_file_chooser_dialog_get_newline_type (XedFileChooserDialog *dialog);
|
||||||
xed_file_chooser_dialog_get_newline_type (XedFileChooserDialog *dialog);
|
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue