changeset 19543:c364b9a44580 gui-release

provide an editor lexer for text or unknown files (bug #43572) * default-qt-settings.in: fix color for numbers in bash files, add defaults for the new text lexer * file-editor-tab.cc (update_lexer): only select the bash lexer for .sh-files, select the new text lexer for .m-files or unnamed files if octave and matlab lexer is not available as well as for files with no or unknown extension * octave-txt-lexer.h: new lexer class derived from QsciLexer just providing the default style for text or unknown files * octave-txt-lexer.cc (language, description): implemented functions * module.mk: added new files octave-txt-lexer.cc/.h * settings-dialog.cc (constructor): read the settings for the new text lexer; (write-changed-settings): write settings for the new lexer into the files
author Torsten <ttl@justmail.de>
date Sun, 23 Nov 2014 13:13:35 +0100
parents 2a790328fc50
children 98c7fa559d75
files libgui/default-qt-settings.in libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/octave-txt-lexer.cc libgui/src/m-editor/octave-txt-lexer.h libgui/src/module.mk libgui/src/settings-dialog.cc
diffstat 6 files changed, 125 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/libgui/default-qt-settings.in
+++ b/libgui/default-qt-settings.in
@@ -550,10 +550,10 @@
 Bash\style2\eolfill=false
 Bash\style2\font=__default_font__, __default_font_size__, 0, 0, 0
 Bash\style2\paper=16777215
-Bash\style3\color=11184640
+Bash\style3\color=43647
 Bash\style3\eolfill=false
 Bash\style3\font=__default_font__, __default_font_size__, 0, 0, 0
-Bash\style3\paper=16711680
+Bash\style0\paper=16777215
 Bash\style4\color=127
 Bash\style4\eolfill=false
 Bash\style4\font=__default_font__, __default_font_size__, 1, 0, 0
@@ -600,3 +600,11 @@
 Bash\defaultpaper=16777215
 Bash\defaultfont=__default_font__, __default_font_size__, 0, 0, 0
 Bash\autoindentstyle=-1
+Text\style0\color=0
+Text\style0\eolfill=false
+Text\style0\font=__default_font__, __default_font_size__, 0, 0, 0
+Text\style0\paper=16777215
+Text\defaultcolor=0
+Text\defaultpaper=16777215
+Text\defaultfont=__default_font__, __default_font_size__, 0, 0, 0
+Text\autoindentstyle=-1
--- a/libgui/src/m-editor/file-editor-tab.cc
+++ b/libgui/src/m-editor/file-editor-tab.cc
@@ -52,6 +52,7 @@
 
 #include "file-editor-tab.h"
 #include "file-editor.h"
+#include "octave-txt-lexer.h"
 
 #include "file-ops.h"
 
@@ -396,6 +397,8 @@
       lexer = new QsciLexerOctave ();
 #elif defined (HAVE_LEXER_MATLAB)
       lexer = new QsciLexerMatlab ();
+#else
+      lexer = new octave_txt_lexer ();
 #endif
       _is_octave_file = true;
     }
@@ -426,6 +429,10 @@
         {
           lexer = new QsciLexerDiff ();
         }
+      else if (_file_name.endsWith (".sh"))
+        {
+          lexer = new QsciLexerBash ();
+        }
       else if (! valid_file_name ())
         {
           // new, no yet named file: let us assume it is octave
@@ -436,13 +443,13 @@
           lexer = new QsciLexerMatlab ();
           _is_octave_file = true;
 #else
-          lexer = new QsciLexerBash ();
+          lexer = new octave_txt_lexer ();
 #endif
         }
       else
         {
           // other or no extension
-          lexer = new QsciLexerBash ();
+          lexer = new octave_txt_lexer ();
         }
     }
 
new file mode 100644
--- /dev/null
+++ b/libgui/src/m-editor/octave-txt-lexer.cc
@@ -0,0 +1,52 @@
+/*
+
+Copyright (C) 2014 Torsten
+
+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
+<http://www.gnu.org/licenses/>.
+
+*/
+
+// Author: Torsten <ttl@justmail.de>
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#ifdef HAVE_QSCINTILLA
+
+#include <Qsci/qscilexer.h>
+
+#include "octave-txt-lexer.h"
+
+QString
+octave_txt_lexer::description (int style) const
+{
+  if (style == 0)
+    return tr ("Default");
+  else
+    return QString ();
+};
+
+
+const char*
+octave_txt_lexer::language () const
+{
+  return "Text";
+}
+
+
+#endif
new file mode 100644
--- /dev/null
+++ b/libgui/src/m-editor/octave-txt-lexer.h
@@ -0,0 +1,43 @@
+/*
+
+Copyright (C) 2013 Torsten
+
+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
+<http://www.gnu.org/licenses/>.
+
+*/
+
+// Author: Torsten <ttl@justmail.de>
+
+#if !defined (octave_txt_lexer_h)
+#define octave_txt_lexer_h 1
+
+#include <Qsci/qsciscintilla.h>
+#include <Qsci/qscilexer.h>
+
+
+class octave_txt_lexer : public QsciLexer
+{
+  Q_OBJECT
+
+public:
+
+  virtual const char *language () const;
+  virtual QString description (int style) const;
+
+};
+
+#endif
\ No newline at end of file
--- a/libgui/src/module.mk
+++ b/libgui/src/module.mk
@@ -81,7 +81,8 @@
   src/m-editor/moc-file-editor-tab.cc \
   src/m-editor/moc-file-editor.cc \
   src/m-editor/moc-find-dialog.cc \
-  src/m-editor/moc-octave-qscintilla.cc
+  src/m-editor/moc-octave-qscintilla.cc \
+  src/m-editor/moc-octave-txt-lexer.cc
 endif
 
 octave_gui_MOC += \
@@ -126,6 +127,7 @@
   src/m-editor/file-editor.h \
   src/m-editor/find-dialog.h \
   src/m-editor/octave-qscintilla.h \
+  src/m-editor/octave-txt-lexer.h \
   src/main-window.h \
   src/octave-gui.h \
   src/octave-interpreter.h \
@@ -153,6 +155,7 @@
   src/m-editor/file-editor.cc \
   src/m-editor/find-dialog.cc \
   src/m-editor/octave-qscintilla.cc \
+  src/m-editor/octave-txt-lexer.cc \
   src/main-window.cc \
   src/octave-dock-widget.cc \
   src/octave-gui.cc \
--- a/libgui/src/settings-dialog.cc
+++ b/libgui/src/settings-dialog.cc
@@ -37,6 +37,7 @@
 
 #ifdef HAVE_QSCINTILLA
 #include "octave-qscintilla.h"
+#include "octave-txt-lexer.h"
 #include <QScrollArea>
 
 #if defined (HAVE_QSCI_QSCILEXEROCTAVE_H)
@@ -358,6 +359,9 @@
   lexer = new QsciLexerBash ();
   read_lexer_settings (lexer,settings);
   delete lexer;
+  lexer = new octave_txt_lexer ();
+  read_lexer_settings (lexer,settings);
+  delete lexer;
 #endif
 
   // which tab is the desired one?
@@ -757,6 +761,9 @@
   lexer = new QsciLexerBash ();
   write_lexer_settings (lexer,settings);
   delete lexer;
+  lexer = new octave_txt_lexer ();
+  write_lexer_settings (lexer,settings);
+  delete lexer;
 #endif
 
   // Workspace