changeset 23234:aaf20024db6f

function providing comment strings uses lexer number and not lexer names * file-editor-tab.cc (comment_string): move function to octave-qscintilla.cc; (do_comment_selected_text): update the call to the function * file-editor-tab.h: remove declaration of comment_string * octave-qscintilla.cc (comment_string): this funtion moved here from file_editor_tab.cc, the current lexer is detected and not given by the caller via the name of the lexer * octave-qscintilla.h: new function comment_string
author Torsten <mttl@mailbox.org>
date Sat, 25 Feb 2017 17:57:01 +0100
parents eb6059699e3b
children a36d3015f8c8
files libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/file-editor-tab.h libgui/src/m-editor/octave-qscintilla.cc libgui/src/m-editor/octave-qscintilla.h
diffstat 4 files changed, 50 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc	Sat Feb 25 12:27:47 2017 +0100
+++ b/libgui/src/m-editor/file-editor-tab.cc	Sat Feb 25 17:57:01 2017 +0100
@@ -797,30 +797,6 @@
   _lexer_apis->savePrepared (_prep_apis_file);
 }
 
-QString
-file_editor_tab::comment_string (const QString& lexer)
-{
-  if (lexer == "octave" || lexer == "matlab")
-    {
-      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")
-    return ("//");
-  else if (lexer == "batch")
-    return ("REM ");
-  else
-    return ("%");  // should never happen
-}
-
 // slot for fetab_set_focus: sets the focus to the current edit area
 void
 file_editor_tab::set_focus (const QWidget *ID)
@@ -1405,7 +1381,7 @@
 void
 file_editor_tab::do_comment_selected_text (bool comment)
 {
-  QString comment_str = comment_string (_edit_area->lexer ()->lexer ());
+  QString comment_str = _edit_area->comment_string ();
   _edit_area->beginUndoAction ();
 
   if (_edit_area->hasSelectedText ())
--- a/libgui/src/m-editor/file-editor-tab.h	Sat Feb 25 12:27:47 2017 +0100
+++ b/libgui/src/m-editor/file-editor-tab.h	Sat Feb 25 17:57:01 2017 +0100
@@ -248,7 +248,6 @@
   void show_dialog (QDialog *dlg, bool modal);
   int check_file_modified ();
   void do_comment_selected_text (bool comment);
-  QString comment_string (const QString&);
   void do_indent_selected_text (bool indent);
 
   void add_breakpoint_callback (const bp_info& info);
--- a/libgui/src/m-editor/octave-qscintilla.cc	Sat Feb 25 12:27:47 2017 +0100
+++ b/libgui/src/m-editor/octave-qscintilla.cc	Sat Feb 25 17:57:01 2017 +0100
@@ -28,6 +28,12 @@
 
 #if defined (HAVE_QSCINTILLA)
 
+#if defined (HAVE_QSCI_QSCILEXEROCTAVE_H)
+#  define HAVE_LEXER_OCTAVE 1
+#elif defined (HAVE_QSCI_QSCILEXERMATLAB_H)
+#  define HAVE_LEXER_MATLAB 1
+#endif
+
 #include <Qsci/qscilexer.h>
 #include <Qsci/qscicommandset.h>
 #include <QShortcut>
@@ -36,6 +42,7 @@
 #include "octave-qscintilla.h"
 #include "file-editor-tab.h"
 #include "shortcut-manager.h"
+#include "resource-manager.h"
 
 octave_qscintilla::octave_qscintilla (QWidget *p)
   : QsciScintilla (p)
@@ -342,6 +349,47 @@
   QsciScintilla::focusInEvent (focusEvent);
 }
 
+// Function returning the comment string of the current lexer
+QString
+octave_qscintilla::comment_string ()
+{
+  int lexer = SendScintilla (SCI_GETLEXER);
+
+  switch (lexer)
+    {
+#if defined (HAVE_LEXER_MATLAB)
+      case SCLEX_MATLAB:
+#if defined (HAVE_LEXER_OCTAVE)
+      case SCLEX_OCTAVE:
+#endif
+       {
+          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
+        }
+#endif
+
+      case SCLEX_PERL:
+      case SCLEX_BASH:
+      case SCLEX_DIFF:
+        return QString ("#");
+
+      case SCLEX_CPP:
+        return QString ("//");
+
+      case SCLEX_BATCH:
+        return QString ("REM ");
+    }
+
+    return QString ("%");  // should never happen
+}
+
 // helper function for clearing all indicators of a specific style
 void
 octave_qscintilla::clear_indicator (int indicator_style)
--- a/libgui/src/m-editor/octave-qscintilla.h	Sat Feb 25 12:27:47 2017 +0100
+++ b/libgui/src/m-editor/octave-qscintilla.h	Sat Feb 25 17:57:01 2017 +0100
@@ -47,6 +47,7 @@
   bool get_actual_word ();
   void clear_indicator (int indicator_style);
   void get_current_position (int *pos, int *line, int *col);
+  QString comment_string ();
 
 signals: