improve makefile highlighter

fix: qsortfilterproxymodel not correctly cleared when exiting and project closed.
This commit is contained in:
Roy Qu 2022-12-07 09:48:10 +08:00
parent 8af963579a
commit b4e561cf83
8 changed files with 87 additions and 30 deletions

View File

@ -54,7 +54,7 @@ QSynedit::PHighlighter HighlighterManager::getHighlighter(const QString &filenam
QFileInfo info(filename); QFileInfo info(filename);
QString suffix = info.suffix(); QString suffix = info.suffix();
QString basename = info.baseName(); QString basename = info.baseName();
if (suffix.isEmpty() || suffix == "c" || suffix == "cpp" || suffix == "cxx" if (suffix == "c" || suffix == "cpp" || suffix == "cxx"
|| suffix == "cc" || suffix == "h" || suffix == "hpp" || suffix == "cc" || suffix == "h" || suffix == "hpp"
|| suffix == "hxx" || suffix == "hh" || suffix == "C" || suffix == "hxx" || suffix == "hh" || suffix == "C"
|| suffix == "CPP" || suffix =="H" || suffix == "c++" || suffix == "CPP" || suffix =="H" || suffix == "c++"
@ -64,8 +64,11 @@ QSynedit::PHighlighter HighlighterManager::getHighlighter(const QString &filenam
return getGLSLHighlighter(); return getGLSLHighlighter();
} else if (suffix == "s" || suffix == "asm") { } else if (suffix == "s" || suffix == "asm") {
return getAsmHighlighter(); return getAsmHighlighter();
} else if (basename.compare("makefile", Qt::CaseInsensitive)==0) } else if (basename.compare("makefile", Qt::CaseInsensitive)==0) {
return getMakefileHighlighter(); return getMakefileHighlighter();
} else if (suffix.isEmpty()) {
return getCppHighlighter();
}
return QSynedit::PHighlighter(); return QSynedit::PHighlighter();
} }

View File

@ -323,6 +323,8 @@ bool Editor::saveAs(const QString &name, bool fromProject){
pos++; pos++;
} }
dialog.setDefaultSuffix(suffix); dialog.setDefaultSuffix(suffix);
} else {
dialog.setDefaultSuffix("");
} }
}); });

View File

@ -4309,6 +4309,7 @@ void MainWindow::onClassBrowserRefreshEnd()
void MainWindow::onProjectSwitchCustomViewMode() void MainWindow::onProjectSwitchCustomViewMode()
{ {
mProject->setModelType(ProjectModelType::Custom); mProject->setModelType(ProjectModelType::Custom);
qDebug()<<"3";
ui->projectView->expand( ui->projectView->expand(
mProjectProxyModel->mapFromSource( mProjectProxyModel->mapFromSource(
mProject->model()->rootIndex())); mProject->model()->rootIndex()));
@ -4752,8 +4753,8 @@ void MainWindow::closeProject(bool refreshEditor)
mTodoModel.setIsForProject(false); mTodoModel.setIsForProject(false);
// Clear error browser // Clear error browser
clearIssues(); clearIssues();
updateProjectView();
} }
updateProjectView();
mClosingProject=false; mClosingProject=false;
} }
} }

View File

@ -3819,7 +3819,7 @@ void CppParser::internalParse(const QString &fileName)
QStringList preprocessResult = mPreprocessor.result(); QStringList preprocessResult = mPreprocessor.result();
#ifdef QT_DEBUG #ifdef QT_DEBUG
stringsToFile(mPreprocessor.result(),QString("r:\\preprocess-%1.txt").arg(extractFileName(fileName))); // stringsToFile(mPreprocessor.result(),QString("r:\\preprocess-%1.txt").arg(extractFileName(fileName)));
// mPreprocessor.dumpDefinesTo("r:\\defines.txt"); // mPreprocessor.dumpDefinesTo("r:\\defines.txt");
// mPreprocessor.dumpIncludesListTo("r:\\includes.txt"); // mPreprocessor.dumpIncludesListTo("r:\\includes.txt");
#endif #endif
@ -3833,7 +3833,7 @@ void CppParser::internalParse(const QString &fileName)
if (mTokenizer.tokenCount() == 0) if (mTokenizer.tokenCount() == 0)
return; return;
#ifdef QT_DEBUG #ifdef QT_DEBUG
mTokenizer.dumpTokens(QString("r:\\tokens-%1.txt").arg(extractFileName(fileName))); // mTokenizer.dumpTokens(QString("r:\\tokens-%1.txt").arg(extractFileName(fileName)));
#endif #endif
#ifdef QT_DEBUG #ifdef QT_DEBUG
lastIndex = -1; lastIndex = -1;
@ -3844,8 +3844,8 @@ void CppParser::internalParse(const QString &fileName)
break; break;
} }
#ifdef QT_DEBUG #ifdef QT_DEBUG
mStatementList.dumpAll(QString("r:\\all-stats-%1.txt").arg(extractFileName(fileName))); // mStatementList.dumpAll(QString("r:\\all-stats-%1.txt").arg(extractFileName(fileName)));
mStatementList.dump(QString("r:\\stats-%1.txt").arg(extractFileName(fileName))); // mStatementList.dump(QString("r:\\stats-%1.txt").arg(extractFileName(fileName)));
#endif #endif
//reduce memory usage //reduce memory usage
internalClear(); internalClear();

