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
|
2014-02-13 16:43:28 +01:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2014-02-13 16:43:28 +01:00
|
|
|
|
|
|
|
|
#include "selectabletexteditorwidget.h"
|
2016-07-13 15:55:18 +02:00
|
|
|
#include "diffeditorwidgetcontroller.h"
|
2014-02-13 16:43:28 +01:00
|
|
|
|
2017-05-09 12:19:11 +02:00
|
|
|
namespace Core { class IContext; }
|
|
|
|
|
|
2014-02-13 16:43:28 +01:00
|
|
|
namespace TextEditor {
|
|
|
|
|
class DisplaySettings;
|
|
|
|
|
class FontSettings;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
namespace DiffEditor {
|
|
|
|
|
|
|
|
|
|
class ChunkData;
|
|
|
|
|
class FileData;
|
2017-11-29 21:36:30 +01:00
|
|
|
class ChunkSelection;
|
2014-02-13 16:43:28 +01:00
|
|
|
|
2015-01-30 14:51:44 +01:00
|
|
|
namespace Internal {
|
|
|
|
|
|
2015-03-10 14:19:38 +01:00
|
|
|
class DiffEditorDocument;
|
|
|
|
|
|
2022-09-22 11:00:38 +02:00
|
|
|
class UnifiedDiffOutput
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
QString diffText;
|
|
|
|
|
// '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;
|
|
|
|
|
|
|
|
|
|
QMap<int, QList<DiffSelection>> selections;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class UnifiedDiffData
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
UnifiedDiffOutput showDiff(const DiffEditorInput &input);
|
|
|
|
|
|
|
|
|
|
// block number, visual line number, chunk row number
|
|
|
|
|
QMap<int, QPair<int, int>> m_leftLineNumbers;
|
|
|
|
|
QMap<int, QPair<int, int>> m_rightLineNumbers;
|
|
|
|
|
|
|
|
|
|
int m_leftLineNumberDigits = 1;
|
|
|
|
|
int m_rightLineNumberDigits = 1;
|
|
|
|
|
|
|
|
|
|
// block number, visual line number.
|
|
|
|
|
QMap<int, QPair<DiffFileInfo, DiffFileInfo>> m_fileInfo;
|
|
|
|
|
// start block number, block count of a chunk, chunk index inside a file.
|
|
|
|
|
QMap<int, QPair<int, int>> m_chunkInfo;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void setLeftLineNumber(int blockNumber, int lineNumber, int rowNumberInChunk);
|
|
|
|
|
void setRightLineNumber(int blockNumber, int lineNumber, int rowNumberInChunk);
|
|
|
|
|
void setFileInfo(int blockNumber, const DiffFileInfo &leftInfo, const DiffFileInfo &rightInfo);
|
|
|
|
|
void setChunkIndex(int startBlockNumber, int blockCount, int chunkIndex);
|
|
|
|
|
QString showChunk(const DiffEditorInput &input, const ChunkData &chunkData, bool lastChunk,
|
|
|
|
|
int *blockNumber, int *charNumber,
|
|
|
|
|
QMap<int, QList<DiffSelection>> *selections);
|
|
|
|
|
};
|
|
|
|
|
|
2020-11-18 17:04:54 +01:00
|
|
|
class UnifiedDiffEditorWidget final : public SelectableTextEditorWidget
|
2014-02-13 16:43:28 +01:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
public:
|
2017-12-06 21:30:57 +01:00
|
|
|
UnifiedDiffEditorWidget(QWidget *parent = nullptr);
|
2014-02-13 16:43:28 +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;
|
2015-01-30 16:59:25 +01:00
|
|
|
|
2021-08-17 12:16:20 +02:00
|
|
|
void setDiff(const QList<FileData> &diffFileList);
|
2015-01-30 16:59:25 +01:00
|
|
|
void setCurrentDiffFileIndex(int diffFileIndex);
|
|
|
|
|
|
|
|
|
|
void saveState();
|
2020-04-23 14:14:05 +02:00
|
|
|
|
|
|
|
|
using TextEditor::TextEditorWidget::restoreState;
|
2015-01-30 16:59:25 +01:00
|
|
|
void restoreState();
|
|
|
|
|
|
|
|
|
|
void clear(const QString &message = QString());
|
2017-03-18 23:31:08 +02:00
|
|
|
void setDisplaySettings(const TextEditor::DisplaySettings &ds) override;
|
2015-01-30 16:59:25 +01:00
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
void currentDiffFileIndexChanged(int index);
|
2014-02-13 16:43:28 +01:00
|
|
|
|
|
|
|
|
protected:
|
2015-06-01 17:55:31 +02:00
|
|
|
void mouseDoubleClickEvent(QMouseEvent *e) override;
|
2017-07-30 08:53:27 +03:00
|
|
|
void keyPressEvent(QKeyEvent *e) override;
|
2015-06-01 17:55:31 +02:00
|
|
|
void contextMenuEvent(QContextMenuEvent *e) override;
|
|
|
|
|
QString lineNumber(int blockNumber) const override;
|
|
|
|
|
int lineNumberDigits() const override;
|
2014-02-13 16:43:28 +01:00
|
|
|
|
2017-03-18 23:31:08 +02:00
|
|
|
private:
|
2014-02-13 16:43:28 +01:00
|
|
|
void setFontSettings(const TextEditor::FontSettings &fontSettings);
|
|
|
|
|
|
|
|
|
|
void slotCursorPositionChangedInEditor();
|
|
|
|
|
|
|
|
|
|
void showDiff();
|
|
|
|
|
int blockNumberForFileIndex(int fileIndex) const;
|
|
|
|
|
int fileIndexForBlockNumber(int blockNumber) const;
|
|
|
|
|
int chunkIndexForBlockNumber(int blockNumber) const;
|
|
|
|
|
void jumpToOriginalFile(const QTextCursor &cursor);
|
|
|
|
|
void addContextMenuActions(QMenu *menu,
|
2018-02-15 10:29:14 +01:00
|
|
|
int fileIndex,
|
2017-11-29 21:36:30 +01:00
|
|
|
int chunkIndex,
|
|
|
|
|
const ChunkSelection &selection);
|
2014-02-13 16:43:28 +01:00
|
|
|
|
2022-09-22 11:00:38 +02:00
|
|
|
UnifiedDiffData m_data;
|
2016-07-13 15:55:18 +02:00
|
|
|
DiffEditorWidgetController m_controller;
|
2014-07-11 12:55:31 +02:00
|
|
|
QByteArray m_state;
|
2014-02-13 16:43:28 +01:00
|
|
|
};
|
|
|
|
|
|
2015-01-30 14:51:44 +01:00
|
|
|
} // namespace Internal
|
2014-02-13 16:43:28 +01:00
|
|
|
} // namespace DiffEditor
|