diff --git a/NEWS.md b/NEWS.md index e2cc2885..31cc9dab 100644 --- a/NEWS.md +++ b/NEWS.md @@ -4,6 +4,7 @@ Red Panda C++ Version 1.0.0 - enhancement: "locate in files view" will request user's confirmation when change the working folder - enhancement: adjust tab order in the find dialog - enhancement: highlight hits in the find panel's result list + - enhancement: optimize startup time Red Panda C++ Version 0.14.5 - fix: the "gnu c++ 20" option in compiler set options is wrong diff --git a/RedPandaIDE/main.cpp b/RedPandaIDE/main.cpp index 7d3c83be..58a3cd62 100644 --- a/RedPandaIDE/main.cpp +++ b/RedPandaIDE/main.cpp @@ -249,7 +249,6 @@ int main(int argc, char *argv[]) QApplication app(argc, argv); QFile tempFile(QDir::tempPath()+QDir::separator()+"RedPandaDevCppStartUp.lock"); - { bool firstRun; QString settingFilename = getSettingFilename(QString(), firstRun); @@ -354,6 +353,13 @@ int main(int argc, char *argv[]) MainWindow mainWindow; pMainWindow = &mainWindow; +#if QT_VERSION_MAJOR==5 && QT_VERSION_MINOR < 15 + setScreenDPI(qApp->primaryScreen()->logicalDotsPerInch()); +#else + if (mainWindow.screen()) + setScreenDPI(mainWindow.screen()->logicalDotsPerInch()); +#endif + mainWindow.show(); if (app.arguments().count()>1) { QStringList filesToOpen = app.arguments(); filesToOpen.pop_front(); @@ -365,22 +371,20 @@ int main(int argc, char *argv[]) pMainWindow->newEditor(); } } -#if QT_VERSION_MAJOR==5 && QT_VERSION_MINOR < 15 - setScreenDPI(qApp->primaryScreen()->logicalDotsPerInch()); -#else - if (mainWindow.screen()) - setScreenDPI(mainWindow.screen()->logicalDotsPerInch()); -#endif - mainWindow.show(); //reset default open folder QDir::setCurrent(pSettings->environment().defaultOpenFolder()); + pMainWindow->setFilesViewRoot(pSettings->environment().currentFolder()); + #ifdef Q_OS_WIN WindowLogoutEventFilter filter; app.installNativeEventFilter(&filter); #endif - tempFile.remove(); + if (tempFile.isOpen()) { + tempFile.close(); + tempFile.remove(); + } int retCode = app.exec(); QString configDir = pSettings->dirs().config(); // save settings diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 89a04783..437a188f 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -299,7 +299,7 @@ MainWindow::MainWindow(QWidget *parent) mFileSystemModel.setNameFilters(pSystemConsts->defaultFileNameFilters()); mFileSystemModel.setNameFilterDisables(false); - setFilesViewRoot(pSettings->environment().currentFolder()); + //setFilesViewRoot(pSettings->environment().currentFolder()); for (int i=1;itreeFiles->hideColumn(i); } @@ -674,7 +674,8 @@ void MainWindow::applySettings() //icon sets for files view pIconsManager->updateFileSystemIcons(pSettings->environment().iconSet(),pointToPixel(pSettings->environment().interfaceFontSize())); - setFilesViewRoot(mFileSystemModel.rootPath()); + if (!mFileSystemModel.rootPath().isEmpty() && mFileSystemModel.rootPath()!=".") + setFilesViewRoot(pSettings->environment().currentFolder()); // for (int i=0;icbFilesPath->count();i++) { // ui->cbFilesPath->setItemIcon(i,pIconsManager->getIcon(IconsManager::FILESYSTEM_GIT)); // } @@ -1205,8 +1206,8 @@ void MainWindow::updateCompilerSet() { mCompilerSet->blockSignals(true); mCompilerSet->clear(); - for (size_t i=0;icompilerSets().list().size();i++) { - mCompilerSet->addItem(pSettings->compilerSets().list()[i]->name()); + for (size_t i=0;icompilerSets().size();i++) { + mCompilerSet->addItem(pSettings->compilerSets().getSet(i)->name()); } int index=pSettings->compilerSets().defaultIndex(); if (mProject) { diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index e5bf6d48..cc52db18 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -120,6 +120,8 @@ public: void showSearchPanel(bool showReplace = false); void showCPUInfoDialog(); + void setFilesViewRoot(const QString& path, bool setOpenFolder=false); + void applySettings(); void applyUISettings(); QFileSystemWatcher* fileSystemWatcher(); @@ -243,7 +245,6 @@ private: void scanActiveProject(bool parse=false); void includeOrSkipDirs(const QStringList& dirs, bool skip); void showSearchReplacePanel(bool show); - void setFilesViewRoot(const QString& path, bool setOpenFolder=false); void clearIssues(); void doCompileRun(RunType runType); void updateProblemCaseOutput(POJProblemCase problemCase); diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index 11488049..2016532a 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -631,7 +631,7 @@ void Project::setCompilerOption(const QString &optionString, char value) if (mOptions.compilerSet<0 || mOptions.compilerSet>=pSettings->compilerSets().size()) { return; } - std::shared_ptr compilerSet = pSettings->compilerSets().list()[mOptions.compilerSet]; + std::shared_ptr compilerSet = pSettings->compilerSets().getSet(mOptions.compilerSet); int optionIndex = compilerSet->findOptionIndex(optionString); // Does the option exist? if (optionIndex>=0){ diff --git a/RedPandaIDE/settings.cpp b/RedPandaIDE/settings.cpp index 3a340a5b..cd52c4fe 100644 --- a/RedPandaIDE/settings.cpp +++ b/RedPandaIDE/settings.cpp @@ -1442,6 +1442,10 @@ Settings::CompilerSet::CompilerSet(const QString& compilerFolder): setUserInput(); setDefines(); + + mFullLoaded = true; + } else { + mFullLoaded = false; } setOptions(); } @@ -1468,7 +1472,8 @@ Settings::CompilerSet::CompilerSet(const Settings::CompilerSet &set): mUseCustomLinkParams(set.mUseCustomLinkParams), mCustomCompileParams(set.mCustomCompileParams), mCustomLinkParams(set.mCustomLinkParams), - mAutoAddCharsetParams(set.mAutoAddCharsetParams) + mAutoAddCharsetParams(set.mAutoAddCharsetParams), + mFullLoaded(set.mFullLoaded) { // Executables, most are hardcoded for (PCompilerOption pOption:set.mOptions) { @@ -1738,16 +1743,31 @@ QStringList &Settings::CompilerSet::libDirs() QStringList &Settings::CompilerSet::defaultCIncludeDirs() { + if (!mFullLoaded && !binDirs().isEmpty()) { + mFullLoaded=true; + setDirectories(binDirs()[0]); + setDefines(); + } return mDefaultCIncludeDirs; } QStringList &Settings::CompilerSet::defaultCppIncludeDirs() { + if (!mFullLoaded && !binDirs().isEmpty()) { + mFullLoaded=true; + setDirectories(binDirs()[0]); + setDefines(); + } return mDefaultCppIncludeDirs; } QStringList &Settings::CompilerSet::defaultLibDirs() { + if (!mFullLoaded && !binDirs().isEmpty()) { + mFullLoaded=true; + setDirectories(binDirs()[0]); + setDefines(); + } return mLibDirs; } @@ -1791,8 +1811,13 @@ void Settings::CompilerSet::setName(const QString &value) mName = value; } -const QStringList& Settings::CompilerSet::defines() const +const QStringList& Settings::CompilerSet::defines() { + if (!mFullLoaded && !binDirs().isEmpty()) { + mFullLoaded=true; + setDirectories(binDirs()[0]); + setDefines(); + } return mDefines; } @@ -2724,11 +2749,6 @@ void Settings::CompilerSets::deleteSet(int index) saveSets(); } -Settings::CompilerSetList &Settings::CompilerSets::list() -{ - return mList; -} - int Settings::CompilerSets::size() const { return mList.size(); @@ -2901,8 +2921,9 @@ Settings::PCompilerSet Settings::CompilerSets::loadSet(int index) if (pSet->binDirs().isEmpty()) return PCompilerSet(); - pSet->setDirectories(pSet->binDirs()[0]); - pSet->setDefines(); + + //pSet->setDirectories(pSet->binDirs()[0]); + //pSet->setDefines(); return pSet; } diff --git a/RedPandaIDE/settings.h b/RedPandaIDE/settings.h index 712c6d88..2d6e17e7 100644 --- a/RedPandaIDE/settings.h +++ b/RedPandaIDE/settings.h @@ -1210,7 +1210,7 @@ public: void setType(const QString& value); const QString& name() const; void setName(const QString& value); - const QStringList& defines() const; + const QStringList& defines(); const QString& target() const; void setTarget(const QString& value); @@ -1261,6 +1261,7 @@ public: QByteArray getCompilerOutput(const QString& binDir, const QString& binFile, const QStringList& arguments); private: + bool mFullLoaded; // Executables, most are hardcoded QString mCCompiler; QString mCppCompiler; @@ -1320,8 +1321,6 @@ public: void saveDefaultIndex(); void deleteSet(int index); void saveSet(int index); - //properties - CompilerSetList& list(); int size() const; int defaultIndex() const; void setDefaultIndex(int value); diff --git a/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp b/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp index e3850d49..c3310fc9 100644 --- a/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp +++ b/RedPandaIDE/settingsdialog/compilersetoptionwidget.cpp @@ -167,7 +167,7 @@ void CompilerSetOptionWidget::doLoad() { disconnectInputs(); ui->cbCompilerSet->clear(); - if (pSettings->compilerSets().list().size()<=0) { + if (pSettings->compilerSets().size()<=0) { ui->btnRenameCompilerSet->setEnabled(false); ui->btnRemoveCompilerSet->setEnabled(false); return; @@ -176,8 +176,8 @@ void CompilerSetOptionWidget::doLoad() ui->btnRemoveCompilerSet->setEnabled(true); } int index=pSettings->compilerSets().defaultIndex(); - for (int i=0;icompilerSets().list().size();i++) { - ui->cbCompilerSet->addItem(pSettings->compilerSets().list()[i]->name()); + for (int i=0;icompilerSets().size();i++) { + ui->cbCompilerSet->addItem(pSettings->compilerSets().getSet(i)->name()); } if (index < 0 || index>=ui->cbCompilerSet->count()) { index = 0; @@ -189,7 +189,7 @@ void CompilerSetOptionWidget::doLoad() void CompilerSetOptionWidget::doSave() { - if (pSettings->compilerSets().list().size()>0) { + if (pSettings->compilerSets().size()>0) { saveCurrentCompilerSet(); } pSettings->compilerSets().saveSets(); @@ -296,7 +296,7 @@ void CompilerSetOptionWidget::on_btnAddBlankCompilerSet_pressed() { QString name = QInputDialog::getText(this,tr("Compiler Set Name"),tr("Name")); pSettings->compilerSets().addSet(); - pSettings->compilerSets().setDefaultIndex(pSettings->compilerSets().list().size()-1); + pSettings->compilerSets().setDefaultIndex(pSettings->compilerSets().size()-1); pSettings->compilerSets().defaultSet()->setName(name); doLoad(); } diff --git a/RedPandaIDE/settingsdialog/projectcompilerwidget.cpp b/RedPandaIDE/settingsdialog/projectcompilerwidget.cpp index 076a9de5..817b369b 100644 --- a/RedPandaIDE/settingsdialog/projectcompilerwidget.cpp +++ b/RedPandaIDE/settingsdialog/projectcompilerwidget.cpp @@ -145,8 +145,8 @@ void ProjectCompilerWidget::doSave() void ProjectCompilerWidget::init() { ui->cbCompilerSet->clear(); - for (const Settings::PCompilerSet& set:pSettings->compilerSets().list()){ - ui->cbCompilerSet->addItem(set->name()); + for (int i=0;icompilerSets().size();i++) { + ui->cbCompilerSet->addItem(pSettings->compilerSets().getSet(i)->name()); } SettingsWidget::init(); } diff --git a/RedPandaIDE/vcs/gitmanager.cpp b/RedPandaIDE/vcs/gitmanager.cpp index 48e76915..109ecbdf 100644 --- a/RedPandaIDE/vcs/gitmanager.cpp +++ b/RedPandaIDE/vcs/gitmanager.cpp @@ -35,7 +35,8 @@ void GitManager::createRepository(const QString &folder) bool GitManager::hasRepository(const QString &folder, QString& currentBranch) { - + if (folder.isEmpty()) + return false; QStringList args; args.append("status"); args.append("-b"); diff --git a/RedPandaIDE/vcs/gitrepository.cpp b/RedPandaIDE/vcs/gitrepository.cpp index 353f3da9..fccb176f 100644 --- a/RedPandaIDE/vcs/gitrepository.cpp +++ b/RedPandaIDE/vcs/gitrepository.cpp @@ -77,13 +77,16 @@ bool GitRepository::revert(QString& output) void GitRepository::setFolder(const QString &newFolder) { mFolder = newFolder; - mRealFolder = mManager->rootFolder(mFolder); + if (!newFolder.isEmpty()) + mRealFolder = mManager->rootFolder(mFolder); + else + mRealFolder = newFolder; update(); } void GitRepository::update() { - if (!mManager->isValid()) { + if (!mManager->isValid() || mFolder.isEmpty()) { mInRepository = false; mBranch = ""; mFilesInRepositories.clear(); diff --git a/RedPandaIDE/widgets/searchdialog.cpp b/RedPandaIDE/widgets/searchdialog.cpp index 60f580cb..ad4417ad 100644 --- a/RedPandaIDE/widgets/searchdialog.cpp +++ b/RedPandaIDE/widgets/searchdialog.cpp @@ -60,6 +60,7 @@ void SearchDialog::find(const QString &text) mTabBar->setCurrentIndex(0); } ui->cbFind->setCurrentText(text); + ui->cbFind->setFocus(); show(); } @@ -81,6 +82,7 @@ void SearchDialog::findInFiles(const QString &text) { mTabBar->setCurrentIndex(2); ui->cbFind->setCurrentText(text); + ui->cbFind->setFocus(); show(); } @@ -89,6 +91,8 @@ void SearchDialog::findInFiles(const QString &keyword, SearchFileScope scope, Sy mTabBar->setCurrentIndex(1); ui->cbFind->setCurrentText(keyword); + ui->cbFind->setFocus(); + switch(scope) { case SearchFileScope::currentFile: ui->rbCurrentFile->setChecked(true); @@ -114,6 +118,7 @@ void SearchDialog::replace(const QString &sFind, const QString &sReplace) mTabBar->setCurrentIndex(1); ui->cbFind->setCurrentText(sFind); ui->cbReplace->setCurrentText(sReplace); + ui->cbFind->setFocus(); show(); }