From 378cdeefd23599ebb8a90b3fec540c831b6cb81b Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Wed, 23 Nov 2022 14:57:26 +0800 Subject: [PATCH] work save --- RedPandaIDE/HighlighterManager.cpp | 10 +++---- RedPandaIDE/editor.cpp | 6 ++-- libs/qsynedit/qsynedit/Constants.h | 4 --- libs/qsynedit/qsynedit/MiscProcs.cpp | 6 ++-- libs/qsynedit/qsynedit/SynEdit.cpp | 6 ++-- libs/qsynedit/qsynedit/TextPainter.cpp | 2 +- libs/qsynedit/qsynedit/highlighter/asm.cpp | 10 ------- libs/qsynedit/qsynedit/highlighter/asm.h | 5 ---- libs/qsynedit/qsynedit/highlighter/base.h | 14 ++------- .../qsynedit/highlighter/composition.cpp | 15 ---------- .../qsynedit/highlighter/composition.h | 13 -------- libs/qsynedit/qsynedit/highlighter/cpp.cpp | 10 ------- libs/qsynedit/qsynedit/highlighter/cpp.h | 2 -- .../highlighter/customhighlighterv1.cpp | 23 ++++++++++++++ .../highlighter/customhighlighterv1.h | 30 +++++++++++++++++-- libs/qsynedit/qsynedit/highlighter/glsl.cpp | 10 ------- libs/qsynedit/qsynedit/highlighter/glsl.h | 2 -- 17 files changed, 67 insertions(+), 101 deletions(-) diff --git a/RedPandaIDE/HighlighterManager.cpp b/RedPandaIDE/HighlighterManager.cpp index b7402c8a..1b74d12d 100644 --- a/RedPandaIDE/HighlighterManager.cpp +++ b/RedPandaIDE/HighlighterManager.cpp @@ -67,11 +67,11 @@ QSynedit::PHighlighter HighlighterManager::copyHighlighter(QSynedit::PHighlighte { if (!highlighter) return QSynedit::PHighlighter(); - if (highlighter->getName() == SYN_HIGHLIGHTER_CPP) + if (highlighter->language() == QSynedit::HighlighterLanguage::Cpp) return getCppHighlighter(); - else if (highlighter->getName() == SYN_HIGHLIGHTER_ASM) + else if (highlighter->language() == QSynedit::HighlighterLanguage::Asssembly) return getAsmHighlighter(); - else if (highlighter->getName() == SYN_HIGHLIGHTER_GLSL) + else if (highlighter->language() == QSynedit::HighlighterLanguage::GLSL) return getGLSLHighlighter(); //todo return QSynedit::PHighlighter(); @@ -99,8 +99,8 @@ void HighlighterManager::applyColorScheme(QSynedit::PHighlighter highlighter, co { if (!highlighter) return; - if ( (highlighter->getName() == SYN_HIGHLIGHTER_CPP) - || (highlighter->getName() == SYN_HIGHLIGHTER_ASM) + if ( (highlighter->language() == QSynedit::HighlighterLanguage::Cpp) + || (highlighter->language() == QSynedit::HighlighterLanguage::Asssembly) ) { for (QString name: highlighter->attributes().keys()) { PColorSchemeItem item = pColorManager->getItem(schemeName,name); diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 8c16a192..f81adcb6 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -390,7 +390,7 @@ bool Editor::saveAs(const QString &name, bool fromProject){ setUseCodeFolding(false); } setHighlighter(newHighlighter); - if (!newHighlighter || newHighlighter->getName() != SYN_HIGHLIGHTER_CPP) { + if (!newHighlighter || newHighlighter->language() != QSynedit::HighlighterLanguage::Cpp) { mSyntaxIssues.clear(); } applyColorScheme(pSettings->editor().colorScheme()); @@ -2650,7 +2650,7 @@ void Editor::initParser() { if (pSettings->codeCompletion().shareParser()) { if (pSettings->codeCompletion().enabled() - && (highlighter() && highlighter()->getClass() == QSynedit::HighlighterClass::CppHighlighter) + && (highlighter() && highlighter()->language() == QSynedit::HighlighterLanguage::Cpp) ) { mParser = sharedParser(mUseCppSyntax?ParserLanguage::CPlusPlus:ParserLanguage::C); } @@ -2670,7 +2670,7 @@ void Editor::initParser() resetCppParser(mParser); mParser->setEnabled( pSettings->codeCompletion().enabled() && - (highlighter() && highlighter()->getClass() == QSynedit::HighlighterClass::CppHighlighter)); + (highlighter() && highlighter()->language() == QSynedit::HighlighterLanguage::Cpp)); } Editor::QuoteStatus Editor::getQuoteStatus() diff --git a/libs/qsynedit/qsynedit/Constants.h b/libs/qsynedit/qsynedit/Constants.h index 68be5332..c1c5d864 100644 --- a/libs/qsynedit/qsynedit/Constants.h +++ b/libs/qsynedit/qsynedit/Constants.h @@ -58,10 +58,6 @@ extern const QChar SoftBreakGlyph; #define SYNS_ExporterFormatRTF "RTF" #define SYNS_ExporterFormatTeX "TeX" -#define SYN_HIGHLIGHTER_CPP "SynCppHighlighter" -#define SYN_HIGHLIGHTER_ASM "SynASMHighlighter" -#define SYN_HIGHLIGHTER_GLSL "SynGLSLHighlighter" - } #endif // CONSTANTS_H diff --git a/libs/qsynedit/qsynedit/MiscProcs.cpp b/libs/qsynedit/qsynedit/MiscProcs.cpp index 3be7a781..061a777d 100644 --- a/libs/qsynedit/qsynedit/MiscProcs.cpp +++ b/libs/qsynedit/qsynedit/MiscProcs.cpp @@ -54,11 +54,9 @@ bool internalEnumHighlighterAttris(PHighlighter Highlighter, } else { HighlighterList.append(Highlighter); } - if (Highlighter->getClass() == HighlighterClass::Composition) { - //todo: handle composition highlighter - } else if (Highlighter) { + if (Highlighter) { for (PHighlighterAttribute pAttr: Highlighter->attributes()){ - QString UniqueAttriName = Highlighter->getName() + QString UniqueAttriName = Highlighter->languageName() + QString("%1").arg(HighlighterList.indexOf(Highlighter)) + '.' + pAttr->name(); Result = highlighterAttriProc(Highlighter, pAttr, diff --git a/libs/qsynedit/qsynedit/SynEdit.cpp b/libs/qsynedit/qsynedit/SynEdit.cpp index 850f044a..4b35a3e0 100644 --- a/libs/qsynedit/qsynedit/SynEdit.cpp +++ b/libs/qsynedit/qsynedit/SynEdit.cpp @@ -1619,13 +1619,13 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent) matchingIndents = rangeAfterFirstToken.matchingIndents; indentAdded = true; l = startLine; - } else if (mHighlighter->getClass() == HighlighterClass::CppHighlighter + } else if (mHighlighter->language() == HighlighterLanguage::Cpp && trimmedLineText.startsWith('#') && attr == ((CppHighlighter *)mHighlighter.get())->preprocessorAttribute()) { indentAdded = true; indentSpaces=0; l=0; - } else if (mHighlighter->getClass() == HighlighterClass::CppHighlighter + } else if (mHighlighter->language() == HighlighterLanguage::Cpp && mHighlighter->isLastLineCommentNotFinished(rangePreceeding.state) ) { // last line is a not finished comment, @@ -2906,7 +2906,7 @@ void SynEdit::doAddChar(QChar AChar) if (mActiveSelectionMode==SelectionMode::Normal && mOptions.testFlag(eoAutoIndent) && mHighlighter - && mHighlighter->getClass()==HighlighterClass::CppHighlighter + && mHighlighter->language() == HighlighterLanguage::Cpp && (oldCaretY<=mDocument->count()) ) { //unindent if ':' at end of the line diff --git a/libs/qsynedit/qsynedit/TextPainter.cpp b/libs/qsynedit/qsynedit/TextPainter.cpp index 41164317..81104980 100644 --- a/libs/qsynedit/qsynedit/TextPainter.cpp +++ b/libs/qsynedit/qsynedit/TextPainter.cpp @@ -766,7 +766,7 @@ void SynEditTextPainter::getBraceColorAttr(int level, PHighlighterAttribute &att { if (!edit->mOptions.testFlag(EditorOption::eoShowRainbowColor)) return; - if (!attr || attr->tokenType() != TokenType::Operator) + if (attr->tokenType() != TokenType::Operator) return; PHighlighterAttribute oldAttr = attr; switch(level % 4) { diff --git a/libs/qsynedit/qsynedit/highlighter/asm.cpp b/libs/qsynedit/qsynedit/highlighter/asm.cpp index b6c873c5..3ce97476 100644 --- a/libs/qsynedit/qsynedit/highlighter/asm.cpp +++ b/libs/qsynedit/qsynedit/highlighter/asm.cpp @@ -324,16 +324,6 @@ void ASMHighlighter::setLine(const QString &newLine, int lineNumber) next(); } -HighlighterClass ASMHighlighter::getClass() const -{ - return HighlighterClass::CppHighlighter; -} - -QString ASMHighlighter::getName() const -{ - return SYN_HIGHLIGHTER_CPP; -} - bool ASMHighlighter::getTokenFinished() const { return true; diff --git a/libs/qsynedit/qsynedit/highlighter/asm.h b/libs/qsynedit/qsynedit/highlighter/asm.h index f43adce8..fc087ddb 100644 --- a/libs/qsynedit/qsynedit/highlighter/asm.h +++ b/libs/qsynedit/qsynedit/highlighter/asm.h @@ -79,11 +79,6 @@ public: void next() override; void setLine(const QString &newLine, int lineNumber) override; - // SynHighlighter interface -public: - HighlighterClass getClass() const override; - QString getName() const override; - // SynHighlighter interface public: bool getTokenFinished() const override; diff --git a/libs/qsynedit/qsynedit/highlighter/base.h b/libs/qsynedit/qsynedit/highlighter/base.h index 7596ba00..ad28fa2f 100644 --- a/libs/qsynedit/qsynedit/highlighter/base.h +++ b/libs/qsynedit/qsynedit/highlighter/base.h @@ -74,18 +74,13 @@ enum class TokenType { Embeded //language embeded in others }; -enum class HighlighterClass { - Composition, - CppHighlighter, - AsmHighlighter, - GLSLHighlighter -}; - enum class HighlighterLanguage { DecideBySuffix, + Composition, Asssembly, Cpp, - GLSL + GLSL, + Custom }; class HighlighterAttribute { @@ -138,9 +133,6 @@ public: virtual bool isIdentChar(const QChar& ch) const; - virtual HighlighterClass getClass() const = 0; - virtual QString getName() const = 0; - virtual bool getTokenFinished() const = 0; virtual bool isLastLineCommentNotFinished(int state) const = 0; virtual bool isLastLineStringNotFinished(int state) const = 0; diff --git a/libs/qsynedit/qsynedit/highlighter/composition.cpp b/libs/qsynedit/qsynedit/highlighter/composition.cpp index 6aef3029..90063908 100644 --- a/libs/qsynedit/qsynedit/highlighter/composition.cpp +++ b/libs/qsynedit/qsynedit/highlighter/composition.cpp @@ -19,21 +19,6 @@ namespace QSynedit { -CompositedHighlighter::CompositedHighlighter() -{ - -} - -HighlighterClass CompositedHighlighter::getClass() const -{ - return HighlighterClass::Composition; -} - -QString CompositedHighlighter::getName() const -{ - return "SynHighlightComposition"; -} - HighlighterSchema::HighlighterSchema(QObject *parent): QObject(parent), mCaseSensitive(true) diff --git a/libs/qsynedit/qsynedit/highlighter/composition.h b/libs/qsynedit/qsynedit/highlighter/composition.h index 94e22969..35716221 100644 --- a/libs/qsynedit/qsynedit/highlighter/composition.h +++ b/libs/qsynedit/qsynedit/highlighter/composition.h @@ -62,18 +62,5 @@ private slots: void MarkerAttriChanged(); }; - - -class CompositedHighlighter : public Highlighter -{ -public: - explicit CompositedHighlighter(); - - // SynHighligterBase interface -public: - HighlighterClass getClass() const override; - QString getName() const override; -}; - } #endif // SYNHIGHLIGHTCOMPOSITION_H diff --git a/libs/qsynedit/qsynedit/highlighter/cpp.cpp b/libs/qsynedit/qsynedit/highlighter/cpp.cpp index b86b1d1d..d10623b5 100644 --- a/libs/qsynedit/qsynedit/highlighter/cpp.cpp +++ b/libs/qsynedit/qsynedit/highlighter/cpp.cpp @@ -1607,16 +1607,6 @@ void CppHighlighter::resetState() mAsmStart = false; } -HighlighterClass CppHighlighter::getClass() const -{ - return HighlighterClass::CppHighlighter; -} - -QString CppHighlighter::getName() const -{ - return SYN_HIGHLIGHTER_CPP; -} - QString CppHighlighter::languageName() { return "cpp"; diff --git a/libs/qsynedit/qsynedit/highlighter/cpp.h b/libs/qsynedit/qsynedit/highlighter/cpp.h index d606644f..19ba426d 100644 --- a/libs/qsynedit/qsynedit/highlighter/cpp.h +++ b/libs/qsynedit/qsynedit/highlighter/cpp.h @@ -181,8 +181,6 @@ public: bool isKeyword(const QString &word) override; void setState(const HighlighterState& rangeState) override; void resetState() override; - HighlighterClass getClass() const override; - QString getName() const override; QString languageName() override; HighlighterLanguage language() override; diff --git a/libs/qsynedit/qsynedit/highlighter/customhighlighterv1.cpp b/libs/qsynedit/qsynedit/highlighter/customhighlighterv1.cpp index 9000e78e..8a601b83 100644 --- a/libs/qsynedit/qsynedit/highlighter/customhighlighterv1.cpp +++ b/libs/qsynedit/qsynedit/highlighter/customhighlighterv1.cpp @@ -5,4 +5,27 @@ CustomHighlighterV1::CustomHighlighterV1() { } + +void CustomHighlighterV1::resetState() +{ + mRange.state = RangeState::rsUnknown; + mRange.braceLevel = 0; + mRange.bracketLevel = 0; + mRange.parenthesisLevel = 0; + mRange.leftBraces = 0; + mRange.rightBraces = 0; + mRange.indents.clear(); + mRange.firstIndentThisLine = 0; + mRange.matchingIndents.clear(); +} + +QString CustomHighlighterV1::languageName() +{ + return mLanguageName; +} + +HighlighterLanguage CustomHighlighterV1::language() +{ + return HighlighterLanguage::Custom; +} } diff --git a/libs/qsynedit/qsynedit/highlighter/customhighlighterv1.h b/libs/qsynedit/qsynedit/highlighter/customhighlighterv1.h index 290fb5f4..8b9604ee 100644 --- a/libs/qsynedit/qsynedit/highlighter/customhighlighterv1.h +++ b/libs/qsynedit/qsynedit/highlighter/customhighlighterv1.h @@ -6,12 +6,36 @@ namespace QSynedit { class CustomHighlighterV1:public Highlighter { public: - CustomHighlighterV1(); + enum RangeState { + rsUnknown, rsComment, rsInlineComment, + rsString, rsMultiLineString, + rsRawString, rsSpace, + }; + CustomHighlighterV1(); +// bool getTokenFinished() const override; +// bool isLastLineCommentNotFinished(int state) const override; +// bool isLastLineStringNotFinished(int state) const override; +// bool eol() const override; +// QString getToken() const override; +// PHighlighterAttribute getTokenAttribute() const override; +// int getTokenPos() override; +// void next() override; +// void setLine(const QString &newLine, int lineNumber) override; +// bool isKeyword(const QString &word) override; +// void setState(const HighlighterState& rangeState) override; + void resetState() override; + + QString languageName() override; + HighlighterLanguage language() override; protected: bool mIgnoreCase; + QString mCommentBlockStart; + QString mCommentBlockEnd; + QString mInlineCommentStart; + QSet mTypeKeywords; - QSet mCallableKeywords; + QSet mFunctionKeywords; QSet mKeywords1; QSet mKeywords2; QSet mKeywords3; @@ -19,10 +43,10 @@ protected: QSet mKeywords5; QSet mKeywords6; QSet mOperators; + QString mLanguageName; QSet mSuffixes; - HighlighterState mRange; // SynRangeState mSpaceRange; QString mLine; diff --git a/libs/qsynedit/qsynedit/highlighter/glsl.cpp b/libs/qsynedit/qsynedit/highlighter/glsl.cpp index 19dadc5a..5cf6ad9e 100644 --- a/libs/qsynedit/qsynedit/highlighter/glsl.cpp +++ b/libs/qsynedit/qsynedit/highlighter/glsl.cpp @@ -1447,16 +1447,6 @@ void GLSLHighlighter::resetState() mAsmStart = false; } -HighlighterClass GLSLHighlighter::getClass() const -{ - return HighlighterClass::GLSLHighlighter; -} - -QString GLSLHighlighter::getName() const -{ - return SYN_HIGHLIGHTER_GLSL; -} - QString GLSLHighlighter::languageName() { return "glsl"; diff --git a/libs/qsynedit/qsynedit/highlighter/glsl.h b/libs/qsynedit/qsynedit/highlighter/glsl.h index 89af6b08..0668de48 100644 --- a/libs/qsynedit/qsynedit/highlighter/glsl.h +++ b/libs/qsynedit/qsynedit/highlighter/glsl.h @@ -177,8 +177,6 @@ public: bool isKeyword(const QString &word) override; void setState(const HighlighterState& rangeState) override; void resetState() override; - HighlighterClass getClass() const override; - QString getName() const override; QString languageName() override; HighlighterLanguage language() override;