diff options
author | Michele Calgaro <michele.calgaro@yahoo.it> | 2022-08-05 10:54:12 +0900 |
---|---|---|
committer | Michele Calgaro <michele.calgaro@yahoo.it> | 2022-08-05 11:10:14 +0900 |
commit | 430373ae38565e0d7f62b8fca0cbad73de73ec7f (patch) | |
tree | 670a7322ddd2732c8824b1fb73090b937e2a1f82 /src/UiGuiHighlighter.cpp | |
parent | d833de5bbe40d780fe02dc95d1c981a4b1007108 (diff) | |
download | universal-indent-gui-tqt-430373ae38565e0d7f62b8fca0cbad73de73ec7f.tar.gz universal-indent-gui-tqt-430373ae38565e0d7f62b8fca0cbad73de73ec7f.zip |
Format code using uncrustify
Signed-off-by: Michele Calgaro <michele.calgaro@yahoo.it>
Diffstat (limited to 'src/UiGuiHighlighter.cpp')
-rw-r--r--[-rwxr-xr-x] | src/UiGuiHighlighter.cpp | 840 |
1 files changed, 458 insertions, 382 deletions
diff --git a/src/UiGuiHighlighter.cpp b/src/UiGuiHighlighter.cpp index c5d7f85..7ee13e8 100755..100644 --- a/src/UiGuiHighlighter.cpp +++ b/src/UiGuiHighlighter.cpp @@ -36,9 +36,9 @@ #include <Qsci/qscilexercss.h> #include <Qsci/qscilexerd.h> #include <Qsci/qscilexerdiff.h> -#if ( TQSCINTILLA_VERSION >= 0x020300 ) -#include <Qsci/qscilexerfortran.h> -#include <Qsci/qscilexerfortran77.h> +#if (TQSCINTILLA_VERSION >= 0x020300) + #include <Qsci/qscilexerfortran.h> + #include <Qsci/qscilexerfortran77.h> #endif #include <Qsci/qscilexerhtml.h> #include <Qsci/qscilexeridl.h> @@ -46,32 +46,32 @@ #include <Qsci/qscilexerjavascript.h> #include <Qsci/qscilexerlua.h> #include <Qsci/qscilexermakefile.h> -#if ( TQSCINTILLA_VERSION >= 0x020300 ) -#include <Qsci/qscilexerpascal.h> +#if (TQSCINTILLA_VERSION >= 0x020300) + #include <Qsci/qscilexerpascal.h> #endif #include <Qsci/qscilexerperl.h> -#if ( TQSCINTILLA_VERSION >= 0x020300 ) -#include <Qsci/qscilexerpostscript.h> +#if (TQSCINTILLA_VERSION >= 0x020300) + #include <Qsci/qscilexerpostscript.h> #endif #include <Qsci/qscilexerpov.h> #include <Qsci/qscilexerproperties.h> #include <Qsci/qscilexerpython.h> #include <Qsci/qscilexerruby.h> -#if ( TQSCINTILLA_VERSION >= 0x020400 ) -#include <Qsci/qscilexerspice.h> +#if (TQSCINTILLA_VERSION >= 0x020400) + #include <Qsci/qscilexerspice.h> #endif #include <Qsci/qscilexersql.h> -#if ( TQSCINTILLA_VERSION >= 0x020300 ) -#include <Qsci/qscilexertcl.h> +#if (TQSCINTILLA_VERSION >= 0x020300) + #include <Qsci/qscilexertcl.h> #endif #include <Qsci/qscilexertex.h> -#if ( TQSCINTILLA_VERSION >= 0x020400 ) -#include <Qsci/qscilexerverilog.h> +#if (TQSCINTILLA_VERSION >= 0x020400) + #include <Qsci/qscilexerverilog.h> #endif #include <Qsci/qscilexervhdl.h> -#if ( TQSCINTILLA_VERSION >= 0x020300 ) -#include <Qsci/qscilexerxml.h> -#include <Qsci/qscilexeryaml.h> +#if (TQSCINTILLA_VERSION >= 0x020300) + #include <Qsci/qscilexerxml.h> + #include <Qsci/qscilexeryaml.h> #endif //! \defgroup grp_EditorComponent All concerning editor widget. @@ -85,444 +85,520 @@ /*! \brief The constructor initializes some regular expressions and keywords to identify cpp tokens */ -UiGuiHighlighter::UiGuiHighlighter(QsciScintilla *parent) : TQObject(parent) { - _qsciEditorParent = parent; - - // Create the highlighter _settings object from the UiGuiSyntaxHighlightConfig.ini file. - _settings = new TQSettings(SettingsPaths::getSettingsPath() + "/UiGuiSyntaxHighlightConfig.ini", TQSettings::IniFormat, this); - - _highlightningIsOn = true; - - _mapHighlighternameToExtension["Bash"] = TQStringList() << "sh"; - _mapHighlighternameToExtension["Batch"] = TQStringList() << "bat"; - _mapHighlighternameToExtension["CMake"] = TQStringList() << "cmake"; - _mapHighlighternameToExtension["C++"] = TQStringList() << "c" << "h" << "cpp" << "hpp" << "cxx" << "hxx"; - _mapHighlighternameToExtension["C#"] = TQStringList() << "cs"; - _mapHighlighternameToExtension["CSS"] = TQStringList() << "css"; - _mapHighlighternameToExtension["D"] = TQStringList() << "d"; - _mapHighlighternameToExtension["Diff"] = TQStringList() << "diff"; -#if ( TQSCINTILLA_VERSION >= 0x020300 ) - _mapHighlighternameToExtension["Fortran"] = TQStringList() << "f" << "for" << "f90"; - _mapHighlighternameToExtension["Fortran77"] = TQStringList() << "f77"; +UiGuiHighlighter::UiGuiHighlighter(QsciScintilla *parent) : + TQObject(parent) +{ + _qsciEditorParent = parent; + + // Create the highlighter _settings object from the UiGuiSyntaxHighlightConfig.ini file. + _settings = new TQSettings( + SettingsPaths::getSettingsPath() + "/UiGuiSyntaxHighlightConfig.ini", TQSettings::IniFormat, + this); + + _highlightningIsOn = true; + + _mapHighlighternameToExtension["Bash"] = TQStringList() << "sh"; + _mapHighlighternameToExtension["Batch"] = TQStringList() << "bat"; + _mapHighlighternameToExtension["CMake"] = TQStringList() << "cmake"; + _mapHighlighternameToExtension["C++"] = TQStringList() << "c" << "h" << "cpp" << "hpp" << + "cxx" << "hxx"; + _mapHighlighternameToExtension["C#"] = TQStringList() << "cs"; + _mapHighlighternameToExtension["CSS"] = TQStringList() << "css"; + _mapHighlighternameToExtension["D"] = TQStringList() << "d"; + _mapHighlighternameToExtension["Diff"] = TQStringList() << "diff"; +#if (TQSCINTILLA_VERSION >= 0x020300) + _mapHighlighternameToExtension["Fortran"] = TQStringList() << "f" << "for" << "f90"; + _mapHighlighternameToExtension["Fortran77"] = TQStringList() << "f77"; #endif - _mapHighlighternameToExtension["HTML"] = TQStringList() << "html" << "htm"; - _mapHighlighternameToExtension["IDL"] = TQStringList() << "idl"; - _mapHighlighternameToExtension["Java"] = TQStringList() << "java"; - _mapHighlighternameToExtension["JavaScript"] = TQStringList() << "js"; - _mapHighlighternameToExtension["LUA"] = TQStringList() << "lua"; - _mapHighlighternameToExtension["Makefile"] = TQStringList() << "makefile"; -#if ( TQSCINTILLA_VERSION >= 0x020300 ) - _mapHighlighternameToExtension["Pascal"] = TQStringList() << "pas"; + _mapHighlighternameToExtension["HTML"] = TQStringList() << "html" << "htm"; + _mapHighlighternameToExtension["IDL"] = TQStringList() << "idl"; + _mapHighlighternameToExtension["Java"] = TQStringList() << "java"; + _mapHighlighternameToExtension["JavaScript"] = TQStringList() << "js"; + _mapHighlighternameToExtension["LUA"] = TQStringList() << "lua"; + _mapHighlighternameToExtension["Makefile"] = TQStringList() << "makefile"; +#if (TQSCINTILLA_VERSION >= 0x020300) + _mapHighlighternameToExtension["Pascal"] = TQStringList() << "pas"; #endif - _mapHighlighternameToExtension["Perl"] = TQStringList() << "perl" << "pl" << "pm"; - _mapHighlighternameToExtension["PHP"] = TQStringList() << "php"; -#if ( TQSCINTILLA_VERSION >= 0x020300 ) - _mapHighlighternameToExtension["PostScript"] = TQStringList() << "ps" << "eps" << "pdf" << "ai" << "fh"; + _mapHighlighternameToExtension["Perl"] = TQStringList() << "perl" << "pl" << "pm"; + _mapHighlighternameToExtension["PHP"] = TQStringList() << "php"; +#if (TQSCINTILLA_VERSION >= 0x020300) + _mapHighlighternameToExtension["PostScript"] = TQStringList() << "ps" << "eps" << "pdf" << "ai" << + "fh"; #endif - _mapHighlighternameToExtension["POV"] = TQStringList() << "pov"; - _mapHighlighternameToExtension["Ini"] = TQStringList() << "ini"; - _mapHighlighternameToExtension["Python"] = TQStringList() << "py"; - _mapHighlighternameToExtension["Ruby"] = TQStringList() << "rub" << "rb"; -#if ( TQSCINTILLA_VERSION >= 0x020400 ) - _mapHighlighternameToExtension["Spice"] = TQStringList() << "cir"; + _mapHighlighternameToExtension["POV"] = TQStringList() << "pov"; + _mapHighlighternameToExtension["Ini"] = TQStringList() << "ini"; + _mapHighlighternameToExtension["Python"] = TQStringList() << "py"; + _mapHighlighternameToExtension["Ruby"] = TQStringList() << "rub" << "rb"; +#if (TQSCINTILLA_VERSION >= 0x020400) + _mapHighlighternameToExtension["Spice"] = TQStringList() << "cir"; #endif - _mapHighlighternameToExtension["SQL"] = TQStringList() << "sql"; -#if ( TQSCINTILLA_VERSION >= 0x020300 ) - _mapHighlighternameToExtension["TCL"] = TQStringList() << "tcl"; + _mapHighlighternameToExtension["SQL"] = TQStringList() << "sql"; +#if (TQSCINTILLA_VERSION >= 0x020300) + _mapHighlighternameToExtension["TCL"] = TQStringList() << "tcl"; #endif - _mapHighlighternameToExtension["TeX"] = TQStringList() << "tex"; -#if ( TQSCINTILLA_VERSION >= 0x020400 ) - _mapHighlighternameToExtension["Verilog"] = TQStringList() << "v" << "vh"; + _mapHighlighternameToExtension["TeX"] = TQStringList() << "tex"; +#if (TQSCINTILLA_VERSION >= 0x020400) + _mapHighlighternameToExtension["Verilog"] = TQStringList() << "v" << "vh"; #endif - _mapHighlighternameToExtension["VHDL"] = TQStringList() << "vhdl"; - _mapHighlighternameToExtension["XML"] = TQStringList() << "xml"; -#if ( TQSCINTILLA_VERSION >= 0x020300 ) - _mapHighlighternameToExtension["YAML"] = TQStringList() << "yaml"; + _mapHighlighternameToExtension["VHDL"] = TQStringList() << "vhdl"; + _mapHighlighternameToExtension["XML"] = TQStringList() << "xml"; +#if (TQSCINTILLA_VERSION >= 0x020300) + _mapHighlighternameToExtension["YAML"] = TQStringList() << "yaml"; #endif - _lexer = NULL; + _lexer = NULL; - // This code is only for testing. - /* - foreach(TQStringList extensionList, _mapHighlighternameToExtension.values() ) { - setLexerForExtension( extensionList.at(0) ); - } - */ + // This code is only for testing. + /* + foreach(TQStringList extensionList, _mapHighlighternameToExtension.values() ) { + setLexerForExtension( extensionList.at(0) ); + } + */ - // Set default highlighter to C++ highlighter. - setLexerForExtension( "cpp" ); + // Set default highlighter to C++ highlighter. + setLexerForExtension("cpp"); } - /*! \brief Returns the available highlighters as TQStringList. */ -TQStringList UiGuiHighlighter::getAvailableHighlighters() { - return _mapHighlighternameToExtension.keys(); +TQStringList UiGuiHighlighter::getAvailableHighlighters() +{ + return _mapHighlighternameToExtension.keys(); } - /*! \brief This slot handles signals coming from selecting another syntax highlighter. */ -void UiGuiHighlighter::setHighlighterByAction(TQAction* highlighterAction) { - TQString highlighterName = highlighterAction->text(); - setLexerForExtension( _mapHighlighternameToExtension[highlighterName].first() ); - //TODO: This is really no nice way. How do it better? - // Need to do this "text update" to update the syntax highlighting. Otherwise highlighting is wrong. - int scrollPos = _qsciEditorParent->verticalScrollBar()->value(); - _qsciEditorParent->setText( _qsciEditorParent->text() ); - _qsciEditorParent->verticalScrollBar()->setValue(scrollPos); +void UiGuiHighlighter::setHighlighterByAction(TQAction *highlighterAction) +{ + TQString highlighterName = highlighterAction->text(); + setLexerForExtension(_mapHighlighternameToExtension[highlighterName].first()); + //TODO: This is really no nice way. How do it better? + // Need to do this "text update" to update the syntax highlighting. Otherwise highlighting is + // wrong. + int scrollPos = _qsciEditorParent->verticalScrollBar()->value(); + _qsciEditorParent->setText(_qsciEditorParent->text()); + _qsciEditorParent->verticalScrollBar()->setValue(scrollPos); } - /*! \brief Turns the syntax parser on. */ -void UiGuiHighlighter::turnHighlightOn() { - _highlightningIsOn = true; - _qsciEditorParent->setLexer(_lexer); - readCurrentSettings(""); +void UiGuiHighlighter::turnHighlightOn() +{ + _highlightningIsOn = true; + _qsciEditorParent->setLexer(_lexer); + readCurrentSettings(""); } /*! \brief Turns the syntax parser off. */ -void UiGuiHighlighter::turnHighlightOff() { - _highlightningIsOn = false; - _qsciEditorParent->setLexer(); -#if defined(Q_OS_WIN) || defined(Q_OS_MAC) - _qsciEditorParent->setFont( TQFont("Courier", 10, TQFont::Normal) ); - _qsciEditorParent->setMarginsFont( TQFont("Courier", 10, TQFont::Normal) ); +void UiGuiHighlighter::turnHighlightOff() +{ + _highlightningIsOn = false; + _qsciEditorParent->setLexer(); +#if defined (Q_OS_WIN) || defined (Q_OS_MAC) + _qsciEditorParent->setFont(TQFont("Courier", 10, TQFont::Normal)); + _qsciEditorParent->setMarginsFont(TQFont("Courier", 10, TQFont::Normal)); #else - _qsciEditorParent->setFont( TQFont("Monospace", 10, TQFont::Normal) ); - _qsciEditorParent->setMarginsFont( TQFont("Monospace", 10, TQFont::Normal) ); + _qsciEditorParent->setFont(TQFont("Monospace", 10, TQFont::Normal)); + _qsciEditorParent->setMarginsFont(TQFont("Monospace", 10, TQFont::Normal)); #endif } - /*! \brief Read the settings for the current lexer from the settings file. */ -//TODO: Refactor this function so that the coding style and variable names suit better. -bool UiGuiHighlighter::readCurrentSettings( const char *prefix ) { - bool ok, flag, rc = true; - int num; - TQString key; - - // Reset lists containing fonts and colors for each style - _fontForStyles.clear(); - _colorForStyles.clear(); - - // Read the styles. - for (int i = 0; i < 128; ++i) { - // Ignore invalid styles. - if ( _lexer->description(i).isEmpty() ) - continue; - - key.sprintf( "%s/%s/style%d/", prefix, _lexer->language(), i ); - key.replace("+", "p"); - - // Read the foreground color. - ok = _settings->contains(key + "color"); - num = _settings->value(key + "color", 0).toInt(); - - if (ok) - setColor( TQColor((num >> 16) & 0xff, (num >> 8) & 0xff, num & 0xff), i ); - else - rc = false; - - // Read the end-of-line fill. - ok = _settings->contains(key + "eolfill"); - flag = _settings->value(key + "eolfill", false).toBool(); - - if (ok) - _lexer->setEolFill( flag, i ); - else - rc = false; - - // Read the font - TQStringList fdesc; - - ok = _settings->contains(key + "font"); - fdesc = _settings->value(key + "font").toStringList(); - if (ok && fdesc.count() == 5) { - TQFont f; - -#if defined(Q_OS_WIN) || defined(Q_OS_MAC) - f.setFamily(fdesc[0]); +//TODO: Refactor this function so that the coding style and variable names suit better. +bool UiGuiHighlighter::readCurrentSettings(const char *prefix) +{ + bool ok, flag, rc = true; + int num; + TQString key; + + // Reset lists containing fonts and colors for each style + _fontForStyles.clear(); + _colorForStyles.clear(); + + // Read the styles. + for (int i = 0; i < 128; ++i) + { + // Ignore invalid styles. + if (_lexer->description(i).isEmpty()) + { + continue; + } + + key.sprintf("%s/%s/style%d/", prefix, _lexer->language(), i); + key.replace("+", "p"); + + // Read the foreground color. + ok = _settings->contains(key + "color"); + num = _settings->value(key + "color", 0).toInt(); + + if (ok) + { + setColor(TQColor((num >> 16) & 0xff, (num >> 8) & 0xff, num & 0xff), i); + } + else + { + rc = false; + } + + // Read the end-of-line fill. + ok = _settings->contains(key + "eolfill"); + flag = _settings->value(key + "eolfill", false).toBool(); + + if (ok) + { + _lexer->setEolFill(flag, i); + } + else + { + rc = false; + } + + // Read the font + TQStringList fdesc; + + ok = _settings->contains(key + "font"); + fdesc = _settings->value(key + "font").toStringList(); + + if (ok && fdesc.count() == 5) + { + TQFont f; + +#if defined (Q_OS_WIN) || defined (Q_OS_MAC) + f.setFamily(fdesc[0]); #else - if ( fdesc[0].contains("courier", TQt::CaseInsensitive) ) - f.setFamily("Monospace"); - else - f.setFamily(fdesc[0]); + if (fdesc[0].contains("courier", TQt::CaseInsensitive)) + { + f.setFamily("Monospace"); + } + else + { + f.setFamily(fdesc[0]); + } #endif - f.setPointSize(fdesc[1].toInt()); - f.setBold(fdesc[2].toInt()); - f.setItalic(fdesc[3].toInt()); - f.setUnderline(fdesc[4].toInt()); - - setFont(f, i); - } - else - rc = false; - - // Read the background color. - ok = _settings->contains(key + "paper"); - num = _settings->value(key + "paper", 0).toInt(); - - if (ok) - _lexer->setPaper( TQColor((num >> 16) & 0xff, (num >> 8) & 0xff, num & 0xff), i ); - else - rc = false; - } - - // Read the properties. - key.sprintf( "%s/%s/properties/", prefix, _lexer->language() ); - - _lexer->refreshProperties(); - - return rc; + f.setPointSize(fdesc[1].toInt()); + f.setBold(fdesc[2].toInt()); + f.setItalic(fdesc[3].toInt()); + f.setUnderline(fdesc[4].toInt()); + + setFont(f, i); + } + else + { + rc = false; + } + + // Read the background color. + ok = _settings->contains(key + "paper"); + num = _settings->value(key + "paper", 0).toInt(); + + if (ok) + { + _lexer->setPaper(TQColor((num >> 16) & 0xff, (num >> 8) & 0xff, num & 0xff), i); + } + else + { + rc = false; + } + } + + // Read the properties. + key.sprintf("%s/%s/properties/", prefix, _lexer->language()); + + _lexer->refreshProperties(); + + return rc; } - /*! \brief Write the settings for the current lexer to the settings file. */ -void UiGuiHighlighter::writeCurrentSettings( const char *prefix ) { - TQString key; - - // Write the styles. - for (int i = 0; i < 128; ++i) { - // Ignore invalid styles. - if ( _lexer->description(i).isEmpty() ) - continue; - - int num; - TQColor c; - - key.sprintf( "%s/%s/style%d/", prefix, _lexer->language(), i ); - key.replace("+", "p"); - - // Write style name - _settings->setValue( key + "", _lexer->description(i) ); - - // Write the foreground color. - if ( _colorForStyles.contains(i) ) { - c = _colorForStyles[i]; - } - else { - c = _lexer->color(i); - } - num = (c.red() << 16) | (c.green() << 8) | c.blue(); - - _settings->setValue(key + "color", num); - - // Write the end-of-line fill. - _settings->setValue( key + "eolfill", _lexer->eolFill(i) ); - - // Write the font - TQStringList fdesc; - TQString fmt("%1"); - TQFont f; - - if ( _fontForStyles.contains(i) ) { - f = _fontForStyles[i]; - } - else { - f = _lexer->font(i); - } - - fdesc += f.family(); - fdesc += fmt.arg( f.pointSize() ); - - // The casts are for Borland. - fdesc += fmt.arg( (int)f.bold() ); - fdesc += fmt.arg( (int)f.italic() ); - fdesc += fmt.arg( (int)f.underline() ); - - _settings->setValue(key + "font", fdesc); - - // Write the background color. - c = _lexer->paper(i); - num = (c.red() << 16) | (c.green() << 8) | c.blue(); - - _settings->setValue(key + "paper", num); - } +void UiGuiHighlighter::writeCurrentSettings(const char *prefix) +{ + TQString key; + + // Write the styles. + for (int i = 0; i < 128; ++i) + { + // Ignore invalid styles. + if (_lexer->description(i).isEmpty()) + { + continue; + } + + int num; + TQColor c; + + key.sprintf("%s/%s/style%d/", prefix, _lexer->language(), i); + key.replace("+", "p"); + + // Write style name + _settings->setValue(key + "", _lexer->description(i)); + + // Write the foreground color. + if (_colorForStyles.contains(i)) + { + c = _colorForStyles[i]; + } + else + { + c = _lexer->color(i); + } + num = (c.red() << 16) | (c.green() << 8) | c.blue(); + + _settings->setValue(key + "color", num); + + // Write the end-of-line fill. + _settings->setValue(key + "eolfill", _lexer->eolFill(i)); + + // Write the font + TQStringList fdesc; + TQString fmt("%1"); + TQFont f; + + if (_fontForStyles.contains(i)) + { + f = _fontForStyles[i]; + } + else + { + f = _lexer->font(i); + } + + fdesc += f.family(); + fdesc += fmt.arg(f.pointSize()); + + // The casts are for Borland. + fdesc += fmt.arg((int)f.bold()); + fdesc += fmt.arg((int)f.italic()); + fdesc += fmt.arg((int)f.underline()); + + _settings->setValue(key + "font", fdesc); + + // Write the background color. + c = _lexer->paper(i); + num = (c.red() << 16) | (c.green() << 8) | c.blue(); + + _settings->setValue(key + "paper", num); + } } - /*! \brief Sets the \a color for the given \a style. */ -void UiGuiHighlighter::setColor(const TQColor &color, int style) { - _colorForStyles[style] = color; - _lexer->setColor( color, style ); +void UiGuiHighlighter::setColor(const TQColor &color, int style) +{ + _colorForStyles[style] = color; + _lexer->setColor(color, style); } - /*! \brief Sets the \a font for the given \a style. */ -void UiGuiHighlighter::setFont(const TQFont &font, int style) { - _fontForStyles[style] = font; - _lexer->setFont( font, style ); +void UiGuiHighlighter::setFont(const TQFont &font, int style) +{ + _fontForStyles[style] = font; + _lexer->setFont(font, style); } - /*! \brief Sets the to be used lexer by giving his name. */ -void UiGuiHighlighter::setLexerByName( TQString lexerName ) { - setLexerForExtension( _mapHighlighternameToExtension[lexerName].first() ); +void UiGuiHighlighter::setLexerByName(TQString lexerName) +{ + setLexerForExtension(_mapHighlighternameToExtension[lexerName].first()); } - /*! \brief Sets the proper highlighter / lexer for the given file \a extension. Returns the index of the used lexer in the list. */ -int UiGuiHighlighter::setLexerForExtension( TQString extension ) { - int indexOfHighlighter = 0; - extension = extension.toLower(); - - if ( _lexer != NULL ) { - writeCurrentSettings(""); - delete _lexer; - } - - if ( extension == "cpp" || extension == "hpp" || extension == "c" || extension == "h" || extension == "cxx" || extension == "hxx" ) { - _lexer = new QsciLexerCPP(); - } - else if ( extension == "sh" ) { - _lexer = new QsciLexerBash(); - } - else if ( extension == "bat" ) { - _lexer = new QsciLexerBatch(); - } - else if ( extension == "cmake" ) { - _lexer = new QsciLexerCMake(); - } - else if ( extension == "cs" ) { - _lexer = new QsciLexerCSharp(); - } - else if ( extension == "css" ) { - _lexer = new QsciLexerCSS(); - } - else if ( extension == "d" ) { - _lexer = new QsciLexerD(); - } - else if ( extension == "diff" ) { - _lexer = new QsciLexerDiff(); - } -#if ( TQSCINTILLA_VERSION >= 0x020300 ) - else if ( extension == "f" || extension == "for" || extension == "f90" ) { - _lexer = new QsciLexerFortran(); - } - else if ( extension == "f77" ) { - _lexer = new QsciLexerFortran77(); - } +int UiGuiHighlighter::setLexerForExtension(TQString extension) +{ + int indexOfHighlighter = 0; + extension = extension.toLower(); + + if (_lexer != NULL) + { + writeCurrentSettings(""); + delete _lexer; + } + + if (extension == "cpp" || extension == "hpp" || extension == "c" || extension == "h" || + extension == "cxx" || extension == "hxx") + { + _lexer = new QsciLexerCPP(); + } + else if (extension == "sh") + { + _lexer = new QsciLexerBash(); + } + else if (extension == "bat") + { + _lexer = new QsciLexerBatch(); + } + else if (extension == "cmake") + { + _lexer = new QsciLexerCMake(); + } + else if (extension == "cs") + { + _lexer = new QsciLexerCSharp(); + } + else if (extension == "css") + { + _lexer = new QsciLexerCSS(); + } + else if (extension == "d") + { + _lexer = new QsciLexerD(); + } + else if (extension == "diff") + { + _lexer = new QsciLexerDiff(); + } +#if (TQSCINTILLA_VERSION >= 0x020300) + else if (extension == "f" || extension == "for" || extension == "f90") + { + _lexer = new QsciLexerFortran(); + } + else if (extension == "f77") + { + _lexer = new QsciLexerFortran77(); + } #endif - else if ( extension == "html" || extension == "htm" ) { - _lexer = new QsciLexerHTML(); - } - else if ( extension == "idl" ) { - _lexer = new QsciLexerIDL(); - } - else if ( extension == "java" ) { - _lexer = new QsciLexerJava(); - } - else if ( extension == "js" ) { - _lexer = new QsciLexerJavaScript(); - } - else if ( extension == "lua" ) { - _lexer = new QsciLexerLua(); - } - else if ( extension == "makefile" ) { - _lexer = new QsciLexerMakefile(); - } -#if ( TQSCINTILLA_VERSION >= 0x020300 ) - else if ( extension == "pas" ) { - _lexer = new QsciLexerPascal(); - } + else if (extension == "html" || extension == "htm") + { + _lexer = new QsciLexerHTML(); + } + else if (extension == "idl") + { + _lexer = new QsciLexerIDL(); + } + else if (extension == "java") + { + _lexer = new QsciLexerJava(); + } + else if (extension == "js") + { + _lexer = new QsciLexerJavaScript(); + } + else if (extension == "lua") + { + _lexer = new QsciLexerLua(); + } + else if (extension == "makefile") + { + _lexer = new QsciLexerMakefile(); + } +#if (TQSCINTILLA_VERSION >= 0x020300) + else if (extension == "pas") + { + _lexer = new QsciLexerPascal(); + } #endif - else if ( extension == "perl" || extension == "pl" || extension == "pm" ) { - _lexer = new QsciLexerPerl(); - } - else if ( extension == "php" ) { - _lexer = new QsciLexerHTML(); - } -#if ( TQSCINTILLA_VERSION >= 0x020300 ) - else if ( extension == "ps" || extension == "eps" || extension == "pdf" || extension == "ai" || extension == "fh") { - _lexer = new QsciLexerPostScript(); - } + else if (extension == "perl" || extension == "pl" || extension == "pm") + { + _lexer = new QsciLexerPerl(); + } + else if (extension == "php") + { + _lexer = new QsciLexerHTML(); + } +#if (TQSCINTILLA_VERSION >= 0x020300) + else if (extension == "ps" || extension == "eps" || extension == "pdf" || extension == "ai" || + extension == "fh") + { + _lexer = new QsciLexerPostScript(); + } #endif - else if ( extension == "pov" ) { - _lexer = new QsciLexerPOV(); - } - else if ( extension == "ini" ) { - _lexer = new QsciLexerProperties(); - } - else if ( extension == "py" ) { - _lexer = new QsciLexerPython(); - } - else if ( extension == "rub" || extension == "rb" ) { - _lexer = new QsciLexerRuby(); - } -#if ( TQSCINTILLA_VERSION >= 0x020400 ) - else if ( extension == "spice?" ) { - _lexer = new QsciLexerSpice(); - } + else if (extension == "pov") + { + _lexer = new QsciLexerPOV(); + } + else if (extension == "ini") + { + _lexer = new QsciLexerProperties(); + } + else if (extension == "py") + { + _lexer = new QsciLexerPython(); + } + else if (extension == "rub" || extension == "rb") + { + _lexer = new QsciLexerRuby(); + } +#if (TQSCINTILLA_VERSION >= 0x020400) + else if (extension == "spice?") + { + _lexer = new QsciLexerSpice(); + } #endif - else if ( extension == "sql" ) { - _lexer = new QsciLexerSQL(); - } -#if ( TQSCINTILLA_VERSION >= 0x020300 ) - else if ( extension == "tcl" ) { - _lexer = new QsciLexerTCL(); - } + else if (extension == "sql") + { + _lexer = new QsciLexerSQL(); + } +#if (TQSCINTILLA_VERSION >= 0x020300) + else if (extension == "tcl") + { + _lexer = new QsciLexerTCL(); + } #endif - else if ( extension == "tex" ) { - _lexer = new QsciLexerTeX(); - } -#if ( TQSCINTILLA_VERSION >= 0x020400 ) - else if ( extension == "vlog?" ) { - _lexer = new QsciLexerVerilog(); - } + else if (extension == "tex") + { + _lexer = new QsciLexerTeX(); + } +#if (TQSCINTILLA_VERSION >= 0x020400) + else if (extension == "vlog?") + { + _lexer = new QsciLexerVerilog(); + } #endif - else if ( extension == "vhdl" ) { - _lexer = new QsciLexerVHDL(); - } - else if ( extension == "xml" ) { -#if ( TQSCINTILLA_VERSION >= 0x020300 ) - _lexer = new QsciLexerXML(); + else if (extension == "vhdl") + { + _lexer = new QsciLexerVHDL(); + } + else if (extension == "xml") + { +#if (TQSCINTILLA_VERSION >= 0x020300) + _lexer = new QsciLexerXML(); #else - _lexer = new QsciLexerHTML(); + _lexer = new QsciLexerHTML(); #endif - } -#if ( TQSCINTILLA_VERSION >= 0x020300 ) - else if ( extension == "yaml" ) { - _lexer = new QsciLexerYAML(); - } + } +#if (TQSCINTILLA_VERSION >= 0x020300) + else if (extension == "yaml") + { + _lexer = new QsciLexerYAML(); + } #endif - else { - _lexer = new QsciLexerCPP(); - extension = "cpp"; - } - - // Find the index of the selected _lexer. - indexOfHighlighter = 0; - while ( !_mapHighlighternameToExtension.values().at(indexOfHighlighter).contains(extension) ) { - indexOfHighlighter++; - } - - // Set the _lexer for the TQScintilla widget. - if ( _highlightningIsOn ) { - _qsciEditorParent->setLexer(_lexer); - } - - // Read the _settings for the _lexer properties from file. - readCurrentSettings(""); - - return indexOfHighlighter; + else + { + _lexer = new QsciLexerCPP(); + extension = "cpp"; + } + + // Find the index of the selected _lexer. + indexOfHighlighter = 0; + while (!_mapHighlighternameToExtension.values().at(indexOfHighlighter).contains(extension)) + { + indexOfHighlighter++; + } + + // Set the _lexer for the TQScintilla widget. + if (_highlightningIsOn) + { + _qsciEditorParent->setLexer(_lexer); + } + + // Read the _settings for the _lexer properties from file. + readCurrentSettings(""); + + return indexOfHighlighter; } |