Add option to set a default encoding when opening files and disable auto detection of the file encoding.

git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@1641 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
Enrico Tröger 2007-06-26 15:41:27 +00:00
parent 22c3dd033b
commit 80918e9f03
7 changed files with 247 additions and 73 deletions

View File

@ -1,3 +1,11 @@
2007-06-26 Enrico Tröger <enrico.troeger@uvena.de>
* geany.glade, src/document.c, src/editor.h, src/interface.c,
src/keyfile.c, src/prefs.c:
Add option to set a default encoding when opening files and disable
auto detection of the file encoding.
2007-06-25 Enrico Tröger <enrico.troeger@uvena.de> 2007-06-25 Enrico Tröger <enrico.troeger@uvena.de>
* src/main.c: Use setlocale to enable translation of strings before * src/main.c: Use setlocale to enable translation of strings before

View File

@ -4970,12 +4970,65 @@ Bottom
<child> <child>
<widget class="GtkTable" id="table5"> <widget class="GtkTable" id="table5">
<property name="visible">True</property> <property name="visible">True</property>
<property name="n_rows">2</property> <property name="n_rows">4</property>
<property name="n_columns">2</property> <property name="n_columns">2</property>
<property name="homogeneous">False</property> <property name="homogeneous">False</property>
<property name="row_spacing">3</property> <property name="row_spacing">3</property>
<property name="column_spacing">25</property> <property name="column_spacing">25</property>
<child>
<widget class="GtkEventBox" id="eventbox1">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Sets the default encoding for newly created files.</property>
<property name="visible_window">True</property>
<property name="above_child">False</property>
<child>
<widget class="GtkComboBox" id="combo_new_encoding">
<property name="visible">True</property>
<property name="add_tearoffs">False</property>
<property name="focus_on_click">True</property>
</widget>
</child>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="x_options">fill</property>
<property name="y_options">fill</property>
</packing>
</child>
<child>
<widget class="GtkLabel" id="label153">
<property name="visible">True</property>
<property name="label" translatable="yes">Default encoding (new files):</property>
<property name="use_underline">False</property>
<property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property>
<property name="selectable">False</property>
<property name="xalign">0</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
<property name="ellipsize">PANGO_ELLIPSIZE_NONE</property>
<property name="width_chars">-1</property>
<property name="single_line_mode">False</property>
<property name="angle">0</property>
</widget>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">1</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="x_options">fill</property>
<property name="y_options"></property>
</packing>
</child>
<child> <child>
<widget class="GtkLabel" id="label116"> <widget class="GtkLabel" id="label116">
<property name="visible">True</property> <property name="visible">True</property>
@ -4997,38 +5050,13 @@ Bottom
<packing> <packing>
<property name="left_attach">0</property> <property name="left_attach">0</property>
<property name="right_attach">1</property> <property name="right_attach">1</property>
<property name="top_attach">1</property> <property name="top_attach">3</property>
<property name="bottom_attach">2</property> <property name="bottom_attach">4</property>
<property name="x_options">fill</property> <property name="x_options">fill</property>
<property name="y_options"></property> <property name="y_options"></property>
</packing> </packing>
</child> </child>
<child>
<widget class="GtkEventBox" id="eventbox1">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Sets the default encoding for newly created files.</property>
<property name="visible_window">True</property>
<property name="above_child">False</property>
<child>
<widget class="GtkComboBox" id="combo_encoding">
<property name="visible">True</property>
<property name="add_tearoffs">False</property>
<property name="focus_on_click">True</property>
</widget>
</child>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">0</property>
<property name="bottom_attach">1</property>
<property name="x_options">fill</property>
<property name="y_options">fill</property>
</packing>
</child>
<child> <child>
<widget class="GtkSpinButton" id="spin_tab_width"> <widget class="GtkSpinButton" id="spin_tab_width">
<property name="visible">True</property> <property name="visible">True</property>
@ -5045,23 +5073,22 @@ Bottom
<packing> <packing>
<property name="left_attach">1</property> <property name="left_attach">1</property>
<property name="right_attach">2</property> <property name="right_attach">2</property>
<property name="top_attach">1</property> <property name="top_attach">3</property>
<property name="bottom_attach">2</property> <property name="bottom_attach">4</property>
<property name="x_options">fill</property>
<property name="y_options"></property> <property name="y_options"></property>
</packing> </packing>
</child> </child>
<child> <child>
<widget class="GtkLabel" id="label153"> <widget class="GtkLabel" id="label_open_encoding">
<property name="visible">True</property> <property name="visible">True</property>
<property name="label" translatable="yes">Default encoding:</property> <property name="label" translatable="yes">Default encoding (existing files):</property>
<property name="use_underline">False</property> <property name="use_underline">False</property>
<property name="use_markup">False</property> <property name="use_markup">False</property>
<property name="justify">GTK_JUSTIFY_LEFT</property> <property name="justify">GTK_JUSTIFY_LEFT</property>
<property name="wrap">False</property> <property name="wrap">False</property>
<property name="selectable">False</property> <property name="selectable">False</property>
<property name="xalign">0.5</property> <property name="xalign">0</property>
<property name="yalign">0.5</property> <property name="yalign">0.5</property>
<property name="xpad">0</property> <property name="xpad">0</property>
<property name="ypad">0</property> <property name="ypad">0</property>
@ -5073,12 +5100,59 @@ Bottom
<packing> <packing>
<property name="left_attach">0</property> <property name="left_attach">0</property>
<property name="right_attach">1</property> <property name="right_attach">1</property>
<property name="top_attach">0</property> <property name="top_attach">2</property>
<property name="bottom_attach">1</property> <property name="bottom_attach">3</property>
<property name="x_options">fill</property> <property name="x_options">fill</property>
<property name="y_options"></property> <property name="y_options"></property>
</packing> </packing>
</child> </child>
<child>
<widget class="GtkCheckButton" id="check_open_encoding">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">This option disables the automatic detection of the file encoding when opening files and opens the file with the specified encoding (usually not needed).</property>
<property name="can_focus">True</property>
<property name="label" translatable="yes">Use fixed encoding when opening files</property>
<property name="use_underline">True</property>
<property name="relief">GTK_RELIEF_NORMAL</property>
<property name="focus_on_click">False</property>
<property name="active">False</property>
<property name="inconsistent">False</property>
<property name="draw_indicator">True</property>
</widget>
<packing>
<property name="left_attach">0</property>
<property name="right_attach">2</property>
<property name="top_attach">1</property>
<property name="bottom_attach">2</property>
<property name="y_options"></property>
</packing>
</child>
<child>
<widget class="GtkEventBox" id="eventbox3">
<property name="visible">True</property>
<property name="tooltip" translatable="yes">Sets the default encoding for opening existing files.</property>
<property name="visible_window">True</property>
<property name="above_child">False</property>
<child>
<widget class="GtkComboBox" id="combo_open_encoding">
<property name="visible">True</property>
<property name="add_tearoffs">False</property>
<property name="focus_on_click">True</property>
</widget>
</child>
</widget>
<packing>
<property name="left_attach">1</property>
<property name="right_attach">2</property>
<property name="top_attach">2</property>
<property name="bottom_attach">3</property>
<property name="x_options">fill</property>
<property name="y_options">fill</property>
</packing>
</child>
</widget> </widget>
<packing> <packing>
<property name="padding">0</property> <property name="padding">0</property>

