- enhancement: Save project files' real encoding;

- enhancement: Use project files' real encoding information when generating the makefile.
This commit is contained in:
Roy Qu 2023-01-19 20:04:05 +08:00
parent 4456772fa7
commit c77a25f109
6 changed files with 59 additions and 12 deletions

View File

@ -6,6 +6,8 @@ Red Panda C++ Version 2.10
- enhancement: Add "Help"/"Submit Iusses". - enhancement: Add "Help"/"Submit Iusses".
- enhancement: Add "Help"/"Document" for Simplified Chinese users. - enhancement: Add "Help"/"Document" for Simplified Chinese users.
- enhancement: Code Completion now respect compiler set's language standard settings. - 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 Red Panda C++ Version 2.9

View File

@ -418,20 +418,26 @@ void ProjectCompiler::writeMakeObjFilesRules(QFile &file)
targetEncoding = encoding; targetEncoding = encoding;
} }
if (unit->encoding() == ENCODING_AUTO_DETECT) { if (unit->realEncoding().isEmpty()) {
Editor* editor = mProject->unitEditor(unit); if (unit->encoding() == ENCODING_AUTO_DETECT) {
if (editor && editor->fileEncoding()!=ENCODING_ASCII Editor* editor = mProject->unitEditor(unit);
&& editor->fileEncoding()!=targetEncoding) { if (editor && editor->fileEncoding()!=ENCODING_ASCII
sourceEncoding = editor->fileEncoding(); && 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 { } else {
sourceEncoding = targetEncoding; sourceEncoding = targetEncoding;
} }
} else if (unit->encoding()==ENCODING_SYSTEM_DEFAULT) { } else if (unit->realEncoding()==ENCODING_ASCII) {
sourceEncoding = defaultSystemEncoding;
} else if (unit->encoding()!=ENCODING_ASCII && !unit->encoding().isEmpty()) {
sourceEncoding = unit->encoding();
} else {
sourceEncoding = targetEncoding; sourceEncoding = targetEncoding;
} else {
sourceEncoding = unit->realEncoding();
} }
if (sourceEncoding!=targetEncoding) { if (sourceEncoding!=targetEncoding) {

View File

@ -230,6 +230,14 @@ void Editor::loadFile(QString filename) {
//FileError should by catched by the caller of loadFile(); //FileError should by catched by the caller of loadFile();
this->document()->loadFromFile(filename,mEncodingOption,mFileEncoding); this->document()->loadFromFile(filename,mEncodingOption,mFileEncoding);
if (mProject) {
PProjectUnit unit = mProject->findUnit(this);
if (unit) {
unit->setEncoding(mEncodingOption);
unit->setRealEncoding(mFileEncoding);
}
}
//this->setModified(false); //this->setModified(false);
updateCaption(); updateCaption();
if (mParentPageControl) if (mParentPageControl)
@ -287,6 +295,12 @@ void Editor::saveFile(QString filename) {
this->document()->saveToFile(file,encoding, this->document()->saveToFile(file,encoding,
pSettings->editor().defaultEncoding(), pSettings->editor().defaultEncoding(),
mFileEncoding); mFileEncoding);
if (mProject) {
PProjectUnit unit = mProject->findUnit(this);
if (unit) {
unit->setRealEncoding(mFileEncoding);
}
}
if (isVisible() && mParentPageControl) if (isVisible() && mParentPageControl)
pMainWindow->updateForEncodingInfo(this); pMainWindow->updateForEncodingInfo(this);
emit fileSaved(filename, inProject()); emit fileSaved(filename, inProject());
@ -518,6 +532,7 @@ void Editor::setEncodingOption(const QByteArray& encoding) noexcept{
PProjectUnit unit = mProject->findUnit(this); PProjectUnit unit = mProject->findUnit(this);
if (unit) { if (unit) {
unit->setEncoding(mEncodingOption); unit->setEncoding(mEncodingOption);
unit->setRealEncoding(mFileEncoding);
} }
} }
} }

View File

@ -4994,7 +4994,7 @@ void MainWindow::closeProject(bool refreshEditor)
} }
} }
} else } 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; mClosingProject=true;
mBookmarkModel->saveProjectBookmarks( mBookmarkModel->saveProjectBookmarks(

View File

@ -246,6 +246,11 @@ void Project::open()
if (QTextCodec::codecForName(newUnit->encoding())==nullptr) { if (QTextCodec::codecForName(newUnit->encoding())==nullptr) {
newUnit->setEncoding(ENCODING_AUTO_DETECT); 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; PProjectModelNode parentNode;
if (mOptions.modelType==ProjectModelType::FileSystem) { if (mOptions.modelType==ProjectModelType::FileSystem) {
parentNode = getParentFileSystemFolderNode(newUnit->fileName()); parentNode = getParentFileSystemFolderNode(newUnit->fileName());
@ -764,9 +769,10 @@ bool Project::saveUnits()
ini.Delete(groupName,"DetectEncoding"); ini.Delete(groupName,"DetectEncoding");
if (unit->encoding() != options().encoding if (unit->encoding() != options().encoding
&& unit->encoding()!=ENCODING_AUTO_DETECT) && unit->encoding()!=ENCODING_AUTO_DETECT)
ini.SetValue(groupName,"FileEncoding", toByteArray(unit->encoding())); ini.SetValue(groupName,"FileEncoding", unit->encoding());
else else
ini.Delete(groupName,"FileEncoding"); ini.Delete(groupName,"FileEncoding");
ini.SetValue(groupName,"RealEncoding",unit->realEncoding());
} }
ini.SetLongValue("Project","UnitCount",count); ini.SetLongValue("Project","UnitCount",count);
ini.SaveFile(mFilename.toLocal8Bit()); ini.SaveFile(mFilename.toLocal8Bit());
@ -800,6 +806,7 @@ void Project::associateEditorToUnit(Editor *editor, PProjectUnit unit)
} }
if (editor) { if (editor) {
unit->setEncoding(editor->encodingOption()); unit->setEncoding(editor->encodingOption());
unit->setRealEncoding(editor->fileEncoding());
editor->setProject(this); editor->setProject(this);
} }
} }
@ -1219,6 +1226,7 @@ PProjectUnit Project::internalAddUnit(const QString &inFileName, PProjectModelNo
Editor * e= unitEditor(newUnit); Editor * e= unitEditor(newUnit);
if (e) { if (e) {
newUnit->setEncoding(e->encodingOption()); newUnit->setEncoding(e->encodingOption());
newUnit->setRealEncoding(e->fileEncoding());
e->setProject(this); e->setProject(this);
} else { } else {
newUnit->setEncoding(options().encoding.toUtf8()); newUnit->setEncoding(options().encoding.toUtf8());
@ -2290,6 +2298,8 @@ ProjectUnit::ProjectUnit(Project* parent)
mFileMissing = false; mFileMissing = false;
mPriority=0; mPriority=0;
mNew = true; mNew = true;
mEncoding=ENCODING_AUTO_DETECT;
mRealEncoding="";
} }
Project *ProjectUnit::parent() const Project *ProjectUnit::parent() const
@ -2318,6 +2328,16 @@ void ProjectUnit::setNew(bool newNew)
mNew = newNew; mNew = newNew;
} }
const QByteArray &ProjectUnit::realEncoding() const
{
return mRealEncoding;
}
void ProjectUnit::setRealEncoding(const QByteArray &newRealEncoding)
{
mRealEncoding = newRealEncoding;
}
const QString &ProjectUnit::folder() const const QString &ProjectUnit::folder() const
{ {
return mFolder; return mFolder;

View File

@ -104,6 +104,9 @@ public:
void setNew(bool newNew); void setNew(bool newNew);
const QByteArray &realEncoding() const;
void setRealEncoding(const QByteArray &newRealEncoding);
private: private:
Project* mParent; Project* mParent;
QString mFileName; QString mFileName;
@ -116,6 +119,7 @@ private:
bool mLink; bool mLink;
int mPriority; int mPriority;
QByteArray mEncoding; QByteArray mEncoding;
QByteArray mRealEncoding;
PProjectModelNode mNode; PProjectModelNode mNode;
bool mFileMissing; bool mFileMissing;
}; };