diff --git a/NEWS.md b/NEWS.md index 94c20fb5..4c3df5d7 100644 --- a/NEWS.md +++ b/NEWS.md @@ -6,6 +6,8 @@ Red Panda C++ Version 2.10 - enhancement: Add "Help"/"Submit Iusses". - enhancement: Add "Help"/"Document" for Simplified Chinese users. - enhancement: Code Completion now respect compiler set's language standard settings. + - enhancement: Save project files' real encoding; + - enhancement: Use project files' real encoding information when generating the makefile. Red Panda C++ Version 2.9 diff --git a/RedPandaIDE/compiler/projectcompiler.cpp b/RedPandaIDE/compiler/projectcompiler.cpp index 89efba86..7b20817d 100644 --- a/RedPandaIDE/compiler/projectcompiler.cpp +++ b/RedPandaIDE/compiler/projectcompiler.cpp @@ -418,20 +418,26 @@ void ProjectCompiler::writeMakeObjFilesRules(QFile &file) targetEncoding = encoding; } - if (unit->encoding() == ENCODING_AUTO_DETECT) { - Editor* editor = mProject->unitEditor(unit); - if (editor && editor->fileEncoding()!=ENCODING_ASCII - && editor->fileEncoding()!=targetEncoding) { - sourceEncoding = editor->fileEncoding(); + if (unit->realEncoding().isEmpty()) { + if (unit->encoding() == ENCODING_AUTO_DETECT) { + Editor* editor = mProject->unitEditor(unit); + if (editor && editor->fileEncoding()!=ENCODING_ASCII + && editor->fileEncoding()!=targetEncoding) { + sourceEncoding = editor->fileEncoding(); + } else { + sourceEncoding = targetEncoding; + } + } else if (unit->encoding()==ENCODING_SYSTEM_DEFAULT) { + sourceEncoding = defaultSystemEncoding; + } else if (unit->encoding()!=ENCODING_ASCII && !unit->encoding().isEmpty()) { + sourceEncoding = unit->encoding(); } else { sourceEncoding = targetEncoding; } - } else if (unit->encoding()==ENCODING_SYSTEM_DEFAULT) { - sourceEncoding = defaultSystemEncoding; - } else if (unit->encoding()!=ENCODING_ASCII && !unit->encoding().isEmpty()) { - sourceEncoding = unit->encoding(); - } else { + } else if (unit->realEncoding()==ENCODING_ASCII) { sourceEncoding = targetEncoding; + } else { + sourceEncoding = unit->realEncoding(); } if (sourceEncoding!=targetEncoding) { diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 8dfed3a6..1e4b0181 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -230,6 +230,14 @@ void Editor::loadFile(QString filename) { //FileError should by catched by the caller of loadFile(); this->document()->loadFromFile(filename,mEncodingOption,mFileEncoding); + + if (mProject) { + PProjectUnit unit = mProject->findUnit(this); + if (unit) { + unit->setEncoding(mEncodingOption); + unit->setRealEncoding(mFileEncoding); + } + } //this->setModified(false); updateCaption(); if (mParentPageControl) @@ -287,6 +295,12 @@ void Editor::saveFile(QString filename) { this->document()->saveToFile(file,encoding, pSettings->editor().defaultEncoding(), mFileEncoding); + if (mProject) { + PProjectUnit unit = mProject->findUnit(this); + if (unit) { + unit->setRealEncoding(mFileEncoding); + } + } if (isVisible() && mParentPageControl) pMainWindow->updateForEncodingInfo(this); emit fileSaved(filename, inProject()); @@ -518,6 +532,7 @@ void Editor::setEncodingOption(const QByteArray& encoding) noexcept{ PProjectUnit unit = mProject->findUnit(this); if (unit) { unit->setEncoding(mEncodingOption); + unit->setRealEncoding(mFileEncoding); } } } diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 962668c1..80831e6c 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -4994,7 +4994,7 @@ void MainWindow::closeProject(bool refreshEditor) } } } else - mProject->saveLayout(); // always save layout, but not when SaveAll has been called + mProject->saveAll(); // always save layout, but not when SaveAll has been called mClosingProject=true; mBookmarkModel->saveProjectBookmarks( diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index 3cb33524..c6ad2201 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -246,6 +246,11 @@ void Project::open() if (QTextCodec::codecForName(newUnit->encoding())==nullptr) { newUnit->setEncoding(ENCODING_AUTO_DETECT); } + if (QTextCodec::codecForName(newUnit->encoding())==nullptr) { + newUnit->setEncoding(ENCODING_AUTO_DETECT); + } + newUnit->setRealEncoding(ini.GetValue(groupName, "RealEncoding",ENCODING_ASCII)); + PProjectModelNode parentNode; if (mOptions.modelType==ProjectModelType::FileSystem) { parentNode = getParentFileSystemFolderNode(newUnit->fileName()); @@ -764,9 +769,10 @@ bool Project::saveUnits() ini.Delete(groupName,"DetectEncoding"); if (unit->encoding() != options().encoding && unit->encoding()!=ENCODING_AUTO_DETECT) - ini.SetValue(groupName,"FileEncoding", toByteArray(unit->encoding())); + ini.SetValue(groupName,"FileEncoding", unit->encoding()); else ini.Delete(groupName,"FileEncoding"); + ini.SetValue(groupName,"RealEncoding",unit->realEncoding()); } ini.SetLongValue("Project","UnitCount",count); ini.SaveFile(mFilename.toLocal8Bit()); @@ -800,6 +806,7 @@ void Project::associateEditorToUnit(Editor *editor, PProjectUnit unit) } if (editor) { unit->setEncoding(editor->encodingOption()); + unit->setRealEncoding(editor->fileEncoding()); editor->setProject(this); } } @@ -1219,6 +1226,7 @@ PProjectUnit Project::internalAddUnit(const QString &inFileName, PProjectModelNo Editor * e= unitEditor(newUnit); if (e) { newUnit->setEncoding(e->encodingOption()); + newUnit->setRealEncoding(e->fileEncoding()); e->setProject(this); } else { newUnit->setEncoding(options().encoding.toUtf8()); @@ -2290,6 +2298,8 @@ ProjectUnit::ProjectUnit(Project* parent) mFileMissing = false; mPriority=0; mNew = true; + mEncoding=ENCODING_AUTO_DETECT; + mRealEncoding=""; } Project *ProjectUnit::parent() const @@ -2318,6 +2328,16 @@ void ProjectUnit::setNew(bool newNew) mNew = newNew; } +const QByteArray &ProjectUnit::realEncoding() const +{ + return mRealEncoding; +} + +void ProjectUnit::setRealEncoding(const QByteArray &newRealEncoding) +{ + mRealEncoding = newRealEncoding; +} + const QString &ProjectUnit::folder() const { return mFolder; diff --git a/RedPandaIDE/project.h b/RedPandaIDE/project.h index 44800c6d..ad4101fd 100644 --- a/RedPandaIDE/project.h +++ b/RedPandaIDE/project.h @@ -104,6 +104,9 @@ public: void setNew(bool newNew); + const QByteArray &realEncoding() const; + void setRealEncoding(const QByteArray &newRealEncoding); + private: Project* mParent; QString mFileName; @@ -116,6 +119,7 @@ private: bool mLink; int mPriority; QByteArray mEncoding; + QByteArray mRealEncoding; PProjectModelNode mNode; bool mFileMissing; };