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

View File

@ -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
if (tempFile.isOpen()) {
tempFile.close();
tempFile.remove();
}
int retCode = app.exec();
QString configDir = pSettings->dirs().config();
// save settings

View File

@ -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;i<mFileSystemModel.columnCount();i++) {
ui->treeFiles->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;i<ui->cbFilesPath->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;i<pSettings->compilerSets().list().size();i++) {
mCompilerSet->addItem(pSettings->compilerSets().list()[i]->name());
for (size_t i=0;i<pSettings->compilerSets().size();i++) {
mCompilerSet->addItem(pSettings->compilerSets().getSet(i)->name());
}
int index=pSettings->compilerSets().defaultIndex();
if (mProject) {

View File

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

View File

@ -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<Settings::CompilerSet> compilerSet = pSettings->compilerSets().list()[mOptions.compilerSet];
std::shared_ptr<Settings::CompilerSet> compilerSet = pSettings->compilerSets().getSet(mOptions.compilerSet);
int optionIndex = compilerSet->findOptionIndex(optionString);
// Does the option exist?
if (optionIndex>=0){

View File

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

View File

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

View File

@ -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;i<pSettings->compilerSets().list().size();i++) {
ui->cbCompilerSet->addItem(pSettings->compilerSets().list()[i]->name());
for (int i=0;i<pSettings->compilerSets().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();
}

View File

@ -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;i<pSettings->compilerSets().size();i++) {
ui->cbCompilerSet->addItem(pSettings->compilerSets().getSet(i)->name());
}
SettingsWidget::init();
}

View File

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

View File

@ -77,13 +77,16 @@ bool GitRepository::revert(QString& output)
void GitRepository::setFolder(const QString &newFolder)
{
mFolder = newFolder;
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();

View File

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