fix: crash when close editor that have issues

This commit is contained in:
Roy Qu 2022-10-21 19:12:18 +08:00
parent 411c740d24
commit aadc8fd0f2
3 changed files with 20 additions and 11 deletions

View File

@ -194,14 +194,6 @@ Editor::Editor(QWidget *parent, const QString& filename,
Editor::~Editor() {
//qDebug()<<"editor "<<mFilename<<" deleted";
if (mParentPageControl) {
pMainWindow->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()

View File

@ -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;i<mLeftPageWidget->count();i++) {
Editor* e = static_cast<Editor*>(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;i<mRightPageWidget->count();i++) {
Editor* e = static_cast<Editor*>(mRightPageWidget->widget(i));
if (!e)
continue;
if (e->filename().compare(filename)==0 || e->filename().compare(fullname)==0) {
return e;
}

View File

@ -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: