- enhancement: don't parse all openned files when start up

- enhancement: don't parse files when close all and exit
This commit is contained in:
Roy Qu 2022-08-24 17:05:16 +08:00
parent 3f37d1d9b6
commit 4df3ba4f14
10 changed files with 78 additions and 38 deletions

View File

@ -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 Red Panda C++ Version 1.2
- enhancement: Portuguese Translation ( Thanks for crcpucmg@github) - enhancement: Portuguese Translation ( Thanks for crcpucmg@github)

View File

@ -10,7 +10,7 @@ isEmpty(APP_NAME) {
} }
isEmpty(APP_VERSION) { isEmpty(APP_VERSION) {
APP_VERSION=1.2 APP_VERSION=1.3
} }
macos: { macos: {

View File

@ -1283,16 +1283,21 @@ void Editor::showEvent(QShowEvent */*event*/)
&& !inProject()) { && !inProject()) {
initParser(); initParser();
} }
if (mParser) { if (mParser && !pMainWindow->isClosingAll()
&& !pMainWindow->isQuitting()
&& !mParser->isFileParsed(mFilename)
) {
connect(mParser.get(), connect(mParser.get(),
&CppParser::onEndParsing, &CppParser::onEndParsing,
this, this,
&SynEdit::invalidate); &SynEdit::invalidate);
}
if (pSettings->codeCompletion().clearWhenEditorHidden()
&& !inProject()) {
reparse(); reparse();
} }
// if (pSettings->codeCompletion().clearWhenEditorHidden()
// && !inProject()) {
// reparse();
// }
reparseTodo(); reparseTodo();
setHideTime(QDateTime()); setHideTime(QDateTime());
} }
@ -1540,11 +1545,13 @@ void Editor::onStatusChanged(SynStatusChanges changes)
&& !changes.testFlag(SynStatusChange::scReadOnly) && !changes.testFlag(SynStatusChange::scReadOnly)
&& changes.testFlag(SynStatusChange::scCaretY))) { && changes.testFlag(SynStatusChange::scCaretY))) {
mCurrentLineModified = false; mCurrentLineModified = false;
if (pSettings->codeCompletion().clearWhenEditorHidden() if (!changes.testFlag(SynStatusChange::scOpenFile))
&& changes.testFlag(SynStatusChange::scOpenFile)) {
} else{
reparse(); reparse();
} // if (pSettings->codeCompletion().clearWhenEditorHidden()
// && changes.testFlag(SynStatusChange::scOpenFile)) {
// } else{
// reparse();
// }
if (pSettings->editor().syntaxCheckWhenLineChanged()) if (pSettings->editor().syntaxCheckWhenLineChanged())
checkSyntaxInBack(); checkSyntaxInBack();
reparseTodo(); reparseTodo();

View File

@ -164,10 +164,6 @@ bool EditorList::closeEditor(Editor* editor, bool transferFocus, bool force) {
} }
beginUpdate(); beginUpdate();
auto end = finally([this] {
this->endUpdate();
});
// if (transferFocus && (editor->pageControl()->currentWidget()==editor)) { // if (transferFocus && (editor->pageControl()->currentWidget()==editor)) {
// //todo: activate & focus the previous editor // //todo: activate & focus the previous editor
// } // }
@ -184,14 +180,17 @@ bool EditorList::closeEditor(Editor* editor, bool transferFocus, bool force) {
delete editor; delete editor;
} }
updateLayout(); updateLayout();
if (!force) { if (!force && transferFocus) {
editor = getEditor(); editor = getEditor();
if (transferFocus && editor) if (editor) {
editor->activate(); editor->activate();
else
pMainWindow->updateClassBrowserForEditor(editor); pMainWindow->updateClassBrowserForEditor(editor);
} else {
pMainWindow->updateClassBrowserForEditor(nullptr);
}
} }
emit editorClosed(); emit editorClosed();
endUpdate();
return true; return true;
} }

