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 {
|
||||
|
||||
DiffEditorController::DiffEditorController(Core::IDocument *document) :
|
||||
QObject(document),
|
||||
m_document(qobject_cast<Internal::DiffEditorDocument *>(document))
|
||||
DiffEditorController::DiffEditorController(Core::IDocument *document)
|
||||
: QObject(document)
|
||||
, m_document(qobject_cast<Internal::DiffEditorDocument *>(document))
|
||||
, m_reloadRecipe{}
|
||||
{
|
||||
QTC_ASSERT(m_document, return);
|
||||
m_document->setController(this);
|
||||
@@ -125,7 +126,7 @@ void DiffEditorController::requestReload()
|
||||
m_reloader();
|
||||
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::errorOccurred, this, [this] { reloadFinished(false); });
|
||||
auto progress = new TaskProgress(m_taskTree.get());
|
||||
|
@@ -61,6 +61,8 @@ protected:
|
||||
void setDisplayName(const QString &name) { m_displayName = name; }
|
||||
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)
|
||||
// or later (for asynchronous reload)
|
||||
void setReloader(const std::function<void ()> &reloader);
|
||||
@@ -78,7 +80,7 @@ private:
|
||||
QString m_displayName;
|
||||
std::function<void()> m_reloader;
|
||||
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;
|
||||
};
|
||||
|
@@ -206,14 +206,13 @@ class FileListDiffController : public GitBaseDiffEditorController
|
||||
{
|
||||
public:
|
||||
FileListDiffController(IDocument *document, const QStringList &stagedFiles,
|
||||
const QStringList &unstagedFiles);
|
||||
};
|
||||
|
||||
FileListDiffController::FileListDiffController(IDocument *document, const QStringList &stagedFiles,
|
||||
const QStringList &unstagedFiles)
|
||||
: GitBaseDiffEditorController(document)
|
||||
, m_stagedFiles(stagedFiles)
|
||||
, m_unstagedFiles(unstagedFiles) {}
|
||||
|
||||
private:
|
||||
Tasking::Group reloadRecipe() final
|
||||
{
|
||||
{
|
||||
using namespace Tasking;
|
||||
|
||||
struct DiffStorage {
|
||||
@@ -223,31 +222,31 @@ private:
|
||||
|
||||
const TreeStorage<DiffStorage> storage;
|
||||
|
||||
const auto setupStaged = [this](QtcProcess &process) {
|
||||
process.setCodec(VcsBaseEditor::getCodec(workingDirectory(), m_stagedFiles));
|
||||
const auto setupStaged = [this, stagedFiles](QtcProcess &process) {
|
||||
process.setCodec(VcsBaseEditor::getCodec(workingDirectory(), stagedFiles));
|
||||
setupCommand(process, addConfigurationArguments(
|
||||
QStringList({"diff", "--cached", "--"}) + m_stagedFiles));
|
||||
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](QtcProcess &process) {
|
||||
process.setCodec(VcsBaseEditor::getCodec(workingDirectory(), m_unstagedFiles));
|
||||
const auto setupUnstaged = [this, unstagedFiles](QtcProcess &process) {
|
||||
process.setCodec(VcsBaseEditor::getCodec(workingDirectory(), unstagedFiles));
|
||||
setupCommand(process, addConfigurationArguments(
|
||||
QStringList({"diff", "--"}) + m_unstagedFiles));
|
||||
QStringList({"diff", "--"}) + unstagedFiles));
|
||||
VcsOutputWindow::appendCommand(process.workingDirectory(), process.commandLine());
|
||||
};
|
||||
const auto onUnstagedDone = [storage](const QtcProcess &process) {
|
||||
storage->m_unstagedOutput = process.cleanedStdOut();
|
||||
};
|
||||
|
||||
const auto onStagingDynamicSetup = [this] {
|
||||
const auto onStagingDynamicSetup = [stagedFiles, unstagedFiles] {
|
||||
QSet<int> config;
|
||||
if (!m_stagedFiles.isEmpty())
|
||||
if (!stagedFiles.isEmpty())
|
||||
config.insert(0);
|
||||
if (!m_unstagedFiles.isEmpty())
|
||||
if (!unstagedFiles.isEmpty())
|
||||
config.insert(1);
|
||||
return GroupConfig{GroupAction::ContinueSelected, config};
|
||||
};
|
||||
@@ -273,31 +272,20 @@ private:
|
||||
},
|
||||
Async<QList<FileData>>(setupProcessDiff, onProcessDiffDone, onProcessDiffError)
|
||||
};
|
||||
return root;
|
||||
}
|
||||
|
||||
QStringList m_stagedFiles;
|
||||
QStringList m_unstagedFiles;
|
||||
};
|
||||
setReloadRecipe(root);
|
||||
}
|
||||
|
||||
class ShowController : public GitBaseDiffEditorController
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ShowController(IDocument *document, const QString &id)
|
||||
: GitBaseDiffEditorController(document)
|
||||
, m_id(id)
|
||||
{
|
||||
setDisplayName("Git Show");
|
||||
}
|
||||
|
||||
private:
|
||||
Tasking::Group reloadRecipe() final;
|
||||
const QString m_id;
|
||||
ShowController(IDocument *document, const QString &id);
|
||||
};
|
||||
|
||||
Tasking::Group ShowController::reloadRecipe()
|
||||
ShowController::ShowController(IDocument *document, const QString &id)
|
||||
: GitBaseDiffEditorController(document)
|
||||
{
|
||||
setDisplayName("Git Show");
|
||||
static const QString busyMessage = Tr::tr("<resolving>");
|
||||
using namespace Tasking;
|
||||
|
||||
@@ -333,9 +321,9 @@ Tasking::Group ShowController::reloadRecipe()
|
||||
|
||||
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"));
|
||||
setupCommand(process, {"show", "-s", noColorOption, showFormatC, m_id});
|
||||
setupCommand(process, {"show", "-s", noColorOption, showFormatC, id});
|
||||
VcsOutputWindow::appendCommand(process.workingDirectory(), process.commandLine());
|
||||
setDescription(Tr::tr("Waiting for data..."));
|
||||
};
|
||||
@@ -460,10 +448,10 @@ Tasking::Group ShowController::reloadRecipe()
|
||||
taskTree.setupRoot(tasks);
|
||||
};
|
||||
|
||||
const auto setupDiff = [this](QtcProcess &process) {
|
||||
const auto setupDiff = [this, id](QtcProcess &process) {
|
||||
setupCommand(process, addConfigurationArguments(
|
||||
{"show", "--format=format:", // omit header, already generated
|
||||
noColorOption, decorateOption, m_id}));
|
||||
noColorOption, decorateOption, id}));
|
||||
VcsOutputWindow::appendCommand(process.workingDirectory(), process.commandLine());
|
||||
};
|
||||
const auto onDiffDone = [storage](const QtcProcess &process) {
|
||||
@@ -483,7 +471,7 @@ Tasking::Group ShowController::reloadRecipe()
|
||||
const Group root {
|
||||
Storage(storage),
|
||||
parallel,
|
||||
OnGroupSetup([this] { setStartupFile(VcsBase::source(document())); }),
|
||||
OnGroupSetup([this] { setStartupFile(VcsBase::source(this->document())); }),
|
||||
Group {
|
||||
optional,
|
||||
Process(setupDescription, onDescriptionDone),
|
||||
@@ -501,7 +489,7 @@ Tasking::Group ShowController::reloadRecipe()
|
||||
Async<QList<FileData>>(setupProcessDiff, onProcessDiffDone, onProcessDiffError)
|
||||
}
|
||||
};
|
||||
return root;
|
||||
setReloadRecipe(root);
|
||||
}
|
||||
|
||||
///////////////////////////////
|
||||
|
Reference in New Issue
Block a user