TextEditor: Make RefactoringFile::apply() a no-op for empty change sets

To simplify some calling sites.

Change-Id: I9736e88053659e5e90bca7b70e6d7e84b0d4fb4e
Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
Christian Kandeler
2024-05-22 15:25:46 +02:00
parent 3697aac20e
commit 389b7b211c
4 changed files with 8 additions and 10 deletions

View File

@@ -307,9 +307,7 @@ public:
insertAndIndent(m_sourceFile, m_sourceFileInsertionPoint, m_sourceFileCode); insertAndIndent(m_sourceFile, m_sourceFileInsertionPoint, m_sourceFileCode);
} }
if (!m_headerFileChangeSet.isEmpty())
m_headerFile->apply(m_headerFileChangeSet); m_headerFile->apply(m_headerFileChangeSet);
if (!m_sourceFileChangeSet.isEmpty())
m_sourceFile->apply(m_sourceFileChangeSet); m_sourceFile->apply(m_sourceFileChangeSet);
} }

View File

@@ -920,7 +920,6 @@ public:
implementationChangeSet.insert(insertPos, QLatin1String("\n\n") + defText); implementationChangeSet.insert(insertPos, QLatin1String("\n\n") + defText);
} }
if (!implementationChangeSet.isEmpty())
implementationFile->apply(implementationChangeSet); implementationFile->apply(implementationChangeSet);
} }
} }

View File

@@ -135,9 +135,7 @@ public:
void applyChanges() void applyChanges()
{ {
if (!m_toFileChangeSet.isEmpty())
m_toFile->apply(m_toFileChangeSet); m_toFile->apply(m_toFileChangeSet);
if (!m_fromFileChangeSet.isEmpty())
m_fromFile->apply(m_fromFileChangeSet); m_fromFile->apply(m_fromFileChangeSet);
} }

View File

@@ -214,6 +214,9 @@ void RefactoringFile::setOpenEditor(bool activate, int pos)
bool RefactoringFile::apply() bool RefactoringFile::apply()
{ {
if (m_changes.isEmpty())
return true;
// test file permissions // test file permissions
if (!m_filePath.isWritableFile()) { if (!m_filePath.isWritableFile()) {
ReadOnlyFilesDialog roDialog(m_filePath, ICore::dialogParent()); ReadOnlyFilesDialog roDialog(m_filePath, ICore::dialogParent());