diff --git a/NEWS.md b/NEWS.md index 19edd157..f028617d 100644 --- a/NEWS.md +++ b/NEWS.md @@ -14,6 +14,8 @@ Red Panda C++ Version 2.10 - enhancement: Use lldb-mi as the debugger. - enhancement: Set lldb-mi as the debugger program for clang, when finding compiler set in folders and gdb doesn't exist. - fix: Settings in Options/Tools/General is messed up when switching items in the list. + - fix: Infos in the status bar not correctly updated when editor closed. + - change: Project's encoding shouldn't be set to "auto detect" Red Panda C++ Version 2.9 diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 1e4b0181..71e2903b 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -94,6 +94,7 @@ Editor::Editor(QWidget *parent, const QString& filename, } QFileInfo fileInfo(mFilename); QSynedit::PSyntaxer syntaxer; + mFileEncoding = ENCODING_ASCII; if (!isNew) { try { loadFile(); @@ -104,10 +105,14 @@ Editor::Editor(QWidget *parent, const QString& filename, } syntaxer = syntaxerManager.getSyntaxer(mFilename); } else { - mFileEncoding = ENCODING_ASCII; syntaxer=syntaxerManager.getSyntaxer(QSynedit::ProgrammingLanguage::CPP); } - + if (mEncodingOption==ENCODING_AUTO_DETECT) { + if (mFileEncoding==ENCODING_ASCII) + mEncodingOption=pSettings->editor().defaultEncoding(); + else + mEncodingOption=mFileEncoding; + } if (syntaxer) { setSyntaxer(syntaxer); setUseCodeFolding(true); @@ -234,7 +239,15 @@ void Editor::loadFile(QString filename) { if (mProject) { PProjectUnit unit = mProject->findUnit(this); if (unit) { - unit->setEncoding(mEncodingOption); + if (mEncodingOption==ENCODING_AUTO_DETECT) { + if (mFileEncoding==ENCODING_ASCII) + unit->setEncoding(mProject->options().encoding); + else + unit->setEncoding(mFileEncoding); + mEncodingOption=unit->encoding(); + } else { + unit->setEncoding(mEncodingOption); + } unit->setRealEncoding(mFileEncoding); } } @@ -648,6 +661,14 @@ void Editor::wheelEvent(QWheelEvent *event) { void Editor::focusInEvent(QFocusEvent *event) { QSynEdit::focusInEvent(event); + if (mParentPageControl) { + pMainWindow->updateClassBrowserForEditor(this); + pMainWindow->updateAppTitle(this); + pMainWindow->updateEditorActions(this); + pMainWindow->updateForEncodingInfo(this); + pMainWindow->updateStatusbarForLineCol(this); + pMainWindow->updateForStatusbarModeInfo(this); + } } void Editor::focusOutEvent(QFocusEvent *event) @@ -1474,10 +1495,6 @@ void Editor::showEvent(QShowEvent */*event*/) pMainWindow->debugger()->setIsForProject(inProject()); pMainWindow->bookmarkModel()->setIsForProject(inProject()); pMainWindow->todoModel()->setIsForProject(inProject()); - - pMainWindow->updateForEncodingInfo(true); - pMainWindow->updateStatusbarForLineCol(true); - pMainWindow->updateForStatusbarModeInfo(true); } if (!pMainWindow->isClosingAll() diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index e1ce840c..87ce162d 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -469,13 +469,15 @@ void MainWindow::updateForEncodingInfo(const Editor* editor, bool clear) { .arg(QString(editor->encodingOption())) ); } - ui->actionAuto_Detect->setChecked(editor->encodingOption() == ENCODING_AUTO_DETECT); + //ui->actionAuto_Detect->setEnabled(editor->inProject()); + //ui->actionAuto_Detect->setChecked(editor->encodingOption() == ENCODING_AUTO_DETECT); ui->actionEncode_in_ANSI->setChecked(editor->encodingOption() == ENCODING_SYSTEM_DEFAULT); ui->actionEncode_in_UTF_8->setChecked(editor->encodingOption() == ENCODING_UTF8); ui->actionEncode_in_UTF_8_BOM->setChecked(editor->encodingOption() == ENCODING_UTF8_BOM); } else { mFileEncodingStatus->setText(""); - ui->actionAuto_Detect->setChecked(false); + //ui->actionAuto_Detect->setEnabled(true); + //ui->actionAuto_Detect->setChecked(false); ui->actionEncode_in_ANSI->setChecked(false); ui->actionEncode_in_UTF_8->setChecked(false); ui->actionEncode_in_UTF_8_BOM->setChecked(false); @@ -1419,7 +1421,7 @@ void MainWindow::openFiles(const QStringList &files) Editor* MainWindow::openFile(const QString &filename, bool activate, QTabWidget* page) { - if (filename.isEmpty()) + if (!fileExists(filename)) return nullptr; Editor* editor = mEditorList->getOpenedEditorByFilename(filename); if (editor!=nullptr) { @@ -3333,7 +3335,7 @@ void MainWindow::buildEncodingMenu() mMenuEncoding = new QMenu(); mMenuEncoding->setTitle(tr("File Encoding")); - mMenuEncoding->addAction(ui->actionAuto_Detect); + //mMenuEncoding->addAction(ui->actionAuto_Detect); mMenuEncoding->addAction(ui->actionEncode_in_ANSI); mMenuEncoding->addAction(ui->actionEncode_in_UTF_8); mMenuEncoding->addAction(ui->actionEncode_in_UTF_8_BOM); @@ -3366,7 +3368,7 @@ void MainWindow::buildEncodingMenu() ui->menuEdit->insertMenu(ui->actionFoldAll,mMenuEncoding); ui->menuEdit->insertSeparator(ui->actionFoldAll); - ui->actionAuto_Detect->setCheckable(true); + //ui->actionAuto_Detect->setCheckable(true); ui->actionEncode_in_ANSI->setCheckable(true); ui->actionEncode_in_UTF_8->setCheckable(true); ui->actionEncode_in_UTF_8_BOM->setCheckable(true); diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index c6ad2201..4ee12e7d 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -236,18 +236,15 @@ void Project::open() newUnit->setPriority(ini.GetLongValue(groupName,"Priority", 1000)); newUnit->setOverrideBuildCmd(ini.GetBoolValue(groupName,"OverrideBuildCmd", false)); newUnit->setBuildCmd(fromByteArray(ini.GetValue(groupName,"BuildCmd", ""))); - QByteArray defaultEncoding = toByteArray(mOptions.encoding); + QByteArray defaultEncoding = mOptions.encoding; //Compatibility if (ini.GetBoolValue(groupName,"DetectEncoding",false)){ - defaultEncoding = ENCODING_AUTO_DETECT; + defaultEncoding = mOptions.encoding; } newUnit->setEncoding(ini.GetValue(groupName, "FileEncoding",defaultEncoding)); if (QTextCodec::codecForName(newUnit->encoding())==nullptr) { - newUnit->setEncoding(ENCODING_AUTO_DETECT); - } - if (QTextCodec::codecForName(newUnit->encoding())==nullptr) { - newUnit->setEncoding(ENCODING_AUTO_DETECT); + newUnit->setEncoding(mOptions.encoding); } newUnit->setRealEncoding(ini.GetValue(groupName, "RealEncoding",ENCODING_ASCII)); @@ -805,9 +802,16 @@ void Project::associateEditorToUnit(Editor *editor, PProjectUnit unit) return; } if (editor) { + editor->setProject(this); + if (editor->encodingOption()==ENCODING_AUTO_DETECT) { + if (editor->fileEncoding()==ENCODING_ASCII) { + editor->setEncodingOption(mOptions.encoding); + } else { + editor->setEncodingOption(editor->fileEncoding()); + } + } unit->setEncoding(editor->encodingOption()); unit->setRealEncoding(editor->fileEncoding()); - editor->setProject(this); } } @@ -1041,7 +1045,7 @@ bool Project::saveAsTemplate(const QString &templateFolder, if (!mOptions.addCharset) ini->SetBoolValue("Project", "AddCharset",false); if (mOptions.encoding!=ENCODING_AUTO_DETECT) - ini->SetValue("Project","Encoding",mOptions.encoding.toUtf8()); + ini->SetValue("Project","Encoding",mOptions.encoding); if (mOptions.modelType!=ProjectModelType::FileSystem) ini->SetLongValue("Project", "ModelType", (int)mOptions.modelType); ini->SetLongValue("Project","ClassBrowserType", (int)mOptions.classBrowserType); @@ -1134,7 +1138,7 @@ void Project::saveOptions() ini.SetLongValue("Project","StaticLink", mOptions.staticLink); ini.SetLongValue("Project","AddCharset", mOptions.addCharset); ini.SetValue("Project","ExecEncoding", mOptions.execEncoding); - ini.SetValue("Project","Encoding",toByteArray(mOptions.encoding)); + ini.SetValue("Project","Encoding",mOptions.encoding); ini.SetLongValue("Project","ModelType", (int)mOptions.modelType); ini.SetLongValue("Project","ClassBrowserType", (int)mOptions.classBrowserType); ini.SetBoolValue("Project","AllowParallelBuilding",mOptions.allowParallelBuilding); @@ -1225,11 +1229,12 @@ PProjectUnit Project::internalAddUnit(const QString &inFileName, PProjectModelNo newUnit->setFileName(QDir(directory()).filePath(inFileName)); Editor * e= unitEditor(newUnit); if (e) { - newUnit->setEncoding(e->encodingOption()); - newUnit->setRealEncoding(e->fileEncoding()); - e->setProject(this); + associateEditorToUnit(e,newUnit); +// newUnit->setEncoding(e->encodingOption()); +// newUnit->setRealEncoding(e->fileEncoding()); +// e->setProject(this); } else { - newUnit->setEncoding(options().encoding.toUtf8()); + newUnit->setEncoding(options().encoding); } // Determine compilation flags @@ -2053,10 +2058,14 @@ void Project::loadOptions(SimpleIni& ini) } bool useUTF8 = ini.GetBoolValue("Project", "UseUTF8", false); if (useUTF8) { - mOptions.encoding = fromByteArray(ini.GetValue("Project","Encoding", ENCODING_UTF8)); + mOptions.encoding = ini.GetValue("Project","Encoding", ENCODING_UTF8); } else { - mOptions.encoding = fromByteArray(ini.GetValue("Project","Encoding", ENCODING_AUTO_DETECT)); + mOptions.encoding = ini.GetValue("Project","Encoding", ENCODING_SYSTEM_DEFAULT); } + if (mOptions.encoding == ENCODING_AUTO_DETECT) + mOptions.encoding = pSettings->editor().defaultEncoding(); + if (mOptions.encoding == ENCODING_AUTO_DETECT) + mOptions.encoding = ENCODING_SYSTEM_DEFAULT; mOptions.allowParallelBuilding = ini.GetBoolValue("Project","AllowParallelBuilding"); mOptions.parellelBuildingJobs = ini.GetLongValue("Project","ParellelBuildingJobs"); @@ -2298,7 +2307,7 @@ ProjectUnit::ProjectUnit(Project* parent) mFileMissing = false; mPriority=0; mNew = true; - mEncoding=ENCODING_AUTO_DETECT; + mEncoding=ENCODING_SYSTEM_DEFAULT; mRealEncoding=""; } diff --git a/RedPandaIDE/projectoptions.h b/RedPandaIDE/projectoptions.h index 82189b34..eab0012b 100644 --- a/RedPandaIDE/projectoptions.h +++ b/RedPandaIDE/projectoptions.h @@ -96,7 +96,7 @@ struct ProjectOptions{ bool staticLink; bool addCharset; QByteArray execEncoding; - QString encoding; + QByteArray encoding; ProjectModelType modelType; ProjectClassBrowserType classBrowserType; bool allowParallelBuilding; diff --git a/RedPandaIDE/projecttemplate.cpp b/RedPandaIDE/projecttemplate.cpp index b179f089..ff739af4 100644 --- a/RedPandaIDE/projecttemplate.cpp +++ b/RedPandaIDE/projecttemplate.cpp @@ -150,10 +150,12 @@ void ProjectTemplate::readTemplateFile(const QString &fileName) mOptions.addCharset = mIni->GetBoolValue("Project", "AddCharset",true); bool useUTF8 = mIni->GetBoolValue("Project", "UseUTF8", false); if (useUTF8) { - mOptions.encoding = fromByteArray(mIni->GetValue("Project","Encoding", ENCODING_UTF8)); + mOptions.encoding = mIni->GetValue("Project","Encoding", ENCODING_UTF8); } else { - mOptions.encoding = fromByteArray(mIni->GetValue("Project","Encoding", ENCODING_AUTO_DETECT)); + mOptions.encoding = mIni->GetValue("Project","Encoding", pSettings->editor().defaultEncoding()); } + if (mOptions.encoding == ENCODING_AUTO_DETECT) + mOptions.encoding = ENCODING_SYSTEM_DEFAULT; mOptions.modelType = (ProjectModelType)mIni->GetLongValue("Project", "ModelType", (int)ProjectModelType::FileSystem); mOptions.classBrowserType = (ProjectClassBrowserType)mIni->GetLongValue("Project", "ClassBrowserType", (int)ProjectClassBrowserType::CurrentFile); diff --git a/RedPandaIDE/settingsdialog/projectgeneralwidget.cpp b/RedPandaIDE/settingsdialog/projectgeneralwidget.cpp index cee78722..c66b8b7d 100644 --- a/RedPandaIDE/settingsdialog/projectgeneralwidget.cpp +++ b/RedPandaIDE/settingsdialog/projectgeneralwidget.cpp @@ -97,7 +97,7 @@ void ProjectGeneralWidget::doSave() return; project->setName(ui->txtName->text().trimmed()); - project->options().encoding = ui->cbDefaultEncoding->currentText(); + project->options().encoding = ui->cbDefaultEncoding->currentText().toUtf8(); int row = std::max(0,ui->lstType->currentRow()); project->options().type = static_cast(row); @@ -167,7 +167,10 @@ void ProjectGeneralWidget::on_btnRemove_clicked() void ProjectGeneralWidget::init() { ui->cbDefaultEncoding->clear(); - ui->cbDefaultEncoding->addItems(pSystemConsts->codecNames()); + QStringList codecNames=pSystemConsts->codecNames(); + //project encoding shouldn't be auto + codecNames.removeAll(ENCODING_AUTO_DETECT); + ui->cbDefaultEncoding->addItems(codecNames); SettingsWidget::init(); }