View File

@ -442,7 +442,7 @@ gint document_new_file(const gchar *filename, filetype *ft)
sci_set_undo_collection(doc_list[idx].sci, TRUE); sci_set_undo_collection(doc_list[idx].sci, TRUE);
sci_empty_undo_buffer(doc_list[idx].sci); sci_empty_undo_buffer(doc_list[idx].sci);
doc_list[idx].encoding = g_strdup(encodings[editor_prefs.default_encoding].charset); doc_list[idx].encoding = g_strdup(encodings[editor_prefs.default_new_encoding].charset);
// store the opened encoding for undo/redo // store the opened encoding for undo/redo
store_saved_encoding(idx); store_saved_encoding(idx);
@ -783,6 +783,10 @@ gint document_open_file(gint idx, const gchar *filename, gint pos, gboolean read
} }
} }
// if default encoding for opening files is set, use it if no forced encoding is set
if (editor_prefs.default_open_encoding >= 0 && forced_enc == NULL)
forced_enc = encodings[editor_prefs.default_open_encoding].charset;
if (! load_text_file(locale_filename, utf8_filename, &filedata, forced_enc)) if (! load_text_file(locale_filename, utf8_filename, &filedata, forced_enc))
{ {
g_free(utf8_filename); g_free(utf8_filename);

View File

@ -61,7 +61,8 @@ typedef struct
gint tab_width; gint tab_width;
gint caret_blink_time; gint caret_blink_time;
gboolean use_tabs; gboolean use_tabs;
gint default_encoding; gint default_new_encoding;
gint default_open_encoding;
gboolean new_line; gboolean new_line;
gboolean replace_tabs; gboolean replace_tabs;
gboolean trail_space; gboolean trail_space;

View File

@ -2535,12 +2535,16 @@ create_prefs_dialog (void)
GtkWidget *alignment7; GtkWidget *alignment7;
GtkWidget *vbox8; GtkWidget *vbox8;
GtkWidget *table5; GtkWidget *table5;
GtkWidget *label116;
GtkWidget *eventbox1; GtkWidget *eventbox1;
GtkWidget *combo_encoding; GtkWidget *combo_new_encoding;
GtkWidget *label153;
GtkWidget *label116;
GtkObject *spin_tab_width_adj; GtkObject *spin_tab_width_adj;
GtkWidget *spin_tab_width; GtkWidget *spin_tab_width;
GtkWidget *label153; GtkWidget *label_open_encoding;
GtkWidget *check_open_encoding;
GtkWidget *eventbox3;
GtkWidget *combo_open_encoding;
GtkWidget *label109; GtkWidget *label109;
GtkWidget *frame2; GtkWidget *frame2;
GtkWidget *alignment3; GtkWidget *alignment3;
@ -3301,19 +3305,12 @@ create_prefs_dialog (void)
gtk_widget_show (vbox8); gtk_widget_show (vbox8);
gtk_container_add (GTK_CONTAINER (alignment7), vbox8); gtk_container_add (GTK_CONTAINER (alignment7), vbox8);
table5 = gtk_table_new (2, 2, FALSE); table5 = gtk_table_new (4, 2, FALSE);
gtk_widget_show (table5); gtk_widget_show (table5);
gtk_box_pack_start (GTK_BOX (vbox8), table5, FALSE, TRUE, 0); gtk_box_pack_start (GTK_BOX (vbox8), table5, FALSE, TRUE, 0);
gtk_table_set_row_spacings (GTK_TABLE (table5), 3); gtk_table_set_row_spacings (GTK_TABLE (table5), 3);
gtk_table_set_col_spacings (GTK_TABLE (table5), 25); gtk_table_set_col_spacings (GTK_TABLE (table5), 25);
label116 = gtk_label_new (_("Tab Width:"));
gtk_widget_show (label116);
gtk_table_attach (GTK_TABLE (table5), label116, 0, 1, 1, 2,
(GtkAttachOptions) (GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
gtk_misc_set_alignment (GTK_MISC (label116), 0, 0.5);
eventbox1 = gtk_event_box_new (); eventbox1 = gtk_event_box_new ();
gtk_widget_show (eventbox1); gtk_widget_show (eventbox1);
gtk_table_attach (GTK_TABLE (table5), eventbox1, 1, 2, 0, 1, gtk_table_attach (GTK_TABLE (table5), eventbox1, 1, 2, 0, 1,
@ -3321,26 +3318,60 @@ create_prefs_dialog (void)
(GtkAttachOptions) (GTK_FILL), 0, 0); (GtkAttachOptions) (GTK_FILL), 0, 0);
gtk_tooltips_set_tip (tooltips, eventbox1, _("Sets the default encoding for newly created files."), NULL); gtk_tooltips_set_tip (tooltips, eventbox1, _("Sets the default encoding for newly created files."), NULL);
combo_encoding = gtk_combo_box_new_text (); combo_new_encoding = gtk_combo_box_new_text ();
gtk_widget_show (combo_encoding); gtk_widget_show (combo_new_encoding);
gtk_container_add (GTK_CONTAINER (eventbox1), combo_encoding); gtk_container_add (GTK_CONTAINER (eventbox1), combo_new_encoding);
label153 = gtk_label_new (_("Default encoding (new files):"));
gtk_widget_show (label153);
gtk_table_attach (GTK_TABLE (table5), label153, 0, 1, 0, 1,
(GtkAttachOptions) (GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
gtk_misc_set_alignment (GTK_MISC (label153), 0, 0.5);
label116 = gtk_label_new (_("Tab Width:"));
gtk_widget_show (label116);
gtk_table_attach (GTK_TABLE (table5), label116, 0, 1, 3, 4,
(GtkAttachOptions) (GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
gtk_misc_set_alignment (GTK_MISC (label116), 0, 0.5);
spin_tab_width_adj = gtk_adjustment_new (-1, 1, 99, 1, 10, 10); spin_tab_width_adj = gtk_adjustment_new (-1, 1, 99, 1, 10, 10);
spin_tab_width = gtk_spin_button_new (GTK_ADJUSTMENT (spin_tab_width_adj), 1, 0); spin_tab_width = gtk_spin_button_new (GTK_ADJUSTMENT (spin_tab_width_adj), 1, 0);
gtk_widget_show (spin_tab_width); gtk_widget_show (spin_tab_width);
gtk_table_attach (GTK_TABLE (table5), spin_tab_width, 1, 2, 1, 2, gtk_table_attach (GTK_TABLE (table5), spin_tab_width, 1, 2, 3, 4,
(GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
(GtkAttachOptions) (0), 0, 0); (GtkAttachOptions) (0), 0, 0);
gtk_tooltips_set_tip (tooltips, spin_tab_width, _("The width in chars, which one tab character will take"), NULL); gtk_tooltips_set_tip (tooltips, spin_tab_width, _("The width in chars, which one tab character will take"), NULL);
gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spin_tab_width), TRUE); gtk_spin_button_set_numeric (GTK_SPIN_BUTTON (spin_tab_width), TRUE);
gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (spin_tab_width), GTK_UPDATE_IF_VALID); gtk_spin_button_set_update_policy (GTK_SPIN_BUTTON (spin_tab_width), GTK_UPDATE_IF_VALID);
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spin_tab_width), TRUE); gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spin_tab_width), TRUE);
label153 = gtk_label_new (_("Default encoding:")); label_open_encoding = gtk_label_new (_("Default encoding (existing files):"));
gtk_widget_show (label153); gtk_widget_show (label_open_encoding);
gtk_table_attach (GTK_TABLE (table5), label153, 0, 1, 0, 1, gtk_table_attach (GTK_TABLE (table5), label_open_encoding, 0, 1, 2, 3,
(GtkAttachOptions) (GTK_FILL), (GtkAttachOptions) (GTK_FILL),
(GtkAttachOptions) (0), 0, 0); (GtkAttachOptions) (0), 0, 0);
gtk_misc_set_alignment (GTK_MISC (label_open_encoding), 0, 0.5);
check_open_encoding = gtk_check_button_new_with_mnemonic (_("Use fixed encoding when opening files"));
gtk_widget_show (check_open_encoding);
gtk_table_attach (GTK_TABLE (table5), check_open_encoding, 0, 2, 1, 2,
(GtkAttachOptions) (GTK_EXPAND | GTK_FILL),
(GtkAttachOptions) (0), 0, 0);
gtk_tooltips_set_tip (tooltips, check_open_encoding, _("This option disables the automatic detection of the file encoding when opening files and opens the file with the specified encoding (usually not needed)."), NULL);
gtk_button_set_focus_on_click (GTK_BUTTON (check_open_encoding), FALSE);
eventbox3 = gtk_event_box_new ();
gtk_widget_show (eventbox3);
gtk_table_attach (GTK_TABLE (table5), eventbox3, 1, 2, 2, 3,
(GtkAttachOptions) (GTK_FILL),
(GtkAttachOptions) (GTK_FILL), 0, 0);
gtk_tooltips_set_tip (tooltips, eventbox3, _("Sets the default encoding for opening existing files."), NULL);
combo_open_encoding = gtk_combo_box_new_text ();
gtk_widget_show (combo_open_encoding);
gtk_container_add (GTK_CONTAINER (eventbox3), combo_open_encoding);
label109 = gtk_label_new (_("<b>New files</b>")); label109 = gtk_label_new (_("<b>New files</b>"));
gtk_widget_show (label109); gtk_widget_show (label109);
@ -4169,11 +4200,15 @@ create_prefs_dialog (void)
GLADE_HOOKUP_OBJECT (prefs_dialog, alignment7, "alignment7"); GLADE_HOOKUP_OBJECT (prefs_dialog, alignment7, "alignment7");
GLADE_HOOKUP_OBJECT (prefs_dialog, vbox8, "vbox8"); GLADE_HOOKUP_OBJECT (prefs_dialog, vbox8, "vbox8");
GLADE_HOOKUP_OBJECT (prefs_dialog, table5, "table5"); GLADE_HOOKUP_OBJECT (prefs_dialog, table5, "table5");
GLADE_HOOKUP_OBJECT (prefs_dialog, label116, "label116");
GLADE_HOOKUP_OBJECT (prefs_dialog, eventbox1, "eventbox1"); GLADE_HOOKUP_OBJECT (prefs_dialog, eventbox1, "eventbox1");
GLADE_HOOKUP_OBJECT (prefs_dialog, combo_encoding, "combo_encoding"); GLADE_HOOKUP_OBJECT (prefs_dialog, combo_new_encoding, "combo_new_encoding");
GLADE_HOOKUP_OBJECT (prefs_dialog, spin_tab_width, "spin_tab_width");
GLADE_HOOKUP_OBJECT (prefs_dialog, label153, "label153"); GLADE_HOOKUP_OBJECT (prefs_dialog, label153, "label153");
GLADE_HOOKUP_OBJECT (prefs_dialog, label116, "label116");
GLADE_HOOKUP_OBJECT (prefs_dialog, spin_tab_width, "spin_tab_width");
GLADE_HOOKUP_OBJECT (prefs_dialog, label_open_encoding, "label_open_encoding");
GLADE_HOOKUP_OBJECT (prefs_dialog, check_open_encoding, "check_open_encoding");
GLADE_HOOKUP_OBJECT (prefs_dialog, eventbox3, "eventbox3");
GLADE_HOOKUP_OBJECT (prefs_dialog, combo_open_encoding, "combo_open_encoding");
GLADE_HOOKUP_OBJECT (prefs_dialog, label109, "label109"); GLADE_HOOKUP_OBJECT (prefs_dialog, label109, "label109");
GLADE_HOOKUP_OBJECT (prefs_dialog, frame2, "frame2"); GLADE_HOOKUP_OBJECT (prefs_dialog, frame2, "frame2");
GLADE_HOOKUP_OBJECT (prefs_dialog, alignment3, "alignment3"); GLADE_HOOKUP_OBJECT (prefs_dialog, alignment3, "alignment3");

View File

@ -268,7 +268,11 @@ void configuration_save()
g_key_file_set_boolean(config, PACKAGE, "pref_editor_replace_tabs", editor_prefs.replace_tabs); g_key_file_set_boolean(config, PACKAGE, "pref_editor_replace_tabs", editor_prefs.replace_tabs);
g_key_file_set_boolean(config, PACKAGE, "pref_editor_trail_space", editor_prefs.trail_space); g_key_file_set_boolean(config, PACKAGE, "pref_editor_trail_space", editor_prefs.trail_space);
g_key_file_set_boolean(config, PACKAGE, "pref_editor_disable_dnd", editor_prefs.disable_dnd); g_key_file_set_boolean(config, PACKAGE, "pref_editor_disable_dnd", editor_prefs.disable_dnd);
g_key_file_set_string(config, PACKAGE, "pref_editor_default_encoding", encodings[editor_prefs.default_encoding].charset); g_key_file_set_string(config, PACKAGE, "pref_editor_default_new_encoding", encodings[editor_prefs.default_new_encoding].charset);
if (editor_prefs.default_open_encoding == -1)
g_key_file_set_string(config, PACKAGE, "pref_editor_default_open_encoding", "none");
else
g_key_file_set_string(config, PACKAGE, "pref_editor_default_open_encoding", encodings[editor_prefs.default_open_encoding].charset);
g_key_file_set_string(config, PACKAGE, "pref_template_developer", app->pref_template_developer); g_key_file_set_string(config, PACKAGE, "pref_template_developer", app->pref_template_developer);
g_key_file_set_string(config, PACKAGE, "pref_template_company", app->pref_template_company); g_key_file_set_string(config, PACKAGE, "pref_template_company", app->pref_template_company);
g_key_file_set_string(config, PACKAGE, "pref_template_mail", app->pref_template_mail); g_key_file_set_string(config, PACKAGE, "pref_template_mail", app->pref_template_mail);
@ -443,17 +447,28 @@ gboolean configuration_load()
editor_prefs.tab_width = utils_get_setting_integer(config, PACKAGE, "pref_editor_tab_width", 4); editor_prefs.tab_width = utils_get_setting_integer(config, PACKAGE, "pref_editor_tab_width", 4);
editor_prefs.use_tabs = utils_get_setting_boolean(config, PACKAGE, "pref_editor_use_tabs", TRUE); editor_prefs.use_tabs = utils_get_setting_boolean(config, PACKAGE, "pref_editor_use_tabs", TRUE);
// use current locale encoding as default for new files (should be in most cases UTF-8) // use current locale encoding as default for new files (should be UTF-8 in most cases)
g_get_charset(&default_charset); g_get_charset(&default_charset);
tmp_string = utils_get_setting_string(config, PACKAGE, "pref_editor_default_encoding", tmp_string = utils_get_setting_string(config, PACKAGE, "pref_editor_default_new_encoding",
default_charset); default_charset);
if (tmp_string) if (tmp_string)
{ {
const GeanyEncoding *enc = encodings_get_from_charset(tmp_string); const GeanyEncoding *enc = encodings_get_from_charset(tmp_string);
if (enc != NULL) if (enc != NULL)
editor_prefs.default_encoding = enc->idx; editor_prefs.default_new_encoding = enc->idx;
else else
editor_prefs.default_encoding = GEANY_ENCODING_UTF_8; editor_prefs.default_new_encoding = GEANY_ENCODING_UTF_8;
g_free(tmp_string);
}
tmp_string = utils_get_setting_string(config, PACKAGE, "pref_editor_default_open_encoding", "none");
if (tmp_string)
{
const GeanyEncoding *enc = encodings_get_from_charset(tmp_string);
if (enc != NULL)
editor_prefs.default_open_encoding = enc->idx;
else
editor_prefs.default_open_encoding = -1;
g_free(tmp_string); g_free(tmp_string);
} }

View File

@ -70,6 +70,7 @@ static void on_toolbar_show_toggled(GtkToggleButton *togglebutton, gpointer user
static void on_show_notebook_tabs_toggled(GtkToggleButton *togglebutton, gpointer user_data); static void on_show_notebook_tabs_toggled(GtkToggleButton *togglebutton, gpointer user_data);
static void on_use_folding_toggled(GtkToggleButton *togglebutton, gpointer user_data); static void on_use_folding_toggled(GtkToggleButton *togglebutton, gpointer user_data);
static void on_symbol_auto_completion_toggled(GtkToggleButton *togglebutton, gpointer user_data); static void on_symbol_auto_completion_toggled(GtkToggleButton *togglebutton, gpointer user_data);
static void on_open_encoding_toggled(GtkToggleButton *togglebutton, gpointer user_data);
void prefs_init_dialog(void) void prefs_init_dialog(void)
@ -231,9 +232,22 @@ void prefs_init_dialog(void)
widget = lookup_widget(app->prefs_dialog, "spin_tab_width"); widget = lookup_widget(app->prefs_dialog, "spin_tab_width");
gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), editor_prefs.tab_width); gtk_spin_button_set_value(GTK_SPIN_BUTTON(widget), editor_prefs.tab_width);
widget = lookup_widget(app->prefs_dialog, "combo_encoding"); widget = lookup_widget(app->prefs_dialog, "combo_new_encoding");
// luckily the index of the combo box items match the index of the encodings array // luckily the index of the combo box items match the index of the encodings array
gtk_combo_box_set_active(GTK_COMBO_BOX(widget), editor_prefs.default_encoding); gtk_combo_box_set_active(GTK_COMBO_BOX(widget), editor_prefs.default_new_encoding);
widget = lookup_widget(app->prefs_dialog, "check_open_encoding");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget),
(editor_prefs.default_open_encoding >= 0) ? TRUE : FALSE);
on_open_encoding_toggled(GTK_TOGGLE_BUTTON(widget), NULL);
widget = lookup_widget(app->prefs_dialog, "combo_open_encoding");
if (editor_prefs.default_open_encoding >= 0)
{
gtk_combo_box_set_active(GTK_COMBO_BOX(widget), editor_prefs.default_open_encoding);
}
else
gtk_combo_box_set_active(GTK_COMBO_BOX(widget), GEANY_ENCODING_UTF_8);
widget = lookup_widget(app->prefs_dialog, "check_trailing_spaces"); widget = lookup_widget(app->prefs_dialog, "check_trailing_spaces");
gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.trail_space); gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), editor_prefs.trail_space);
@ -561,8 +575,17 @@ void on_prefs_button_clicked(GtkDialog *dialog, gint response, gpointer user_dat
widget = lookup_widget(app->prefs_dialog, "spin_tab_width"); widget = lookup_widget(app->prefs_dialog, "spin_tab_width");
editor_prefs.tab_width = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget)); editor_prefs.tab_width = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
widget = lookup_widget(app->prefs_dialog, "combo_encoding"); widget = lookup_widget(app->prefs_dialog, "combo_new_encoding");
editor_prefs.default_encoding = gtk_combo_box_get_active(GTK_COMBO_BOX(widget)); editor_prefs.default_new_encoding = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
widget = lookup_widget(app->prefs_dialog, "check_open_encoding");
if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)))
{
widget = lookup_widget(app->prefs_dialog, "combo_open_encoding");
editor_prefs.default_open_encoding = gtk_combo_box_get_active(GTK_COMBO_BOX(widget));
}
else
editor_prefs.default_open_encoding = -1;
widget = lookup_widget(app->prefs_dialog, "check_trailing_spaces"); widget = lookup_widget(app->prefs_dialog, "check_trailing_spaces");
editor_prefs.trail_space = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)); editor_prefs.trail_space = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
@ -1018,11 +1041,20 @@ static void on_symbol_auto_completion_toggled(GtkToggleButton *togglebutton, gpo
} }
static void on_open_encoding_toggled(GtkToggleButton *togglebutton, gpointer user_data)
{
gboolean sens = gtk_toggle_button_get_active(togglebutton);
gtk_widget_set_sensitive(lookup_widget(app->prefs_dialog, "eventbox3"), sens);
gtk_widget_set_sensitive(lookup_widget(app->prefs_dialog, "label_open_encoding"), sens);
}
void prefs_show_dialog(void) void prefs_show_dialog(void)
{ {
if (app->prefs_dialog == NULL) if (app->prefs_dialog == NULL)
{ {
GtkWidget *combo; GtkWidget *combo_new, *combo_open;
guint i; guint i;
gchar *encoding_string; gchar *encoding_string;
@ -1031,12 +1063,15 @@ void prefs_show_dialog(void)
gtk_window_set_transient_for(GTK_WINDOW(app->prefs_dialog), GTK_WINDOW(app->window)); gtk_window_set_transient_for(GTK_WINDOW(app->prefs_dialog), GTK_WINDOW(app->window));
// init the default file encoding combo box // init the default file encoding combo box
combo = lookup_widget(app->prefs_dialog, "combo_encoding"); combo_new = lookup_widget(app->prefs_dialog, "combo_new_encoding");
gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(combo), 3); combo_open = lookup_widget(app->prefs_dialog, "combo_open_encoding");
gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(combo_new), 3);
gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(combo_open), 3);
for (i = 0; i < GEANY_ENCODINGS_MAX; i++) for (i = 0; i < GEANY_ENCODINGS_MAX; i++)
{ {
encoding_string = encodings_to_string(&encodings[i]); encoding_string = encodings_to_string(&encodings[i]);
gtk_combo_box_append_text(GTK_COMBO_BOX(combo), encoding_string); gtk_combo_box_append_text(GTK_COMBO_BOX(combo_new), encoding_string);
gtk_combo_box_append_text(GTK_COMBO_BOX(combo_open), encoding_string);
g_free(encoding_string); g_free(encoding_string);
} }
@ -1080,6 +1115,8 @@ void prefs_show_dialog(void)
"toggled", G_CALLBACK(on_use_folding_toggled), NULL); "toggled", G_CALLBACK(on_use_folding_toggled), NULL);
g_signal_connect((gpointer) lookup_widget(app->prefs_dialog, "check_symbol_auto_completion"), g_signal_connect((gpointer) lookup_widget(app->prefs_dialog, "check_symbol_auto_completion"),
"toggled", G_CALLBACK(on_symbol_auto_completion_toggled), NULL); "toggled", G_CALLBACK(on_symbol_auto_completion_toggled), NULL);
g_signal_connect((gpointer) lookup_widget(app->prefs_dialog, "check_open_encoding"),
"toggled", G_CALLBACK(on_open_encoding_toggled), NULL);
} }
prefs_init_dialog(); prefs_init_dialog();