2014-02-13 16:43:28 +01:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2014-02-13 16:43:28 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2014-02-13 16:43:28 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
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;
|
|
|
|
|
|
2015-01-30 14:51:44 +01:00
|
|
|
class UnifiedDiffEditorWidget : 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
|
|
|
|
|
|
|
|
void setDiff(const QList<FileData> &diffFileList,
|
|
|
|
|
const QString &workingDirectory);
|
|
|
|
|
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();
|
|
|
|
|
|
2017-11-29 21:36:30 +01:00
|
|
|
void setLeftLineNumber(int blockNumber, int lineNumber, int rowNumberInChunk);
|
|
|
|
|
void setRightLineNumber(int blockNumber, int lineNumber, int rowNumberInChunk);
|
2014-02-13 16:43:28 +01:00
|
|
|
void setFileInfo(int blockNumber,
|
|
|
|
|
const DiffFileInfo &leftFileInfo,
|
|
|
|
|
const DiffFileInfo &rightFileInfo);
|
|
|
|
|
void setChunkIndex(int startBlockNumber, int blockCount, int chunkIndex);
|
|
|
|
|
void showDiff();
|
|
|
|
|
QString showChunk(const ChunkData &chunkData,
|
|
|
|
|
bool lastChunk,
|
|
|
|
|
int *blockNumber,
|
|
|
|
|
int *charNumber,
|
|
|
|
|
QMap<int, QList<DiffSelection> > *selections);
|
|
|
|
|
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
|
|
|
|
2017-11-29 21:36:30 +01:00
|
|
|
// block number, visual line number, chunk row number
|
|
|
|
|
QMap<int, QPair<int, int> > m_leftLineNumbers;
|
|
|
|
|
QMap<int, QPair<int, int> > m_rightLineNumbers;
|
2014-02-13 16:43:28 +01:00
|
|
|
|
2016-07-13 15:55:18 +02:00
|
|
|
DiffEditorWidgetController m_controller;
|
|
|
|
|
|
|
|
|
|
int m_leftLineNumberDigits = 1;
|
|
|
|
|
int m_rightLineNumberDigits = 1;
|
2014-02-13 16:43:28 +01:00
|
|
|
// 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;
|
|
|
|
|
|
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
|