ProjectExplorer: Use FilePath for ProjectNode::{path,directory}

... and let the fallout trickle down a bit.

Change-Id: I1a2f79e281725c4a121cc2fbbc0377e881616ce5
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2021-07-26 17:20:03 +02:00
parent f53d993d95
commit ef1653698e
15 changed files with 55 additions and 45 deletions

View File

@@ -242,7 +242,7 @@ static bool wizardFactoryLessThan(const IWizardFactory *f1, const IWizardFactory
} }
void NewDialog::setWizardFactories(QList<IWizardFactory *> factories, void NewDialog::setWizardFactories(QList<IWizardFactory *> factories,
const QString &defaultLocation, const FilePath &defaultLocation,
const QVariantMap &extraVariables) const QVariantMap &extraVariables)
{ {
m_defaultLocation = defaultLocation; m_defaultLocation = defaultLocation;
@@ -501,7 +501,7 @@ void NewDialog::accept()
if (m_ui->templatesView->currentIndex().isValid()) { if (m_ui->templatesView->currentIndex().isValid()) {
IWizardFactory *wizard = currentWizardFactory(); IWizardFactory *wizard = currentWizardFactory();
if (QTC_GUARD(wizard)) { if (QTC_GUARD(wizard)) {
QMetaObject::invokeMethod(wizard, std::bind(&runWizard, wizard, m_defaultLocation, QMetaObject::invokeMethod(wizard, std::bind(&runWizard, wizard, m_defaultLocation.toString(),
selectedPlatform(), m_extraVariables), Qt::QueuedConnection); selectedPlatform(), m_extraVariables), Qt::QueuedConnection);
} }
} }

View File

@@ -27,6 +27,8 @@
#include "../iwizardfactory.h" #include "../iwizardfactory.h"
#include <utils/filepath.h>
#include <QDialog> #include <QDialog>
#include <QIcon> #include <QIcon>
#include <QList> #include <QList>
@@ -54,7 +56,9 @@ public:
explicit NewDialog(QWidget *parent); explicit NewDialog(QWidget *parent);
~NewDialog() override; ~NewDialog() override;
void setWizardFactories(QList<IWizardFactory*> factories, const QString &defaultLocation, const QVariantMap &extraVariables); void setWizardFactories(QList<IWizardFactory*> factories,
const Utils::FilePath &defaultLocation,
const QVariantMap &extraVariables);
void showDialog(); void showDialog();
Utils::Id selectedPlatform() const; Utils::Id selectedPlatform() const;
@@ -84,7 +88,7 @@ private:
QPushButton *m_okButton = nullptr; QPushButton *m_okButton = nullptr;
QIcon m_dummyIcon; QIcon m_dummyIcon;
QList<QStandardItem*> m_categoryItems; QList<QStandardItem*> m_categoryItems;
QString m_defaultLocation; Utils::FilePath m_defaultLocation;
QVariantMap m_extraVariables; QVariantMap m_extraVariables;
}; };

View File

