- enhancement: Save project files' real encoding;
- enhancement: Use project files' real encoding information when generating the makefile.
This commit is contained in:
parent
4456772fa7
commit
c77a25f109
2
NEWS.md
2
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
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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(
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue