forked from qt-creator/qt-creator
VcsBaseDiffEditorController: Remove unused stuff
Change-Id: I34cc9dee686929fb69253ba16ff0fd5fed023ca1 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
// Copyright (C) 2016 The Qt Company Ltd.
|
// Copyright (C) 2016 The Qt Company Ltd.
|
||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
#include "diffeditorconstants.h"
|
|
||||||
#include "diffeditorcontroller.h"
|
#include "diffeditorcontroller.h"
|
||||||
|
|
||||||
|
#include "diffeditorconstants.h"
|
||||||
#include "diffeditordocument.h"
|
#include "diffeditordocument.h"
|
||||||
|
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
@@ -12,14 +13,12 @@
|
|||||||
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QStringList>
|
|
||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace DiffEditor {
|
namespace DiffEditor {
|
||||||
|
|
||||||
DiffEditorController::DiffEditorController(Core::IDocument *document)
|
DiffEditorController::DiffEditorController(IDocument *document)
|
||||||
: QObject(document)
|
: QObject(document)
|
||||||
, m_document(qobject_cast<Internal::DiffEditorDocument *>(document))
|
, m_document(qobject_cast<Internal::DiffEditorDocument *>(document))
|
||||||
, m_reloadRecipe{}
|
, m_reloadRecipe{}
|
||||||
@@ -62,16 +61,16 @@ QString DiffEditorController::makePatch(int fileIndex, int chunkIndex,
|
|||||||
options & AddPrefix);
|
options & AddPrefix);
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::IDocument *DiffEditorController::findOrCreateDocument(const QString &vcsId,
|
IDocument *DiffEditorController::findOrCreateDocument(const QString &vcsId,
|
||||||
const QString &displayName)
|
const QString &displayName)
|
||||||
{
|
{
|
||||||
QString preferredDisplayName = displayName;
|
QString preferredDisplayName = displayName;
|
||||||
Core::IEditor *editor = Core::EditorManager::openEditorWithContents(
|
IEditor *editor = EditorManager::openEditorWithContents(Constants::DIFF_EDITOR_ID,
|
||||||
Constants::DIFF_EDITOR_ID, &preferredDisplayName, {}, vcsId);
|
&preferredDisplayName, {}, vcsId);
|
||||||
return editor ? editor->document() : nullptr;
|
return editor ? editor->document() : nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
DiffEditorController *DiffEditorController::controller(Core::IDocument *document)
|
DiffEditorController *DiffEditorController::controller(IDocument *document)
|
||||||
{
|
{
|
||||||
auto doc = qobject_cast<Internal::DiffEditorDocument *>(document);
|
auto doc = qobject_cast<Internal::DiffEditorDocument *>(document);
|
||||||
return doc ? doc->controller() : nullptr;
|
return doc ? doc->controller() : nullptr;
|
||||||
@@ -110,7 +109,7 @@ void DiffEditorController::setReloader(const std::function<void ()> &reloader)
|
|||||||
m_reloader = reloader;
|
m_reloader = reloader;
|
||||||
}
|
}
|
||||||
|
|
||||||
Core::IDocument *DiffEditorController::document() const
|
IDocument *DiffEditorController::document() const
|
||||||
{
|
{
|
||||||
return m_document;
|
return m_document;
|
||||||
}
|
}
|
||||||
|
@@ -6,14 +6,16 @@
|
|||||||
#include "diffeditor_global.h"
|
#include "diffeditor_global.h"
|
||||||
#include "diffutils.h"
|
#include "diffutils.h"
|
||||||
|
|
||||||
#include <utils/filepath.h>
|
|
||||||
#include <utils/tasktree.h>
|
#include <utils/tasktree.h>
|
||||||
|
|
||||||
#include <QObject>
|
#include <QObject>
|
||||||
|
|
||||||
QT_FORWARD_DECLARE_CLASS(QMenu)
|
QT_BEGIN_NAMESPACE
|
||||||
|
class QMenu;
|
||||||
|
QT_END_NAMESPACE
|
||||||
|
|
||||||
namespace Core { class IDocument; }
|
namespace Core { class IDocument; }
|
||||||
|
namespace Utils { class FilePath; }
|
||||||
|
|
||||||
namespace DiffEditor {
|
namespace DiffEditor {
|
||||||
|
|
||||||
|
@@ -938,7 +938,6 @@ void GitClient::requestReload(const QString &documentId, const QString &source,
|
|||||||
GitBaseDiffEditorController *controller = factory(document);
|
GitBaseDiffEditorController *controller = factory(document);
|
||||||
QTC_ASSERT(controller, return);
|
QTC_ASSERT(controller, return);
|
||||||
controller->setVcsBinary(settings().gitExecutable());
|
controller->setVcsBinary(settings().gitExecutable());
|
||||||
controller->setVcsTimeoutS(settings().timeout.value());
|
|
||||||
controller->setProcessEnvironment(processEnvironment());
|
controller->setProcessEnvironment(processEnvironment());
|
||||||
controller->setWorkingDirectory(workingDirectory);
|
controller->setWorkingDirectory(workingDirectory);
|
||||||
|
|
||||||
|
@@ -427,7 +427,6 @@ void MercurialClient::requestReload(const QString &documentId, const QString &so
|
|||||||
QTC_ASSERT(document, return);
|
QTC_ASSERT(document, return);
|
||||||
auto controller = new MercurialDiffEditorController(document, args);
|
auto controller = new MercurialDiffEditorController(document, args);
|
||||||
controller->setVcsBinary(settings().binaryPath.filePath());
|
controller->setVcsBinary(settings().binaryPath.filePath());
|
||||||
controller->setVcsTimeoutS(settings().timeout.value());
|
|
||||||
controller->setProcessEnvironment(processEnvironment());
|
controller->setProcessEnvironment(processEnvironment());
|
||||||
controller->setWorkingDirectory(workingDirectory);
|
controller->setWorkingDirectory(workingDirectory);
|
||||||
|
|
||||||
|
@@ -246,7 +246,6 @@ SubversionDiffEditorController *SubversionClient::findOrCreateDiffEditor(const Q
|
|||||||
if (!controller) {
|
if (!controller) {
|
||||||
controller = new SubversionDiffEditorController(document, addAuthenticationOptions(settings));
|
controller = new SubversionDiffEditorController(document, addAuthenticationOptions(settings));
|
||||||
controller->setVcsBinary(settings.binaryPath.filePath());
|
controller->setVcsBinary(settings.binaryPath.filePath());
|
||||||
controller->setVcsTimeoutS(settings.timeout.value());
|
|
||||||
controller->setProcessEnvironment(processEnvironment());
|
controller->setProcessEnvironment(processEnvironment());
|
||||||
controller->setWorkingDirectory(workingDirectory);
|
controller->setWorkingDirectory(workingDirectory);
|
||||||
}
|
}
|
||||||
|
@@ -2,25 +2,15 @@
|
|||||||
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
||||||
|
|
||||||
#include "vcsbasediffeditorcontroller.h"
|
#include "vcsbasediffeditorcontroller.h"
|
||||||
#include "vcsbaseclient.h"
|
|
||||||
#include "vcscommand.h"
|
|
||||||
#include "vcsplugin.h"
|
#include "vcsplugin.h"
|
||||||
|
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
|
||||||
#include <coreplugin/progressmanager/progressmanager.h>
|
|
||||||
|
|
||||||
#include <utils/asynctask.h>
|
#include <utils/asynctask.h>
|
||||||
#include <utils/commandline.h>
|
|
||||||
#include <utils/environment.h>
|
#include <utils/environment.h>
|
||||||
#include <utils/futuresynchronizer.h>
|
#include <utils/futuresynchronizer.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/qtcprocess.h>
|
#include <utils/qtcprocess.h>
|
||||||
#include <utils/runextensions.h>
|
|
||||||
|
|
||||||
#include <QPointer>
|
|
||||||
|
|
||||||
using namespace DiffEditor;
|
using namespace DiffEditor;
|
||||||
using namespace Core;
|
|
||||||
using namespace Utils;
|
using namespace Utils;
|
||||||
|
|
||||||
namespace VcsBase {
|
namespace VcsBase {
|
||||||
@@ -38,92 +28,13 @@ class VcsBaseDiffEditorControllerPrivate
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
VcsBaseDiffEditorControllerPrivate(VcsBaseDiffEditorController *q) : q(q) {}
|
VcsBaseDiffEditorControllerPrivate(VcsBaseDiffEditorController *q) : q(q) {}
|
||||||
~VcsBaseDiffEditorControllerPrivate();
|
|
||||||
|
|
||||||
void processingFinished();
|
|
||||||
void processDiff(const QString &patch);
|
|
||||||
void cancelReload();
|
|
||||||
void commandFinished(bool success);
|
|
||||||
|
|
||||||
VcsBaseDiffEditorController *q;
|
VcsBaseDiffEditorController *q;
|
||||||
Environment m_processEnvironment;
|
Environment m_processEnvironment;
|
||||||
FilePath m_vcsBinary;
|
FilePath m_vcsBinary;
|
||||||
int m_vscTimeoutS;
|
|
||||||
QPointer<VcsCommand> m_command;
|
|
||||||
QFutureWatcher<QList<FileData>> *m_processWatcher = nullptr;
|
|
||||||
|
|
||||||
const Tasking::TreeStorage<QString> m_inputStorage;
|
const Tasking::TreeStorage<QString> m_inputStorage;
|
||||||
};
|
};
|
||||||
|
|
||||||
VcsBaseDiffEditorControllerPrivate::~VcsBaseDiffEditorControllerPrivate()
|
|
||||||
{
|
|
||||||
delete m_command;
|
|
||||||
cancelReload();
|
|
||||||
}
|
|
||||||
|
|
||||||
void VcsBaseDiffEditorControllerPrivate::processingFinished()
|
|
||||||
{
|
|
||||||
QTC_ASSERT(m_processWatcher, return);
|
|
||||||
|
|
||||||
// success is false when the user clicked the cancel micro button
|
|
||||||
// inside the progress indicator
|
|
||||||
const bool success = !m_processWatcher->future().isCanceled();
|
|
||||||
const QList<FileData> fileDataList = success
|
|
||||||
? m_processWatcher->future().result() : QList<FileData>();
|
|
||||||
|
|
||||||
// Prevent direct deletion of m_processWatcher since
|
|
||||||
// processingFinished() is called directly by the m_processWatcher.
|
|
||||||
m_processWatcher->deleteLater();
|
|
||||||
m_processWatcher = nullptr;
|
|
||||||
|
|
||||||
q->setDiffFiles(fileDataList);
|
|
||||||
q->reloadFinished(success);
|
|
||||||
}
|
|
||||||
|
|
||||||
void VcsBaseDiffEditorControllerPrivate::processDiff(const QString &patch)
|
|
||||||
{
|
|
||||||
cancelReload();
|
|
||||||
|
|
||||||
m_processWatcher = new QFutureWatcher<QList<FileData>>();
|
|
||||||
|
|
||||||
QObject::connect(m_processWatcher, &QFutureWatcherBase::finished,
|
|
||||||
q, [this] { processingFinished(); });
|
|
||||||
|
|
||||||
m_processWatcher->setFuture(Utils::runAsync(&readPatch, patch));
|
|
||||||
|
|
||||||
ProgressManager::addTask(m_processWatcher->future(),
|
|
||||||
VcsBaseDiffEditorController::tr("Processing diff"), "DiffEditor");
|
|
||||||
}
|
|
||||||
|
|
||||||
void VcsBaseDiffEditorControllerPrivate::cancelReload()
|
|
||||||
{
|
|
||||||
m_command.clear();
|
|
||||||
|
|
||||||
if (m_processWatcher) {
|
|
||||||
// Cancel the running process without the further processingFinished()
|
|
||||||
// notification for this process.
|
|
||||||
m_processWatcher->future().cancel();
|
|
||||||
delete m_processWatcher;
|
|
||||||
m_processWatcher = nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void VcsBaseDiffEditorControllerPrivate::commandFinished(bool success)
|
|
||||||
{
|
|
||||||
const QString output = m_command->cleanedStdOut();
|
|
||||||
// Don't delete here, as it is called from command finished signal.
|
|
||||||
// Clear it only, as we may call runCommand() again from inside processCommandOutput overload.
|
|
||||||
m_command.clear();
|
|
||||||
|
|
||||||
if (!success) {
|
|
||||||
cancelReload();
|
|
||||||
q->reloadFinished(success);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
q->processCommandOutput(output);
|
|
||||||
}
|
|
||||||
|
|
||||||
/////////////////////
|
/////////////////////
|
||||||
|
|
||||||
VcsBaseDiffEditorController::VcsBaseDiffEditorController(Core::IDocument *document)
|
VcsBaseDiffEditorController::VcsBaseDiffEditorController(Core::IDocument *document)
|
||||||
@@ -169,42 +80,6 @@ void VcsBaseDiffEditorController::setupCommand(QtcProcess &process, const QStrin
|
|||||||
process.setCommand({d->m_vcsBinary, args});
|
process.setCommand({d->m_vcsBinary, args});
|
||||||
}
|
}
|
||||||
|
|
||||||
void VcsBaseDiffEditorController::runCommand(const QList<QStringList> &args, RunFlags flags, QTextCodec *codec)
|
|
||||||
{
|
|
||||||
// Cancel the possible ongoing reload without the commandFinished() nor
|
|
||||||
// processingFinished() notifications, as right after that
|
|
||||||
// we re-reload it from scratch. So no intermediate "Retrieving data failed."
|
|
||||||
// and "Waiting for data..." will be shown.
|
|
||||||
delete d->m_command;
|
|
||||||
d->cancelReload();
|
|
||||||
|
|
||||||
d->m_command = VcsBaseClient::createVcsCommand(workingDirectory(), d->m_processEnvironment);
|
|
||||||
d->m_command->setDisplayName(displayName());
|
|
||||||
d->m_command->setCodec(codec ? codec : EditorManager::defaultTextCodec());
|
|
||||||
connect(d->m_command.data(), &VcsCommand::done, this, [this] {
|
|
||||||
d->commandFinished(d->m_command->result() == ProcessResult::FinishedWithSuccess);
|
|
||||||
});
|
|
||||||
d->m_command->addFlags(flags);
|
|
||||||
|
|
||||||
for (const QStringList &arg : args) {
|
|
||||||
QTC_ASSERT(!arg.isEmpty(), continue);
|
|
||||||
|
|
||||||
d->m_command->addJob({d->m_vcsBinary, arg}, d->m_vscTimeoutS);
|
|
||||||
}
|
|
||||||
|
|
||||||
d->m_command->start();
|
|
||||||
}
|
|
||||||
|
|
||||||
void VcsBaseDiffEditorController::processCommandOutput(const QString &output)
|
|
||||||
{
|
|
||||||
d->processDiff(output);
|
|
||||||
}
|
|
||||||
|
|
||||||
void VcsBaseDiffEditorController::setVcsTimeoutS(int value)
|
|
||||||
{
|
|
||||||
d->m_vscTimeoutS = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
void VcsBaseDiffEditorController::setVcsBinary(const FilePath &path)
|
void VcsBaseDiffEditorController::setVcsBinary(const FilePath &path)
|
||||||
{
|
{
|
||||||
d->m_vcsBinary = path;
|
d->m_vcsBinary = path;
|
||||||
|
@@ -4,20 +4,11 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "vcsbase_global.h"
|
#include "vcsbase_global.h"
|
||||||
#include "vcsenums.h"
|
|
||||||
|
|
||||||
#include <diffeditor/diffeditorcontroller.h>
|
#include <diffeditor/diffeditorcontroller.h>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
|
||||||
class QTextCodec;
|
|
||||||
QT_END_NAMESPACE
|
|
||||||
|
|
||||||
namespace Core { class IDocument; }
|
|
||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
template <typename R> class AsyncTask;
|
|
||||||
class Environment;
|
class Environment;
|
||||||
class FilePath;
|
|
||||||
class QtcProcess;
|
class QtcProcess;
|
||||||
} // Utils
|
} // Utils
|
||||||
|
|
||||||
@@ -35,15 +26,12 @@ public:
|
|||||||
|
|
||||||
void setProcessEnvironment(const Utils::Environment &value);
|
void setProcessEnvironment(const Utils::Environment &value);
|
||||||
void setVcsBinary(const Utils::FilePath &path);
|
void setVcsBinary(const Utils::FilePath &path);
|
||||||
void setVcsTimeoutS(int value);
|
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
Utils::Tasking::TreeStorage<QString> inputStorage() const;
|
Utils::Tasking::TreeStorage<QString> inputStorage() const;
|
||||||
Utils::Tasking::TaskItem postProcessTask();
|
Utils::Tasking::TaskItem postProcessTask();
|
||||||
|
|
||||||
void setupCommand(Utils::QtcProcess &process, const QStringList &args) const;
|
void setupCommand(Utils::QtcProcess &process, const QStringList &args) const;
|
||||||
void runCommand(const QList<QStringList> &args, RunFlags flags, QTextCodec *codec = nullptr);
|
|
||||||
virtual void processCommandOutput(const QString &output);
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
friend class VcsBaseDiffEditorControllerPrivate;
|
friend class VcsBaseDiffEditorControllerPrivate;
|
||||||
|
Reference in New Issue
Block a user