diff libgui/src/m-editor/file-editor-tab.cc @ 19440:54943eb0ce37 gui-release

reorder eol modes in the editor settings * settings-dialog.ui: order the eol mode such that their indexes correspond to the values of the enum value in scintilla * file-editor-tab.cc (detect_eol_mode): use settings or OS eol mode as default if no detection is possible (e.g. empty file); (new_file): use static cast from int to eol enum instead of array * settings-dialog.cc (constructor): choose 2 (EolUnix) as default eol mode if qscintilla is not available
author Torsten <ttl@justmail.de>
date Sat, 11 Oct 2014 15:44:07 +0200
parents 9582fad68730
children d10c711a08d8
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc
+++ b/libgui/src/m-editor/file-editor-tab.cc
@@ -1369,17 +1369,34 @@
         }
     }
 
-  QsciScintilla::EolMode eol_mode = QsciScintilla::EolUnix;
-  int count_max = count_lf;
+  // get default from OS or from settings
+#if defined (Q_OS_WIN32)
+  int os_eol_mode = QsciScintilla::EolWindows;
+#elif defined (Q_OS_MAC)
+  int os_eol_mode = QsciScintilla::EolMac;
+#else
+  int os_eol_mode = QsciScintilla::EolUnix;
+#endif
+QSettings *settings = resource_manager::get_settings ();
+QsciScintilla::EolMode eol_mode = static_cast<QsciScintilla::EolMode> (
+      settings->value("editor/default_eol_mode",os_eol_mode).toInt ());
 
+  int count_max = 0;
+
+  if (count_crlf > count_max)
+    {
+      eol_mode = QsciScintilla::EolWindows;
+      count_max = count_crlf;
+    }
   if (count_cr > count_max)
     {
       eol_mode = QsciScintilla::EolMac;
       count_max = count_cr;
     }
-  if (count_crlf > count_max)
+  if (count_lf > count_max)
     {
-      eol_mode = QsciScintilla::EolWindows;
+      eol_mode = QsciScintilla::EolUnix;
+      count_max = count_lf;
     }
 
   return eol_mode;
@@ -1411,9 +1428,6 @@
 
   // set the eol mode from the settings or depending on the OS if the entry is
   // missing in the settings
-  QsciScintilla::EolMode eol_modes[] =
-    {QsciScintilla::EolWindows, QsciScintilla::EolUnix, QsciScintilla::EolMac};
-
 #if defined (Q_OS_WIN32)
   int eol_mode = QsciScintilla::EolWindows;
 #elif defined (Q_OS_MAC)
@@ -1422,7 +1436,8 @@
   int eol_mode = QsciScintilla::EolUnix;
 #endif
   _edit_area->setEolMode (
-      eol_modes[settings->value("editor/default_eol_mode",eol_mode).toInt ()]);
+    static_cast<QsciScintilla::EolMode> (
+      settings->value("editor/default_eol_mode",eol_mode).toInt ()));
 
   update_eol_indicator ();