forked from qt-creator/qt-creator
DiffEditorController: Aggregate reloadRecipe
Instead of declaring virtual getter. Change-Id: I0f9e995bdff1b7e387e71daaf149a3726b7c09af Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -19,9 +19,10 @@ using namespace Utils;
|
|||||||
|
|
||||||
namespace DiffEditor {
|
namespace DiffEditor {
|
||||||
|
|
||||||
DiffEditorController::DiffEditorController(Core::IDocument *document) :
|
DiffEditorController::DiffEditorController(Core::IDocument *document)
|
||||||
QObject(document),
|
: QObject(document)
|
||||||
m_document(qobject_cast<Internal::DiffEditorDocument *>(document))
|
, m_document(qobject_cast<Internal::DiffEditorDocument *>(document))
|
||||||
|
, m_reloadRecipe{}
|
||||||
{
|
{
|
||||||
QTC_ASSERT(m_document, return);
|
QTC_ASSERT(m_document, return);
|
||||||
m_document->setController(this);
|
m_document->setController(this);
|
||||||
@@ -125,7 +126,7 @@ void DiffEditorController::requestReload()
|
|||||||
m_reloader();
|
m_reloader();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
m_taskTree.reset(new TaskTree(reloadRecipe()));
|
m_taskTree.reset(new TaskTree(m_reloadRecipe));
|
||||||
connect(m_taskTree.get(), &TaskTree::done, this, [this] { reloadFinished(true); });
|
connect(m_taskTree.get(), &TaskTree::done, this, [this] { reloadFinished(true); });
|
||||||
connect(m_taskTree.get(), &TaskTree::errorOccurred, this, [this] { reloadFinished(false); });
|
connect(m_taskTree.get(), &TaskTree::errorOccurred, this, [this] { reloadFinished(false); });
|
||||||
auto progress = new TaskProgress(m_taskTree.get());
|
auto progress = new TaskProgress(m_taskTree.get());
|
||||||
|
@@ -61,6 +61,8 @@ protected:
|
|||||||
void setDisplayName(const QString &name) { m_displayName = name; }
|
void setDisplayName(const QString &name) { m_displayName = name; }
|
||||||
QString displayName() const { return m_displayName; }
|
QString displayName() const { return m_displayName; }
|
||||||
|
|
||||||
|
void setReloadRecipe(const Utils::Tasking::Group &recipe) { m_reloadRecipe = recipe; }
|
||||||
|
|
||||||
// reloadFinished() should be called inside the reloader (for synchronous reload)
|
// reloadFinished() should be called inside the reloader (for synchronous reload)
|
||||||
// or later (for asynchronous reload)
|
// or later (for asynchronous reload)
|
||||||
void setReloader(const std::function<void ()> &reloader);
|
void setReloader(const std::function<void ()> &reloader);
|
||||||
@@ -78,7 +80,7 @@ private:
|
|||||||
QString m_displayName;
|
QString m_displayName;
|
||||||
std::function<void()> m_reloader;
|
std::function<void()> m_reloader;
|
||||||
std::unique_ptr<Utils::TaskTree> m_taskTree;
|
std::unique_ptr<Utils::TaskTree> m_taskTree;
|
||||||
virtual Utils::Tasking::Group reloadRecipe() { return {}; } // TODO: make pure abstract
|
Utils::Tasking::Group m_reloadRecipe;
|
||||||
|
|
||||||
friend class Internal::DiffEditorDocument;
|
friend class Internal::DiffEditorDocument;
|
||||||
};
|
};
|
||||||
|
@@ -206,13 +206,12 @@ class FileListDiffController : public GitBaseDiffEditorController
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
FileListDiffController(IDocument *document, const QStringList &stagedFiles,
|
FileListDiffController(IDocument *document, const QStringList &stagedFiles,
|
||||||
|
const QStringList &unstagedFiles);
|
||||||
|
};
|
||||||
|
|
||||||
|
FileListDiffController::FileListDiffController(IDocument *document, const QStringList &stagedFiles,
|
||||||
const QStringList &unstagedFiles)
|
const QStringList &unstagedFiles)
|
||||||
: GitBaseDiffEditorController(document)
|
: GitBaseDiffEditorController(document)
|
||||||
, m_stagedFiles(stagedFiles)
|
|
||||||
, m_unstagedFiles(unstagedFiles) {}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Tasking::Group reloadRecipe() final
|
|
||||||
{
|
{
|
||||||
using namespace Tasking;
|
using namespace Tasking;
|
||||||
|
|
||||||
@@ -223,31 +222,31 @@ private:
|
|||||||
|
|
||||||
const TreeStorage<DiffStorage> storage;
|
const TreeStorage<DiffStorage> storage;
|
||||||
|
|
||||||
const auto setupStaged = [this](QtcProcess &process) {
|
const auto setupStaged = [this, stagedFiles](QtcProcess &process) {
|
||||||
process.setCodec(VcsBaseEditor::getCodec(workingDirectory(), m_stagedFiles));
|
process.setCodec(VcsBaseEditor::getCodec(workingDirectory(), stagedFiles));
|
||||||
setupCommand(process, addConfigurationArguments(
|
setupCommand(process, addConfigurationArguments(
|
||||||
QStringList({"diff", "--cached", "--"}) + m_stagedFiles));
|
QStringList({"diff", "--cached", "--"}) + stagedFiles));
|
||||||
VcsOutputWindow::appendCommand(process.workingDirectory(), process.commandLine());
|
VcsOutputWindow::appendCommand(process.workingDirectory(), process.commandLine());
|
||||||
};
|
};
|
||||||
const auto onStagedDone = [storage](const QtcProcess &process) {
|
const auto onStagedDone = [storage](const QtcProcess &process) {
|
||||||
storage->m_stagedOutput = process.cleanedStdOut();
|
storage->m_stagedOutput = process.cleanedStdOut();
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto setupUnstaged = [this](QtcProcess &process) {
|
const auto setupUnstaged = [this, unstagedFiles](QtcProcess &process) {
|
||||||
process.setCodec(VcsBaseEditor::getCodec(workingDirectory(), m_unstagedFiles));
|
process.setCodec(VcsBaseEditor::getCodec(workingDirectory(), unstagedFiles));
|
||||||
setupCommand(process, addConfigurationArguments(
|
setupCommand(process, addConfigurationArguments(
|
||||||
QStringList({"diff", "--"}) + m_unstagedFiles));
|
QStringList({"diff", "--"}) + unstagedFiles));
|
||||||
VcsOutputWindow::appendCommand(process.workingDirectory(), process.commandLine());
|
VcsOutputWindow::appendCommand(process.workingDirectory(), process.commandLine());
|
||||||
};
|
};
|
||||||
const auto onUnstagedDone = [storage](const QtcProcess &process) {
|
const auto onUnstagedDone = [storage](const QtcProcess &process) {
|
||||||
storage->m_unstagedOutput = process.cleanedStdOut();
|
storage->m_unstagedOutput = process.cleanedStdOut();
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto onStagingDynamicSetup = [this] {
|
const auto onStagingDynamicSetup = [stagedFiles, unstagedFiles] {
|
||||||
QSet<int> config;
|
QSet<int> config;
|
||||||
if (!m_stagedFiles.isEmpty())
|
if (!stagedFiles.isEmpty())
|
||||||
config.insert(0);
|
config.insert(0);
|
||||||
if (!m_unstagedFiles.isEmpty())
|
if (!unstagedFiles.isEmpty())
|
||||||
config.insert(1);
|
config.insert(1);
|
||||||
return GroupConfig{GroupAction::ContinueSelected, config};
|
return GroupConfig{GroupAction::ContinueSelected, config};
|
||||||
};
|
};
|
||||||
@@ -273,31 +272,20 @@ private:
|
|||||||
},
|
},
|
||||||
Async<QList<FileData>>(setupProcessDiff, onProcessDiffDone, onProcessDiffError)
|
Async<QList<FileData>>(setupProcessDiff, onProcessDiffDone, onProcessDiffError)
|
||||||
};
|
};
|
||||||
return root;
|
setReloadRecipe(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList m_stagedFiles;
|
|
||||||
QStringList m_unstagedFiles;
|
|
||||||
};
|
|
||||||
|
|
||||||
class ShowController : public GitBaseDiffEditorController
|
class ShowController : public GitBaseDiffEditorController
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
public:
|
public:
|
||||||
ShowController(IDocument *document, const QString &id)
|
ShowController(IDocument *document, const QString &id);
|
||||||
: GitBaseDiffEditorController(document)
|
|
||||||
, m_id(id)
|
|
||||||
{
|
|
||||||
setDisplayName("Git Show");
|
|
||||||
}
|
|
||||||
|
|
||||||
private:
|
|
||||||
Tasking::Group reloadRecipe() final;
|
|
||||||
const QString m_id;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
Tasking::Group ShowController::reloadRecipe()
|
ShowController::ShowController(IDocument *document, const QString &id)
|
||||||
|
: GitBaseDiffEditorController(document)
|
||||||
{
|
{
|
||||||
|
setDisplayName("Git Show");
|
||||||
static const QString busyMessage = Tr::tr("<resolving>");
|
static const QString busyMessage = Tr::tr("<resolving>");
|
||||||
using namespace Tasking;
|
using namespace Tasking;
|
||||||
|
|
||||||
@@ -333,9 +321,9 @@ Tasking::Group ShowController::reloadRecipe()
|
|||||||
|
|
||||||
const TreeStorage<ReloadStorage> storage;
|
const TreeStorage<ReloadStorage> storage;
|
||||||
|
|
||||||
const auto setupDescription = [this](QtcProcess &process) {
|
const auto setupDescription = [this, id](QtcProcess &process) {
|
||||||
process.setCodec(m_instance->encoding(workingDirectory(), "i18n.commitEncoding"));
|
process.setCodec(m_instance->encoding(workingDirectory(), "i18n.commitEncoding"));
|
||||||
setupCommand(process, {"show", "-s", noColorOption, showFormatC, m_id});
|
setupCommand(process, {"show", "-s", noColorOption, showFormatC, id});
|
||||||
VcsOutputWindow::appendCommand(process.workingDirectory(), process.commandLine());
|
VcsOutputWindow::appendCommand(process.workingDirectory(), process.commandLine());
|
||||||
setDescription(Tr::tr("Waiting for data..."));
|
setDescription(Tr::tr("Waiting for data..."));
|
||||||
};
|
};
|
||||||
@@ -460,10 +448,10 @@ Tasking::Group ShowController::reloadRecipe()
|
|||||||
taskTree.setupRoot(tasks);
|
taskTree.setupRoot(tasks);
|
||||||
};
|
};
|
||||||
|
|
||||||
const auto setupDiff = [this](QtcProcess &process) {
|
const auto setupDiff = [this, id](QtcProcess &process) {
|
||||||
setupCommand(process, addConfigurationArguments(
|
setupCommand(process, addConfigurationArguments(
|
||||||
{"show", "--format=format:", // omit header, already generated
|
{"show", "--format=format:", // omit header, already generated
|
||||||
noColorOption, decorateOption, m_id}));
|
noColorOption, decorateOption, id}));
|
||||||
VcsOutputWindow::appendCommand(process.workingDirectory(), process.commandLine());
|
VcsOutputWindow::appendCommand(process.workingDirectory(), process.commandLine());
|
||||||
};
|
};
|
||||||
const auto onDiffDone = [storage](const QtcProcess &process) {
|
const auto onDiffDone = [storage](const QtcProcess &process) {
|
||||||
@@ -483,7 +471,7 @@ Tasking::Group ShowController::reloadRecipe()
|
|||||||
const Group root {
|
const Group root {
|
||||||
Storage(storage),
|
Storage(storage),
|
||||||
parallel,
|
parallel,
|
||||||
OnGroupSetup([this] { setStartupFile(VcsBase::source(document())); }),
|
OnGroupSetup([this] { setStartupFile(VcsBase::source(this->document())); }),
|
||||||
Group {
|
Group {
|
||||||
optional,
|
optional,
|
||||||
Process(setupDescription, onDescriptionDone),
|
Process(setupDescription, onDescriptionDone),
|
||||||
@@ -501,7 +489,7 @@ Tasking::Group ShowController::reloadRecipe()
|
|||||||
Async<QList<FileData>>(setupProcessDiff, onProcessDiffDone, onProcessDiffError)
|
Async<QList<FileData>>(setupProcessDiff, onProcessDiffDone, onProcessDiffError)
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
return root;
|
setReloadRecipe(root);
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////
|
///////////////////////////////
|
||||||
|
Reference in New Issue
Block a user