Mercurial > hg > octave-nkf
changeset 16646:025bc6b5080e
use QScintilla's lexer for highlighting Octave programs
* file-editor-tab.cc: Include Qsci/qscilexeroctave.h instead of
lexer-octave-gui.h.
(file_editor_tab::update_lexer): Use QsciLexerOctave instead of
lexer_octave_gui.
* settings-dialog.h: Use forward declaration for QsciLexer.
* settings-dialog.cc: Include Qsci/qscilexeroctave.h instead of
lexer-octave-gui.h.
(settings_dialog::settings_dialog): Use QsciLexerOctave instead of
lexer_octave_gui.
* lexer-octave-gui.h, lexer-octave-gui.cc: Delete.
* libgui/src/module.mk: Update file lists.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sun, 12 May 2013 22:21:46 -0400 |
parents | 4258750c76ed |
children | d446e99f89f7 |
files | libgui/src/m-editor/file-editor-tab.cc libgui/src/m-editor/lexer-octave-gui.cc libgui/src/m-editor/lexer-octave-gui.h libgui/src/module.mk libgui/src/settings-dialog.cc libgui/src/settings-dialog.h |
diffstat | 6 files changed, 8 insertions(+), 263 deletions(-) [+] |
line wrap: on
line diff
--- a/libgui/src/m-editor/file-editor-tab.cc +++ b/libgui/src/m-editor/file-editor-tab.cc @@ -27,9 +27,7 @@ #ifdef HAVE_QSCINTILLA #include <Qsci/qsciapis.h> -// Not available in the Debian repos yet! -// #include <Qsci/qscilexeroctave.h> -#include "lexer-octave-gui.h" +#include <Qsci/qscilexeroctave.h> #include <Qsci/qscilexercpp.h> #include <Qsci/qscilexerbash.h> #include <Qsci/qscilexerperl.h> @@ -215,7 +213,7 @@ || _file_name.endsWith (".M") || _file_name.endsWith ("octaverc")) { - lexer = new lexer_octave_gui (); + lexer = new QsciLexerOctave (); } else if (_file_name.endsWith (".c") || _file_name.endsWith (".cc")
deleted file mode 100644 --- a/libgui/src/m-editor/lexer-octave-gui.cc +++ /dev/null @@ -1,185 +0,0 @@ -/* - -Copyright (C) 2011-2012 Jacob Dawid - -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/>. - -*/ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#ifdef HAVE_QSCINTILLA - -#include "lexer-octave-gui.h" -#include <qcolor.h> -#include <qfont.h> - -// ----------------------------------------------------- -// Some basic functions -// ----------------------------------------------------- -lexer_octave_gui::lexer_octave_gui (QObject *p) - : QsciLexer (p) -{ - // The API info that is used for auto completion - // TODO: Where to store a file with API info (raw or prepared?)? - // TODO: Also provide infos on octave-forge functions? - // TODO: Also provide infos on function parameters? - // By now, use the keywords-list from syntax highlighting - QString keyword; - QStringList keywordList; - keyword = this->keywords (1); // get whole string with all keywords - keywordList = keyword.split (QRegExp ("\\s+")); // split into single strings - lexer_api = new QsciAPIs (this); - if (lexer_api) - { - for (int i = 0; i < keywordList.size (); i++) // add all keywords to API - lexer_api->add (keywordList.at (i)); - lexer_api->prepare (); // prepare API info ... this may take some time - } -} - -lexer_octave_gui::~lexer_octave_gui() -{ - if (lexer_api) - delete lexer_api; -} - -// ----------------------------------------------------------------------------- -// Redefined functions to make an octave lexer from the abtract class Qscilexer. -// Scintilla has an octave/matlab-lexer but the interface in Qscintilla is -// only available in version 2.5.1. Redefining the following purely virtual -// functions of the class QsciLexer () and the enum of available styles (see -// lexer-octave-gui.h provides the functionality of the octave lexer. -// ----------------------------------------------------------------------------- -const char * -lexer_octave_gui::language() const -{ - return "Octave"; // return the name of the language -} - -const char * -lexer_octave_gui::lexer() const -{ - return "octave"; // return the name of the lexer -} - -QString -lexer_octave_gui::description(int style) const -{ - switch (style) - { - case Default: - return tr("Default"); - case Comment: - return tr("Comment"); - case Command: - return tr("Command"); - case Number: - return tr("Number"); - case Keyword: - return tr("Keyword"); - case SingleQuotedString: - return tr("Single-quoted string"); - case Operator: - return tr("Operator"); - case Identifier: - return tr("Identifier"); - case DoubleQuotedString: - return tr("Double-quoted string"); - } - return QString(); // no valid style, return empty string -} - - -// ----------------------------------------------------- -// The set of default colors -// ----------------------------------------------------- -QColor -lexer_octave_gui::defaultColor (int style) const -{ - switch (style) - { - case Default: - case Operator: - return QColor (0x00,0x00,0x00); - - case Comment: - return QColor (0x00,0x7f,0x00); - - case Command: - return QColor (0x7f,0x7f,0x00); - - case Number: - return QColor (0x00,0x7f,0x7f); - - case Keyword: - return QColor (0x00,0x00,0x7f); - - case SingleQuotedString: - case DoubleQuotedString: - return QColor (0x7f,0x00,0x7f); - } - - return QsciLexer::defaultColor (style); -} - -// ----------------------------------------------------- -// The defaulot fonts -// ----------------------------------------------------- -QFont -lexer_octave_gui::defaultFont (int style) const -{ - QFont f; - - switch (style) - { - case Keyword: - f = QsciLexer::defaultFont (style); - f.setBold(true); - break; - - default: - f = QsciLexer::defaultFont (style); - } - - return f; -} - -// ----------------------------------------------------- -// The style used for braces -// ----------------------------------------------------- -int -lexer_octave_gui::braceStyle() const -{ - return Operator; -} - -// ----------------------------------------------------- -// The set of keywords for highlighting -// ----------------------------------------------------- -const char * -lexer_octave_gui::keywords(int set) const -{ - if (set == 1) - return resource_manager::octave_keywords (); - - return 0; -} - -#endif
deleted file mode 100644 --- a/libgui/src/m-editor/lexer-octave-gui.h +++ /dev/null @@ -1,67 +0,0 @@ -/* - -Copyright (C) 2011-2012 Jacob Dawid - -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/>. - -*/ - -#ifndef LEXEROCTAVE_H -#define LEXEROCTAVE_H - -#include "resource-manager.h" -#include <QObject> -#include <Qsci/qsciglobal.h> -#include <Qsci/qscilexer.h> -#include <Qsci/qsciapis.h> - -class lexer_octave_gui : public QsciLexer -{ - Q_OBJECT - -public: - - enum { - Default = 0, - Comment = 1, - Command = 2, - Number = 3, - Keyword = 4, - SingleQuotedString = 5, - Operator = 6, - Identifier = 7, - DoubleQuotedString = 8 - }; - - - lexer_octave_gui (QObject *parent = 0); - ~lexer_octave_gui (); - virtual const char *keywords (int set) const; - virtual const char *lexer () const; - virtual const char *language () const; - QString description (int style) const; - QColor defaultColor (int style) const; - QFont defaultFont (int style) const; - int braceStyle() const; - -private: - lexer_octave_gui (const lexer_octave_gui &); - lexer_octave_gui &operator= (const lexer_octave_gui &); - QsciAPIs *lexer_api; -}; - -#endif
--- a/libgui/src/module.mk +++ b/libgui/src/module.mk @@ -69,8 +69,7 @@ src/m-editor/moc-file-editor-interface.cc \ 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-lexer-octave-gui.cc + src/m-editor/moc-find-dialog.cc endif octave_gui_MOC += \ @@ -111,7 +110,6 @@ src/m-editor/file-editor-tab.h \ src/m-editor/file-editor.h \ src/m-editor/find-dialog.h \ - src/m-editor/lexer-octave-gui.h \ src/main-window.h \ src/octave-gui.h \ src/octave-main-thread.h \ @@ -136,7 +134,6 @@ src/m-editor/file-editor-tab.cc \ src/m-editor/file-editor.cc \ src/m-editor/find-dialog.cc \ - src/m-editor/lexer-octave-gui.cc \ src/main-window.cc \ src/octave-gui.cc \ src/octave-main-thread.cc \
--- a/libgui/src/settings-dialog.cc +++ b/libgui/src/settings-dialog.cc @@ -35,6 +35,7 @@ #ifdef HAVE_QSCINTILLA #include <QScrollArea> +#include <Qsci/qscilexeroctave.h> #include <Qsci/qscilexercpp.h> #include <Qsci/qscilexerbash.h> #include <Qsci/qscilexerperl.h> @@ -136,7 +137,7 @@ #ifdef HAVE_QSCINTILLA // editor styles: create lexer, read settings, and create dialog elements QsciLexer *lexer; - lexer = new lexer_octave_gui (); + lexer = new QsciLexerOctave (); read_lexer_settings (lexer,settings); delete lexer; lexer = new QsciLexerCPP (); @@ -392,7 +393,7 @@ #ifdef HAVE_QSCINTILLA // editor styles: create lexer, get dialog contents, and write settings QsciLexer *lexer; - lexer = new lexer_octave_gui (); + lexer = new QsciLexerOctave (); write_lexer_settings (lexer,settings); delete lexer; lexer = new QsciLexerCPP ();