forked from qt-creator/qt-creator
CppEditor: Reuse QScopeGuard instead of ExecuteOnDestruction
Change-Id: Ia60c8eab687599dbaa519daeab74e8799c33af95 Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org> Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -23,7 +23,6 @@
|
|||||||
#include <qtsupport/qtkitinformation.h>
|
#include <qtsupport/qtkitinformation.h>
|
||||||
|
|
||||||
#include <utils/environment.h>
|
#include <utils/environment.h>
|
||||||
#include <utils/executeondestruction.h>
|
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
|
|
||||||
#include <QSignalSpy>
|
#include <QSignalSpy>
|
||||||
|
@@ -8,7 +8,6 @@
|
|||||||
#include "wrappablelineedit.h"
|
#include "wrappablelineedit.h"
|
||||||
|
|
||||||
#include <utils/environment.h>
|
#include <utils/environment.h>
|
||||||
#include <utils/executeondestruction.h>
|
|
||||||
#include <utils/infolabel.h>
|
#include <utils/infolabel.h>
|
||||||
#include <utils/layoutbuilder.h>
|
#include <utils/layoutbuilder.h>
|
||||||
#include <utils/stringutils.h>
|
#include <utils/stringutils.h>
|
||||||
@@ -21,6 +20,7 @@
|
|||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
#include <QScopeGuard>
|
||||||
#include <QTabWidget>
|
#include <QTabWidget>
|
||||||
#include <QTreeView>
|
#include <QTreeView>
|
||||||
|
|
||||||
@@ -323,7 +323,7 @@ void ClangDiagnosticConfigsWidget::sync()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
disconnectClangOnlyOptionsChanged();
|
disconnectClangOnlyOptionsChanged();
|
||||||
ExecuteOnDestruction e([this] { connectClangOnlyOptionsChanged(); });
|
const QScopeGuard cleanup([this] { connectClangOnlyOptionsChanged(); });
|
||||||
|
|
||||||
// Update main button row
|
// Update main button row
|
||||||
const ClangDiagnosticConfig &config = currentConfig();
|
const ClangDiagnosticConfig &config = currentConfig();
|
||||||
|
@@ -20,8 +20,8 @@
|
|||||||
#include <texteditor/textdocument.h>
|
#include <texteditor/textdocument.h>
|
||||||
#include <texteditor/texteditor.h>
|
#include <texteditor/texteditor.h>
|
||||||
#include <texteditor/texteditorsettings.h>
|
#include <texteditor/texteditorsettings.h>
|
||||||
#include <utils/executeondestruction.h>
|
|
||||||
|
|
||||||
|
#include <QScopeGuard>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
#endif // WITH_TESTS
|
#endif // WITH_TESTS
|
||||||
@@ -267,9 +267,7 @@ void AutoCompleterTest::testAutoComplete()
|
|||||||
|
|
||||||
QVERIFY(text.contains(QLatin1Char('|')));
|
QVERIFY(text.contains(QLatin1Char('|')));
|
||||||
|
|
||||||
Utils::ExecuteOnDestruction guard([](){
|
const QScopeGuard cleanup([] { Core::EditorManager::closeAllEditors(false); });
|
||||||
Core::EditorManager::closeAllEditors(false);
|
|
||||||
});
|
|
||||||
QTextCursor tc = openEditor(text);
|
QTextCursor tc = openEditor(text);
|
||||||
|
|
||||||
QVERIFY(!tc.isNull());
|
QVERIFY(!tc.isNull());
|
||||||
@@ -328,9 +326,7 @@ void AutoCompleterTest::testSurroundWithSelection()
|
|||||||
|
|
||||||
QVERIFY(text.count(QLatin1Char('|')) == 2);
|
QVERIFY(text.count(QLatin1Char('|')) == 2);
|
||||||
|
|
||||||
Utils::ExecuteOnDestruction guard([](){
|
const QScopeGuard cleanup([] { Core::EditorManager::closeAllEditors(false); });
|
||||||
Core::EditorManager::closeAllEditors(false);
|
|
||||||
});
|
|
||||||
QTextCursor tc = openEditor(text);
|
QTextCursor tc = openEditor(text);
|
||||||
|
|
||||||
QVERIFY(!tc.isNull());
|
QVERIFY(!tc.isNull());
|
||||||
@@ -363,9 +359,7 @@ void AutoCompleterTest::testAutoBackspace()
|
|||||||
|
|
||||||
QVERIFY(text.contains(QLatin1Char('|')));
|
QVERIFY(text.contains(QLatin1Char('|')));
|
||||||
|
|
||||||
Utils::ExecuteOnDestruction guard([](){
|
const QScopeGuard cleanup([] { Core::EditorManager::closeAllEditors(false); });
|
||||||
Core::EditorManager::closeAllEditors(false);
|
|
||||||
});
|
|
||||||
QTextCursor tc = openEditor(text);
|
QTextCursor tc = openEditor(text);
|
||||||
|
|
||||||
QVERIFY(!tc.isNull());
|
QVERIFY(!tc.isNull());
|
||||||
@@ -405,9 +399,7 @@ void AutoCompleterTest::testInsertParagraph()
|
|||||||
|
|
||||||
QVERIFY(text.contains(QLatin1Char('|')));
|
QVERIFY(text.contains(QLatin1Char('|')));
|
||||||
|
|
||||||
Utils::ExecuteOnDestruction guard([](){
|
const QScopeGuard cleanup([] { Core::EditorManager::closeAllEditors(false); });
|
||||||
Core::EditorManager::closeAllEditors(false);
|
|
||||||
});
|
|
||||||
QTextCursor tc = openEditor(text);
|
QTextCursor tc = openEditor(text);
|
||||||
|
|
||||||
QVERIFY(!tc.isNull());
|
QVERIFY(!tc.isNull());
|
||||||
|
@@ -16,12 +16,12 @@
|
|||||||
#include <app/app_version.h>
|
#include <app/app_version.h>
|
||||||
#include <coreplugin/messagemanager.h>
|
#include <coreplugin/messagemanager.h>
|
||||||
#include <texteditor/basehoverhandler.h>
|
#include <texteditor/basehoverhandler.h>
|
||||||
#include <utils/executeondestruction.h>
|
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/textutils.h>
|
#include <utils/textutils.h>
|
||||||
|
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
#include <QFile>
|
#include <QFile>
|
||||||
|
#include <QScopeGuard>
|
||||||
#include <QTextDocument>
|
#include <QTextDocument>
|
||||||
|
|
||||||
using namespace Core;
|
using namespace Core;
|
||||||
@@ -42,7 +42,7 @@ private:
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils::ExecuteOnDestruction reportPriority([this, report](){ report(priority()); });
|
const QScopeGuard cleanup([this, report] { report(priority()); });
|
||||||
|
|
||||||
QTextCursor tc(editorWidget->document());
|
QTextCursor tc(editorWidget->document());
|
||||||
tc.setPosition(pos);
|
tc.setPosition(pos);
|
||||||
|
@@ -23,7 +23,6 @@
|
|||||||
#include <texteditor/textdocumentlayout.h>
|
#include <texteditor/textdocumentlayout.h>
|
||||||
#include <texteditor/texteditorsettings.h>
|
#include <texteditor/texteditorsettings.h>
|
||||||
|
|
||||||
#include <utils/executeondestruction.h>
|
|
||||||
#include <utils/infobar.h>
|
#include <utils/infobar.h>
|
||||||
#include <utils/mimeutils.h>
|
#include <utils/mimeutils.h>
|
||||||
#include <utils/minimizableinfobars.h>
|
#include <utils/minimizableinfobars.h>
|
||||||
@@ -31,6 +30,7 @@
|
|||||||
#include <utils/utilsicons.h>
|
#include <utils/utilsicons.h>
|
||||||
|
|
||||||
#include <QApplication>
|
#include <QApplication>
|
||||||
|
#include <QScopeGuard>
|
||||||
#include <QTextDocument>
|
#include <QTextDocument>
|
||||||
|
|
||||||
const char NO_PROJECT_CONFIGURATION[] = "NoProject";
|
const char NO_PROJECT_CONFIGURATION[] = "NoProject";
|
||||||
@@ -437,47 +437,45 @@ TextEditor::TabSettings CppEditorDocument::tabSettings() const
|
|||||||
|
|
||||||
bool CppEditorDocument::save(QString *errorString, const FilePath &filePath, bool autoSave)
|
bool CppEditorDocument::save(QString *errorString, const FilePath &filePath, bool autoSave)
|
||||||
{
|
{
|
||||||
ExecuteOnDestruction resetSettingsOnScopeExit;
|
if (!indenter()->formatOnSave() || autoSave)
|
||||||
|
return TextEditor::TextDocument::save(errorString, filePath, autoSave);
|
||||||
|
|
||||||
if (indenter()->formatOnSave() && !autoSave) {
|
auto *layout = qobject_cast<TextEditor::TextDocumentLayout *>(document()->documentLayout());
|
||||||
auto *layout = qobject_cast<TextEditor::TextDocumentLayout *>(document()->documentLayout());
|
const int documentRevision = layout->lastSaveRevision;
|
||||||
const int documentRevision = layout->lastSaveRevision;
|
|
||||||
|
|
||||||
TextEditor::RangesInLines editedRanges;
|
TextEditor::RangesInLines editedRanges;
|
||||||
TextEditor::RangeInLines lastRange{-1, -1};
|
TextEditor::RangeInLines lastRange{-1, -1};
|
||||||
for (int i = 0; i < document()->blockCount(); ++i) {
|
for (int i = 0; i < document()->blockCount(); ++i) {
|
||||||
const QTextBlock block = document()->findBlockByNumber(i);
|
const QTextBlock block = document()->findBlockByNumber(i);
|
||||||
if (block.revision() == documentRevision) {
|
if (block.revision() == documentRevision) {
|
||||||
if (lastRange.startLine != -1)
|
if (lastRange.startLine != -1)
|
||||||
editedRanges.push_back(lastRange);
|
editedRanges.push_back(lastRange);
|
||||||
|
|
||||||
lastRange.startLine = lastRange.endLine = -1;
|
lastRange.startLine = lastRange.endLine = -1;
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
// block.revision() != documentRevision
|
|
||||||
if (lastRange.startLine == -1)
|
|
||||||
lastRange.startLine = block.blockNumber() + 1;
|
|
||||||
lastRange.endLine = block.blockNumber() + 1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lastRange.startLine != -1)
|
// block.revision() != documentRevision
|
||||||
editedRanges.push_back(lastRange);
|
if (lastRange.startLine == -1)
|
||||||
|
lastRange.startLine = block.blockNumber() + 1;
|
||||||
if (!editedRanges.empty()) {
|
lastRange.endLine = block.blockNumber() + 1;
|
||||||
QTextCursor cursor(document());
|
|
||||||
cursor.joinPreviousEditBlock();
|
|
||||||
indenter()->format(editedRanges);
|
|
||||||
cursor.endEditBlock();
|
|
||||||
}
|
|
||||||
|
|
||||||
TextEditor::StorageSettings settings = storageSettings();
|
|
||||||
resetSettingsOnScopeExit.reset(
|
|
||||||
[this, defaultSettings = settings]() { setStorageSettings(defaultSettings); });
|
|
||||||
settings.m_cleanWhitespace = false;
|
|
||||||
setStorageSettings(settings);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (lastRange.startLine != -1)
|
||||||
|
editedRanges.push_back(lastRange);
|
||||||
|
|
||||||
|
if (!editedRanges.empty()) {
|
||||||
|
QTextCursor cursor(document());
|
||||||
|
cursor.joinPreviousEditBlock();
|
||||||
|
indenter()->format(editedRanges);
|
||||||
|
cursor.endEditBlock();
|
||||||
|
}
|
||||||
|
|
||||||
|
TextEditor::StorageSettings settings = storageSettings();
|
||||||
|
const QScopeGuard cleanup([this, settings] { setStorageSettings(settings); });
|
||||||
|
settings.m_cleanWhitespace = false;
|
||||||
|
setStorageSettings(settings);
|
||||||
|
|
||||||
return TextEditor::TextDocument::save(errorString, filePath, autoSave);
|
return TextEditor::TextDocument::save(errorString, filePath, autoSave);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -20,11 +20,11 @@
|
|||||||
#include <projectexplorer/projectexplorer.h>
|
#include <projectexplorer/projectexplorer.h>
|
||||||
#include <projectexplorer/projectmanager.h>
|
#include <projectexplorer/projectmanager.h>
|
||||||
|
|
||||||
#include <utils/executeondestruction.h>
|
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
|
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
|
#include <QScopeGuard>
|
||||||
#include <QtTest>
|
#include <QtTest>
|
||||||
|
|
||||||
#define VERIFY_DOCUMENT_REVISION(document, expectedRevision) \
|
#define VERIFY_DOCUMENT_REVISION(document, expectedRevision) \
|
||||||
@@ -1085,9 +1085,7 @@ void ModelManagerTest::testRenameIncludesInEditor()
|
|||||||
Core::IEditor *editor = Core::EditorManager::openEditor(mainFile);
|
Core::IEditor *editor = Core::EditorManager::openEditor(mainFile);
|
||||||
QVERIFY(editor);
|
QVERIFY(editor);
|
||||||
EditorCloser editorCloser(editor);
|
EditorCloser editorCloser(editor);
|
||||||
Utils::ExecuteOnDestruction saveAllFiles([](){
|
const QScopeGuard cleanup([] { Core::DocumentManager::saveAllModifiedDocumentsSilently(); });
|
||||||
Core::DocumentManager::saveAllModifiedDocumentsSilently();
|
|
||||||
});
|
|
||||||
QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1);
|
QCOMPARE(Core::DocumentModel::openedDocuments().size(), 1);
|
||||||
QVERIFY(modelManager->isCppEditor(editor));
|
QVERIFY(modelManager->isCppEditor(editor));
|
||||||
QVERIFY(modelManager->workingCopy().get(mainFile));
|
QVERIFY(modelManager->workingCopy().get(mainFile));
|
||||||
|
@@ -26,7 +26,6 @@
|
|||||||
#include <texteditor/storagesettings.h>
|
#include <texteditor/storagesettings.h>
|
||||||
|
|
||||||
#include <utils/environment.h>
|
#include <utils/environment.h>
|
||||||
#include <utils/executeondestruction.h>
|
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
@@ -376,11 +375,8 @@ ProjectOpenerAndCloser::~ProjectOpenerAndCloser()
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
bool hasGcFinished = false;
|
bool hasGcFinished = false;
|
||||||
QMetaObject::Connection connection;
|
auto connection = QObject::connect(CppModelManager::instance(), &CppModelManager::gcFinished,
|
||||||
Utils::ExecuteOnDestruction disconnect([&]() { QObject::disconnect(connection); });
|
[&hasGcFinished] { hasGcFinished = true; });
|
||||||
connection = QObject::connect(CppModelManager::instance(), &CppModelManager::gcFinished, [&]() {
|
|
||||||
hasGcFinished = true;
|
|
||||||
});
|
|
||||||
|
|
||||||
for (Project *project : std::as_const(m_openProjects))
|
for (Project *project : std::as_const(m_openProjects))
|
||||||
ProjectExplorerPlugin::unloadProject(project);
|
ProjectExplorerPlugin::unloadProject(project);
|
||||||
@@ -389,6 +385,8 @@ ProjectOpenerAndCloser::~ProjectOpenerAndCloser()
|
|||||||
t.start();
|
t.start();
|
||||||
while (!hasGcFinished && t.elapsed() <= 30000)
|
while (!hasGcFinished && t.elapsed() <= 30000)
|
||||||
QCoreApplication::processEvents();
|
QCoreApplication::processEvents();
|
||||||
|
|
||||||
|
QObject::disconnect(connection);
|
||||||
}
|
}
|
||||||
|
|
||||||
ProjectInfo::ConstPtr ProjectOpenerAndCloser::open(const FilePath &projectFile,
|
ProjectInfo::ConstPtr ProjectOpenerAndCloser::open(const FilePath &projectFile,
|
||||||
|
@@ -8,13 +8,13 @@
|
|||||||
#include <projectexplorer/projectnodes.h>
|
#include <projectexplorer/projectnodes.h>
|
||||||
#include <projectexplorer/projecttree.h>
|
#include <projectexplorer/projecttree.h>
|
||||||
#include <texteditor/texteditor.h>
|
#include <texteditor/texteditor.h>
|
||||||
#include <utils/executeondestruction.h>
|
|
||||||
#include <utils/fileutils.h>
|
#include <utils/fileutils.h>
|
||||||
#include <utils/mimeutils.h>
|
#include <utils/mimeutils.h>
|
||||||
#include <utils/qtcassert.h>
|
#include <utils/qtcassert.h>
|
||||||
#include <utils/tooltip/tooltip.h>
|
#include <utils/tooltip/tooltip.h>
|
||||||
|
|
||||||
#include <QPoint>
|
#include <QPoint>
|
||||||
|
#include <QScopeGuard>
|
||||||
#include <QTextBlock>
|
#include <QTextBlock>
|
||||||
#include <QXmlStreamReader>
|
#include <QXmlStreamReader>
|
||||||
|
|
||||||
@@ -148,7 +148,7 @@ void ResourcePreviewHoverHandler::identifyMatch(TextEditorWidget *editorWidget,
|
|||||||
int pos,
|
int pos,
|
||||||
ReportPriority report)
|
ReportPriority report)
|
||||||
{
|
{
|
||||||
Utils::ExecuteOnDestruction reportPriority([this, report](){ report(priority()); });
|
const QScopeGuard cleanup([this, report] { report(priority()); });
|
||||||
|
|
||||||
if (editorWidget->extraSelectionTooltip(pos).isEmpty()) {
|
if (editorWidget->extraSelectionTooltip(pos).isEmpty()) {
|
||||||
const QTextBlock tb = editorWidget->document()->findBlock(pos);
|
const QTextBlock tb = editorWidget->document()->findBlock(pos);
|
||||||
|
@@ -28,7 +28,6 @@
|
|||||||
#include <texteditor/textmark.h>
|
#include <texteditor/textmark.h>
|
||||||
|
|
||||||
#include <utils/algorithm.h>
|
#include <utils/algorithm.h>
|
||||||
#include <utils/executeondestruction.h>
|
|
||||||
#include <utils/theme/theme.h>
|
#include <utils/theme/theme.h>
|
||||||
#include <utils/utilsicons.h>
|
#include <utils/utilsicons.h>
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user