DiffEditor: Refactor DiffEditorController

Replace requestChunkActions() and chunkActionsRequested()
with a virtual method addExtraActions().
Implement it in GitBaseDiffEditorController.

Task-number: QTCREATORBUG-23242
Change-Id: I5da166b35d1146b9fd439e748803531d982ad2a8
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Jarek Kobus
2023-06-08 16:10:03 +02:00
parent 7f2ad8079d
commit 2caf4efbb2
5 changed files with 98 additions and 120 deletions

View File

@@ -124,17 +124,20 @@ void DiffEditorController::reloadFinished(bool success)
m_document->endReload(success);
}
void DiffEditorController::addExtraActions(QMenu *menu, int fileIndex, int chunkIndex,
const ChunkSelection &selection)
{
Q_UNUSED(menu)
Q_UNUSED(fileIndex)
Q_UNUSED(chunkIndex)
Q_UNUSED(selection)
}
void DiffEditorController::setStartupFile(const QString &startupFile)
{
m_document->setStartupFile(startupFile);
}
void DiffEditorController::requestChunkActions(QMenu *menu, int fileIndex, int chunkIndex,
const ChunkSelection &selection)
{
emit chunkActionsRequested(menu, fileIndex, chunkIndex, selection);
}
bool DiffEditorController::chunkExists(int fileIndex, int chunkIndex) const
{
if (!m_document)

View File

@@ -19,7 +19,10 @@ namespace Utils { class FilePath; }
namespace DiffEditor {
namespace Internal { class DiffEditorDocument; }
namespace Internal {
class DiffEditorDocument;
class DiffEditorWidgetController;
}
class ChunkSelection;
@@ -40,26 +43,18 @@ public:
AddPrefix = 2
};
Q_DECLARE_FLAGS(PatchOptions, PatchOption)
QString makePatch(int fileIndex, int chunkIndex, const ChunkSelection &selection,
PatchOptions options) const;
static Core::IDocument *findOrCreateDocument(const QString &vcsId,
const QString &displayName);
static Core::IDocument *findOrCreateDocument(const QString &vcsId, const QString &displayName);
static DiffEditorController *controller(Core::IDocument *document);
void requestChunkActions(QMenu *menu, int fileIndex, int chunkIndex,
const ChunkSelection &selection);
bool chunkExists(int fileIndex, int chunkIndex) const;
Core::IDocument *document() const;
signals:
void chunkActionsRequested(QMenu *menu, int fileIndex, int chunkIndex,
const ChunkSelection &selection);
protected:
bool isReloading() const;
int contextLineCount() const;
bool ignoreWhitespace() const;
bool chunkExists(int fileIndex, int chunkIndex) const;
Core::IDocument *document() const;
QString makePatch(int fileIndex, int chunkIndex, const ChunkSelection &selection,
PatchOptions options) const;
// Core functions:
void setReloadRecipe(const Tasking::Group &recipe) { m_reloadRecipe = recipe; }
@@ -72,6 +67,9 @@ protected:
private:
void reloadFinished(bool success);
friend class Internal::DiffEditorWidgetController;
virtual void addExtraActions(QMenu *menu, int fileIndex, int chunkIndex,
const ChunkSelection &selection);
Internal::DiffEditorDocument *const m_document;
QString m_displayName;

View File

@@ -280,7 +280,7 @@ void DiffEditorWidgetController::addExtraActions(QMenu *menu, int fileIndex, int
const ChunkSelection &selection)
{
if (DiffEditorController *controller = m_document->controller())
controller->requestChunkActions(menu, fileIndex, chunkIndex, selection);
controller->addExtraActions(menu, fileIndex, chunkIndex, selection);
}
void DiffEditorWidgetController::updateCannotDecodeInfo()