- enhancement: optimize startup time

This commit is contained in:
Roy Qu 2022-03-11 20:51:33 +08:00
parent 42af39d28f
commit 416023dc60
12 changed files with 73 additions and 37 deletions

View File

@ -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: "locate in files view" will request user's confirmation when change the working folder
- enhancement: adjust tab order in the find dialog - enhancement: adjust tab order in the find dialog
- enhancement: highlight hits in the find panel's result list - enhancement: highlight hits in the find panel's result list
- enhancement: optimize startup time
Red Panda C++ Version 0.14.5 Red Panda C++ Version 0.14.5
- fix: the "gnu c++ 20" option in compiler set options is wrong - fix: the "gnu c++ 20" option in compiler set options is wrong

View File

@ -249,7 +249,6 @@ int main(int argc, char *argv[])
QApplication app(argc, argv); QApplication app(argc, argv);
QFile tempFile(QDir::tempPath()+QDir::separator()+"RedPandaDevCppStartUp.lock"); QFile tempFile(QDir::tempPath()+QDir::separator()+"RedPandaDevCppStartUp.lock");
{ {
bool firstRun; bool firstRun;
QString settingFilename = getSettingFilename(QString(), firstRun); QString settingFilename = getSettingFilename(QString(), firstRun);
@ -354,6 +353,13 @@ int main(int argc, char *argv[])
MainWindow mainWindow; MainWindow mainWindow;
pMainWindow = &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) { if (app.arguments().count()>1) {
QStringList filesToOpen = app.arguments(); QStringList filesToOpen = app.arguments();
filesToOpen.pop_front(); filesToOpen.pop_front();
@ -365,22 +371,20 @@ int main(int argc, char *argv[])
pMainWindow->newEditor(); 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 //reset default open folder
QDir::setCurrent(pSettings->environment().defaultOpenFolder()); QDir::setCurrent(pSettings->environment().defaultOpenFolder());
pMainWindow->setFilesViewRoot(pSettings->environment().currentFolder());
#ifdef Q_OS_WIN #ifdef Q_OS_WIN
WindowLogoutEventFilter filter; WindowLogoutEventFilter filter;
app.installNativeEventFilter(&filter); app.installNativeEventFilter(&filter);
#endif #endif
if (tempFile.isOpen()) {
tempFile.close();
tempFile.remove(); tempFile.remove();
}
int retCode = app.exec(); int retCode = app.exec();
QString configDir = pSettings->dirs().config(); QString configDir = pSettings->dirs().config();
// save settings // save settings

View File

@ -299,7 +299,7 @@ MainWindow::MainWindow(QWidget *parent)
mFileSystemModel.setNameFilters(pSystemConsts->defaultFileNameFilters()); mFileSystemModel.setNameFilters(pSystemConsts->defaultFileNameFilters());
mFileSystemModel.setNameFilterDisables(false); mFileSystemModel.setNameFilterDisables(false);
setFilesViewRoot(pSettings->environment().currentFolder()); //setFilesViewRoot(pSettings->environment().currentFolder());
for (int i=1;i<mFileSystemModel.columnCount();i++) { for (int i=1;i<mFileSystemModel.columnCount();i++) {
ui->treeFiles->hideColumn(i); ui->treeFiles->hideColumn(i);
} }
@ -674,7 +674,8 @@ void MainWindow::applySettings()
//icon sets for files view //icon sets for files view
pIconsManager->updateFileSystemIcons(pSettings->environment().iconSet(),pointToPixel(pSettings->environment().interfaceFontSize())); 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;i<ui->cbFilesPath->count();i++) { // for (int i=0;i<ui->cbFilesPath->count();i++) {
// ui->cbFilesPath->setItemIcon(i,pIconsManager->getIcon(IconsManager::FILESYSTEM_GIT)); // ui->cbFilesPath->setItemIcon(i,pIconsManager->getIcon(IconsManager::FILESYSTEM_GIT));
// } // }
@ -1205,8 +1206,8 @@ void MainWindow::updateCompilerSet()
{ {
mCompilerSet->blockSignals(true); mCompilerSet->blockSignals(true);
mCompilerSet->clear(); mCompilerSet->clear();
for (size_t i=0;i<pSettings->compilerSets().list().size();i++) { for (size_t i=0;i<pSettings->compilerSets().size();i++) {
mCompilerSet->addItem(pSettings->compilerSets().list()[i]->name()); mCompilerSet->addItem(pSettings->compilerSets().getSet(i)->name());
} }
int index=pSettings->compilerSets().defaultIndex(); int index=pSettings->compilerSets().defaultIndex();
if (mProject) { if (mProject) {

View File

@ -120,6 +120,8 @@ public:
void showSearchPanel(bool showReplace = false); void showSearchPanel(bool showReplace = false);
void showCPUInfoDialog(); void showCPUInfoDialog();
void setFilesViewRoot(const QString& path, bool setOpenFolder=false);
void applySettings(); void applySettings();
void applyUISettings(); void applyUISettings();
QFileSystemWatcher* fileSystemWatcher(); QFileSystemWatcher* fileSystemWatcher();
@ -243,7 +245,6 @@ private:
void scanActiveProject(bool parse=false); void scanActiveProject(bool parse=false);
void includeOrSkipDirs(const QStringList& dirs, bool skip); void includeOrSkipDirs(const QStringList& dirs, bool skip);
void showSearchReplacePanel(bool show); void showSearchReplacePanel(bool show);
void setFilesViewRoot(const QString& path, bool setOpenFolder=false);
void clearIssues(); void clearIssues();
void doCompileRun(RunType runType); void doCompileRun(RunType runType);
void updateProblemCaseOutput(POJProblemCase problemCase); void updateProblemCaseOutput(POJProblemCase problemCase);

View File

@ -631,7 +631,7 @@ void Project::setCompilerOption(const QString &optionString, char value)
if (mOptions.compilerSet<0 || mOptions.compilerSet>=pSettings->compilerSets().size()) { if (mOptions.compilerSet<0 || mOptions.compilerSet>=pSettings->compilerSets().size()) {
return; return;
} }
std::shared_ptr<Settings::CompilerSet> compilerSet = pSettings->compilerSets().list()[mOptions.compilerSet]; std::shared_ptr<Settings::CompilerSet> compilerSet = pSettings->compilerSets().getSet(mOptions.compilerSet);
int optionIndex = compilerSet->findOptionIndex(optionString); int optionIndex = compilerSet->findOptionIndex(optionString);
// Does the option exist? // Does the option exist?
if (optionIndex>=0){ if (optionIndex>=0){

View File

@ -1442,6 +1442,10 @@ Settings::CompilerSet::CompilerSet(const QString& compilerFolder):
setUserInput(); setUserInput();
setDefines(); setDefines();
mFullLoaded = true;
} else {
mFullLoaded = false;
} }
setOptions(); setOptions();
} }
@ -1468,7 +1472,8 @@ Settings::CompilerSet::CompilerSet(const Settings::CompilerSet &set):
mUseCustomLinkParams(set.mUseCustomLinkParams), mUseCustomLinkParams(set.mUseCustomLinkParams),
mCustomCompileParams(set.mCustomCompileParams), mCustomCompileParams(set.mCustomCompileParams),
mCustomLinkParams(set.mCustomLinkParams), mCustomLinkParams(set.mCustomLinkParams),
mAutoAddCharsetParams(set.mAutoAddCharsetParams) mAutoAddCharsetParams(set.mAutoAddCharsetParams),
mFullLoaded(set.mFullLoaded)
{ {
// Executables, most are hardcoded // Executables, most are hardcoded
for (PCompilerOption pOption:set.mOptions) { for (PCompilerOption pOption:set.mOptions) {
@ -1738,16 +1743,31 @@ QStringList &Settings::CompilerSet::libDirs()
QStringList &Settings::CompilerSet::defaultCIncludeDirs() QStringList &Settings::CompilerSet::defaultCIncludeDirs()
{ {
if (!mFullLoaded && !binDirs().isEmpty()) {
mFullLoaded=true;
setDirectories(binDirs()[0]);
setDefines();
}
return mDefaultCIncludeDirs; return mDefaultCIncludeDirs;
} }
QStringList &Settings::CompilerSet::defaultCppIncludeDirs() QStringList &Settings::CompilerSet::defaultCppIncludeDirs()
{ {
if (!mFullLoaded && !binDirs().isEmpty()) {
mFullLoaded=true;
setDirectories(binDirs()[0]);
setDefines();
}
return mDefaultCppIncludeDirs; return mDefaultCppIncludeDirs;
} }
QStringList &Settings::CompilerSet::defaultLibDirs() QStringList &Settings::CompilerSet::defaultLibDirs()
{ {
if (!mFullLoaded && !binDirs().isEmpty()) {
mFullLoaded=true;
setDirectories(binDirs()[0]);
setDefines();
}
return mLibDirs; return mLibDirs;
} }
@ -1791,8 +1811,13 @@ void Settings::CompilerSet::setName(const QString &value)
mName = 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; return mDefines;
} }
@ -2724,11 +2749,6 @@ void Settings::CompilerSets::deleteSet(int index)
saveSets(); saveSets();
} }
Settings::CompilerSetList &Settings::CompilerSets::list()
{
return mList;
}
int Settings::CompilerSets::size() const int Settings::CompilerSets::size() const
{ {
return mList.size(); return mList.size();
@ -2901,8 +2921,9 @@ Settings::PCompilerSet Settings::CompilerSets::loadSet(int index)
if (pSet->binDirs().isEmpty()) if (pSet->binDirs().isEmpty())
return PCompilerSet(); return PCompilerSet();
pSet->setDirectories(pSet->binDirs()[0]);
pSet->setDefines(); //pSet->setDirectories(pSet->binDirs()[0]);
//pSet->setDefines();
return pSet; return pSet;
} }

View File

@ -1210,7 +1210,7 @@ public:
void setType(const QString& value); void setType(const QString& value);
const QString& name() const; const QString& name() const;
void setName(const QString& value); void setName(const QString& value);
const QStringList& defines() const; const QStringList& defines();
const QString& target() const; const QString& target() const;
void setTarget(const QString& value); void setTarget(const QString& value);
@ -1261,6 +1261,7 @@ public:
QByteArray getCompilerOutput(const QString& binDir, const QString& binFile, QByteArray getCompilerOutput(const QString& binDir, const QString& binFile,
const QStringList& arguments); const QStringList& arguments);
private: private:
bool mFullLoaded;
// Executables, most are hardcoded // Executables, most are hardcoded
QString mCCompiler; QString mCCompiler;
QString mCppCompiler; QString mCppCompiler;
@ -1320,8 +1321,6 @@ public:
void saveDefaultIndex(); void saveDefaultIndex();
void deleteSet(int index); void deleteSet(int index);
void saveSet(int index); void saveSet(int index);
//properties
CompilerSetList& list();
int size() const; int size() const;
int defaultIndex() const; int defaultIndex() const;
void setDefaultIndex(int value); void setDefaultIndex(int value);

View File

@ -167,7 +167,7 @@ void CompilerSetOptionWidget::doLoad()
{ {
disconnectInputs(); disconnectInputs();
ui->cbCompilerSet->clear(); ui->cbCompilerSet->clear();
if (pSettings->compilerSets().list().size()<=0) { if (pSettings->compilerSets().size()<=0) {
ui->btnRenameCompilerSet->setEnabled(false); ui->btnRenameCompilerSet->setEnabled(false);
ui->btnRemoveCompilerSet->setEnabled(false); ui->btnRemoveCompilerSet->setEnabled(false);
return; return;
@ -176,8 +176,8 @@ void CompilerSetOptionWidget::doLoad()
ui->btnRemoveCompilerSet->setEnabled(true); ui->btnRemoveCompilerSet->setEnabled(true);
} }
int index=pSettings->compilerSets().defaultIndex(); int index=pSettings->compilerSets().defaultIndex();
for (int i=0;i<pSettings->compilerSets().list().size();i++) { for (int i=0;i<pSettings->compilerSets().size();i++) {
ui->cbCompilerSet->addItem(pSettings->compilerSets().list()[i]->name()); ui->cbCompilerSet->addItem(pSettings->compilerSets().getSet(i)->name());
} }
if (index < 0 || index>=ui->cbCompilerSet->count()) { if (index < 0 || index>=ui->cbCompilerSet->count()) {
index = 0; index = 0;
@ -189,7 +189,7 @@ void CompilerSetOptionWidget::doLoad()
void CompilerSetOptionWidget::doSave() void CompilerSetOptionWidget::doSave()
{ {
if (pSettings->compilerSets().list().size()>0) { if (pSettings->compilerSets().size()>0) {
saveCurrentCompilerSet(); saveCurrentCompilerSet();
} }
pSettings->compilerSets().saveSets(); pSettings->compilerSets().saveSets();
@ -296,7 +296,7 @@ void CompilerSetOptionWidget::on_btnAddBlankCompilerSet_pressed()
{ {
QString name = QInputDialog::getText(this,tr("Compiler Set Name"),tr("Name")); QString name = QInputDialog::getText(this,tr("Compiler Set Name"),tr("Name"));
pSettings->compilerSets().addSet(); pSettings->compilerSets().addSet();
pSettings->compilerSets().setDefaultIndex(pSettings->compilerSets().list().size()-1); pSettings->compilerSets().setDefaultIndex(pSettings->compilerSets().size()-1);
pSettings->compilerSets().defaultSet()->setName(name); pSettings->compilerSets().defaultSet()->setName(name);
doLoad(); doLoad();
} }

View File

@ -145,8 +145,8 @@ void ProjectCompilerWidget::doSave()
void ProjectCompilerWidget::init() void ProjectCompilerWidget::init()
{ {
ui->cbCompilerSet->clear(); ui->cbCompilerSet->clear();
for (const Settings::PCompilerSet& set:pSettings->compilerSets().list()){ for (int i=0;i<pSettings->compilerSets().size();i++) {
ui->cbCompilerSet->addItem(set->name()); ui->cbCompilerSet->addItem(pSettings->compilerSets().getSet(i)->name());
} }
SettingsWidget::init(); SettingsWidget::init();
} }

View File

@ -35,7 +35,8 @@ void GitManager::createRepository(const QString &folder)
bool GitManager::hasRepository(const QString &folder, QString& currentBranch) bool GitManager::hasRepository(const QString &folder, QString& currentBranch)
{ {
if (folder.isEmpty())
return false;
QStringList args; QStringList args;
args.append("status"); args.append("status");
args.append("-b"); args.append("-b");

View File

@ -77,13 +77,16 @@ bool GitRepository::revert(QString& output)
void GitRepository::setFolder(const QString &newFolder) void GitRepository::setFolder(const QString &newFolder)
{ {
mFolder = newFolder; mFolder = newFolder;
if (!newFolder.isEmpty())
mRealFolder = mManager->rootFolder(mFolder); mRealFolder = mManager->rootFolder(mFolder);
else
mRealFolder = newFolder;
update(); update();
} }
void GitRepository::update() void GitRepository::update()
{ {
if (!mManager->isValid()) { if (!mManager->isValid() || mFolder.isEmpty()) {
mInRepository = false; mInRepository = false;
mBranch = ""; mBranch = "";
mFilesInRepositories.clear(); mFilesInRepositories.clear();

View File

@ -60,6 +60,7 @@ void SearchDialog::find(const QString &text)
mTabBar->setCurrentIndex(0); mTabBar->setCurrentIndex(0);
} }
ui->cbFind->setCurrentText(text); ui->cbFind->setCurrentText(text);
ui->cbFind->setFocus();
show(); show();
} }
@ -81,6 +82,7 @@ void SearchDialog::findInFiles(const QString &text)
{ {
mTabBar->setCurrentIndex(2); mTabBar->setCurrentIndex(2);
ui->cbFind->setCurrentText(text); ui->cbFind->setCurrentText(text);
ui->cbFind->setFocus();
show(); show();
} }
@ -89,6 +91,8 @@ void SearchDialog::findInFiles(const QString &keyword, SearchFileScope scope, Sy
mTabBar->setCurrentIndex(1); mTabBar->setCurrentIndex(1);
ui->cbFind->setCurrentText(keyword); ui->cbFind->setCurrentText(keyword);
ui->cbFind->setFocus();
switch(scope) { switch(scope) {
case SearchFileScope::currentFile: case SearchFileScope::currentFile:
ui->rbCurrentFile->setChecked(true); ui->rbCurrentFile->setChecked(true);
@ -114,6 +118,7 @@ void SearchDialog::replace(const QString &sFind, const QString &sReplace)
mTabBar->setCurrentIndex(1); mTabBar->setCurrentIndex(1);
ui->cbFind->setCurrentText(sFind); ui->cbFind->setCurrentText(sFind);
ui->cbReplace->setCurrentText(sReplace); ui->cbReplace->setCurrentText(sReplace);
ui->cbFind->setFocus();
show(); show();
} }