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
|
|
|
|
2016-07-13 15:55:18 +02:00
|
|
|
#include "diffeditorwidgetcontroller.h"
|
2015-03-10 14:19:38 +01:00
|
|
|
|
2014-03-10 12:57:48 +01:00
|
|
|
#include <QWidget>
|
|
|
|
|
#include <QTextCharFormat>
|
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-26 16:47:39 +02:00
|
|
|
class SideDiffData
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
// block number, visual line number.
|
|
|
|
|
QMap<int, int> m_lineNumbers;
|
|
|
|
|
// block number, fileInfo. Set for file lines only.
|
|
|
|
|
QMap<int, DiffFileInfo> m_fileInfo;
|
|
|
|
|
// block number, skipped lines and context info. Set for chunk lines only.
|
|
|
|
|
QMap<int, QPair<int, QString>> m_skippedLines;
|
|
|
|
|
// start block number, block count of a chunk, chunk index inside a file.
|
|
|
|
|
QMap<int, QPair<int, int>> m_chunkInfo;
|
|
|
|
|
// block number, separator. Set for file, chunk or span line.
|
|
|
|
|
QMap<int, bool> m_separators;
|
|
|
|
|
|
|
|
|
|
int m_lineNumberDigits = 1;
|
|
|
|
|
|
|
|
|
|
void setLineNumber(int blockNumber, int lineNumber);
|
|
|
|
|
void setFileInfo(int blockNumber, const DiffFileInfo &fileInfo);
|
|
|
|
|
void setSkippedLines(int blockNumber, int skippedLines, const QString &contextInfo = QString()) {
|
|
|
|
|
m_skippedLines[blockNumber] = qMakePair(skippedLines, contextInfo);
|
|
|
|
|
setSeparator(blockNumber, true);
|
|
|
|
|
}
|
|
|
|
|
void setChunkIndex(int startBlockNumber, int blockCount, int chunkIndex);
|
|
|
|
|
void setSeparator(int blockNumber, bool separator) {
|
|
|
|
|
m_separators[blockNumber] = separator;
|
|
|
|
|
}
|
|
|
|
|
bool isFileLine(int blockNumber) const {
|
|
|
|
|
return m_fileInfo.contains(blockNumber);
|
|
|
|
|
}
|
|
|
|
|
int blockNumberForFileIndex(int fileIndex) const;
|
|
|
|
|
int fileIndexForBlockNumber(int blockNumber) const;
|
|
|
|
|
int chunkIndexForBlockNumber(int blockNumber) const;
|
|
|
|
|
int chunkRowForBlockNumber(int blockNumber) const;
|
|
|
|
|
int chunkRowsCountForBlockNumber(int blockNumber) const;
|
|
|
|
|
bool isChunkLine(int blockNumber) const {
|
|
|
|
|
return m_skippedLines.contains(blockNumber);
|
|
|
|
|
}
|
|
|
|
|
private:
|
|
|
|
|
};
|
|
|
|
|
|
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);
|
2017-05-09 12:19:11 +02:00
|
|
|
|
|
|
|
|
TextEditor::TextEditorWidget *leftEditorWidget() const;
|
|
|
|
|
TextEditor::TextEditorWidget *rightEditorWidget() 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();
|
|
|
|
|
|
|
|
|
|
void clear(const QString &message = QString());
|
|
|
|
|
|
|
|
|
|
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);
|
2014-02-13 16:43:28 +01:00
|
|
|
void slotLeftJumpToOriginalFileRequested(int diffFileIndex,
|
|
|
|
|
int lineNumber, int columnNumber);
|
|
|
|
|
void slotRightJumpToOriginalFileRequested(int diffFileIndex,
|
|
|
|
|
int lineNumber, int columnNumber);
|
2018-02-15 10:29:14 +01:00
|
|
|
void slotLeftContextMenuRequested(QMenu *menu, int fileIndex,
|
2017-11-29 21:36:30 +01:00
|
|
|
int chunkIndex, const ChunkSelection &selection);
|
2018-02-15 10:29:14 +01:00
|
|
|
void slotRightContextMenuRequested(QMenu *menu, int fileIndex,
|
2017-11-29 21:36:30 +01:00
|
|
|
int chunkIndex, const ChunkSelection &selection);
|
2013-05-22 16:33:44 +02:00
|
|
|
void leftVSliderChanged();
|
|
|
|
|
void rightVSliderChanged();
|
|
|
|
|
void leftHSliderChanged();
|
|
|
|
|
void rightHSliderChanged();
|
2013-05-23 13:36:27 +02:00
|
|
|
void leftCursorPositionChanged();
|
|
|
|
|
void rightCursorPositionChanged();
|
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();
|
|
|
|
|
|
2017-12-06 21:30:57 +01:00
|
|
|
SideDiffEditorWidget *m_leftEditor = nullptr;
|
|
|
|
|
SideDiffEditorWidget *m_rightEditor = nullptr;
|
|
|
|
|
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;
|
2013-06-05 15:25:42 +02:00
|
|
|
|
2014-02-13 16:43:28 +01:00
|
|
|
QTextCharFormat m_spanLineFormat;
|
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
|