From aadc8fd0f203c714413b9b9edec1d863d435884f Mon Sep 17 00:00:00 2001 From: Roy Qu Date: Fri, 21 Oct 2022 19:12:18 +0800 Subject: [PATCH] fix: crash when close editor that have issues --- RedPandaIDE/editor.cpp | 11 +---------- RedPandaIDE/editorlist.cpp | 19 ++++++++++++++++++- RedPandaIDE/editorlist.h | 1 + 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/RedPandaIDE/editor.cpp b/RedPandaIDE/editor.cpp index af986408..4843163b 100644 --- a/RedPandaIDE/editor.cpp +++ b/RedPandaIDE/editor.cpp @@ -194,14 +194,6 @@ Editor::Editor(QWidget *parent, const QString& filename, Editor::~Editor() { //qDebug()<<"editor "<fileSystemWatcher()->removePath(mFilename); - pMainWindow->caretList().removeEditor(this); - pMainWindow->updateCaretActions(); - int index = mParentPageControl->indexOf(this); - mParentPageControl->removeTab(index); - this->setParent(nullptr); - } } void Editor::loadFile(QString filename) { @@ -4359,8 +4351,7 @@ void Editor::checkSyntaxInBack() return; if (highlighter()->language()!=QSynedit::HighlighterLanguage::Cpp) return; - if(pSettings->editor().syntaxCheck()) - pMainWindow->checkSyntaxInBack(this); + pMainWindow->checkSyntaxInBack(this); } const PCppParser &Editor::parser() diff --git a/RedPandaIDE/editorlist.cpp b/RedPandaIDE/editorlist.cpp index a50d9a54..883d1fd5 100644 --- a/RedPandaIDE/editorlist.cpp +++ b/RedPandaIDE/editorlist.cpp @@ -113,6 +113,18 @@ void EditorList::showLayout(LayoutShowType layout) } } +void EditorList::doRemoveEditor(Editor *e) +{ + QTabWidget* parentPage=e->pageControl(); + int index = parentPage->indexOf(e); + parentPage->removeTab(index); + pMainWindow->fileSystemWatcher()->removePath(e->filename()); + pMainWindow->caretList().removeEditor(e); + pMainWindow->updateCaretActions(); + e->setParent(nullptr); + delete e; +} + void EditorList::onEditorRenamed(const QString &oldFilename, const QString &newFilename, bool firstSave) { emit editorRenamed(oldFilename, newFilename, firstSave); @@ -178,7 +190,7 @@ bool EditorList::closeEditor(Editor* editor, bool transferFocus, bool force) { if (pMainWindow->visitHistoryManager()->addFile(editor->filename())) { pMainWindow->rebuildOpenedFileHisotryMenu(); } - delete editor; + doRemoveEditor(editor); } updateLayout(); if (!force && transferFocus) { @@ -370,6 +382,7 @@ bool EditorList::closeAll(bool force) { void EditorList::forceCloseEditor(Editor *editor) { beginUpdate(); + doRemoveEditor(editor); delete editor; // Force layout update when creating, destroying or moving editors updateLayout(); @@ -385,6 +398,8 @@ Editor* EditorList::getOpenedEditorByFilename(QString filename) QString fullname = fileInfo.absoluteFilePath(); for (int i=0;icount();i++) { Editor* e = static_cast(mLeftPageWidget->widget(i)); + if (!e) + continue; if (e->filename().compare(filename, PATH_SENSITIVITY)==0 || e->filename().compare(fullname, PATH_SENSITIVITY)==0) { return e; @@ -392,6 +407,8 @@ Editor* EditorList::getOpenedEditorByFilename(QString filename) } for (int i=0;icount();i++) { Editor* e = static_cast(mRightPageWidget->widget(i)); + if (!e) + continue; if (e->filename().compare(filename)==0 || e->filename().compare(fullname)==0) { return e; } diff --git a/RedPandaIDE/editorlist.h b/RedPandaIDE/editorlist.h index d0e7f5d1..b546bd19 100644 --- a/RedPandaIDE/editorlist.h +++ b/RedPandaIDE/editorlist.h @@ -89,6 +89,7 @@ private: QTabWidget* getNewEditorPageControl() const; QTabWidget* getFocusedPageControl() const; void showLayout(LayoutShowType layout); + void doRemoveEditor(Editor* e); private slots: void onEditorRenamed(const QString& oldFilename, const QString& newFilename, bool firstSave); private: