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-02-15 12:49:50 +01:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2013-02-15 12:49:50 +01:00
|
|
|
|
2022-09-29 14:25:34 +02:00
|
|
|
#include "diffenums.h"
|
2016-07-13 15:55:18 +02:00
|
|
|
#include "diffeditorwidgetcontroller.h"
|
2022-09-27 15:48:33 +02:00
|
|
|
#include "selectabletexteditorwidget.h" // TODO: we need DiffSelections here only
|
2015-03-10 14:19:38 +01:00
|
|
|
|
2022-09-27 15:48:33 +02:00
|
|
|
#include <QFutureWatcher>
|
|
|
|
|
#include <QWidget>
|
2013-02-15 12:49:50 +01:00
|
|
|
|
2017-05-09 12:19:11 +02:00
|
|
|
namespace Core { class IContext; }
|
|
|
|
|
|
|
|
|
|
namespace TextEditor {
|
|
|
|
|
class FontSettings;
|
|
|
|
|
class TextEditorWidget;
|
|
|
|
|
}
|
2013-02-15 12:49:50 +01:00
|
|
|
|
|
|
|
|
QT_BEGIN_NAMESPACE
|
2014-02-13 16:43:28 +01:00
|
|
|
class QMenu;
|
2015-03-10 14:19:38 +01:00
|
|
|
class QSplitter;
|
2013-02-15 12:49:50 +01:00
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
2013-02-21 17:03:00 +01:00
|
|
|
namespace DiffEditor {
|
2015-01-30 14:46:20 +01:00
|
|
|
|
2016-07-13 15:55:18 +02:00
|
|
|
class FileData;
|
2013-02-15 12:49:50 +01:00
|
|
|
|
2015-01-30 14:55:56 +01:00
|
|
|
namespace Internal {
|
|
|
|
|
|
2015-03-10 14:19:38 +01:00
|
|
|
class DiffEditorDocument;
|
2015-01-30 14:55:56 +01:00
|
|
|
class SideDiffEditorWidget;
|
2022-09-27 15:48:33 +02:00
|
|
|
class SideBySideDiffOutput;
|
2015-01-30 14:55:56 +01:00
|
|
|
|
2022-09-26 16:47:39 +02:00
|
|
|
class SideDiffData
|
|
|
|
|
{
|
|
|
|
|
public:
|
2022-09-27 15:48:33 +02:00
|
|
|
static SideBySideDiffOutput diffOutput(QFutureInterface<void> &fi, int progressMin,
|
|
|
|
|
int progressMax, const DiffEditorInput &input);
|
|
|
|
|
|
2022-09-29 19:13:12 +02:00
|
|
|
DiffChunkInfo m_chunkInfo;
|
2022-09-26 16:47:39 +02:00
|
|
|
// block number, fileInfo. Set for file lines only.
|
|
|
|
|
QMap<int, DiffFileInfo> m_fileInfo;
|
2022-09-29 19:13:12 +02:00
|
|
|
// block number, visual line number.
|
|
|
|
|
QMap<int, int> m_lineNumbers;
|
2022-09-26 16:47:39 +02:00
|
|
|
// block number, skipped lines and context info. Set for chunk lines only.
|
|
|
|
|
QMap<int, QPair<int, QString>> m_skippedLines;
|
|
|
|
|
// block number, separator. Set for file, chunk or span line.
|
|
|
|
|
QMap<int, bool> m_separators;
|
|
|
|
|
|
|
|
|
|
int m_lineNumberDigits = 1;
|
|
|
|
|
|
2022-09-27 15:48:33 +02:00
|
|
|
bool isFileLine(int blockNumber) const { return m_fileInfo.contains(blockNumber); }
|
|
|
|
|
bool isChunkLine(int blockNumber) const { return m_skippedLines.contains(blockNumber); }
|
2022-09-26 16:47:39 +02:00
|
|
|
int blockNumberForFileIndex(int fileIndex) const;
|
|
|
|
|
int fileIndexForBlockNumber(int blockNumber) const;
|
2022-09-27 15:48:33 +02:00
|
|
|
|
2022-09-26 16:47:39 +02:00
|
|
|
private:
|
2022-09-27 15:48:33 +02:00
|
|
|
void setLineNumber(int blockNumber, int lineNumber);
|
|
|
|
|
void setFileInfo(int blockNumber, const DiffFileInfo &fileInfo);
|
|
|
|
|
void setSkippedLines(int blockNumber, int skippedLines, const QString &contextInfo = {}) {
|
|
|
|
|
m_skippedLines[blockNumber] = {skippedLines, contextInfo};
|
|
|
|
|
setSeparator(blockNumber, true);
|
|
|
|
|
}
|
|
|
|
|
void setSeparator(int blockNumber, bool separator) { m_separators[blockNumber] = separator; }
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class SideDiffOutput
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
SideDiffData diffData;
|
|
|
|
|
QString diffText;
|
|
|
|
|
DiffSelections selections;
|
2022-09-26 16:47:39 +02:00
|
|
|
};
|
|
|
|
|
|
2022-09-27 15:48:33 +02:00
|
|
|
class SideBySideDiffOutput
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
std::array<SideDiffOutput, SideCount> side{};
|
|
|
|
|
// 'foldingIndent' is populated with <block number> and folding indentation
|
|
|
|
|
// value where 1 indicates start of new file and 2 indicates a diff chunk.
|
|
|
|
|
// Remaining lines (diff contents) are assigned 3.
|
|
|
|
|
QHash<int, int> foldingIndent;
|
|
|
|
|
};
|
|
|
|
|
|
2015-01-30 14:55:56 +01:00
|
|
|
class SideBySideDiffEditorWidget : public QWidget
|
2013-02-15 12:49:50 +01:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2017-12-06 21:30:57 +01:00
|
|
|
explicit SideBySideDiffEditorWidget(QWidget *parent = nullptr);
|
2022-09-28 11:32:13 +02:00
|
|
|
~SideBySideDiffEditorWidget();
|
2017-05-09 12:19:11 +02:00
|
|
|
|
2022-09-29 14:25:34 +02:00
|
|
|
TextEditor::TextEditorWidget *sideEditorWidget(DiffSide side) const;
|
2013-02-15 12:49:50 +01:00
|
|
|
|
2015-01-30 16:59:25 +01:00
|
|
|
void setDocument(DiffEditorDocument *document);
|
2016-11-23 11:20:12 +01:00
|
|
|
DiffEditorDocument *diffDocument() const;
|
2013-12-16 16:19:40 +01:00
|
|
|
|
2021-08-17 12:16:20 +02:00
|
|
|
void setDiff(const QList<FileData> &diffFileList);
|
2013-12-16 16:19:40 +01:00
|
|
|
void setCurrentDiffFileIndex(int diffFileIndex);
|
2013-02-15 12:49:50 +01:00
|
|
|
|
2015-01-30 16:59:25 +01:00
|
|
|
void setHorizontalSync(bool sync);
|
|
|
|
|
|
|
|
|
|
void saveState();
|
|
|
|
|
void restoreState();
|
|
|
|
|
|
2022-09-27 15:13:33 +02:00
|
|
|
void clear(const QString &message = {});
|
2015-01-30 16:59:25 +01:00
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
void currentDiffFileIndexChanged(int index);
|
|
|
|
|
|
2017-03-18 23:31:08 +02:00
|
|
|
private:
|
2013-06-05 15:25:42 +02:00
|
|
|
void setFontSettings(const TextEditor::FontSettings &fontSettings);
|
2022-09-29 14:25:34 +02:00
|
|
|
void jumpToOriginalFileRequested(DiffSide side, int diffFileIndex,
|
|
|
|
|
int lineNumber, int columnNumber);
|
|
|
|
|
void contextMenuRequested(DiffSide side, QMenu *menu, int fileIndex, int chunkIndex,
|
|
|
|
|
const ChunkSelection &selection);
|
|
|
|
|
void verticalSliderChanged(DiffSide side);
|
|
|
|
|
void horizontalSliderChanged(DiffSide side);
|
|
|
|
|
void cursorPositionChanged(DiffSide side);
|
2018-05-16 13:28:29 +02:00
|
|
|
void syncHorizontalScrollBarPolicy();
|
2017-11-02 13:06:38 +01:00
|
|
|
void handlePositionChange(SideDiffEditorWidget *source, SideDiffEditorWidget *dest);
|
|
|
|
|
void syncCursor(SideDiffEditorWidget *source, SideDiffEditorWidget *dest);
|
2013-02-15 12:49:50 +01:00
|
|
|
|
|
|
|
|
void showDiff();
|
|
|
|
|
|
2022-09-29 14:25:34 +02:00
|
|
|
std::array<SideDiffEditorWidget *, SideCount> m_editor{};
|
2017-12-06 21:30:57 +01:00
|
|
|
QSplitter *m_splitter = nullptr;
|
2013-02-15 12:49:50 +01:00
|
|
|
|
2016-07-13 15:55:18 +02:00
|
|
|
DiffEditorWidgetController m_controller;
|
2013-02-15 12:49:50 +01:00
|
|
|
|
2016-07-13 15:55:18 +02:00
|
|
|
bool m_horizontalSync = false;
|
2022-09-28 11:32:13 +02:00
|
|
|
|
|
|
|
|
struct ShowResult
|
|
|
|
|
{
|
|
|
|
|
QSharedPointer<TextEditor::TextDocument> textDocument{};
|
|
|
|
|
SideDiffData diffData;
|
|
|
|
|
DiffSelections selections;
|
|
|
|
|
};
|
|
|
|
|
using ShowResults = std::array<ShowResult, SideCount>;
|
|
|
|
|
|
|
|
|
|
std::unique_ptr<QFutureWatcher<ShowResults>> m_watcher;
|
2013-02-15 12:49:50 +01:00
|
|
|
};
|
|
|
|
|
|
2015-01-30 14:55:56 +01:00
|
|
|
} // namespace Internal
|
2013-02-21 17:03:00 +01:00
|
|
|
} // namespace DiffEditor
|