forked from qt-creator/qt-creator
UnifiedDiffEditor: Move some methods into UnifiedDiffData
Like it's done in case of SideDiffData. Change-Id: I27af423e50277c81e596006c960daecc6a51145f Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
@@ -126,7 +126,7 @@ void UnifiedDiffEditorWidget::slotCursorPositionChangedInEditor()
|
|||||||
if (m_controller.m_ignoreChanges.isLocked())
|
if (m_controller.m_ignoreChanges.isLocked())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const int fileIndex = fileIndexForBlockNumber(textCursor().blockNumber());
|
const int fileIndex = m_data.fileIndexForBlockNumber(textCursor().blockNumber());
|
||||||
if (fileIndex < 0)
|
if (fileIndex < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -171,7 +171,7 @@ void UnifiedDiffEditorWidget::contextMenuEvent(QContextMenuEvent *e)
|
|||||||
QTextCursor cursor = cursorForPosition(e->pos());
|
QTextCursor cursor = cursorForPosition(e->pos());
|
||||||
const int blockNumber = cursor.blockNumber();
|
const int blockNumber = cursor.blockNumber();
|
||||||
|
|
||||||
const int fileIndex = fileIndexForBlockNumber(blockNumber);
|
const int fileIndex = m_data.fileIndexForBlockNumber(blockNumber);
|
||||||
const int chunkIndex = m_data.m_chunkInfo.chunkIndexForBlockNumber(blockNumber);
|
const int chunkIndex = m_data.m_chunkInfo.chunkIndexForBlockNumber(blockNumber);
|
||||||
|
|
||||||
const ChunkData chunkData = m_controller.chunkData(fileIndex, chunkIndex);
|
const ChunkData chunkData = m_controller.chunkData(fileIndex, chunkIndex);
|
||||||
@@ -179,7 +179,7 @@ void UnifiedDiffEditorWidget::contextMenuEvent(QContextMenuEvent *e)
|
|||||||
QList<int> leftSelection, rightSelection;
|
QList<int> leftSelection, rightSelection;
|
||||||
|
|
||||||
for (int i = startBlockNumber; i <= endBlockNumber; ++i) {
|
for (int i = startBlockNumber; i <= endBlockNumber; ++i) {
|
||||||
const int currentFileIndex = fileIndexForBlockNumber(i);
|
const int currentFileIndex = m_data.fileIndexForBlockNumber(i);
|
||||||
if (currentFileIndex < fileIndex)
|
if (currentFileIndex < fileIndex)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
@@ -204,7 +204,7 @@ void UnifiedDiffEditorWidget::contextMenuEvent(QContextMenuEvent *e)
|
|||||||
|
|
||||||
const ChunkSelection selection(leftSelection, rightSelection);
|
const ChunkSelection selection(leftSelection, rightSelection);
|
||||||
|
|
||||||
addContextMenuActions(menu, fileIndexForBlockNumber(blockNumber),
|
addContextMenuActions(menu, m_data.fileIndexForBlockNumber(blockNumber),
|
||||||
m_data.m_chunkInfo.chunkIndexForBlockNumber(blockNumber), selection);
|
m_data.m_chunkInfo.chunkIndexForBlockNumber(blockNumber), selection);
|
||||||
|
|
||||||
connect(this, &UnifiedDiffEditorWidget::destroyed, menu.data(), &QMenu::deleteLater);
|
connect(this, &UnifiedDiffEditorWidget::destroyed, menu.data(), &QMenu::deleteLater);
|
||||||
@@ -266,6 +266,24 @@ int UnifiedDiffEditorWidget::lineNumberDigits() const
|
|||||||
return m_data.m_lineNumberDigits[LeftSide] + m_data.m_lineNumberDigits[RightSide] + 1;
|
return m_data.m_lineNumberDigits[LeftSide] + m_data.m_lineNumberDigits[RightSide] + 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int UnifiedDiffData::blockNumberForFileIndex(int fileIndex) const
|
||||||
|
{
|
||||||
|
if (fileIndex < 0 || fileIndex >= m_fileInfo.count())
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return std::next(m_fileInfo.constBegin(), fileIndex).key();
|
||||||
|
}
|
||||||
|
|
||||||
|
int UnifiedDiffData::fileIndexForBlockNumber(int blockNumber) const
|
||||||
|
{
|
||||||
|
int i = -1;
|
||||||
|
for (auto it = m_fileInfo.cbegin(), end = m_fileInfo.cend(); it != end; ++it, ++i) {
|
||||||
|
if (it.key() > blockNumber)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return i;
|
||||||
|
}
|
||||||
|
|
||||||
void UnifiedDiffData::setLineNumber(DiffSide side, int blockNumber, int lineNumber, int rowNumberInChunk)
|
void UnifiedDiffData::setLineNumber(DiffSide side, int blockNumber, int lineNumber, int rowNumberInChunk)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(side < SideCount, return);
|
QTC_ASSERT(side < SideCount, return);
|
||||||
@@ -545,32 +563,13 @@ void UnifiedDiffEditorWidget::showDiff()
|
|||||||
ProgressManager::addTask(m_watcher->future(), tr("Rendering diff"), "DiffEditor");
|
ProgressManager::addTask(m_watcher->future(), tr("Rendering diff"), "DiffEditor");
|
||||||
}
|
}
|
||||||
|
|
||||||
int UnifiedDiffEditorWidget::blockNumberForFileIndex(int fileIndex) const
|
|
||||||
{
|
|
||||||
if (fileIndex < 0 || fileIndex >= m_data.m_fileInfo.count())
|
|
||||||
return -1;
|
|
||||||
|
|
||||||
return std::next(m_data.m_fileInfo.constBegin(), fileIndex).key();
|
|
||||||
}
|
|
||||||
|
|
||||||
int UnifiedDiffEditorWidget::fileIndexForBlockNumber(int blockNumber) const
|
|
||||||
{
|
|
||||||
int i = -1;
|
|
||||||
for (auto it = m_data.m_fileInfo.cbegin(), end = m_data.m_fileInfo.cend(); it != end; ++it, ++i) {
|
|
||||||
if (it.key() > blockNumber)
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
|
|
||||||
void UnifiedDiffEditorWidget::jumpToOriginalFile(const QTextCursor &cursor)
|
void UnifiedDiffEditorWidget::jumpToOriginalFile(const QTextCursor &cursor)
|
||||||
{
|
{
|
||||||
if (m_data.m_fileInfo.isEmpty())
|
if (m_data.m_fileInfo.isEmpty())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const int blockNumber = cursor.blockNumber();
|
const int blockNumber = cursor.blockNumber();
|
||||||
const int fileIndex = fileIndexForBlockNumber(blockNumber);
|
const int fileIndex = m_data.fileIndexForBlockNumber(blockNumber);
|
||||||
if (fileIndex < 0)
|
if (fileIndex < 0)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
@@ -619,7 +618,7 @@ void UnifiedDiffEditorWidget::setCurrentDiffFileIndex(int diffFileIndex)
|
|||||||
|
|
||||||
const GuardLocker locker(m_controller.m_ignoreChanges);
|
const GuardLocker locker(m_controller.m_ignoreChanges);
|
||||||
m_controller.setCurrentDiffFileIndex(diffFileIndex);
|
m_controller.setCurrentDiffFileIndex(diffFileIndex);
|
||||||
const int blockNumber = blockNumberForFileIndex(diffFileIndex);
|
const int blockNumber = m_data.blockNumberForFileIndex(diffFileIndex);
|
||||||
|
|
||||||
QTextBlock block = document()->findBlockByNumber(blockNumber);
|
QTextBlock block = document()->findBlockByNumber(blockNumber);
|
||||||
QTextCursor cursor = textCursor();
|
QTextCursor cursor = textCursor();
|
||||||
|
@@ -40,6 +40,9 @@ public:
|
|||||||
std::array<LineNumbers, SideCount> m_lineNumbers{};
|
std::array<LineNumbers, SideCount> m_lineNumbers{};
|
||||||
std::array<int, SideCount> m_lineNumberDigits{1, 1};
|
std::array<int, SideCount> m_lineNumberDigits{1, 1};
|
||||||
|
|
||||||
|
int blockNumberForFileIndex(int fileIndex) const;
|
||||||
|
int fileIndexForBlockNumber(int blockNumber) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void setLineNumber(DiffSide side, int blockNumber, int lineNumber, int rowNumberInChunk);
|
void setLineNumber(DiffSide side, int blockNumber, int lineNumber, int rowNumberInChunk);
|
||||||
QString setChunk(const DiffEditorInput &input, const ChunkData &chunkData,
|
QString setChunk(const DiffEditorInput &input, const ChunkData &chunkData,
|
||||||
@@ -91,12 +94,8 @@ protected:
|
|||||||
|
|
||||||
private:
|
private:
|
||||||
void setFontSettings(const TextEditor::FontSettings &fontSettings);
|
void setFontSettings(const TextEditor::FontSettings &fontSettings);
|
||||||
|
|
||||||
void slotCursorPositionChangedInEditor();
|
void slotCursorPositionChangedInEditor();
|
||||||
|
|
||||||
void showDiff();
|
void showDiff();
|
||||||
int blockNumberForFileIndex(int fileIndex) const;
|
|
||||||
int fileIndexForBlockNumber(int blockNumber) const;
|
|
||||||
void jumpToOriginalFile(const QTextCursor &cursor);
|
void jumpToOriginalFile(const QTextCursor &cursor);
|
||||||
void addContextMenuActions(QMenu *menu, int fileIndex, int chunkIndex,
|
void addContextMenuActions(QMenu *menu, int fileIndex, int chunkIndex,
|
||||||
const ChunkSelection &selection);
|
const ChunkSelection &selection);
|
||||||
|
Reference in New Issue
Block a user