Improve encoding dialog
Closes #28 (closed).
This MR fixes various bugs and confusing behaviors of the encoding dialog, and addresses #28 (closed), by always ending up proposing something to the user, as most other text editors do.
To achieve this, I used g_utf8_make_valid()
, which is only available since GLib 2.52 (we require GLib 2.42). So I simply copied the source code of current version 2.62 in mousepad/mousepad-util.[ch]
with a code switch.
I'm not quite sure if this is legally sufficient in form (author's quotation, license, etc.), so it would be nice if someone who knows these issues better than I do could take a look. Thanks!
Here is a summary of the changes:
- Always show something to the user:
- if
convert()
succeeded, show the list of valid encodings; - else if
convert()
partially succeeded (didn't returnNULL
but not UTF-8 valid), show the list of partially valid encodings (made valid byg_utf8_make_valid()
); - else (unlikely) show the output of
g_utf8_make_valid()
.
- if
- Hide unused widgets:
- don't show the user a button or a list item that only leads to an error;
- always show the default UTF-8, since it never fails (but possibly hide the radio button if there are no others).
- treat the system encoding as a special case:
- if it is the same as default UTF-8, hide it;
- else show it, even if it is an unsupported charset (the user should be informed what is his system charset, and if it is supported or not).
- Update the dialog header consequently.
Edited by Gaël Bonithon