- 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"
This commit is contained in:
Roy Qu 2023-01-24 10:21:19 +08:00
parent 4a941b63b4
commit 1f491fccfd
7 changed files with 68 additions and 33 deletions

View File

@ -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

View File

@ -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()

View File

@ -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);

View File

@ -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="";
}

View File

@ -96,7 +96,7 @@ struct ProjectOptions{
bool staticLink;
bool addCharset;
QByteArray execEncoding;
QString encoding;
QByteArray encoding;
ProjectModelType modelType;
ProjectClassBrowserType classBrowserType;
bool allowParallelBuilding;

View File

@ -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);

View File

@ -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<ProjectType>(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();
}