forked from qt-creator/qt-creator
Core: use FilePaths to notify files changed internally
Change-Id: I2fce65ad340f18292fc0286233e78aaf769a130d Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -899,9 +899,10 @@ void ClangdClient::Private::handleRenameRequest(const SearchResult *search,
|
|||||||
const QList<SearchResultItem> &checkedItems,
|
const QList<SearchResultItem> &checkedItems,
|
||||||
bool preserveCase)
|
bool preserveCase)
|
||||||
{
|
{
|
||||||
const QStringList fileNames = TextEditor::BaseFileFind::replaceAll(newSymbolName, checkedItems,
|
const Utils::FilePaths filePaths = TextEditor::BaseFileFind::replaceAll(newSymbolName,
|
||||||
|
checkedItems,
|
||||||
preserveCase);
|
preserveCase);
|
||||||
if (!fileNames.isEmpty())
|
if (!filePaths.isEmpty())
|
||||||
SearchResultWindow::instance()->hide();
|
SearchResultWindow::instance()->hide();
|
||||||
|
|
||||||
const auto renameFilesCheckBox = qobject_cast<QCheckBox *>(search->additionalReplaceWidget());
|
const auto renameFilesCheckBox = qobject_cast<QCheckBox *>(search->additionalReplaceWidget());
|
||||||
|
@@ -1527,9 +1527,9 @@ void DocumentManager::setFileDialogLastVisitedDirectory(const QString &directory
|
|||||||
d->m_lastVisitedDirectory = 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()
|
void DocumentManager::registerSaveAllAction()
|
||||||
|
@@ -139,12 +139,12 @@ public:
|
|||||||
|
|
||||||
/* Used to notify e.g. the code model to update the given files. Does *not*
|
/* 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. */
|
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:
|
signals:
|
||||||
/* Used to notify e.g. the code model to update the given files. Does *not*
|
/* 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. */
|
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
|
/// 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);
|
void allDocumentsRenamed(const Utils::FilePath &from, const Utils::FilePath &to);
|
||||||
/// emitted if one document changed its name e.g. due to save as
|
/// emitted if one document changed its name e.g. due to save as
|
||||||
|
@@ -173,8 +173,11 @@ void VcsManager::extensionsInitialized()
|
|||||||
{
|
{
|
||||||
// Change signal connections
|
// Change signal connections
|
||||||
foreach (IVersionControl *versionControl, versionControls()) {
|
foreach (IVersionControl *versionControl, versionControls()) {
|
||||||
connect(versionControl, &IVersionControl::filesChanged,
|
connect(versionControl, &IVersionControl::filesChanged, DocumentManager::instance(),
|
||||||
DocumentManager::instance(), &DocumentManager::filesChangedInternally);
|
[](const QStringList fileNames) {
|
||||||
|
DocumentManager::notifyFilesChangedInternally(
|
||||||
|
Utils::transform(fileNames, &Utils::FilePath::fromString));
|
||||||
|
});
|
||||||
connect(versionControl, &IVersionControl::repositoryChanged,
|
connect(versionControl, &IVersionControl::repositoryChanged,
|
||||||
m_instance, &VcsManager::repositoryChanged);
|
m_instance, &VcsManager::repositoryChanged);
|
||||||
connect(versionControl, &IVersionControl::configurationChanged,
|
connect(versionControl, &IVersionControl::configurationChanged,
|
||||||
|
@@ -391,9 +391,9 @@ static void onReplaceUsagesClicked(const QString &text,
|
|||||||
if (!modelManager)
|
if (!modelManager)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const QStringList fileNames = TextEditor::BaseFileFind::replaceAll(text, items, preserveCase);
|
const FilePaths filePaths = TextEditor::BaseFileFind::replaceAll(text, items, preserveCase);
|
||||||
if (!fileNames.isEmpty()) {
|
if (!filePaths.isEmpty()) {
|
||||||
modelManager->updateSourceFiles(Utils::toSet(fileNames));
|
modelManager->updateSourceFiles(Utils::transform<QSet>(filePaths, &FilePath::toString));
|
||||||
SearchResultWindow::instance()->hide();
|
SearchResultWindow::instance()->hide();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@@ -528,9 +528,10 @@ void CppFindReferences::onReplaceButtonClicked(const QString &text,
|
|||||||
const QList<SearchResultItem> &items,
|
const QList<SearchResultItem> &items,
|
||||||
bool preserveCase)
|
bool preserveCase)
|
||||||
{
|
{
|
||||||
const QStringList fileNames = TextEditor::BaseFileFind::replaceAll(text, items, preserveCase);
|
const Utils::FilePaths filePaths = TextEditor::BaseFileFind::replaceAll(text, items, preserveCase);
|
||||||
if (!fileNames.isEmpty()) {
|
if (!filePaths.isEmpty()) {
|
||||||
m_modelManager->updateSourceFiles(Utils::toSet(fileNames));
|
m_modelManager->updateSourceFiles(
|
||||||
|
Utils::transform<QSet>(filePaths, &Utils::FilePath::toString));
|
||||||
SearchResultWindow::instance()->hide();
|
SearchResultWindow::instance()->hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -601,8 +601,8 @@ void CppModelManager::initCppTools()
|
|||||||
connect(Core::VcsManager::instance(), &Core::VcsManager::repositoryChanged,
|
connect(Core::VcsManager::instance(), &Core::VcsManager::repositoryChanged,
|
||||||
this, &CppModelManager::updateModifiedSourceFiles);
|
this, &CppModelManager::updateModifiedSourceFiles);
|
||||||
connect(Core::DocumentManager::instance(), &Core::DocumentManager::filesChangedInternally,
|
connect(Core::DocumentManager::instance(), &Core::DocumentManager::filesChangedInternally,
|
||||||
[this](const QStringList &files) {
|
[this](const Utils::FilePaths &filePaths) {
|
||||||
updateSourceFiles(Utils::toSet(files));
|
updateSourceFiles(Utils::transform<QSet>(filePaths, &Utils::FilePath::toString));
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(this, &CppModelManager::documentUpdated,
|
connect(this, &CppModelManager::documentUpdated,
|
||||||
|
@@ -1041,16 +1041,18 @@ void FindReferences::setPaused(bool paused)
|
|||||||
|
|
||||||
void FindReferences::onReplaceButtonClicked(const QString &text, const QList<SearchResultItem> &items, bool preserveCase)
|
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
|
// files that are opened in an editor are changed, but not saved
|
||||||
QStringList changedOnDisk;
|
QStringList changedOnDisk;
|
||||||
QStringList changedUnsavedEditors;
|
QStringList changedUnsavedEditors;
|
||||||
foreach (const QString &fileName, fileNames) {
|
for (const Utils::FilePath &filePath : filePaths) {
|
||||||
if (DocumentModel::documentForFilePath(Utils::FilePath::fromString(fileName)))
|
if (DocumentModel::documentForFilePath(filePath))
|
||||||
changedOnDisk += fileName;
|
changedOnDisk += filePath.toString();
|
||||||
else
|
else
|
||||||
changedUnsavedEditors += fileName;
|
changedUnsavedEditors += filePath.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!changedOnDisk.isEmpty())
|
if (!changedOnDisk.isEmpty())
|
||||||
|
@@ -346,7 +346,7 @@ void BaseFileFind::doReplace(const QString &text,
|
|||||||
const QList<SearchResultItem> &items,
|
const QList<SearchResultItem> &items,
|
||||||
bool preserveCase)
|
bool preserveCase)
|
||||||
{
|
{
|
||||||
const QStringList files = replaceAll(text, items, preserveCase);
|
const FilePaths files = replaceAll(text, items, preserveCase);
|
||||||
if (!files.isEmpty()) {
|
if (!files.isEmpty()) {
|
||||||
Utils::FadingIndicator::showText(ICore::dialogParent(),
|
Utils::FadingIndicator::showText(ICore::dialogParent(),
|
||||||
tr("%n occurrences replaced.", nullptr, items.size()),
|
tr("%n occurrences replaced.", nullptr, items.size()),
|
||||||
@@ -485,25 +485,24 @@ void BaseFileFind::recheckEnabled(SearchResult *search)
|
|||||||
search->setSearchAgainEnabled(isEnabled());
|
search->setSearchAgainEnabled(isEnabled());
|
||||||
}
|
}
|
||||||
|
|
||||||
QStringList BaseFileFind::replaceAll(const QString &text,
|
FilePaths BaseFileFind::replaceAll(const QString &text,
|
||||||
const QList<SearchResultItem> &items,
|
const QList<SearchResultItem> &items,
|
||||||
bool preserveCase)
|
bool preserveCase)
|
||||||
{
|
{
|
||||||
if (items.isEmpty())
|
if (items.isEmpty())
|
||||||
return QStringList();
|
return {};
|
||||||
|
|
||||||
RefactoringChanges refactoring;
|
RefactoringChanges refactoring;
|
||||||
|
|
||||||
QHash<QString, QList<SearchResultItem> > changes;
|
QHash<FilePath, QList<SearchResultItem> > changes;
|
||||||
for (const SearchResultItem &item : items)
|
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
|
// Checking for files without write permissions
|
||||||
QSet<FilePath> roFiles;
|
QSet<FilePath> roFiles;
|
||||||
for (auto it = changes.cbegin(), end = changes.cend(); it != end; ++it) {
|
for (auto it = changes.cbegin(), end = changes.cend(); it != end; ++it) {
|
||||||
const QFileInfo fileInfo(it.key());
|
if (!it.key().isWritableFile())
|
||||||
if (!fileInfo.isWritable())
|
roFiles.insert(it.key());
|
||||||
roFiles.insert(FilePath::fromString(it.key()));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Query the user for permissions
|
// Query the user for permissions
|
||||||
@@ -511,15 +510,15 @@ QStringList BaseFileFind::replaceAll(const QString &text,
|
|||||||
ReadOnlyFilesDialog roDialog(Utils::toList(roFiles), ICore::dialogParent());
|
ReadOnlyFilesDialog roDialog(Utils::toList(roFiles), ICore::dialogParent());
|
||||||
roDialog.setShowFailWarning(true, tr("Aborting replace."));
|
roDialog.setShowFailWarning(true, tr("Aborting replace."));
|
||||||
if (roDialog.exec() == ReadOnlyFilesDialog::RO_Cancel)
|
if (roDialog.exec() == ReadOnlyFilesDialog::RO_Cancel)
|
||||||
return QStringList();
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto it = changes.cbegin(), end = changes.cend(); it != end; ++it) {
|
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();
|
const QList<SearchResultItem> changeItems = it.value();
|
||||||
|
|
||||||
ChangeSet changeSet;
|
ChangeSet changeSet;
|
||||||
RefactoringFilePtr file = refactoring.file(FilePath::fromString(fileName));
|
RefactoringFilePtr file = refactoring.file(filePath);
|
||||||
QSet<QPair<int, int> > processed;
|
QSet<QPair<int, int> > processed;
|
||||||
for (const SearchResultItem &item : changeItems) {
|
for (const SearchResultItem &item : changeItems) {
|
||||||
const QPair<int, int> &p = qMakePair(item.mainRange().begin.line,
|
const QPair<int, int> &p = qMakePair(item.mainRange().begin.line,
|
||||||
|
@@ -103,7 +103,7 @@ public:
|
|||||||
void addSearchEngine(SearchEngine *searchEngine);
|
void addSearchEngine(SearchEngine *searchEngine);
|
||||||
|
|
||||||
/* returns the list of unique files that were passed in items */
|
/* 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,
|
const QList<Core::SearchResultItem> &items,
|
||||||
bool preserveCase = false);
|
bool preserveCase = false);
|
||||||
virtual Utils::FileIterator *files(const QStringList &nameFilters,
|
virtual Utils::FileIterator *files(const QStringList &nameFilters,
|
||||||
|
Reference in New Issue
Block a user