Mercurial > octave
diff libgui/src/settings-dialog.cc @ 20731:83611b387bc5
provide a user preference for the encoding used by the editor (bug #45597)
* file-editor-tab.cc (load_file/save_file): get the codec used for loading or
saving the file from the settings file, default is system default encoding
* settings-dialog.cc (settings_dialog): calling new function for initializing
the new combo-box with the available encodings;
(write_changed_settings): store the value from the new combo-box in settings;
(init_combo_encoding): initializing the new combo-box with available encodings
* settings-dialog.h: new function for initializing the new combo-box with
all available encodings
* settings-dialog.ui: new location of eol-mode in editor settings and
new combo-box for file encoding used in the editor
author | Torsten <ttl@justmail.de> |
---|---|
date | Sat, 21 Nov 2015 14:47:22 +0100 |
parents | fec7cc73507b |
children | 7d6f38541902 |
line wrap: on
line diff
--- a/libgui/src/settings-dialog.cc Thu Nov 19 16:57:51 2015 -0500 +++ b/libgui/src/settings-dialog.cc Sat Nov 21 14:47:22 2015 +0100 @@ -34,6 +34,7 @@ #include <QFileDialog> #include <QVector> #include <QHash> +#include <QTextCodec> #ifdef HAVE_QSCINTILLA #include "octave-qscintilla.h" @@ -365,7 +366,9 @@ connect (ui->pb_octave_dir, SIGNAL (pressed ()), this, SLOT (get_octave_dir ())); + // // editor + // ui->useCustomFileEditor->setChecked (settings->value ("useCustomFileEditor", false).toBool ()); ui->customFileEditor->setText ( @@ -373,6 +376,8 @@ ui->editor_showLineNumbers->setChecked ( settings->value ("editor/showLineNumbers",true).toBool ()); + init_combo_encoding (settings); + default_var = QColor (240, 240, 240); QColor setting_color = settings->value ("editor/highlight_current_line_color", default_var).value<QColor> (); @@ -798,6 +803,10 @@ ui->cb_show_hscrollbar->isChecked ()); settings->setValue ("editor/default_eol_mode", ui->combo_eol_mode->currentIndex ()); + QString encoding = ui->editor_combo_encoding->currentText (); + if (encoding == tr ("System default")) + encoding = "SYSTEM"; + settings->setValue ("editor/default_encoding", encoding); settings->setValue ("editor/auto_indent", ui->editor_auto_ind_checkbox->isChecked ()); settings->setValue ("editor/tab_indents_line", @@ -1015,6 +1024,48 @@ } } +// initialize the combo box with possible text encodings +void +settings_dialog::init_combo_encoding (QSettings *settings) +{ + // get the codec name for each mib + QList<int> all_mibs = QTextCodec::availableMibs (); + QStringList all_codecs; + foreach (int mib, all_mibs) + { + QTextCodec *c = QTextCodec::codecForMib (mib); + all_codecs << c->name ().toUpper (); + } + all_codecs.removeDuplicates (); + + // remove the "system" entry + int idx = all_codecs.indexOf ("SYSTEM"); + if (idx >= 0) + all_codecs.removeAt (idx); + + // sort and prepend meaningfull text for system's default codec + qSort (all_codecs); + all_codecs.prepend (tr ("System default")); + + // get the value from the settings file (system is default) + QString encoding = settings->value ("editor/default_encoding","SYSTEM") + .toString (); + if (encoding == "SYSTEM") + encoding = tr ("System default"); + + // fill the combo box and select the current item or system if + // current item from the settings file can not be found + foreach (QString c, all_codecs) + ui->editor_combo_encoding->addItem (c); + idx = ui->editor_combo_encoding->findText (encoding); + if (idx >= 0) + ui->editor_combo_encoding->setCurrentIndex (idx); + else + ui->editor_combo_encoding->setCurrentIndex (0); + + ui->editor_combo_encoding->setMaxVisibleItems (12); +} + // slots for import/export of shortcut sets void settings_dialog::import_shortcut_set ()