refactor highlighters
This commit is contained in:
parent
d0732b9989
commit
c4a41403bc
|
@ -1,38 +0,0 @@
|
||||||
/*
|
|
||||||
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
|
|
||||||
*
|
|
||||||
* This program 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.
|
|
||||||
*
|
|
||||||
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
|
||||||
*/
|
|
||||||
#ifndef HIGHLIGHTERMANAGER_H
|
|
||||||
#define HIGHLIGHTERMANAGER_H
|
|
||||||
#include "qsynedit/highlighter/base.h"
|
|
||||||
|
|
||||||
class HighlighterManager
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
HighlighterManager();
|
|
||||||
|
|
||||||
QSynedit::PHighlighter getHighlighter(QSynedit::ProgrammingLanguage language);
|
|
||||||
QSynedit::PHighlighter getHighlighter(const QString& filename);
|
|
||||||
QSynedit::PHighlighter copyHighlighter(QSynedit::PHighlighter highlighter);
|
|
||||||
QSynedit::PHighlighter getCppHighlighter();
|
|
||||||
QSynedit::PHighlighter getAsmHighlighter();
|
|
||||||
QSynedit::PHighlighter getGLSLHighlighter();
|
|
||||||
QSynedit::PHighlighter getMakefileHighlighter();
|
|
||||||
void applyColorScheme(QSynedit::PHighlighter highlighter, const QString& schemeName);
|
|
||||||
};
|
|
||||||
|
|
||||||
extern HighlighterManager highlighterManager;
|
|
||||||
|
|
||||||
#endif // HIGHLIGHTERMANAGER_H
|
|
|
@ -75,7 +75,6 @@ LIBS += advapi32.lib user32.lib
|
||||||
}
|
}
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
HighlighterManager.cpp \
|
|
||||||
autolinkmanager.cpp \
|
autolinkmanager.cpp \
|
||||||
caretlist.cpp \
|
caretlist.cpp \
|
||||||
codeformatter.cpp \
|
codeformatter.cpp \
|
||||||
|
@ -129,6 +128,7 @@ SOURCES += \
|
||||||
settingsdialog/toolsgitwidget.cpp \
|
settingsdialog/toolsgitwidget.cpp \
|
||||||
shortcutmanager.cpp \
|
shortcutmanager.cpp \
|
||||||
symbolusagemanager.cpp \
|
symbolusagemanager.cpp \
|
||||||
|
syntaxermanager.cpp \
|
||||||
thememanager.cpp \
|
thememanager.cpp \
|
||||||
todoparser.cpp \
|
todoparser.cpp \
|
||||||
toolsmanager.cpp \
|
toolsmanager.cpp \
|
||||||
|
@ -209,7 +209,6 @@ SOURCES += \
|
||||||
widgets/signalmessagedialog.cpp
|
widgets/signalmessagedialog.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
HighlighterManager.h \
|
|
||||||
SimpleIni.h \
|
SimpleIni.h \
|
||||||
autolinkmanager.h \
|
autolinkmanager.h \
|
||||||
caretlist.h \
|
caretlist.h \
|
||||||
|
@ -264,6 +263,7 @@ HEADERS += \
|
||||||
settingsdialog/toolsgitwidget.h \
|
settingsdialog/toolsgitwidget.h \
|
||||||
shortcutmanager.h \
|
shortcutmanager.h \
|
||||||
symbolusagemanager.h \
|
symbolusagemanager.h \
|
||||||
|
syntaxermanager.h \
|
||||||
thememanager.h \
|
thememanager.h \
|
||||||
todoparser.h \
|
todoparser.h \
|
||||||
toolsmanager.h \
|
toolsmanager.h \
|
||||||
|
|
|
@ -428,7 +428,7 @@ void ColorManager::loadSchemesInDir(const QString &dirName, bool isBundled, bool
|
||||||
|
|
||||||
void ColorManager::initItemDefines()
|
void ColorManager::initItemDefines()
|
||||||
{
|
{
|
||||||
//Highlighter colors
|
//Token highlight colors
|
||||||
addDefine(SYNS_AttrAssembler,
|
addDefine(SYNS_AttrAssembler,
|
||||||
QObject::tr("Assembler"),
|
QObject::tr("Assembler"),
|
||||||
QObject::tr("Syntax"),
|
QObject::tr("Syntax"),
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
#define COLORSCHEME_H
|
#define COLORSCHEME_H
|
||||||
|
|
||||||
#include <QColor>
|
#include <QColor>
|
||||||
#include "qsynedit/highlighter/base.h"
|
#include "qsynedit/syntaxer/syntaxer.h"
|
||||||
#include "parser/statementmodel.h"
|
#include "parser/statementmodel.h"
|
||||||
|
|
||||||
#define EXT_COLOR_SCHEME ".scheme"
|
#define EXT_COLOR_SCHEME ".scheme"
|
||||||
|
|
|
@ -22,7 +22,7 @@
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QTextCodec>
|
#include <QTextCodec>
|
||||||
#include "HighlighterManager.h"
|
#include "syntaxermanager.h"
|
||||||
#include "project.h"
|
#include "project.h"
|
||||||
|
|
||||||
CppRefacter::CppRefacter(QObject *parent) : QObject(parent)
|
CppRefacter::CppRefacter(QObject *parent) : QObject(parent)
|
||||||
|
@ -207,7 +207,7 @@ PSearchResultTreeItem CppRefacter::findOccurenceInFile(
|
||||||
QByteArray encoding;
|
QByteArray encoding;
|
||||||
editor.document()->loadFromFile(filename,ENCODING_AUTO_DETECT,encoding);
|
editor.document()->loadFromFile(filename,ENCODING_AUTO_DETECT,encoding);
|
||||||
}
|
}
|
||||||
editor.setHighlighter(HighlighterManager().getCppHighlighter());
|
editor.setSyntaxer(syntaxerManager.getCppSyntaxer());
|
||||||
int posY = 0;
|
int posY = 0;
|
||||||
while (posY < editor.document()->count()) {
|
while (posY < editor.document()->count()) {
|
||||||
QString line = editor.document()->getString(posY);
|
QString line = editor.document()->getString(posY);
|
||||||
|
@ -217,16 +217,16 @@ PSearchResultTreeItem CppRefacter::findOccurenceInFile(
|
||||||
}
|
}
|
||||||
|
|
||||||
if (posY == 0) {
|
if (posY == 0) {
|
||||||
editor.highlighter()->resetState();
|
editor.syntaxer()->resetState();
|
||||||
} else {
|
} else {
|
||||||
editor.highlighter()->setState(
|
editor.syntaxer()->setState(
|
||||||
editor.document()->ranges(posY-1));
|
editor.document()->ranges(posY-1));
|
||||||
}
|
}
|
||||||
editor.highlighter()->setLine(line,posY);
|
editor.syntaxer()->setLine(line,posY);
|
||||||
while (!editor.highlighter()->eol()) {
|
while (!editor.syntaxer()->eol()) {
|
||||||
int start = editor.highlighter()->getTokenPos() + 1;
|
int start = editor.syntaxer()->getTokenPos() + 1;
|
||||||
QString token = editor.highlighter()->getToken();
|
QString token = editor.syntaxer()->getToken();
|
||||||
QSynedit::PTokenAttribute attr = editor.highlighter()->getTokenAttribute();
|
QSynedit::PTokenAttribute attr = editor.syntaxer()->getTokenAttribute();
|
||||||
if (attr && attr->tokenType()==QSynedit::TokenType::Identifier) {
|
if (attr && attr->tokenType()==QSynedit::TokenType::Identifier) {
|
||||||
if (token == statement->command) {
|
if (token == statement->command) {
|
||||||
//same name symbol , test if the same statement;
|
//same name symbol , test if the same statement;
|
||||||
|
@ -253,7 +253,7 @@ PSearchResultTreeItem CppRefacter::findOccurenceInFile(
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
editor.highlighter()->next();
|
editor.syntaxer()->next();
|
||||||
}
|
}
|
||||||
posY++;
|
posY++;
|
||||||
}
|
}
|
||||||
|
@ -272,22 +272,22 @@ void CppRefacter::renameSymbolInFile(const QString &filename, const PStatement &
|
||||||
editor.document()->loadFromFile(filename,ENCODING_AUTO_DETECT,encoding);
|
editor.document()->loadFromFile(filename,ENCODING_AUTO_DETECT,encoding);
|
||||||
}
|
}
|
||||||
QStringList newContents;
|
QStringList newContents;
|
||||||
editor.setHighlighter(HighlighterManager().getCppHighlighter());
|
editor.setSyntaxer(syntaxerManager.getCppSyntaxer());
|
||||||
int posY = 0;
|
int posY = 0;
|
||||||
while (posY < editor.document()->count()) {
|
while (posY < editor.document()->count()) {
|
||||||
QString line = editor.document()->getString(posY);
|
QString line = editor.document()->getString(posY);
|
||||||
|
|
||||||
if (posY == 0) {
|
if (posY == 0) {
|
||||||
editor.highlighter()->resetState();
|
editor.syntaxer()->resetState();
|
||||||
} else {
|
} else {
|
||||||
editor.highlighter()->setState(
|
editor.syntaxer()->setState(
|
||||||
editor.document()->ranges(posY-1));
|
editor.document()->ranges(posY-1));
|
||||||
}
|
}
|
||||||
editor.highlighter()->setLine(line,posY);
|
editor.syntaxer()->setLine(line,posY);
|
||||||
QString newLine;
|
QString newLine;
|
||||||
while (!editor.highlighter()->eol()) {
|
while (!editor.syntaxer()->eol()) {
|
||||||
int start = editor.highlighter()->getTokenPos() + 1;
|
int start = editor.syntaxer()->getTokenPos() + 1;
|
||||||
QString token = editor.highlighter()->getToken();
|
QString token = editor.syntaxer()->getToken();
|
||||||
if (token == statement->command) {
|
if (token == statement->command) {
|
||||||
//same name symbol , test if the same statement;
|
//same name symbol , test if the same statement;
|
||||||
QSynedit::BufferCoord p;
|
QSynedit::BufferCoord p;
|
||||||
|
@ -305,7 +305,7 @@ void CppRefacter::renameSymbolInFile(const QString &filename, const PStatement &
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
newLine += token;
|
newLine += token;
|
||||||
editor.highlighter()->next();
|
editor.syntaxer()->next();
|
||||||
}
|
}
|
||||||
newContents.append(newLine);
|
newContents.append(newLine);
|
||||||
posY++;
|
posY++;
|
||||||
|
|
|
@ -29,8 +29,8 @@
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QMimeData>
|
#include <QMimeData>
|
||||||
#include "qsynedit/highlighter/cpp.h"
|
#include "qsynedit/syntaxer/cpp.h"
|
||||||
#include "HighlighterManager.h"
|
#include "syntaxermanager.h"
|
||||||
#include "qsynedit/exporter/synrtfexporter.h"
|
#include "qsynedit/exporter/synrtfexporter.h"
|
||||||
#include "qsynedit/exporter/synhtmlexporter.h"
|
#include "qsynedit/exporter/synhtmlexporter.h"
|
||||||
#include "qsynedit/Constants.h"
|
#include "qsynedit/Constants.h"
|
||||||
|
@ -105,17 +105,17 @@ Editor::Editor(QWidget *parent, const QString& filename,
|
||||||
mFilename = QString("untitled%1").arg(getNewFileNumber());
|
mFilename = QString("untitled%1").arg(getNewFileNumber());
|
||||||
}
|
}
|
||||||
QFileInfo fileInfo(mFilename);
|
QFileInfo fileInfo(mFilename);
|
||||||
QSynedit::PHighlighter highlighter;
|
QSynedit::PSyntaxer syntaxer;
|
||||||
if (!isNew) {
|
if (!isNew) {
|
||||||
loadFile();
|
loadFile();
|
||||||
highlighter = highlighterManager.getHighlighter(mFilename);
|
syntaxer = syntaxerManager.getSyntaxer(mFilename);
|
||||||
} else {
|
} else {
|
||||||
mFileEncoding = ENCODING_ASCII;
|
mFileEncoding = ENCODING_ASCII;
|
||||||
highlighter=highlighterManager.getCppHighlighter();
|
syntaxer=syntaxerManager.getCppSyntaxer();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (highlighter) {
|
if (syntaxer) {
|
||||||
setHighlighter(highlighter);
|
setSyntaxer(syntaxer);
|
||||||
setUseCodeFolding(true);
|
setUseCodeFolding(true);
|
||||||
} else {
|
} else {
|
||||||
setUseCodeFolding(false);
|
setUseCodeFolding(false);
|
||||||
|
@ -225,7 +225,7 @@ void Editor::loadFile(QString filename) {
|
||||||
default:
|
default:
|
||||||
mUseCppSyntax = pSettings->editor().defaultFileCpp();
|
mUseCppSyntax = pSettings->editor().defaultFileCpp();
|
||||||
}
|
}
|
||||||
if (highlighter()) {
|
if (syntaxer()) {
|
||||||
reparse(true);
|
reparse(true);
|
||||||
if (pSettings->editor().syntaxCheckWhenLineChanged()) {
|
if (pSettings->editor().syntaxCheckWhenLineChanged()) {
|
||||||
checkSyntaxInBack();
|
checkSyntaxInBack();
|
||||||
|
@ -382,15 +382,15 @@ bool Editor::saveAs(const QString &name, bool fromProject){
|
||||||
mUseCppSyntax = pSettings->editor().defaultFileCpp();
|
mUseCppSyntax = pSettings->editor().defaultFileCpp();
|
||||||
}
|
}
|
||||||
|
|
||||||
//update (reassign highlighter)
|
//update (reassign syntaxer)
|
||||||
QSynedit::PHighlighter newHighlighter = HighlighterManager().getHighlighter(mFilename);
|
QSynedit::PSyntaxer newSyntaxer = syntaxerManager.getSyntaxer(mFilename);
|
||||||
if (newHighlighter) {
|
if (newSyntaxer) {
|
||||||
setUseCodeFolding(true);
|
setUseCodeFolding(true);
|
||||||
} else {
|
} else {
|
||||||
setUseCodeFolding(false);
|
setUseCodeFolding(false);
|
||||||
}
|
}
|
||||||
setHighlighter(newHighlighter);
|
setSyntaxer(newSyntaxer);
|
||||||
if (!newHighlighter || newHighlighter->language() != QSynedit::ProgrammingLanguage::Cpp) {
|
if (!newSyntaxer || newSyntaxer->language() != QSynedit::ProgrammingLanguage::Cpp) {
|
||||||
mSyntaxIssues.clear();
|
mSyntaxIssues.clear();
|
||||||
}
|
}
|
||||||
applyColorScheme(pSettings->editor().colorScheme());
|
applyColorScheme(pSettings->editor().colorScheme());
|
||||||
|
@ -483,11 +483,11 @@ void Editor::undoSymbolCompletion(int pos)
|
||||||
QString token;
|
QString token;
|
||||||
bool tokenFinished;
|
bool tokenFinished;
|
||||||
|
|
||||||
if (!highlighter())
|
if (!syntaxer())
|
||||||
return;
|
return;
|
||||||
if (!pSettings->editor().removeSymbolPairs())
|
if (!pSettings->editor().removeSymbolPairs())
|
||||||
return;
|
return;
|
||||||
if (!getHighlighterAttriAtRowCol(caretXY(), token, tokenFinished, attr))
|
if (!getTokenAttriAtRowCol(caretXY(), token, tokenFinished, attr))
|
||||||
return;
|
return;
|
||||||
if ((attr->tokenType() == QSynedit::TokenType::Comment) && (!tokenFinished))
|
if ((attr->tokenType() == QSynedit::TokenType::Comment) && (!tokenFinished))
|
||||||
return ;
|
return ;
|
||||||
|
@ -635,9 +635,9 @@ void Editor::keyPressEvent(QKeyEvent *event)
|
||||||
insertString.append(" */");
|
insertString.append(" */");
|
||||||
}
|
}
|
||||||
insertCodeSnippet(linesToText(insertString));
|
insertCodeSnippet(linesToText(insertString));
|
||||||
} else if (highlighter()
|
} else if (syntaxer()
|
||||||
&& caretY()>=2
|
&& caretY()>=2
|
||||||
&& highlighter()->isLastLineCommentNotFinished(
|
&& syntaxer()->isLastLineCommentNotFinished(
|
||||||
document()->ranges(caretY()-2).state)) {
|
document()->ranges(caretY()-2).state)) {
|
||||||
s=trimLeft(lineText());
|
s=trimLeft(lineText());
|
||||||
if (s.startsWith("* ")) {
|
if (s.startsWith("* ")) {
|
||||||
|
@ -917,7 +917,7 @@ void Editor::onGetEditingAreas(int Line, QSynedit::EditingAreaList &areaList)
|
||||||
// int spaceBefore = mLineBeforeTabStop.length()-TrimLeft(mLineBeforeTabStop).length();
|
// int spaceBefore = mLineBeforeTabStop.length()-TrimLeft(mLineBeforeTabStop).length();
|
||||||
p->beginX = mTabStopBegin;
|
p->beginX = mTabStopBegin;
|
||||||
p->endX = mTabStopEnd;
|
p->endX = mTabStopEnd;
|
||||||
p->color = highlighter()->stringAttribute()->foreground();
|
p->color = syntaxer()->stringAttribute()->foreground();
|
||||||
areaList.append(p);
|
areaList.append(p);
|
||||||
}
|
}
|
||||||
PSyntaxIssueList lst = getSyntaxIssuesAtLine(Line);
|
PSyntaxIssueList lst = getSyntaxIssuesAtLine(Line);
|
||||||
|
@ -966,7 +966,7 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
|
||||||
if (token.isEmpty())
|
if (token.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (mParser && highlighter()) {
|
if (mParser && syntaxer()) {
|
||||||
QString lineText = document()->getString(line-1);
|
QString lineText = document()->getString(line-1);
|
||||||
if (mParser->isIncludeLine(lineText)) {
|
if (mParser->isIncludeLine(lineText)) {
|
||||||
if (cursor() == Qt::PointingHandCursor) {
|
if (cursor() == Qt::PointingHandCursor) {
|
||||||
|
@ -1018,7 +1018,7 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
|
||||||
style.setFlag(QSynedit::FontStyle::fsUnderline,item->underlined());
|
style.setFlag(QSynedit::FontStyle::fsUnderline,item->underlined());
|
||||||
style.setFlag(QSynedit::FontStyle::fsStrikeOut,item->strikeout());
|
style.setFlag(QSynedit::FontStyle::fsStrikeOut,item->strikeout());
|
||||||
} else {
|
} else {
|
||||||
foreground = highlighter()->identifierAttribute()->foreground();
|
foreground = syntaxer()->identifierAttribute()->foreground();
|
||||||
}
|
}
|
||||||
if (cursor() == Qt::PointingHandCursor) {
|
if (cursor() == Qt::PointingHandCursor) {
|
||||||
QSynedit::BufferCoord p;
|
QSynedit::BufferCoord p;
|
||||||
|
@ -1032,14 +1032,14 @@ void Editor::onPreparePaintHighlightToken(int line, int aChar, const QString &to
|
||||||
}
|
}
|
||||||
|
|
||||||
//selection
|
//selection
|
||||||
if (highlighter() && attr) {
|
if (syntaxer() && attr) {
|
||||||
if (attr->tokenType() == QSynedit::TokenType::Keyword) {
|
if (attr->tokenType() == QSynedit::TokenType::Keyword) {
|
||||||
if (CppTypeKeywords.contains(token)
|
if (CppTypeKeywords.contains(token)
|
||||||
||
|
||
|
||||||
(
|
(
|
||||||
highlighter()->language()==QSynedit::ProgrammingLanguage::Cpp
|
syntaxer()->language()==QSynedit::ProgrammingLanguage::Cpp
|
||||||
&&
|
&&
|
||||||
((QSynedit::CppHighlighter*)highlighter().get())->customTypeKeywords().contains(token)
|
((QSynedit::CppSyntaxer*)syntaxer().get())->customTypeKeywords().contains(token)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
|
@ -1481,12 +1481,12 @@ void Editor::copyAsHTML()
|
||||||
exporter.setExportAsText(false);
|
exporter.setExportAsText(false);
|
||||||
exporter.setUseBackground(pSettings->editor().copyHTMLUseBackground());
|
exporter.setUseBackground(pSettings->editor().copyHTMLUseBackground());
|
||||||
exporter.setFont(font());
|
exporter.setFont(font());
|
||||||
QSynedit::PHighlighter hl = highlighter();
|
QSynedit::PSyntaxer hl = syntaxer();
|
||||||
if (!pSettings->editor().copyHTMLUseEditorColor()) {
|
if (!pSettings->editor().copyHTMLUseEditorColor()) {
|
||||||
hl = highlighterManager.copyHighlighter(highlighter());
|
hl = syntaxerManager.copy(syntaxer());
|
||||||
highlighterManager.applyColorScheme(hl,pSettings->editor().copyHTMLColorScheme());
|
syntaxerManager.applyColorScheme(hl,pSettings->editor().copyHTMLColorScheme());
|
||||||
}
|
}
|
||||||
exporter.setHighlighter(hl);
|
exporter.setSyntaxer(hl);
|
||||||
exporter.setOnFormatToken(std::bind(&Editor::onExportedFormatToken,
|
exporter.setOnFormatToken(std::bind(&Editor::onExportedFormatToken,
|
||||||
this,
|
this,
|
||||||
std::placeholders::_1,
|
std::placeholders::_1,
|
||||||
|
@ -1541,7 +1541,7 @@ void Editor::addSyntaxIssues(int line, int startChar, int endChar, CompileIssueT
|
||||||
start = 1;
|
start = 1;
|
||||||
token = document()->getString(line-1);
|
token = document()->getString(line-1);
|
||||||
} else if (endChar < 1) {
|
} else if (endChar < 1) {
|
||||||
if (!getHighlighterAttriAtRowColEx(p,token,start,attr))
|
if (!getTokenAttriAtRowColEx(p,token,start,attr))
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
start = startChar;
|
start = startChar;
|
||||||
|
@ -1699,7 +1699,7 @@ void Editor::onStatusChanged(QSynedit::StatusChanges changes)
|
||||||
clearUserCodeInTabStops();
|
clearUserCodeInTabStops();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (!selAvail() && highlighter() && pSettings->editor().highlightMathingBraces()){
|
} else if (!selAvail() && syntaxer() && pSettings->editor().highlightMathingBraces()){
|
||||||
invalidateLine(mHighlightCharPos1.line);
|
invalidateLine(mHighlightCharPos1.line);
|
||||||
invalidateLine(mHighlightCharPos2.line);
|
invalidateLine(mHighlightCharPos2.line);
|
||||||
mHighlightCharPos1 = QSynedit::BufferCoord{0,0};
|
mHighlightCharPos1 = QSynedit::BufferCoord{0,0};
|
||||||
|
@ -1720,7 +1720,7 @@ void Editor::onStatusChanged(QSynedit::StatusChanges changes)
|
||||||
}
|
}
|
||||||
QSynedit::PTokenAttribute attr;
|
QSynedit::PTokenAttribute attr;
|
||||||
QString token;
|
QString token;
|
||||||
if (getHighlighterAttriAtRowCol(coord,token,attr)
|
if (getTokenAttriAtRowCol(coord,token,attr)
|
||||||
&& attr->tokenType() == QSynedit::TokenType::Operator) {
|
&& attr->tokenType() == QSynedit::TokenType::Operator) {
|
||||||
QSynedit::BufferCoord complementCharPos = getMatchingBracketEx(coord);
|
QSynedit::BufferCoord complementCharPos = getMatchingBracketEx(coord);
|
||||||
if (!foldHidesLine(coord.line)
|
if (!foldHidesLine(coord.line)
|
||||||
|
@ -1938,38 +1938,38 @@ QStringList Editor::getExpressionAtPosition(
|
||||||
const QSynedit::BufferCoord &pos)
|
const QSynedit::BufferCoord &pos)
|
||||||
{
|
{
|
||||||
QStringList result;
|
QStringList result;
|
||||||
if (!highlighter())
|
if (!syntaxer())
|
||||||
return result;
|
return result;
|
||||||
int line = pos.line-1;
|
int line = pos.line-1;
|
||||||
int ch = pos.ch-1;
|
int ch = pos.ch-1;
|
||||||
int symbolMatchingLevel = 0;
|
int symbolMatchingLevel = 0;
|
||||||
LastSymbolType lastSymbolType=LastSymbolType::None;
|
LastSymbolType lastSymbolType=LastSymbolType::None;
|
||||||
QSynedit::PHighlighter highlighter;
|
QSynedit::PSyntaxer syntaxer;
|
||||||
if (isNew())
|
if (isNew())
|
||||||
highlighter = highlighterManager.getCppHighlighter();
|
syntaxer = syntaxerManager.getCppSyntaxer();
|
||||||
else
|
else
|
||||||
highlighter = highlighterManager.getHighlighter(mFilename);
|
syntaxer = syntaxerManager.getSyntaxer(mFilename);
|
||||||
if (!highlighter)
|
if (!syntaxer)
|
||||||
return result;
|
return result;
|
||||||
while (true) {
|
while (true) {
|
||||||
if (line>=document()->count() || line<0)
|
if (line>=document()->count() || line<0)
|
||||||
break;
|
break;
|
||||||
QStringList tokens;
|
QStringList tokens;
|
||||||
if (line==0) {
|
if (line==0) {
|
||||||
highlighter->resetState();
|
syntaxer->resetState();
|
||||||
} else {
|
} else {
|
||||||
highlighter->setState(document()->ranges(line-1));
|
syntaxer->setState(document()->ranges(line-1));
|
||||||
}
|
}
|
||||||
QString sLine = document()->getString(line);
|
QString sLine = document()->getString(line);
|
||||||
highlighter->setLine(sLine,line-1);
|
syntaxer->setLine(sLine,line-1);
|
||||||
while (!highlighter->eol()) {
|
while (!syntaxer->eol()) {
|
||||||
int start = highlighter->getTokenPos();
|
int start = syntaxer->getTokenPos();
|
||||||
QString token = highlighter->getToken();
|
QString token = syntaxer->getToken();
|
||||||
int endPos = start + token.length()-1;
|
int endPos = start + token.length()-1;
|
||||||
if (start>ch) {
|
if (start>ch) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
QSynedit::PTokenAttribute attr = highlighter->getTokenAttribute();
|
QSynedit::PTokenAttribute attr = syntaxer->getTokenAttribute();
|
||||||
if ( (line == pos.line-1)
|
if ( (line == pos.line-1)
|
||||||
&& (start<=ch) && (ch<=endPos)) {
|
&& (start<=ch) && (ch<=endPos)) {
|
||||||
if (attr->tokenType() == QSynedit::TokenType::Comment
|
if (attr->tokenType() == QSynedit::TokenType::Comment
|
||||||
|
@ -1981,7 +1981,7 @@ QStringList Editor::getExpressionAtPosition(
|
||||||
&& attr->tokenType() != QSynedit::TokenType::Space){
|
&& attr->tokenType() != QSynedit::TokenType::Space){
|
||||||
tokens.append(token);
|
tokens.append(token);
|
||||||
}
|
}
|
||||||
highlighter->next();
|
syntaxer->next();
|
||||||
}
|
}
|
||||||
for (int i=tokens.count()-1;i>=0;i--) {
|
for (int i=tokens.count()-1;i>=0;i--) {
|
||||||
QString token = tokens[i];
|
QString token = tokens[i];
|
||||||
|
@ -2199,12 +2199,12 @@ bool Editor::handleSymbolCompletion(QChar key)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
//todo: better methods to detect current caret type
|
//todo: better methods to detect current caret type
|
||||||
if (highlighter()) {
|
if (syntaxer()) {
|
||||||
if (caretX() <= 1) {
|
if (caretX() <= 1) {
|
||||||
if (caretY()>1) {
|
if (caretY()>1) {
|
||||||
if (highlighter()->isLastLineCommentNotFinished(document()->ranges(caretY() - 2).state))
|
if (syntaxer()->isLastLineCommentNotFinished(document()->ranges(caretY() - 2).state))
|
||||||
return false;
|
return false;
|
||||||
if (highlighter()->isLastLineStringNotFinished(document()->ranges(caretY() - 2).state)
|
if (syntaxer()->isLastLineStringNotFinished(document()->ranges(caretY() - 2).state)
|
||||||
&& (key!='\"') && (key!='\''))
|
&& (key!='\"') && (key!='\''))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -2214,7 +2214,7 @@ bool Editor::handleSymbolCompletion(QChar key)
|
||||||
QSynedit::PTokenAttribute attr;
|
QSynedit::PTokenAttribute attr;
|
||||||
QString token;
|
QString token;
|
||||||
bool tokenFinished;
|
bool tokenFinished;
|
||||||
if (getHighlighterAttriAtRowCol(HighlightPos, token, tokenFinished, attr)) {
|
if (getTokenAttriAtRowCol(HighlightPos, token, tokenFinished, attr)) {
|
||||||
if ((attr->tokenType() == QSynedit::TokenType::Comment) && (!tokenFinished))
|
if ((attr->tokenType() == QSynedit::TokenType::Comment) && (!tokenFinished))
|
||||||
return false;
|
return false;
|
||||||
if ((attr->tokenType() == QSynedit::TokenType::String) && (!tokenFinished)
|
if ((attr->tokenType() == QSynedit::TokenType::String) && (!tokenFinished)
|
||||||
|
@ -2228,11 +2228,6 @@ bool Editor::handleSymbolCompletion(QChar key)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check if that line is highlighted as string or character or comment
|
|
||||||
// if (Attr = fText.Highlighter.StringAttribute) or (Attr = fText.Highlighter.CommentAttribute) or SameStr(Attr.Name,
|
|
||||||
// 'Character') then
|
|
||||||
// Exit;
|
|
||||||
|
|
||||||
QuoteStatus status;
|
QuoteStatus status;
|
||||||
switch(key.unicode()) {
|
switch(key.unicode()) {
|
||||||
case '(':
|
case '(':
|
||||||
|
@ -2349,7 +2344,7 @@ bool Editor::handleParentheseSkip()
|
||||||
|
|
||||||
if (document()->count()==0)
|
if (document()->count()==0)
|
||||||
return false;
|
return false;
|
||||||
if (highlighter() && highlighter()->supportBraceLevel()) {
|
if (syntaxer() && syntaxer()->supportBraceLevel()) {
|
||||||
QSynedit::SyntaxerState lastLineState = document()->ranges(document()->count()-1);
|
QSynedit::SyntaxerState lastLineState = document()->ranges(document()->count()-1);
|
||||||
if (lastLineState.parenthesisLevel==0) {
|
if (lastLineState.parenthesisLevel==0) {
|
||||||
setCaretXY( QSynedit::BufferCoord{caretX() + 1, caretY()}); // skip over
|
setCaretXY( QSynedit::BufferCoord{caretX() + 1, caretY()}); // skip over
|
||||||
|
@ -2400,7 +2395,7 @@ bool Editor::handleBracketSkip()
|
||||||
|
|
||||||
if (document()->count()==0)
|
if (document()->count()==0)
|
||||||
return false;
|
return false;
|
||||||
if (highlighter() && highlighter()->supportBraceLevel()) {
|
if (syntaxer() && syntaxer()->supportBraceLevel()) {
|
||||||
QSynedit::SyntaxerState lastLineState = document()->ranges(document()->count()-1);
|
QSynedit::SyntaxerState lastLineState = document()->ranges(document()->count()-1);
|
||||||
if (lastLineState.bracketLevel==0) {
|
if (lastLineState.bracketLevel==0) {
|
||||||
setCaretXY( QSynedit::BufferCoord{caretX() + 1, caretY()}); // skip over
|
setCaretXY( QSynedit::BufferCoord{caretX() + 1, caretY()}); // skip over
|
||||||
|
@ -2487,7 +2482,7 @@ bool Editor::handleBraceSkip()
|
||||||
if (document()->count()==0)
|
if (document()->count()==0)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if (highlighter() && highlighter()->supportBraceLevel()) {
|
if (syntaxer() && syntaxer()->supportBraceLevel()) {
|
||||||
QSynedit::SyntaxerState lastLineState = document()->ranges(document()->count()-1);
|
QSynedit::SyntaxerState lastLineState = document()->ranges(document()->count()-1);
|
||||||
if (lastLineState.braceLevel==0) {
|
if (lastLineState.braceLevel==0) {
|
||||||
bool oldInsertMode = insertMode();
|
bool oldInsertMode = insertMode();
|
||||||
|
@ -2531,7 +2526,7 @@ bool Editor::handleSingleQuoteCompletion()
|
||||||
endUpdate();
|
endUpdate();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (ch == 0 || highlighter()->isWordBreakChar(ch) || highlighter()->isSpaceChar(ch)) {
|
if (ch == 0 || syntaxer()->isWordBreakChar(ch) || syntaxer()->isSpaceChar(ch)) {
|
||||||
// insert ''
|
// insert ''
|
||||||
beginUpdate();
|
beginUpdate();
|
||||||
beginUndoBlock();
|
beginUndoBlock();
|
||||||
|
@ -2571,7 +2566,7 @@ bool Editor::handleDoubleQuoteCompletion()
|
||||||
endUpdate();
|
endUpdate();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if ((ch == 0) || highlighter()->isWordBreakChar(ch) || highlighter()->isSpaceChar(ch)) {
|
if ((ch == 0) || syntaxer()->isWordBreakChar(ch) || syntaxer()->isSpaceChar(ch)) {
|
||||||
// insert ""
|
// insert ""
|
||||||
beginUpdate();
|
beginUpdate();
|
||||||
beginUndoBlock();
|
beginUndoBlock();
|
||||||
|
@ -2662,7 +2657,7 @@ void Editor::initParser()
|
||||||
{
|
{
|
||||||
if (pSettings->codeCompletion().shareParser()) {
|
if (pSettings->codeCompletion().shareParser()) {
|
||||||
if (pSettings->codeCompletion().enabled()
|
if (pSettings->codeCompletion().enabled()
|
||||||
&& (highlighter() && highlighter()->language() == QSynedit::ProgrammingLanguage::Cpp)
|
&& (syntaxer() && syntaxer()->language() == QSynedit::ProgrammingLanguage::Cpp)
|
||||||
) {
|
) {
|
||||||
mParser = sharedParser(mUseCppSyntax?ParserLanguage::CPlusPlus:ParserLanguage::C);
|
mParser = sharedParser(mUseCppSyntax?ParserLanguage::CPlusPlus:ParserLanguage::C);
|
||||||
}
|
}
|
||||||
|
@ -2682,15 +2677,15 @@ void Editor::initParser()
|
||||||
resetCppParser(mParser);
|
resetCppParser(mParser);
|
||||||
mParser->setEnabled(
|
mParser->setEnabled(
|
||||||
pSettings->codeCompletion().enabled() &&
|
pSettings->codeCompletion().enabled() &&
|
||||||
(highlighter() && highlighter()->language() == QSynedit::ProgrammingLanguage::Cpp));
|
(syntaxer() && syntaxer()->language() == QSynedit::ProgrammingLanguage::Cpp));
|
||||||
}
|
}
|
||||||
|
|
||||||
Editor::QuoteStatus Editor::getQuoteStatus()
|
Editor::QuoteStatus Editor::getQuoteStatus()
|
||||||
{
|
{
|
||||||
QuoteStatus Result = QuoteStatus::NotQuote;
|
QuoteStatus Result = QuoteStatus::NotQuote;
|
||||||
if (!highlighter())
|
if (!syntaxer())
|
||||||
return Result;
|
return Result;
|
||||||
if ((caretY()>1) && highlighter()->isLastLineStringNotFinished(document()->ranges(caretY() - 2).state))
|
if ((caretY()>1) && syntaxer()->isLastLineStringNotFinished(document()->ranges(caretY() - 2).state))
|
||||||
Result = QuoteStatus::DoubleQuote;
|
Result = QuoteStatus::DoubleQuote;
|
||||||
|
|
||||||
QString Line = document()->getString(caretY()-1);
|
QString Line = document()->getString(caretY()-1);
|
||||||
|
@ -2812,10 +2807,10 @@ void Editor::reparse(bool resetParser)
|
||||||
return;
|
return;
|
||||||
if (!pSettings->codeCompletion().enabled())
|
if (!pSettings->codeCompletion().enabled())
|
||||||
return;
|
return;
|
||||||
if (!highlighter())
|
if (!syntaxer())
|
||||||
return;
|
return;
|
||||||
if (highlighter()->language() != QSynedit::ProgrammingLanguage::Cpp
|
if (syntaxer()->language() != QSynedit::ProgrammingLanguage::Cpp
|
||||||
&& highlighter()->language() != QSynedit::ProgrammingLanguage::GLSL)
|
&& syntaxer()->language() != QSynedit::ProgrammingLanguage::GLSL)
|
||||||
return;
|
return;
|
||||||
if (!mParser)
|
if (!mParser)
|
||||||
return;
|
return;
|
||||||
|
@ -2845,7 +2840,7 @@ void Editor::reparseTodo()
|
||||||
{
|
{
|
||||||
if (!mParentPageControl)
|
if (!mParentPageControl)
|
||||||
return;
|
return;
|
||||||
if (!highlighter())
|
if (!syntaxer())
|
||||||
return;
|
return;
|
||||||
if (pSettings->editor().parseTodos())
|
if (pSettings->editor().parseTodos())
|
||||||
pMainWindow->todoParser()->parseFile(mFilename, inProject());
|
pMainWindow->todoParser()->parseFile(mFilename, inProject());
|
||||||
|
@ -2996,12 +2991,12 @@ void Editor::exportAsRTF(const QString &rtfFilename)
|
||||||
exporter.setExportAsText(true);
|
exporter.setExportAsText(true);
|
||||||
exporter.setUseBackground(pSettings->editor().copyRTFUseBackground());
|
exporter.setUseBackground(pSettings->editor().copyRTFUseBackground());
|
||||||
exporter.setFont(font());
|
exporter.setFont(font());
|
||||||
QSynedit::PHighlighter hl = highlighter();
|
QSynedit::PSyntaxer hl = syntaxer();
|
||||||
if (!pSettings->editor().copyRTFUseEditorColor()) {
|
if (!pSettings->editor().copyRTFUseEditorColor()) {
|
||||||
hl = highlighterManager.copyHighlighter(highlighter());
|
hl = syntaxerManager.copy(syntaxer());
|
||||||
highlighterManager.applyColorScheme(hl,pSettings->editor().copyRTFColorScheme());
|
syntaxerManager.applyColorScheme(hl,pSettings->editor().copyRTFColorScheme());
|
||||||
}
|
}
|
||||||
exporter.setHighlighter(hl);
|
exporter.setSyntaxer(hl);
|
||||||
exporter.setOnFormatToken(std::bind(&Editor::onExportedFormatToken,
|
exporter.setOnFormatToken(std::bind(&Editor::onExportedFormatToken,
|
||||||
this,
|
this,
|
||||||
std::placeholders::_1,
|
std::placeholders::_1,
|
||||||
|
@ -3021,12 +3016,12 @@ void Editor::exportAsHTML(const QString &htmlFilename)
|
||||||
exporter.setExportAsText(false);
|
exporter.setExportAsText(false);
|
||||||
exporter.setUseBackground(pSettings->editor().copyHTMLUseBackground());
|
exporter.setUseBackground(pSettings->editor().copyHTMLUseBackground());
|
||||||
exporter.setFont(font());
|
exporter.setFont(font());
|
||||||
QSynedit::PHighlighter hl = highlighter();
|
QSynedit::PSyntaxer hl = syntaxer();
|
||||||
if (!pSettings->editor().copyHTMLUseEditorColor()) {
|
if (!pSettings->editor().copyHTMLUseEditorColor()) {
|
||||||
hl = highlighterManager.copyHighlighter(highlighter());
|
hl = syntaxerManager.copy(syntaxer());
|
||||||
highlighterManager.applyColorScheme(hl,pSettings->editor().copyHTMLColorScheme());
|
syntaxerManager.applyColorScheme(hl,pSettings->editor().copyHTMLColorScheme());
|
||||||
}
|
}
|
||||||
exporter.setHighlighter(hl);
|
exporter.setSyntaxer(hl);
|
||||||
exporter.setOnFormatToken(std::bind(&Editor::onExportedFormatToken,
|
exporter.setOnFormatToken(std::bind(&Editor::onExportedFormatToken,
|
||||||
this,
|
this,
|
||||||
std::placeholders::_1,
|
std::placeholders::_1,
|
||||||
|
@ -3049,7 +3044,7 @@ void Editor::showCompletion(const QString& preWord,bool autoComplete, CodeComple
|
||||||
if (!mParser || !mParser->enabled())
|
if (!mParser || !mParser->enabled())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!highlighter())
|
if (!syntaxer())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (mCompletionPopup->isVisible()) // already in search, don't do it again
|
if (mCompletionPopup->isVisible()) // already in search, don't do it again
|
||||||
|
@ -3061,7 +3056,7 @@ void Editor::showCompletion(const QString& preWord,bool autoComplete, CodeComple
|
||||||
QSynedit::PTokenAttribute attr;
|
QSynedit::PTokenAttribute attr;
|
||||||
bool tokenFinished;
|
bool tokenFinished;
|
||||||
QSynedit::BufferCoord pBeginPos, pEndPos;
|
QSynedit::BufferCoord pBeginPos, pEndPos;
|
||||||
if (getHighlighterAttriAtRowCol(
|
if (getTokenAttriAtRowCol(
|
||||||
QSynedit::BufferCoord{caretX() - 1,
|
QSynedit::BufferCoord{caretX() - 1,
|
||||||
caretY()}, s, tokenFinished, attr)) {
|
caretY()}, s, tokenFinished, attr)) {
|
||||||
if (attr->tokenType() == QSynedit::TokenType::Preprocessor) {//Preprocessor
|
if (attr->tokenType() == QSynedit::TokenType::Preprocessor) {//Preprocessor
|
||||||
|
@ -3121,9 +3116,9 @@ void Editor::showCompletion(const QString& preWord,bool autoComplete, CodeComple
|
||||||
);
|
);
|
||||||
|
|
||||||
QSet<QString> keywords;
|
QSet<QString> keywords;
|
||||||
if (highlighter()) {
|
if (syntaxer()) {
|
||||||
if (highlighter()->language() != QSynedit::ProgrammingLanguage::Cpp ) {
|
if (syntaxer()->language() != QSynedit::ProgrammingLanguage::Cpp ) {
|
||||||
keywords = highlighter()->keywords();
|
keywords = syntaxer()->keywords();
|
||||||
} else {
|
} else {
|
||||||
if (mUseCppSyntax) {
|
if (mUseCppSyntax) {
|
||||||
foreach (const QString& keyword, CppKeywords.keys()) {
|
foreach (const QString& keyword, CppKeywords.keys()) {
|
||||||
|
@ -3341,14 +3336,6 @@ void Editor::completionInsert(bool appendFunc)
|
||||||
&& (statement->args != "(void)")) {
|
&& (statement->args != "(void)")) {
|
||||||
setCaretX(caretX() - funcAddOn.length()+1);
|
setCaretX(caretX() - funcAddOn.length()+1);
|
||||||
|
|
||||||
//todo: function hint
|
|
||||||
// immediately activate function hint
|
|
||||||
// if devEditor.ShowFunctionTip and Assigned(fText.Highlighter) then begin
|
|
||||||
// fText.SetFocus;
|
|
||||||
// fFunctionTip.Parser := fParser;
|
|
||||||
// fFunctionTip.FileName := fFileName;
|
|
||||||
// fFunctionTip.Show;
|
|
||||||
// end;
|
|
||||||
} else {
|
} else {
|
||||||
setCaretX(caretX());
|
setCaretX(caretX());
|
||||||
}
|
}
|
||||||
|
@ -3542,7 +3529,7 @@ bool Editor::onCompletionInputMethod(QInputMethodEvent *event)
|
||||||
Editor::TipType Editor::getTipType(QPoint point, QSynedit::BufferCoord& pos)
|
Editor::TipType Editor::getTipType(QPoint point, QSynedit::BufferCoord& pos)
|
||||||
{
|
{
|
||||||
// Only allow in the text area...
|
// Only allow in the text area...
|
||||||
if (pointToCharLine(point, pos) && highlighter()) {
|
if (pointToCharLine(point, pos) && syntaxer()) {
|
||||||
if (!pMainWindow->debugger()->executing()
|
if (!pMainWindow->debugger()->executing()
|
||||||
&& getSyntaxIssueAtPosition(pos)) {
|
&& getSyntaxIssueAtPosition(pos)) {
|
||||||
return TipType::Error;
|
return TipType::Error;
|
||||||
|
@ -3552,7 +3539,7 @@ Editor::TipType Editor::getTipType(QPoint point, QSynedit::BufferCoord& pos)
|
||||||
QString s;
|
QString s;
|
||||||
|
|
||||||
// Only allow hand tips in highlighted areas
|
// Only allow hand tips in highlighted areas
|
||||||
if (getHighlighterAttriAtRowCol(pos,s,attr)) {
|
if (getTokenAttriAtRowCol(pos,s,attr)) {
|
||||||
// Only allow Identifiers, Preprocessor directives, and selection
|
// Only allow Identifiers, Preprocessor directives, and selection
|
||||||
if (attr) {
|
if (attr) {
|
||||||
if (selAvail()) {
|
if (selAvail()) {
|
||||||
|
@ -3561,7 +3548,7 @@ Editor::TipType Editor::getTipType(QPoint point, QSynedit::BufferCoord& pos)
|
||||||
return TipType::Selection;
|
return TipType::Selection;
|
||||||
} else if (mParser && mParser->isIncludeLine(document()->getString(pos.line-1))) {
|
} else if (mParser && mParser->isIncludeLine(document()->getString(pos.line-1))) {
|
||||||
return TipType::Preprocessor;
|
return TipType::Preprocessor;
|
||||||
}else if (attr == highlighter()->identifierAttribute())
|
}else if (attr == syntaxer()->identifierAttribute())
|
||||||
return TipType::Identifier;
|
return TipType::Identifier;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3710,7 +3697,7 @@ void Editor::updateFunctionTip(bool showTip)
|
||||||
pMainWindow->functionTip()->hide();
|
pMainWindow->functionTip()->hide();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (!highlighter())
|
if (!syntaxer())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!mParser || !mParser->enabled())
|
if (!mParser || !mParser->enabled())
|
||||||
|
@ -3745,22 +3732,22 @@ void Editor::updateFunctionTip(bool showTip)
|
||||||
QStringList tokens;
|
QStringList tokens;
|
||||||
QList<int> positions;
|
QList<int> positions;
|
||||||
if (currentLine==0)
|
if (currentLine==0)
|
||||||
highlighter()->resetState();
|
syntaxer()->resetState();
|
||||||
else
|
else
|
||||||
highlighter()->setState(
|
syntaxer()->setState(
|
||||||
document()->ranges(currentLine-1));
|
document()->ranges(currentLine-1));
|
||||||
highlighter()->setLine(line,currentLine);
|
syntaxer()->setLine(line,currentLine);
|
||||||
while(!highlighter()->eol()) {
|
while(!syntaxer()->eol()) {
|
||||||
int start = highlighter()->getTokenPos();
|
int start = syntaxer()->getTokenPos();
|
||||||
QString token = highlighter()->getToken();
|
QString token = syntaxer()->getToken();
|
||||||
QSynedit::PTokenAttribute attr = highlighter()->getTokenAttribute();
|
QSynedit::PTokenAttribute attr = syntaxer()->getTokenAttribute();
|
||||||
if (start>=currentChar)
|
if (start>=currentChar)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if (attr->tokenType() != QSynedit::TokenType::Comment
|
if (attr->tokenType() != QSynedit::TokenType::Comment
|
||||||
&& attr->tokenType() != QSynedit::TokenType::Space) {
|
&& attr->tokenType() != QSynedit::TokenType::Space) {
|
||||||
if (foundFunctionStart) {
|
if (foundFunctionStart) {
|
||||||
if (attr!=highlighter()->identifierAttribute())
|
if (attr!=syntaxer()->identifierAttribute())
|
||||||
return; // not a function
|
return; // not a function
|
||||||
functionNamePos.line = currentLine+1;
|
functionNamePos.line = currentLine+1;
|
||||||
functionNamePos.ch = start+1;
|
functionNamePos.ch = start+1;
|
||||||
|
@ -3773,7 +3760,7 @@ void Editor::updateFunctionTip(bool showTip)
|
||||||
&& start+token.length()>=caretPos.ch) {
|
&& start+token.length()>=caretPos.ch) {
|
||||||
return; // in comment, do nothing
|
return; // in comment, do nothing
|
||||||
}
|
}
|
||||||
highlighter()->next();
|
syntaxer()->next();
|
||||||
}
|
}
|
||||||
if (!foundFunctionStart) {
|
if (!foundFunctionStart) {
|
||||||
for (int i=tokens.length()-1;i>=0;i--) {
|
for (int i=tokens.length()-1;i>=0;i--) {
|
||||||
|
@ -3962,9 +3949,9 @@ void Editor::popUserCodeInTabStops()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Editor::onExportedFormatToken(QSynedit::PHighlighter syntaxHighlighter, int Line, int column, const QString &token, QSynedit::PTokenAttribute& attr)
|
void Editor::onExportedFormatToken(QSynedit::PSyntaxer syntaxer, int Line, int column, const QString &token, QSynedit::PTokenAttribute& attr)
|
||||||
{
|
{
|
||||||
if (!syntaxHighlighter)
|
if (!syntaxer)
|
||||||
return;
|
return;
|
||||||
if (token.isEmpty())
|
if (token.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
@ -3972,7 +3959,7 @@ void Editor::onExportedFormatToken(QSynedit::PHighlighter syntaxHighlighter, int
|
||||||
if (mCompletionPopup->isVisible() || mHeaderCompletionPopup->isVisible())
|
if (mCompletionPopup->isVisible() || mHeaderCompletionPopup->isVisible())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (mParser && (attr == syntaxHighlighter->identifierAttribute())) {
|
if (mParser && (attr == syntaxer->identifierAttribute())) {
|
||||||
QSynedit::BufferCoord p{column,Line};
|
QSynedit::BufferCoord p{column,Line};
|
||||||
QSynedit::BufferCoord pBeginPos,pEndPos;
|
QSynedit::BufferCoord pBeginPos,pEndPos;
|
||||||
QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation);
|
QString s= getWordAtPosition(this,p, pBeginPos,pEndPos, WordPurpose::wpInformation);
|
||||||
|
@ -3990,41 +3977,41 @@ void Editor::onExportedFormatToken(QSynedit::PHighlighter syntaxHighlighter, int
|
||||||
kind = StatementKind::skVariable;
|
kind = StatementKind::skVariable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
QSynedit::CppHighlighter* cppHighlighter = dynamic_cast<QSynedit::CppHighlighter*>(syntaxHighlighter.get());
|
QSynedit::CppSyntaxer* cppSyntaxer = dynamic_cast<QSynedit::CppSyntaxer*>(syntaxer.get());
|
||||||
switch(kind) {
|
switch(kind) {
|
||||||
case StatementKind::skFunction:
|
case StatementKind::skFunction:
|
||||||
case StatementKind::skConstructor:
|
case StatementKind::skConstructor:
|
||||||
case StatementKind::skDestructor:
|
case StatementKind::skDestructor:
|
||||||
attr = cppHighlighter->functionAttribute();
|
attr = cppSyntaxer->functionAttribute();
|
||||||
break;
|
break;
|
||||||
case StatementKind::skClass:
|
case StatementKind::skClass:
|
||||||
case StatementKind::skTypedef:
|
case StatementKind::skTypedef:
|
||||||
case StatementKind::skAlias:
|
case StatementKind::skAlias:
|
||||||
attr = cppHighlighter->classAttribute();
|
attr = cppSyntaxer->classAttribute();
|
||||||
break;
|
break;
|
||||||
case StatementKind::skEnumClassType:
|
case StatementKind::skEnumClassType:
|
||||||
case StatementKind::skEnumType:
|
case StatementKind::skEnumType:
|
||||||
break;
|
break;
|
||||||
case StatementKind::skLocalVariable:
|
case StatementKind::skLocalVariable:
|
||||||
case StatementKind::skParameter:
|
case StatementKind::skParameter:
|
||||||
attr = cppHighlighter->localVarAttribute();
|
attr = cppSyntaxer->localVarAttribute();
|
||||||
break;
|
break;
|
||||||
case StatementKind::skVariable:
|
case StatementKind::skVariable:
|
||||||
attr = cppHighlighter->variableAttribute();
|
attr = cppSyntaxer->variableAttribute();
|
||||||
break;
|
break;
|
||||||
case StatementKind::skGlobalVariable:
|
case StatementKind::skGlobalVariable:
|
||||||
attr = cppHighlighter->globalVarAttribute();
|
attr = cppSyntaxer->globalVarAttribute();
|
||||||
break;
|
break;
|
||||||
case StatementKind::skEnum:
|
case StatementKind::skEnum:
|
||||||
case StatementKind::skPreprocessor:
|
case StatementKind::skPreprocessor:
|
||||||
attr = cppHighlighter->preprocessorAttribute();
|
attr = cppSyntaxer->preprocessorAttribute();
|
||||||
break;
|
break;
|
||||||
case StatementKind::skKeyword:
|
case StatementKind::skKeyword:
|
||||||
attr = cppHighlighter->keywordAttribute();
|
attr = cppSyntaxer->keywordAttribute();
|
||||||
break;
|
break;
|
||||||
case StatementKind::skNamespace:
|
case StatementKind::skNamespace:
|
||||||
case StatementKind::skNamespaceAlias:
|
case StatementKind::skNamespaceAlias:
|
||||||
attr = cppHighlighter->stringAttribute();
|
attr = cppSyntaxer->stringAttribute();
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
|
@ -4580,9 +4567,9 @@ void Editor::checkSyntaxInBack()
|
||||||
return;
|
return;
|
||||||
if (readOnly())
|
if (readOnly())
|
||||||
return;
|
return;
|
||||||
if (!highlighter())
|
if (!syntaxer())
|
||||||
return;
|
return;
|
||||||
if (highlighter()->language()!=QSynedit::ProgrammingLanguage::Cpp)
|
if (syntaxer()->language()!=QSynedit::ProgrammingLanguage::Cpp)
|
||||||
return;
|
return;
|
||||||
pMainWindow->checkSyntaxInBack(this);
|
pMainWindow->checkSyntaxInBack(this);
|
||||||
}
|
}
|
||||||
|
@ -4737,7 +4724,7 @@ void Editor::applySettings()
|
||||||
options.setFlag(QSynedit::eoHalfPageScroll,pSettings->editor().halfPageScroll());
|
options.setFlag(QSynedit::eoHalfPageScroll,pSettings->editor().halfPageScroll());
|
||||||
options.setFlag(QSynedit::eoShowRainbowColor,
|
options.setFlag(QSynedit::eoShowRainbowColor,
|
||||||
pSettings->editor().rainbowParenthesis()
|
pSettings->editor().rainbowParenthesis()
|
||||||
&& highlighter() && highlighter()->supportBraceLevel());
|
&& syntaxer() && syntaxer()->supportBraceLevel());
|
||||||
setOptions(options);
|
setOptions(options);
|
||||||
|
|
||||||
setTabWidth(pSettings->editor().tabWidth());
|
setTabWidth(pSettings->editor().tabWidth());
|
||||||
|
@ -4792,15 +4779,15 @@ void Editor::applySettings()
|
||||||
}
|
}
|
||||||
|
|
||||||
if (pSettings->editor().enableCustomCTypeKeywords()) {
|
if (pSettings->editor().enableCustomCTypeKeywords()) {
|
||||||
if (highlighter() && highlighter()->language() == QSynedit::ProgrammingLanguage::Cpp) {
|
if (syntaxer() && syntaxer()->language() == QSynedit::ProgrammingLanguage::Cpp) {
|
||||||
QSet<QString> set;
|
QSet<QString> set;
|
||||||
foreach(const QString& s, pSettings->editor().customCTypeKeywords())
|
foreach(const QString& s, pSettings->editor().customCTypeKeywords())
|
||||||
set.insert(s);
|
set.insert(s);
|
||||||
((QSynedit::CppHighlighter*)(highlighter().get()))->setCustomTypeKeywords(set);
|
((QSynedit::CppSyntaxer*)(syntaxer().get()))->setCustomTypeKeywords(set);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (highlighter() && highlighter()->language() == QSynedit::ProgrammingLanguage::Cpp) {
|
if (syntaxer() && syntaxer()->language() == QSynedit::ProgrammingLanguage::Cpp) {
|
||||||
((QSynedit::CppHighlighter*)(highlighter().get()))->setCustomTypeKeywords(QSet<QString>());
|
((QSynedit::CppSyntaxer*)(syntaxer().get()))->setCustomTypeKeywords(QSet<QString>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4828,9 +4815,9 @@ void Editor::applyColorScheme(const QString& schemeName)
|
||||||
QSynedit::EditorOptions options = getOptions();
|
QSynedit::EditorOptions options = getOptions();
|
||||||
options.setFlag(QSynedit::EditorOption::eoShowRainbowColor,
|
options.setFlag(QSynedit::EditorOption::eoShowRainbowColor,
|
||||||
pSettings->editor().rainbowParenthesis()
|
pSettings->editor().rainbowParenthesis()
|
||||||
&& highlighter() && highlighter()->supportBraceLevel());
|
&& syntaxer() && syntaxer()->supportBraceLevel());
|
||||||
setOptions(options);
|
setOptions(options);
|
||||||
highlighterManager.applyColorScheme(highlighter(),schemeName);
|
syntaxerManager.applyColorScheme(syntaxer(),schemeName);
|
||||||
if (pSettings->editor().rainbowParenthesis()) {
|
if (pSettings->editor().rainbowParenthesis()) {
|
||||||
QSynedit::PTokenAttribute attr0 =createRainbowAttribute(SYNS_AttrSymbol,
|
QSynedit::PTokenAttribute attr0 =createRainbowAttribute(SYNS_AttrSymbol,
|
||||||
schemeName,COLOR_SCHEME_BRACE_1);
|
schemeName,COLOR_SCHEME_BRACE_1);
|
||||||
|
|
|
@ -290,7 +290,7 @@ private:
|
||||||
void updateFunctionTip(bool showTip);
|
void updateFunctionTip(bool showTip);
|
||||||
void clearUserCodeInTabStops();
|
void clearUserCodeInTabStops();
|
||||||
void popUserCodeInTabStops();
|
void popUserCodeInTabStops();
|
||||||
void onExportedFormatToken(QSynedit::PHighlighter syntaxHighlighter, int Line, int column, const QString& token,
|
void onExportedFormatToken(QSynedit::PSyntaxer syntaxer, int Line, int column, const QString& token,
|
||||||
QSynedit::PTokenAttribute &attr);
|
QSynedit::PTokenAttribute &attr);
|
||||||
void onScrollBarValueChanged();
|
void onScrollBarValueChanged();
|
||||||
static PCppParser sharedParser(ParserLanguage language);
|
static PCppParser sharedParser(ParserLanguage language);
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#include "cppparser.h"
|
#include "cppparser.h"
|
||||||
#include "parserutils.h"
|
#include "parserutils.h"
|
||||||
#include "../utils.h"
|
#include "../utils.h"
|
||||||
#include "qsynedit/highlighter/cpp.h"
|
#include "qsynedit/syntaxer/cpp.h"
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QDate>
|
#include <QDate>
|
||||||
|
@ -4772,19 +4772,19 @@ PStatement CppParser::doParseEvalTypeInfo(
|
||||||
QString s = type;
|
QString s = type;
|
||||||
// qDebug()<<"eval type info"<<type;
|
// qDebug()<<"eval type info"<<type;
|
||||||
int position = s.length()-1;
|
int position = s.length()-1;
|
||||||
QSynedit::CppHighlighter highlighter;
|
QSynedit::CppSyntaxer syntaxer;
|
||||||
highlighter.resetState();
|
syntaxer.resetState();
|
||||||
highlighter.setLine(type,0);
|
syntaxer.setLine(type,0);
|
||||||
int bracketLevel = 0;
|
int bracketLevel = 0;
|
||||||
int templateLevel = 0;
|
int templateLevel = 0;
|
||||||
while(!highlighter.eol()) {
|
while(!syntaxer.eol()) {
|
||||||
QString token = highlighter.getToken();
|
QString token = syntaxer.getToken();
|
||||||
if (bracketLevel == 0 && templateLevel ==0) {
|
if (bracketLevel == 0 && templateLevel ==0) {
|
||||||
if (token == "*")
|
if (token == "*")
|
||||||
pointerLevel++;
|
pointerLevel++;
|
||||||
else if (token == "&")
|
else if (token == "&")
|
||||||
pointerLevel--;
|
pointerLevel--;
|
||||||
else if (highlighter.getTokenAttribute()->tokenType() == QSynedit::TokenType::Identifier) {
|
else if (syntaxer.getTokenAttribute()->tokenType() == QSynedit::TokenType::Identifier) {
|
||||||
baseType += token;
|
baseType += token;
|
||||||
} else if (token == "[") {
|
} else if (token == "[") {
|
||||||
pointerLevel++;
|
pointerLevel++;
|
||||||
|
@ -4809,7 +4809,7 @@ PStatement CppParser::doParseEvalTypeInfo(
|
||||||
}
|
}
|
||||||
templateParams += token;
|
templateParams += token;
|
||||||
}
|
}
|
||||||
highlighter.next();
|
syntaxer.next();
|
||||||
}
|
}
|
||||||
while ((position >= 0) && (s[position] == '*'
|
while ((position >= 0) && (s[position] == '*'
|
||||||
|| s[position] == ' '
|
|| s[position] == ' '
|
||||||
|
|
|
@ -14,42 +14,42 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#include "HighlighterManager.h"
|
#include "syntaxermanager.h"
|
||||||
#include <QFileInfo>
|
#include <QFileInfo>
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
#include "qsynedit/Constants.h"
|
#include "qsynedit/Constants.h"
|
||||||
#include "qsynedit/highlighter/cpp.h"
|
#include "qsynedit/syntaxer/cpp.h"
|
||||||
#include "qsynedit/highlighter/asm.h"
|
#include "qsynedit/syntaxer/asm.h"
|
||||||
#include "qsynedit/highlighter/glsl.h"
|
#include "qsynedit/syntaxer/glsl.h"
|
||||||
#include "qsynedit/highlighter/makefilehighlighter.h"
|
#include "qsynedit/syntaxer/makefile.h"
|
||||||
|
|
||||||
#include "qsynedit/Constants.h"
|
#include "qsynedit/Constants.h"
|
||||||
#include "colorscheme.h"
|
#include "colorscheme.h"
|
||||||
|
|
||||||
HighlighterManager highlighterManager;
|
SyntaxerManager syntaxerManager;
|
||||||
|
|
||||||
HighlighterManager::HighlighterManager()
|
SyntaxerManager::SyntaxerManager()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QSynedit::PHighlighter HighlighterManager::getHighlighter(QSynedit::ProgrammingLanguage language)
|
QSynedit::PSyntaxer SyntaxerManager::getSyntaxer(QSynedit::ProgrammingLanguage language)
|
||||||
{
|
{
|
||||||
switch(language) {
|
switch(language) {
|
||||||
case QSynedit::ProgrammingLanguage::Cpp:
|
case QSynedit::ProgrammingLanguage::Cpp:
|
||||||
return getCppHighlighter();
|
return getCppSyntaxer();
|
||||||
case QSynedit::ProgrammingLanguage::Asssembly:
|
case QSynedit::ProgrammingLanguage::Asssembly:
|
||||||
return getAsmHighlighter();
|
return getAsmSyntaxer();
|
||||||
case QSynedit::ProgrammingLanguage::Makefile:
|
case QSynedit::ProgrammingLanguage::Makefile:
|
||||||
return getMakefileHighlighter();
|
return getMakefileSyntaxer();
|
||||||
case QSynedit::ProgrammingLanguage::GLSL:
|
case QSynedit::ProgrammingLanguage::GLSL:
|
||||||
return getGLSLHighlighter();
|
return getGLSLSyntaxer();
|
||||||
default:
|
default:
|
||||||
return QSynedit::PHighlighter();
|
return QSynedit::PSyntaxer();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QSynedit::PHighlighter HighlighterManager::getHighlighter(const QString &filename)
|
QSynedit::PSyntaxer SyntaxerManager::getSyntaxer(const QString &filename)
|
||||||
{
|
{
|
||||||
QFileInfo info(filename);
|
QFileInfo info(filename);
|
||||||
QString suffix = info.suffix();
|
QString suffix = info.suffix();
|
||||||
|
@ -59,59 +59,55 @@ QSynedit::PHighlighter HighlighterManager::getHighlighter(const QString &filenam
|
||||||
|| suffix == "hxx" || suffix == "hh" || suffix == "C"
|
|| suffix == "hxx" || suffix == "hh" || suffix == "C"
|
||||||
|| suffix == "CPP" || suffix =="H" || suffix == "c++"
|
|| suffix == "CPP" || suffix =="H" || suffix == "c++"
|
||||||
|| suffix == "h++") {
|
|| suffix == "h++") {
|
||||||
return getCppHighlighter();
|
return getCppSyntaxer();
|
||||||
} else if (suffix == "vs" || suffix == "fs" || suffix == "frag") {
|
} else if (suffix == "vs" || suffix == "fs" || suffix == "frag") {
|
||||||
return getGLSLHighlighter();
|
return getGLSLSyntaxer();
|
||||||
} else if (suffix == "s" || suffix == "asm") {
|
} else if (suffix == "s" || suffix == "asm") {
|
||||||
return getAsmHighlighter();
|
return getAsmSyntaxer();
|
||||||
} else if (basename.compare("makefile", Qt::CaseInsensitive)==0) {
|
} else if (basename.compare("makefile", Qt::CaseInsensitive)==0) {
|
||||||
return getMakefileHighlighter();
|
return getMakefileSyntaxer();
|
||||||
} else if (suffix.isEmpty()) {
|
} else if (suffix.isEmpty()) {
|
||||||
return getCppHighlighter();
|
return getCppSyntaxer();
|
||||||
}
|
}
|
||||||
return QSynedit::PHighlighter();
|
return QSynedit::PSyntaxer();
|
||||||
}
|
}
|
||||||
|
|
||||||
QSynedit::PHighlighter HighlighterManager::copyHighlighter(QSynedit::PHighlighter highlighter)
|
QSynedit::PSyntaxer SyntaxerManager::copy(QSynedit::PSyntaxer syntaxer)
|
||||||
{
|
{
|
||||||
if (!highlighter)
|
if (!syntaxer)
|
||||||
return QSynedit::PHighlighter();
|
return QSynedit::PSyntaxer();
|
||||||
return getHighlighter(highlighter->language());
|
return getSyntaxer(syntaxer->language());
|
||||||
}
|
}
|
||||||
|
|
||||||
QSynedit::PHighlighter HighlighterManager::getCppHighlighter()
|
QSynedit::PSyntaxer SyntaxerManager::getCppSyntaxer()
|
||||||
{
|
{
|
||||||
std::shared_ptr<QSynedit::CppHighlighter> highlighter = std::make_shared<QSynedit::CppHighlighter>();
|
return std::make_shared<QSynedit::CppSyntaxer>();
|
||||||
return highlighter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QSynedit::PHighlighter HighlighterManager::getAsmHighlighter()
|
QSynedit::PSyntaxer SyntaxerManager::getAsmSyntaxer()
|
||||||
{
|
{
|
||||||
std::shared_ptr<QSynedit::ASMHighlighter> highlighter=std::make_shared<QSynedit::ASMHighlighter>();
|
return std::make_shared<QSynedit::ASMSyntaxer>();
|
||||||
return highlighter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QSynedit::PHighlighter HighlighterManager::getGLSLHighlighter()
|
QSynedit::PSyntaxer SyntaxerManager::getGLSLSyntaxer()
|
||||||
{
|
{
|
||||||
std::shared_ptr<QSynedit::GLSLHighlighter> highlighter=std::make_shared<QSynedit::GLSLHighlighter>();
|
return std::make_shared<QSynedit::GLSLSyntaxer>();
|
||||||
return highlighter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QSynedit::PHighlighter HighlighterManager::getMakefileHighlighter()
|
QSynedit::PSyntaxer SyntaxerManager::getMakefileSyntaxer()
|
||||||
{
|
{
|
||||||
std::shared_ptr<QSynedit::MakefileHighlighter> highlighter=std::make_shared<QSynedit::MakefileHighlighter>();
|
return std::make_shared<QSynedit::MakefileSyntaxer>();
|
||||||
return highlighter;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void HighlighterManager::applyColorScheme(QSynedit::PHighlighter highlighter, const QString &schemeName)
|
void SyntaxerManager::applyColorScheme(QSynedit::PSyntaxer syntaxer, const QString &schemeName)
|
||||||
{
|
{
|
||||||
if (!highlighter)
|
if (!syntaxer)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (QString name: highlighter->attributes().keys()) {
|
for (QString name: syntaxer->attributes().keys()) {
|
||||||
PColorSchemeItem item = pColorManager->getItem(schemeName,name);
|
PColorSchemeItem item = pColorManager->getItem(schemeName,name);
|
||||||
if (item) {
|
if (item) {
|
||||||
QSynedit::PTokenAttribute attr = highlighter->attributes()[name];
|
QSynedit::PTokenAttribute attr = syntaxer->attributes()[name];
|
||||||
attr->setBackground(item->background());
|
attr->setBackground(item->background());
|
||||||
attr->setForeground(item->foreground());
|
attr->setForeground(item->foreground());
|
||||||
QSynedit::FontStyles styles = QSynedit::FontStyle::fsNone;
|
QSynedit::FontStyles styles = QSynedit::FontStyle::fsNone;
|
|
@ -0,0 +1,38 @@
|
||||||
|
/*
|
||||||
|
* Copyright (C) 2020-2022 Roy Qu (royqh1979@gmail.com)
|
||||||
|
*
|
||||||
|
* This program 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.
|
||||||
|
*
|
||||||
|
* This program 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 this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
#ifndef SYNTAXERMANAGER_H
|
||||||
|
#define SYNTAXERMANAGER_H
|
||||||
|
#include "qsynedit/syntaxer/syntaxer.h"
|
||||||
|
|
||||||
|
class SyntaxerManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
SyntaxerManager();
|
||||||
|
|
||||||
|
QSynedit::PSyntaxer getSyntaxer(QSynedit::ProgrammingLanguage language);
|
||||||
|
QSynedit::PSyntaxer getSyntaxer(const QString& filename);
|
||||||
|
QSynedit::PSyntaxer copy(QSynedit::PSyntaxer syntaxer);
|
||||||
|
QSynedit::PSyntaxer getCppSyntaxer();
|
||||||
|
QSynedit::PSyntaxer getAsmSyntaxer();
|
||||||
|
QSynedit::PSyntaxer getGLSLSyntaxer();
|
||||||
|
QSynedit::PSyntaxer getMakefileSyntaxer();
|
||||||
|
void applyColorScheme(QSynedit::PSyntaxer syntaxer, const QString& schemeName);
|
||||||
|
};
|
||||||
|
|
||||||
|
extern SyntaxerManager syntaxerManager;
|
||||||
|
|
||||||
|
#endif // SYNTAXERMANAGER_H
|
|
@ -106,15 +106,15 @@ TodoThread::TodoThread(const QStringList &files, QObject *parent): QThread(paren
|
||||||
|
|
||||||
void TodoThread::parseFile()
|
void TodoThread::parseFile()
|
||||||
{
|
{
|
||||||
QSynedit::PHighlighter highlighter = highlighterManager.getCppHighlighter();
|
QSynedit::PSyntaxer syntaxer = syntaxerManager.getCppSyntaxer();
|
||||||
emit parseStarted();
|
emit parseStarted();
|
||||||
doParseFile(mFilename,highlighter);
|
doParseFile(mFilename,syntaxer);
|
||||||
emit parseFinished();
|
emit parseFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TodoThread::parseFiles()
|
void TodoThread::parseFiles()
|
||||||
{
|
{
|
||||||
QSynedit::PHighlighter highlighter = highlighterManager.getCppHighlighter();
|
QSynedit::PSyntaxer highlighter = syntaxerManager.getCppSyntaxer();
|
||||||
emit parseStarted();
|
emit parseStarted();
|
||||||
foreach(const QString& filename,mFiles) {
|
foreach(const QString& filename,mFiles) {
|
||||||
doParseFile(filename,highlighter);
|
doParseFile(filename,highlighter);
|
||||||
|
@ -122,33 +122,33 @@ void TodoThread::parseFiles()
|
||||||
emit parseFinished();
|
emit parseFinished();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TodoThread::doParseFile(const QString &filename, QSynedit::PHighlighter highlighter)
|
void TodoThread::doParseFile(const QString &filename, QSynedit::PSyntaxer syntaxer)
|
||||||
{
|
{
|
||||||
emit parsingFile(filename);
|
emit parsingFile(filename);
|
||||||
QStringList lines;
|
QStringList lines;
|
||||||
if (!pMainWindow->editorList()->getContentFromOpenedEditor(filename,lines)) {
|
if (!pMainWindow->editorList()->getContentFromOpenedEditor(filename,lines)) {
|
||||||
lines = readFileToLines(filename);
|
lines = readFileToLines(filename);
|
||||||
}
|
}
|
||||||
highlighter->resetState();
|
syntaxer->resetState();
|
||||||
for (int i =0;i<lines.count();i++) {
|
for (int i =0;i<lines.count();i++) {
|
||||||
highlighter->setLine(lines[i],i);
|
syntaxer->setLine(lines[i],i);
|
||||||
while (!highlighter->eol()) {
|
while (!syntaxer->eol()) {
|
||||||
QSynedit::PTokenAttribute attr;
|
QSynedit::PTokenAttribute attr;
|
||||||
attr = highlighter->getTokenAttribute();
|
attr = syntaxer->getTokenAttribute();
|
||||||
if (attr && attr->tokenType() == QSynedit::TokenType::Comment) {
|
if (attr && attr->tokenType() == QSynedit::TokenType::Comment) {
|
||||||
QString token = highlighter->getToken();
|
QString token = syntaxer->getToken();
|
||||||
int pos = token.indexOf(todoReg);
|
int pos = token.indexOf(todoReg);
|
||||||
if (pos>=0) {
|
if (pos>=0) {
|
||||||
emit todoFound(
|
emit todoFound(
|
||||||
filename,
|
filename,
|
||||||
i+1,
|
i+1,
|
||||||
pos+highlighter->getTokenPos(),
|
pos+syntaxer->getTokenPos(),
|
||||||
lines[i].trimmed()
|
lines[i].trimmed()
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
highlighter->next();
|
syntaxer->next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include <QThread>
|
#include <QThread>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QAbstractListModel>
|
#include <QAbstractListModel>
|
||||||
#include "HighlighterManager.h"
|
#include "syntaxermanager.h"
|
||||||
#include "qsynedit/Constants.h"
|
#include "qsynedit/Constants.h"
|
||||||
|
|
||||||
struct TodoItem {
|
struct TodoItem {
|
||||||
|
@ -76,7 +76,7 @@ signals:
|
||||||
private:
|
private:
|
||||||
void parseFile();
|
void parseFile();
|
||||||
void parseFiles();
|
void parseFiles();
|
||||||
void doParseFile(const QString& filename, QSynedit::PHighlighter highlighter);
|
void doParseFile(const QString& filename, QSynedit::PSyntaxer syntaxer);
|
||||||
private:
|
private:
|
||||||
QString mFilename;
|
QString mFilename;
|
||||||
QStringList mFiles;
|
QStringList mFiles;
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#include <QDesktopWidget>
|
#include <QDesktopWidget>
|
||||||
#include "cpudialog.h"
|
#include "cpudialog.h"
|
||||||
#include "ui_cpudialog.h"
|
#include "ui_cpudialog.h"
|
||||||
#include "../HighlighterManager.h"
|
#include "../syntaxermanager.h"
|
||||||
#include "../mainwindow.h"
|
#include "../mainwindow.h"
|
||||||
#include "../debugger.h"
|
#include "../debugger.h"
|
||||||
#include "../settings.h"
|
#include "../settings.h"
|
||||||
|
@ -32,7 +32,7 @@ CPUDialog::CPUDialog(QWidget *parent) :
|
||||||
setWindowFlags(windowFlags() | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint);
|
setWindowFlags(windowFlags() | Qt::WindowMinimizeButtonHint | Qt::WindowMaximizeButtonHint);
|
||||||
setWindowFlag(Qt::WindowContextHelpButtonHint,false);
|
setWindowFlag(Qt::WindowContextHelpButtonHint,false);
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
ui->txtCode->setHighlighter(highlighterManager.getAsmHighlighter());
|
ui->txtCode->setSyntaxer(syntaxerManager.getAsmSyntaxer());
|
||||||
ui->txtCode->setReadOnly(true);
|
ui->txtCode->setReadOnly(true);
|
||||||
ui->txtCode->gutter().setShowLineNumbers(false);
|
ui->txtCode->gutter().setShowLineNumbers(false);
|
||||||
ui->txtCode->setCaretUseTextColor(true);
|
ui->txtCode->setCaretUseTextColor(true);
|
||||||
|
@ -42,7 +42,7 @@ CPUDialog::CPUDialog(QWidget *parent) :
|
||||||
ui->txtCode->setGutterWidth(0);
|
ui->txtCode->setGutterWidth(0);
|
||||||
ui->txtCode->setUseCodeFolding(false);
|
ui->txtCode->setUseCodeFolding(false);
|
||||||
ui->txtCode->setRightEdge(0);
|
ui->txtCode->setRightEdge(0);
|
||||||
highlighterManager.applyColorScheme(ui->txtCode->highlighter(),
|
syntaxerManager.applyColorScheme(ui->txtCode->syntaxer(),
|
||||||
pSettings->editor().colorScheme());
|
pSettings->editor().colorScheme());
|
||||||
PColorSchemeItem item = pColorManager->getItem(pSettings->editor().colorScheme(),COLOR_SCHEME_ACTIVE_LINE);
|
PColorSchemeItem item = pColorManager->getItem(pSettings->editor().colorScheme(),COLOR_SCHEME_ACTIVE_LINE);
|
||||||
if (item) {
|
if (item) {
|
||||||
|
|
|
@ -57,7 +57,7 @@ void FilePropertiesDialog::calcFile(Editor *editor,
|
||||||
j++;
|
j++;
|
||||||
QString token;
|
QString token;
|
||||||
QSynedit::PTokenAttribute attr;
|
QSynedit::PTokenAttribute attr;
|
||||||
if (editor->getHighlighterAttriAtRowCol(QSynedit::BufferCoord{j+1,i+1},
|
if (editor->getTokenAttriAtRowCol(QSynedit::BufferCoord{j+1,i+1},
|
||||||
token,attr)) {
|
token,attr)) {
|
||||||
// if it is preprocessor...
|
// if it is preprocessor...
|
||||||
if (attr->name() == SYNS_AttrPreprocessor) {
|
if (attr->name() == SYNS_AttrPreprocessor) {
|
||||||
|
|
|
@ -30,17 +30,16 @@ SOURCES += qsynedit/CodeFolding.cpp \
|
||||||
qsynedit/exporter/synexporter.cpp \
|
qsynedit/exporter/synexporter.cpp \
|
||||||
qsynedit/exporter/synhtmlexporter.cpp \
|
qsynedit/exporter/synhtmlexporter.cpp \
|
||||||
qsynedit/exporter/synrtfexporter.cpp \
|
qsynedit/exporter/synrtfexporter.cpp \
|
||||||
qsynedit/highlighter/asm.cpp \
|
qsynedit/syntaxer/asm.cpp \
|
||||||
qsynedit/highlighter/base.cpp \
|
qsynedit/syntaxer/cpp.cpp \
|
||||||
qsynedit/highlighter/composition.cpp \
|
qsynedit/syntaxer/customhighlighterv1.cpp \
|
||||||
qsynedit/highlighter/cpp.cpp \
|
qsynedit/syntaxer/glsl.cpp \
|
||||||
qsynedit/highlighter/customhighlighterv1.cpp \
|
|
||||||
qsynedit/highlighter/glsl.cpp \
|
|
||||||
qsynedit/Search.cpp \
|
qsynedit/Search.cpp \
|
||||||
qsynedit/SearchBase.cpp \
|
qsynedit/SearchBase.cpp \
|
||||||
qsynedit/SearchRegex.cpp \
|
qsynedit/SearchRegex.cpp \
|
||||||
qsynedit/Types.cpp \
|
qsynedit/Types.cpp \
|
||||||
qsynedit/highlighter/makefilehighlighter.cpp
|
qsynedit/syntaxer/makefile.cpp \
|
||||||
|
qsynedit/syntaxer/syntaxer.cpp
|
||||||
|
|
||||||
HEADERS += qsynedit/Search.h \
|
HEADERS += qsynedit/Search.h \
|
||||||
qsynedit/SearchBase.h \
|
qsynedit/SearchBase.h \
|
||||||
|
@ -57,12 +56,11 @@ HEADERS += qsynedit/Search.h \
|
||||||
qsynedit/exporter/synexporter.h \
|
qsynedit/exporter/synexporter.h \
|
||||||
qsynedit/exporter/synhtmlexporter.h \
|
qsynedit/exporter/synhtmlexporter.h \
|
||||||
qsynedit/exporter/synrtfexporter.h \
|
qsynedit/exporter/synrtfexporter.h \
|
||||||
qsynedit/highlighter/asm.h \
|
qsynedit/syntaxer/asm.h \
|
||||||
qsynedit/highlighter/base.h \
|
qsynedit/syntaxer/cpp.h \
|
||||||
qsynedit/highlighter/composition.h \
|
qsynedit/syntaxer/customhighlighterv1.h \
|
||||||
qsynedit/highlighter/cpp.h \
|
qsynedit/syntaxer/glsl.h \
|
||||||
qsynedit/highlighter/customhighlighterv1.h \
|
qsynedit/syntaxer/makefile.h \
|
||||||
qsynedit/highlighter/glsl.h \
|
qsynedit/syntaxer/syntaxer.h
|
||||||
qsynedit/highlighter/makefilehighlighter.h
|
|
||||||
|
|
||||||
INCLUDEPATH += ../redpanda_qt_utils
|
INCLUDEPATH += ../redpanda_qt_utils
|
||||||
|
|
|
@ -30,7 +30,7 @@ extern const QChar SoftBreakGlyph;
|
||||||
|
|
||||||
#define MAX_SCROLL 65535
|
#define MAX_SCROLL 65535
|
||||||
|
|
||||||
// names for highlighter attributes
|
// names for token attributes
|
||||||
#define SYNS_AttrAssembler "Assembler"
|
#define SYNS_AttrAssembler "Assembler"
|
||||||
#define SYNS_AttrCharacter "Character"
|
#define SYNS_AttrCharacter "Character"
|
||||||
#define SYNS_AttrClass "Class"
|
#define SYNS_AttrClass "Class"
|
||||||
|
|
|
@ -42,24 +42,24 @@ int getEOL(const QString &Line, int start)
|
||||||
return Line.size();
|
return Line.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool internalEnumHighlighterAttris(PSyntaxer syntaxer,
|
static bool internalEnumTokenAttributes(PSyntaxer syntaxer,
|
||||||
bool skipDuplicates,
|
bool skipDuplicates,
|
||||||
TokenAttributeProc highlighterAttriProc,
|
TokenAttributeProc tokenAttriProc,
|
||||||
std::initializer_list<void *>& params,
|
std::initializer_list<void *>& params,
|
||||||
SyntaxerList& highlighterList) {
|
SyntaxerList& syntaxerList) {
|
||||||
bool Result = true;
|
bool Result = true;
|
||||||
if (highlighterList.indexOf(syntaxer)>0) {
|
if (syntaxerList.indexOf(syntaxer)>0) {
|
||||||
if (skipDuplicates)
|
if (skipDuplicates)
|
||||||
return Result;
|
return Result;
|
||||||
} else {
|
} else {
|
||||||
highlighterList.append(syntaxer);
|
syntaxerList.append(syntaxer);
|
||||||
}
|
}
|
||||||
if (syntaxer) {
|
if (syntaxer) {
|
||||||
for (PTokenAttribute pAttr: syntaxer->attributes()){
|
for (PTokenAttribute pAttr: syntaxer->attributes()){
|
||||||
QString UniqueAttriName = syntaxer->languageName()
|
QString UniqueAttriName = syntaxer->languageName()
|
||||||
+ QString("%1").arg(highlighterList.indexOf(syntaxer)) + '.'
|
+ QString("%1").arg(syntaxerList.indexOf(syntaxer)) + '.'
|
||||||
+ pAttr->name();
|
+ pAttr->name();
|
||||||
Result = highlighterAttriProc(syntaxer, pAttr,
|
Result = tokenAttriProc(syntaxer, pAttr,
|
||||||
UniqueAttriName, params);
|
UniqueAttriName, params);
|
||||||
if (!Result)
|
if (!Result)
|
||||||
break;
|
break;
|
||||||
|
@ -69,16 +69,16 @@ static bool internalEnumHighlighterAttris(PSyntaxer syntaxer,
|
||||||
}
|
}
|
||||||
|
|
||||||
bool enumTokenAttributes(PSyntaxer syntaxer, bool skipDuplicates,
|
bool enumTokenAttributes(PSyntaxer syntaxer, bool skipDuplicates,
|
||||||
TokenAttributeProc highlighterAttriProc,
|
TokenAttributeProc tokenAttriProc,
|
||||||
std::initializer_list<void *> params)
|
std::initializer_list<void *> params)
|
||||||
{
|
{
|
||||||
if (!syntaxer || !highlighterAttriProc) {
|
if (!syntaxer || !tokenAttriProc) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
SyntaxerList syntaxerList;
|
SyntaxerList syntaxerList;
|
||||||
return internalEnumHighlighterAttris(syntaxer, skipDuplicates,
|
return internalEnumTokenAttributes(syntaxer, skipDuplicates,
|
||||||
highlighterAttriProc, params, syntaxerList);
|
tokenAttriProc, params, syntaxerList);
|
||||||
}
|
}
|
||||||
|
|
||||||
int mulDiv(int a, int b, int c)
|
int mulDiv(int a, int b, int c)
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
#include "highlighter/syntaxer.h"
|
#include "syntaxer/syntaxer.h"
|
||||||
#include <QPaintDevice>
|
#include <QPaintDevice>
|
||||||
#include <QTextStream>
|
#include <QTextStream>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
@ -50,7 +50,7 @@ using TokenAttributeProc = std::function<bool(PSyntaxer syntaxer,
|
||||||
PTokenAttribute attri, const QString& uniqueAttriName,
|
PTokenAttribute attri, const QString& uniqueAttriName,
|
||||||
QList<void *> params)>;
|
QList<void *> params)>;
|
||||||
|
|
||||||
// Enums all child highlighters and their attributes of a TSynMultiSyn through a
|
// Enums all child syntaxers and their attributes of a TSynMultiSyn through a
|
||||||
// callback function.
|
// callback function.
|
||||||
// This function also handles nested TSynMultiSyns including their MarkerAttri.
|
// This function also handles nested TSynMultiSyns including their MarkerAttri.
|
||||||
bool enumTokenAttributes(PSyntaxer syntaxer,
|
bool enumTokenAttributes(PSyntaxer syntaxer,
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#include "SynEdit.h"
|
#include "SynEdit.h"
|
||||||
#include "highlighter/cpp.h"
|
#include "syntaxer/cpp.h"
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
#include <QFontMetrics>
|
#include <QFontMetrics>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
@ -24,7 +24,7 @@
|
||||||
#include <QPaintEvent>
|
#include <QPaintEvent>
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QTimerEvent>
|
#include <QTimerEvent>
|
||||||
#include "highlighter/syntaxer.h"
|
#include "syntaxer/syntaxer.h"
|
||||||
#include "Constants.h"
|
#include "Constants.h"
|
||||||
#include "TextPainter.h"
|
#include "TextPainter.h"
|
||||||
#include <QClipboard>
|
#include <QClipboard>
|
||||||
|
@ -349,48 +349,48 @@ bool SynEdit::canRedo() const
|
||||||
int SynEdit::maxScrollWidth() const
|
int SynEdit::maxScrollWidth() const
|
||||||
{
|
{
|
||||||
int maxLen = mDocument->lengthOfLongestLine();
|
int maxLen = mDocument->lengthOfLongestLine();
|
||||||
if (highlighter())
|
if (syntaxer())
|
||||||
maxLen = maxLen+stringColumns(highlighter()->foldString(),maxLen);
|
maxLen = maxLen+stringColumns(syntaxer()->foldString(),maxLen);
|
||||||
if (mOptions.testFlag(eoScrollPastEol))
|
if (mOptions.testFlag(eoScrollPastEol))
|
||||||
return std::max(maxLen ,1);
|
return std::max(maxLen ,1);
|
||||||
else
|
else
|
||||||
return std::max(maxLen-mCharsInWindow+1, 1);
|
return std::max(maxLen-mCharsInWindow+1, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SynEdit::getHighlighterAttriAtRowCol(const BufferCoord &pos, QString &token, PTokenAttribute &attri)
|
bool SynEdit::getTokenAttriAtRowCol(const BufferCoord &pos, QString &token, PTokenAttribute &attri)
|
||||||
{
|
{
|
||||||
int tmpStart;
|
int tmpStart;
|
||||||
return getHighlighterAttriAtRowColEx(pos, token, tmpStart, attri);
|
return getTokenAttriAtRowColEx(pos, token, tmpStart, attri);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SynEdit::getHighlighterAttriAtRowCol(const BufferCoord &pos, QString &token, bool &tokenFinished, PTokenAttribute &attri)
|
bool SynEdit::getTokenAttriAtRowCol(const BufferCoord &pos, QString &token, bool &tokenFinished, PTokenAttribute &attri)
|
||||||
{
|
{
|
||||||
int posX, posY, endPos, start;
|
int posX, posY, endPos, start;
|
||||||
QString line;
|
QString line;
|
||||||
posY = pos.line - 1;
|
posY = pos.line - 1;
|
||||||
if (mHighlighter && (posY >= 0) && (posY < mDocument->count())) {
|
if (mSyntaxer && (posY >= 0) && (posY < mDocument->count())) {
|
||||||
line = mDocument->getString(posY);
|
line = mDocument->getString(posY);
|
||||||
if (posY == 0) {
|
if (posY == 0) {
|
||||||
mHighlighter->resetState();
|
mSyntaxer->resetState();
|
||||||
} else {
|
} else {
|
||||||
mHighlighter->setState(mDocument->ranges(posY-1));
|
mSyntaxer->setState(mDocument->ranges(posY-1));
|
||||||
}
|
}
|
||||||
mHighlighter->setLine(line, posY);
|
mSyntaxer->setLine(line, posY);
|
||||||
posX = pos.ch;
|
posX = pos.ch;
|
||||||
if ((posX > 0) && (posX <= line.length())) {
|
if ((posX > 0) && (posX <= line.length())) {
|
||||||
while (!mHighlighter->eol()) {
|
while (!mSyntaxer->eol()) {
|
||||||
start = mHighlighter->getTokenPos() + 1;
|
start = mSyntaxer->getTokenPos() + 1;
|
||||||
token = mHighlighter->getToken();
|
token = mSyntaxer->getToken();
|
||||||
endPos = start + token.length()-1;
|
endPos = start + token.length()-1;
|
||||||
if ((posX >= start) && (posX <= endPos)) {
|
if ((posX >= start) && (posX <= endPos)) {
|
||||||
attri = mHighlighter->getTokenAttribute();
|
attri = mSyntaxer->getTokenAttribute();
|
||||||
if (posX == endPos)
|
if (posX == endPos)
|
||||||
tokenFinished = mHighlighter->getTokenFinished();
|
tokenFinished = mSyntaxer->getTokenFinished();
|
||||||
else
|
else
|
||||||
tokenFinished = false;
|
tokenFinished = false;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
mHighlighter->next();
|
mSyntaxer->next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -400,30 +400,30 @@ bool SynEdit::getHighlighterAttriAtRowCol(const BufferCoord &pos, QString &token
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool SynEdit::getHighlighterAttriAtRowColEx(const BufferCoord &pos, QString &token, int &start, PTokenAttribute &attri)
|
bool SynEdit::getTokenAttriAtRowColEx(const BufferCoord &pos, QString &token, int &start, PTokenAttribute &attri)
|
||||||
{
|
{
|
||||||
int posX, posY, endPos;
|
int posX, posY, endPos;
|
||||||
QString line;
|
QString line;
|
||||||
posY = pos.line - 1;
|
posY = pos.line - 1;
|
||||||
if (mHighlighter && (posY >= 0) && (posY < mDocument->count())) {
|
if (mSyntaxer && (posY >= 0) && (posY < mDocument->count())) {
|
||||||
line = mDocument->getString(posY);
|
line = mDocument->getString(posY);
|
||||||
if (posY == 0) {
|
if (posY == 0) {
|
||||||
mHighlighter->resetState();
|
mSyntaxer->resetState();
|
||||||
} else {
|
} else {
|
||||||
mHighlighter->setState(mDocument->ranges(posY-1));
|
mSyntaxer->setState(mDocument->ranges(posY-1));
|
||||||
}
|
}
|
||||||
mHighlighter->setLine(line, posY);
|
mSyntaxer->setLine(line, posY);
|
||||||
posX = pos.ch;
|
posX = pos.ch;
|
||||||
if ((posX > 0) && (posX <= line.length())) {
|
if ((posX > 0) && (posX <= line.length())) {
|
||||||
while (!mHighlighter->eol()) {
|
while (!mSyntaxer->eol()) {
|
||||||
start = mHighlighter->getTokenPos() + 1;
|
start = mSyntaxer->getTokenPos() + 1;
|
||||||
token = mHighlighter->getToken();
|
token = mSyntaxer->getToken();
|
||||||
endPos = start + token.length()-1;
|
endPos = start + token.length()-1;
|
||||||
if ((posX >= start) && (posX <= endPos)) {
|
if ((posX >= start) && (posX <= endPos)) {
|
||||||
attri = mHighlighter->getTokenAttribute();
|
attri = mSyntaxer->getTokenAttribute();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
mHighlighter->next();
|
mSyntaxer->next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -516,7 +516,7 @@ BufferCoord SynEdit::getMatchingBracketEx(BufferCoord APoint)
|
||||||
p.line = PosY;
|
p.line = PosY;
|
||||||
if ((Test == BracketInc) || (Test == BracketDec)) {
|
if ((Test == BracketInc) || (Test == BracketDec)) {
|
||||||
isCommentOrStringOrChar = false;
|
isCommentOrStringOrChar = false;
|
||||||
if (getHighlighterAttriAtRowCol(p, vDummy, attr))
|
if (getTokenAttriAtRowCol(p, vDummy, attr))
|
||||||
isCommentOrStringOrChar =
|
isCommentOrStringOrChar =
|
||||||
(attr->tokenType() == TokenType::String) ||
|
(attr->tokenType() == TokenType::String) ||
|
||||||
(attr->tokenType() == TokenType::Comment) ||
|
(attr->tokenType() == TokenType::Comment) ||
|
||||||
|
@ -550,7 +550,7 @@ BufferCoord SynEdit::getMatchingBracketEx(BufferCoord APoint)
|
||||||
p.line = PosY;
|
p.line = PosY;
|
||||||
if ((Test == BracketInc) || (Test == BracketDec)) {
|
if ((Test == BracketInc) || (Test == BracketDec)) {
|
||||||
isCommentOrStringOrChar = false;
|
isCommentOrStringOrChar = false;
|
||||||
if (getHighlighterAttriAtRowCol(p, vDummy, attr))
|
if (getTokenAttriAtRowCol(p, vDummy, attr))
|
||||||
isCommentOrStringOrChar =
|
isCommentOrStringOrChar =
|
||||||
(attr->tokenType() == TokenType::String) ||
|
(attr->tokenType() == TokenType::String) ||
|
||||||
(attr->tokenType() == TokenType::Comment) ||
|
(attr->tokenType() == TokenType::Comment) ||
|
||||||
|
@ -1292,7 +1292,7 @@ BufferCoord SynEdit::getPreviousLeftBrace(int x, int y)
|
||||||
p.ch = PosX;
|
p.ch = PosX;
|
||||||
p.line = PosY;
|
p.line = PosY;
|
||||||
if (Test=='{' || Test == '}') {
|
if (Test=='{' || Test == '}') {
|
||||||
if (getHighlighterAttriAtRowCol(p, vDummy, attr)) {
|
if (getTokenAttriAtRowCol(p, vDummy, attr)) {
|
||||||
isCommentOrStringOrChar =
|
isCommentOrStringOrChar =
|
||||||
(attr->tokenType() == TokenType::String) ||
|
(attr->tokenType() == TokenType::String) ||
|
||||||
(attr->tokenType() == TokenType::Comment) ||
|
(attr->tokenType() == TokenType::Comment) ||
|
||||||
|
@ -1538,7 +1538,7 @@ int SynEdit::findCommentStartLine(int searchStartLine)
|
||||||
SyntaxerState range;
|
SyntaxerState range;
|
||||||
while (commentStartLine>=1) {
|
while (commentStartLine>=1) {
|
||||||
range = mDocument->ranges(commentStartLine-1);
|
range = mDocument->ranges(commentStartLine-1);
|
||||||
if (!mHighlighter->isLastLineCommentNotFinished(range.state)){
|
if (!mSyntaxer->isLastLineCommentNotFinished(range.state)){
|
||||||
commentStartLine++;
|
commentStartLine++;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -1554,7 +1554,7 @@ int SynEdit::findCommentStartLine(int searchStartLine)
|
||||||
|
|
||||||
int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
|
int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
|
||||||
{
|
{
|
||||||
if (!mHighlighter)
|
if (!mSyntaxer)
|
||||||
return 0;
|
return 0;
|
||||||
line = std::min(line, mDocument->count()+1);
|
line = std::min(line, mDocument->count()+1);
|
||||||
if (line<=1)
|
if (line<=1)
|
||||||
|
@ -1574,20 +1574,20 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
|
||||||
//calculate the indents of last statement;
|
//calculate the indents of last statement;
|
||||||
indentSpaces = leftSpaces(startLineText);
|
indentSpaces = leftSpaces(startLineText);
|
||||||
SyntaxerState rangePreceeding = mDocument->ranges(startLine-1);
|
SyntaxerState rangePreceeding = mDocument->ranges(startLine-1);
|
||||||
mHighlighter->setState(rangePreceeding);
|
mSyntaxer->setState(rangePreceeding);
|
||||||
if (addIndent) {
|
if (addIndent) {
|
||||||
// QString trimmedS = s.trimmed();
|
// QString trimmedS = s.trimmed();
|
||||||
QString trimmedLineText = lineText.trimmed();
|
QString trimmedLineText = lineText.trimmed();
|
||||||
mHighlighter->setLine(trimmedLineText,line-1);
|
mSyntaxer->setLine(trimmedLineText,line-1);
|
||||||
int statePrePre;
|
int statePrePre;
|
||||||
if (startLine>1) {
|
if (startLine>1) {
|
||||||
statePrePre = mDocument->ranges(startLine-2).state;
|
statePrePre = mDocument->ranges(startLine-2).state;
|
||||||
} else {
|
} else {
|
||||||
statePrePre = 0;
|
statePrePre = 0;
|
||||||
}
|
}
|
||||||
SyntaxerState rangeAfterFirstToken = mHighlighter->getState();
|
SyntaxerState rangeAfterFirstToken = mSyntaxer->getState();
|
||||||
QString firstToken = mHighlighter->getToken();
|
QString firstToken = mSyntaxer->getToken();
|
||||||
PTokenAttribute attr = mHighlighter->getTokenAttribute();
|
PTokenAttribute attr = mSyntaxer->getTokenAttribute();
|
||||||
if (attr->tokenType() == TokenType::Keyword
|
if (attr->tokenType() == TokenType::Keyword
|
||||||
&& lineText.endsWith(':')
|
&& lineText.endsWith(':')
|
||||||
&& (
|
&& (
|
||||||
|
@ -1596,11 +1596,11 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
|
||||||
|| firstToken == "default"
|
|| firstToken == "default"
|
||||||
)) {
|
)) {
|
||||||
// public: private: protecte: case: should indents like it's parent statement
|
// public: private: protecte: case: should indents like it's parent statement
|
||||||
mHighlighter->setState(rangePreceeding);
|
mSyntaxer->setState(rangePreceeding);
|
||||||
mHighlighter->setLine("}",line-1);
|
mSyntaxer->setLine("}",line-1);
|
||||||
rangeAfterFirstToken = mHighlighter->getState();
|
rangeAfterFirstToken = mSyntaxer->getState();
|
||||||
firstToken = mHighlighter->getToken();
|
firstToken = mSyntaxer->getToken();
|
||||||
attr = mHighlighter->getTokenAttribute();
|
attr = mSyntaxer->getTokenAttribute();
|
||||||
}
|
}
|
||||||
bool indentAdded = false;
|
bool indentAdded = false;
|
||||||
int additionIndent = 0;
|
int additionIndent = 0;
|
||||||
|
@ -1619,14 +1619,14 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
|
||||||
matchingIndents = rangeAfterFirstToken.matchingIndents;
|
matchingIndents = rangeAfterFirstToken.matchingIndents;
|
||||||
indentAdded = true;
|
indentAdded = true;
|
||||||
l = startLine;
|
l = startLine;
|
||||||
} else if (mHighlighter->language() == ProgrammingLanguage::Cpp
|
} else if (mSyntaxer->language() == ProgrammingLanguage::Cpp
|
||||||
&& trimmedLineText.startsWith('#')
|
&& trimmedLineText.startsWith('#')
|
||||||
&& attr == ((CppSyntaxer *)mHighlighter.get())->preprocessorAttribute()) {
|
&& attr == ((CppSyntaxer *)mSyntaxer.get())->preprocessorAttribute()) {
|
||||||
indentAdded = true;
|
indentAdded = true;
|
||||||
indentSpaces=0;
|
indentSpaces=0;
|
||||||
l=0;
|
l=0;
|
||||||
} else if (mHighlighter->language() == ProgrammingLanguage::Cpp
|
} else if (mSyntaxer->language() == ProgrammingLanguage::Cpp
|
||||||
&& mHighlighter->isLastLineCommentNotFinished(rangePreceeding.state)
|
&& mSyntaxer->isLastLineCommentNotFinished(rangePreceeding.state)
|
||||||
) {
|
) {
|
||||||
// last line is a not finished comment,
|
// last line is a not finished comment,
|
||||||
if (trimmedLineText.startsWith("*")) {
|
if (trimmedLineText.startsWith("*")) {
|
||||||
|
@ -1652,10 +1652,10 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
|
||||||
indentAdded = true;
|
indentAdded = true;
|
||||||
l = startLine;
|
l = startLine;
|
||||||
}
|
}
|
||||||
} else if ( mHighlighter->isLastLineCommentNotFinished(statePrePre)
|
} else if ( mSyntaxer->isLastLineCommentNotFinished(statePrePre)
|
||||||
&& rangePreceeding.matchingIndents.isEmpty()
|
&& rangePreceeding.matchingIndents.isEmpty()
|
||||||
&& rangePreceeding.firstIndentThisLine>=rangePreceeding.indents.length()
|
&& rangePreceeding.firstIndentThisLine>=rangePreceeding.indents.length()
|
||||||
&& !mHighlighter->isLastLineCommentNotFinished(rangePreceeding.state)) {
|
&& !mSyntaxer->isLastLineCommentNotFinished(rangePreceeding.state)) {
|
||||||
// the preceeding line is the end of comment
|
// the preceeding line is the end of comment
|
||||||
// we should use the indents of the start line of the comment
|
// we should use the indents of the start line of the comment
|
||||||
int commentStartLine = findCommentStartLine(startLine-2);
|
int commentStartLine = findCommentStartLine(startLine-2);
|
||||||
|
@ -1723,7 +1723,7 @@ int SynEdit::calcIndentSpaces(int line, const QString& lineText, bool addIndent)
|
||||||
PTokenAttribute attr;
|
PTokenAttribute attr;
|
||||||
coord.line = startLine;
|
coord.line = startLine;
|
||||||
coord.ch = document()->getString(startLine-1).length();
|
coord.ch = document()->getString(startLine-1).length();
|
||||||
if (getHighlighterAttriAtRowCol(coord,token,attr)
|
if (getTokenAttriAtRowCol(coord,token,attr)
|
||||||
&& attr->tokenType() == QSynedit::TokenType::Operator
|
&& attr->tokenType() == QSynedit::TokenType::Operator
|
||||||
&& token == ":") {
|
&& token == ":") {
|
||||||
indentSpaces += tabWidth();
|
indentSpaces += tabWidth();
|
||||||
|
@ -1982,7 +1982,7 @@ QString SynEdit::getDisplayStringAtLine(int line) const
|
||||||
QString s = mDocument->getString(line-1);
|
QString s = mDocument->getString(line-1);
|
||||||
PCodeFoldingRange foldRange = foldStartAtLine(line);
|
PCodeFoldingRange foldRange = foldStartAtLine(line);
|
||||||
if ((foldRange) && foldRange->collapsed) {
|
if ((foldRange) && foldRange->collapsed) {
|
||||||
return s+highlighter()->foldString();
|
return s+syntaxer()->foldString();
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
@ -2395,7 +2395,7 @@ void SynEdit::insertLine(bool moveCaret)
|
||||||
if (mCaretX>lineText().length()+1) {
|
if (mCaretX>lineText().length()+1) {
|
||||||
PCodeFoldingRange foldRange = foldStartAtLine(mCaretY);
|
PCodeFoldingRange foldRange = foldStartAtLine(mCaretY);
|
||||||
if ((foldRange) && foldRange->collapsed) {
|
if ((foldRange) && foldRange->collapsed) {
|
||||||
QString s = Temp+highlighter()->foldString();
|
QString s = Temp+syntaxer()->foldString();
|
||||||
if (mCaretX > s.length()) {
|
if (mCaretX > s.length()) {
|
||||||
if (!mUndoing) {
|
if (!mUndoing) {
|
||||||
addCaretToUndo();
|
addCaretToUndo();
|
||||||
|
@ -2426,19 +2426,19 @@ void SynEdit::insertLine(bool moveCaret)
|
||||||
bool notInComment=true;
|
bool notInComment=true;
|
||||||
properSetLine(mCaretY-1,leftLineText);
|
properSetLine(mCaretY-1,leftLineText);
|
||||||
//update range stated for line mCaretY
|
//update range stated for line mCaretY
|
||||||
if (mHighlighter) {
|
if (mSyntaxer) {
|
||||||
if (mCaretY==1) {
|
if (mCaretY==1) {
|
||||||
mHighlighter->resetState();
|
mSyntaxer->resetState();
|
||||||
} else {
|
} else {
|
||||||
mHighlighter->setState(mDocument->ranges(mCaretY-2));
|
mSyntaxer->setState(mDocument->ranges(mCaretY-2));
|
||||||
}
|
}
|
||||||
mHighlighter->setLine(leftLineText, mCaretY-1);
|
mSyntaxer->setLine(leftLineText, mCaretY-1);
|
||||||
mHighlighter->nextToEol();
|
mSyntaxer->nextToEol();
|
||||||
mDocument->setRange(mCaretY-1,mHighlighter->getState());
|
mDocument->setRange(mCaretY-1,mSyntaxer->getState());
|
||||||
notInComment = !mHighlighter->isLastLineCommentNotFinished(
|
notInComment = !mSyntaxer->isLastLineCommentNotFinished(
|
||||||
mHighlighter->getState().state)
|
mSyntaxer->getState().state)
|
||||||
&& !mHighlighter->isLastLineStringNotFinished(
|
&& !mSyntaxer->isLastLineStringNotFinished(
|
||||||
mHighlighter->getState().state);
|
mSyntaxer->getState().state);
|
||||||
}
|
}
|
||||||
int indentSpaces = 0;
|
int indentSpaces = 0;
|
||||||
if (mOptions.testFlag(eoAutoIndent)) {
|
if (mOptions.testFlag(eoAutoIndent)) {
|
||||||
|
@ -2905,8 +2905,8 @@ void SynEdit::doAddChar(QChar AChar)
|
||||||
// auto
|
// auto
|
||||||
if (mActiveSelectionMode==SelectionMode::Normal
|
if (mActiveSelectionMode==SelectionMode::Normal
|
||||||
&& mOptions.testFlag(eoAutoIndent)
|
&& mOptions.testFlag(eoAutoIndent)
|
||||||
&& mHighlighter
|
&& mSyntaxer
|
||||||
&& mHighlighter->language() == ProgrammingLanguage::Cpp
|
&& mSyntaxer->language() == ProgrammingLanguage::Cpp
|
||||||
&& (oldCaretY<=mDocument->count()) ) {
|
&& (oldCaretY<=mDocument->count()) ) {
|
||||||
|
|
||||||
//unindent if ':' at end of the line
|
//unindent if ':' at end of the line
|
||||||
|
@ -3295,8 +3295,8 @@ void SynEdit::recalcCharExtent()
|
||||||
FontStyle styles[] = {FontStyle::fsBold, FontStyle::fsItalic, FontStyle::fsStrikeOut, FontStyle::fsUnderline};
|
FontStyle styles[] = {FontStyle::fsBold, FontStyle::fsItalic, FontStyle::fsStrikeOut, FontStyle::fsUnderline};
|
||||||
bool hasStyles[] = {false,false,false,false};
|
bool hasStyles[] = {false,false,false,false};
|
||||||
int size = 4;
|
int size = 4;
|
||||||
if (mHighlighter && mHighlighter->attributes().count()>0) {
|
if (mSyntaxer && mSyntaxer->attributes().count()>0) {
|
||||||
for (const PTokenAttribute& attribute: mHighlighter->attributes()) {
|
for (const PTokenAttribute& attribute: mSyntaxer->attributes()) {
|
||||||
for (int i=0;i<size;i++) {
|
for (int i=0;i<size;i++) {
|
||||||
if (attribute->styles().testFlag(styles[i]))
|
if (attribute->styles().testFlag(styles[i]))
|
||||||
hasStyles[i] = true;
|
hasStyles[i] = true;
|
||||||
|
@ -3414,14 +3414,14 @@ int SynEdit::scanFrom(int Index, int canStopIndex)
|
||||||
return Result;
|
return Result;
|
||||||
|
|
||||||
if (Result == 0) {
|
if (Result == 0) {
|
||||||
mHighlighter->resetState();
|
mSyntaxer->resetState();
|
||||||
} else {
|
} else {
|
||||||
mHighlighter->setState(mDocument->ranges(Result-1));
|
mSyntaxer->setState(mDocument->ranges(Result-1));
|
||||||
}
|
}
|
||||||
do {
|
do {
|
||||||
mHighlighter->setLine(mDocument->getString(Result), Result);
|
mSyntaxer->setLine(mDocument->getString(Result), Result);
|
||||||
mHighlighter->nextToEol();
|
mSyntaxer->nextToEol();
|
||||||
iRange = mHighlighter->getState();
|
iRange = mSyntaxer->getState();
|
||||||
if (Result > canStopIndex){
|
if (Result > canStopIndex){
|
||||||
if (mDocument->ranges(Result).state == iRange.state
|
if (mDocument->ranges(Result).state == iRange.state
|
||||||
&& mDocument->ranges(Result).blockLevel == iRange.blockLevel
|
&& mDocument->ranges(Result).blockLevel == iRange.blockLevel
|
||||||
|
@ -3448,7 +3448,7 @@ int SynEdit::scanFrom(int Index, int canStopIndex)
|
||||||
|
|
||||||
void SynEdit::rescanRange(int line)
|
void SynEdit::rescanRange(int line)
|
||||||
{
|
{
|
||||||
if (!mHighlighter)
|
if (!mSyntaxer)
|
||||||
return;
|
return;
|
||||||
line--;
|
line--;
|
||||||
line = std::max(0,line);
|
line = std::max(0,line);
|
||||||
|
@ -3456,24 +3456,24 @@ void SynEdit::rescanRange(int line)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (line == 0) {
|
if (line == 0) {
|
||||||
mHighlighter->resetState();
|
mSyntaxer->resetState();
|
||||||
} else {
|
} else {
|
||||||
mHighlighter->setState(mDocument->ranges(line-1));
|
mSyntaxer->setState(mDocument->ranges(line-1));
|
||||||
}
|
}
|
||||||
mHighlighter->setLine(mDocument->getString(line), line);
|
mSyntaxer->setLine(mDocument->getString(line), line);
|
||||||
mHighlighter->nextToEol();
|
mSyntaxer->nextToEol();
|
||||||
SyntaxerState iRange = mHighlighter->getState();
|
SyntaxerState iRange = mSyntaxer->getState();
|
||||||
mDocument->setRange(line,iRange);
|
mDocument->setRange(line,iRange);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SynEdit::rescanRanges()
|
void SynEdit::rescanRanges()
|
||||||
{
|
{
|
||||||
if (mHighlighter && !mDocument->empty()) {
|
if (mSyntaxer && !mDocument->empty()) {
|
||||||
mHighlighter->resetState();
|
mSyntaxer->resetState();
|
||||||
for (int i =0;i<mDocument->count();i++) {
|
for (int i =0;i<mDocument->count();i++) {
|
||||||
mHighlighter->setLine(mDocument->getString(i), i);
|
mSyntaxer->setLine(mDocument->getString(i), i);
|
||||||
mHighlighter->nextToEol();
|
mSyntaxer->nextToEol();
|
||||||
mDocument->setRange(i, mHighlighter->getState());
|
mDocument->setRange(i, mSyntaxer->getState());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (mUseCodeFolding)
|
if (mUseCodeFolding)
|
||||||
|
@ -3611,9 +3611,9 @@ void SynEdit::scanForFoldRanges(PCodeFoldingRanges topFoldRanges)
|
||||||
}
|
}
|
||||||
|
|
||||||
//this func should only be used in findSubFoldRange
|
//this func should only be used in findSubFoldRange
|
||||||
int SynEdit::lineHasChar(int Line, int startChar, QChar character, const QString& highlighterAttrName) {
|
int SynEdit::lineHasChar(int Line, int startChar, QChar character, const QString& tokenAttrName) {
|
||||||
QString CurLine = mDocument->getString(Line);
|
QString CurLine = mDocument->getString(Line);
|
||||||
if (!mHighlighter){
|
if (!mSyntaxer){
|
||||||
for (int i=startChar; i<CurLine.length();i++) {
|
for (int i=startChar; i<CurLine.length();i++) {
|
||||||
if (CurLine[i]==character) {
|
if (CurLine[i]==character) {
|
||||||
return i;
|
return i;
|
||||||
|
@ -3629,12 +3629,12 @@ int SynEdit::lineHasChar(int Line, int startChar, QChar character, const QString
|
||||||
mHighlighter->setLine(CurLine,Line);
|
mHighlighter->setLine(CurLine,Line);
|
||||||
*/
|
*/
|
||||||
QString token;
|
QString token;
|
||||||
while (!mHighlighter->eol()) {
|
while (!mSyntaxer->eol()) {
|
||||||
token = mHighlighter->getToken();
|
token = mSyntaxer->getToken();
|
||||||
PTokenAttribute attr = mHighlighter->getTokenAttribute();
|
PTokenAttribute attr = mSyntaxer->getTokenAttribute();
|
||||||
if (token == character && attr->name()==highlighterAttrName)
|
if (token == character && attr->name()==tokenAttrName)
|
||||||
return mHighlighter->getTokenPos();
|
return mSyntaxer->getTokenPos();
|
||||||
mHighlighter->next();
|
mSyntaxer->next();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
|
@ -3645,7 +3645,7 @@ void SynEdit::findSubFoldRange(PCodeFoldingRanges topFoldRanges, PCodeFoldingRan
|
||||||
PCodeFoldingRange collapsedFold;
|
PCodeFoldingRange collapsedFold;
|
||||||
int line = 0;
|
int line = 0;
|
||||||
QString curLine;
|
QString curLine;
|
||||||
if (!mHighlighter)
|
if (!mSyntaxer)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
while (line < mDocument->count()) { // index is valid for LinesToScan and fLines
|
while (line < mDocument->count()) { // index is valid for LinesToScan and fLines
|
||||||
|
@ -4597,7 +4597,7 @@ QString SynEdit::selText() const
|
||||||
PCodeFoldingRange foldRange = foldStartAtLine(blockEnd().line);
|
PCodeFoldingRange foldRange = foldStartAtLine(blockEnd().line);
|
||||||
QString s = mDocument->getString(Last);
|
QString s = mDocument->getString(Last);
|
||||||
if ((foldRange) && foldRange->collapsed && ColTo>s.length()) {
|
if ((foldRange) && foldRange->collapsed && ColTo>s.length()) {
|
||||||
s=s+highlighter()->foldString();
|
s=s+syntaxer()->foldString();
|
||||||
if (ColTo>s.length()) {
|
if (ColTo>s.length()) {
|
||||||
Last = foldRange->toLine-1;
|
Last = foldRange->toLine-1;
|
||||||
ColTo = mDocument->getString(Last).length()+1;
|
ColTo = mDocument->getString(Last).length()+1;
|
||||||
|
@ -4676,7 +4676,7 @@ QStringList SynEdit::getContent(BufferCoord startPos, BufferCoord endPos, Select
|
||||||
PCodeFoldingRange foldRange = foldStartAtLine(endPos.line);
|
PCodeFoldingRange foldRange = foldStartAtLine(endPos.line);
|
||||||
QString s = mDocument->getString(Last);
|
QString s = mDocument->getString(Last);
|
||||||
if ((foldRange) && foldRange->collapsed && ColTo>s.length()) {
|
if ((foldRange) && foldRange->collapsed && ColTo>s.length()) {
|
||||||
s=s+highlighter()->foldString();
|
s=s+syntaxer()->foldString();
|
||||||
if (ColTo>s.length()) {
|
if (ColTo>s.length()) {
|
||||||
Last = foldRange->toLine-1;
|
Last = foldRange->toLine-1;
|
||||||
ColTo = mDocument->getString(Last).length()+1;
|
ColTo = mDocument->getString(Last).length()+1;
|
||||||
|
@ -4751,7 +4751,7 @@ QString SynEdit::displayLineText()
|
||||||
QString s= mDocument->getString(mCaretY - 1);
|
QString s= mDocument->getString(mCaretY - 1);
|
||||||
PCodeFoldingRange foldRange = foldStartAtLine(mCaretY);
|
PCodeFoldingRange foldRange = foldStartAtLine(mCaretY);
|
||||||
if ((foldRange) && foldRange->collapsed) {
|
if ((foldRange) && foldRange->collapsed) {
|
||||||
return s+highlighter()->foldString();
|
return s+syntaxer()->foldString();
|
||||||
}
|
}
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
@ -4772,17 +4772,17 @@ void SynEdit::setLineText(const QString s)
|
||||||
mDocument->putString(mCaretY-1,s);
|
mDocument->putString(mCaretY-1,s);
|
||||||
}
|
}
|
||||||
|
|
||||||
PSyntaxer SynEdit::highlighter() const
|
PSyntaxer SynEdit::syntaxer() const
|
||||||
{
|
{
|
||||||
return mHighlighter;
|
return mSyntaxer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SynEdit::setHighlighter(const PSyntaxer &highlighter)
|
void SynEdit::setSyntaxer(const PSyntaxer &syntaxer)
|
||||||
{
|
{
|
||||||
PSyntaxer oldHighlighter= mHighlighter;
|
PSyntaxer oldSyntaxer = mSyntaxer;
|
||||||
mHighlighter = highlighter;
|
mSyntaxer = syntaxer;
|
||||||
if (oldHighlighter && mHighlighter &&
|
if (oldSyntaxer && mSyntaxer &&
|
||||||
oldHighlighter->language() == highlighter->language()) {
|
oldSyntaxer ->language() == syntaxer->language()) {
|
||||||
} else {
|
} else {
|
||||||
recalcCharExtent();
|
recalcCharExtent();
|
||||||
mDocument->beginUpdate();
|
mDocument->beginUpdate();
|
||||||
|
@ -5335,7 +5335,7 @@ void SynEdit::doDeleteText(BufferCoord startPos, BufferCoord endPos, SelectionMo
|
||||||
PCodeFoldingRange foldRange = foldStartAtLine(endPos.line);
|
PCodeFoldingRange foldRange = foldStartAtLine(endPos.line);
|
||||||
QString s = mDocument->getString(endPos.line-1);
|
QString s = mDocument->getString(endPos.line-1);
|
||||||
if ((foldRange) && foldRange->collapsed && endPos.ch>s.length()) {
|
if ((foldRange) && foldRange->collapsed && endPos.ch>s.length()) {
|
||||||
QString newS=s+highlighter()->foldString();
|
QString newS=s+syntaxer()->foldString();
|
||||||
if ((startPos.ch<=s.length() || startPos.line<endPos.line)
|
if ((startPos.ch<=s.length() || startPos.line<endPos.line)
|
||||||
&& endPos.ch>newS.length() ) {
|
&& endPos.ch>newS.length() ) {
|
||||||
//selection has whole block
|
//selection has whole block
|
||||||
|
@ -5479,7 +5479,7 @@ int SynEdit::doInsertTextByNormalMode(const BufferCoord& pos, const QStringList&
|
||||||
int caretY=pos.line;
|
int caretY=pos.line;
|
||||||
// step1: insert the first line of Value into current line
|
// step1: insert the first line of Value into current line
|
||||||
if (text.length()>1) {
|
if (text.length()>1) {
|
||||||
if (!mUndoing && mHighlighter && mHighlighter->language()==ProgrammingLanguage::Cpp && mOptions.testFlag(eoAutoIndent)) {
|
if (!mUndoing && mSyntaxer && mSyntaxer->language()==ProgrammingLanguage::Cpp && mOptions.testFlag(eoAutoIndent)) {
|
||||||
QString s = trimLeft(text[0]);
|
QString s = trimLeft(text[0]);
|
||||||
if (sLeftSide.isEmpty()) {
|
if (sLeftSide.isEmpty()) {
|
||||||
sLeftSide = GetLeftSpacing(calcIndentSpaces(caretY,s,true),true);
|
sLeftSide = GetLeftSpacing(calcIndentSpaces(caretY,s,true),true);
|
||||||
|
@ -5509,7 +5509,7 @@ int SynEdit::doInsertTextByNormalMode(const BufferCoord& pos, const QStringList&
|
||||||
if (i==text.length()-1) {
|
if (i==text.length()-1) {
|
||||||
str = sRightSide;
|
str = sRightSide;
|
||||||
} else {
|
} else {
|
||||||
if (!mUndoing && mHighlighter && mHighlighter->language()==ProgrammingLanguage::Cpp && mOptions.testFlag(eoAutoIndent) && notInComment) {
|
if (!mUndoing && mSyntaxer && mSyntaxer->language()==ProgrammingLanguage::Cpp && mOptions.testFlag(eoAutoIndent) && notInComment) {
|
||||||
str = GetLeftSpacing(calcIndentSpaces(caretY,"",true),true);
|
str = GetLeftSpacing(calcIndentSpaces(caretY,"",true),true);
|
||||||
} else {
|
} else {
|
||||||
str = "";
|
str = "";
|
||||||
|
@ -5519,7 +5519,7 @@ int SynEdit::doInsertTextByNormalMode(const BufferCoord& pos, const QStringList&
|
||||||
str = text[i];
|
str = text[i];
|
||||||
if (i==text.length()-1)
|
if (i==text.length()-1)
|
||||||
str += sRightSide;
|
str += sRightSide;
|
||||||
if (!mUndoing && mHighlighter && mHighlighter->language()==ProgrammingLanguage::Cpp && mOptions.testFlag(eoAutoIndent) && notInComment) {
|
if (!mUndoing && mSyntaxer && mSyntaxer->language()==ProgrammingLanguage::Cpp && mOptions.testFlag(eoAutoIndent) && notInComment) {
|
||||||
int indentSpaces = calcIndentSpaces(caretY,str,true);
|
int indentSpaces = calcIndentSpaces(caretY,str,true);
|
||||||
str = GetLeftSpacing(indentSpaces,true)+trimLeft(str);
|
str = GetLeftSpacing(indentSpaces,true)+trimLeft(str);
|
||||||
}
|
}
|
||||||
|
@ -5983,8 +5983,8 @@ void SynEdit::onBeginFirstPaintLock()
|
||||||
|
|
||||||
bool SynEdit::isIdentChar(const QChar &ch)
|
bool SynEdit::isIdentChar(const QChar &ch)
|
||||||
{
|
{
|
||||||
if (mHighlighter) {
|
if (mSyntaxer) {
|
||||||
return mHighlighter->isIdentChar(ch);
|
return mSyntaxer->isIdentChar(ch);
|
||||||
} else {
|
} else {
|
||||||
if (ch == '_') {
|
if (ch == '_') {
|
||||||
return true;
|
return true;
|
||||||
|
@ -6639,7 +6639,7 @@ void SynEdit::onLinesDeleted(int index, int count)
|
||||||
{
|
{
|
||||||
if (mUseCodeFolding)
|
if (mUseCodeFolding)
|
||||||
foldOnListDeleted(index + 1, count);
|
foldOnListDeleted(index + 1, count);
|
||||||
if (mHighlighter && mDocument->count() > 0)
|
if (mSyntaxer && mDocument->count() > 0)
|
||||||
scanFrom(index, index+1);
|
scanFrom(index, index+1);
|
||||||
invalidateLines(index + 1, INT_MAX);
|
invalidateLines(index + 1, INT_MAX);
|
||||||
invalidateGutterLines(index + 1, INT_MAX);
|
invalidateGutterLines(index + 1, INT_MAX);
|
||||||
|
@ -6649,7 +6649,7 @@ void SynEdit::onLinesInserted(int index, int count)
|
||||||
{
|
{
|
||||||
if (mUseCodeFolding)
|
if (mUseCodeFolding)
|
||||||
foldOnListInserted(index + 1, count);
|
foldOnListInserted(index + 1, count);
|
||||||
if (mHighlighter && mDocument->count() > 0) {
|
if (mSyntaxer && mDocument->count() > 0) {
|
||||||
// int vLastScan = index;
|
// int vLastScan = index;
|
||||||
// do {
|
// do {
|
||||||
scanFrom(index, index+count);
|
scanFrom(index, index+count);
|
||||||
|
@ -6663,7 +6663,7 @@ void SynEdit::onLinesInserted(int index, int count)
|
||||||
void SynEdit::onLinesPutted(int index, int count)
|
void SynEdit::onLinesPutted(int index, int count)
|
||||||
{
|
{
|
||||||
int vEndLine = index + 1;
|
int vEndLine = index + 1;
|
||||||
if (mHighlighter) {
|
if (mSyntaxer) {
|
||||||
vEndLine = std::max(vEndLine, scanFrom(index, index+count) + 1);
|
vEndLine = std::max(vEndLine, scanFrom(index, index+count) + 1);
|
||||||
}
|
}
|
||||||
invalidateLines(index + 1, vEndLine);
|
invalidateLines(index + 1, vEndLine);
|
||||||
|
@ -6721,8 +6721,8 @@ void SynEdit::setBlockEnd(BufferCoord Value)
|
||||||
Value.ch = 1;
|
Value.ch = 1;
|
||||||
} else {
|
} else {
|
||||||
int maxLen = mDocument->lengthOfLongestLine();
|
int maxLen = mDocument->lengthOfLongestLine();
|
||||||
if (highlighter())
|
if (syntaxer())
|
||||||
maxLen = maxLen+stringColumns(highlighter()->foldString(),maxLen);
|
maxLen = maxLen+stringColumns(syntaxer()->foldString(),maxLen);
|
||||||
Value.ch = minMax(Value.ch, 1, maxLen+1);
|
Value.ch = minMax(Value.ch, 1, maxLen+1);
|
||||||
}
|
}
|
||||||
if (Value.ch != mBlockEnd.ch || Value.line != mBlockEnd.line) {
|
if (Value.ch != mBlockEnd.ch || Value.line != mBlockEnd.line) {
|
||||||
|
@ -6820,8 +6820,8 @@ void SynEdit::setBlockBegin(BufferCoord value)
|
||||||
value.ch = 1;
|
value.ch = 1;
|
||||||
} else {
|
} else {
|
||||||
int maxLen = mDocument->lengthOfLongestLine();
|
int maxLen = mDocument->lengthOfLongestLine();
|
||||||
if (highlighter())
|
if (syntaxer())
|
||||||
maxLen = maxLen+stringColumns(highlighter()->foldString(),maxLen);
|
maxLen = maxLen+stringColumns(syntaxer()->foldString(),maxLen);
|
||||||
value.ch = minMax(value.ch, 1, maxLen+1);
|
value.ch = minMax(value.ch, 1, maxLen+1);
|
||||||
}
|
}
|
||||||
if (selAvail()) {
|
if (selAvail()) {
|
||||||
|
|
|
@ -131,9 +131,6 @@ using SynPaintTransientProc = std::function<void(const QPaintDevice& paintDevice
|
||||||
using ProcessCommandProc = std::function<void(EditCommand& command, QChar& AChar, void* data)>;
|
using ProcessCommandProc = std::function<void(EditCommand& command, QChar& AChar, void* data)>;
|
||||||
using MouseCursorProc = std::function<void(const BufferCoord& aLineCharPos, QCursor & aCursor)>;
|
using MouseCursorProc = std::function<void(const BufferCoord& aLineCharPos, QCursor & aCursor)>;
|
||||||
using PaintProc = std::function<void(const QPaintDevice& paintDevice )>;
|
using PaintProc = std::function<void(const QPaintDevice& paintDevice )>;
|
||||||
//using SynPreparePaintHighlightTokenProc = std::function<void(int row,
|
|
||||||
// int column, const QString& token, PSynHighlighterAttribute attr,
|
|
||||||
// FontStyles& style, QColor& foreground, QColor& background)>;
|
|
||||||
using SearchMathedProc = std::function<SearchAction(const QString& sSearch,
|
using SearchMathedProc = std::function<SearchAction(const QString& sSearch,
|
||||||
const QString& sReplace, int Line, int ch, int wordLen)>;
|
const QString& sReplace, int Line, int ch, int wordLen)>;
|
||||||
using SearchConfirmAroundProc = std::function<bool ()>;
|
using SearchConfirmAroundProc = std::function<bool ()>;
|
||||||
|
@ -247,11 +244,11 @@ public:
|
||||||
int maxScrollWidth() const;
|
int maxScrollWidth() const;
|
||||||
int maxScrollHeight() const;
|
int maxScrollHeight() const;
|
||||||
|
|
||||||
bool getHighlighterAttriAtRowCol(const BufferCoord& pos, QString& token,
|
bool getTokenAttriAtRowCol(const BufferCoord& pos, QString& token,
|
||||||
PTokenAttribute& attri);
|
PTokenAttribute& attri);
|
||||||
bool getHighlighterAttriAtRowCol(const BufferCoord& pos, QString& token,
|
bool getTokenAttriAtRowCol(const BufferCoord& pos, QString& token,
|
||||||
bool& tokenFinished, PTokenAttribute& attri);
|
bool& tokenFinished, PTokenAttribute& attri);
|
||||||
bool getHighlighterAttriAtRowColEx(const BufferCoord& pos, QString& token,
|
bool getTokenAttriAtRowColEx(const BufferCoord& pos, QString& token,
|
||||||
int &start, PTokenAttribute& attri);
|
int &start, PTokenAttribute& attri);
|
||||||
|
|
||||||
void beginUndoBlock();
|
void beginUndoBlock();
|
||||||
|
@ -341,8 +338,8 @@ public:
|
||||||
bool modified() const;
|
bool modified() const;
|
||||||
void setModified(bool Value);
|
void setModified(bool Value);
|
||||||
|
|
||||||
PSyntaxer highlighter() const;
|
PSyntaxer syntaxer() const;
|
||||||
void setHighlighter(const PSyntaxer &highlighter);
|
void setSyntaxer(const PSyntaxer &syntaxer);
|
||||||
|
|
||||||
bool useCodeFolding() const;
|
bool useCodeFolding() const;
|
||||||
void setUseCodeFolding(bool value);
|
void setUseCodeFolding(bool value);
|
||||||
|
@ -514,7 +511,7 @@ private:
|
||||||
void rescanFolds(); // rescan for folds
|
void rescanFolds(); // rescan for folds
|
||||||
void rescanForFoldRanges();
|
void rescanForFoldRanges();
|
||||||
void scanForFoldRanges(PCodeFoldingRanges topFoldRanges);
|
void scanForFoldRanges(PCodeFoldingRanges topFoldRanges);
|
||||||
int lineHasChar(int Line, int startChar, QChar character, const QString& highlighterAttrName);
|
int lineHasChar(int Line, int startChar, QChar character, const QString& tokenAttrName);
|
||||||
void findSubFoldRange(PCodeFoldingRanges topFoldRanges,PCodeFoldingRanges& parentFoldRanges, PCodeFoldingRange Parent);
|
void findSubFoldRange(PCodeFoldingRanges topFoldRanges,PCodeFoldingRanges& parentFoldRanges, PCodeFoldingRange Parent);
|
||||||
PCodeFoldingRange collapsedFoldStartAtLine(int Line);
|
PCodeFoldingRange collapsedFoldStartAtLine(int Line);
|
||||||
void initializeCaret();
|
void initializeCaret();
|
||||||
|
@ -667,7 +664,7 @@ private:
|
||||||
ScrollStyle mScrollBars;
|
ScrollStyle mScrollBars;
|
||||||
int mTextHeight;
|
int mTextHeight;
|
||||||
int mTopLine;
|
int mTopLine;
|
||||||
PSyntaxer mHighlighter;
|
PSyntaxer mSyntaxer;
|
||||||
QColor mSelectedForeground;
|
QColor mSelectedForeground;
|
||||||
QColor mSelectedBackground;
|
QColor mSelectedBackground;
|
||||||
QColor mForegroundColor;
|
QColor mForegroundColor;
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
#define SYNEDITSTRINGLIST_H
|
#define SYNEDITSTRINGLIST_H
|
||||||
|
|
||||||
#include <QStringList>
|
#include <QStringList>
|
||||||
#include "highlighter/syntaxer.h"
|
#include "syntaxer/syntaxer.h"
|
||||||
#include <QFontMetrics>
|
#include <QFontMetrics>
|
||||||
#include <QMutex>
|
#include <QMutex>
|
||||||
#include <QVector>
|
#include <QVector>
|
||||||
|
|
|
@ -619,7 +619,7 @@ void SynEditTextPainter::addHighlightToken(const QString &Token, int columnsBefo
|
||||||
foreground = edit->mForegroundColor;
|
foreground = edit->mForegroundColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
edit->onPreparePaintHighlightToken(cLine,edit->mHighlighter->getTokenPos()+1,
|
edit->onPreparePaintHighlightToken(cLine,edit->mSyntaxer->getTokenPos()+1,
|
||||||
Token,p_Attri,style,foreground,background);
|
Token,p_Attri,style,foreground,background);
|
||||||
|
|
||||||
// Do we have to paint the old chars first, or can we just append?
|
// Do we have to paint the old chars first, or can we just append?
|
||||||
|
@ -702,17 +702,17 @@ void SynEditTextPainter::paintFoldAttributes()
|
||||||
X = TabSteps * edit->mCharWidth + edit->textOffset() - 2;
|
X = TabSteps * edit->mCharWidth + edit->textOffset() - 2;
|
||||||
TabSteps+=edit->tabWidth();
|
TabSteps+=edit->tabWidth();
|
||||||
indentLevel++ ;
|
indentLevel++ ;
|
||||||
if (edit->mHighlighter) {
|
if (edit->mSyntaxer) {
|
||||||
if (edit->mCodeFolding.indentGuides) {
|
if (edit->mCodeFolding.indentGuides) {
|
||||||
PTokenAttribute attr = edit->mHighlighter->symbolAttribute();
|
PTokenAttribute attr = edit->mSyntaxer->symbolAttribute();
|
||||||
getBraceColorAttr(indentLevel,attr);
|
getBraceColorAttr(indentLevel,attr);
|
||||||
paintColor = attr->foreground();
|
paintColor = attr->foreground();
|
||||||
}
|
}
|
||||||
if (edit->mCodeFolding.fillIndents) {
|
if (edit->mCodeFolding.fillIndents) {
|
||||||
PTokenAttribute attr = edit->mHighlighter->symbolAttribute();
|
PTokenAttribute attr = edit->mSyntaxer->symbolAttribute();
|
||||||
getBraceColorAttr(indentLevel,attr);
|
getBraceColorAttr(indentLevel,attr);
|
||||||
gradientStart=attr->foreground();
|
gradientStart=attr->foreground();
|
||||||
attr = edit->mHighlighter->symbolAttribute();
|
attr = edit->mSyntaxer->symbolAttribute();
|
||||||
getBraceColorAttr(indentLevel+1,attr);
|
getBraceColorAttr(indentLevel+1,attr);
|
||||||
gradientStart=attr->foreground();
|
gradientStart=attr->foreground();
|
||||||
}
|
}
|
||||||
|
@ -792,7 +792,7 @@ void SynEditTextPainter::paintLines()
|
||||||
int cRow; // row index for the loop
|
int cRow; // row index for the loop
|
||||||
int vLine;
|
int vLine;
|
||||||
QString sLine; // the current line
|
QString sLine; // the current line
|
||||||
QString sToken; // highlighter token info
|
QString sToken; // token info
|
||||||
int nTokenColumnsBefore, nTokenColumnLen;
|
int nTokenColumnsBefore, nTokenColumnLen;
|
||||||
PTokenAttribute attr;
|
PTokenAttribute attr;
|
||||||
int vFirstChar;
|
int vFirstChar;
|
||||||
|
@ -894,7 +894,7 @@ void SynEditTextPainter::paintLines()
|
||||||
|
|
||||||
bLineSelected = (!bComplexLine) && (nLineSelStart > 0);
|
bLineSelected = (!bComplexLine) && (nLineSelStart > 0);
|
||||||
rcToken = rcLine;
|
rcToken = rcLine;
|
||||||
if (!edit->mHighlighter || !edit->mHighlighter->enabled()) {
|
if (!edit->mSyntaxer || !edit->mSyntaxer->enabled()) {
|
||||||
sToken = sLine;
|
sToken = sLine;
|
||||||
if (bCurrentLine) {
|
if (bCurrentLine) {
|
||||||
nTokenColumnLen = edit->stringColumns(sLine,0);
|
nTokenColumnLen = edit->stringColumns(sLine,0);
|
||||||
|
@ -938,12 +938,12 @@ void SynEditTextPainter::paintLines()
|
||||||
// necessary because we probably did not scan to the end of the last
|
// necessary because we probably did not scan to the end of the last
|
||||||
// line - the internal highlighter range might be wrong.
|
// line - the internal highlighter range might be wrong.
|
||||||
if (vLine == 1) {
|
if (vLine == 1) {
|
||||||
edit->mHighlighter->resetState();
|
edit->mSyntaxer->resetState();
|
||||||
} else {
|
} else {
|
||||||
edit->mHighlighter->setState(
|
edit->mSyntaxer->setState(
|
||||||
edit->mDocument->ranges(vLine-2));
|
edit->mDocument->ranges(vLine-2));
|
||||||
}
|
}
|
||||||
edit->mHighlighter->setLine(sLine, vLine - 1);
|
edit->mSyntaxer->setLine(sLine, vLine - 1);
|
||||||
// Try to concatenate as many tokens as possible to minimize the count
|
// Try to concatenate as many tokens as possible to minimize the count
|
||||||
// of ExtTextOut calls necessary. This depends on the selection state
|
// of ExtTextOut calls necessary. This depends on the selection state
|
||||||
// or the line having special colors. For spaces the foreground color
|
// or the line having special colors. For spaces the foreground color
|
||||||
|
@ -951,14 +951,14 @@ void SynEditTextPainter::paintLines()
|
||||||
TokenAccu.Columns = 0;
|
TokenAccu.Columns = 0;
|
||||||
nTokenColumnsBefore = 0;
|
nTokenColumnsBefore = 0;
|
||||||
// Test first whether anything of this token is visible.
|
// Test first whether anything of this token is visible.
|
||||||
while (!edit->mHighlighter->eol()) {
|
while (!edit->mSyntaxer->eol()) {
|
||||||
sToken = edit->mHighlighter->getToken();
|
sToken = edit->mSyntaxer->getToken();
|
||||||
// Work-around buggy highlighters which return empty tokens.
|
// Work-around buggy highlighters which return empty tokens.
|
||||||
if (sToken.isEmpty()) {
|
if (sToken.isEmpty()) {
|
||||||
edit->mHighlighter->next();
|
edit->mSyntaxer->next();
|
||||||
if (edit->mHighlighter->eol())
|
if (edit->mSyntaxer->eol())
|
||||||
break;
|
break;
|
||||||
sToken = edit->mHighlighter->getToken();
|
sToken = edit->mSyntaxer->getToken();
|
||||||
// Maybe should also test whether GetTokenPos changed...
|
// Maybe should also test whether GetTokenPos changed...
|
||||||
if (sToken.isEmpty()) {
|
if (sToken.isEmpty()) {
|
||||||
qDebug()<<SynEdit::tr("The highlighter seems to be in an infinite loop");
|
qDebug()<<SynEdit::tr("The highlighter seems to be in an infinite loop");
|
||||||
|
@ -974,12 +974,12 @@ void SynEditTextPainter::paintLines()
|
||||||
nTokenColumnLen = vLastChar - nTokenColumnsBefore;
|
nTokenColumnLen = vLastChar - nTokenColumnsBefore;
|
||||||
}
|
}
|
||||||
// It's at least partially visible. Get the token attributes now.
|
// It's at least partially visible. Get the token attributes now.
|
||||||
attr = edit->mHighlighter->getTokenAttribute();
|
attr = edit->mSyntaxer->getTokenAttribute();
|
||||||
if (sToken == "["
|
if (sToken == "["
|
||||||
|| sToken == "("
|
|| sToken == "("
|
||||||
|| sToken == "{"
|
|| sToken == "{"
|
||||||
) {
|
) {
|
||||||
SyntaxerState rangeState = edit->mHighlighter->getState();
|
SyntaxerState rangeState = edit->mSyntaxer->getState();
|
||||||
getBraceColorAttr(rangeState.bracketLevel
|
getBraceColorAttr(rangeState.bracketLevel
|
||||||
+rangeState.braceLevel
|
+rangeState.braceLevel
|
||||||
+rangeState.parenthesisLevel
|
+rangeState.parenthesisLevel
|
||||||
|
@ -988,15 +988,15 @@ void SynEditTextPainter::paintLines()
|
||||||
|| sToken == ")"
|
|| sToken == ")"
|
||||||
|| sToken == "}"
|
|| sToken == "}"
|
||||||
){
|
){
|
||||||
SyntaxerState rangeState = edit->mHighlighter->getState();
|
SyntaxerState rangeState = edit->mSyntaxer->getState();
|
||||||
getBraceColorAttr(rangeState.bracketLevel
|
getBraceColorAttr(rangeState.bracketLevel
|
||||||
+rangeState.braceLevel
|
+rangeState.braceLevel
|
||||||
+rangeState.parenthesisLevel+1,
|
+rangeState.parenthesisLevel+1,
|
||||||
attr);
|
attr);
|
||||||
}
|
}
|
||||||
if (bCurrentLine && edit->mInputPreeditString.length()>0) {
|
if (bCurrentLine && edit->mInputPreeditString.length()>0) {
|
||||||
int startPos = edit->mHighlighter->getTokenPos()+1;
|
int startPos = edit->mSyntaxer->getTokenPos()+1;
|
||||||
int endPos = edit->mHighlighter->getTokenPos() + sToken.length();
|
int endPos = edit->mSyntaxer->getTokenPos() + sToken.length();
|
||||||
//qDebug()<<startPos<<":"<<endPos<<" - "+sToken+" - "<<edit->mCaretX<<":"<<edit->mCaretX+edit->mInputPreeditString.length();
|
//qDebug()<<startPos<<":"<<endPos<<" - "+sToken+" - "<<edit->mCaretX<<":"<<edit->mCaretX+edit->mInputPreeditString.length();
|
||||||
if (!(endPos < edit->mCaretX
|
if (!(endPos < edit->mCaretX
|
||||||
|| startPos >= edit->mCaretX+edit->mInputPreeditString.length())) {
|
|| startPos >= edit->mCaretX+edit->mInputPreeditString.length())) {
|
||||||
|
@ -1012,11 +1012,11 @@ void SynEditTextPainter::paintLines()
|
||||||
}
|
}
|
||||||
nTokenColumnsBefore+=nTokenColumnLen;
|
nTokenColumnsBefore+=nTokenColumnLen;
|
||||||
// Let the highlighter scan the next token.
|
// Let the highlighter scan the next token.
|
||||||
edit->mHighlighter->next();
|
edit->mSyntaxer->next();
|
||||||
}
|
}
|
||||||
// Don't assume HL.GetTokenPos is valid after HL.GetEOL == True.
|
// Don't assume HL.GetTokenPos is valid after HL.GetEOL == True.
|
||||||
//nTokenColumnsBefore += edit->stringColumns(sToken,nTokenColumnsBefore);
|
//nTokenColumnsBefore += edit->stringColumns(sToken,nTokenColumnsBefore);
|
||||||
if (edit->mHighlighter->eol() && (nTokenColumnsBefore < vLastChar)) {
|
if (edit->mSyntaxer->eol() && (nTokenColumnsBefore < vLastChar)) {
|
||||||
int lineColumns = edit->mDocument->lineColumns(vLine-1);
|
int lineColumns = edit->mDocument->lineColumns(vLine-1);
|
||||||
// Draw text that couldn't be parsed by the highlighter, if any.
|
// Draw text that couldn't be parsed by the highlighter, if any.
|
||||||
if (nTokenColumnsBefore < lineColumns) {
|
if (nTokenColumnsBefore < lineColumns) {
|
||||||
|
@ -1034,17 +1034,17 @@ void SynEditTextPainter::paintLines()
|
||||||
(!bSpecialLine) && (edit->mDocument->lineColumns(vLine-1) < vLastChar)) {
|
(!bSpecialLine) && (edit->mDocument->lineColumns(vLine-1) < vLastChar)) {
|
||||||
addHighlightToken(LineBreakGlyph,
|
addHighlightToken(LineBreakGlyph,
|
||||||
edit->mDocument->lineColumns(vLine-1) - (vFirstChar - FirstCol),
|
edit->mDocument->lineColumns(vLine-1) - (vFirstChar - FirstCol),
|
||||||
edit->charColumns(LineBreakGlyph),vLine, edit->mHighlighter->whitespaceAttribute());
|
edit->charColumns(LineBreakGlyph),vLine, edit->mSyntaxer->whitespaceAttribute());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Paint folding
|
// Paint folding
|
||||||
foldRange = edit->foldStartAtLine(vLine);
|
foldRange = edit->foldStartAtLine(vLine);
|
||||||
if ((foldRange) && foldRange->collapsed) {
|
if ((foldRange) && foldRange->collapsed) {
|
||||||
sFold = edit->highlighter()->foldString();
|
sFold = edit->syntaxer()->foldString();
|
||||||
nFold = edit->stringColumns(sFold,edit->mDocument->lineColumns(vLine-1));
|
nFold = edit->stringColumns(sFold,edit->mDocument->lineColumns(vLine-1));
|
||||||
attr = edit->mHighlighter->symbolAttribute();
|
attr = edit->mSyntaxer->symbolAttribute();
|
||||||
getBraceColorAttr(edit->mHighlighter->getState().braceLevel,attr);
|
getBraceColorAttr(edit->mSyntaxer->getState().braceLevel,attr);
|
||||||
addHighlightToken(sFold,edit->mDocument->lineColumns(vLine-1) - (vFirstChar - FirstCol)
|
addHighlightToken(sFold,edit->mDocument->lineColumns(vLine-1) - (vFirstChar - FirstCol)
|
||||||
, nFold, vLine, attr);
|
, nFold, vLine, attr);
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
#include <QPainter>
|
#include <QPainter>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include "Types.h"
|
#include "Types.h"
|
||||||
#include "highlighter/syntaxer.h"
|
#include "syntaxer/syntaxer.h"
|
||||||
#include "MiscClasses.h"
|
#include "MiscClasses.h"
|
||||||
|
|
||||||
namespace QSynedit {
|
namespace QSynedit {
|
||||||
|
|
|
@ -61,7 +61,7 @@ void SynExporter::ExportAll(PDocument ALines)
|
||||||
void SynExporter::ExportRange(PDocument ALines, BufferCoord Start, BufferCoord Stop)
|
void SynExporter::ExportRange(PDocument ALines, BufferCoord Start, BufferCoord Stop)
|
||||||
{
|
{
|
||||||
// abort if not all necessary conditions are met
|
// abort if not all necessary conditions are met
|
||||||
if (!ALines || !mHighlighter || (ALines->count() == 0))
|
if (!ALines || !mSyntaxer || (ALines->count() == 0))
|
||||||
return;
|
return;
|
||||||
Stop.line = std::max(1, std::min(Stop.line, ALines->count()));
|
Stop.line = std::max(1, std::min(Stop.line, ALines->count()));
|
||||||
Stop.ch = std::max(1, std::min(Stop.ch, ALines->getString(Stop.line - 1).length() + 1));
|
Stop.ch = std::max(1, std::min(Stop.ch, ALines->getString(Stop.line - 1).length() + 1));
|
||||||
|
@ -77,9 +77,9 @@ void SynExporter::ExportRange(PDocument ALines, BufferCoord Start, BufferCoord S
|
||||||
mFirstAttribute = true;
|
mFirstAttribute = true;
|
||||||
|
|
||||||
if (Start.line == 1)
|
if (Start.line == 1)
|
||||||
mHighlighter->resetState();
|
mSyntaxer->resetState();
|
||||||
else
|
else
|
||||||
mHighlighter->setState(ALines->ranges(Start.line-2));
|
mSyntaxer->setState(ALines->ranges(Start.line-2));
|
||||||
for (int i = Start.line; i<=Stop.line; i++) {
|
for (int i = Start.line; i<=Stop.line; i++) {
|
||||||
QString Line = ALines->getString(i-1);
|
QString Line = ALines->getString(i-1);
|
||||||
// order is important, since Start.Y might be equal to Stop.Y
|
// order is important, since Start.Y might be equal to Stop.Y
|
||||||
|
@ -88,17 +88,17 @@ void SynExporter::ExportRange(PDocument ALines, BufferCoord Start, BufferCoord S
|
||||||
// if ( (i = Start.Line) && (Start.Char > 1))
|
// if ( (i = Start.Line) && (Start.Char > 1))
|
||||||
// Line.remove(0, Start.Char - 1);
|
// Line.remove(0, Start.Char - 1);
|
||||||
// export the line
|
// export the line
|
||||||
mHighlighter->setLine(Line, i);
|
mSyntaxer->setLine(Line, i);
|
||||||
while (!mHighlighter->eol()) {
|
while (!mSyntaxer->eol()) {
|
||||||
PTokenAttribute attri = mHighlighter->getTokenAttribute();
|
PTokenAttribute attri = mSyntaxer->getTokenAttribute();
|
||||||
int startPos = mHighlighter->getTokenPos();
|
int startPos = mSyntaxer->getTokenPos();
|
||||||
QString token = mHighlighter->getToken();
|
QString token = mSyntaxer->getToken();
|
||||||
if (i==Start.line && (startPos+token.length() < Start.ch)) {
|
if (i==Start.line && (startPos+token.length() < Start.ch)) {
|
||||||
mHighlighter->next();
|
mSyntaxer->next();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (i==Stop.line && (startPos >= Stop.ch-1)) {
|
if (i==Stop.line && (startPos >= Stop.ch-1)) {
|
||||||
mHighlighter->next();
|
mSyntaxer->next();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (i==Stop.line && (startPos+token.length() > Stop.ch)) {
|
if (i==Stop.line && (startPos+token.length() > Stop.ch)) {
|
||||||
|
@ -110,10 +110,10 @@ void SynExporter::ExportRange(PDocument ALines, BufferCoord Start, BufferCoord S
|
||||||
|
|
||||||
QString Token = ReplaceReservedChars(token);
|
QString Token = ReplaceReservedChars(token);
|
||||||
if (mOnFormatToken)
|
if (mOnFormatToken)
|
||||||
mOnFormatToken(mHighlighter, i, mHighlighter->getTokenPos()+1, mHighlighter->getToken(),attri);
|
mOnFormatToken(mSyntaxer, i, mSyntaxer->getTokenPos()+1, mSyntaxer->getToken(),attri);
|
||||||
SetTokenAttribute(attri);
|
SetTokenAttribute(attri);
|
||||||
FormatToken(Token);
|
FormatToken(Token);
|
||||||
mHighlighter->next();
|
mSyntaxer->next();
|
||||||
}
|
}
|
||||||
if (i!=Stop.line)
|
if (i!=Stop.line)
|
||||||
FormatNewLine();
|
FormatNewLine();
|
||||||
|
@ -166,18 +166,18 @@ void SynExporter::setFont(const QFont &font)
|
||||||
mFont = font;
|
mFont = font;
|
||||||
}
|
}
|
||||||
|
|
||||||
PSyntaxer SynExporter::highlighter() const
|
PSyntaxer SynExporter::syntaxer() const
|
||||||
{
|
{
|
||||||
return mHighlighter;
|
return mSyntaxer;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SynExporter::setHighlighter(PSyntaxer Value)
|
void SynExporter::setSyntaxer(PSyntaxer value)
|
||||||
{
|
{
|
||||||
if (mHighlighter != Value) {
|
if (mSyntaxer != value) {
|
||||||
mHighlighter = Value;
|
mSyntaxer = value;
|
||||||
clear();
|
clear();
|
||||||
if ((mHighlighter) && (mHighlighter->whitespaceAttribute()) && mUseBackground)
|
if ((mSyntaxer) && (mSyntaxer->whitespaceAttribute()) && mUseBackground)
|
||||||
mBackgroundColor = mHighlighter->whitespaceAttribute()->background();
|
mBackgroundColor = mSyntaxer->whitespaceAttribute()->background();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -206,8 +206,8 @@ void SynExporter::setUseBackground(bool Value)
|
||||||
if (mUseBackground != Value) {
|
if (mUseBackground != Value) {
|
||||||
mUseBackground = Value;
|
mUseBackground = Value;
|
||||||
clear();
|
clear();
|
||||||
if ((mHighlighter) && (mHighlighter->whitespaceAttribute()) && mUseBackground)
|
if ((mSyntaxer) && (mSyntaxer->whitespaceAttribute()) && mUseBackground)
|
||||||
mBackgroundColor = mHighlighter->whitespaceAttribute()->background();
|
mBackgroundColor = mSyntaxer->whitespaceAttribute()->background();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -69,8 +69,8 @@ public:
|
||||||
QFont font() const;
|
QFont font() const;
|
||||||
void setFont(const QFont &font);
|
void setFont(const QFont &font);
|
||||||
|
|
||||||
PSyntaxer highlighter() const;
|
PSyntaxer syntaxer() const;
|
||||||
void setHighlighter(PSyntaxer Value);
|
void setSyntaxer(PSyntaxer value);
|
||||||
|
|
||||||
QString title() const;
|
QString title() const;
|
||||||
void setTitle(const QString &Value);
|
void setTitle(const QString &Value);
|
||||||
|
@ -112,7 +112,7 @@ protected:
|
||||||
QString mDefaultFilter;
|
QString mDefaultFilter;
|
||||||
bool mExportAsText;
|
bool mExportAsText;
|
||||||
QFont mFont;
|
QFont mFont;
|
||||||
PSyntaxer mHighlighter;
|
PSyntaxer mSyntaxer;
|
||||||
QColor mLastBG;
|
QColor mLastBG;
|
||||||
QColor mLastFG;
|
QColor mLastFG;
|
||||||
FontStyles mLastStyle;
|
FontStyles mLastStyle;
|
||||||
|
|
|
@ -124,7 +124,7 @@ void SynHTMLExporter::FormatAttributeDone(bool , bool , FontStyles )
|
||||||
|
|
||||||
void SynHTMLExporter::FormatAttributeInit(bool , bool , FontStyles )
|
void SynHTMLExporter::FormatAttributeInit(bool , bool , FontStyles )
|
||||||
{
|
{
|
||||||
QString StyleName = GetStyleName(mHighlighter, mLastAttri);
|
QString StyleName = GetStyleName(mSyntaxer, mLastAttri);
|
||||||
AddData(QString("<span class=\"%1\">").arg(StyleName));
|
AddData(QString("<span class=\"%1\">").arg(StyleName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -135,7 +135,7 @@ void SynHTMLExporter::FormatAfterLastAttribute()
|
||||||
|
|
||||||
void SynHTMLExporter::FormatBeforeFirstAttribute(bool, bool, FontStyles)
|
void SynHTMLExporter::FormatBeforeFirstAttribute(bool, bool, FontStyles)
|
||||||
{
|
{
|
||||||
QString StyleName = GetStyleName(mHighlighter, mLastAttri);
|
QString StyleName = GetStyleName(mSyntaxer, mLastAttri);
|
||||||
AddData(QString("<span class=\"%1\">").arg(StyleName));
|
AddData(QString("<span class=\"%1\">").arg(StyleName));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -164,7 +164,7 @@ QString SynHTMLExporter::GetHeader()
|
||||||
{
|
{
|
||||||
using namespace std::placeholders;
|
using namespace std::placeholders;
|
||||||
QString Styles;
|
QString Styles;
|
||||||
enumTokenAttributes(mHighlighter, true,
|
enumTokenAttributes(mSyntaxer, true,
|
||||||
std::bind(&SynHTMLExporter::AttriToCSSCallback,
|
std::bind(&SynHTMLExporter::AttriToCSSCallback,
|
||||||
this, _1, _2, _3, _4),
|
this, _1, _2, _3, _4),
|
||||||
{&Styles});
|
{&Styles});
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#ifndef SYNEDITCPPHIGHLIGHTER_H
|
#ifndef QSYNEDIT_CPP_SYNTAXER_H
|
||||||
#define SYNEDITCPPHIGHLIGHTER_H
|
#define QSYNEDIT_CPP_SYNTAXER_H
|
||||||
#include "syntaxer.h"
|
#include "syntaxer.h"
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#ifndef SYNEDITGLSLHIGHLIGHTER_H
|
#ifndef QSYNEDIT_GLSL_SYNTAXER_H
|
||||||
#define SYNEDITGLSLHIGHLIGHTER_H
|
#define QSYNEDIT_GLSL_SYNTAXER_H
|
||||||
#include "syntaxer.h"
|
#include "syntaxer.h"
|
||||||
#include <QSet>
|
#include <QSet>
|
||||||
|
|
|
@ -14,8 +14,8 @@
|
||||||
* You should have received a copy of the GNU General Public License
|
* You should have received a copy of the GNU General Public License
|
||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#ifndef MAKEFILE_H
|
#ifndef QSYNEDIT_MAKEFILE_SYNTAXER_H
|
||||||
#define MAKEFILE_H
|
#define QSYNEDIT_MAKEFILE_SYNTAXER_H
|
||||||
|
|
||||||
|
|
||||||
#include "syntaxer.h"
|
#include "syntaxer.h"
|
Loading…
Reference in New Issue