Vcs: FilePath-ify VcsManager::promptToAdd

And adjust users a bit.

Change-Id: Idb31030b208403e88c5be0171b3ca9d4d7ded35d
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
hjk
2021-09-28 15:53:08 +02:00
parent b237db519b
commit 66bf957618
5 changed files with 22 additions and 22 deletions

View File

@@ -175,24 +175,21 @@ void FileSystemFilter::accept(LocatorFilterEntry selection,
int *selectionLength) const int *selectionLength) const
{ {
Q_UNUSED(selectionLength) Q_UNUSED(selectionLength)
QFileInfo info = selection.filePath.toFileInfo(); if (selection.filePath.isDir()) {
if (info.isDir()) {
const QString value = shortcutString() + ' ' const QString value = shortcutString() + ' '
+ QDir::toNativeSeparators(info.absoluteFilePath() + '/'); + selection.filePath.absoluteFilePath().toUserOutput() + '/';
*newText = value; *newText = value;
*selectionStart = value.length(); *selectionStart = value.length();
} else { } else {
// Don't block locator filter execution with dialog // Don't block locator filter execution with dialog
QMetaObject::invokeMethod(EditorManager::instance(), [info, selection] { QMetaObject::invokeMethod(EditorManager::instance(), [selection] {
const QString targetFile = selection.internalData.toString(); const FilePath targetFile = FilePath::fromVariant(selection.internalData);
if (!info.exists()) { if (!selection.filePath.exists()) {
if (CheckableMessageBox::shouldAskAgain(ICore::settings(), kAlwaysCreate)) { if (CheckableMessageBox::shouldAskAgain(ICore::settings(), kAlwaysCreate)) {
CheckableMessageBox messageBox(ICore::dialogParent()); CheckableMessageBox messageBox(ICore::dialogParent());
messageBox.setWindowTitle(tr("Create File")); messageBox.setWindowTitle(tr("Create File"));
messageBox.setIcon(QMessageBox::Question); messageBox.setIcon(QMessageBox::Question);
messageBox.setText( messageBox.setText(tr("Create \"%1\"?").arg(targetFile.shortNativePath()));
tr("Create \"%1\"?")
.arg(FilePath::fromString(targetFile).shortNativePath()));
messageBox.setCheckBoxVisible(true); messageBox.setCheckBoxVisible(true);
messageBox.setCheckBoxText(tr("Always create")); messageBox.setCheckBoxText(tr("Always create"));
messageBox.setChecked(false); messageBox.setChecked(false);
@@ -206,10 +203,10 @@ void FileSystemFilter::accept(LocatorFilterEntry selection,
if (messageBox.isChecked()) if (messageBox.isChecked())
CheckableMessageBox::doNotAskAgain(ICore::settings(), kAlwaysCreate); CheckableMessageBox::doNotAskAgain(ICore::settings(), kAlwaysCreate);
} }
QFile file(targetFile); QFile file(targetFile.toString());
file.open(QFile::WriteOnly); file.open(QFile::WriteOnly);
file.close(); file.close();
VcsManager::promptToAdd(QFileInfo(targetFile).absolutePath(), { targetFile }); VcsManager::promptToAdd(targetFile.absolutePath(), {targetFile});
} }
BaseFileFilter::openEditorAt(selection); BaseFileFilter::openEditorAt(selection);
}, Qt::QueuedConnection); }, Qt::QueuedConnection);

View File

@@ -431,13 +431,13 @@ QStringList VcsManager::additionalToolsPath()
return d->m_cachedAdditionalToolsPaths; return d->m_cachedAdditionalToolsPaths;
} }
void VcsManager::promptToAdd(const QString &directory, const QStringList &fileNames) void VcsManager::promptToAdd(const FilePath &directory, const FilePaths &filePaths)
{ {
IVersionControl *vc = findVersionControlForDirectory(FilePath::fromString(directory)); IVersionControl *vc = findVersionControlForDirectory(directory);
if (!vc || !vc->supportsOperation(IVersionControl::AddOperation)) if (!vc || !vc->supportsOperation(IVersionControl::AddOperation))
return; return;
const FilePaths unmanagedFiles = vc->unmanagedFiles(Utils::transform(fileNames, &FilePath::fromString)); const FilePaths unmanagedFiles = vc->unmanagedFiles(filePaths);
if (unmanagedFiles.isEmpty()) if (unmanagedFiles.isEmpty())
return; return;
@@ -446,7 +446,7 @@ void VcsManager::promptToAdd(const QString &directory, const QStringList &fileNa
if (dlg.exec() == QDialog::Accepted) { if (dlg.exec() == QDialog::Accepted) {
QStringList notAddedToVc; QStringList notAddedToVc;
for (const FilePath &file : unmanagedFiles) { for (const FilePath &file : unmanagedFiles) {
if (!vc->vcsAdd(FilePath::fromString(QDir(directory).filePath(file.path())))) if (!vc->vcsAdd(directory.resolvePath(file)))
notAddedToVc << file.toUserOutput(); notAddedToVc << file.toUserOutput();
} }

View File

@@ -80,7 +80,7 @@ public:
// Shows a confirmation dialog, whether the files in the list should be // Shows a confirmation dialog, whether the files in the list should be
// added to revision control. Calls vcsAdd for each file. // added to revision control. Calls vcsAdd for each file.
static void promptToAdd(const QString &directory, const QStringList &fileNames); static void promptToAdd(const Utils::FilePath &directory, const Utils::FilePaths &filePaths);
static void emitRepositoryChanged(const Utils::FilePath &repository); static void emitRepositoryChanged(const Utils::FilePath &repository);

View File

@@ -3619,10 +3619,10 @@ void ProjectExplorerPluginPrivate::addExistingProjects()
if (subProjectFilePaths.empty()) if (subProjectFilePaths.empty())
return; return;
FilePaths failedProjects; FilePaths failedProjects;
QStringList addedProjects; FilePaths addedProjects;
for (const FilePath &filePath : qAsConst(subProjectFilePaths)) { for (const FilePath &filePath : qAsConst(subProjectFilePaths)) {
if (projectNode->addSubProject(filePath)) if (projectNode->addSubProject(filePath))
addedProjects << filePath.toString(); addedProjects << filePath;
else else
failedProjects << filePath; failedProjects << filePath;
} }
@@ -3633,7 +3633,7 @@ void ProjectExplorerPluginPrivate::addExistingProjects()
message + "\n " + FilePath::formatFilePaths(failedProjects, "\n ")); message + "\n " + FilePath::formatFilePaths(failedProjects, "\n "));
return; return;
} }
VcsManager::promptToAdd(dir.toString(), addedProjects); VcsManager::promptToAdd(dir, addedProjects);
} }
void ProjectExplorerPluginPrivate::handleAddExistingFiles() void ProjectExplorerPluginPrivate::handleAddExistingFiles()
@@ -3685,7 +3685,7 @@ void ProjectExplorerPlugin::addExistingFiles(FolderNode *folderNode, const FileP
[&notAdded](const FilePath &f) { return !notAdded.contains(f); }); [&notAdded](const FilePath &f) { return !notAdded.contains(f); });
} }
VcsManager::promptToAdd(dir.toString(), Utils::transform(fileNames, &FilePath::toString)); VcsManager::promptToAdd(dir, fileNames);
} }
void ProjectExplorerPluginPrivate::removeProject() void ProjectExplorerPluginPrivate::removeProject()

View File

@@ -30,7 +30,9 @@
#include <coreplugin/icore.h> #include <coreplugin/icore.h>
#include <coreplugin/vcsmanager.h> #include <coreplugin/vcsmanager.h>
#include <projectexplorer/projectexplorerconstants.h> #include <projectexplorer/projectexplorerconstants.h>
#include <utils/fileutils.h>
#include <utils/algorithm.h>
#include <utils/filepath.h>
#include <utils/removefiledialog.h> #include <utils/removefiledialog.h>
#include <utils/theme/theme.h> #include <utils/theme/theme.h>
@@ -995,7 +997,8 @@ void ResourceModel::addFiles(int prefixIndex, const QStringList &fileNames, int
firstFile = cnt; firstFile = cnt;
lastFile = cnt + unique_list.count() - 1; lastFile = cnt + unique_list.count() - 1;
Core::VcsManager::promptToAdd(m_resource_file.filePath().absolutePath().toString(), fileNames); Core::VcsManager::promptToAdd(m_resource_file.filePath().absolutePath(),
Utils::transform(fileNames, &FilePath::fromString));
} }