fix: can't correctly create project in release mode

This commit is contained in:
royqh1979@gmail.com 2021-09-26 22:39:26 +08:00
parent 6ec3cfbfca
commit 2915a862ff
9 changed files with 43 additions and 38 deletions

View File

@ -63,8 +63,7 @@ PSearchResultTreeItem CppRefacter::findOccurenceInFile(
editor.lines()->setContents(buffer); editor.lines()->setContents(buffer);
} else { } else {
QByteArray encoding; QByteArray encoding;
QFile file(filename); editor.lines()->LoadFromFile(filename,ENCODING_AUTO_DETECT,encoding);
editor.lines()->LoadFromFile(file,ENCODING_AUTO_DETECT,encoding);
} }
editor.setHighlighter(HighlighterManager().getCppHighlighter()); editor.setHighlighter(HighlighterManager().getCppHighlighter());
int posY = 0; int posY = 0;

View File

@ -152,11 +152,9 @@ Editor::~Editor() {
void Editor::loadFile(const QString& filename) { void Editor::loadFile(const QString& filename) {
if (filename.isEmpty()) { if (filename.isEmpty()) {
QFile file(mFilename); this->lines()->LoadFromFile(mFilename,mEncodingOption,mFileEncoding);
this->lines()->LoadFromFile(file,mEncodingOption,mFileEncoding);
} else { } else {
QFile file(filename); this->lines()->LoadFromFile(filename,mEncodingOption,mFileEncoding);
this->lines()->LoadFromFile(file,mEncodingOption,mFileEncoding);
} }
//this->setModified(false); //this->setModified(false);
updateCaption(); updateCaption();
@ -300,7 +298,6 @@ bool Editor::saveAs(const QString &name, bool fromProject){
mUseCppSyntax = pSettings->editor().defaultFileCpp(); mUseCppSyntax = pSettings->editor().defaultFileCpp();
} }
//update (reassign highlighter) //update (reassign highlighter)
PSynHighlighter newHighlighter = HighlighterManager().getHighlighter(mFilename); PSynHighlighter newHighlighter = HighlighterManager().getHighlighter(mFilename);
if (newHighlighter) { if (newHighlighter) {

View File

@ -15,6 +15,7 @@
#include <QFileInfo> #include <QFileInfo>
#include <QMessageBox> #include <QMessageBox>
#include <QTextCodec> #include <QTextCodec>
#include <QMessageBox>
#include "settings.h" #include "settings.h"
#include <QDebug> #include <QDebug>
@ -644,6 +645,7 @@ bool Project::assignTemplate(const std::shared_ptr<ProjectTemplate> aTemplate)
s = templateUnit->CText; s = templateUnit->CText;
unit = newUnit(mNode,templateUnit->CName); unit = newUnit(mNode,templateUnit->CName);
} }
Editor * editor = pMainWindow->editorList()->newEditor( Editor * editor = pMainWindow->editorList()->newEditor(
QDir(directory()).absoluteFilePath(unit->fileName()), QDir(directory()).absoluteFilePath(unit->fileName()),
unit->encoding(), unit->encoding(),
@ -651,7 +653,7 @@ bool Project::assignTemplate(const std::shared_ptr<ProjectTemplate> aTemplate)
true); true);
QString s2 = QDir(pSettings->dirs().templateDir()).absoluteFilePath(s); QString s2 = QDir(pSettings->dirs().templateDir()).absoluteFilePath(s);
if (QFile(s2).exists()) { if (fileExists(s2)) {
editor->loadFile(s2); editor->loadFile(s2);
} else { } else {
s.replace("#13#10","\r\n"); s.replace("#13#10","\r\n");

View File

@ -17,6 +17,7 @@
#include <QPaintEvent> #include <QPaintEvent>
#include <QResizeEvent> #include <QResizeEvent>
#include <QStyleHints> #include <QStyleHints>
#include <QMessageBox>
SynEdit::SynEdit(QWidget *parent) : QAbstractScrollArea(parent) 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) // search for the matching bracket (that is until NumBrackets = 0)
NumBrackets = 1; NumBrackets = 1;
if (i%2==1) { if (i%2==1) {
do { while (true) {
// search until start of line // search until start of line
while (PosX > 1) { while (PosX > 1) {
PosX--; PosX--;
@ -486,9 +487,9 @@ BufferCoord SynEdit::getMatchingBracketEx(BufferCoord APoint)
PosY--; PosY--;
Line = mLines->getString(PosY - 1); Line = mLines->getString(PosY - 1);
PosX = Line.length() + 1; PosX = Line.length() + 1;
} while (true); }
} else { } else {
do { while (true) {
// search until end of line // search until end of line
Len = Line.length(); Len = Line.length();
while (PosX < Len) { while (PosX < Len) {
@ -521,7 +522,7 @@ BufferCoord SynEdit::getMatchingBracketEx(BufferCoord APoint)
PosY++; PosY++;
Line = mLines->getString(PosY - 1); Line = mLines->getString(PosY - 1);
PosX = 0; PosX = 0;
} while (true); }
} }
// don't test the other brackets, we're done // don't test the other brackets, we're done
break; break;
@ -2810,6 +2811,8 @@ int SynEdit::scanFrom(int Index, int canStopIndex)
Result ++ ; Result ++ ;
} while (Result < mLines->count()); } while (Result < mLines->count());
Result--; Result--;
if (mUseCodeFolding)
rescan();
return Result; return Result;
} }
@ -2825,6 +2828,8 @@ void SynEdit::scanRanges()
mHighlighter->getRightBraces()); mHighlighter->getRightBraces());
} }
} }
if (mUseCodeFolding)
rescan();
} }
void SynEdit::uncollapse(PSynEditFoldRange FoldRange) 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? // Did we leave any collapsed folds and are we viewing a code file?
if (mAllFoldRanges.count() > 0) { if (mAllFoldRanges.count() > 0) {
// Add folds to a separate list // Add folds to a separate list
PSynEditFoldRanges TemporaryAllFoldRanges = std::make_shared<SynEditFoldRanges>(); PSynEditFoldRanges TemporaryAllFoldRanges = std::make_shared<SynEditFoldRanges>();
scanForFoldRanges(TemporaryAllFoldRanges); scanForFoldRanges(TemporaryAllFoldRanges);
@ -2932,6 +2938,7 @@ void SynEdit::rescanForFoldRanges()
} }
} else { } else {
// We ended up with no folds after deleting, just pass standard data... // We ended up with no folds after deleting, just pass standard data...
PSynEditFoldRanges temp(&mAllFoldRanges, null_deleter); PSynEditFoldRanges temp(&mAllFoldRanges, null_deleter);
scanForFoldRanges(temp); scanForFoldRanges(temp);
@ -2941,10 +2948,10 @@ void SynEdit::rescanForFoldRanges()
void SynEdit::scanForFoldRanges(PSynEditFoldRanges TopFoldRanges) void SynEdit::scanForFoldRanges(PSynEditFoldRanges TopFoldRanges)
{ {
PSynEditFoldRanges parentFoldRanges = TopFoldRanges; PSynEditFoldRanges parentFoldRanges = TopFoldRanges;
// Recursively scan for folds (all types) // Recursively scan for folds (all types)
for (int i= 0 ; i< mCodeFolding.foldRegions.count() ; i++ ) { for (int i= 0 ; i< mCodeFolding.foldRegions.count() ; i++ ) {
findSubFoldRange(TopFoldRanges, i,parentFoldRanges,PSynEditFoldRange()); findSubFoldRange(TopFoldRanges, i,parentFoldRanges,PSynEditFoldRange());
} }
} }
//this func should only be used in findSubFoldRange //this func should only be used in findSubFoldRange
@ -2982,11 +2989,11 @@ void SynEdit::findSubFoldRange(PSynEditFoldRanges TopFoldRanges, int FoldIndex,P
PSynEditFoldRange CollapsedFold; PSynEditFoldRange CollapsedFold;
int Line = 0; int Line = 0;
QString CurLine; QString CurLine;
if (!mHighlighter)
return;
bool useBraces = ( mCodeFolding.foldRegions.get(FoldIndex)->openSymbol == "{" bool useBraces = ( mCodeFolding.foldRegions.get(FoldIndex)->openSymbol == "{"
&& mCodeFolding.foldRegions.get(FoldIndex)->closeSymbol == "}"); && mCodeFolding.foldRegions.get(FoldIndex)->closeSymbol == "}");
if (!mHighlighter)
return;
while (Line < mLines->count()) { // index is valid for LinesToScan and fLines while (Line < mLines->count()) { // index is valid for LinesToScan and fLines
// If there is a collapsed fold over here, skip it // If there is a collapsed fold over here, skip it
CollapsedFold = collapsedFoldStartAtLine(Line + 1); // only collapsed folds remain CollapsedFold = collapsedFoldStartAtLine(Line + 1); // only collapsed folds remain
@ -4075,7 +4082,6 @@ void SynEdit::setUseCodeFolding(bool value)
{ {
if (mUseCodeFolding!=value) { if (mUseCodeFolding!=value) {
mUseCodeFolding = value; mUseCodeFolding = value;
rescan();
} }
} }
@ -5659,8 +5665,6 @@ void SynEdit::onLinesChanged()
{ {
SynSelectionMode vOldMode; SynSelectionMode vOldMode;
mStateFlags.setFlag(SynStateFlag::sfLinesChanging, false); mStateFlags.setFlag(SynStateFlag::sfLinesChanging, false);
if (mUseCodeFolding)
rescan();
updateScrollbars(); updateScrollbars();
vOldMode = mActiveSelectionMode; vOldMode = mActiveSelectionMode;
@ -5671,7 +5675,6 @@ void SynEdit::onLinesChanged()
else else
invalidateRect(mInvalidateRect); invalidateRect(mInvalidateRect);
mInvalidateRect = {0,0,0,0}; mInvalidateRect = {0,0,0,0};
if (mGutter.showLineNumbers() && (mGutter.autoSize())) if (mGutter.showLineNumbers() && (mGutter.autoSize()))
mGutter.autoSizeDigitCount(mLines->count()); mGutter.autoSizeDigitCount(mLines->count());
//if (!mOptions.testFlag(SynEditorOption::eoScrollPastEof)) //if (!mOptions.testFlag(SynEditorOption::eoScrollPastEof))

View File

@ -7,6 +7,7 @@
#include "SynEdit.h" #include "SynEdit.h"
#include "../utils.h" #include "../utils.h"
#include "../platform.h" #include "../platform.h"
#include <QMessageBox>
SynEditStringList::SynEditStringList(SynEdit *pEdit, QObject *parent): SynEditStringList::SynEditStringList(SynEdit *pEdit, QObject *parent):
QObject(parent), QObject(parent),
@ -477,15 +478,15 @@ void SynEditStringList::InsertText(int Index, const QString &NewText)
InsertStrings(Index,lines); 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())); throw FileError(tr("Can't open file '%1' for read!").arg(file.fileName()));
beginUpdate(); beginUpdate();
auto action = finally([this]{ auto action = finally([this]{
endUpdate(); endUpdate();
}); });
//test for utf8 / utf 8 bom //test for utf8 / utf 8 bom
if (encoding == ENCODING_AUTO_DETECT) { if (encoding == ENCODING_AUTO_DETECT) {
if (file.atEnd()) { if (file.atEnd()) {
@ -514,7 +515,7 @@ void SynEditStringList::LoadFromFile(QFile &file, const QByteArray& encoding, QB
mFileEndingType = FileEndingType::Mac; mFileEndingType = FileEndingType::Mac;
} }
clear(); clear();
do { while (true) {
if (allAscii) { if (allAscii) {
allAscii = isTextAllAscii(line); allAscii = isTextAllAscii(line);
} }
@ -532,7 +533,8 @@ void SynEditStringList::LoadFromFile(QFile &file, const QByteArray& encoding, QB
break; break;
} }
line = file.readLine(); line = file.readLine();
} while (true); }
emit inserted(0,mList.count());
if (!needReread) { if (!needReread) {
if (allAscii) if (allAscii)
realEncoding = ENCODING_ASCII; realEncoding = ENCODING_ASCII;
@ -545,15 +547,6 @@ void SynEditStringList::LoadFromFile(QFile &file, const QByteArray& encoding, QB
if (realEncoding == ENCODING_SYSTEM_DEFAULT) { if (realEncoding == ENCODING_SYSTEM_DEFAULT) {
realEncoding = getDefaultSystemEncoding(); 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(); file.reset();
QTextStream textStream(&file); QTextStream textStream(&file);
@ -569,6 +562,7 @@ void SynEditStringList::LoadFromFile(QFile &file, const QByteArray& encoding, QB
while (textStream.readLineInto(&line)) { while (textStream.readLineInto(&line)) {
addItem(TrimRight(line)); addItem(TrimRight(line));
} }
emit inserted(0,mList.count());
} }

View File

@ -86,7 +86,7 @@ public:
void InsertLines(int Index, int NumLines); void InsertLines(int Index, int NumLines);
void InsertStrings(int Index, const QStringList& NewStrings); void InsertStrings(int Index, const QStringList& NewStrings);
void InsertText(int Index,const QString& NewText); 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); void SaveToFile(QFile& file, const QByteArray& encoding, QByteArray& realEncoding);
bool getAppendNewLineAtEOF() const; bool getAppendNewLineAtEOF() const;

View File

@ -50,7 +50,7 @@
#error "Only support windows and linux now!" #error "Only support windows and linux now!"
#endif #endif
#define DEVCPP_VERSION "0.1.0" #define DEVCPP_VERSION "0.2.0"
class SystemConsts class SystemConsts
{ {

View File

@ -66,6 +66,15 @@ const QByteArray GuessTextEncoding(const QByteArray& text){
return ENCODING_UTF8; 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) { bool isTextAllAscii(const QString& text) {
for (QChar c:text) { for (QChar c:text) {
if (c.unicode()>127) { if (c.unicode()>127) {

View File

@ -114,6 +114,7 @@ bool isGreenEdition();
const QByteArray GuessTextEncoding(const QByteArray& text); const QByteArray GuessTextEncoding(const QByteArray& text);
bool isTextAllAscii(const QByteArray& text);
bool isTextAllAscii(const QString& text); bool isTextAllAscii(const QString& text);
QByteArray runAndGetOutput(const QString& cmd, const QString& workingDir, const QStringList& arguments, QByteArray runAndGetOutput(const QString& cmd, const QString& workingDir, const QStringList& arguments,