@@ -245,7 +245,7 @@ ICore::~ICore()
*/ */
void ICore::showNewItemDialog(const QString &title, void ICore::showNewItemDialog(const QString &title,
const QList<IWizardFactory *> &factories, const QList<IWizardFactory *> &factories,
const QString &defaultLocation, const FilePath &defaultLocation,
const QVariantMap &extraVariables) const QVariantMap &extraVariables)
{ {
QTC_ASSERT(!isNewItemDialogRunning(), return); QTC_ASSERT(!isNewItemDialogRunning(), return);

View File

@@ -78,8 +78,8 @@ public:
static QWidget *newItemDialog(); static QWidget *newItemDialog();
static void showNewItemDialog(const QString &title, static void showNewItemDialog(const QString &title,
const QList<IWizardFactory *> &factories, const QList<IWizardFactory *> &factories,
const QString &defaultLocation = QString(), const Utils::FilePath &defaultLocation = {},
const QVariantMap &extraVariables = QVariantMap()); const QVariantMap &extraVariables = {});
static bool showOptionsDialog(const Utils::Id page, QWidget *parent = nullptr); static bool showOptionsDialog(const Utils::Id page, QWidget *parent = nullptr);
static QString msgShowOptionsDialog(); static QString msgShowOptionsDialog();

View File

@@ -141,7 +141,7 @@ class NewItemDialogData
{ {
public: public:
void setData(const QString &t, const QList<IWizardFactory *> &f, void setData(const QString &t, const QList<IWizardFactory *> &f,
const QString &dl, const QVariantMap &ev) const FilePath &dl, const QVariantMap &ev)
{ {
QTC_ASSERT(!hasData(), return); QTC_ASSERT(!hasData(), return);
@@ -173,7 +173,7 @@ public:
private: private:
QString title; QString title;
QList<IWizardFactory *> factories; QList<IWizardFactory *> factories;
QString defaultLocation; FilePath defaultLocation;
QVariantMap extraVariables; QVariantMap extraVariables;
}; };
@@ -358,7 +358,7 @@ QWidget *IWizardFactory::currentWizard()
void IWizardFactory::requestNewItemDialog(const QString &title, void IWizardFactory::requestNewItemDialog(const QString &title,
const QList<IWizardFactory *> &factories, const QList<IWizardFactory *> &factories,
const QString &defaultLocation, const FilePath &defaultLocation,
const QVariantMap &extraVariables) const QVariantMap &extraVariables)
{ {
s_reopenData.setData(title, factories, defaultLocation, extraVariables); s_reopenData.setData(title, factories, defaultLocation, extraVariables);

View File

@@ -36,7 +36,10 @@
QT_FORWARD_DECLARE_CLASS(QAction) QT_FORWARD_DECLARE_CLASS(QAction)
namespace Utils { class Wizard; } namespace Utils {
class FilePath;
class Wizard;
} // Utils
namespace Core { namespace Core {
@@ -107,7 +110,7 @@ public:
static void requestNewItemDialog(const QString &title, static void requestNewItemDialog(const QString &title,
const QList<IWizardFactory *> &factories, const QList<IWizardFactory *> &factories,
const QString &defaultLocation, const Utils::FilePath &defaultLocation,
const QVariantMap &extraVariables); const QVariantMap &extraVariables);
protected: protected:

View File

@@ -525,7 +525,7 @@ void MainWindow::registerDefaultActions()
connect(m_newAction, &QAction::triggered, this, []() { connect(m_newAction, &QAction::triggered, this, []() {
if (!ICore::isNewItemDialogRunning()) { if (!ICore::isNewItemDialogRunning()) {
ICore::showNewItemDialog(tr("New File or Project", "Title of dialog"), ICore::showNewItemDialog(tr("New File or Project", "Title of dialog"),
IWizardFactory::allWizardFactories(), QString()); IWizardFactory::allWizardFactories(), FilePath());
} else { } else {
ICore::raiseWindow(ICore::newItemDialog()); ICore::raiseWindow(ICore::newItemDialog());
} }

View File

@@ -58,7 +58,7 @@ void addTargetNode(std::unique_ptr<MesonProjectNode> &root, const Target &target
if (asFolder) { if (asFolder) {
auto targetNode = std::make_unique<MesonTargetNode>( auto targetNode = std::make_unique<MesonTargetNode>(
path.absolutePath().pathAppended(target.name), path.absolutePath().pathAppended(target.name),
Target::fullName(Utils::FilePath::fromString(root->path()), target)); Target::fullName(root->path(), target));
targetNode->setDisplayName(target.name); targetNode->setDisplayName(target.name);
asFolder->addNode(std::move(targetNode)); asFolder->addNode(std::move(targetNode));
} }

View File

@@ -77,7 +77,8 @@ NimProjectScanner::NimProjectScanner(Project *project)
} }
// Sync watched dirs // Sync watched dirs
const QSet<QString> fsDirs = Utils::transform<QSet>(nodes, &FileNode::directory); const QSet<QString> fsDirs = Utils::transform<QSet>(nodes,
[](const std::unique_ptr<FileNode> &fn) { return fn->directory().toString(); });
const QSet<QString> projectDirs = Utils::toSet(m_directoryWatcher.directories()); const QSet<QString> projectDirs = Utils::toSet(m_directoryWatcher.directories());
m_directoryWatcher.addDirectories(Utils::toList(fsDirs - projectDirs), FileSystemWatcher::WatchAllChanges); m_directoryWatcher.addDirectories(Utils::toList(fsDirs - projectDirs), FileSystemWatcher::WatchAllChanges);
m_directoryWatcher.removeDirectories(Utils::toList(projectDirs - fsDirs)); m_directoryWatcher.removeDirectories(Utils::toList(projectDirs - fsDirs));

View File

@@ -512,7 +512,7 @@ void FolderNavigationWidget::addNewItem()
Utils::filtered(Core::IWizardFactory::allWizardFactories(), Utils::filtered(Core::IWizardFactory::allWizardFactories(),
Utils::equal(&Core::IWizardFactory::kind, Utils::equal(&Core::IWizardFactory::kind,
Core::IWizardFactory::FileWizard)), Core::IWizardFactory::FileWizard)),
path.toString()); path);
} }
void FolderNavigationWidget::editCurrentItem() void FolderNavigationWidget::editCurrentItem()

View File

@@ -3515,7 +3515,7 @@ void ProjectExplorerPluginPrivate::addNewFile()
{ {
Node *currentNode = ProjectTree::currentNode(); Node *currentNode = ProjectTree::currentNode();
QTC_ASSERT(currentNode, return); QTC_ASSERT(currentNode, return);
QString location = currentNode->directory(); FilePath location = currentNode->directory();
QVariantMap map; QVariantMap map;
// store void pointer to avoid QVariant to use qobject_cast, which might core-dump when trying // store void pointer to avoid QVariant to use qobject_cast, which might core-dump when trying
@@ -3541,7 +3541,7 @@ void ProjectExplorerPluginPrivate::addNewSubproject()
{ {
Node* currentNode = ProjectTree::currentNode(); Node* currentNode = ProjectTree::currentNode();
QTC_ASSERT(currentNode, return); QTC_ASSERT(currentNode, return);
QString location = currentNode->directory(); FilePath location = currentNode->directory();
if (currentNode->isProjectNodeType() if (currentNode->isProjectNodeType()
&& currentNode->supportsAction(AddSubProject, currentNode)) { && currentNode->supportsAction(AddSubProject, currentNode)) {
@@ -3576,9 +3576,9 @@ void ProjectExplorerPluginPrivate::addExistingProjects()
if (!projectNode && currentNode->asContainerNode()) if (!projectNode && currentNode->asContainerNode())
projectNode = currentNode->asContainerNode()->rootProjectNode(); projectNode = currentNode->asContainerNode()->rootProjectNode();
QTC_ASSERT(projectNode, return); QTC_ASSERT(projectNode, return);
const QString dir = currentNode->directory(); const FilePath dir = currentNode->directory();
QStringList subProjectFilePaths = QFileDialog::getOpenFileNames( QStringList subProjectFilePaths = QFileDialog::getOpenFileNames(
ICore::dialogParent(), tr("Choose Project File"), dir, ICore::dialogParent(), tr("Choose Project File"), dir.toString(),
projectNode->subProjectFileNamePatterns().join(";;")); projectNode->subProjectFileNamePatterns().join(";;"));
if (!ProjectTree::hasNode(projectNode)) if (!ProjectTree::hasNode(projectNode))
return; return;
@@ -3605,7 +3605,7 @@ void ProjectExplorerPluginPrivate::addExistingProjects()
message + "\n " + failedProjects.join("\n ")); message + "\n " + failedProjects.join("\n "));
return; return;
} }
VcsManager::promptToAdd(dir, addedProjects); VcsManager::promptToAdd(dir.toString(), addedProjects);
} }
void ProjectExplorerPluginPrivate::handleAddExistingFiles() void ProjectExplorerPluginPrivate::handleAddExistingFiles()
@@ -3616,7 +3616,7 @@ void ProjectExplorerPluginPrivate::handleAddExistingFiles()
QTC_ASSERT(folderNode, return); QTC_ASSERT(folderNode, return);
QStringList fileNames = QFileDialog::getOpenFileNames(ICore::dialogParent(), QStringList fileNames = QFileDialog::getOpenFileNames(ICore::dialogParent(),
tr("Add Existing Files"), node->directory()); tr("Add Existing Files"), node->directory().toString());
if (fileNames.isEmpty()) if (fileNames.isEmpty())
return; return;
@@ -3631,8 +3631,7 @@ void ProjectExplorerPluginPrivate::addExistingDirectory()
QTC_ASSERT(folderNode, return); QTC_ASSERT(folderNode, return);
SelectableFilesDialogAddDirectory dialog(FilePath::fromString(node->directory()), SelectableFilesDialogAddDirectory dialog(node->directory(), FilePaths(), ICore::dialogParent());
FilePaths(), ICore::dialogParent());
dialog.setAddFileFilter({}); dialog.setAddFileFilter({});
if (dialog.exec() == QDialog::Accepted) if (dialog.exec() == QDialog::Accepted)
@@ -3645,7 +3644,7 @@ void ProjectExplorerPlugin::addExistingFiles(FolderNode *folderNode, const FileP
if (!folderNode || !ProjectTree::hasNode(folderNode)) if (!folderNode || !ProjectTree::hasNode(folderNode))
return; return;
const QString dir = folderNode->directory(); const FilePath dir = folderNode->directory();
FilePaths fileNames = filePaths; FilePaths fileNames = filePaths;
FilePaths notAdded; FilePaths notAdded;
folderNode->addFiles(fileNames, &notAdded); folderNode->addFiles(fileNames, &notAdded);
@@ -3659,7 +3658,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, Utils::transform(fileNames, &FilePath::toString)); VcsManager::promptToAdd(dir.toString(), Utils::transform(fileNames, &FilePath::toString));
} }
void ProjectExplorerPluginPrivate::removeProject() void ProjectExplorerPluginPrivate::removeProject()
@@ -3687,14 +3686,14 @@ void ProjectExplorerPluginPrivate::searchOnFileSystem()
{ {
const Node *currentNode = ProjectTree::currentNode(); const Node *currentNode = ProjectTree::currentNode();
QTC_ASSERT(currentNode, return); QTC_ASSERT(currentNode, return);
TextEditor::FindInFiles::findOnFileSystem(currentNode->path()); TextEditor::FindInFiles::findOnFileSystem(currentNode->path().toString());
} }
void ProjectExplorerPluginPrivate::showInGraphicalShell() void ProjectExplorerPluginPrivate::showInGraphicalShell()
{ {
Node *currentNode = ProjectTree::currentNode(); Node *currentNode = ProjectTree::currentNode();
QTC_ASSERT(currentNode, return); QTC_ASSERT(currentNode, return);
Core::FileUtils::showInGraphicalShell(ICore::dialogParent(), currentNode->path()); Core::FileUtils::showInGraphicalShell(ICore::dialogParent(), currentNode->path().toString());
} }
void ProjectExplorerPluginPrivate::openTerminalHere(const EnvironmentGetter &env) void ProjectExplorerPluginPrivate::openTerminalHere(const EnvironmentGetter &env)
@@ -3706,7 +3705,7 @@ void ProjectExplorerPluginPrivate::openTerminalHere(const EnvironmentGetter &env
if (!environment) if (!environment)
return; return;
Core::FileUtils::openTerminal(currentNode->directory(), environment.value()); Core::FileUtils::openTerminal(currentNode->directory().toString(), environment.value());
} }
void ProjectExplorerPluginPrivate::openTerminalHereWithRunEnv() void ProjectExplorerPluginPrivate::openTerminalHereWithRunEnv()
@@ -3728,7 +3727,7 @@ void ProjectExplorerPluginPrivate::openTerminalHereWithRunEnv()
device = DeviceKitAspect::device(target->kit()); device = DeviceKitAspect::device(target->kit());
QTC_ASSERT(device && device->canOpenTerminal(), return); QTC_ASSERT(device && device->canOpenTerminal(), return);
const QString workingDir = device->type() == Constants::DESKTOP_DEVICE_TYPE const QString workingDir = device->type() == Constants::DESKTOP_DEVICE_TYPE
? currentNode->directory() : runnable.workingDirectory; ? currentNode->directory().toString() : runnable.workingDirectory;
device->openTerminal(runnable.environment, workingDir); device->openTerminal(runnable.environment, workingDir);
} }

View File

@@ -311,28 +311,30 @@ FileType Node::fileTypeForFileName(const Utils::FilePath &file)
return fileTypeForMimeType(Utils::mimeTypeForFile(file, Utils::MimeMatchMode::MatchExtension)); return fileTypeForMimeType(Utils::mimeTypeForFile(file, Utils::MimeMatchMode::MatchExtension));
} }
QString Node::pathOrDirectory(bool dir) const FilePath Node::pathOrDirectory(bool dir) const
{ {
QString location; FilePath location;
const FolderNode *folder = asFolderNode(); const FolderNode *folder = asFolderNode();
if (isVirtualFolderType() && folder) { if (isVirtualFolderType() && folder) {
// Virtual Folder case // Virtual Folder case
// If there are files directly below or no subfolders, take the folder path // If there are files directly below or no subfolders, take the folder path
if (!folder->fileNodes().isEmpty() || folder->folderNodes().isEmpty()) { if (!folder->fileNodes().isEmpty() || folder->folderNodes().isEmpty()) {
location = m_filePath.toString(); location = m_filePath;
} else { } else {
// Otherwise we figure out a commonPath from the subfolders // Otherwise we figure out a commonPath from the subfolders
QStringList list; QStringList list;
foreach (FolderNode *f, folder->folderNodes()) foreach (FolderNode *f, folder->folderNodes())
list << f->filePath().toString() + QLatin1Char('/'); list << f->filePath().toString() + QLatin1Char('/');
location = Utils::commonPath(list); location = FilePath::fromString(Utils::commonPath(list));
} }
QFileInfo fi(location); QTC_CHECK(!location.needsDevice());
QFileInfo fi = location.toFileInfo();
while ((!fi.exists() || !fi.isDir()) && !fi.isRoot()) while ((!fi.exists() || !fi.isDir()) && !fi.isRoot())
fi.setFile(fi.absolutePath()); fi.setFile(fi.absolutePath());
location = fi.absoluteFilePath(); location = FilePath::fromString(fi.absoluteFilePath());
} else if (!m_filePath.isEmpty()) { } else if (!m_filePath.isEmpty()) {
QTC_CHECK(!m_filePath.needsDevice());
QFileInfo fi = m_filePath.toFileInfo(); QFileInfo fi = m_filePath.toFileInfo();
// remove any /suffixes, which e.g. ResourceNode uses // remove any /suffixes, which e.g. ResourceNode uses
// Note this could be removed again by making path() a true path again // Note this could be removed again by making path() a true path again
@@ -341,9 +343,9 @@ QString Node::pathOrDirectory(bool dir) const
fi.setFile(fi.absolutePath()); fi.setFile(fi.absolutePath());
if (dir) if (dir)
location = fi.isDir() ? fi.absoluteFilePath() : fi.absolutePath(); location = FilePath::fromString(fi.isDir() ? fi.absoluteFilePath() : fi.absolutePath());
else else
location = fi.absoluteFilePath(); location = FilePath::fromString(fi.absoluteFilePath());
} }
return location; return location;
} }

