forked from qt-creator/qt-creator
Reuse the Guard class
Change-Id: Ia742ab92fd7947f4d156d03e112ee32363312996 Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
@@ -26,11 +26,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "utils_global.h"
|
#include "utils_global.h"
|
||||||
|
#include <QtGlobal>
|
||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT Guard
|
class QTCREATOR_UTILS_EXPORT Guard
|
||||||
{
|
{
|
||||||
|
Q_DISABLE_COPY(Guard)
|
||||||
public:
|
public:
|
||||||
Guard();
|
Guard();
|
||||||
~Guard();
|
~Guard();
|
||||||
@@ -42,6 +44,7 @@ private:
|
|||||||
|
|
||||||
class QTCREATOR_UTILS_EXPORT GuardLocker
|
class QTCREATOR_UTILS_EXPORT GuardLocker
|
||||||
{
|
{
|
||||||
|
Q_DISABLE_COPY(GuardLocker)
|
||||||
public:
|
public:
|
||||||
GuardLocker(Guard &guard);
|
GuardLocker(Guard &guard);
|
||||||
~GuardLocker();
|
~GuardLocker();
|
||||||
|
@@ -69,19 +69,6 @@ static const char useDiffEditorKeyC[] = "UseDiffEditor";
|
|||||||
|
|
||||||
using namespace TextEditor;
|
using namespace TextEditor;
|
||||||
|
|
||||||
namespace {
|
|
||||||
|
|
||||||
class Guard
|
|
||||||
{
|
|
||||||
public:
|
|
||||||
Guard(int *state) : m_state(state) { ++(*state); }
|
|
||||||
~Guard() { --(*m_state); QTC_ASSERT(*m_state >= 0, return); }
|
|
||||||
private:
|
|
||||||
int *m_state;
|
|
||||||
};
|
|
||||||
|
|
||||||
} // namespace
|
|
||||||
|
|
||||||
namespace DiffEditor {
|
namespace DiffEditor {
|
||||||
namespace Internal {
|
namespace Internal {
|
||||||
|
|
||||||
@@ -226,7 +213,6 @@ DiffEditor::DiffEditor()
|
|||||||
, m_viewSwitcherAction(0)
|
, m_viewSwitcherAction(0)
|
||||||
, m_currentViewIndex(-1)
|
, m_currentViewIndex(-1)
|
||||||
, m_currentDiffFileIndex(-1)
|
, m_currentDiffFileIndex(-1)
|
||||||
, m_ignoreChanges(0)
|
|
||||||
, m_sync(false)
|
, m_sync(false)
|
||||||
, m_showDescription(true)
|
, m_showDescription(true)
|
||||||
{
|
{
|
||||||
@@ -329,7 +315,7 @@ void DiffEditor::setDocument(QSharedPointer<DiffEditorDocument>(doc))
|
|||||||
|
|
||||||
DiffEditor::DiffEditor(DiffEditorDocument *doc) : DiffEditor()
|
DiffEditor::DiffEditor(DiffEditorDocument *doc) : DiffEditor()
|
||||||
{
|
{
|
||||||
Guard guard(&m_ignoreChanges);
|
Utils::GuardLocker guard(m_ignoreChanges);
|
||||||
setDocument(QSharedPointer<DiffEditorDocument>(doc));
|
setDocument(QSharedPointer<DiffEditorDocument>(doc));
|
||||||
setupView(loadSettings());
|
setupView(loadSettings());
|
||||||
}
|
}
|
||||||
@@ -343,7 +329,7 @@ DiffEditor::~DiffEditor()
|
|||||||
Core::IEditor *DiffEditor::duplicate()
|
Core::IEditor *DiffEditor::duplicate()
|
||||||
{
|
{
|
||||||
DiffEditor *editor = new DiffEditor();
|
DiffEditor *editor = new DiffEditor();
|
||||||
Guard guard(&editor->m_ignoreChanges);
|
Utils::GuardLocker guard(editor->m_ignoreChanges);
|
||||||
|
|
||||||
editor->setDocument(m_document);
|
editor->setDocument(m_document);
|
||||||
editor->m_sync = m_sync;
|
editor->m_sync = m_sync;
|
||||||
@@ -371,7 +357,7 @@ QWidget *DiffEditor::toolBar()
|
|||||||
|
|
||||||
void DiffEditor::documentHasChanged()
|
void DiffEditor::documentHasChanged()
|
||||||
{
|
{
|
||||||
Guard guard(&m_ignoreChanges);
|
Utils::GuardLocker guard(m_ignoreChanges);
|
||||||
const QList<FileData> diffFileList = m_document->diffFiles();
|
const QList<FileData> diffFileList = m_document->diffFiles();
|
||||||
|
|
||||||
updateDescription();
|
updateDescription();
|
||||||
@@ -430,7 +416,7 @@ void DiffEditor::documentHasChanged()
|
|||||||
|
|
||||||
void DiffEditor::toggleDescription()
|
void DiffEditor::toggleDescription()
|
||||||
{
|
{
|
||||||
if (m_ignoreChanges > 0)
|
if (m_ignoreChanges.isLocked())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_showDescription = !m_showDescription;
|
m_showDescription = !m_showDescription;
|
||||||
@@ -446,7 +432,7 @@ void DiffEditor::updateDescription()
|
|||||||
m_descriptionWidget->setPlainText(description);
|
m_descriptionWidget->setPlainText(description);
|
||||||
m_descriptionWidget->setVisible(m_showDescription && !description.isEmpty());
|
m_descriptionWidget->setVisible(m_showDescription && !description.isEmpty());
|
||||||
|
|
||||||
Guard guard(&m_ignoreChanges);
|
Utils::GuardLocker guard(m_ignoreChanges);
|
||||||
m_toggleDescriptionAction->setChecked(m_showDescription);
|
m_toggleDescriptionAction->setChecked(m_showDescription);
|
||||||
m_toggleDescriptionAction->setToolTip(m_showDescription ? tr("Hide Change Description")
|
m_toggleDescriptionAction->setToolTip(m_showDescription ? tr("Hide Change Description")
|
||||||
: tr("Show Change Description"));
|
: tr("Show Change Description"));
|
||||||
@@ -458,7 +444,7 @@ void DiffEditor::updateDescription()
|
|||||||
void DiffEditor::contextLineCountHasChanged(int lines)
|
void DiffEditor::contextLineCountHasChanged(int lines)
|
||||||
{
|
{
|
||||||
QTC_ASSERT(!m_document->isContextLineCountForced(), return);
|
QTC_ASSERT(!m_document->isContextLineCountForced(), return);
|
||||||
if (m_ignoreChanges > 0 || lines == m_document->contextLineCount())
|
if (m_ignoreChanges.isLocked() || lines == m_document->contextLineCount())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
m_document->setContextLineCount(lines);
|
m_document->setContextLineCount(lines);
|
||||||
@@ -471,7 +457,7 @@ void DiffEditor::ignoreWhitespaceHasChanged()
|
|||||||
{
|
{
|
||||||
const bool ignore = m_whitespaceButtonAction->isChecked();
|
const bool ignore = m_whitespaceButtonAction->isChecked();
|
||||||
|
|
||||||
if (m_ignoreChanges > 0 || ignore == m_document->ignoreWhitespace())
|
if (m_ignoreChanges.isLocked() || ignore == m_document->ignoreWhitespace())
|
||||||
return;
|
return;
|
||||||
m_document->setIgnoreWhitespace(ignore);
|
m_document->setIgnoreWhitespace(ignore);
|
||||||
saveSetting(QLatin1String(ignoreWhitespaceKeyC), ignore);
|
saveSetting(QLatin1String(ignoreWhitespaceKeyC), ignore);
|
||||||
@@ -494,7 +480,7 @@ void DiffEditor::prepareForReload()
|
|||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
Guard guard(&m_ignoreChanges);
|
Utils::GuardLocker guard(m_ignoreChanges);
|
||||||
m_contextSpinBox->setValue(m_document->contextLineCount());
|
m_contextSpinBox->setValue(m_document->contextLineCount());
|
||||||
m_whitespaceButtonAction->setChecked(m_document->ignoreWhitespace());
|
m_whitespaceButtonAction->setChecked(m_document->ignoreWhitespace());
|
||||||
}
|
}
|
||||||
@@ -539,12 +525,12 @@ void DiffEditor::updateEntryToolTip()
|
|||||||
|
|
||||||
void DiffEditor::setCurrentDiffFileIndex(int index)
|
void DiffEditor::setCurrentDiffFileIndex(int index)
|
||||||
{
|
{
|
||||||
if (m_ignoreChanges > 0)
|
if (m_ignoreChanges.isLocked())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QTC_ASSERT((index < 0) != (m_entriesComboBox->count() > 0), return);
|
QTC_ASSERT((index < 0) != (m_entriesComboBox->count() > 0), return);
|
||||||
|
|
||||||
Guard guard(&m_ignoreChanges);
|
Utils::GuardLocker guard(m_ignoreChanges);
|
||||||
m_currentDiffFileIndex = index;
|
m_currentDiffFileIndex = index;
|
||||||
currentView()->setCurrentDiffFileIndex(index);
|
currentView()->setCurrentDiffFileIndex(index);
|
||||||
|
|
||||||
@@ -575,7 +561,7 @@ void DiffEditor::updateDiffEditorSwitcher()
|
|||||||
|
|
||||||
void DiffEditor::toggleSync()
|
void DiffEditor::toggleSync()
|
||||||
{
|
{
|
||||||
if (m_ignoreChanges > 0)
|
if (m_ignoreChanges.isLocked())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
QTC_ASSERT(currentView(), return);
|
QTC_ASSERT(currentView(), return);
|
||||||
@@ -669,7 +655,7 @@ void DiffEditor::setupView(IDiffView *view)
|
|||||||
saveSetting(QLatin1String(diffViewKeyC), currentView()->id().toSetting());
|
saveSetting(QLatin1String(diffViewKeyC), currentView()->id().toSetting());
|
||||||
|
|
||||||
{
|
{
|
||||||
Guard guard(&m_ignoreChanges);
|
Utils::GuardLocker guard(m_ignoreChanges);
|
||||||
m_toggleSyncAction->setVisible(currentView()->supportsSync());
|
m_toggleSyncAction->setVisible(currentView()->supportsSync());
|
||||||
m_toggleSyncAction->setToolTip(currentView()->syncToolTip());
|
m_toggleSyncAction->setToolTip(currentView()->syncToolTip());
|
||||||
m_toggleSyncAction->setText(currentView()->syncToolTip());
|
m_toggleSyncAction->setText(currentView()->syncToolTip());
|
||||||
|
@@ -29,6 +29,7 @@
|
|||||||
|
|
||||||
#include <coreplugin/editormanager/ieditor.h>
|
#include <coreplugin/editormanager/ieditor.h>
|
||||||
#include <coreplugin/idocument.h>
|
#include <coreplugin/idocument.h>
|
||||||
|
#include <utils/guard.h>
|
||||||
|
|
||||||
QT_BEGIN_NAMESPACE
|
QT_BEGIN_NAMESPACE
|
||||||
class QComboBox;
|
class QComboBox;
|
||||||
@@ -103,7 +104,7 @@ private:
|
|||||||
QPair<QString, QString> m_currentFileChunk;
|
QPair<QString, QString> m_currentFileChunk;
|
||||||
int m_currentViewIndex;
|
int m_currentViewIndex;
|
||||||
int m_currentDiffFileIndex;
|
int m_currentDiffFileIndex;
|
||||||
int m_ignoreChanges;
|
Utils::Guard m_ignoreChanges;
|
||||||
bool m_sync;
|
bool m_sync;
|
||||||
bool m_showDescription;
|
bool m_showDescription;
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user