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-09-29 17:02:04 +02:00
|
|
|
#include <utils/filepath.h>
|
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>
|
|
|
|
|
|
2015-03-10 14:19:38 +01:00
|
|
|
QT_FORWARD_DECLARE_CLASS(QMenu)
|
|
|
|
|
|
2015-01-30 16:59:25 +01:00
|
|
|
namespace Core { class IDocument; }
|
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
|
|
|
|
2021-08-17 12:26:10 +02:00
|
|
|
Utils::FilePath baseDirectory() const;
|
|
|
|
|
void setBaseDirectory(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-12 14:40:56 +01:00
|
|
|
void setDisplayName(const QString &name) { m_displayName = name; }
|
|
|
|
|
QString displayName() const { return m_displayName; }
|
|
|
|
|
|
2022-12-11 14:54:13 +01:00
|
|
|
// reloadFinished() should be called inside the reloader (for synchronous reload)
|
|
|
|
|
// or later (for asynchronous reload)
|
|
|
|
|
void setReloader(const std::function<void ()> &reloader);
|
2017-06-29 16:08:37 +02:00
|
|
|
void reloadFinished(bool success);
|
2015-01-30 16:59:25 +01:00
|
|
|
|
|
|
|
|
void setDiffFiles(const QList<FileData> &diffFileList,
|
2021-08-17 12:26:10 +02:00
|
|
|
const Utils::FilePath &baseDirectory = {},
|
2022-09-27 15:13:33 +02:00
|
|
|
const QString &startupFile = {});
|
2015-01-30 16:59:25 +01:00
|
|
|
void setDescription(const QString &description);
|
2018-02-16 12:53:35 +01:00
|
|
|
QString description() const;
|
2015-01-30 16:59:25 +01:00
|
|
|
void forceContextLineCount(int lines);
|
2013-12-16 16:19:40 +01:00
|
|
|
|
|
|
|
|
private:
|
2015-01-30 16:59:25 +01:00
|
|
|
Internal::DiffEditorDocument *const m_document;
|
2017-12-06 21:30:57 +01:00
|
|
|
bool m_isReloading = false;
|
2022-12-12 14:40:56 +01:00
|
|
|
QString m_displayName;
|
2020-02-06 11:52:59 +01:00
|
|
|
std::function<void()> m_reloader;
|
2022-12-12 14:40:56 +01:00
|
|
|
std::unique_ptr<Utils::TaskTree> m_taskTree;
|
|
|
|
|
virtual Utils::Tasking::Group reloadRecipe() { return {}; } // TODO: make pure abstract
|
2015-01-30 16:59:25 +01:00
|
|
|
|
|
|
|
|
friend class Internal::DiffEditorDocument;
|
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
|