View File

@ -828,7 +828,7 @@ p, li { white-space: pre-wrap; }
<message> <message>
<location filename="../settingsdialog/compilersetoptionwidget.ui" line="157"/> <location filename="../settingsdialog/compilersetoptionwidget.ui" line="157"/>
<source>Statically link libraries</source> <source>Statically link libraries</source>
<translation></translation> <translation></translation>
</message> </message>
<message> <message>
<location filename="../settingsdialog/compilersetoptionwidget.ui" line="185"/> <location filename="../settingsdialog/compilersetoptionwidget.ui" line="185"/>

View File

@ -5533,7 +5533,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 && mOptions.testFlag(eoAutoIndent)) { if (!mUndoing && mHighlighter && mHighlighter->language()==HighlighterLanguage::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);
@ -5563,7 +5563,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 && mOptions.testFlag(eoAutoIndent) && notInComment) { if (!mUndoing && mHighlighter && mHighlighter->language()==HighlighterLanguage::Cpp && mOptions.testFlag(eoAutoIndent) && notInComment) {
str = GetLeftSpacing(calcIndentSpaces(caretY,"",true),true); str = GetLeftSpacing(calcIndentSpaces(caretY,"",true),true);
} else { } else {
str = ""; str = "";
@ -5573,7 +5573,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 && mOptions.testFlag(eoAutoIndent) && notInComment) { if (!mUndoing && mHighlighter && mHighlighter->language()==HighlighterLanguage::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);
} }

View File