View File

@ -110,6 +110,7 @@ MainWindow::MainWindow(QWidget *parent)
mCheckSyntaxInBack(false), mCheckSyntaxInBack(false),
mShouldRemoveAllSettings(false), mShouldRemoveAllSettings(false),
mClosing(false), mClosing(false),
mClosingAll(false),
mOpenningFiles(false), mOpenningFiles(false),
mSystemTurnedOff(false) mSystemTurnedOff(false)
{ {
@ -877,7 +878,7 @@ void MainWindow::onFileSaved(const QString &path, bool inProject)
ui->treeFiles->update(index); ui->treeFiles->update(index);
} }
} }
pMainWindow->updateForEncodingInfo(); //updateForEncodingInfo();
} }
void MainWindow::updateAppTitle() void MainWindow::updateAppTitle()
@ -1160,17 +1161,25 @@ void MainWindow::openFiles(const QStringList &files)
} }
} }
//Didn't find a project? Open all files //Didn't find a project? Open all files
for (const QString& file:files) { for (int i=0;i<files.length()-1;i++) {
openFile(file); openFile(files[i],false);
}
if (files.length()>0) {
openFile(files.last(),true);
} }
mEditorList->endUpdate(); 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); Editor* editor = mEditorList->getOpenedEditorByFilename(filename);
if (editor!=nullptr) { if (editor!=nullptr) {
if (activate) {
editor->activate(); editor->activate();
}
return; return;
} }
try { try {
@ -1187,8 +1196,10 @@ void MainWindow::openFile(const QString &filename, QTabWidget* page)
// if (mProject) { // if (mProject) {
// mProject->associateEditorToUnit(editor,unit); // mProject->associateEditorToUnit(editor,unit);
// } // }
if (activate) {
editor->activate(); editor->activate();
this->updateForEncodingInfo(); }
// editor->activate();
} catch (FileError e) { } catch (FileError e) {
QMessageBox::critical(this,tr("Error"),e.reason()); QMessageBox::critical(this,tr("Error"),e.reason());
} }
@ -1263,7 +1274,7 @@ void MainWindow::openProject(const QString &filename, bool openFiles)
updateCompilerSet(); updateCompilerSet();
updateClassBrowserForEditor(e); updateClassBrowserForEditor(e);
} }
updateForEncodingInfo(); //updateForEncodingInfo();
} }
void MainWindow::changeOptions(const QString &widgetName, const QString &groupName) void MainWindow::changeOptions(const QString &widgetName, const QString &groupName)
@ -2230,7 +2241,7 @@ void MainWindow::loadLastOpens()
} }
if (count>0) { if (count>0) {
updateEditorActions(); updateEditorActions();
updateForEncodingInfo(); //updateForEncodingInfo();
} }
if (focusedEditor) if (focusedEditor)
focusedEditor->activate(); focusedEditor->activate();
@ -2298,7 +2309,7 @@ void MainWindow::newEditor()
pSettings->editor().defaultEncoding(), pSettings->editor().defaultEncoding(),
false,true); false,true);
editor->activate(); editor->activate();
updateForEncodingInfo(); //updateForEncodingInfo();
} catch (FileError e) { } catch (FileError e) {
QMessageBox::critical(this,tr("Error"),e.reason()); QMessageBox::critical(this,tr("Error"),e.reason());
} }
@ -4510,11 +4521,14 @@ void MainWindow::closeEvent(QCloseEvent *event) {
} }
} }
mClosingAll=true;
if (!mEditorList->closeAll(false)) { if (!mEditorList->closeAll(false)) {
mClosingAll=false;
mQuitting = false; mQuitting = false;
event->ignore(); event->ignore();
return ; return ;
} }
mClosingAll=false;
if (!mShouldRemoveAllSettings && pSettings->editor().autoLoadLastFiles()) { if (!mShouldRemoveAllSettings && pSettings->editor().autoLoadLastFiles()) {
if (mProject) { if (mProject) {
@ -5542,9 +5556,11 @@ void MainWindow::on_actionClose_triggered()
void MainWindow::on_actionClose_All_triggered() void MainWindow::on_actionClose_All_triggered()
{ {
mClosingAll=true;
mClosing = true; mClosing = true;
mEditorList->closeAll(mSystemTurnedOff); mEditorList->closeAll(mSystemTurnedOff);
mClosing = false; 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;
}

View File

@ -190,7 +190,7 @@ public:
const PBookmarkModel &bookmarkModel() const; 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 openProject(const QString& filename, bool openFiles = true);
void changeOptions(const QString& widgetName=QString(), const QString& groupName=QString()); void changeOptions(const QString& widgetName=QString(), const QString& groupName=QString());
@ -759,6 +759,7 @@ private:
CaretList mCaretList; CaretList mCaretList;
bool mClosing; bool mClosing;
bool mClosingAll;
bool mOpenningFiles; bool mOpenningFiles;
bool mSystemTurnedOff; bool mSystemTurnedOff;
QPoint mEditorContextMenuPos; QPoint mEditorContextMenuPos;
@ -844,6 +845,8 @@ protected:
// QObject interface // QObject interface
public: public:
bool event(QEvent *event) override; bool event(QEvent *event) override;
bool isClosingAll() const;
bool isQuitting() const;
}; };
extern MainWindow* pMainWindow; extern MainWindow* pMainWindow;

View File

@ -959,6 +959,11 @@ QSet<QString> CppParser::scannedFiles()
return mPreprocessor.scannedFiles(); return mPreprocessor.scannedFiles();
} }
bool CppParser::isFileParsed(const QString &filename)
{
return mPreprocessor.scannedFiles().contains(filename);
}
QString CppParser::getScopePrefix(const PStatement& statement){ QString CppParser::getScopePrefix(const PStatement& statement){
switch (statement->classScope) { switch (statement->classScope) {
case StatementClassScope::scsPublic: case StatementClassScope::scsPublic:

View File

@ -112,6 +112,8 @@ public:
void unFreeze(); // UnFree/UnLock (reparse while searching) void unFreeze(); // UnFree/UnLock (reparse while searching)
QSet<QString> scannedFiles(); QSet<QString> scannedFiles();
bool isFileParsed(const QString& filename);
QString prettyPrintStatement(const PStatement& statement, const QString& filename, int line = -1); QString prettyPrintStatement(const PStatement& statement, const QString& filename, int line = -1);
bool enabled() const; bool enabled() const;

View File

@ -31,21 +31,14 @@ EditorsTabWidget::EditorsTabWidget(QWidget* parent):QTabWidget(parent)
void EditorsTabWidget::dropEvent(QDropEvent *event) void EditorsTabWidget::dropEvent(QDropEvent *event)
{ {
if (event->mimeData()->hasUrls()) { if (event->mimeData()->hasUrls()) {
QStringList files;
foreach(const QUrl& url, event->mimeData()->urls()){ foreach(const QUrl& url, event->mimeData()->urls()){
if (!url.isLocalFile()) if (!url.isLocalFile())
continue; continue;
QString file = url.toLocalFile(); QString file = url.toLocalFile();
if (getFileType(file)==FileType::Project) { files.append(file);
pMainWindow->openProject(file);
return;
}
}
foreach(const QUrl& url, event->mimeData()->urls()){
if (!url.isLocalFile())
continue;
QString file = url.toLocalFile();
pMainWindow->openFile(file,this);
} }
pMainWindow->openFiles(files);
} }
} }

View File

@ -23,7 +23,7 @@ SUBDIRS += \
APP_NAME = RedPandaCPP APP_NAME = RedPandaCPP
APP_VERSION = 1.2 APP_VERSION = 1.3
linux: { linux: {
isEmpty(PREFIX) { isEmpty(PREFIX) {