changeset 25617:44d638d5eea5

reorganize constants for preferences keys and default values * editor-settings.h: rename into gui-preferences.h * gui-preferences.h: define a structure for key string and default value, reorganize existing constants using the new structure, renaming constants reflecting the main widget they are used in * file-editor-tab.cc: include gui-preferences.h; (do_comment_selected_text): use const structure with new names for preferences keys and default values file-editor-tab.cc Wed Jul 11 07:56:05 2018 +0200 * octave-qscintilla.cc: include gui-preferences.h; (comment_string): use const structure with new names for preferences keys and default values * module.mk: rename editor-settings.h into gui-preferences.h * settings-dialog.cc: include gui-preferences.h; (settings_dialog, write_changed_settings): use const structure with new names for preferences keys and default values * settings-dialog.h: include gui-preferences.h, use const structure with new names for preferences keys and default values
author Torsten <mttl@mailbox.org>
date Fri, 13 Jul 2018 22:58:56 +0200
parents bd362df6277c
children d88bc4983ce7
files libgui/src/editor-settings.h libgui/src/gui-preferences.h libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/octave-qscintilla.cc libgui/src/module.mk libgui/src/settings-dialog.cc libgui/src/settings-dialog.h
diffstat 7 files changed, 89 insertions(+), 77 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/editor-settings.h	Fri Jul 13 22:58:45 2018 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,44 +0,0 @@
-/*
-
-Copyright (C) 2017-2018 Torsten <mttl@mailbox.de>
-
-This file is part of Octave.
-
-Octave is free software: you can redistribute it and/or modify it
-under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 3 of the License, or
-(at your option) any later version.
-
-Octave is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with Octave; see the file COPYING.  If not, see
-<https://www.gnu.org/licenses/>.
-
-*/
-
-#if ! defined (octave_editor_settings_h)
-#define octave_editor_settings_h 1
-
-//#if defined (HAVE_CONFIG_H)
-//#  include "config.h"
-//#endif
-
-#include <QStringList>
-
-// Octave comment strings
-const QString oct_comment_str_old ("editor/octave_comment_string");
-const int oct_comment_str_old_d = 0;
-
-const QString oct_comment_str ("editor/oct_comment_str");
-const QString oct_uncomment_str ("editor/oct_uncomment_str");
-const QString oct_last_comment_str ("editor/oct_last_comment_str");
-const QStringList oct_comment_strings (QStringList () << "##" << "#" << "%"<< "%%" << "%!");
-const int oct_comment_strings_count = 5;
-const int oct_comment_str_d = 0;
-const int oct_uncomment_str_d = 1 + 2 + 4 + 8;
-
-#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/libgui/src/gui-preferences.h	Fri Jul 13 22:58:56 2018 +0200
@@ -0,0 +1,56 @@
+/*
+
+Copyright (C) 2017-2018 Torsten <mttl@mailbox.de>
+
+This file is part of Octave.
+
+Octave is free software: you can redistribute it and/or modify it
+under the terms of the GNU General Public License as published by
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
+
+Octave is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with Octave; see the file COPYING.  If not, see
+<https://www.gnu.org/licenses/>.
+
+*/
+
+#if ! defined (octave_editor_settings_h)
+#define octave_editor_settings_h 1
+
+//#if defined (HAVE_CONFIG_H)
+//#  include "config.h"
+//#endif
+
+#include <QStringList>
+#include <QVariant>
+
+// Structure for the definition of pairs: key and default value
+
+struct gui_pref
+{
+  gui_pref (const QString& key_, QVariant def_): key (key_), def (def_) {}
+  QString   key;  // the key name
+  QVariant  def;  // the default value
+};
+
+// Editor preferences
+
+// Octave comment strings
+const gui_pref ed_comment_str_old = gui_pref ("editor/octave_comment_string", QVariant (0));
+const gui_pref ed_comment_str ("editor/oct_comment_str", QVariant (0));
+const gui_pref ed_uncomment_str ("editor/oct_uncomment_str", QVariant (1 + 2 + 4 + 8));
+
+const QString ed_last_comment_str ("editor/oct_last_comment_str");
+const QStringList ed_comment_strings (QStringList () << "##" << "#" << "%"<< "%%" << "%!");
+const int ed_comment_strings_count = 5;
+
+// File handling
+
+
+#endif
--- a/libgui/src/m-editor/file-editor-tab.cc	Fri Jul 13 22:58:45 2018 +0200
+++ b/libgui/src/m-editor/file-editor-tab.cc	Fri Jul 13 22:58:56 2018 +0200
@@ -60,7 +60,7 @@
 #include <QDialogButtonBox>
 #include <QPushButton>
 
