From b2e88c4c00c31bddeecffd1b64ef60a9c9752873 Mon Sep 17 00:00:00 2001 From: royqh1979 Date: Mon, 25 Oct 2021 00:30:53 +0800 Subject: [PATCH] - fix: crash when create an empty project --- NEWS.md | 1 + RedPandaIDE/editor.cpp | 10 ++++++++++ RedPandaIDE/editor.h | 3 +++ RedPandaIDE/mainwindow.cpp | 4 +++- RedPandaIDE/project.cpp | 10 ++++++++-- 5 files changed, 25 insertions(+), 3 deletions(-) diff --git a/NEWS.md b/NEWS.md index 2945c93e..44d691da 100644 --- a/NEWS.md +++ b/NEWS.md @@ -9,6 +9,7 @@ Version 0.7.3 - fix: syntax issues not correctly cleared when the file was saved as another name. - enhancement: when running a program, redirect a data file to its stdin - fix: can't correctly handle '&&' and '||' in the #if directive (and correctly parse windows.h header file) + - fix: crash when create an empty project Version 0.7.2 - fix: rainbow parenthesis stop functioning when change editor's general options diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index dcc0cc35..cd20d4f8 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -3114,6 +3114,16 @@ void Editor::onExportedFormatToken(PSynHighlighter syntaxHighlighter, int Line, } } +bool Editor::useCppSyntax() const +{ + return mUseCppSyntax; +} + +void Editor::setUseCppSyntax(bool newUseCppSyntax) +{ + mUseCppSyntax = newUseCppSyntax; +} + void Editor::setInProject(bool newInProject) { if (mInProject == newInProject) diff --git a/RedPandaIDE/editor.h b/RedPandaIDE/editor.h index 9f841247..147d24e0 100644 --- a/RedPandaIDE/editor.h +++ b/RedPandaIDE/editor.h @@ -299,6 +299,9 @@ public: // QWidget interface void setInProject(bool newInProject); + bool useCppSyntax() const; + void setUseCppSyntax(bool newUseCppSyntax); + protected: void mouseReleaseEvent(QMouseEvent *event) override; diff --git a/RedPandaIDE/mainwindow.cpp b/RedPandaIDE/mainwindow.cpp index 10a24607..b69387d8 100644 --- a/RedPandaIDE/mainwindow.cpp +++ b/RedPandaIDE/mainwindow.cpp @@ -4169,6 +4169,7 @@ void MainWindow::on_actionNew_Project_triggered() tr("Can't assign project template"), QMessageBox::Ok); } + mProject->options().useGPP = dialog.isCppProject(); mProject->saveAll(); updateProjectView(); } @@ -4209,11 +4210,12 @@ void MainWindow::on_actionProject_New_File_triggered() node = static_cast(current.internalPointer()); } PProjectUnit newUnit = mProject->newUnit( - mProject->pointerToNode(node) ); + mProject->pointerToNode(node)); idx = mProject->units().count()-1; mProject->saveUnits(); updateProjectView(); Editor * editor = mProject->openUnit(idx); + editor->setUseCppSyntax(mProject->options().useGPP); editor->setModified(true); editor->activate(); } diff --git a/RedPandaIDE/project.cpp b/RedPandaIDE/project.cpp index d9a395ef..c3a56574 100644 --- a/RedPandaIDE/project.cpp +++ b/RedPandaIDE/project.cpp @@ -661,8 +661,14 @@ bool Project::assignTemplate(const std::shared_ptr aTemplate) true); QString s2 = QDir(pSettings->dirs().templateDir()).absoluteFilePath(s); - if (fileExists(s2)) { - editor->loadFile(s2); + if (fileExists(s2) && !s.isEmpty()) { + try { + editor->loadFile(s2); + } catch(FileError& e) { + QMessageBox::critical(pMainWindow, + tr("Error Load File"), + e.reason()); + } } else { s.replace("#13#10","\r\n"); editor->insertString(s,false);