# HG changeset patch # User John W. Eaton # Date 1368411706 14400 # Node ID 025bc6b5080e6b7c0531f893e61c611d053b5b9a # Parent 4258750c76eddedcd29e2f9a0f88c8db8a3fa688 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. diff -r 4258750c76ed -r 025bc6b5080e libgui/src/m-editor/file-editor-tab.cc --- a/libgui/src/m-editor/file-editor-tab.cc Sun May 12 21:05:19 2013 -0400 +++ b/libgui/src/m-editor/file-editor-tab.cc Sun May 12 22:21:46 2013 -0400 @@ -27,9 +27,7 @@ #ifdef HAVE_QSCINTILLA #include -// Not available in the Debian repos yet! -// #include -#include "lexer-octave-gui.h" +#include #include #include #include @@ -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") diff -r 4258750c76ed -r 025bc6b5080e libgui/src/m-editor/lexer-octave-gui.cc --- a/libgui/src/m-editor/lexer-octave-gui.cc Sun May 12 21:05:19 2013 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -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 -. - -*/ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#ifdef HAVE_QSCINTILLA - -#include "lexer-octave-gui.h" -#include -#include - -// ----------------------------------------------------- -// 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 diff -r 4258750c76ed -r 025bc6b5080e libgui/src/m-editor/lexer-octave-gui.h --- a/libgui/src/m-editor/lexer-octave-gui.h Sun May 12 21:05:19 2013 -0400 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -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 -. - -*/ - -#ifndef LEXEROCTAVE_H -#define LEXEROCTAVE_H - -#include "resource-manager.h" -#include -#include -#include -#include - -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 diff -r 4258750c76ed -r 025bc6b5080e libgui/src/module.mk --- a/libgui/src/module.mk Sun May 12 21:05:19 2013 -0400 +++ b/libgui/src/module.mk Sun May 12 22:21:46 2013 -0400 @@ -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 \ diff -r 4258750c76ed -r 025bc6b5080e libgui/src/settings-dialog.cc --- a/libgui/src/settings-dialog.cc Sun May 12 21:05:19 2013 -0400 +++ b/libgui/src/settings-dialog.cc Sun May 12 22:21:46 2013 -0400 @@ -35,6 +35,7 @@ #ifdef HAVE_QSCINTILLA #include +#include #include #include #include @@ -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 (); diff -r 4258750c76ed -r 025bc6b5080e libgui/src/settings-dialog.h --- a/libgui/src/settings-dialog.h Sun May 12 21:05:19 2013 -0400 +++ b/libgui/src/settings-dialog.h Sun May 12 22:21:46 2013 -0400 @@ -25,8 +25,9 @@ #include #include + #ifdef HAVE_QSCINTILLA -#include "lexer-octave-gui.h" +class QsciLexer; #endif namespace Ui