# HG changeset patch
# User Abhinav Tripathi <genuinelucifer@gmail.com>
# Date 1478586984 28800
#      Mon Nov 07 22:36:24 2016 -0800
# Node ID 736adf0f583e14083d0e46edde3c21d02debfda9
# Parent  e6fac42c8d561b7d4c2e335c243f9223e5f8dffe
Allow changing comment character when using Ctrl+R... (bug #49182)

* file-editor-tab.cc (file_editor_tab::comment_string): Get the comment
character to be used from settings.
* settings-dialog.cc (settings_dialog::settings_dialog): Set the previously
selected comment character when the dialog opens.
(settings_dialog::write_changed_settings): Store the settings for comment
character.
* settings-dialog.ui: Add a new layout for the user to select the required
comment character.

diff -r e6fac42c8d56 -r 736adf0f583e libgui/src/m-editor/file-editor-tab.cc
--- a/libgui/src/m-editor/file-editor-tab.cc	Fri Nov 04 08:14:44 2016 -0700
+++ b/libgui/src/m-editor/file-editor-tab.cc	Mon Nov 07 22:36:24 2016 -0800
@@ -775,7 +775,16 @@
 file_editor_tab::comment_string (const QString& lexer)
 {
   if (lexer == "octave" || lexer == "matlab")
-    return QString("%");
+    {
+      QSettings *settings = resource_manager::get_settings ();
+      int comment_index = settings->value ("editor/octave_comment_string", 0).toInt ();
+      if (comment_index == 1)
+      	return QString("#");
+      else if (comment_index == 2)
+        return QString("%");
+      else
+        return QString("##");  // default and for index 0
+    }
   else if (lexer == "perl" || lexer == "bash" || lexer == "diff")
     return QString("#");
   else if (lexer == "cpp")
diff -r e6fac42c8d56 -r 736adf0f583e libgui/src/settings-dialog.cc
--- a/libgui/src/settings-dialog.cc	Fri Nov 04 08:14:44 2016 -0700
+++ b/libgui/src/settings-dialog.cc	Mon Nov 07 22:36:24 2016 -0800
@@ -438,6 +438,8 @@
     settings->value ("editor/show_eol_chars",false).toBool ());
   ui->cb_show_hscrollbar->setChecked (
     settings->value ("editor/show_hscroll_bar",true).toBool ());
+  ui->combo_oct_comment_str->setCurrentIndex (
+    settings->value ("editor/octave_comment_string", 0).toInt ());
 
 #if defined (HAVE_QSCINTILLA)
 #  if defined (Q_OS_WIN32)
@@ -816,6 +818,8 @@
                       ui->cb_show_hscrollbar->isChecked ());
   settings->setValue ("editor/default_eol_mode",
                       ui->combo_eol_mode->currentIndex ());
+  settings->setValue ("editor/octave_comment_string",
+                      ui->combo_oct_comment_str->currentIndex ());
   settings->setValue ("editor/default_encoding",
                       ui->editor_combo_encoding->currentText ());
   settings->setValue ("editor/auto_indent",
diff -r e6fac42c8d56 -r 736adf0f583e libgui/src/settings-dialog.ui
--- a/libgui/src/settings-dialog.ui	Fri Nov 04 08:14:44 2016 -0700
+++ b/libgui/src/settings-dialog.ui	Mon Nov 07 22:36:24 2016 -0800
@@ -917,6 +917,64 @@
                 </item>
                </layout>
               </item>
+              <item>
+               <layout class="QHBoxLayout" name="horizontalLayout_17">
+                <property name="topMargin">
+                 <number>0</number>
+                </property>
+                <item>
+                 <widget class="QLabel" name="label_23">
+                  <property name="text">
+                   <string>Character used to comment selected text (Ctrl+R)</string>
+                  </property>
+                 </widget>
+                </item>
+                <item>
+                 <widget class="QComboBox" name="combo_oct_comment_str">
+                  <property name="sizePolicy">
+                   <sizepolicy hsizetype="Preferred" vsizetype="Preferred">
+                    <horstretch>0</horstretch>
+                    <verstretch>0</verstretch>
+                   </sizepolicy>
+                  </property>
+                  <property name="sizeAdjustPolicy">
+                   <enum>QComboBox::AdjustToContents</enum>
+                  </property>
+                  <property name="minimumContentsLength">
+                   <number>3</number>
+                  </property>
+                  <item>
+                   <property name="text">
+                    <string>##</string>
+                   </property>
+                  </item>
+                  <item>
+                   <property name="text">
+                    <string>#</string>
+                   </property>
+                  </item>
+                  <item>
+                   <property name="text">
+                    <string>%</string>
+                   </property>
+                  </item>
+                 </widget>
+                </item>
+                <item>
+                 <spacer name="horizontalSpacer_33">
+                  <property name="orientation">
+                   <enum>Qt::Horizontal</enum>
+                  </property>
+                  <property name="sizeHint" stdset="0">
+                   <size>
+                    <width>40</width>
+                    <height>20</height>
+                   </size>
+                  </property>
+                 </spacer>
+                </item>
+               </layout>
+              </item>
              </layout>
             </widget>
            </item>
