2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2013-12-16 16:19:40 +01:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2013-12-16 16:19:40 +01:00
|
|
|
|
|
|
|
|
#include "diffeditor_global.h"
|
2014-02-13 16:43:28 +01:00
|
|
|
#include "diffutils.h"
|
2013-12-16 16:19:40 +01:00
|
|
|
|
2022-12-12 14:40:56 +01:00
|
|
|
#include <utils/tasktree.h>
|
2022-09-29 17:02:04 +02:00
|
|
|
|
2013-12-16 16:19:40 +01:00
|
|
|
#include <QObject>
|
|
|
|
|
|
2022-12-15 14:53:08 +01:00
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
class QMenu;
|
|
|
|
|
QT_END_NAMESPACE
|
2015-03-10 14:19:38 +01:00
|
|
|
|
2015-01-30 16:59:25 +01:00
|
|
|
namespace Core { class IDocument; }
|
2022-12-15 14:53:08 +01:00
|
|
|
namespace Utils { class FilePath; }
|
2013-12-16 16:19:40 +01:00
|
|
|
|
2015-01-30 16:59:25 +01:00
|
|
|
namespace DiffEditor {
|
2015-03-10 14:19:38 +01:00
|
|
|
|
2015-01-30 16:59:25 +01:00
|
|
|
namespace Internal { class DiffEditorDocument; }
|
2014-07-04 13:55:51 +02:00
|
|
|
|
2017-11-29 21:36:30 +01:00
|
|
|
class ChunkSelection;
|
|
|
|
|
|
2013-12-16 16:19:40 +01:00
|
|
|
class DIFFEDITOR_EXPORT DiffEditorController : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2015-01-30 16:59:25 +01:00
|
|
|
explicit DiffEditorController(Core::IDocument *document);
|
2013-12-16 16:19:40 +01:00
|
|
|
|
2015-01-30 16:59:25 +01:00
|
|
|
void requestReload();
|
|
|
|
|
bool isReloading() const;
|
2013-12-16 16:19:40 +01:00
|
|
|
|
2022-12-14 22:16:49 +01:00
|
|
|
Utils::FilePath workingDirectory() const;
|
|
|
|
|
void setWorkingDirectory(const Utils::FilePath &directory);
|
2015-01-30 16:59:25 +01:00
|
|
|
int contextLineCount() const;
|
|
|
|
|
bool ignoreWhitespace() const;
|
2014-02-13 16:43:28 +01:00
|
|
|
|
2018-01-16 22:20:07 +02:00
|
|
|
enum PatchOption {
|
|
|
|
|
NoOption = 0,
|
|
|
|
|
Revert = 1,
|
|
|
|
|
AddPrefix = 2
|
|
|
|
|
};
|
|
|
|
|
Q_DECLARE_FLAGS(PatchOptions, PatchOption)
|
2017-11-29 21:36:30 +01:00
|
|
|
QString makePatch(int fileIndex, int chunkIndex, const ChunkSelection &selection,
|
|
|
|
|
PatchOptions options) const;
|
2014-07-04 13:55:51 +02:00
|
|
|
|
2016-11-24 09:58:11 +01:00
|
|
|
static Core::IDocument *findOrCreateDocument(const QString &vcsId,
|
|
|
|
|
const QString &displayName);
|
2015-04-06 15:01:05 +03:00
|
|
|
static DiffEditorController *controller(Core::IDocument *document);
|
|
|
|
|
|
2017-11-29 21:36:30 +01:00
|
|
|
void requestChunkActions(QMenu *menu, int fileIndex, int chunkIndex,
|
|
|
|
|
const ChunkSelection &selection);
|
2018-02-15 10:29:14 +01:00
|
|
|
bool chunkExists(int fileIndex, int chunkIndex) const;
|
2018-02-16 12:53:35 +01:00
|
|
|
Core::IDocument *document() const;
|
2013-12-16 16:19:40 +01:00
|
|
|
|
|
|
|
|
signals:
|
2017-11-29 21:36:30 +01:00
|
|
|
void chunkActionsRequested(QMenu *menu, int fileIndex, int chunkIndex,
|
|
|
|
|
const ChunkSelection &selection);
|
2015-01-30 16:59:25 +01:00
|
|
|
|
|
|
|
|
protected:
|
2022-12-15 17:32:45 +01:00
|
|
|
// Core functions:
|
2022-12-15 09:19:09 +01:00
|
|
|
void setReloadRecipe(const Utils::Tasking::Group &recipe) { m_reloadRecipe = recipe; }
|
2022-12-14 22:16:49 +01:00
|
|
|
void setDiffFiles(const QList<FileData> &diffFileList);
|
2022-12-15 17:32:45 +01:00
|
|
|
// Optional:
|
|
|
|
|
void setDisplayName(const QString &name) { m_displayName = name; }
|
2015-01-30 16:59:25 +01:00
|
|
|
void setDescription(const QString &description);
|
2022-12-15 17:32:45 +01:00
|
|
|
void setStartupFile(const QString &startupFile);
|
2015-01-30 16:59:25 +01:00
|
|
|
void forceContextLineCount(int lines);
|
2013-12-16 16:19:40 +01:00
|
|
|
|
|
|
|
|
private:
|
2022-12-15 17:32:45 +01:00
|
|
|
void reloadFinished(bool success);
|
|
|
|
|
|
2015-01-30 16:59:25 +01:00
|
|
|
Internal::DiffEditorDocument *const m_document;
|
2022-12-12 14:40:56 +01:00
|
|
|
QString m_displayName;
|
|
|
|
|
std::unique_ptr<Utils::TaskTree> m_taskTree;
|
2022-12-15 09:19:09 +01:00
|
|
|
Utils::Tasking::Group m_reloadRecipe;
|
2013-12-16 16:19:40 +01:00
|
|
|
};
|
|
|
|
|
|
2018-02-15 10:29:14 +01:00
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(DiffEditorController::PatchOptions)
|
|
|
|
|
|
2013-12-16 16:19:40 +01:00
|
|
|
} // namespace DiffEditor
|