diff options
author | Jarek Kobus <jaroslaw.kobus@qt.io> | 2022-07-22 12:12:33 +0200 |
---|---|---|
committer | Jarek Kobus <jaroslaw.kobus@qt.io> | 2022-07-25 13:02:43 +0000 |
commit | d96bfdff84019e2df66055acf72abd7ca2e9735d (patch) | |
tree | 7ddedcec4fa04607b5c865e9208dcd44cab3a487 /src/plugins/diffeditor/unifieddiffeditorwidget.cpp | |
parent | 256b983d285818e2526df1455d12b17623b6b75e (diff) | |
download | qt-creator-d96bfdff84019e2df66055acf72abd7ca2e9735d.tar.gz |
DiffEditorWidgetController: Use Utils::Guard
Change-Id: I3d3e22ce26c85859eb8024f2b87c7c85c5ac65f1
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Diffstat (limited to 'src/plugins/diffeditor/unifieddiffeditorwidget.cpp')
-rw-r--r-- | src/plugins/diffeditor/unifieddiffeditorwidget.cpp | 40 |
1 files changed, 15 insertions, 25 deletions
diff --git a/src/plugins/diffeditor/unifieddiffeditorwidget.cpp b/src/plugins/diffeditor/unifieddiffeditorwidget.cpp index fc187cc237..640e91d7fa 100644 --- a/src/plugins/diffeditor/unifieddiffeditorwidget.cpp +++ b/src/plugins/diffeditor/unifieddiffeditorwidget.cpp @@ -47,6 +47,7 @@ using namespace Core; using namespace TextEditor; +using namespace Utils; namespace DiffEditor { namespace Internal { @@ -112,11 +113,9 @@ void UnifiedDiffEditorWidget::restoreState() if (m_state.isNull()) return; - const bool oldIgnore = m_controller.m_ignoreCurrentIndexChange; - m_controller.m_ignoreCurrentIndexChange = true; + const GuardLocker locker(m_controller.m_ignoreChanges); SelectableTextEditorWidget::restoreState(m_state); m_state.clear(); - m_controller.m_ignoreCurrentIndexChange = oldIgnore; } void UnifiedDiffEditorWidget::setDisplaySettings(const DisplaySettings &ds) @@ -136,13 +135,11 @@ void UnifiedDiffEditorWidget::setFontSettings(const FontSettings &fontSettings) void UnifiedDiffEditorWidget::slotCursorPositionChangedInEditor() { - if (m_controller.m_ignoreCurrentIndexChange) + if (m_controller.m_ignoreChanges.isLocked()) return; - const bool oldIgnore = m_controller.m_ignoreCurrentIndexChange; - m_controller.m_ignoreCurrentIndexChange = true; + const GuardLocker locker(m_controller.m_ignoreChanges); emit currentDiffFileIndexChanged(fileIndexForBlockNumber(textCursor().blockNumber())); - m_controller.m_ignoreCurrentIndexChange = oldIgnore; } void UnifiedDiffEditorWidget::mouseDoubleClickEvent(QMouseEvent *e) @@ -245,12 +242,10 @@ void UnifiedDiffEditorWidget::clear(const QString &message) m_chunkInfo.clear(); setSelections(QMap<int, QList<DiffSelection> >()); - const bool oldIgnore = m_controller.m_ignoreCurrentIndexChange; - m_controller.m_ignoreCurrentIndexChange = true; + const GuardLocker locker(m_controller.m_ignoreChanges); SelectableTextEditorWidget::clear(); m_controller.m_contextFileData.clear(); setPlainText(message); - m_controller.m_ignoreCurrentIndexChange = oldIgnore; } QString UnifiedDiffEditorWidget::lineNumber(int blockNumber) const @@ -317,12 +312,10 @@ void UnifiedDiffEditorWidget::setChunkIndex(int startBlockNumber, void UnifiedDiffEditorWidget::setDiff(const QList<FileData> &diffFileList) { - const bool oldIgnore = m_controller.m_ignoreCurrentIndexChange; - m_controller.m_ignoreCurrentIndexChange = true; + const GuardLocker locker(m_controller.m_ignoreChanges); clear(); m_controller.m_contextFileData = diffFileList; showDiff(); - m_controller.m_ignoreCurrentIndexChange = oldIgnore; } QString UnifiedDiffEditorWidget::showChunk(const ChunkData &chunkData, @@ -563,15 +556,14 @@ void UnifiedDiffEditorWidget::showDiff() } diffText.replace('\r', ' '); - const bool oldIgnore = m_controller.m_ignoreCurrentIndexChange; - m_controller.m_ignoreCurrentIndexChange = true; - setPlainText(diffText); + { + const GuardLocker locker(m_controller.m_ignoreChanges); + setPlainText(diffText); - QTextBlock block = document()->firstBlock(); - for (int b = 0; block.isValid(); block = block.next(), ++b) - setFoldingIndent(block, foldingIndent.value(b, 3)); - - m_controller.m_ignoreCurrentIndexChange = oldIgnore; + QTextBlock block = document()->firstBlock(); + for (int b = 0; block.isValid(); block = block.next(), ++b) + setFoldingIndent(block, foldingIndent.value(b, 3)); + } setSelections(selections); } @@ -662,11 +654,10 @@ void UnifiedDiffEditorWidget::jumpToOriginalFile(const QTextCursor &cursor) void UnifiedDiffEditorWidget::setCurrentDiffFileIndex(int diffFileIndex) { - if (m_controller.m_ignoreCurrentIndexChange) + if (m_controller.m_ignoreChanges.isLocked()) return; - const bool oldIgnore = m_controller.m_ignoreCurrentIndexChange; - m_controller.m_ignoreCurrentIndexChange = true; + const GuardLocker locker(m_controller.m_ignoreChanges); const int blockNumber = blockNumberForFileIndex(diffFileIndex); QTextBlock block = document()->findBlockByNumber(blockNumber); @@ -674,7 +665,6 @@ void UnifiedDiffEditorWidget::setCurrentDiffFileIndex(int diffFileIndex) cursor.setPosition(block.position()); setTextCursor(cursor); verticalScrollBar()->setValue(blockNumber); - m_controller.m_ignoreCurrentIndexChange = oldIgnore; } } // namespace Internal |