Editor: centrally emit filesChangedInternally after refactorings

...instead of relying on the surrounding code of the refactoring to emit the signal.
This also ensures that the signal is only emitted for files that are not opened inside
a TextEditor.

Change-Id: I6223362864014c691962d895b864f9f44c36e035
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
This commit is contained in:
David Schulz
2023-11-16 09:48:38 +01:00
parent 7819fc5dfb
commit b960fb4481
4 changed files with 4 additions and 14 deletions

View File

@@ -252,10 +252,8 @@ void ClangdFindReferences::Private::handleRenameRequest(
{ {
const Utils::FilePaths filePaths = BaseFileFind::replaceAll(newSymbolName, checkedItems, const Utils::FilePaths filePaths = BaseFileFind::replaceAll(newSymbolName, checkedItems,
preserveCase); preserveCase);
if (!filePaths.isEmpty()) { if (!filePaths.isEmpty())
DocumentManager::notifyFilesChangedInternally(filePaths);
SearchResultWindow::instance()->hide(); SearchResultWindow::instance()->hide();
}
const auto renameFilesCheckBox = qobject_cast<QCheckBox *>(search->additionalReplaceWidget()); const auto renameFilesCheckBox = qobject_cast<QCheckBox *>(search->additionalReplaceWidget());
QTC_ASSERT(renameFilesCheckBox, return); QTC_ASSERT(renameFilesCheckBox, return);

View File

@@ -691,13 +691,10 @@ void SymbolSupport::handleRenameResponse(Core::SearchResult *search,
void SymbolSupport::applyRename(const Utils::SearchResultItems &checkedItems, void SymbolSupport::applyRename(const Utils::SearchResultItems &checkedItems,
Core::SearchResult *search) Core::SearchResult *search)
{ {
QSet<Utils::FilePath> affectedNonOpenFilePaths;
QMap<Utils::FilePath, QList<TextEdit>> editsForDocuments; QMap<Utils::FilePath, QList<TextEdit>> editsForDocuments;
QList<DocumentChange> changes; QList<DocumentChange> changes;
for (const Utils::SearchResultItem &item : checkedItems) { for (const Utils::SearchResultItem &item : checkedItems) {
const auto filePath = Utils::FilePath::fromUserInput(item.path().value(0)); const auto filePath = Utils::FilePath::fromUserInput(item.path().value(0));
if (!m_client->documentForFilePath(filePath))
affectedNonOpenFilePaths << filePath;
const QJsonObject jsonObject = item.userData().toJsonObject(); const QJsonObject jsonObject = item.userData().toJsonObject();
if (const TextEdit edit(jsonObject); edit.isValid()) if (const TextEdit edit(jsonObject); edit.isValid())
editsForDocuments[filePath] << edit; editsForDocuments[filePath] << edit;
@@ -715,10 +712,6 @@ void SymbolSupport::applyRename(const Utils::SearchResultItems &checkedItems,
for (auto it = editsForDocuments.begin(), end = editsForDocuments.end(); it != end; ++it) for (auto it = editsForDocuments.begin(), end = editsForDocuments.end(); it != end; ++it)
applyTextEdits(m_client, it.key(), it.value()); applyTextEdits(m_client, it.key(), it.value());
if (!affectedNonOpenFilePaths.isEmpty()) {
Core::DocumentManager::notifyFilesChangedInternally(Utils::toList(affectedNonOpenFilePaths));
}
const auto extraWidget = qobject_cast<ReplaceWidget *>(search->additionalReplaceWidget()); const auto extraWidget = qobject_cast<ReplaceWidget *>(search->additionalReplaceWidget());
QTC_ASSERT(extraWidget, return); QTC_ASSERT(extraWidget, return);
if (!extraWidget->shouldRenameFiles()) if (!extraWidget->shouldRenameFiles())

View File

@@ -388,7 +388,6 @@ void BaseFileFind::doReplace(const QString &text, const SearchResultItems &items
if (!files.isEmpty()) { if (!files.isEmpty()) {
FadingIndicator::showText(ICore::dialogParent(), FadingIndicator::showText(ICore::dialogParent(),
Tr::tr("%n occurrences replaced.", nullptr, items.size()), FadingIndicator::SmallText); Tr::tr("%n occurrences replaced.", nullptr, items.size()), FadingIndicator::SmallText);
DocumentManager::notifyFilesChangedInternally(files);
SearchResultWindow::instance()->hide(); SearchResultWindow::instance()->hide();
} }
} }

View File

@@ -355,9 +355,9 @@ bool RefactoringFile::apply()
QString error; QString error;
// suppress "file has changed" warnings if the file is open in a read-only editor // suppress "file has changed" warnings if the file is open in a read-only editor
Core::FileChangeBlocker block(m_filePath); Core::FileChangeBlocker block(m_filePath);
if (!m_textFileFormat.writeFile(m_filePath, if (m_textFileFormat.writeFile(m_filePath, doc->toPlainText(), &error)) {
doc->toPlainText(), Core::DocumentManager::notifyFilesChangedInternally({m_filePath});
&error)) { } else {
qWarning() << "Could not apply changes to" << m_filePath qWarning() << "Could not apply changes to" << m_filePath
<< ". Error: " << error; << ". Error: " << error;
result = false; result = false;