View File

@@ -176,8 +176,8 @@ public:
static FileType fileTypeForMimeType(const Utils::MimeType &mt); static FileType fileTypeForMimeType(const Utils::MimeType &mt);
static FileType fileTypeForFileName(const Utils::FilePath &file); static FileType fileTypeForFileName(const Utils::FilePath &file);
QString path() const { return pathOrDirectory(false); } Utils::FilePath path() const { return pathOrDirectory(false); }
QString directory() const { return pathOrDirectory(true); } Utils::FilePath directory() const { return pathOrDirectory(true); }
protected: protected:
Node(); Node();
@@ -187,7 +187,7 @@ protected:
void setFilePath(const Utils::FilePath &filePath); void setFilePath(const Utils::FilePath &filePath);
private: private:
QString pathOrDirectory(bool dir) const; Utils::FilePath pathOrDirectory(bool dir) const;
FolderNode *m_parentFolderNode = nullptr; FolderNode *m_parentFolderNode = nullptr;
Utils::FilePath m_filePath; Utils::FilePath m_filePath;

View File

@@ -95,7 +95,7 @@ AddNewTree::AddNewTree(FolderNode *node, QList<AddNewTree *> children, const QSt
m_canAdd(false) m_canAdd(false)
{ {
if (node) if (node)
m_toolTip = node->directory(); m_toolTip = node->directory().toString();
foreach (AddNewTree *child, children) foreach (AddNewTree *child, children)
appendChild(child); appendChild(child);
} }
@@ -107,7 +107,7 @@ AddNewTree::AddNewTree(FolderNode *node, QList<AddNewTree *> children,
m_priority(info.priority) m_priority(info.priority)
{ {
if (node) if (node)
m_toolTip = node->directory(); m_toolTip = node->directory().toString();
foreach (AddNewTree *child, children) foreach (AddNewTree *child, children)
appendChild(child); appendChild(child);
} }
@@ -180,7 +180,7 @@ void BestNodeSelector::inspect(AddNewTree *tree, bool isContextNode)
if (m_deploys) if (m_deploys)
return; return;
const QString projectDirectory = node->directory(); const QString projectDirectory = node->directory().toString();
const int projectDirectorySize = projectDirectory.size(); const int projectDirectorySize = projectDirectory.size();
if (m_commonDirectory != projectDirectory if (m_commonDirectory != projectDirectory
&& !m_commonDirectory.startsWith(projectDirectory + QLatin1Char('/')) && !m_commonDirectory.startsWith(projectDirectory + QLatin1Char('/'))

View File

@@ -96,7 +96,8 @@ bool SubdirsProjectWizard::postGenerateFiles(const QWizard *w, const Core::Gener
[](Core::IWizardFactory *f) { [](Core::IWizardFactory *f) {
return f->supportedProjectTypes().contains(Constants::QMAKEPROJECT_ID); return f->supportedProjectTypes().contains(Constants::QMAKEPROJECT_ID);
}), }),
wizard->parameters().projectPath(), map); Utils::FilePath::fromString(wizard->parameters().projectPath()),
map);
} else { } else {
return false; return false;
} }