Commit 7a8e9b3e authored by Jonathan Verner's avatar Jonathan Verner Committed by Milian Wolff
Browse files

Fix a crash when showing stash while patch review plugin is not loaded.

The stash manager (in the Git Plugin) lists available stashed patches. When
a user clicked on a stash item, the stash manager tried to use the patch
review plugin to show the stash item. However, it did not check that it
was actually loaded and this lead to a crash when the patch review plugin
was not enabled.

This commit tests whether the plugin is available. If not, it opens the
stashed patch as a plain diff document.
parent eee53758
......@@ -11,6 +11,7 @@
#include <interfaces/icore.h>
#include <interfaces/iruncontroller.h>
#include <interfaces/iplugincontroller.h>
#include <interfaces/idocumentcontroller.h>
#include <vcs/dvcs/dvcsjob.h>
#include <QDialogButtonBox>
......@@ -19,6 +20,7 @@
#include <KLocalizedString>
#include <KMessageBox>
#include <KTextEditor/Document>
using namespace KDevelop;
......@@ -77,10 +79,26 @@ void StashManagerDialog::runStash(const QStringList& arguments)
void StashManagerDialog::showStash()
{
auto * review = ICore::self()->pluginController()->extensionForPlugin<IPatchReview>();
IPatchSource::Ptr stashPatch(new StashPatchSource(selection(), m_plugin, m_dir));
review->startReview(stashPatch);
if (auto * review = ICore::self()->pluginController()->extensionForPlugin<IPatchReview>()) {
review->startReview(stashPatch);
} else {
auto* docCtrl = ICore::self()->documentController();
connect(stashPatch, &StashPatchSource::patchChanged, docCtrl, [=] {
auto* doc = docCtrl->openDocument(
stashPatch->file(),
KTextEditor::Range::invalid(),
IDocumentController::DoNotAddToRecentOpen
);
doc->setPrettyName(stashPatch->name());
doc->textDocument()->setReadWrite(false);
doc->textDocument()->setMode(QStringLiteral("diff"));
doc->textDocument()->setHighlightingMode(QStringLiteral("diff"));
docCtrl->activateDocument(doc);
connect(ICore::self(), &ICore::aboutToShutdown, docCtrl, [=] {doc->close();});
});
}
accept();
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment