From 4df3ba4f148265e342abff6cfaed4492bf52e33d Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Wed, 24 Aug 2022 17:05:16 +0800 Subject: [PATCH] - enhancement: don't parse all openned files when start up - enhancement: don't parse files when close all and exit --- NEWS.md | 5 +++ RedPandaIDE/RedPandaIDE.pro | 2 +- RedPandaIDE/editor.cpp | 23 +++++++----- RedPandaIDE/editorlist.cpp | 13 ++++--- RedPandaIDE/mainwindow.cpp | 46 ++++++++++++++++++------ RedPandaIDE/mainwindow.h | 5 ++- RedPandaIDE/parser/cppparser.cpp | 5 +++ RedPandaIDE/parser/cppparser.h | 2 ++ RedPandaIDE/widgets/editorstabwidget.cpp | 13 ++----- Red_Panda_CPP.pro | 2 +- 10 files changed, 78 insertions(+), 38 deletions(-) diff --git a/NEWS.md b/NEWS.md index 1b5db1a4..7bb8d1d4 100644 --- a/NEWS.md +++ b/NEWS.md @@ -1,3 +1,8 @@ +Red Panda C++ Version 1.3 + + - enhancement: don't parse all openned files when start up + - enhancement: don't parse files when close all and exit + Red Panda C++ Version 1.2 - enhancement: Portuguese Translation ( Thanks for crcpucmg@github) diff --git a/RedPandaIDE/RedPandaIDE.pro b/RedPandaIDE/RedPandaIDE.pro index c8a3fb25..260da8be 100644 --- a/RedPandaIDE/RedPandaIDE.pro +++ b/RedPandaIDE/RedPandaIDE.pro @@ -10,7 +10,7 @@ isEmpty(APP_NAME) { } isEmpty(APP_VERSION) { - APP_VERSION=1.2 + APP_VERSION=1.3 } macos: { diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 3cf3b208..de501e66 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -1283,16 +1283,21 @@ void Editor::showEvent(QShowEvent */*event*/) && !inProject()) { initParser(); } - if (mParser) { + if (mParser && !pMainWindow->isClosingAll() + && !pMainWindow->isQuitting() + && !mParser->isFileParsed(mFilename) + ) { connect(mParser.get(), &CppParser::onEndParsing, this, &SynEdit::invalidate); - } - if (pSettings->codeCompletion().clearWhenEditorHidden() - && !inProject()) { reparse(); } + +// if (pSettings->codeCompletion().clearWhenEditorHidden() +// && !inProject()) { +// reparse(); +// } reparseTodo(); setHideTime(QDateTime()); } @@ -1540,11 +1545,13 @@ void Editor::onStatusChanged(SynStatusChanges changes) && !changes.testFlag(SynStatusChange::scReadOnly) && changes.testFlag(SynStatusChange::scCaretY))) { mCurrentLineModified = false; - if (pSettings->codeCompletion().clearWhenEditorHidden() - && changes.testFlag(SynStatusChange::scOpenFile)) { - } else{ + if (!changes.testFlag(SynStatusChange::scOpenFile)) reparse(); - } +// if (pSettings->codeCompletion().clearWhenEditorHidden() +// && changes.testFlag(SynStatusChange::scOpenFile)) { +// } else{ +// reparse(); +// } if (pSettings->editor().syntaxCheckWhenLineChanged()) checkSyntaxInBack(); reparseTodo(); diff --git a/RedPandaIDE/editorlist.cpp b/RedPandaIDE/editorlist.cpp index d54ae8a2..a626b4e7 100644 --- a/RedPandaIDE/editorlist.cpp +++ b/RedPandaIDE/editorlist.cpp @@ -164,10 +164,6 @@ bool EditorList::closeEditor(Editor* editor, bool transferFocus, bool force) { } beginUpdate(); - auto end = finally([this] { - this->endUpdate(); - }); - // if (transferFocus && (editor->pageControl()->currentWidget()==editor)) { // //todo: activate & focus the previous editor // } @@ -184,14 +180,17 @@ bool EditorList::closeEditor(Editor* editor, bool transferFocus, bool force) { delete editor; } updateLayout(); - if (!force) { + if (!force && transferFocus) { editor = getEditor(); - if (transferFocus && editor) + if (editor) { editor->activate(); - else pMainWindow->updateClassBrowserForEditor(editor); + } else { + pMainWindow->updateClassBrowserForEditor(nullptr); + } } emit editorClosed(); + endUpdate(); return true; } diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index a474be33..e78005ac 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -110,6 +110,7 @@ MainWindow::MainWindow(QWidget *parent) mCheckSyntaxInBack(false), mShouldRemoveAllSettings(false), mClosing(false), + mClosingAll(false), mOpenningFiles(false), mSystemTurnedOff(false) { @@ -877,7 +878,7 @@ void MainWindow::onFileSaved(const QString &path, bool inProject) ui->treeFiles->update(index); } } - pMainWindow->updateForEncodingInfo(); + //updateForEncodingInfo(); } void MainWindow::updateAppTitle() @@ -1160,17 +1161,25 @@ void MainWindow::openFiles(const QStringList &files) } } //Didn't find a project? Open all files - for (const QString& file:files) { - openFile(file); + for (int i=0;i0) { + openFile(files.last(),true); } mEditorList->endUpdate(); + Editor* e=mEditorList->getEditor(); + if (e) + e->activate(); } -void MainWindow::openFile(const QString &filename, QTabWidget* page) +void MainWindow::openFile(const QString &filename, bool activate, QTabWidget* page) { Editor* editor = mEditorList->getOpenedEditorByFilename(filename); if (editor!=nullptr) { - editor->activate(); + if (activate) { + editor->activate(); + } return; } try { @@ -1187,8 +1196,10 @@ void MainWindow::openFile(const QString &filename, QTabWidget* page) // if (mProject) { // mProject->associateEditorToUnit(editor,unit); // } - editor->activate(); - this->updateForEncodingInfo(); + if (activate) { + editor->activate(); + } +// editor->activate(); } catch (FileError e) { QMessageBox::critical(this,tr("Error"),e.reason()); } @@ -1263,7 +1274,7 @@ void MainWindow::openProject(const QString &filename, bool openFiles) updateCompilerSet(); updateClassBrowserForEditor(e); } - updateForEncodingInfo(); + //updateForEncodingInfo(); } void MainWindow::changeOptions(const QString &widgetName, const QString &groupName) @@ -2230,7 +2241,7 @@ void MainWindow::loadLastOpens() } if (count>0) { updateEditorActions(); - updateForEncodingInfo(); + //updateForEncodingInfo(); } if (focusedEditor) focusedEditor->activate(); @@ -2298,7 +2309,7 @@ void MainWindow::newEditor() pSettings->editor().defaultEncoding(), false,true); editor->activate(); - updateForEncodingInfo(); + //updateForEncodingInfo(); } catch (FileError e) { QMessageBox::critical(this,tr("Error"),e.reason()); } @@ -4510,11 +4521,14 @@ void MainWindow::closeEvent(QCloseEvent *event) { } } + mClosingAll=true; if (!mEditorList->closeAll(false)) { + mClosingAll=false; mQuitting = false; event->ignore(); return ; } + mClosingAll=false; if (!mShouldRemoveAllSettings && pSettings->editor().autoLoadLastFiles()) { if (mProject) { @@ -5542,9 +5556,11 @@ void MainWindow::on_actionClose_triggered() void MainWindow::on_actionClose_All_triggered() { + mClosingAll=true; mClosing = true; mEditorList->closeAll(mSystemTurnedOff); mClosing = false; + mClosingAll=false; } @@ -8089,3 +8105,13 @@ void MainWindow::on_actionNew_Template_triggered() } } +bool MainWindow::isQuitting() const +{ + return mQuitting; +} + +bool MainWindow::isClosingAll() const +{ + return mClosingAll; +} + diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index 8b383936..3cda6279 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -190,7 +190,7 @@ public: const PBookmarkModel &bookmarkModel() const; - void openFile(const QString& filename, QTabWidget* page=nullptr); + void openFile(const QString& filename, bool activate=true, QTabWidget* page=nullptr); void openProject(const QString& filename, bool openFiles = true); void changeOptions(const QString& widgetName=QString(), const QString& groupName=QString()); @@ -759,6 +759,7 @@ private: CaretList mCaretList; bool mClosing; + bool mClosingAll; bool mOpenningFiles; bool mSystemTurnedOff; QPoint mEditorContextMenuPos; @@ -844,6 +845,8 @@ protected: // QObject interface public: bool event(QEvent *event) override; + bool isClosingAll() const; + bool isQuitting() const; }; extern MainWindow* pMainWindow; diff --git a/RedPandaIDE/parser/cppparser.cpp b/RedPandaIDE/parser/cppparser.cpp index ffef086b..0e0b3ea0 100644 --- a/RedPandaIDE/parser/cppparser.cpp +++ b/RedPandaIDE/parser/cppparser.cpp @@ -959,6 +959,11 @@ QSet CppParser::scannedFiles() return mPreprocessor.scannedFiles(); } +bool CppParser::isFileParsed(const QString &filename) +{ + return mPreprocessor.scannedFiles().contains(filename); +} + QString CppParser::getScopePrefix(const PStatement& statement){ switch (statement->classScope) { case StatementClassScope::scsPublic: diff --git a/RedPandaIDE/parser/cppparser.h b/RedPandaIDE/parser/cppparser.h index c8e9f727..36e9f1ba 100644 --- a/RedPandaIDE/parser/cppparser.h +++ b/RedPandaIDE/parser/cppparser.h @@ -112,6 +112,8 @@ public: void unFreeze(); // UnFree/UnLock (reparse while searching) QSet scannedFiles(); + bool isFileParsed(const QString& filename); + QString prettyPrintStatement(const PStatement& statement, const QString& filename, int line = -1); bool enabled() const; diff --git a/RedPandaIDE/widgets/editorstabwidget.cpp b/RedPandaIDE/widgets/editorstabwidget.cpp index f1aed1fd..22e94a4e 100644 --- a/RedPandaIDE/widgets/editorstabwidget.cpp +++ b/RedPandaIDE/widgets/editorstabwidget.cpp @@ -31,21 +31,14 @@ EditorsTabWidget::EditorsTabWidget(QWidget* parent):QTabWidget(parent) void EditorsTabWidget::dropEvent(QDropEvent *event) { if (event->mimeData()->hasUrls()) { + QStringList files; foreach(const QUrl& url, event->mimeData()->urls()){ if (!url.isLocalFile()) continue; QString file = url.toLocalFile(); - if (getFileType(file)==FileType::Project) { - pMainWindow->openProject(file); - return; - } - } - foreach(const QUrl& url, event->mimeData()->urls()){ - if (!url.isLocalFile()) - continue; - QString file = url.toLocalFile(); - pMainWindow->openFile(file,this); + files.append(file); } + pMainWindow->openFiles(files); } } diff --git a/Red_Panda_CPP.pro b/Red_Panda_CPP.pro index 2da0d2bd..123ca3b0 100644 --- a/Red_Panda_CPP.pro +++ b/Red_Panda_CPP.pro @@ -23,7 +23,7 @@ SUBDIRS += \ APP_NAME = RedPandaCPP -APP_VERSION = 1.2 +APP_VERSION = 1.3 linux: { isEmpty(PREFIX) {