* work save
This commit is contained in:
parent
37a40c9a78
commit
2ea5169675
|
@ -0,0 +1,55 @@
|
||||||
|
#include "HighlighterManager.h"
|
||||||
|
#include <QFileInfo>
|
||||||
|
#include <QObject>
|
||||||
|
#include "qsynedit/highlighter/cpp.h"
|
||||||
|
|
||||||
|
HighlighterManager highlighterManager;
|
||||||
|
|
||||||
|
HighlighterManager::HighlighterManager()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
PSynHighlighter HighlighterManager::createHighlighter(const QString &filename)
|
||||||
|
{
|
||||||
|
if (filename.isEmpty() || filename.startsWith(QObject::tr("untitled"))) {
|
||||||
|
return createCppHighlighter();
|
||||||
|
} else {
|
||||||
|
QFileInfo info(filename);
|
||||||
|
QString suffix = info.suffix();
|
||||||
|
if (suffix.isEmpty() || suffix == "c" || suffix == "cpp" || suffix == "cxx"
|
||||||
|
|| suffix == "cc" || suffix == "h" || suffix == "hpp"
|
||||||
|
|| suffix == "hxx" || suffix == "hh") {
|
||||||
|
return createCppHighlighter();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return PSynHighlighter();
|
||||||
|
}
|
||||||
|
|
||||||
|
PSynHighlighter HighlighterManager::createCppHighlighter()
|
||||||
|
{
|
||||||
|
SynEditCppHighlighter* highlighter = new SynEditCppHighlighter();
|
||||||
|
PSynHighlighter pHighlighter(highlighter);
|
||||||
|
highlighter->asmAttribute()->setForeground(QColorConstants::Blue);
|
||||||
|
highlighter->charAttribute()->setForeground(QColorConstants::Black);
|
||||||
|
highlighter->commentAttribute()->setForeground(0x8C8C8C);
|
||||||
|
highlighter->commentAttribute()->setStyles(SynFontStyle::fsItalic);
|
||||||
|
highlighter->classAttribute()->setForeground(0x008080);
|
||||||
|
highlighter->floatAttribute()->setForeground(QColorConstants::Svg::purple);
|
||||||
|
highlighter->functionAttribute()->setForeground(0x00627A);
|
||||||
|
highlighter->globalVarAttribute()->setForeground(0x660E7A);
|
||||||
|
highlighter->hexAttribute()->setForeground(QColorConstants::Svg::purple);
|
||||||
|
highlighter->identifierAttribute()->setForeground(0x080808);
|
||||||
|
highlighter->invalidAttribute()->setForeground(QColorConstants::Svg::red);
|
||||||
|
highlighter->localVarAttribute()->setForeground(QColorConstants::Black);
|
||||||
|
highlighter->numberAttribute()->setForeground(0x1750EB);
|
||||||
|
highlighter->octAttribute()->setForeground(QColorConstants::Svg::purple);
|
||||||
|
highlighter->direcAttribute()->setForeground(0x1f542e);
|
||||||
|
highlighter->keyAttribute()->setForeground(0x0033b3);
|
||||||
|
highlighter->whitespaceAttribute()->setForeground(QColorConstants::Svg::silver);
|
||||||
|
highlighter->stringAttribute()->setForeground(0x007d17);
|
||||||
|
highlighter->stringEscapeSequenceAttribute()->setForeground(QColorConstants::Svg::red);
|
||||||
|
highlighter->symbolAttribute()->setForeground(0xc10000);
|
||||||
|
highlighter->variableAttribute()->setForeground(0x400080);
|
||||||
|
return pHighlighter;
|
||||||
|
}
|
|
@ -0,0 +1,16 @@
|
||||||
|
#ifndef HIGHLIGHTERMANAGER_H
|
||||||
|
#define HIGHLIGHTERMANAGER_H
|
||||||
|
#include "qsynedit/highlighter/base.h"
|
||||||
|
|
||||||
|
class HighlighterManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
HighlighterManager();
|
||||||
|
|
||||||
|
PSynHighlighter createHighlighter(const QString& filename);
|
||||||
|
PSynHighlighter createCppHighlighter();
|
||||||
|
};
|
||||||
|
|
||||||
|
extern HighlighterManager highlighterManager;
|
||||||
|
|
||||||
|
#endif // HIGHLIGHTERMANAGER_H
|
|
@ -9,6 +9,7 @@ CONFIG += c++14
|
||||||
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
#DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
|
HighlighterManager.cpp \
|
||||||
compiler/compiler.cpp \
|
compiler/compiler.cpp \
|
||||||
compiler/compilermanager.cpp \
|
compiler/compilermanager.cpp \
|
||||||
compiler/executablerunner.cpp \
|
compiler/executablerunner.cpp \
|
||||||
|
@ -38,6 +39,7 @@ SOURCES += \
|
||||||
widgets/issuestable.cpp
|
widgets/issuestable.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
|
HighlighterManager.h \
|
||||||
compiler/compiler.h \
|
compiler/compiler.h \
|
||||||
compiler/compilermanager.h \
|
compiler/compilermanager.h \
|
||||||
compiler/executablerunner.h \
|
compiler/executablerunner.h \
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include "qsynedit/highlighter/cpp.h"
|
#include "qsynedit/highlighter/cpp.h"
|
||||||
|
#include "HighlighterManager.h"
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
@ -30,6 +31,7 @@ const char *SaveException::what() const noexcept {
|
||||||
return mReason.toLocal8Bit();
|
return mReason.toLocal8Bit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Editor::newfileCount=0;
|
||||||
|
|
||||||
Editor::Editor(QWidget *parent, const QString& filename,
|
Editor::Editor(QWidget *parent, const QString& filename,
|
||||||
const QByteArray& encoding,
|
const QByteArray& encoding,
|
||||||
|
@ -43,7 +45,8 @@ Editor::Editor(QWidget *parent, const QString& filename,
|
||||||
mParentPageControl(parentPageControl)
|
mParentPageControl(parentPageControl)
|
||||||
{
|
{
|
||||||
if (mFilename.isEmpty()) {
|
if (mFilename.isEmpty()) {
|
||||||
mFilename = tr("untitled") + "1";
|
newfileCount++;
|
||||||
|
mFilename = tr("untitled") + newfileCount;
|
||||||
}
|
}
|
||||||
QFileInfo fileInfo(mFilename);
|
QFileInfo fileInfo(mFilename);
|
||||||
if (mParentPageControl!=NULL) {
|
if (mParentPageControl!=NULL) {
|
||||||
|
@ -52,11 +55,13 @@ Editor::Editor(QWidget *parent, const QString& filename,
|
||||||
}
|
}
|
||||||
if (!isNew) {
|
if (!isNew) {
|
||||||
loadFile();
|
loadFile();
|
||||||
|
setHighlighter(highlighterManager.createHighlighter(mFilename));
|
||||||
} else {
|
} else {
|
||||||
if (mEncodingOption == ENCODING_AUTO_DETECT)
|
if (mEncodingOption == ENCODING_AUTO_DETECT)
|
||||||
mFileEncoding = ENCODING_ASCII;
|
mFileEncoding = ENCODING_ASCII;
|
||||||
else
|
else
|
||||||
mFileEncoding = mEncodingOption;
|
mFileEncoding = mEncodingOption;
|
||||||
|
setHighlighter(highlighterManager.createCppHighlighter());
|
||||||
}
|
}
|
||||||
|
|
||||||
//SynEditCppHighlighter highlighter;
|
//SynEditCppHighlighter highlighter;
|
||||||
|
|
|
@ -73,6 +73,7 @@ protected slots:
|
||||||
void onLinesChanged(int startLine, int count) ;
|
void onLinesChanged(int startLine, int count) ;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
static int newfileCount;
|
||||||
QByteArray mEncodingOption; // the encoding type set by the user
|
QByteArray mEncodingOption; // the encoding type set by the user
|
||||||
QByteArray mFileEncoding; // the real encoding of the file (auto detected)
|
QByteArray mFileEncoding; // the real encoding of the file (auto detected)
|
||||||
QString mFilename;
|
QString mFilename;
|
||||||
|
@ -80,7 +81,6 @@ private:
|
||||||
bool mInProject;
|
bool mInProject;
|
||||||
bool mIsNew;
|
bool mIsNew;
|
||||||
|
|
||||||
|
|
||||||
// QWidget interface
|
// QWidget interface
|
||||||
protected:
|
protected:
|
||||||
void wheelEvent(QWheelEvent *event) override;
|
void wheelEvent(QWheelEvent *event) override;
|
||||||
|
|
|
@ -1143,6 +1143,23 @@ int SynEdit::scanFrom(int Index)
|
||||||
return Result;
|
return Result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int SynEdit::scanRanges()
|
||||||
|
{
|
||||||
|
if (mHighlighter && !mLines->empty()) {
|
||||||
|
mHighlighter->resetState();
|
||||||
|
for (int i =0;i<mLines->count();i++) {
|
||||||
|
mHighlighter->setLine(mLines->getString(i), i);
|
||||||
|
qDebug()<<i<<mLines->getString(i);
|
||||||
|
mHighlighter->nextToEol();
|
||||||
|
mLines->setRange(i, mHighlighter->getRangeState());
|
||||||
|
mLines->setParenthesisLevel(i, mHighlighter->getParenthesisLevel());
|
||||||
|
mLines->setBracketLevel(i, mHighlighter->getBracketLevel());
|
||||||
|
mLines->setBraceLevel(i, mHighlighter->getBraceLevel());
|
||||||
|
}
|
||||||
|
qDebug()<<"finished.";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void SynEdit::uncollapse(PSynEditFoldRange FoldRange)
|
void SynEdit::uncollapse(PSynEditFoldRange FoldRange)
|
||||||
{
|
{
|
||||||
FoldRange->linesCollapsed = 0;
|
FoldRange->linesCollapsed = 0;
|
||||||
|
@ -1521,7 +1538,6 @@ void SynEdit::sizeOrFontChanged(bool bFont)
|
||||||
gutterChanged();
|
gutterChanged();
|
||||||
else
|
else
|
||||||
updateScrollbars();
|
updateScrollbars();
|
||||||
initializeCaret();
|
|
||||||
mStateFlags.setFlag(SynStateFlag::sfCaretChanged,false);
|
mStateFlags.setFlag(SynStateFlag::sfCaretChanged,false);
|
||||||
invalidate();
|
invalidate();
|
||||||
} else
|
} else
|
||||||
|
@ -1546,6 +1562,29 @@ void SynEdit::doScrolled(int)
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PSynHighlighter SynEdit::highlighter() const
|
||||||
|
{
|
||||||
|
return mHighlighter;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SynEdit::setHighlighter(const PSynHighlighter &highlighter)
|
||||||
|
{
|
||||||
|
PSynHighlighter oldHighlighter= mHighlighter;
|
||||||
|
mHighlighter = highlighter;
|
||||||
|
if (oldHighlighter && mHighlighter &&
|
||||||
|
oldHighlighter->language() == highlighter->language()) {
|
||||||
|
} else {
|
||||||
|
recalcCharExtent();
|
||||||
|
mLines->beginUpdate();
|
||||||
|
auto action=finally([this]{
|
||||||
|
mLines->endUpdate();
|
||||||
|
});
|
||||||
|
scanRanges();
|
||||||
|
}
|
||||||
|
sizeOrFontChanged(true);
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
PSynEditStringList SynEdit::lines() const
|
PSynEditStringList SynEdit::lines() const
|
||||||
{
|
{
|
||||||
return mLines;
|
return mLines;
|
||||||
|
|
|
@ -292,6 +292,7 @@ private:
|
||||||
QString expandAtWideGlyphs(const QString& S);
|
QString expandAtWideGlyphs(const QString& S);
|
||||||
void updateModifiedStatus();
|
void updateModifiedStatus();
|
||||||
int scanFrom(int Index);
|
int scanFrom(int Index);
|
||||||
|
int scanRanges();
|
||||||
void uncollapse(PSynEditFoldRange FoldRange);
|
void uncollapse(PSynEditFoldRange FoldRange);
|
||||||
void foldOnListInserted(int Line, int Count);
|
void foldOnListInserted(int Line, int Count);
|
||||||
void foldOnListDeleted(int Line, int Count);
|
void foldOnListDeleted(int Line, int Count);
|
||||||
|
@ -458,6 +459,9 @@ public:
|
||||||
bool event(QEvent *event) override;
|
bool event(QEvent *event) override;
|
||||||
|
|
||||||
// QWidget interface
|
// QWidget interface
|
||||||
|
PSynHighlighter highlighter() const;
|
||||||
|
void setHighlighter(const PSynHighlighter &highlighter);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
void focusInEvent(QFocusEvent *event) override;
|
void focusInEvent(QFocusEvent *event) override;
|
||||||
void focusOutEvent(QFocusEvent *event) override;
|
void focusOutEvent(QFocusEvent *event) override;
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
#include "base.h"
|
#include "base.h"
|
||||||
#include "../Constants.h"
|
#include "../Constants.h"
|
||||||
|
|
||||||
SynHighlighter::SynHighlighter(QObject *parent) : QObject(parent),
|
SynHighlighter::SynHighlighter() :
|
||||||
mWordBreakChars{ SynWordBreakChars },
|
|
||||||
mEnabled(true),
|
mEnabled(true),
|
||||||
mUpdateCount(0)
|
mWordBreakChars{ SynWordBreakChars }
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -49,34 +48,6 @@ PSynHighlighterAttribute SynHighlighter::symbolAttribute() const
|
||||||
return mSymbolAttribute;
|
return mSymbolAttribute;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SynHighlighter::onAttributeChanged()
|
|
||||||
{
|
|
||||||
setAttributesChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
void SynHighlighter::setAttributesChanged()
|
|
||||||
{
|
|
||||||
if (mUpdateCount == 0) {
|
|
||||||
emit attributesChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SynHighlighter::beginUpdate()
|
|
||||||
{
|
|
||||||
mUpdateCount++;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SynHighlighter::endUpdate()
|
|
||||||
{
|
|
||||||
mUpdateCount--;
|
|
||||||
if (mUpdateCount == 0) {
|
|
||||||
setAttributesChanged();
|
|
||||||
}
|
|
||||||
if (mUpdateCount<0) {
|
|
||||||
throw new std::out_of_range("mUpdateCount in SynHighlighterBase < 0");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SynRangeState SynHighlighter::getRangeState() const
|
SynRangeState SynHighlighter::getRangeState() const
|
||||||
{
|
{
|
||||||
return {0,0};
|
return {0,0};
|
||||||
|
@ -129,7 +100,7 @@ bool SynHighlighter::isIdentChar(const QChar &ch) const
|
||||||
if (ch>='a' && ch <= 'z') {
|
if (ch>='a' && ch <= 'z') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if (ch>='A' && ch <= 'A') {
|
if (ch>='A' && ch <= 'Z') {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -138,8 +109,6 @@ bool SynHighlighter::isIdentChar(const QChar &ch) const
|
||||||
void SynHighlighter::addAttribute(PSynHighlighterAttribute attribute)
|
void SynHighlighter::addAttribute(PSynHighlighterAttribute attribute)
|
||||||
{
|
{
|
||||||
mAttributes[attribute->name()]=attribute;
|
mAttributes[attribute->name()]=attribute;
|
||||||
connect(attribute.get(), &SynHighlighterAttribute::changed,
|
|
||||||
this, &SynHighlighter::setAttributesChanged);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SynHighlighter::clearAttributes()
|
void SynHighlighter::clearAttributes()
|
||||||
|
@ -170,15 +139,9 @@ void SynHighlighter::setEnabled(bool value)
|
||||||
{
|
{
|
||||||
if (value != mEnabled) {
|
if (value != mEnabled) {
|
||||||
mEnabled = value;
|
mEnabled = value;
|
||||||
setAttributesChanged();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SynHighlighterAttribute::setChanged()
|
|
||||||
{
|
|
||||||
emit changed();
|
|
||||||
}
|
|
||||||
|
|
||||||
SynFontStyles SynHighlighterAttribute::styles() const
|
SynFontStyles SynHighlighterAttribute::styles() const
|
||||||
{
|
{
|
||||||
return mStyles;
|
return mStyles;
|
||||||
|
@ -188,10 +151,29 @@ void SynHighlighterAttribute::setStyles(const SynFontStyles &styles)
|
||||||
{
|
{
|
||||||
if (mStyles!=styles) {
|
if (mStyles!=styles) {
|
||||||
mStyles = styles;
|
mStyles = styles;
|
||||||
setChanged();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QColor SynHighlighterAttribute::foreground() const
|
||||||
|
{
|
||||||
|
return mForeground;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SynHighlighterAttribute::setForeground(const QColor &color)
|
||||||
|
{
|
||||||
|
mForeground = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
QColor SynHighlighterAttribute::background() const
|
||||||
|
{
|
||||||
|
return mBackground;
|
||||||
|
}
|
||||||
|
|
||||||
|
void SynHighlighterAttribute::setBackground(const QColor &background)
|
||||||
|
{
|
||||||
|
mBackground = background;
|
||||||
|
}
|
||||||
|
|
||||||
QString SynHighlighterAttribute::name() const
|
QString SynHighlighterAttribute::name() const
|
||||||
{
|
{
|
||||||
return mName;
|
return mName;
|
||||||
|
@ -201,41 +183,13 @@ void SynHighlighterAttribute::setName(const QString &name)
|
||||||
{
|
{
|
||||||
if (mName!=name) {
|
if (mName!=name) {
|
||||||
mName = name;
|
mName = name;
|
||||||
setChanged();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor SynHighlighterAttribute::foreground() const
|
SynHighlighterAttribute::SynHighlighterAttribute(const QString &name):
|
||||||
{
|
mForeground(QColor()),
|
||||||
return mForeground;
|
mBackground(QColor()),
|
||||||
}
|
mName(name)
|
||||||
|
|
||||||
void SynHighlighterAttribute::setForeground(const QColor &foreground)
|
|
||||||
{
|
|
||||||
if (mForeground!=foreground) {
|
|
||||||
mForeground = foreground;
|
|
||||||
setChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
SynHighlighterAttribute::SynHighlighterAttribute(const QString &name, QObject *parent):
|
|
||||||
QObject(parent),
|
|
||||||
mName(name),
|
|
||||||
mForeground(QColorConstants::Black),
|
|
||||||
mBackground(QColorConstants::White)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QColor SynHighlighterAttribute::background() const
|
|
||||||
{
|
|
||||||
return mBackground;
|
|
||||||
}
|
|
||||||
|
|
||||||
void SynHighlighterAttribute::setBackground(const QColor &background)
|
|
||||||
{
|
|
||||||
if (mBackground!=background) {
|
|
||||||
mBackground = background;
|
|
||||||
setChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
|
@ -28,15 +28,13 @@ enum class SynHighlighterClass {
|
||||||
CppHighlighter,
|
CppHighlighter,
|
||||||
};
|
};
|
||||||
|
|
||||||
class SynHighlighterAttribute : public QObject{
|
enum class SynHighlighterLanguage {
|
||||||
Q_OBJECT
|
Cpp
|
||||||
public:
|
};
|
||||||
explicit SynHighlighterAttribute(const QString& name, QObject* parent = nullptr);
|
|
||||||
QColor background() const;
|
|
||||||
void setBackground(const QColor &background);
|
|
||||||
|
|
||||||
QColor foreground() const;
|
class SynHighlighterAttribute {
|
||||||
void setForeground(const QColor &foreground);
|
public:
|
||||||
|
explicit SynHighlighterAttribute(const QString& name);
|
||||||
|
|
||||||
QString name() const;
|
QString name() const;
|
||||||
void setName(const QString &name);
|
void setName(const QString &name);
|
||||||
|
@ -44,13 +42,15 @@ public:
|
||||||
SynFontStyles styles() const;
|
SynFontStyles styles() const;
|
||||||
void setStyles(const SynFontStyles &styles);
|
void setStyles(const SynFontStyles &styles);
|
||||||
|
|
||||||
signals:
|
QColor foreground() const;
|
||||||
void changed();
|
void setForeground(const QColor &color);
|
||||||
|
|
||||||
|
QColor background() const;
|
||||||
|
void setBackground(const QColor &background);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setChanged();
|
|
||||||
private:
|
|
||||||
QColor mBackground;
|
|
||||||
QColor mForeground;
|
QColor mForeground;
|
||||||
|
QColor mBackground;
|
||||||
QString mName;
|
QString mName;
|
||||||
SynFontStyles mStyles;
|
SynFontStyles mStyles;
|
||||||
};
|
};
|
||||||
|
@ -58,11 +58,9 @@ private:
|
||||||
typedef std::shared_ptr<SynHighlighterAttribute> PSynHighlighterAttribute;
|
typedef std::shared_ptr<SynHighlighterAttribute> PSynHighlighterAttribute;
|
||||||
using SynHighlighterAttributeList = QVector<PSynHighlighterAttribute>;
|
using SynHighlighterAttributeList = QVector<PSynHighlighterAttribute>;
|
||||||
|
|
||||||
class SynHighlighter : public QObject
|
class SynHighlighter {
|
||||||
{
|
|
||||||
Q_OBJECT
|
|
||||||
public:
|
public:
|
||||||
explicit SynHighlighter(QObject *parent = nullptr);
|
explicit SynHighlighter();
|
||||||
|
|
||||||
const QMap<QString, PSynHighlighterAttribute>& attributes() const;
|
const QMap<QString, PSynHighlighterAttribute>& attributes() const;
|
||||||
|
|
||||||
|
@ -87,8 +85,6 @@ public:
|
||||||
virtual SynHighlighterClass getClass() const = 0;
|
virtual SynHighlighterClass getClass() const = 0;
|
||||||
virtual QString getName() const = 0;
|
virtual QString getName() const = 0;
|
||||||
|
|
||||||
void beginUpdate();
|
|
||||||
void endUpdate();
|
|
||||||
virtual bool getTokenFinished() const = 0;
|
virtual bool getTokenFinished() const = 0;
|
||||||
virtual bool isLastLineCommentNotFinished(int state) const = 0;
|
virtual bool isLastLineCommentNotFinished(int state) const = 0;
|
||||||
virtual bool isLastLineStringNotFinished(int state) const = 0;
|
virtual bool isLastLineStringNotFinished(int state) const = 0;
|
||||||
|
@ -110,18 +106,12 @@ public:
|
||||||
virtual void resetState() = 0;
|
virtual void resetState() = 0;
|
||||||
|
|
||||||
virtual QString languageName() = 0;
|
virtual QString languageName() = 0;
|
||||||
|
virtual SynHighlighterLanguage language() = 0;
|
||||||
|
|
||||||
static bool isSpaceChar(const QChar& ch);
|
static bool isSpaceChar(const QChar& ch);
|
||||||
bool enabled() const;
|
bool enabled() const;
|
||||||
void setEnabled(bool value);
|
void setEnabled(bool value);
|
||||||
|
|
||||||
signals:
|
|
||||||
void attributesChanged();
|
|
||||||
|
|
||||||
protected:
|
|
||||||
void onAttributeChanged();
|
|
||||||
void setAttributesChanged();
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
PSynHighlighterAttribute mCommentAttribute;
|
PSynHighlighterAttribute mCommentAttribute;
|
||||||
PSynHighlighterAttribute mIdentifierAttribute;
|
PSynHighlighterAttribute mIdentifierAttribute;
|
||||||
|
@ -138,7 +128,6 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QMap<QString,PSynHighlighterAttribute> mAttributes;
|
QMap<QString,PSynHighlighterAttribute> mAttributes;
|
||||||
int mUpdateCount;
|
|
||||||
bool mEnabled;
|
bool mEnabled;
|
||||||
QSet<QChar> mWordBreakChars;
|
QSet<QChar> mWordBreakChars;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
#include "composition.h"
|
#include "composition.h"
|
||||||
#include "../Constants.h"
|
#include "../Constants.h"
|
||||||
|
|
||||||
SynHighlightComposition::SynHighlightComposition(QObject *parent):
|
SynHighlightComposition::SynHighlightComposition()
|
||||||
SynHighlighter(parent)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,9 +21,7 @@ SynScheme::SynScheme(QObject *parent):
|
||||||
mCaseSensitive(true)
|
mCaseSensitive(true)
|
||||||
{
|
{
|
||||||
mMarkerAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrMarker);
|
mMarkerAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrMarker);
|
||||||
connect(mMarkerAttribute.get(),&SynHighlighterAttribute::changed,
|
mMarkerAttribute->setForeground(QColorConstants::Yellow);
|
||||||
this, &SynScheme::MarkerAttriChanged);
|
|
||||||
mMarkerAttribute->setBackground(QColorConstants::Yellow);
|
|
||||||
mMarkerAttribute->setStyles(SynFontStyle::fsBold);
|
mMarkerAttribute->setStyles(SynFontStyle::fsBold);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -49,9 +49,8 @@ private slots:
|
||||||
|
|
||||||
class SynHighlightComposition : public SynHighlighter
|
class SynHighlightComposition : public SynHighlighter
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
public:
|
public:
|
||||||
explicit SynHighlightComposition(QObject *parent = nullptr);
|
explicit SynHighlightComposition();
|
||||||
|
|
||||||
// SynHighligterBase interface
|
// SynHighligterBase interface
|
||||||
public:
|
public:
|
||||||
|
|
|
@ -110,14 +110,13 @@ const QSet<QString> SynEditCppHighlighter::Keywords {
|
||||||
|
|
||||||
"nullptr",
|
"nullptr",
|
||||||
};
|
};
|
||||||
SynEditCppHighlighter::SynEditCppHighlighter(QObject *parent): SynHighlighter(parent)
|
SynEditCppHighlighter::SynEditCppHighlighter(): SynHighlighter()
|
||||||
{
|
{
|
||||||
mAsmAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrAssembler);
|
mAsmAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrAssembler);
|
||||||
addAttribute(mAsmAttribute);
|
addAttribute(mAsmAttribute);
|
||||||
mCharAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrCharacter);
|
mCharAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrCharacter);
|
||||||
addAttribute(mCharAttribute);
|
addAttribute(mCharAttribute);
|
||||||
mCommentAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrComment);
|
mCommentAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrComment);
|
||||||
mCommentAttribute->setStyles(SynFontStyle::fsItalic);
|
|
||||||
addAttribute(mCommentAttribute);
|
addAttribute(mCommentAttribute);
|
||||||
mClassAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrClass);
|
mClassAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrClass);
|
||||||
addAttribute(mClassAttribute);
|
addAttribute(mClassAttribute);
|
||||||
|
@ -142,7 +141,6 @@ SynEditCppHighlighter::SynEditCppHighlighter(QObject *parent): SynHighlighter(pa
|
||||||
mDirecAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrPreprocessor);
|
mDirecAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrPreprocessor);
|
||||||
addAttribute(mDirecAttribute);
|
addAttribute(mDirecAttribute);
|
||||||
mKeyAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrReservedWord);
|
mKeyAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrReservedWord);
|
||||||
mCommentAttribute->setStyles(SynFontStyle::fsBold);
|
|
||||||
addAttribute(mKeyAttribute);
|
addAttribute(mKeyAttribute);
|
||||||
mWhitespaceAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrSpace);
|
mWhitespaceAttribute = std::make_shared<SynHighlighterAttribute>(SYNS_AttrSpace);
|
||||||
addAttribute(mWhitespaceAttribute);
|
addAttribute(mWhitespaceAttribute);
|
||||||
|
@ -621,7 +619,6 @@ void SynEditCppHighlighter::numberProc()
|
||||||
mRun+=1;
|
mRun+=1;
|
||||||
mTokenId = TokenKind::Number;
|
mTokenId = TokenKind::Number;
|
||||||
bool shouldExit = false;
|
bool shouldExit = false;
|
||||||
double x=010.140;
|
|
||||||
while (mLine[mRun]!=0) {
|
while (mLine[mRun]!=0) {
|
||||||
switch(mLine[mRun].unicode()) {
|
switch(mLine[mRun].unicode()) {
|
||||||
case '\'':
|
case '\'':
|
||||||
|
@ -772,8 +769,13 @@ void SynEditCppHighlighter::numberProc()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
shouldExit=true;
|
||||||
}
|
}
|
||||||
mRun+=1;
|
if (shouldExit) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
mRun+=1;
|
||||||
}
|
}
|
||||||
if (mLine[mRun-1] == '\'') {
|
if (mLine[mRun-1] == '\'') {
|
||||||
mTokenId = TokenKind::Unknown;
|
mTokenId = TokenKind::Unknown;
|
||||||
|
@ -1162,6 +1164,7 @@ void SynEditCppHighlighter::stringProc()
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
mRun+=1;
|
||||||
}
|
}
|
||||||
mRange.state = RangeState::rsUnknown;
|
mRange.state = RangeState::rsUnknown;
|
||||||
}
|
}
|
||||||
|
@ -1570,3 +1573,13 @@ QString SynEditCppHighlighter::getName() const
|
||||||
{
|
{
|
||||||
return "SynCppHighlighter";
|
return "SynCppHighlighter";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString SynEditCppHighlighter::languageName()
|
||||||
|
{
|
||||||
|
return "cpp";
|
||||||
|
}
|
||||||
|
|
||||||
|
SynHighlighterLanguage SynEditCppHighlighter::language()
|
||||||
|
{
|
||||||
|
return SynHighlighterLanguage::Cpp;
|
||||||
|
}
|
||||||
|
|
|
@ -5,8 +5,6 @@
|
||||||
|
|
||||||
class SynEditCppHighlighter: public SynHighlighter
|
class SynEditCppHighlighter: public SynHighlighter
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
|
||||||
|
|
||||||
enum TokenKind {
|
enum TokenKind {
|
||||||
Asm = 1,
|
Asm = 1,
|
||||||
Comment,
|
Comment,
|
||||||
|
@ -50,7 +48,7 @@ class SynEditCppHighlighter: public SynHighlighter
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit SynEditCppHighlighter(QObject* parent = nullptr);
|
explicit SynEditCppHighlighter();
|
||||||
|
|
||||||
PSynHighlighterAttribute asmAttribute() const;
|
PSynHighlighterAttribute asmAttribute() const;
|
||||||
|
|
||||||
|
@ -177,36 +175,18 @@ public:
|
||||||
int getTokenPos() override;
|
int getTokenPos() override;
|
||||||
void next() override;
|
void next() override;
|
||||||
void setLine(const QString &newLine, int lineNumber) override;
|
void setLine(const QString &newLine, int lineNumber) override;
|
||||||
|
|
||||||
// SynHighligterBase interface
|
|
||||||
public:
|
|
||||||
int getBraceLevel() const override;
|
int getBraceLevel() const override;
|
||||||
int getBracketLevel() const override;
|
int getBracketLevel() const override;
|
||||||
int getParenthesisLevel() const override;
|
int getParenthesisLevel() const override;
|
||||||
|
|
||||||
// SynHighligterBase interface
|
|
||||||
public:
|
|
||||||
bool isKeyword(const QString &word) override;
|
bool isKeyword(const QString &word) override;
|
||||||
|
|
||||||
// SynHighligterBase interface
|
|
||||||
public:
|
|
||||||
SynHighlighterTokenType getTokenType() override;
|
SynHighlighterTokenType getTokenType() override;
|
||||||
|
|
||||||
// SynHighligterBase interface
|
|
||||||
public:
|
|
||||||
void setState(SynRangeState rangeState, int braceLevel, int bracketLevel, int parenthesisLevel) override;
|
void setState(SynRangeState rangeState, int braceLevel, int bracketLevel, int parenthesisLevel) override;
|
||||||
|
|
||||||
// SynHighligterBase interface
|
|
||||||
public:
|
|
||||||
void resetState() override;
|
void resetState() override;
|
||||||
|
|
||||||
// SynHighligterBase interface
|
|
||||||
public:
|
|
||||||
SynHighlighterClass getClass() const override;
|
SynHighlighterClass getClass() const override;
|
||||||
|
|
||||||
// SynHighlighter interface
|
|
||||||
public:
|
|
||||||
QString getName() const override;
|
QString getName() const override;
|
||||||
|
|
||||||
|
QString languageName() override;
|
||||||
|
SynHighlighterLanguage language() override;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // SYNEDITCPPHIGHLIGHTER_H
|
#endif // SYNEDITCPPHIGHLIGHTER_H
|
||||||
|
|
Loading…
Reference in New Issue