From 0875d15d67c681e636af757e45d68a3796d34702 Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Thu, 13 Jan 2022 16:47:48 +0800 Subject: [PATCH] - fix: project's icon setting is not correctly saved - fix: project's type setting won't be saved - fix: If project's compiler set is not the same with the default compiler set, auto openned project's file will use wrong compiler set to do syntax check. - fix: open a project file through "File"->"Open" will not correctly connect it with the project internally --- NEWS.md | 4 +++ RedPandaIDE/mainwindow.cpp | 26 ++++++++------- RedPandaIDE/mainwindow.h | 2 +- RedPandaIDE/project.cpp | 23 ++++++------- RedPandaIDE/project.h | 1 + .../settingsdialog/projectgeneralwidget.cpp | 32 ++++++++++--------- .../settingsdialog/projectgeneralwidget.ui | 4 +-- RedPandaIDE/settingsdialog/settingswidget.cpp | 21 ++++++++++++ 8 files changed, 70 insertions(+), 43 deletions(-) diff --git a/NEWS.md b/NEWS.md index a1fbb23a..4c0eaf76 100644 --- a/NEWS.md +++ b/NEWS.md @@ -17,6 +17,10 @@ Red Panda C++ Version 0.13.2 - fix: caret dispears when at '\t' under Windows 7 - enhancement: ctrl+up/down scrolls in the editor - enhancement: add "wrap around" option to find/replace + - fix: project's icon setting is not correctly saved + - fix: project's type setting won't be saved + - fix: If project's compiler set is not the same with the default compiler set, auto openned project's file will use wrong compiler set to do syntax check. + - fix: open a project file through "File"->"Open" will not correctly connect it with the project internally Red Panda C++ Version 0.13.1 - enhancement: suppoort localization info in project templates diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 5887da2a..cae2e734 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -975,8 +975,9 @@ void MainWindow::openFile(const QString &filename, QTabWidget* page) } try { pSettings->history().removeFile(filename); + bool inProject = (mProject && mProject->isProjectUnit(filename)); editor = mEditorList->newEditor(filename,ENCODING_AUTO_DETECT, - false, false, page); + inProject, false, page); editor->activate(); this->updateForEncodingInfo(); } catch (FileError e) { @@ -984,7 +985,7 @@ void MainWindow::openFile(const QString &filename, QTabWidget* page) } } -void MainWindow::openProject(const QString &filename) +void MainWindow::openProject(const QString &filename, bool openFiles) { if (!fileExists(filename)) { return; @@ -1029,13 +1030,12 @@ void MainWindow::openProject(const QString &filename) // if not devData.ShowLeftPages then // actProjectManager.Execute; //checkForDllProfiling(); - updateAppTitle(); - updateCompilerSet(); //parse the project // UpdateClassBrowsing; scanActiveProject(true); - mProject->doAutoOpen(); + if (openFiles) + mProject->doAutoOpen(); //update editor's inproject flag for (int i=0;iunits().count();i++) { @@ -1054,6 +1054,8 @@ void MainWindow::openProject(const QString &filename) if (e) { checkSyntaxInBack(e); } + updateAppTitle(); + updateCompilerSet(); updateClassBrowserForEditor(e); } updateForEncodingInfo(); @@ -1985,8 +1987,12 @@ void MainWindow::loadLastOpens() QMessageBox::Ok); return; } - Editor * focusedEditor = nullptr; + QString projectFilename = QString::fromLocal8Bit((lastOpenIni.GetValue("LastOpens", "Project",""))); int count = lastOpenIni.GetLongValue("LastOpens","Count",0); + if (fileExists(projectFilename)) { + openProject(projectFilename, false); + } + Editor * focusedEditor = nullptr; for (int i=0;ileftPageWidget(); else page = mEditorList->rightPageWidget(); - Editor * editor = mEditorList->newEditor(editorFilename,ENCODING_AUTO_DETECT,false,false,page); + bool inProject = (mProject && mProject->isProjectUnit(editorFilename)); + Editor * editor = mEditorList->newEditor(editorFilename,ENCODING_AUTO_DETECT,inProject,false,page); if (!editor) continue; BufferCoord pos; @@ -2016,10 +2023,7 @@ void MainWindow::loadLastOpens() focusedEditor = editor; pSettings->history().removeFile(editorFilename); } - QString projectFilename = QString::fromLocal8Bit((lastOpenIni.GetValue("LastOpens", "Project",""))); - if (fileExists(projectFilename)) { - openProject(projectFilename); - } else { + if (count>0) { updateEditorActions(); updateForEncodingInfo(); } diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index afb60dc3..d0c7d868 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -177,7 +177,7 @@ public: const PBookmarkModel &bookmarkModel() const; void openFile(const QString& filename, QTabWidget* page=nullptr); - void openProject(const QString& filename); + void openProject(const QString& filename, bool openFiles = true); void changeOptions(const QString& widgetName=QString(), const QString& groupName=QString()); bool openningFiles() const; diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index dcc2619d..d2cd6b8e 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -564,6 +564,15 @@ bool Project::saveUnits() return true; } +bool Project::isProjectUnit(const QString &filename) +{ + foreach(const PProjectUnit& unit, mUnits) { + if (QString::compare(unit->fileName(),filename, PATH_SENSITIVITY)==0) + return true; + } + return false; +} + void Project::setCompilerOption(const QString &optionString, char value) { if (mOptions.compilerSet<0 || mOptions.compilerSet>=pSettings->compilerSets().size()) { @@ -1211,20 +1220,6 @@ void Project::createFolderNodes() void Project::doAutoOpen() { - //todo: -// case devData.AutoOpen of -// 0: begin -// for i := 0 to pred(fUnits.Count) do -// OpenUnit(i); // Open all -// if fUnits.Count > 0 then -// fUnits[0].Editor.Activate; // Show first -// end; -// 1: -// if fUnits.Count > 0 then -// OpenUnit(0).Activate; // Open and show first -// 2: -// LoadLayout; // Open previous selection -// end; loadLayout(); } diff --git a/RedPandaIDE/project.h b/RedPandaIDE/project.h index 3d833e38..6ade7f3c 100644 --- a/RedPandaIDE/project.h +++ b/RedPandaIDE/project.h @@ -184,6 +184,7 @@ public: void saveUnitAs(int i, const QString& sFileName, bool syncEditor = true); // save single [UnitX] void saveUnitLayout(Editor* e, int index); // save single [UnitX] cursor positions bool saveUnits(); + bool isProjectUnit(const QString& filename); void setCompilerOption(const QString& optionString, char value); void sortUnitsByPriority(); void sortUnitsByAlpha(); diff --git a/RedPandaIDE/settingsdialog/projectgeneralwidget.cpp b/RedPandaIDE/settingsdialog/projectgeneralwidget.cpp index d12748d2..8a1e7795 100644 --- a/RedPandaIDE/settingsdialog/projectgeneralwidget.cpp +++ b/RedPandaIDE/settingsdialog/projectgeneralwidget.cpp @@ -42,7 +42,7 @@ ProjectGeneralWidget::~ProjectGeneralWidget() void ProjectGeneralWidget::refreshIcon() { QPixmap icon(mIconPath); - ui->lblICon->setPixmap(icon); + ui->lbIcon->setPixmap(icon); } void ProjectGeneralWidget::doLoad() @@ -103,23 +103,25 @@ void ProjectGeneralWidget::doSave() project->options().useGPP = ui->cbDefaultCpp->isChecked(); project->options().supportXPThemes = ui->cbSupportXPTheme->isChecked(); if (mIconPath.isEmpty() - || !ui->lblICon->pixmap() || ui->lblICon->pixmap()->isNull()) { + || !ui->lbIcon->pixmap() || ui->lbIcon->pixmap()->isNull()) { project->options().icon = ""; } else { QString iconPath = changeFileExt(project->filename(),"ico"); - if (QFile(iconPath).exists()) { - if (!QFile::remove(iconPath)) { - QMessageBox::critical(this, - tr("Can't remove old icon file"), - tr("Can't remove old icon file '%1'") - .arg(iconPath), - QMessageBox::Ok); + if (iconPath!=mIconPath) { + if (QFile(iconPath).exists()) { + if (!QFile::remove(iconPath)) { + QMessageBox::critical(this, + tr("Can't remove old icon file"), + tr("Can't remove old icon file '%1'") + .arg(iconPath), + QMessageBox::Ok); + } } + QFile::copy(mIconPath, iconPath); + project->options().icon = iconPath; + mIconPath = iconPath; + refreshIcon(); } - QFile::copy(mIconPath, iconPath); - project->options().icon = iconPath; - mIconPath = iconPath; - refreshIcon(); } project->saveOptions(); @@ -130,7 +132,7 @@ void ProjectGeneralWidget::on_btnBrowse_clicked() QString fileName = QFileDialog::getOpenFileName(this, tr("Select icon file"), pSettings->dirs().appDir(), - tr("Icon Files (*.ico)")); + tr("Image Files (*.ico *.png *.jpg)")); if (!fileName.isEmpty()) { mIconPath = fileName; QPixmap icon(mIconPath); @@ -144,7 +146,7 @@ void ProjectGeneralWidget::on_btnBrowse_clicked() void ProjectGeneralWidget::on_btnRemove_clicked() { mIconPath = ""; - ui->lblICon->setPixmap(QPixmap()); + ui->lbIcon->setPixmap(QPixmap()); ui->btnRemove->setEnabled(!mIconPath.isEmpty()); setSettingsChanged(); } diff --git a/RedPandaIDE/settingsdialog/projectgeneralwidget.ui b/RedPandaIDE/settingsdialog/projectgeneralwidget.ui index 2369ca5f..889b4c56 100644 --- a/RedPandaIDE/settingsdialog/projectgeneralwidget.ui +++ b/RedPandaIDE/settingsdialog/projectgeneralwidget.ui @@ -6,7 +6,7 @@ 0 0 - 685 + 687 639 @@ -114,7 +114,7 @@ - + 128 diff --git a/RedPandaIDE/settingsdialog/settingswidget.cpp b/RedPandaIDE/settingsdialog/settingswidget.cpp index 72979f30..2d52e912 100644 --- a/RedPandaIDE/settingsdialog/settingswidget.cpp +++ b/RedPandaIDE/settingsdialog/settingswidget.cpp @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include "../widgets/coloredit.h" @@ -121,6 +122,9 @@ void SettingsWidget::connectInputs() for (QAbstractItemView* p: findChildren()) { connectAbstractItemView(p); } + for (QListWidget* p:findChildren()) { + connect(p, QOverload::of(&QListWidget::currentRowChanged) ,this, &SettingsWidget::setSettingsChanged); + } for (QGroupBox* p: findChildren()) { connect(p, &QGroupBox::toggled,this, &SettingsWidget::setSettingsChanged); } @@ -135,15 +139,32 @@ void SettingsWidget::disconnectInputs() for (QCheckBox* p:findChildren()) { disconnect(p, &QCheckBox::stateChanged, this, &SettingsWidget::setSettingsChanged); } + for (QRadioButton* p:findChildren()) { + disconnect(p, &QRadioButton::toggled, this, &SettingsWidget::setSettingsChanged); + } for (QPlainTextEdit* p:findChildren()) { disconnect(p, &QPlainTextEdit::textChanged, this, &SettingsWidget::setSettingsChanged); } + for (QSpinBox* p:findChildren()) { + disconnect(p, QOverload::of(&QSpinBox::valueChanged), this, &SettingsWidget::setSettingsChanged); + } + for (ColorEdit* p:findChildren()) { + disconnect(p, &ColorEdit::colorChanged, this, &SettingsWidget::setSettingsChanged); + } + for (QComboBox* p: findChildren()) { disconnect(p, QOverload::of(&QComboBox::currentIndexChanged) ,this, &SettingsWidget::setSettingsChanged); } for (QAbstractItemView* p: findChildren()) { disconnectAbstractItemView(p); } + for (QListWidget* p:findChildren()) { + disconnect(p, QOverload::of(&QListWidget::currentRowChanged) ,this, &SettingsWidget::setSettingsChanged); + } + for (QGroupBox* p: findChildren()) { + disconnect(p, &QGroupBox::toggled,this, &SettingsWidget::setSettingsChanged); + } + } const QString &SettingsWidget::group()