changeset 25702:bd30c6f8cfb7

update internal __mfile_encoding__ when gui default encoding changes (bug #54310) * gui-preferences.h: define constants for editor default encoding prefs * main-window.cc (main_window): initialize new class variable storing the default encoding; (notice_settings): check for changes in default encoding and update __mfile_encoding__ via worker thread if required; (gui_preference_adjust): use constants for pref key; * main-window.h: new class variable storing the default encoding * resource-manager.cc: include gui-preferences.h; (do_combo_encoding): use constants for key and default of encoding
author Torsten <mttl@mailbox.org>
date Sun, 29 Jul 2018 12:57:07 +0200
parents 9a385fab138e
children 7b4e99fbe9d4
files libgui/src/gui-preferences.h libgui/src/main-window.cc libgui/src/main-window.h libgui/src/resource-manager.cc
diffstat 4 files changed, 26 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/gui-preferences.h	Sun Jul 29 11:30:33 2018 +0200
+++ b/libgui/src/gui-preferences.h	Sun Jul 29 12:57:07 2018 +0200
@@ -52,6 +52,12 @@
 
 // File handling
 const gui_pref ed_show_dbg_file ("editor/show_dbg_file", QVariant (true));
+#if defined (Q_OS_WIN32)
+const gui_pref ed_default_enc ("editor/default_encoding", QVariant ("SYSTEM"));
+#else
+const gui_pref ed_default_enc ("editor/default_encoding", QVariant ("UTF-8"));
+#endif
+
 
 
 #endif
--- a/libgui/src/main-window.cc	Sun Jul 29 11:30:33 2018 +0200
+++ b/libgui/src/main-window.cc	Sun Jul 29 12:57:07 2018 +0200
@@ -211,6 +211,8 @@
           = settings->value ("news/last_time_checked", QDateTime ()).toDateTime ();
 
         serial = settings->value ("news/last_news_item", 0).toInt ();
+        m_default_encoding = settings->value (ed_default_enc.key,
+                                              ed_default_enc.def).toString ();
       }
 
     QDateTime current = QDateTime::currentDateTime ();
@@ -758,6 +760,17 @@
     set_global_shortcuts (m_active_dock == m_command_window);
     disable_menu_shortcuts (m_active_dock == m_editor_window);
 
+    // Ckeck whether some octave internal preferences have to be updated
+    QString new_default_encoding
+      = settings->value (ed_default_enc.key, ed_default_enc.def).toString ();
+    if (new_default_encoding != m_default_encoding)
+      {
+        m_default_encoding = new_default_encoding;
+        octave_cmd_builtin *cmd = new octave_cmd_builtin (
+                                    &F__mfile_encoding__,
+                                    ovl (m_default_encoding.toStdString ()));
+        m_cmd_queue.add_cmd (cmd);
+      }
 
     // Set cursor blinking depending on the settings
     // Cursor blinking: consider old terminal related setting if not yet set
@@ -2503,7 +2516,7 @@
 
     // Not all encodings are available. Encodings are uppercase and do not
     // use CPxxx but IBMxxx or WINDOWS-xxx.
-    if (key == "editor/default_encoding")
+    if (key == ed_default_enc.key)
       {
         adjusted_value = adjusted_value.toUpper ();
 
--- a/libgui/src/main-window.h	Sun Jul 29 11:30:33 2018 +0200
+++ b/libgui/src/main-window.h	Sun Jul 29 12:57:07 2018 +0200
@@ -365,6 +365,8 @@
 
     QHash<QMenu*, QStringList> m_hash_menu_text;
 
+    QString m_default_encoding;
+
     //! Toolbar.
 
     QStatusBar *m_status_bar;
--- a/libgui/src/resource-manager.cc	Sun Jul 29 11:30:33 2018 +0200
+++ b/libgui/src/resource-manager.cc	Sun Jul 29 12:57:07 2018 +0200
@@ -47,6 +47,7 @@
 #include "workspace-model.h"
 #include "variable-editor.h"
 #include "resource-manager.h"
+#include "gui-preferences.h"
 
 namespace octave
 {
@@ -360,20 +361,13 @@
     QStringList all_codecs;
     do_get_codecs (&all_codecs);
 
-    // the default encoding
-#if defined (Q_OS_WIN32)
-    QString def_enc = "SYSTEM";
-#else
-    QString def_enc = "UTF-8";
-#endif
-
     // get the value from the settings file if no current encoding is given
     QString enc = current;
     if (enc.isEmpty ())
       {
-        enc = m_settings->value ("editor/default_encoding",def_enc).toString ();
+        enc = m_settings->value (ed_default_enc.key, ed_default_enc.def).toString ();
         if (enc.isEmpty ())  // still empty?
-          enc = def_enc;     // take default
+          enc = ed_default_enc.def.toString ();     // take default
       }
 
     // fill the combo box
@@ -382,7 +376,7 @@
 
     // prepend the default item
     combo->insertSeparator (0);
-    combo->insertItem (0, def_enc);
+    combo->insertItem (0, ed_default_enc.def.toString ());
 
     // select the current/default item
     int idx = combo->findText (enc);