-#include "editor-settings.h"
+#include "gui-preferences.h"
 #include "resource-manager.h"
 
 #include "file-editor-tab.h"
@@ -1445,13 +1445,13 @@
             used_comment_str = QInputDialog::getText (
                                  this, tr ("Comment selected text"),
                                  tr ("Comment string to use:\n"), QLineEdit::Normal,
-                                 settings->value (oct_last_comment_str, comment_str.at (0)).toString (),
+                                 settings->value (ed_last_comment_str, comment_str.at (0)).toString (),
                                  &ok);
 
             if ((! ok) || used_comment_str.isEmpty ())
               return;  // No input, do nothing
             else
-              settings->setValue (oct_last_comment_str, used_comment_str);  // Store last
+              settings->setValue (ed_last_comment_str, used_comment_str);  // Store last
           }
       }
     else
--- a/libgui/src/m-editor/octave-qscintilla.cc	Fri Jul 13 22:58:45 2018 +0200
+++ b/libgui/src/m-editor/octave-qscintilla.cc	Fri Jul 13 22:58:56 2018 +0200
@@ -50,7 +50,7 @@
 #include <QToolTip>
 #include <QVBoxLayout>
 
-#include "editor-settings.h"
+#include "gui-preferences.h"
 #include "resource-manager.h"
 #include "shortcut-manager.h"
 
