From 2915a862ffa638f93ce109f1668cfb44e85caa3e Mon Sep 17 00:00:00 2001 From: "royqh1979@gmail.com" Date: Sun, 26 Sep 2021 22:39:26 +0800 Subject: [PATCH] fix: can't correctly create project in release mode --- RedPandaIDE/cpprefacter.cpp | 3 +-- RedPandaIDE/editor.cpp | 7 ++----- RedPandaIDE/project.cpp | 4 +++- RedPandaIDE/qsynedit/SynEdit.cpp | 31 ++++++++++++++++------------- RedPandaIDE/qsynedit/TextBuffer.cpp | 22 ++++++++------------ RedPandaIDE/qsynedit/TextBuffer.h | 2 +- RedPandaIDE/systemconsts.h | 2 +- RedPandaIDE/utils.cpp | 9 +++++++++ RedPandaIDE/utils.h | 1 + 9 files changed, 43 insertions(+), 38 deletions(-) diff --git a/RedPandaIDE/cpprefacter.cpp b/RedPandaIDE/cpprefacter.cpp index a1361177..abd259fc 100644 --- a/RedPandaIDE/cpprefacter.cpp +++ b/RedPandaIDE/cpprefacter.cpp @@ -63,8 +63,7 @@ PSearchResultTreeItem CppRefacter::findOccurenceInFile( editor.lines()->setContents(buffer); } else { QByteArray encoding; - QFile file(filename); - editor.lines()->LoadFromFile(file,ENCODING_AUTO_DETECT,encoding); + editor.lines()->LoadFromFile(filename,ENCODING_AUTO_DETECT,encoding); } editor.setHighlighter(HighlighterManager().getCppHighlighter()); int posY = 0; diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index af2ef766..20807ea2 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -152,11 +152,9 @@ Editor::~Editor() { void Editor::loadFile(const QString& filename) { if (filename.isEmpty()) { - QFile file(mFilename); - this->lines()->LoadFromFile(file,mEncodingOption,mFileEncoding); + this->lines()->LoadFromFile(mFilename,mEncodingOption,mFileEncoding); } else { - QFile file(filename); - this->lines()->LoadFromFile(file,mEncodingOption,mFileEncoding); + this->lines()->LoadFromFile(filename,mEncodingOption,mFileEncoding); } //this->setModified(false); updateCaption(); @@ -300,7 +298,6 @@ bool Editor::saveAs(const QString &name, bool fromProject){ mUseCppSyntax = pSettings->editor().defaultFileCpp(); } - //update (reassign highlighter) PSynHighlighter newHighlighter = HighlighterManager().getHighlighter(mFilename); if (newHighlighter) { diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index 81cf86f9..0cb6183b 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -15,6 +15,7 @@ #include #include #include +#include #include "settings.h" #include @@ -644,6 +645,7 @@ bool Project::assignTemplate(const std::shared_ptr aTemplate) s = templateUnit->CText; unit = newUnit(mNode,templateUnit->CName); } + Editor * editor = pMainWindow->editorList()->newEditor( QDir(directory()).absoluteFilePath(unit->fileName()), unit->encoding(), @@ -651,7 +653,7 @@ bool Project::assignTemplate(const std::shared_ptr aTemplate) true); QString s2 = QDir(pSettings->dirs().templateDir()).absoluteFilePath(s); - if (QFile(s2).exists()) { + if (fileExists(s2)) { editor->loadFile(s2); } else { s.replace("#13#10","\r\n"); diff --git a/RedPandaIDE/qsynedit/SynEdit.cpp b/RedPandaIDE/qsynedit/SynEdit.cpp index 6c5ee13c..542e8bc6 100644 --- a/RedPandaIDE/qsynedit/SynEdit.cpp +++ b/RedPandaIDE/qsynedit/SynEdit.cpp @@ -17,6 +17,7 @@ #include #include #include +#include SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent) { @@ -454,7 +455,7 @@ BufferCoord SynEdit::getMatchingBracketEx(BufferCoord APoint) // search for the matching bracket (that is until NumBrackets = 0) NumBrackets = 1; if (i%2==1) { - do { + while (true) { // search until start of line while (PosX > 1) { PosX--; @@ -486,9 +487,9 @@ BufferCoord SynEdit::getMatchingBracketEx(BufferCoord APoint) PosY--; Line = mLines->getString(PosY - 1); PosX = Line.length() + 1; - } while (true); + } } else { - do { + while (true) { // search until end of line Len = Line.length(); while (PosX < Len) { @@ -521,7 +522,7 @@ BufferCoord SynEdit::getMatchingBracketEx(BufferCoord APoint) PosY++; Line = mLines->getString(PosY - 1); PosX = 0; - } while (true); + } } // don't test the other brackets, we're done break; @@ -2810,6 +2811,8 @@ int SynEdit::scanFrom(int Index, int canStopIndex) Result ++ ; } while (Result < mLines->count()); Result--; + if (mUseCodeFolding) + rescan(); return Result; } @@ -2825,6 +2828,8 @@ void SynEdit::scanRanges() mHighlighter->getRightBraces()); } } + if (mUseCodeFolding) + rescan(); } void SynEdit::uncollapse(PSynEditFoldRange FoldRange) @@ -2914,6 +2919,7 @@ void SynEdit::rescanForFoldRanges() // Did we leave any collapsed folds and are we viewing a code file? if (mAllFoldRanges.count() > 0) { + // Add folds to a separate list PSynEditFoldRanges TemporaryAllFoldRanges = std::make_shared(); scanForFoldRanges(TemporaryAllFoldRanges); @@ -2932,6 +2938,7 @@ void SynEdit::rescanForFoldRanges() } } else { + // We ended up with no folds after deleting, just pass standard data... PSynEditFoldRanges temp(&mAllFoldRanges, null_deleter); scanForFoldRanges(temp); @@ -2941,10 +2948,10 @@ void SynEdit::rescanForFoldRanges() void SynEdit::scanForFoldRanges(PSynEditFoldRanges TopFoldRanges) { PSynEditFoldRanges parentFoldRanges = TopFoldRanges; - // Recursively scan for folds (all types) - for (int i= 0 ; i< mCodeFolding.foldRegions.count() ; i++ ) { - findSubFoldRange(TopFoldRanges, i,parentFoldRanges,PSynEditFoldRange()); - } + // Recursively scan for folds (all types) + for (int i= 0 ; i< mCodeFolding.foldRegions.count() ; i++ ) { + findSubFoldRange(TopFoldRanges, i,parentFoldRanges,PSynEditFoldRange()); + } } //this func should only be used in findSubFoldRange @@ -2982,11 +2989,11 @@ void SynEdit::findSubFoldRange(PSynEditFoldRanges TopFoldRanges, int FoldIndex,P PSynEditFoldRange CollapsedFold; int Line = 0; QString CurLine; + if (!mHighlighter) + return; bool useBraces = ( mCodeFolding.foldRegions.get(FoldIndex)->openSymbol == "{" && mCodeFolding.foldRegions.get(FoldIndex)->closeSymbol == "}"); - if (!mHighlighter) - return; while (Line < mLines->count()) { // index is valid for LinesToScan and fLines // If there is a collapsed fold over here, skip it CollapsedFold = collapsedFoldStartAtLine(Line + 1); // only collapsed folds remain @@ -4075,7 +4082,6 @@ void SynEdit::setUseCodeFolding(bool value) { if (mUseCodeFolding!=value) { mUseCodeFolding = value; - rescan(); } } @@ -5659,8 +5665,6 @@ void SynEdit::onLinesChanged() { SynSelectionMode vOldMode; mStateFlags.setFlag(SynStateFlag::sfLinesChanging, false); - if (mUseCodeFolding) - rescan(); updateScrollbars(); vOldMode = mActiveSelectionMode; @@ -5671,7 +5675,6 @@ void SynEdit::onLinesChanged() else invalidateRect(mInvalidateRect); mInvalidateRect = {0,0,0,0}; - if (mGutter.showLineNumbers() && (mGutter.autoSize())) mGutter.autoSizeDigitCount(mLines->count()); //if (!mOptions.testFlag(SynEditorOption::eoScrollPastEof)) diff --git a/RedPandaIDE/qsynedit/TextBuffer.cpp b/RedPandaIDE/qsynedit/TextBuffer.cpp index 0e20f76f..78e6f0a8 100644 --- a/RedPandaIDE/qsynedit/TextBuffer.cpp +++ b/RedPandaIDE/qsynedit/TextBuffer.cpp @@ -7,6 +7,7 @@ #include "SynEdit.h" #include "../utils.h" #include "../platform.h" +#include SynEditStringList::SynEditStringList(SynEdit *pEdit, QObject *parent): QObject(parent), @@ -477,15 +478,15 @@ void SynEditStringList::InsertText(int Index, const QString &NewText) InsertStrings(Index,lines); } -void SynEditStringList::LoadFromFile(QFile &file, const QByteArray& encoding, QByteArray& realEncoding) +void SynEditStringList::LoadFromFile(const QString& filename, const QByteArray& encoding, QByteArray& realEncoding) { - if (!file.open(QFile::ReadOnly)) + QFile file(filename); + if (!file.open(QFile::ReadOnly )) throw FileError(tr("Can't open file '%1' for read!").arg(file.fileName())); beginUpdate(); auto action = finally([this]{ endUpdate(); }); - //test for utf8 / utf 8 bom if (encoding == ENCODING_AUTO_DETECT) { if (file.atEnd()) { @@ -514,7 +515,7 @@ void SynEditStringList::LoadFromFile(QFile &file, const QByteArray& encoding, QB mFileEndingType = FileEndingType::Mac; } clear(); - do { + while (true) { if (allAscii) { allAscii = isTextAllAscii(line); } @@ -532,7 +533,8 @@ void SynEditStringList::LoadFromFile(QFile &file, const QByteArray& encoding, QB break; } line = file.readLine(); - } while (true); + } + emit inserted(0,mList.count()); if (!needReread) { if (allAscii) realEncoding = ENCODING_ASCII; @@ -545,15 +547,6 @@ void SynEditStringList::LoadFromFile(QFile &file, const QByteArray& encoding, QB if (realEncoding == ENCODING_SYSTEM_DEFAULT) { realEncoding = getDefaultSystemEncoding(); - QFile file("f:\\test.txt"); - if (file.open(QFile::WriteOnly|QFile::Truncate)) { - file.write("----test----\n"); - for (QByteArray a:QTextCodec::codecForLocale()->aliases()) { - file.write(a); - file.write("\n"); - } - file.close(); - } } file.reset(); QTextStream textStream(&file); @@ -569,6 +562,7 @@ void SynEditStringList::LoadFromFile(QFile &file, const QByteArray& encoding, QB while (textStream.readLineInto(&line)) { addItem(TrimRight(line)); } + emit inserted(0,mList.count()); } diff --git a/RedPandaIDE/qsynedit/TextBuffer.h b/RedPandaIDE/qsynedit/TextBuffer.h index 8304ada3..fe48d9a8 100644 --- a/RedPandaIDE/qsynedit/TextBuffer.h +++ b/RedPandaIDE/qsynedit/TextBuffer.h @@ -86,7 +86,7 @@ public: void InsertLines(int Index, int NumLines); void InsertStrings(int Index, const QStringList& NewStrings); void InsertText(int Index,const QString& NewText); - void LoadFromFile(QFile& file, const QByteArray& encoding, QByteArray& realEncoding); + void LoadFromFile(const QString& filename, const QByteArray& encoding, QByteArray& realEncoding); void SaveToFile(QFile& file, const QByteArray& encoding, QByteArray& realEncoding); bool getAppendNewLineAtEOF() const; diff --git a/RedPandaIDE/systemconsts.h b/RedPandaIDE/systemconsts.h index 3dddfe98..a4bd4382 100644 --- a/RedPandaIDE/systemconsts.h +++ b/RedPandaIDE/systemconsts.h @@ -50,7 +50,7 @@ #error "Only support windows and linux now!" #endif -#define DEVCPP_VERSION "0.1.0" +#define DEVCPP_VERSION "0.2.0" class SystemConsts { diff --git a/RedPandaIDE/utils.cpp b/RedPandaIDE/utils.cpp index a53e7e61..205817a0 100644 --- a/RedPandaIDE/utils.cpp +++ b/RedPandaIDE/utils.cpp @@ -66,6 +66,15 @@ const QByteArray GuessTextEncoding(const QByteArray& text){ return ENCODING_UTF8; } +bool isTextAllAscii(const QByteArray& text) { + for (char c:text) { + if (c<0 || c>127) { + return false; + } + } + return true; +} + bool isTextAllAscii(const QString& text) { for (QChar c:text) { if (c.unicode()>127) { diff --git a/RedPandaIDE/utils.h b/RedPandaIDE/utils.h index 7596d414..3ece7743 100644 --- a/RedPandaIDE/utils.h +++ b/RedPandaIDE/utils.h @@ -114,6 +114,7 @@ bool isGreenEdition(); const QByteArray GuessTextEncoding(const QByteArray& text); +bool isTextAllAscii(const QByteArray& text); bool isTextAllAscii(const QString& text); QByteArray runAndGetOutput(const QString& cmd, const QString& workingDir, const QStringList& arguments,