@ -218,10 +218,13 @@ void MakefileHighlighter::procNull()
void MakefileHighlighter::procString(bool inExpression ) void MakefileHighlighter::procString(bool inExpression )
{ {
mState = RangeState::String;
mTokenID = TokenId::String; mTokenID = TokenId::String;
while (mLine[mRun] != 0) { while (mLine[mRun] != 0) {
if (mLine[mRun] == '\"') { if (mState==RangeState::DQString && mLine[mRun] == '\"') {
mRun++;
popState();
break;
} else if (mState==RangeState::SQString && mLine[mRun] == '\'') {
mRun++; mRun++;
popState(); popState();
break; break;
@ -235,12 +238,19 @@ void MakefileHighlighter::procString(bool inExpression )
} }
void MakefileHighlighter::procStringStart() void MakefileHighlighter::procStringStart(StringStartType type,bool inExpression )
{ {
mRun++; mRun++;
pushState(); pushState();
procString(mState!=RangeState::BraceExpression switch(type) {
&& mState!=RangeState::ParenthesisExpression); case StringStartType::SingleQuoted:
mState = RangeState::SQString;
break;
case StringStartType::DoubleQuoted:
mState = RangeState::DQString;
break;
}
procString(inExpression);
} }
void MakefileHighlighter::procExpressionStart(ExpressionStartType type) void MakefileHighlighter::procExpressionStart(ExpressionStartType type)
@ -355,7 +365,8 @@ void MakefileHighlighter::procIdentifier()
case RangeState::Unknown: case RangeState::Unknown:
mTokenID = TokenId::Target; mTokenID = TokenId::Target;
break; break;
case RangeState::String: case RangeState::DQString:
case RangeState::SQString:
mTokenID = TokenId::String; mTokenID = TokenId::String;
break; break;
} }
@ -378,9 +389,6 @@ void MakefileHighlighter::popState()
bool MakefileHighlighter::isIdentChar(const QChar &ch) const bool MakefileHighlighter::isIdentChar(const QChar &ch) const
{ {
if (ch == '_' || ch =='-') {
return true;
}
if ((ch>='0') && (ch <= '9')) { if ((ch>='0') && (ch <= '9')) {
return true; return true;
} }
@ -390,6 +398,16 @@ bool MakefileHighlighter::isIdentChar(const QChar &ch) const
if ((ch>='A') && (ch <= 'Z')) { if ((ch>='A') && (ch <= 'Z')) {
return true; return true;
} }
switch(ch.unicode()) {
case '_':
case '%':
case '.':
case '*':
case '-':
case '+':
case '/':
return true;
}
return false; return false;
} }
@ -469,7 +487,8 @@ void MakefileHighlighter::next()
return; return;
} }
switch(mState) { switch(mState) {
case RangeState::String: case RangeState::DQString:
case RangeState::SQString:
if (mLine[mRun] == '$') if (mLine[mRun] == '$')
procDollar(); procDollar();
else else
@ -484,7 +503,10 @@ void MakefileHighlighter::next()
procDollar(); procDollar();
break; break;
case '\"': case '\"':
procStringStart(); procStringStart(StringStartType::DoubleQuoted,false);
break;
case '\'':
procStringStart(StringStartType::SingleQuoted,false);
break; break;
case '#': case '#':
procComment(); procComment();
@ -511,6 +533,12 @@ void MakefileHighlighter::next()
else else
procSymbol(); procSymbol();
break; break;
case '\"':
procStringStart(StringStartType::DoubleQuoted,true);
break;
case '\'':
procStringStart(StringStartType::SingleQuoted,true);
break;
case '}': case '}':
if (mState == RangeState::BraceExpression) if (mState == RangeState::BraceExpression)
procExpressionEnd(); procExpressionEnd();
@ -523,7 +551,6 @@ void MakefileHighlighter::next()
case '@': case '@':
case '+': case '+':
case '*': case '*':
case '%':
case '^': case '^':
case '<': case '<':
case '?': case '?':
@ -534,6 +561,14 @@ void MakefileHighlighter::next()
} else } else
procSymbol(); procSymbol();
break; break;
case '%':
if (mLine[mRun]=='D' || mLine[mRun]=='F') {
//auto variable
mRun+=2;
mTokenID = TokenId::Variable;
} else
procIdentifier();
break;
default: default:
if (mLine[mRun]>='0' && mLine[mRun]<='9') { if (mLine[mRun]>='0' && mLine[mRun]<='9') {
procNumber(); procNumber();
@ -553,7 +588,10 @@ void MakefileHighlighter::next()
procComment(); procComment();
break; break;
case '\"': case '\"':
procStringStart(); procStringStart(StringStartType::DoubleQuoted,false);
break;
case '\'':
procStringStart(StringStartType::SingleQuoted,false);
break; break;
case '?': case '?':
case '+': case '+':

View File

@ -42,7 +42,9 @@ class MakefileHighlighter : public Highlighter
}; };
enum RangeState { enum RangeState {
Unknown, String, Unknown,
DQString, // Double Quoted "blahblah"
SQString, // Single Quoted 'blahblah'
/* Targets, */ /* Targets, */
Prequisitions, Prequisitions,
Command, Command,
@ -52,11 +54,16 @@ class MakefileHighlighter : public Highlighter
Assignment, Assignment,
}; };
enum ExpressionStartType { enum class ExpressionStartType {
Parenthesis, Parenthesis,
Brace Brace
}; };
enum class StringStartType {
SingleQuoted,
DoubleQuoted
};
public: public:
explicit MakefileHighlighter(); explicit MakefileHighlighter();
@ -85,7 +92,7 @@ private:
void procNumber(); void procNumber();
void procNull(); void procNull();
void procString(bool inExpression ); void procString(bool inExpression );
void procStringStart(); void procStringStart(StringStartType type, bool inExpression);
void procExpressionStart(ExpressionStartType type); void procExpressionStart(ExpressionStartType type);
void procExpressionEnd(); void procExpressionEnd();
void procSymbol(); void procSymbol();
@ -99,15 +106,21 @@ private:
void pushState(); void pushState();
void popState(); void popState();
bool isIdentStartChar(const QChar& ch) { bool isIdentStartChar(const QChar& ch) {
if (ch == '_') {
return true;
}
if ((ch>='a') && (ch <= 'z')) { if ((ch>='a') && (ch <= 'z')) {
return true; return true;
} }
if ((ch>='A') && (ch <= 'Z')) { if ((ch>='A') && (ch <= 'Z')) {
return true; return true;
} }
switch(ch.unicode()) {
case '_':
case '%':
case '.':
case '*':
case '/':
return true;
}
return false; return false;
} }