forked from qt-creator/qt-creator
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:
@@ -242,7 +242,7 @@ static bool wizardFactoryLessThan(const IWizardFactory *f1, const IWizardFactory
|
||||
}
|
||||
|
||||
void NewDialog::setWizardFactories(QList<IWizardFactory *> factories,
|
||||
const QString &defaultLocation,
|
||||
const FilePath &defaultLocation,
|
||||
const QVariantMap &extraVariables)
|
||||
{
|
||||
m_defaultLocation = defaultLocation;
|
||||
@@ -501,7 +501,7 @@ void NewDialog::accept()
|
||||
if (m_ui->templatesView->currentIndex().isValid()) {
|
||||
IWizardFactory *wizard = currentWizardFactory();
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
@@ -27,6 +27,8 @@
|
||||
|
||||
#include "../iwizardfactory.h"
|
||||
|
||||
#include <utils/filepath.h>
|
||||
|
||||
#include <QDialog>
|
||||
#include <QIcon>
|
||||
#include <QList>
|
||||
@@ -54,7 +56,9 @@ public:
|
||||
explicit NewDialog(QWidget *parent);
|
||||
~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();
|
||||
Utils::Id selectedPlatform() const;
|
||||
@@ -84,7 +88,7 @@ private:
|
||||
QPushButton *m_okButton = nullptr;
|
||||
QIcon m_dummyIcon;
|
||||
QList<QStandardItem*> m_categoryItems;
|
||||
QString m_defaultLocation;
|
||||
Utils::FilePath m_defaultLocation;
|
||||
QVariantMap m_extraVariables;
|
||||
};
|
||||
|
||||
|
@@ -245,7 +245,7 @@ ICore::~ICore()
|
||||
*/
|
||||
void ICore::showNewItemDialog(const QString &title,
|
||||
const QList<IWizardFactory *> &factories,
|
||||
const QString &defaultLocation,
|
||||
const FilePath &defaultLocation,
|
||||
const QVariantMap &extraVariables)
|
||||
{
|
||||
QTC_ASSERT(!isNewItemDialogRunning(), return);
|
||||
|
@@ -78,8 +78,8 @@ public:
|
||||
static QWidget *newItemDialog();
|
||||
static void showNewItemDialog(const QString &title,
|
||||
const QList<IWizardFactory *> &factories,
|
||||
const QString &defaultLocation = QString(),
|
||||
const QVariantMap &extraVariables = QVariantMap());
|
||||
const Utils::FilePath &defaultLocation = {},
|
||||
const QVariantMap &extraVariables = {});
|
||||
|
||||
static bool showOptionsDialog(const Utils::Id page, QWidget *parent = nullptr);
|
||||
static QString msgShowOptionsDialog();
|
||||
|
@@ -141,7 +141,7 @@ class NewItemDialogData
|
||||
{
|
||||
public:
|
||||
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);
|
||||
|
||||
@@ -173,7 +173,7 @@ public:
|
||||
private:
|
||||
QString title;
|
||||
QList<IWizardFactory *> factories;
|
||||
QString defaultLocation;
|
||||
FilePath defaultLocation;
|
||||
QVariantMap extraVariables;
|
||||
};
|
||||
|
||||
@@ -358,7 +358,7 @@ QWidget *IWizardFactory::currentWizard()
|
||||
|
||||
void IWizardFactory::requestNewItemDialog(const QString &title,
|
||||
const QList<IWizardFactory *> &factories,
|
||||
const QString &defaultLocation,
|
||||
const FilePath &defaultLocation,
|
||||
const QVariantMap &extraVariables)
|
||||
{
|
||||
s_reopenData.setData(title, factories, defaultLocation, extraVariables);
|
||||
|
@@ -36,7 +36,10 @@
|
||||
|
||||
QT_FORWARD_DECLARE_CLASS(QAction)
|
||||
|
||||
namespace Utils { class Wizard; }
|
||||
namespace Utils {
|
||||
class FilePath;
|
||||
class Wizard;
|
||||
} // Utils
|
||||
|
||||
namespace Core {
|
||||
|
||||
@@ -107,7 +110,7 @@ public:
|
||||
|
||||
static void requestNewItemDialog(const QString &title,
|
||||
const QList<IWizardFactory *> &factories,
|
||||
const QString &defaultLocation,
|
||||
const Utils::FilePath &defaultLocation,
|
||||
const QVariantMap &extraVariables);
|
||||
|
||||
protected:
|
||||
|
@@ -525,7 +525,7 @@ void MainWindow::registerDefaultActions()
|
||||
connect(m_newAction, &QAction::triggered, this, []() {
|
||||
if (!ICore::isNewItemDialogRunning()) {
|
||||
ICore::showNewItemDialog(tr("New File or Project", "Title of dialog"),
|
||||
IWizardFactory::allWizardFactories(), QString());
|
||||
IWizardFactory::allWizardFactories(), FilePath());
|
||||
} else {
|
||||
ICore::raiseWindow(ICore::newItemDialog());
|
||||
}
|
||||
|
@@ -58,7 +58,7 @@ void addTargetNode(std::unique_ptr<MesonProjectNode> &root, const Target &target
|
||||
if (asFolder) {
|
||||
auto targetNode = std::make_unique<MesonTargetNode>(
|
||||
path.absolutePath().pathAppended(target.name),
|
||||
Target::fullName(Utils::FilePath::fromString(root->path()), target));
|
||||
Target::fullName(root->path(), target));
|
||||
targetNode->setDisplayName(target.name);
|
||||
asFolder->addNode(std::move(targetNode));
|
||||
}
|
||||
|
@@ -77,7 +77,8 @@ NimProjectScanner::NimProjectScanner(Project *project)
|
||||
}
|
||||
|
||||
// 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());
|
||||
m_directoryWatcher.addDirectories(Utils::toList(fsDirs - projectDirs), FileSystemWatcher::WatchAllChanges);
|
||||
m_directoryWatcher.removeDirectories(Utils::toList(projectDirs - fsDirs));
|
||||
|
@@ -512,7 +512,7 @@ void FolderNavigationWidget::addNewItem()
|
||||
Utils::filtered(Core::IWizardFactory::allWizardFactories(),
|
||||
Utils::equal(&Core::IWizardFactory::kind,
|
||||
Core::IWizardFactory::FileWizard)),
|
||||
path.toString());
|
||||
path);
|
||||
}
|
||||
|
||||
void FolderNavigationWidget::editCurrentItem()
|
||||
|
@@ -3515,7 +3515,7 @@ void ProjectExplorerPluginPrivate::addNewFile()
|
||||
{
|
||||
Node *currentNode = ProjectTree::currentNode();
|
||||
QTC_ASSERT(currentNode, return);
|
||||
QString location = currentNode->directory();
|
||||
FilePath location = currentNode->directory();
|
||||
|
||||
QVariantMap map;
|
||||
// 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();
|
||||
QTC_ASSERT(currentNode, return);
|
||||
QString location = currentNode->directory();
|
||||
FilePath location = currentNode->directory();
|
||||
|
||||
if (currentNode->isProjectNodeType()
|
||||
&& currentNode->supportsAction(AddSubProject, currentNode)) {
|
||||
@@ -3576,9 +3576,9 @@ void ProjectExplorerPluginPrivate::addExistingProjects()
|
||||
if (!projectNode && currentNode->asContainerNode())
|
||||
projectNode = currentNode->asContainerNode()->rootProjectNode();
|
||||
QTC_ASSERT(projectNode, return);
|
||||
const QString dir = currentNode->directory();
|
||||
const FilePath dir = currentNode->directory();
|
||||
QStringList subProjectFilePaths = QFileDialog::getOpenFileNames(
|
||||
ICore::dialogParent(), tr("Choose Project File"), dir,
|
||||
ICore::dialogParent(), tr("Choose Project File"), dir.toString(),
|
||||
projectNode->subProjectFileNamePatterns().join(";;"));
|
||||
if (!ProjectTree::hasNode(projectNode))
|
||||
return;
|
||||
@@ -3605,7 +3605,7 @@ void ProjectExplorerPluginPrivate::addExistingProjects()
|
||||
message + "\n " + failedProjects.join("\n "));
|
||||
return;
|
||||
}
|
||||
VcsManager::promptToAdd(dir, addedProjects);
|
||||
VcsManager::promptToAdd(dir.toString(), addedProjects);
|
||||
}
|
||||
|
||||
void ProjectExplorerPluginPrivate::handleAddExistingFiles()
|
||||
@@ -3616,7 +3616,7 @@ void ProjectExplorerPluginPrivate::handleAddExistingFiles()
|
||||
QTC_ASSERT(folderNode, return);
|
||||
|
||||
QStringList fileNames = QFileDialog::getOpenFileNames(ICore::dialogParent(),
|
||||
tr("Add Existing Files"), node->directory());
|
||||
tr("Add Existing Files"), node->directory().toString());
|
||||
if (fileNames.isEmpty())
|
||||
return;
|
||||
|
||||
@@ -3631,8 +3631,7 @@ void ProjectExplorerPluginPrivate::addExistingDirectory()
|
||||
|
||||
QTC_ASSERT(folderNode, return);
|
||||
|
||||
SelectableFilesDialogAddDirectory dialog(FilePath::fromString(node->directory()),
|
||||
FilePaths(), ICore::dialogParent());
|
||||
SelectableFilesDialogAddDirectory dialog(node->directory(), FilePaths(), ICore::dialogParent());
|
||||
dialog.setAddFileFilter({});
|
||||
|
||||
if (dialog.exec() == QDialog::Accepted)
|
||||
@@ -3645,7 +3644,7 @@ void ProjectExplorerPlugin::addExistingFiles(FolderNode *folderNode, const FileP
|
||||
if (!folderNode || !ProjectTree::hasNode(folderNode))
|
||||
return;
|
||||
|
||||
const QString dir = folderNode->directory();
|
||||
const FilePath dir = folderNode->directory();
|
||||
FilePaths fileNames = filePaths;
|
||||
FilePaths notAdded;
|
||||
folderNode->addFiles(fileNames, ¬Added);
|
||||
@@ -3659,7 +3658,7 @@ void ProjectExplorerPlugin::addExistingFiles(FolderNode *folderNode, const FileP
|
||||
[¬Added](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()
|
||||
@@ -3687,14 +3686,14 @@ void ProjectExplorerPluginPrivate::searchOnFileSystem()
|
||||
{
|
||||
const Node *currentNode = ProjectTree::currentNode();
|
||||
QTC_ASSERT(currentNode, return);
|
||||
TextEditor::FindInFiles::findOnFileSystem(currentNode->path());
|
||||
TextEditor::FindInFiles::findOnFileSystem(currentNode->path().toString());
|
||||
}
|
||||
|
||||
void ProjectExplorerPluginPrivate::showInGraphicalShell()
|
||||
{
|
||||
Node *currentNode = ProjectTree::currentNode();
|
||||
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)
|
||||
@@ -3706,7 +3705,7 @@ void ProjectExplorerPluginPrivate::openTerminalHere(const EnvironmentGetter &env
|
||||
if (!environment)
|
||||
return;
|
||||
|
||||
Core::FileUtils::openTerminal(currentNode->directory(), environment.value());
|
||||
Core::FileUtils::openTerminal(currentNode->directory().toString(), environment.value());
|
||||
}
|
||||
|
||||
void ProjectExplorerPluginPrivate::openTerminalHereWithRunEnv()
|
||||
@@ -3728,7 +3727,7 @@ void ProjectExplorerPluginPrivate::openTerminalHereWithRunEnv()
|
||||
device = DeviceKitAspect::device(target->kit());
|
||||
QTC_ASSERT(device && device->canOpenTerminal(), return);
|
||||
const QString workingDir = device->type() == Constants::DESKTOP_DEVICE_TYPE
|
||||
? currentNode->directory() : runnable.workingDirectory;
|
||||
? currentNode->directory().toString() : runnable.workingDirectory;
|
||||
device->openTerminal(runnable.environment, workingDir);
|
||||
}
|
||||
|
||||
|
@@ -311,28 +311,30 @@ FileType Node::fileTypeForFileName(const Utils::FilePath &file)
|
||||
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();
|
||||
if (isVirtualFolderType() && folder) {
|
||||
// Virtual Folder case
|
||||
// If there are files directly below or no subfolders, take the folder path
|
||||
if (!folder->fileNodes().isEmpty() || folder->folderNodes().isEmpty()) {
|
||||
location = m_filePath.toString();
|
||||
location = m_filePath;
|
||||
} else {
|
||||
// Otherwise we figure out a commonPath from the subfolders
|
||||
QStringList list;
|
||||
foreach (FolderNode *f, folder->folderNodes())
|
||||
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())
|
||||
fi.setFile(fi.absolutePath());
|
||||
location = fi.absoluteFilePath();
|
||||
location = FilePath::fromString(fi.absoluteFilePath());
|
||||
} else if (!m_filePath.isEmpty()) {
|
||||
QTC_CHECK(!m_filePath.needsDevice());
|
||||
QFileInfo fi = m_filePath.toFileInfo();
|
||||
// remove any /suffixes, which e.g. ResourceNode uses
|
||||
// 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());
|
||||
|
||||
if (dir)
|
||||
location = fi.isDir() ? fi.absoluteFilePath() : fi.absolutePath();
|
||||
location = FilePath::fromString(fi.isDir() ? fi.absoluteFilePath() : fi.absolutePath());
|
||||
else
|
||||
location = fi.absoluteFilePath();
|
||||
location = FilePath::fromString(fi.absoluteFilePath());
|
||||
}
|
||||
return location;
|
||||
}
|
||||
|
@@ -176,8 +176,8 @@ public:
|
||||
static FileType fileTypeForMimeType(const Utils::MimeType &mt);
|
||||
static FileType fileTypeForFileName(const Utils::FilePath &file);
|
||||
|
||||
QString path() const { return pathOrDirectory(false); }
|
||||
QString directory() const { return pathOrDirectory(true); }
|
||||
Utils::FilePath path() const { return pathOrDirectory(false); }
|
||||
Utils::FilePath directory() const { return pathOrDirectory(true); }
|
||||
|
||||
protected:
|
||||
Node();
|
||||
@@ -187,7 +187,7 @@ protected:
|
||||
void setFilePath(const Utils::FilePath &filePath);
|
||||
|
||||
private:
|
||||
QString pathOrDirectory(bool dir) const;
|
||||
Utils::FilePath pathOrDirectory(bool dir) const;
|
||||
|
||||
FolderNode *m_parentFolderNode = nullptr;
|
||||
Utils::FilePath m_filePath;
|
||||
|
@@ -95,7 +95,7 @@ AddNewTree::AddNewTree(FolderNode *node, QList<AddNewTree *> children, const QSt
|
||||
m_canAdd(false)
|
||||
{
|
||||
if (node)
|
||||
m_toolTip = node->directory();
|
||||
m_toolTip = node->directory().toString();
|
||||
foreach (AddNewTree *child, children)
|
||||
appendChild(child);
|
||||
}
|
||||
@@ -107,7 +107,7 @@ AddNewTree::AddNewTree(FolderNode *node, QList<AddNewTree *> children,
|
||||
m_priority(info.priority)
|
||||
{
|
||||
if (node)
|
||||
m_toolTip = node->directory();
|
||||
m_toolTip = node->directory().toString();
|
||||
foreach (AddNewTree *child, children)
|
||||
appendChild(child);
|
||||
}
|
||||
@@ -180,7 +180,7 @@ void BestNodeSelector::inspect(AddNewTree *tree, bool isContextNode)
|
||||
if (m_deploys)
|
||||
return;
|
||||
|
||||
const QString projectDirectory = node->directory();
|
||||
const QString projectDirectory = node->directory().toString();
|
||||
const int projectDirectorySize = projectDirectory.size();
|
||||
if (m_commonDirectory != projectDirectory
|
||||
&& !m_commonDirectory.startsWith(projectDirectory + QLatin1Char('/'))
|
||||
|
@@ -96,7 +96,8 @@ bool SubdirsProjectWizard::postGenerateFiles(const QWizard *w, const Core::Gener
|
||||
[](Core::IWizardFactory *f) {
|
||||
return f->supportedProjectTypes().contains(Constants::QMAKEPROJECT_ID);
|
||||
}),
|
||||
wizard->parameters().projectPath(), map);
|
||||
Utils::FilePath::fromString(wizard->parameters().projectPath()),
|
||||
map);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
Reference in New Issue
Block a user