From 2182553fe126912a768d939e4773ef2b27d355ad Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Sun, 12 Jun 2022 18:26:39 +0800 Subject: [PATCH] - fix: rename macro doesn't work in project --- NEWS.md | 1 + RedPandaIDE/mainwindow.cpp | 12 ++--- RedPandaIDE/qsynedit/highlighter/cpp.cpp | 68 ++++++++++++++++-------- RedPandaIDE/qsynedit/highlighter/cpp.h | 4 +- 4 files changed, 56 insertions(+), 29 deletions(-) diff --git a/NEWS.md b/NEWS.md index e9fb831a..3d8cdbdf 100644 --- a/NEWS.md +++ b/NEWS.md @@ -7,6 +7,7 @@ Red Panda C++ Version 1.1.0 - enhancement: rename in files view's context menu - enhancement: delete in files view's context menu - change: drag&drop in files view default to move + - fix: rename macro doesn't work in project Red Panda C++ Version 1.0.10 - fix: modify watch doesn't work diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 3d1c8561..4d865a20 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -4175,7 +4175,6 @@ void MainWindow::onFileChanged(const QString &path) mFilesChangedNotifying.insert(path); Editor *e = mEditorList->getOpenedEditorByFilename(path); if (e) { - e->setModified(true); if (fileExists(path)) { e->activate(); if (QMessageBox::question(this,tr("File Changed"), @@ -4187,6 +4186,8 @@ void MainWindow::onFileChanged(const QString &path) } catch(FileError e) { QMessageBox::critical(this,tr("Error"),e.reason()); } + } else { + e->setModified(true); } } else { mFileSystemWatcher.removePath(path); @@ -4197,7 +4198,6 @@ void MainWindow::onFileChanged(const QString &path) mEditorList->closeEditor(e); } else { e->setModified(true); - e->updateCaption(); } } } @@ -6317,11 +6317,11 @@ void MainWindow::on_actionRename_Symbol_triggered() coord.Char--; expression = editor->getExpressionAtPosition(coord); } - // Find it's definition + // Find it's definition PStatement oldStatement = editor->parser()->findStatementOf( - editor->filename(), - expression, - oldCaretXY.Line); + editor->filename(), + expression, + oldCaretXY.Line); // definition of the symbol not found if (!oldStatement) return; diff --git a/RedPandaIDE/qsynedit/highlighter/cpp.cpp b/RedPandaIDE/qsynedit/highlighter/cpp.cpp index 24fdfc43..edc3db53 100644 --- a/RedPandaIDE/qsynedit/highlighter/cpp.cpp +++ b/RedPandaIDE/qsynedit/highlighter/cpp.cpp @@ -451,32 +451,50 @@ void SynEditCppHighlighter::directiveProc() mRun+=1; } if (directive == "define") { - do { - switch(mLine[mRun].unicode()) { - case '/': //comment? - switch (mLine[mRun+1].unicode()) { - case '/': // is end of directive as well - mRange.state = RangeState::rsUnknown; - return; - case '*': // might be embeded only - mRange.state = RangeState::rsDirectiveComment; - return; - } - break; - case '\\': // yet another line? - if (mLine[mRun+1] == 0) { - mRun+=1; - mRange.state = RangeState::rsMultiLineDirective; - return; - } - break; - } - mRun+=1; - } while (mLine[mRun]!=0); + while(mLine[mRun]!=0 && isSpaceChar(mLine[mRun])) + mRun++; + mRange.state = RangeState::rsDefineIdentifier; + return; } else mRange.state = RangeState::rsUnknown; } +void SynEditCppHighlighter::defineIdentProc() +{ + mTokenId = TokenKind::Identifier; + while(mLine[mRun]!=0 && isIdentChar(mLine[mRun])) + mRun++; + mRange.state = RangeState::rsDefineRemaining; +} + +void SynEditCppHighlighter::defineRemainingProc() +{ + mTokenId = TokenKind::Directive; + do { + switch(mLine[mRun].unicode()) { + case '/': //comment? + switch (mLine[mRun+1].unicode()) { + case '/': // is end of directive as well + mRange.state = RangeState::rsUnknown; + return; + case '*': // might be embeded only + mRange.state = RangeState::rsDirectiveComment; + return; + } + break; + case '\\': // yet another line? + if (mLine[mRun+1] == 0) { + mRun+=1; + mRange.state = RangeState::rsMultiLineDirective; + return; + } + break; + } + mRun+=1; + } while (mLine[mRun]!=0); + mRange.state=RangeState::rsUnknown; +} + void SynEditCppHighlighter::directiveEndProc() { mTokenId = TokenKind::Directive; @@ -1518,6 +1536,12 @@ void SynEditCppHighlighter::next() asciiCharProc(); } break; + case RangeState::rsDefineIdentifier: + defineIdentProc(); + break; + case RangeState::rsDefineRemaining: + defineRemainingProc(); + break; default: mRange.state = RangeState::rsUnknown; if (mLine[mRun] == 'R' && mLine[mRun+1] == '"') { diff --git a/RedPandaIDE/qsynedit/highlighter/cpp.h b/RedPandaIDE/qsynedit/highlighter/cpp.h index aecc3c67..30bb97f4 100644 --- a/RedPandaIDE/qsynedit/highlighter/cpp.h +++ b/RedPandaIDE/qsynedit/highlighter/cpp.h @@ -62,7 +62,7 @@ class SynEditCppHighlighter: public SynHighlighter rsMultiLineString, rsMultiLineDirective, rsCppComment, rsStringEscapeSeq, rsMultiLineStringEscapeSeq, rsRawString, rsSpace,rsRawStringEscaping,rsRawStringNotEscaping,rsChar, - rsCppCommentEnded + rsCppCommentEnded, rsDefineStart, rsDefineIdentifier, rsDefineRemaining }; public: @@ -111,6 +111,8 @@ private: void colonProc(); void commaProc(); void directiveProc(); + void defineIdentProc(); + void defineRemainingProc(); void directiveEndProc(); void equalProc(); void greaterProc();