forked from qt-creator/qt-creator
Diff/Vcs: Use a function object for reloading
Helps with slimming down the user code side. Change-Id: I4b0aac76c0d1516eb05bff9c18594e64f8b41a7a Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -123,6 +123,11 @@ void DiffEditorController::forceContextLineCount(int lines)
|
||||
m_document->forceContextLineCount(lines);
|
||||
}
|
||||
|
||||
void DiffEditorController::setReloader(const std::function<void ()> &reloader)
|
||||
{
|
||||
m_reloader = reloader;
|
||||
}
|
||||
|
||||
Core::IDocument *DiffEditorController::document() const
|
||||
{
|
||||
return m_document;
|
||||
@@ -135,7 +140,8 @@ void DiffEditorController::requestReload()
|
||||
{
|
||||
m_isReloading = true;
|
||||
m_document->beginReload();
|
||||
reload();
|
||||
QTC_ASSERT(m_reloader, reloadFinished(false); return);
|
||||
m_reloader();
|
||||
}
|
||||
|
||||
void DiffEditorController::reloadFinished(bool success)
|
||||
|
@@ -72,15 +72,15 @@ public:
|
||||
bool chunkExists(int fileIndex, int chunkIndex) const;
|
||||
Core::IDocument *document() const;
|
||||
|
||||
// reloadFinished() should be called inside the reloader (for synchronous reload)
|
||||
// or later (for asynchronous reload)
|
||||
void setReloader(const std::function<void ()> &reloader);
|
||||
|
||||
signals:
|
||||
void chunkActionsRequested(QMenu *menu, int fileIndex, int chunkIndex,
|
||||
const ChunkSelection &selection);
|
||||
|
||||
protected:
|
||||
// reloadFinished() should be called
|
||||
// inside reload() (for synchronous reload)
|
||||
// or later (for asynchronous reload)
|
||||
virtual void reload() = 0;
|
||||
void reloadFinished(bool success);
|
||||
|
||||
void setDiffFiles(const QList<FileData> &diffFileList,
|
||||
@@ -93,6 +93,7 @@ protected:
|
||||
private:
|
||||
Internal::DiffEditorDocument *const m_document;
|
||||
bool m_isReloading = false;
|
||||
std::function<void()> m_reloader;
|
||||
|
||||
friend class Internal::DiffEditorDocument;
|
||||
};
|
||||
|
@@ -130,11 +130,11 @@ class DiffFilesController : public DiffEditorController
|
||||
Q_OBJECT
|
||||
public:
|
||||
DiffFilesController(IDocument *document);
|
||||
~DiffFilesController() override;
|
||||
~DiffFilesController() override { cancelReload(); }
|
||||
|
||||
protected:
|
||||
void reload() final;
|
||||
virtual QList<ReloadInput> reloadInputList() const = 0;
|
||||
|
||||
private:
|
||||
void reloaded();
|
||||
void cancelReload();
|
||||
@@ -147,22 +147,16 @@ DiffFilesController::DiffFilesController(IDocument *document)
|
||||
{
|
||||
connect(&m_futureWatcher, &QFutureWatcher<FileData>::finished,
|
||||
this, &DiffFilesController::reloaded);
|
||||
}
|
||||
|
||||
DiffFilesController::~DiffFilesController()
|
||||
{
|
||||
cancelReload();
|
||||
}
|
||||
setReloader([this] {
|
||||
cancelReload();
|
||||
m_futureWatcher.setFuture(Utils::map(reloadInputList(),
|
||||
DiffFile(ignoreWhitespace(),
|
||||
contextLineCount())));
|
||||
|
||||
void DiffFilesController::reload()
|
||||
{
|
||||
cancelReload();
|
||||
m_futureWatcher.setFuture(Utils::map(reloadInputList(),
|
||||
DiffFile(ignoreWhitespace(),
|
||||
contextLineCount())));
|
||||
|
||||
Core::ProgressManager::addTask(m_futureWatcher.future(),
|
||||
tr("Calculating diff"), "DiffEditor");
|
||||
Core::ProgressManager::addTask(m_futureWatcher.future(),
|
||||
tr("Calculating diff"), "DiffEditor");
|
||||
});
|
||||
}
|
||||
|
||||
void DiffFilesController::reloaded()
|
||||
|
@@ -383,127 +383,88 @@ QStringList GitDiffEditorController::addHeadWhenCommandInProgress() const
|
||||
|
||||
class RepositoryDiffController : public GitDiffEditorController
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit RepositoryDiffController(IDocument *document) :
|
||||
GitDiffEditorController(document)
|
||||
{ }
|
||||
|
||||
void reload() override;
|
||||
{
|
||||
setReloader([this] {
|
||||
QStringList args = {"diff"};
|
||||
args.append(addHeadWhenCommandInProgress());
|
||||
runCommand({addConfigurationArguments(args)});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
void RepositoryDiffController::reload()
|
||||
{
|
||||
QStringList args = {"diff"};
|
||||
args.append(addHeadWhenCommandInProgress());
|
||||
runCommand(QList<QStringList>() << addConfigurationArguments(args));
|
||||
}
|
||||
|
||||
class FileDiffController : public GitDiffEditorController
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
FileDiffController(IDocument *document, const QString &fileName) :
|
||||
GitDiffEditorController(document),
|
||||
m_fileName(fileName)
|
||||
{ }
|
||||
|
||||
void reload() override;
|
||||
|
||||
private:
|
||||
const QString m_fileName;
|
||||
GitDiffEditorController(document)
|
||||
{
|
||||
setReloader([this, fileName] {
|
||||
QStringList args = {"diff"};
|
||||
args.append(addHeadWhenCommandInProgress());
|
||||
args << "--" << fileName;
|
||||
runCommand({addConfigurationArguments(args)});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
void FileDiffController::reload()
|
||||
{
|
||||
QStringList args = {"diff"};
|
||||
args.append(addHeadWhenCommandInProgress());
|
||||
args << "--" << m_fileName;
|
||||
|
||||
runCommand(QList<QStringList>() << addConfigurationArguments(args));
|
||||
}
|
||||
|
||||
class FileListDiffController : public GitDiffEditorController
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
FileListDiffController(IDocument *document,
|
||||
const QStringList &stagedFiles, const QStringList &unstagedFiles) :
|
||||
GitDiffEditorController(document),
|
||||
m_stagedFiles(stagedFiles),
|
||||
m_unstagedFiles(unstagedFiles)
|
||||
{ }
|
||||
GitDiffEditorController(document)
|
||||
{
|
||||
setReloader([this, stagedFiles, unstagedFiles] {
|
||||
QList<QStringList> argLists;
|
||||
if (!stagedFiles.isEmpty()) {
|
||||
QStringList stagedArgs = {"diff", "--cached", "--"};
|
||||
stagedArgs << stagedFiles;
|
||||
argLists << addConfigurationArguments(stagedArgs);
|
||||
}
|
||||
|
||||
void reload() override;
|
||||
if (!unstagedFiles.isEmpty()) {
|
||||
QStringList unstagedArgs = {"diff"};
|
||||
unstagedArgs << addHeadWhenCommandInProgress() << "--" << unstagedFiles;
|
||||
argLists << addConfigurationArguments(unstagedArgs);
|
||||
}
|
||||
|
||||
private:
|
||||
const QStringList m_stagedFiles;
|
||||
const QStringList m_unstagedFiles;
|
||||
if (!argLists.isEmpty())
|
||||
runCommand(argLists);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
void FileListDiffController::reload()
|
||||
{
|
||||
QList<QStringList> argLists;
|
||||
if (!m_stagedFiles.isEmpty()) {
|
||||
QStringList stagedArgs = {"diff", "--cached", "--"};
|
||||
stagedArgs << m_stagedFiles;
|
||||
argLists << addConfigurationArguments(stagedArgs);
|
||||
}
|
||||
|
||||
if (!m_unstagedFiles.isEmpty()) {
|
||||
QStringList unstagedArgs = {"diff"};
|
||||
unstagedArgs << addHeadWhenCommandInProgress() << "--" << m_unstagedFiles;
|
||||
argLists << addConfigurationArguments(unstagedArgs);
|
||||
}
|
||||
|
||||
if (!argLists.isEmpty())
|
||||
runCommand(argLists);
|
||||
}
|
||||
|
||||
class ProjectDiffController : public GitDiffEditorController
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
ProjectDiffController(IDocument *document, const QStringList &projectPaths) :
|
||||
GitDiffEditorController(document),
|
||||
m_projectPaths(projectPaths)
|
||||
{ }
|
||||
|
||||
void reload() override;
|
||||
|
||||
private:
|
||||
const QStringList m_projectPaths;
|
||||
GitDiffEditorController(document)
|
||||
{
|
||||
setReloader([this, projectPaths] {
|
||||
QStringList args = {"diff"};
|
||||
args << addHeadWhenCommandInProgress() << "--" << projectPaths;
|
||||
runCommand({addConfigurationArguments(args)});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
void ProjectDiffController::reload()
|
||||
{
|
||||
QStringList args = {"diff"};
|
||||
args << addHeadWhenCommandInProgress() << "--" << m_projectPaths;
|
||||
runCommand(QList<QStringList>() << addConfigurationArguments(args));
|
||||
}
|
||||
|
||||
class BranchDiffController : public GitDiffEditorController
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
BranchDiffController(IDocument *document, const QString &branch) :
|
||||
GitDiffEditorController(document),
|
||||
m_branch(branch)
|
||||
{ }
|
||||
|
||||
void reload() override;
|
||||
|
||||
private:
|
||||
const QString m_branch;
|
||||
GitDiffEditorController(document)
|
||||
{
|
||||
setReloader([this, branch] {
|
||||
QStringList args = {"diff"};
|
||||
args << addHeadWhenCommandInProgress() << branch;
|
||||
runCommand({addConfigurationArguments(args)});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
void BranchDiffController::reload()
|
||||
{
|
||||
QStringList args = {"diff"};
|
||||
args << addHeadWhenCommandInProgress() << m_branch;
|
||||
runCommand(QList<QStringList>() << addConfigurationArguments(args));
|
||||
}
|
||||
|
||||
class ShowController : public GitDiffEditorController
|
||||
{
|
||||
Q_OBJECT
|
||||
@@ -514,9 +475,14 @@ public:
|
||||
m_state(Idle)
|
||||
{
|
||||
setDisplayName("Git Show");
|
||||
setReloader([this] {
|
||||
m_state = GettingDescription;
|
||||
const QStringList args = {"show", "-s", noColorOption, showFormatC, m_id};
|
||||
runCommand({args}, GitPluginPrivate::client()->encoding(workingDirectory(), "i18n.commitEncoding"));
|
||||
setStartupFile(VcsBase::source(this->document()));
|
||||
});
|
||||
}
|
||||
|
||||
void reload() override;
|
||||
void processCommandOutput(const QString &output) override;
|
||||
|
||||
private:
|
||||
@@ -525,15 +491,6 @@ private:
|
||||
State m_state;
|
||||
};
|
||||
|
||||
void ShowController::reload()
|
||||
{
|
||||
// stage 1
|
||||
m_state = GettingDescription;
|
||||
const QStringList args = {"show", "-s", noColorOption, showFormatC, m_id};
|
||||
runCommand(QList<QStringList>() << args, GitPluginPrivate::client()->encoding(workingDirectory(), "i18n.commitEncoding"));
|
||||
setStartupFile(VcsBase::source(document()));
|
||||
}
|
||||
|
||||
void ShowController::processCommandOutput(const QString &output)
|
||||
{
|
||||
QTC_ASSERT(m_state != Idle, return);
|
||||
|
@@ -89,37 +89,27 @@ class FileDiffController : public MercurialDiffEditorController
|
||||
{
|
||||
public:
|
||||
FileDiffController(IDocument *document, const QString &fileName) :
|
||||
MercurialDiffEditorController(document),
|
||||
m_fileName(fileName)
|
||||
{ }
|
||||
|
||||
void reload() override
|
||||
MercurialDiffEditorController(document)
|
||||
{
|
||||
QStringList args = { "diff", m_fileName };
|
||||
runCommand({ addConfigurationArguments(args) });
|
||||
setReloader([this, fileName] {
|
||||
QStringList args = { "diff", fileName };
|
||||
runCommand({ addConfigurationArguments(args) });
|
||||
});
|
||||
}
|
||||
|
||||
private:
|
||||
const QString m_fileName;
|
||||
};
|
||||
|
||||
class FileListDiffController : public MercurialDiffEditorController
|
||||
{
|
||||
public:
|
||||
FileListDiffController(IDocument *document, const QStringList &fileNames) :
|
||||
MercurialDiffEditorController(document),
|
||||
m_fileNames(fileNames)
|
||||
{ }
|
||||
|
||||
void reload() override
|
||||
MercurialDiffEditorController(document)
|
||||
{
|
||||
QStringList args { "diff" };
|
||||
args << m_fileNames;
|
||||
runCommand({addConfigurationArguments(args)});
|
||||
setReloader([this, fileNames] {
|
||||
QStringList args { "diff" };
|
||||
args << fileNames;
|
||||
runCommand({addConfigurationArguments(args)});
|
||||
});
|
||||
}
|
||||
|
||||
private:
|
||||
const QStringList m_fileNames;
|
||||
};
|
||||
|
||||
|
||||
@@ -128,12 +118,11 @@ class RepositoryDiffController : public MercurialDiffEditorController
|
||||
public:
|
||||
RepositoryDiffController(IDocument *document) :
|
||||
MercurialDiffEditorController(document)
|
||||
{ }
|
||||
|
||||
void reload() override
|
||||
{
|
||||
QStringList args = { "diff" };
|
||||
runCommand({addConfigurationArguments(args)});
|
||||
setReloader([this] {
|
||||
QStringList args = { "diff" };
|
||||
runCommand({addConfigurationArguments(args)});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -175,13 +175,13 @@ public:
|
||||
: VcsBaseDiffEditorController(document), m_authenticationOptions(authOptions)
|
||||
{
|
||||
forceContextLineCount(3); // SVN cannot change that when using internal diff
|
||||
setReloader([this] { m_changeNumber ? requestDescription() : requestDiff(); });
|
||||
}
|
||||
|
||||
void setFilesList(const QStringList &filesList);
|
||||
void setChangeNumber(int changeNumber);
|
||||
|
||||
protected:
|
||||
void reload() override;
|
||||
void processCommandOutput(const QString &output) override;
|
||||
|
||||
private:
|
||||
@@ -242,15 +242,6 @@ void SubversionDiffEditorController::requestDiff()
|
||||
runCommand(QList<QStringList>() << args, 0);
|
||||
}
|
||||
|
||||
void SubversionDiffEditorController::reload()
|
||||
{
|
||||
if (m_changeNumber) {
|
||||
requestDescription();
|
||||
} else {
|
||||
requestDiff();
|
||||
}
|
||||
}
|
||||
|
||||
void SubversionDiffEditorController::processCommandOutput(const QString &output)
|
||||
{
|
||||
QTC_ASSERT(m_state != Idle, return);
|
||||
|
Reference in New Issue
Block a user