forked from qt-creator/qt-creator
Editors: Fix crash after triggering dropdown menu after closing editor
The context menu kept a handle on the editor and document, and these could be deleted behind its back. Use QPointers to actually check. Fixes: QTCREATORBUG-31232 Change-Id: I613abbe6dc0fbac60c2e527f715a7b8c2f083893 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -539,12 +539,12 @@ void EditorManagerPrivate::init()
|
||||
this, &EditorManagerPrivate::closeAllEditorsExceptVisible);
|
||||
|
||||
connect(m_openGraphicalShellContextAction, &QAction::triggered, this, [this] {
|
||||
if (!m_contextMenuEntry || m_contextMenuEntry->filePath().isEmpty())
|
||||
if (!m_contextMenuDocument || m_contextMenuEntry->filePath().isEmpty())
|
||||
return;
|
||||
FileUtils::showInGraphicalShell(ICore::dialogParent(), m_contextMenuEntry->filePath());
|
||||
});
|
||||
connect(m_showInFileSystemViewContextAction, &QAction::triggered, this, [this] {
|
||||
if (!m_contextMenuEntry || m_contextMenuEntry->filePath().isEmpty())
|
||||
if (!m_contextMenuDocument || m_contextMenuEntry->filePath().isEmpty())
|
||||
return;
|
||||
FileUtils::showInFileSystemView(m_contextMenuEntry->filePath());
|
||||
});
|
||||
@@ -552,7 +552,7 @@ void EditorManagerPrivate::init()
|
||||
connect(m_findInDirectoryAction, &QAction::triggered,
|
||||
this, &EditorManagerPrivate::findInDirectory);
|
||||
connect(m_filePropertiesAction, &QAction::triggered, this, [this] {
|
||||
if (!m_contextMenuEntry || m_contextMenuEntry->filePath().isEmpty())
|
||||
if (!m_contextMenuDocument || m_contextMenuEntry->filePath().isEmpty())
|
||||
return;
|
||||
DocumentManager::showFilePropertiesDialog(m_contextMenuEntry->filePath());
|
||||
});
|
||||
@@ -2402,14 +2402,14 @@ void EditorManagerPrivate::handleContextChange(const QList<IContext *> &context)
|
||||
|
||||
void EditorManagerPrivate::copyFilePathFromContextMenu()
|
||||
{
|
||||
if (!d->m_contextMenuEntry)
|
||||
if (!d->m_contextMenuDocument)
|
||||
return;
|
||||
setClipboardAndSelection(d->m_contextMenuEntry->filePath().toUserOutput());
|
||||
}
|
||||
|
||||
void EditorManagerPrivate::copyLocationFromContextMenu()
|
||||
{
|
||||
if (!d->m_contextMenuEntry)
|
||||
if (!d->m_contextMenuDocument)
|
||||
return;
|
||||
const QString text = d->m_contextMenuEntry->filePath().toUserOutput()
|
||||
+ QLatin1Char(':') + m_copyLocationContextAction->data().toString();
|
||||
@@ -2418,28 +2418,28 @@ void EditorManagerPrivate::copyLocationFromContextMenu()
|
||||
|
||||
void EditorManagerPrivate::copyFileNameFromContextMenu()
|
||||
{
|
||||
if (!d->m_contextMenuEntry)
|
||||
if (!d->m_contextMenuDocument)
|
||||
return;
|
||||
setClipboardAndSelection(d->m_contextMenuEntry->filePath().fileName());
|
||||
}
|
||||
|
||||
void EditorManagerPrivate::saveDocumentFromContextMenu()
|
||||
{
|
||||
IDocument *document = d->m_contextMenuEntry ? d->m_contextMenuEntry->document : nullptr;
|
||||
IDocument *document = d->m_contextMenuDocument.get();
|
||||
if (document)
|
||||
saveDocument(document);
|
||||
}
|
||||
|
||||
void EditorManagerPrivate::saveDocumentAsFromContextMenu()
|
||||
{
|
||||
IDocument *document = d->m_contextMenuEntry ? d->m_contextMenuEntry->document : nullptr;
|
||||
IDocument *document = d->m_contextMenuDocument.get();
|
||||
if (document)
|
||||
saveDocumentAs(document);
|
||||
}
|
||||
|
||||
void EditorManagerPrivate::revertToSavedFromContextMenu()
|
||||
{
|
||||
IDocument *document = d->m_contextMenuEntry ? d->m_contextMenuEntry->document : nullptr;
|
||||
IDocument *document = d->m_contextMenuDocument.get();
|
||||
if (document)
|
||||
revertToSaved(document);
|
||||
}
|
||||
@@ -2449,7 +2449,7 @@ void EditorManagerPrivate::closeEditorFromContextMenu()
|
||||
if (d->m_contextMenuEditor) {
|
||||
closeEditorOrDocument(d->m_contextMenuEditor);
|
||||
} else {
|
||||
IDocument *document = d->m_contextMenuEntry ? d->m_contextMenuEntry->document : nullptr;
|
||||
IDocument *document = d->m_contextMenuDocument.get();
|
||||
if (document)
|
||||
EditorManager::closeDocuments({document});
|
||||
}
|
||||
@@ -2457,7 +2457,7 @@ void EditorManagerPrivate::closeEditorFromContextMenu()
|
||||
|
||||
void EditorManagerPrivate::closeOtherDocumentsFromContextMenu()
|
||||
{
|
||||
IDocument *document = d->m_contextMenuEntry ? d->m_contextMenuEntry->document : nullptr;
|
||||
IDocument *document = d->m_contextMenuDocument.get();
|
||||
EditorManager::closeOtherDocuments(document);
|
||||
}
|
||||
|
||||
@@ -2613,14 +2613,14 @@ void EditorManagerPrivate::autoSuspendDocuments()
|
||||
|
||||
void EditorManagerPrivate::openTerminal()
|
||||
{
|
||||
if (!d->m_contextMenuEntry || d->m_contextMenuEntry->filePath().isEmpty())
|
||||
if (!d->m_contextMenuDocument || d->m_contextMenuEntry->filePath().isEmpty())
|
||||
return;
|
||||
FileUtils::openTerminal(d->m_contextMenuEntry->filePath().parentDir(), {});
|
||||
}
|
||||
|
||||
void EditorManagerPrivate::findInDirectory()
|
||||
{
|
||||
if (!d->m_contextMenuEntry || d->m_contextMenuEntry->filePath().isEmpty())
|
||||
if (!d->m_contextMenuDocument || d->m_contextMenuEntry->filePath().isEmpty())
|
||||
return;
|
||||
const FilePath path = d->m_contextMenuEntry->filePath();
|
||||
emit m_instance->findOnFileSystemRequest(
|
||||
@@ -2629,7 +2629,7 @@ void EditorManagerPrivate::findInDirectory()
|
||||
|
||||
void EditorManagerPrivate::togglePinned()
|
||||
{
|
||||
if (!d->m_contextMenuEntry || d->m_contextMenuEntry->filePath().isEmpty())
|
||||
if (!d->m_contextMenuDocument || d->m_contextMenuEntry->filePath().isEmpty())
|
||||
return;
|
||||
|
||||
const bool currentlyPinned = d->m_contextMenuEntry->pinned;
|
||||
@@ -2832,6 +2832,7 @@ void EditorManager::addSaveAndCloseEditorActions(QMenu *contextMenu, DocumentMod
|
||||
{
|
||||
QTC_ASSERT(contextMenu, return);
|
||||
d->m_contextMenuEntry = entry;
|
||||
d->m_contextMenuDocument = entry ? entry->document : nullptr;
|
||||
d->m_contextMenuEditor = editor;
|
||||
|
||||
const FilePath filePath = entry ? entry->filePath() : FilePath();
|
||||
@@ -2911,6 +2912,7 @@ void EditorManager::addNativeDirAndOpenWithActions(QMenu *contextMenu, DocumentM
|
||||
{
|
||||
QTC_ASSERT(contextMenu, return);
|
||||
d->m_contextMenuEntry = entry;
|
||||
d->m_contextMenuDocument = entry ? entry->document : nullptr;
|
||||
bool enabled = entry && !entry->filePath().isEmpty();
|
||||
d->m_openGraphicalShellContextAction->setEnabled(enabled);
|
||||
d->m_showInFileSystemViewContextAction->setEnabled(enabled);
|
||||
|
@@ -250,7 +250,8 @@ private:
|
||||
QAction *m_filePropertiesAction = nullptr;
|
||||
QAction *m_pinAction = nullptr;
|
||||
DocumentModel::Entry *m_contextMenuEntry = nullptr;
|
||||
IEditor *m_contextMenuEditor = nullptr;
|
||||
QPointer<IDocument> m_contextMenuDocument;
|
||||
QPointer<IEditor> m_contextMenuEditor;
|
||||
|
||||
OpenEditorsWindow *m_windowPopup = nullptr;
|
||||
|
||||
|
Reference in New Issue
Block a user