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-05-07 14:02:08 +02:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2013-05-07 14:02:08 +02:00
|
|
|
|
2015-01-30 16:59:25 +01:00
|
|
|
#include "diffutils.h"
|
|
|
|
|
|
2014-06-30 15:04:36 +02:00
|
|
|
#include <coreplugin/textdocument.h>
|
2013-05-07 14:02:08 +02:00
|
|
|
|
2015-03-10 14:19:38 +01:00
|
|
|
QT_FORWARD_DECLARE_CLASS(QMenu)
|
|
|
|
|
|
2013-05-07 14:02:08 +02:00
|
|
|
namespace DiffEditor {
|
|
|
|
|
|
2014-01-31 09:01:49 +01:00
|
|
|
class DiffEditorController;
|
2017-11-29 21:36:30 +01:00
|
|
|
class ChunkSelection;
|
2014-01-31 09:01:49 +01:00
|
|
|
|
2015-01-30 14:33:39 +01:00
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
class DiffEditorDocument : public Core::BaseTextDocument
|
2013-05-07 14:02:08 +02:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
2014-11-13 09:11:56 +01:00
|
|
|
Q_PROPERTY(QString plainText READ plainText STORED false) // For access by code pasters
|
2013-05-07 14:02:08 +02:00
|
|
|
public:
|
2015-01-30 11:18:08 +01:00
|
|
|
DiffEditorDocument();
|
2014-01-31 09:01:49 +01:00
|
|
|
|
2014-02-11 13:00:35 +01:00
|
|
|
DiffEditorController *controller() const;
|
2013-05-07 14:02:08 +02:00
|
|
|
|
2017-07-03 11:26:52 +02:00
|
|
|
enum State {
|
|
|
|
|
LoadOK,
|
|
|
|
|
Reloading,
|
|
|
|
|
LoadFailed
|
|
|
|
|
};
|
|
|
|
|
|
2017-11-29 21:36:30 +01:00
|
|
|
static ChunkData filterChunk(const ChunkData &data,
|
|
|
|
|
const ChunkSelection &selection, bool revert);
|
|
|
|
|
QString makePatch(int fileIndex, int chunkIndex, const ChunkSelection &selection,
|
2016-10-19 16:44:25 +02:00
|
|
|
bool revert, bool addPrefix = false,
|
|
|
|
|
const QString &overriddenFileName = QString()) const;
|
2015-01-30 16:59:25 +01:00
|
|
|
|
2021-08-17 12:26:10 +02:00
|
|
|
void setDiffFiles(const QList<FileData> &data, const Utils::FilePath &directory,
|
2015-08-20 16:45:30 +03:00
|
|
|
const QString &startupFile = QString());
|
2015-01-30 16:59:25 +01:00
|
|
|
QList<FileData> diffFiles() const;
|
2021-08-17 12:26:10 +02:00
|
|
|
Utils::FilePath baseDirectory() const;
|
|
|
|
|
void setBaseDirectory(const Utils::FilePath &directory);
|
2015-08-20 16:45:30 +03:00
|
|
|
QString startupFile() const;
|
2015-01-30 16:59:25 +01:00
|
|
|
|
|
|
|
|
void setDescription(const QString &description);
|
|
|
|
|
QString description() const;
|
|
|
|
|
|
|
|
|
|
void setContextLineCount(int lines);
|
|
|
|
|
int contextLineCount() const;
|
|
|
|
|
void forceContextLineCount(int lines);
|
|
|
|
|
bool isContextLineCountForced() const;
|
|
|
|
|
void setIgnoreWhitespace(bool ignore);
|
|
|
|
|
bool ignoreWhitespace() const;
|
|
|
|
|
|
2015-06-04 15:54:10 +02:00
|
|
|
bool setContents(const QByteArray &contents) override;
|
2021-09-21 06:36:32 +02:00
|
|
|
Utils::FilePath fallbackSaveAsPath() const override;
|
2016-01-14 14:45:01 +01:00
|
|
|
QString fallbackSaveAsFileName() const override;
|
2013-05-07 14:02:08 +02:00
|
|
|
|
2017-06-29 12:03:10 +02:00
|
|
|
bool isSaveAsAllowed() const override;
|
2021-05-18 13:55:23 +02:00
|
|
|
bool save(QString *errorString, const Utils::FilePath &filePath, bool autoSave) override;
|
2015-01-30 16:59:25 +01:00
|
|
|
void reload();
|
2015-06-04 15:54:10 +02:00
|
|
|
bool reload(QString *errorString, ReloadFlag flag, ChangeType type) override;
|
2021-05-18 13:55:23 +02:00
|
|
|
OpenResult open(QString *errorString, const Utils::FilePath &filePath,
|
|
|
|
|
const Utils::FilePath &realFilePath) override;
|
2020-04-14 11:10:52 +02:00
|
|
|
bool selectEncoding();
|
2017-07-03 11:26:52 +02:00
|
|
|
State state() const { return m_state; }
|
2013-05-07 14:02:08 +02:00
|
|
|
|
2014-11-13 09:11:56 +01:00
|
|
|
QString plainText() const;
|
|
|
|
|
|
2015-01-30 16:59:25 +01:00
|
|
|
signals:
|
|
|
|
|
void temporaryStateChanged();
|
|
|
|
|
void documentChanged();
|
|
|
|
|
void descriptionChanged();
|
|
|
|
|
|
2013-05-07 14:02:08 +02:00
|
|
|
private:
|
2017-07-06 11:44:11 +02:00
|
|
|
void beginReload();
|
|
|
|
|
void endReload(bool success);
|
2015-01-30 16:59:25 +01:00
|
|
|
void setController(DiffEditorController *controller);
|
|
|
|
|
|
2017-12-06 21:30:57 +01:00
|
|
|
DiffEditorController *m_controller = nullptr;
|
2015-01-30 16:59:25 +01:00
|
|
|
QList<FileData> m_diffFiles;
|
2021-08-17 12:26:10 +02:00
|
|
|
Utils::FilePath m_baseDirectory;
|
2015-08-20 16:45:30 +03:00
|
|
|
QString m_startupFile;
|
2015-01-30 16:59:25 +01:00
|
|
|
QString m_description;
|
2017-12-06 21:30:57 +01:00
|
|
|
int m_contextLineCount = 3;
|
|
|
|
|
bool m_isContextLineCountForced = false;
|
|
|
|
|
bool m_ignoreWhitespace = false;
|
2017-07-03 11:26:52 +02:00
|
|
|
State m_state = LoadOK;
|
2015-01-30 16:59:25 +01:00
|
|
|
|
|
|
|
|
friend class ::DiffEditor::DiffEditorController;
|
2013-05-07 14:02:08 +02:00
|
|
|
};
|
|
|
|
|
|
2015-01-30 14:33:39 +01:00
|
|
|
} // namespace Internal
|
2013-05-07 14:02:08 +02:00
|
|
|
} // namespace DiffEditor
|