@@ -392,29 +392,29 @@
           if (comment)
             {
               // The commenting string is requested
-              if (settings->contains (oct_comment_str))
+              if (settings->contains (ed_comment_str.key))
                 // new version (radio buttons)
-                comment_string = settings->value (oct_comment_str,
-                                                  oct_comment_str_d).toInt ();
+                comment_string = settings->value (ed_comment_str.key,
+                                                  ed_comment_str.def).toInt ();
               else
                 // old version (combo box)
-                comment_string = settings->value (oct_comment_str_old,
-                                                  oct_comment_str_d).toInt ();
+                comment_string = settings->value (ed_comment_str_old.key,
+                                                  ed_comment_str.def).toInt ();
 
-              return (QStringList (oct_comment_strings.at (comment_string)));
+              return (QStringList (ed_comment_strings.at (comment_string)));
             }
           else
             {
               QStringList c_str;
 
               // The possible uncommenting string(s) are requested
-              comment_string = settings->value (oct_uncomment_str,
-                                                oct_uncomment_str_d).toInt ();
+              comment_string = settings->value (ed_uncomment_str.key,
+                                                ed_uncomment_str.def).toInt ();
 
-              for (int i = 0; i < oct_comment_strings_count; i++)
+              for (int i = 0; i < ed_comment_strings_count; i++)
                 {
                   if (1 << i & comment_string)
-                    c_str.append (oct_comment_strings.at (i));
+                    c_str.append (ed_comment_strings.at (i));
                 }
 
               return c_str;
--- a/libgui/src/module.mk	Fri Jul 13 22:58:45 2018 +0200
+++ b/libgui/src/module.mk	Fri Jul 13 22:58:56 2018 +0200
@@ -155,7 +155,7 @@
   %reldir%/documentation-dock-widget.h \
   %reldir%/documentation.h \
   %reldir%/dw-main-window.h \
-  %reldir%/editor-settings.h \
+  %reldir%/gui-preferences.h \
   %reldir%/external-editor-interface.h \
   %reldir%/files-dock-widget.h \
   %reldir%/history-dock-widget.h \
--- a/libgui/src/settings-dialog.cc	Fri Jul 13 22:58:45 2018 +0200
+++ b/libgui/src/settings-dialog.cc	Fri Jul 13 22:58:56 2018 +0200
@@ -451,17 +451,17 @@
 
   int selected_comment_string, selected_uncomment_string;
 
-  if (settings->contains (oct_comment_str))   // new version (radio buttons)
-    selected_comment_string = settings->value (oct_comment_str,
-                                               oct_comment_str_d).toInt ();
+  if (settings->contains (ed_comment_str.key))   // new version (radio buttons)
+    selected_comment_string = settings->value (ed_comment_str.key,
+                                               ed_comment_str.def).toInt ();
   else                                         // old version (combo box)
-    selected_comment_string = settings->value (oct_comment_str_old,
-                                               oct_comment_str_d).toInt ();
+    selected_comment_string = settings->value (ed_comment_str_old.key,
+                                               ed_comment_str.def).toInt ();
 
-  selected_uncomment_string = settings->value (oct_uncomment_str,
-                                               oct_uncomment_str_d).toInt ();
+  selected_uncomment_string = settings->value (ed_uncomment_str.key,
+                                               ed_uncomment_str.def).toInt ();
 
-  for (int i = 0; i < oct_comment_strings_count; i++)
+  for (int i = 0; i < ed_comment_strings_count; i++)
     {
       m_rb_comment_strings[i] = new QRadioButton ();
       m_rb_uncomment_strings[i] = new QRadioButton ();
@@ -471,11 +471,11 @@
       connect (m_rb_comment_strings[i], SIGNAL (toggled (bool)),
                m_rb_uncomment_strings[i], SLOT (setDisabled (bool)));
 
-      m_rb_comment_strings[i]->setText (oct_comment_strings.at(i));
+      m_rb_comment_strings[i]->setText (ed_comment_strings.at(i));
       m_rb_comment_strings[i]->setChecked (i == selected_comment_string);
       ui->layout_comment_strings->addWidget (m_rb_comment_strings[i]);
 
-      m_rb_uncomment_strings[i]->setText (oct_comment_strings.at(i));
+      m_rb_uncomment_strings[i]->setText (ed_comment_strings.at(i));
       m_rb_uncomment_strings[i]->setAutoExclusive (false);
       m_rb_uncomment_strings[i]->setChecked ( 1 << i & selected_uncomment_string);
       ui->layout_uncomment_strings->addWidget (m_rb_uncomment_strings[i]);
@@ -853,20 +853,20 @@
 
   // Comment strings
   int rb_uncomment = 0;
-  for (int i = 0; i < oct_comment_strings_count; i++)
+  for (int i = 0; i < ed_comment_strings_count; i++)
     {
       if (m_rb_comment_strings[i]->isChecked ())
         {
-          settings->setValue (oct_comment_str, i);
+          settings->setValue (ed_comment_str.key, i);
           if (i < 3)
-            settings->setValue (oct_comment_str_old, i);
+            settings->setValue (ed_comment_str_old.key, i);
           else
-            settings->setValue (oct_comment_str_old, oct_comment_str_d);
+            settings->setValue (ed_comment_str_old.key, ed_comment_str.def);
         }
       if (m_rb_uncomment_strings[i]->isChecked ())
         rb_uncomment = rb_uncomment + (1 << i);
     }
-  settings->setValue (oct_uncomment_str, rb_uncomment);
+  settings->setValue (ed_uncomment_str.key, rb_uncomment);
 
   settings->setValue ("editor/default_encoding", ui->editor_combo_encoding->currentText ());
   settings->setValue ("editor/auto_indent", ui->editor_auto_ind_checkbox->isChecked ());
--- a/libgui/src/settings-dialog.h	Fri Jul 13 22:58:45 2018 +0200
+++ b/libgui/src/settings-dialog.h	Fri Jul 13 22:58:56 2018 +0200
@@ -29,7 +29,7 @@
 #include <QRadioButton>
 
 #include "color-picker.h"
-#include "editor-settings.h"
+#include "gui-preferences.h"
 
 namespace Ui
 {
@@ -86,8 +86,8 @@
   color_picker *m_widget_title_fg_color_active;
   color_picker *m_editor_current_line_color;
 
-  QRadioButton *m_rb_comment_strings[oct_comment_strings_count];
-  QRadioButton *m_rb_uncomment_strings[oct_comment_strings_count];
+  QRadioButton *m_rb_comment_strings[ed_comment_strings_count];
+  QRadioButton *m_rb_uncomment_strings[ed_comment_strings_count];
 };
 
 #endif