diff --git a/NEWS.md b/NEWS.md index f285ed7d..a0569d15 100644 --- a/NEWS.md +++ b/NEWS.md @@ -10,6 +10,7 @@ Red Panda C++ Version 2.8 - enhancement: "Switch Header/Source" in editor title bar context menu. - enhancement: "Toggle readonly" in the Edit menu. - fix: Error When save project units' encoding settings. + - enhancement: Waiting for syntax parsers to finish before saving files, to prevent data lost caused by syntax parsering crash. Red Panda C++ Version 2.7 diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index 73c2a453..d1415895 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -260,6 +260,9 @@ bool Editor::save(bool force, bool doReparse) { if (this->mIsNew && !force) { return saveAs(); } + while (pMainWindow->parsing()) { + QThread::msleep(200); + } //is this file writable; pMainWindow->fileSystemWatcher()->removePath(mFilename); try { diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index f055e637..f94b1d58 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -519,6 +519,9 @@ void MainWindow::updateEditorActions() void MainWindow::updateEditorActions(const Editor *e) { + //it's not a compile action, but put here for convinience + ui->actionSaveAll->setEnabled( + (mProject!=nullptr || mEditorList->pageCount()>0)); if (e==nullptr) { ui->actionAuto_Detect->setEnabled(false); ui->actionEncode_in_ANSI->setEnabled(false); @@ -659,7 +662,9 @@ void MainWindow::updateCompileActions() { void MainWindow::updateCompileActions(const Editor *e) { - if (mCompilerManager->compiling() || mCompilerManager->running() || mDebugger->executing()) { + if (mCompilerManager->compiling() + //|| mCompilerManager->backgroundSyntaxChecking() + || mCompilerManager->running() || mDebugger->executing()) { ui->actionCompile->setEnabled(false); ui->actionCompile_Run->setEnabled(false); ui->actionRun->setEnabled(false); @@ -712,9 +717,7 @@ void MainWindow::updateCompileActions(const Editor *e) } ui->actionStop_Execution->setEnabled(mCompilerManager->running() || mDebugger->executing()); - //it's not a compile action, but put here for convinience - ui->actionSaveAll->setEnabled(mProject!=nullptr - || mEditorList->pageCount()>0); + } void MainWindow::updateEditorColorSchemes() @@ -1850,6 +1853,24 @@ void MainWindow::checkSyntaxInBack(Editor *e) } } +bool MainWindow::compiling() +{ + return (mCompilerManager->backgroundSyntaxChecking()) || (mCompilerManager->compiling()); +} + +bool MainWindow::parsing() +{ + if (mProject && mProject->cppParser() && mProject->cppParser()->parsing()) + return true; + for(int i=0;ipageCount();i++) { + Editor * editor = (*mEditorList)[i]; + if (editor->parser() && editor->parser()->parsing()) + return true; + } + return false; +} + + bool MainWindow::compile(bool rebuild, CppCompileType compileType) { mCompilerManager->stopPausing(); diff --git a/RedPandaIDE/mainwindow.h b/RedPandaIDE/mainwindow.h index 4621fbc1..ee5092dc 100644 --- a/RedPandaIDE/mainwindow.h +++ b/RedPandaIDE/mainwindow.h @@ -131,6 +131,8 @@ public: void updateDebuggerSettings(); void updateActionIcons(); void checkSyntaxInBack(Editor* e); + bool compiling(); + bool parsing(); bool compile(bool rebuild=false, CppCompileType compileType=CppCompileType::Normal); void runExecutable( const QString& exeName,