Branch: refs/heads/master Author: Colomban Wendling ban@herbesfolles.org Committer: GitHub noreply@github.com Date: Sun, 21 Apr 2024 19:34:31 UTC Commit: 15831f4dfb7c8cd7de5080e8dfddf7d84ca60c4f https://github.com/geany/geany/commit/15831f4dfb7c8cd7de5080e8dfddf7d84ca60c...
Log Message: ----------- Merge pull request #3720 from b4n/encodings-ui-improvements
Encodings UI improvements
Modified Paths: -------------- data/geany.glade doc/geany.txt src/encodings.c src/encodingsprivate.h src/prefs.c
Modified: data/geany.glade 16 lines changed, 0 insertions(+), 16 deletions(-) =================================================================== @@ -4550,22 +4550,6 @@ <property name="position">0</property> </packing> </child> - <child> - <object class="GtkCheckButton" id="check_open_encoding"> - <property name="label" translatable="yes">Use fixed encoding when opening non-Unicode files</property> - <property name="visible">True</property> - <property name="can-focus">True</property> - <property name="receives-default">False</property> - <property name="tooltip-text" translatable="yes">This option disables the automatic detection of the file encoding when opening non-Unicode files and opens the file with the specified encoding (usually not needed)</property> - <property name="use-underline">True</property> - <property name="draw-indicator">True</property> - </object> - <packing> - <property name="expand">False</property> - <property name="fill">False</property> - <property name="position">1</property> - </packing> - </child> <child> <object class="GtkVBox" id="vbox45"> <property name="visible">True</property>
Modified: doc/geany.txt 10 lines changed, 5 insertions(+), 5 deletions(-) =================================================================== @@ -2473,12 +2473,12 @@ Open new documents from the command-line Default encoding (new files) The type of file encoding you wish to use when creating files.
-Used fixed encoding when opening files - Assume all files you are opening are using the type of encoding specified below. - Default encoding (existing files) - Opens all files with the specified encoding instead of auto-detecting it. - Use this option when it's not possible for Geany to detect the exact encoding. + Selects the encoding used when opening existing files. If set to something + other than *Detect from file*, all files will be opened with the specified + encoding instead of auto-detecting it. + Use a specific encoding when it's not possible for Geany to detect the + correct one.
Default end of line characters The end of line characters to which should be used for new files.
Modified: src/encodings.c 35 lines changed, 32 insertions(+), 3 deletions(-) =================================================================== @@ -59,12 +59,24 @@ static gboolean pregs_loaded = FALSE; GeanyEncoding encodings[GEANY_ENCODINGS_MAX];
+static gboolean conversion_supported(const gchar *to, const gchar *from) +{ + GIConv conv = g_iconv_open(to, from); + if (conv == (GIConv) -1) + return FALSE; + + g_iconv_close(conv); + return TRUE; +} + + #define fill(Order, Group, Idx, Charset, Name) \ encodings[Idx].idx = Idx; \ encodings[Idx].order = Order; \ encodings[Idx].group = Group; \ encodings[Idx].charset = Charset; \ - encodings[Idx].name = Name; + encodings[Idx].name = Name; \ + encodings[Idx].supported = FALSE;
static void init_encodings(void) { @@ -140,6 +152,19 @@ static void init_encodings(void) fill(14, EASTASIAN, GEANY_ENCODING_UHC, "UHC", _("Korean"));
fill(0, NONE, GEANY_ENCODING_NONE, "None", _("Without encoding")); + + /* fill the flags member */ + for (guint i = 0; i < G_N_ELEMENTS(encodings); i++) + { + if (i == GEANY_ENCODING_NONE || conversion_supported("UTF-8", encodings[i].charset)) + encodings[i].supported = TRUE; + else + { + /* geany_debug() doesn't really work at this point, unless G_MESSAGES_DEBUG + * is set explicitly by the caller, but that's better than nothing */ + geany_debug("Encoding %s is not supported by the system", encodings[i].charset); + } + } }
@@ -476,7 +501,8 @@ void encodings_init(void) } else item = gtk_menu_item_new_with_label(label); - gtk_widget_show(item); + if (encodings[i].supported) + gtk_widget_show(item); gtk_container_add(GTK_CONTAINER(submenus[encodings[i].group]), item); g_signal_connect(item, "activate", cb_func[k], (gpointer) encodings[i].charset); @@ -548,6 +574,9 @@ GtkTreeStore *encodings_encoding_store_new(gboolean has_detect) { gchar *encoding_string;
+ if (! encodings[i].supported) + continue; + switch (encodings[i].group) { case WESTEUROPEAN: iter_parent = &iter_westeuro; break; @@ -756,7 +785,7 @@ static gchar *encodings_convert_to_utf8_with_suggestion(const gchar *buffer, gss else continue; } - else if (i >= 0) + else if (i >= 0 && encodings[i].supported) charset = encodings[i].charset; else /* in this case we have i == -2, continue to increase i and go ahead */ continue;
Modified: src/encodingsprivate.h 1 lines changed, 1 insertions(+), 0 deletions(-) =================================================================== @@ -46,6 +46,7 @@ typedef struct GeanyEncoding GeanyEncodingGroup group; /* Internally used member for grouping */ const gchar *charset; /* String representation of the encoding, e.g. "ISO-8859-3" */ const gchar *name; /* Translatable and descriptive name of the encoding, e.g. "South European" */ + gboolean supported; /* Whether this encoding is supported on the system */ } GeanyEncoding;
Modified: src/prefs.c 40 lines changed, 9 insertions(+), 31 deletions(-) =================================================================== @@ -89,7 +89,6 @@ static void on_show_notebook_tabs_toggled(GtkToggleButton *togglebutton, gpointe static void on_enable_plugins_toggled(GtkToggleButton *togglebutton, gpointer user_data); static void on_use_folding_toggled(GtkToggleButton *togglebutton, gpointer user_data); static void on_check_line_end_toggled(GtkToggleButton *togglebutton, gpointer user_data); -static void on_open_encoding_toggled(GtkToggleButton *togglebutton, gpointer user_data); static void on_sidebar_visible_toggled(GtkToggleButton *togglebutton, gpointer user_data); static void on_prefs_print_radio_button_toggled(GtkToggleButton *togglebutton, gpointer user_data); static void on_prefs_print_page_header_toggled(GtkToggleButton *togglebutton, gpointer user_data); @@ -533,18 +532,11 @@ static void prefs_init_dialog(void) widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_new_encoding"); ui_encodings_combo_box_set_active_encoding(GTK_COMBO_BOX(widget), file_prefs.default_new_encoding);
- widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_open_encoding"); - gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(widget), - (file_prefs.default_open_encoding >= 0) ? TRUE : FALSE); - on_open_encoding_toggled(GTK_TOGGLE_BUTTON(widget), NULL); - widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_open_encoding"); if (file_prefs.default_open_encoding >= 0) - { ui_encodings_combo_box_set_active_encoding(GTK_COMBO_BOX(widget), file_prefs.default_open_encoding); - } else - ui_encodings_combo_box_set_active_encoding(GTK_COMBO_BOX(widget), GEANY_ENCODING_UTF_8); + ui_encodings_combo_box_set_active_encoding(GTK_COMBO_BOX(widget), GEANY_ENCODINGS_MAX);
widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_eol"); if (file_prefs.default_eol_character >= 0 && file_prefs.default_eol_character < 3) @@ -1006,13 +998,9 @@ on_prefs_dialog_response(GtkDialog *dialog, gint response, gpointer user_data) widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_new_encoding"); file_prefs.default_new_encoding = ui_encodings_combo_box_get_active_encoding(GTK_COMBO_BOX(widget));
- widget = ui_lookup_widget(ui_widgets.prefs_dialog, "check_open_encoding"); - if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) - { - widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_open_encoding"); - file_prefs.default_open_encoding = ui_encodings_combo_box_get_active_encoding(GTK_COMBO_BOX(widget)); - } - else + widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_open_encoding"); + file_prefs.default_open_encoding = ui_encodings_combo_box_get_active_encoding(GTK_COMBO_BOX(widget)); + if (file_prefs.default_open_encoding >= GEANY_ENCODINGS_MAX) file_prefs.default_open_encoding = -1;
widget = ui_lookup_widget(ui_widgets.prefs_dialog, "combo_eol"); @@ -1547,15 +1535,6 @@ static void on_enable_plugins_toggled(GtkToggleButton *togglebutton, gpointer us }
-static void on_open_encoding_toggled(GtkToggleButton *togglebutton, gpointer user_data) -{ - gboolean sens = gtk_toggle_button_get_active(togglebutton); - - gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "eventbox3"), sens); - gtk_widget_set_sensitive(ui_lookup_widget(ui_widgets.prefs_dialog, "label_open_encoding"), sens); -} - - static void on_sidebar_visible_toggled(GtkToggleButton *togglebutton, gpointer user_data) { gboolean sens = gtk_toggle_button_get_active(togglebutton); @@ -1664,23 +1643,24 @@ void prefs_show_dialog(void) { struct { const gchar *combo, *renderer; + gboolean has_detect; } names[] = { - { "combo_new_encoding", "combo_new_encoding_renderer" }, - { "combo_open_encoding", "combo_open_encoding_renderer" } + { "combo_new_encoding", "combo_new_encoding_renderer", FALSE }, + { "combo_open_encoding", "combo_open_encoding_renderer", TRUE } }; guint i; - GtkTreeStore *encoding_list = encodings_encoding_store_new(FALSE);
for (i = 0; i < G_N_ELEMENTS(names); i++) { + GtkTreeStore *encoding_list = encodings_encoding_store_new(names[i].has_detect); GtkWidget *combo = ui_lookup_widget(ui_widgets.prefs_dialog, names[i].combo);
gtk_cell_layout_set_cell_data_func(GTK_CELL_LAYOUT(combo), ui_builder_get_object(names[i].renderer), encodings_encoding_store_cell_data_func, NULL, NULL); gtk_combo_box_set_model(GTK_COMBO_BOX(combo), GTK_TREE_MODEL(encoding_list)); + g_object_unref(encoding_list); } - g_object_unref(encoding_list); }
/* init the eol character combo box */ @@ -1810,8 +1790,6 @@ void prefs_show_dialog(void) "toggled", G_CALLBACK(on_use_folding_toggled), NULL); g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_line_end"), "toggled", G_CALLBACK(on_check_line_end_toggled), NULL); - g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_open_encoding"), - "toggled", G_CALLBACK(on_open_encoding_toggled), NULL); g_signal_connect(ui_lookup_widget(ui_widgets.prefs_dialog, "check_sidebar_visible"), "toggled", G_CALLBACK(on_sidebar_visible_toggled), NULL);
-------------- This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).