DiffEditorController: Aggregate reloadRecipe

Instead of declaring virtual getter.

Change-Id: I0f9e995bdff1b7e387e71daaf149a3726b7c09af
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Jarek Kobus
2022-12-15 09:19:09 +01:00
parent 5aedb4ba56
commit 7bd26571e4
3 changed files with 85 additions and 94 deletions

View File

@@ -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());

View File

@@ -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;
}; };

View File

@@ -206,98 +206,86 @@ class FileListDiffController : public GitBaseDiffEditorController
{ {
public: public:
FileListDiffController(IDocument *document, const QStringList &stagedFiles, FileListDiffController(IDocument *document, const QStringList &stagedFiles,
const QStringList &unstagedFiles) const QStringList &unstagedFiles);
: GitBaseDiffEditorController(document)
, m_stagedFiles(stagedFiles)
, m_unstagedFiles(unstagedFiles) {}
private:
Tasking::Group reloadRecipe() final
{
using namespace Tasking;
struct DiffStorage {
QString m_stagedOutput;
QString m_unstagedOutput;
};
const TreeStorage<DiffStorage> storage;
const auto setupStaged = [this](QtcProcess &process) {
process.setCodec(VcsBaseEditor::getCodec(workingDirectory(), m_stagedFiles));
setupCommand(process, addConfigurationArguments(
QStringList({"diff", "--cached", "--"}) + m_stagedFiles));
VcsOutputWindow::appendCommand(process.workingDirectory(), process.commandLine());
};
const auto onStagedDone = [storage](const QtcProcess &process) {
storage->m_stagedOutput = process.cleanedStdOut();
};
const auto setupUnstaged = [this](QtcProcess &process) {
process.setCodec(VcsBaseEditor::getCodec(workingDirectory(), m_unstagedFiles));
setupCommand(process, addConfigurationArguments(
QStringList({"diff", "--"}) + m_unstagedFiles));
VcsOutputWindow::appendCommand(process.workingDirectory(), process.commandLine());
};
const auto onUnstagedDone = [storage](const QtcProcess &process) {
storage->m_unstagedOutput = process.cleanedStdOut();
};
const auto onStagingDynamicSetup = [this] {
QSet<int> config;
if (!m_stagedFiles.isEmpty())
config.insert(0);
if (!m_unstagedFiles.isEmpty())
config.insert(1);
return GroupConfig{GroupAction::ContinueSelected, config};
};
const auto setupProcessDiff = [this, storage](AsyncTask<QList<FileData>> &async) {
setupDiffProcessor(async, storage->m_stagedOutput + storage->m_unstagedOutput);
};
const auto onProcessDiffDone = [this, storage](const AsyncTask<QList<FileData>> &async) {
setDiffFiles(async.result());
};
const auto onProcessDiffError = [this, storage](const AsyncTask<QList<FileData>> &) {
setDiffFiles({});
};
const Group root {
Storage(storage),
Group {
parallel,
optional,
DynamicSetup(onStagingDynamicSetup),
Process(setupStaged, onStagedDone),
Process(setupUnstaged, onUnstagedDone)
},
Async<QList<FileData>>(setupProcessDiff, onProcessDiffDone, onProcessDiffError)
};
return root;
}
QStringList m_stagedFiles;
QStringList m_unstagedFiles;
}; };
FileListDiffController::FileListDiffController(IDocument *document, const QStringList &stagedFiles,
const QStringList &unstagedFiles)
: GitBaseDiffEditorController(document)
{
using namespace Tasking;
struct DiffStorage {
QString m_stagedOutput;
QString m_unstagedOutput;
};
const TreeStorage<DiffStorage> storage;
const auto setupStaged = [this, stagedFiles](QtcProcess &process) {
process.setCodec(VcsBaseEditor::getCodec(workingDirectory(), stagedFiles));
setupCommand(process, addConfigurationArguments(
QStringList({"diff", "--cached", "--"}) + stagedFiles));
VcsOutputWindow::appendCommand(process.workingDirectory(), process.commandLine());
};
const auto onStagedDone = [storage](const QtcProcess &process) {
storage->m_stagedOutput = process.cleanedStdOut();
};
const auto setupUnstaged = [this, unstagedFiles](QtcProcess &process) {
process.setCodec(VcsBaseEditor::getCodec(workingDirectory(), unstagedFiles));
setupCommand(process, addConfigurationArguments(
QStringList({"diff", "--"}) + unstagedFiles));
VcsOutputWindow::appendCommand(process.workingDirectory(), process.commandLine());
};
const auto onUnstagedDone = [storage](const QtcProcess &process) {
storage->m_unstagedOutput = process.cleanedStdOut();
};
const auto onStagingDynamicSetup = [stagedFiles, unstagedFiles] {
QSet<int> config;
if (!stagedFiles.isEmpty())
config.insert(0);
if (!unstagedFiles.isEmpty())
config.insert(1);
return GroupConfig{GroupAction::ContinueSelected, config};
};
const auto setupProcessDiff = [this, storage](AsyncTask<QList<FileData>> &async) {
setupDiffProcessor(async, storage->m_stagedOutput + storage->m_unstagedOutput);
};
const auto onProcessDiffDone = [this, storage](const AsyncTask<QList<FileData>> &async) {
setDiffFiles(async.result());
};
const auto onProcessDiffError = [this, storage](const AsyncTask<QList<FileData>> &) {
setDiffFiles({});
};
const Group root {
Storage(storage),
Group {
parallel,
optional,
DynamicSetup(onStagingDynamicSetup),
Process(setupStaged, onStagedDone),
Process(setupUnstaged, onUnstagedDone)
},
Async<QList<FileData>>(setupProcessDiff, onProcessDiffDone, onProcessDiffError)
};
setReloadRecipe(root);
}
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);
} }
/////////////////////////////// ///////////////////////////////