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,10 +307,8 @@ public:
insertAndIndent(m_sourceFile, m_sourceFileInsertionPoint, m_sourceFileCode);
}
if (!m_headerFileChangeSet.isEmpty())
m_headerFile->apply(m_headerFileChangeSet);
if (!m_sourceFileChangeSet.isEmpty())
m_sourceFile->apply(m_sourceFileChangeSet);
m_headerFile->apply(m_headerFileChangeSet);
m_sourceFile->apply(m_sourceFileChangeSet);
}
bool hasSourceFile() const { return m_headerFile != m_sourceFile; }

View File

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

View File

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

View File

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