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() { Editor::~Editor() {
//qDebug()<<"editor "<<mFilename<<" deleted"; //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) { void Editor::loadFile(QString filename) {
@ -4359,7 +4351,6 @@ void Editor::checkSyntaxInBack()
return; return;
if (highlighter()->language()!=QSynedit::HighlighterLanguage::Cpp) if (highlighter()->language()!=QSynedit::HighlighterLanguage::Cpp)
return; return;
if(pSettings->editor().syntaxCheck())
pMainWindow->checkSyntaxInBack(this); pMainWindow->checkSyntaxInBack(this);
} }

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) void EditorList::onEditorRenamed(const QString &oldFilename, const QString &newFilename, bool firstSave)
{ {
emit editorRenamed(oldFilename, newFilename, 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())) { if (pMainWindow->visitHistoryManager()->addFile(editor->filename())) {
pMainWindow->rebuildOpenedFileHisotryMenu(); pMainWindow->rebuildOpenedFileHisotryMenu();
} }
delete editor; doRemoveEditor(editor);
} }
updateLayout(); updateLayout();
if (!force && transferFocus) { if (!force && transferFocus) {
@ -370,6 +382,7 @@ bool EditorList::closeAll(bool force) {
void EditorList::forceCloseEditor(Editor *editor) void EditorList::forceCloseEditor(Editor *editor)
{ {
beginUpdate(); beginUpdate();
doRemoveEditor(editor);
delete editor; delete editor;
// Force layout update when creating, destroying or moving editors // Force layout update when creating, destroying or moving editors
updateLayout(); updateLayout();
@ -385,6 +398,8 @@ Editor* EditorList::getOpenedEditorByFilename(QString filename)
QString fullname = fileInfo.absoluteFilePath(); QString fullname = fileInfo.absoluteFilePath();
for (int i=0;i<mLeftPageWidget->count();i++) { for (int i=0;i<mLeftPageWidget->count();i++) {
Editor* e = static_cast<Editor*>(mLeftPageWidget->widget(i)); Editor* e = static_cast<Editor*>(mLeftPageWidget->widget(i));
if (!e)
continue;
if (e->filename().compare(filename, PATH_SENSITIVITY)==0 || if (e->filename().compare(filename, PATH_SENSITIVITY)==0 ||
e->filename().compare(fullname, PATH_SENSITIVITY)==0) { e->filename().compare(fullname, PATH_SENSITIVITY)==0) {
return e; return e;
@ -392,6 +407,8 @@ Editor* EditorList::getOpenedEditorByFilename(QString filename)
} }
for (int i=0;i<mRightPageWidget->count();i++) { for (int i=0;i<mRightPageWidget->count();i++) {
Editor* e = static_cast<Editor*>(mRightPageWidget->widget(i)); Editor* e = static_cast<Editor*>(mRightPageWidget->widget(i));
if (!e)
continue;
if (e->filename().compare(filename)==0 || e->filename().compare(fullname)==0) { if (e->filename().compare(filename)==0 || e->filename().compare(fullname)==0) {
return e; return e;
} }

View File

@ -89,6 +89,7 @@ private:
QTabWidget* getNewEditorPageControl() const; QTabWidget* getNewEditorPageControl() const;
QTabWidget* getFocusedPageControl() const; QTabWidget* getFocusedPageControl() const;
void showLayout(LayoutShowType layout); void showLayout(LayoutShowType layout);
void doRemoveEditor(Editor* e);
private slots: private slots:
void onEditorRenamed(const QString& oldFilename, const QString& newFilename, bool firstSave); void onEditorRenamed(const QString& oldFilename, const QString& newFilename, bool firstSave);
private: private: