Core: use FilePaths to notify files changed internally

Change-Id: I2fce65ad340f18292fc0286233e78aaf769a130d
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
David Schulz
2021-06-22 08:57:36 +02:00
parent 1955c82d5c
commit b6367b6359
10 changed files with 44 additions and 38 deletions

View File

@@ -899,9 +899,10 @@ void ClangdClient::Private::handleRenameRequest(const SearchResult *search,
const QList<SearchResultItem> &checkedItems,
bool preserveCase)
{
const QStringList fileNames = TextEditor::BaseFileFind::replaceAll(newSymbolName, checkedItems,
const Utils::FilePaths filePaths = TextEditor::BaseFileFind::replaceAll(newSymbolName,
checkedItems,
preserveCase);
if (!fileNames.isEmpty())
if (!filePaths.isEmpty())
SearchResultWindow::instance()->hide();
const auto renameFilesCheckBox = qobject_cast<QCheckBox *>(search->additionalReplaceWidget());

View File

@@ -1527,9 +1527,9 @@ void DocumentManager::setFileDialogLastVisitedDirectory(const QString &directory
d->m_lastVisitedDirectory = directory;
}
void DocumentManager::notifyFilesChangedInternally(const QStringList &files)
void DocumentManager::notifyFilesChangedInternally(const Utils::FilePaths &filePaths)
{
emit m_instance->filesChangedInternally(files);
emit m_instance->filesChangedInternally(filePaths);
}
void DocumentManager::registerSaveAllAction()

View File

@@ -139,12 +139,12 @@ public:
/* Used to notify e.g. the code model to update the given files. Does *not*
lead to any editors to reload or any other editor manager actions. */
static void notifyFilesChangedInternally(const QStringList &files);
static void notifyFilesChangedInternally(const Utils::FilePaths &filePaths);
signals:
/* Used to notify e.g. the code model to update the given files. Does *not*
lead to any editors to reload or any other editor manager actions. */
void filesChangedInternally(const QStringList &files);
void filesChangedInternally(const Utils::FilePaths &filePaths);
/// emitted if all documents changed their name e.g. due to the file changing on disk
void allDocumentsRenamed(const Utils::FilePath &from, const Utils::FilePath &to);
/// emitted if one document changed its name e.g. due to save as

View File

@@ -173,8 +173,11 @@ void VcsManager::extensionsInitialized()
{
// Change signal connections
foreach (IVersionControl *versionControl, versionControls()) {
connect(versionControl, &IVersionControl::filesChanged,
DocumentManager::instance(), &DocumentManager::filesChangedInternally);
connect(versionControl, &IVersionControl::filesChanged, DocumentManager::instance(),
[](const QStringList fileNames) {
DocumentManager::notifyFilesChangedInternally(
Utils::transform(fileNames, &Utils::FilePath::fromString));
});
connect(versionControl, &IVersionControl::repositoryChanged,
m_instance, &VcsManager::repositoryChanged);
connect(versionControl, &IVersionControl::configurationChanged,

View File

@@ -391,9 +391,9 @@ static void onReplaceUsagesClicked(const QString &text,
if (!modelManager)
return;
const QStringList fileNames = TextEditor::BaseFileFind::replaceAll(text, items, preserveCase);
if (!fileNames.isEmpty()) {
modelManager->updateSourceFiles(Utils::toSet(fileNames));
const FilePaths filePaths = TextEditor::BaseFileFind::replaceAll(text, items, preserveCase);
if (!filePaths.isEmpty()) {
modelManager->updateSourceFiles(Utils::transform<QSet>(filePaths, &FilePath::toString));
SearchResultWindow::instance()->hide();
}
}

View File

@@ -528,9 +528,10 @@ void CppFindReferences::onReplaceButtonClicked(const QString &text,
const QList<SearchResultItem> &items,
bool preserveCase)
{
const QStringList fileNames = TextEditor::BaseFileFind::replaceAll(text, items, preserveCase);
if (!fileNames.isEmpty()) {
m_modelManager->updateSourceFiles(Utils::toSet(fileNames));
const Utils::FilePaths filePaths = TextEditor::BaseFileFind::replaceAll(text, items, preserveCase);
if (!filePaths.isEmpty()) {
m_modelManager->updateSourceFiles(
Utils::transform<QSet>(filePaths, &Utils::FilePath::toString));
SearchResultWindow::instance()->hide();
}

View File

@@ -601,8 +601,8 @@ void CppModelManager::initCppTools()
connect(Core::VcsManager::instance(), &Core::VcsManager::repositoryChanged,
this, &CppModelManager::updateModifiedSourceFiles);
connect(Core::DocumentManager::instance(), &Core::DocumentManager::filesChangedInternally,
[this](const QStringList &files) {
updateSourceFiles(Utils::toSet(files));
[this](const Utils::FilePaths &filePaths) {
updateSourceFiles(Utils::transform<QSet>(filePaths, &Utils::FilePath::toString));
});
connect(this, &CppModelManager::documentUpdated,

View File

@@ -1041,16 +1041,18 @@ void FindReferences::setPaused(bool paused)
void FindReferences::onReplaceButtonClicked(const QString &text, const QList<SearchResultItem> &items, bool preserveCase)
{
const QStringList fileNames = TextEditor::BaseFileFind::replaceAll(text, items, preserveCase);
const Utils::FilePaths filePaths = TextEditor::BaseFileFind::replaceAll(text,
items,
preserveCase);
// files that are opened in an editor are changed, but not saved
QStringList changedOnDisk;
QStringList changedUnsavedEditors;
foreach (const QString &fileName, fileNames) {
if (DocumentModel::documentForFilePath(Utils::FilePath::fromString(fileName)))
changedOnDisk += fileName;
for (const Utils::FilePath &filePath : filePaths) {
if (DocumentModel::documentForFilePath(filePath))
changedOnDisk += filePath.toString();
else
changedUnsavedEditors += fileName;
changedUnsavedEditors += filePath.toString();
}
if (!changedOnDisk.isEmpty())

View File

@@ -346,7 +346,7 @@ void BaseFileFind::doReplace(const QString &text,
const QList<SearchResultItem> &items,
bool preserveCase)
{
const QStringList files = replaceAll(text, items, preserveCase);
const FilePaths files = replaceAll(text, items, preserveCase);
if (!files.isEmpty()) {
Utils::FadingIndicator::showText(ICore::dialogParent(),
tr("%n occurrences replaced.", nullptr, items.size()),
@@ -485,25 +485,24 @@ void BaseFileFind::recheckEnabled(SearchResult *search)
search->setSearchAgainEnabled(isEnabled());
}
QStringList BaseFileFind::replaceAll(const QString &text,
FilePaths BaseFileFind::replaceAll(const QString &text,
const QList<SearchResultItem> &items,
bool preserveCase)
{
if (items.isEmpty())
return QStringList();
return {};
RefactoringChanges refactoring;
QHash<QString, QList<SearchResultItem> > changes;
QHash<FilePath, QList<SearchResultItem> > changes;
for (const SearchResultItem &item : items)
changes[QDir::fromNativeSeparators(item.path().first())].append(item);
changes[FilePath::fromUserInput(item.path().first())].append(item);
// Checking for files without write permissions
QSet<FilePath> roFiles;
for (auto it = changes.cbegin(), end = changes.cend(); it != end; ++it) {
const QFileInfo fileInfo(it.key());
if (!fileInfo.isWritable())
roFiles.insert(FilePath::fromString(it.key()));
if (!it.key().isWritableFile())
roFiles.insert(it.key());
}
// Query the user for permissions
@@ -511,15 +510,15 @@ QStringList BaseFileFind::replaceAll(const QString &text,
ReadOnlyFilesDialog roDialog(Utils::toList(roFiles), ICore::dialogParent());
roDialog.setShowFailWarning(true, tr("Aborting replace."));
if (roDialog.exec() == ReadOnlyFilesDialog::RO_Cancel)
return QStringList();
return {};
}
for (auto it = changes.cbegin(), end = changes.cend(); it != end; ++it) {
const QString fileName = it.key();
const FilePath filePath = it.key();
const QList<SearchResultItem> changeItems = it.value();
ChangeSet changeSet;
RefactoringFilePtr file = refactoring.file(FilePath::fromString(fileName));
RefactoringFilePtr file = refactoring.file(filePath);
QSet<QPair<int, int> > processed;
for (const SearchResultItem &item : changeItems) {
const QPair<int, int> &p = qMakePair(item.mainRange().begin.line,

View File

@@ -103,7 +103,7 @@ public:
void addSearchEngine(SearchEngine *searchEngine);
/* returns the list of unique files that were passed in items */
static QStringList replaceAll(const QString &txt,
static Utils::FilePaths replaceAll(const QString &txt,
const QList<Core::SearchResultItem> &items,
bool preserveCase = false);
virtual Utils::FileIterator *files(const QStringList &nameFilters,