Core: FilePath-ify DocumentManager

And adjust users.

Change-Id: I10ca9aeb442a07f7c8d42af362b294aa3398f5c1
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
hjk
2021-09-21 06:36:32 +02:00
parent 08f3c10bf5
commit 1167f0fac7
22 changed files with 127 additions and 124 deletions

View File

@@ -69,7 +69,7 @@ static int indexOfFile(const GeneratedFiles &f, const QString &path)
\sa Core::BaseFileWizardFactory \sa Core::BaseFileWizardFactory
*/ */
Utils::Wizard *BaseFileWizardFactory::runWizardImpl(const QString &path, QWidget *parent, Utils::Wizard *BaseFileWizardFactory::runWizardImpl(const FilePath &path, QWidget *parent,
Id platform, Id platform,
const QVariantMap &extraValues, const QVariantMap &extraValues,
bool showWizard) bool showWizard)
@@ -86,7 +86,8 @@ Utils::Wizard *BaseFileWizardFactory::runWizardImpl(const QString &path, QWidget
if (flags().testFlag(ForceCapitalLetterForFileName)) if (flags().testFlag(ForceCapitalLetterForFileName))
dialogParameterFlags |= WizardDialogParameters::ForceCapitalLetterForFileName; dialogParameterFlags |= WizardDialogParameters::ForceCapitalLetterForFileName;
Utils::Wizard *wizard = create(parent, WizardDialogParameters(path, platform, Utils::Wizard *wizard = create(parent, WizardDialogParameters(path.toString(),
platform,
requiredFeatures(), requiredFeatures(),
dialogParameterFlags, dialogParameterFlags,
extraValues)); extraValues));

View File

@@ -114,9 +114,8 @@ protected:
static bool postGenerateOpenEditors(const GeneratedFiles &l, QString *errorMessage = nullptr); static bool postGenerateOpenEditors(const GeneratedFiles &l, QString *errorMessage = nullptr);
private: private:
// IWizard Utils::Wizard *runWizardImpl(const Utils::FilePath &path, QWidget *parent, Utils::Id platform,
Utils::Wizard *runWizardImpl(const QString &path, QWidget *parent, Utils::Id platform, const QVariantMap &extraValues, bool showWizard = true) final;
const QVariantMap &extraValues, bool showWizard = true) override;
}; };
} // namespace Core } // namespace Core

View File

@@ -202,7 +202,7 @@ bool CorePlugin::initialize(const QStringList &arguments, QString *errorMessage)
expander->registerVariable("Config:DefaultProjectDirectory", tr("The configured default directory for projects."), expander->registerVariable("Config:DefaultProjectDirectory", tr("The configured default directory for projects."),
[]() { return DocumentManager::projectsDirectory().toString(); }); []() { return DocumentManager::projectsDirectory().toString(); });
expander->registerVariable("Config:LastFileDialogDirectory", tr("The directory last visited in a file dialog."), expander->registerVariable("Config:LastFileDialogDirectory", tr("The directory last visited in a file dialog."),
[]() { return DocumentManager::fileDialogLastVisitedDirectory(); }); []() { return DocumentManager::fileDialogLastVisitedDirectory().toString(); });
expander->registerVariable("HostOs:isWindows", expander->registerVariable("HostOs:isWindows",
tr("Is %1 running on Windows?").arg(Constants::IDE_DISPLAY_NAME), tr("Is %1 running on Windows?").arg(Constants::IDE_DISPLAY_NAME),
[]() { return QVariant(Utils::HostOsInfo::isWindowsHost()).toString(); }); []() { return QVariant(Utils::HostOsInfo::isWindowsHost()).toString(); });

View File

@@ -473,10 +473,10 @@ void NewDialogWidget::saveState()
m_ui->comboBox->currentData().toString()); m_ui->comboBox->currentData().toString());
} }
static void runWizard(IWizardFactory *wizard, const QString &defaultLocation, Id platform, static void runWizard(IWizardFactory *wizard, const FilePath &defaultLocation, Id platform,
const QVariantMap &variables) const QVariantMap &variables)
{ {
QString path = wizard->runPath(defaultLocation); const FilePath path = wizard->runPath(defaultLocation);
wizard->runWizard(path, ICore::dialogParent(), platform, variables); wizard->runWizard(path, ICore::dialogParent(), platform, variables);
} }
@@ -486,7 +486,7 @@ void NewDialogWidget::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.toString(), QMetaObject::invokeMethod(wizard, std::bind(&runWizard, wizard, m_defaultLocation,
selectedPlatform(), m_extraVariables), Qt::QueuedConnection); selectedPlatform(), m_extraVariables), Qt::QueuedConnection);
} }
} }

View File

@@ -530,12 +530,12 @@ void ShortcutSettingsWidget::defaultAction()
void ShortcutSettingsWidget::exportAction() void ShortcutSettingsWidget::exportAction()
{ {
QString fileName const FilePath filePath
= DocumentManager::getSaveFileNameWithExtension(tr("Export Keyboard Mapping Scheme"), = DocumentManager::getSaveFileNameWithExtension(tr("Export Keyboard Mapping Scheme"),
schemesPath().toString(), schemesPath(),
tr("Keyboard Mapping Scheme (*.kms)")); tr("Keyboard Mapping Scheme (*.kms)"));
if (!fileName.isEmpty()) { if (!filePath.isEmpty()) {
CommandsFile cf(FilePath::fromString(fileName)); CommandsFile cf(filePath);
cf.exportCommands(m_scitems); cf.exportCommands(m_scitems);
} }
} }

View File

@@ -188,8 +188,8 @@ public:
QFileSystemWatcher *m_fileWatcher = nullptr; // Delayed creation. QFileSystemWatcher *m_fileWatcher = nullptr; // Delayed creation.
QFileSystemWatcher *m_linkWatcher = nullptr; // Delayed creation (only UNIX/if a link is seen). QFileSystemWatcher *m_linkWatcher = nullptr; // Delayed creation (only UNIX/if a link is seen).
QString m_lastVisitedDirectory = QDir::currentPath(); FilePath m_lastVisitedDirectory = FilePath::fromString(QDir::currentPath());
QString m_defaultLocationForNewFiles; FilePath m_defaultLocationForNewFiles;
FilePath m_projectsDirectory; FilePath m_projectsDirectory;
// When we are calling into an IDocument // When we are calling into an IDocument
// we don't want to receive a changed() // we don't want to receive a changed()
@@ -287,7 +287,7 @@ DocumentManager::DocumentManager(QObject *parent)
readSettings(); readSettings();
if (d->m_useProjectsDirectory) if (d->m_useProjectsDirectory)
setFileDialogLastVisitedDirectory(d->m_projectsDirectory.toString()); setFileDialogLastVisitedDirectory(d->m_projectsDirectory);
} }
DocumentManager::~DocumentManager() DocumentManager::~DocumentManager()
@@ -796,17 +796,17 @@ QString DocumentManager::allDocumentFactoryFiltersString(QString *allFilesFilter
return filters.join(QLatin1String(";;")); return filters.join(QLatin1String(";;"));
} }
QString DocumentManager::getSaveFileName(const QString &title, const QString &pathIn, FilePath DocumentManager::getSaveFileName(const QString &title, const FilePath &pathIn,
const QString &filter, QString *selectedFilter) const QString &filter, QString *selectedFilter)
{ {
const FilePath path = FilePath::fromString(pathIn.isEmpty() ? fileDialogInitialDirectory() : pathIn); const FilePath path = pathIn.isEmpty() ? fileDialogInitialDirectory() : pathIn;
QString fileName; FilePath filePath;
bool repeat; bool repeat;
do { do {
repeat = false; repeat = false;
fileName = FileUtils::getSaveFilePath(nullptr, title, path, filter, selectedFilter, filePath = FileUtils::getSaveFilePath(nullptr, title, path, filter, selectedFilter,
QFileDialog::DontConfirmOverwrite).toString(); QFileDialog::DontConfirmOverwrite);
if (!fileName.isEmpty()) { if (!filePath.isEmpty()) {
// If the selected filter is All Files (*) we leave the name exactly as the user // If the selected filter is All Files (*) we leave the name exactly as the user
// specified. Otherwise the suffix must be one available in the selected filter. If // specified. Otherwise the suffix must be one available in the selected filter. If
// the name already ends with such suffix nothing needs to be done. But if not, the // the name already ends with such suffix nothing needs to be done. But if not, the
@@ -822,31 +822,31 @@ QString DocumentManager::getSaveFileName(const QString &title, const QString &pa
caption.remove(QLatin1Char('*')); caption.remove(QLatin1Char('*'));
const QStringList suffixes = caption.split(QLatin1Char(' ')); const QStringList suffixes = caption.split(QLatin1Char(' '));
for (const QString &suffix : suffixes) for (const QString &suffix : suffixes)
if (fileName.endsWith(suffix)) { if (filePath.endsWith(suffix)) {
suffixOk = true; suffixOk = true;
break; break;
} }
if (!suffixOk && !suffixes.isEmpty()) if (!suffixOk && !suffixes.isEmpty())
fileName.append(suffixes.at(0)); filePath = filePath.stringAppended(suffixes.at(0));
} }
} }
if (QFile::exists(fileName)) { if (filePath.exists()) {
if (QMessageBox::warning(ICore::dialogParent(), tr("Overwrite?"), if (QMessageBox::warning(ICore::dialogParent(), tr("Overwrite?"),
tr("An item named \"%1\" already exists at this location. " tr("An item named \"%1\" already exists at this location. "
"Do you want to overwrite it?").arg(QDir::toNativeSeparators(fileName)), "Do you want to overwrite it?").arg(filePath.toUserOutput()),
QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) { QMessageBox::Yes | QMessageBox::No) == QMessageBox::No) {
repeat = true; repeat = true;
} }
} }
} }
} while (repeat); } while (repeat);
if (!fileName.isEmpty()) if (!filePath.isEmpty())
setFileDialogLastVisitedDirectory(QFileInfo(fileName).absolutePath()); setFileDialogLastVisitedDirectory(filePath.absolutePath());
return fileName; return filePath;
} }
QString DocumentManager::getSaveFileNameWithExtension(const QString &title, const QString &pathIn, FilePath DocumentManager::getSaveFileNameWithExtension(const QString &title, const FilePath &pathIn,
const QString &filter) const QString &filter)
{ {
QString selected = filter; QString selected = filter;
return getSaveFileName(title, pathIn, filter, &selected); return getSaveFileName(title, pathIn, filter, &selected);
@@ -855,13 +855,13 @@ QString DocumentManager::getSaveFileNameWithExtension(const QString &title, cons
/*! /*!
Asks the user for a new file name (\uicontrol {Save File As}) for \a document. Asks the user for a new file name (\uicontrol {Save File As}) for \a document.
*/ */
QString DocumentManager::getSaveAsFileName(const IDocument *document) FilePath DocumentManager::getSaveAsFileName(const IDocument *document)
{ {
QTC_ASSERT(document, return QString()); QTC_ASSERT(document, return {});
const QString filter = allDocumentFactoryFiltersString(); const QString filter = allDocumentFactoryFiltersString();
const QString filePath = document->filePath().toString(); const FilePath filePath = document->filePath();
QString selectedFilter; QString selectedFilter;
QString fileDialogPath = filePath; FilePath fileDialogPath = filePath;
if (!filePath.isEmpty()) { if (!filePath.isEmpty()) {
selectedFilter = Utils::mimeTypeForFile(filePath).filterString(); selectedFilter = Utils::mimeTypeForFile(filePath).filterString();
} else { } else {
@@ -871,11 +871,9 @@ QString DocumentManager::getSaveAsFileName(const IDocument *document)
if (!types.isEmpty()) if (!types.isEmpty())
selectedFilter = types.first().filterString(); selectedFilter = types.first().filterString();
} }
const QString defaultPath = document->fallbackSaveAsPath(); const FilePath defaultPath = document->fallbackSaveAsPath();
if (!defaultPath.isEmpty()) if (!defaultPath.isEmpty() && !suggestedName.isEmpty())
fileDialogPath = defaultPath + (suggestedName.isEmpty() fileDialogPath = defaultPath / suggestedName;
? QString()
: '/' + suggestedName);
} }
if (selectedFilter.isEmpty()) if (selectedFilter.isEmpty())
selectedFilter = Utils::mimeTypeForName(document->mimeType()).filterString(); selectedFilter = Utils::mimeTypeForName(document->mimeType()).filterString();
@@ -1037,12 +1035,11 @@ FilePaths DocumentManager::getOpenFileNames(const QString &filters,
const FilePath &pathIn, const FilePath &pathIn,
QString *selectedFilter) QString *selectedFilter)
{ {
const FilePath path = pathIn.isEmpty() ? FilePath::fromString(fileDialogInitialDirectory()) const FilePath path = pathIn.isEmpty() ? fileDialogInitialDirectory() : pathIn;
: pathIn;
const FilePaths files = FileUtils::getOpenFilePaths(nullptr, tr("Open File"), path, filters, const FilePaths files = FileUtils::getOpenFilePaths(nullptr, tr("Open File"), path, filters,
selectedFilter); selectedFilter);
if (!files.isEmpty()) if (!files.isEmpty())
setFileDialogLastVisitedDirectory(files.front().absolutePath().toString()); setFileDialogLastVisitedDirectory(files.front().absolutePath());
return files; return files;
} }
@@ -1086,7 +1083,7 @@ void DocumentManager::checkForReload()
FileDeletedPromptAnswer previousDeletedAnswer = FileDeletedSave; FileDeletedPromptAnswer previousDeletedAnswer = FileDeletedSave;
QList<IDocument *> documentsToClose; QList<IDocument *> documentsToClose;
QHash<IDocument*, QString> documentsToSave; QHash<IDocument*, FilePath> documentsToSave;
// collect file information // collect file information
QMap<FilePath, FileStateItem> currentStates; QMap<FilePath, FileStateItem> currentStates;
@@ -1264,12 +1261,12 @@ void DocumentManager::checkForReload()
} }
switch (previousDeletedAnswer) { switch (previousDeletedAnswer) {
case FileDeletedSave: case FileDeletedSave:
documentsToSave.insert(document, document->filePath().toString()); documentsToSave.insert(document, document->filePath());
unhandled = false; unhandled = false;
break; break;
case FileDeletedSaveAs: case FileDeletedSaveAs:
{ {
const QString &saveFileName = getSaveAsFileName(document); const FilePath saveFileName = getSaveAsFileName(document);
if (!saveFileName.isEmpty()) { if (!saveFileName.isEmpty()) {
documentsToSave.insert(document, saveFileName); documentsToSave.insert(document, saveFileName);
unhandled = false; unhandled = false;
@@ -1307,7 +1304,7 @@ void DocumentManager::checkForReload()
// handle deleted files // handle deleted files
EditorManager::closeDocuments(documentsToClose, false); EditorManager::closeDocuments(documentsToClose, false);
for (auto it = documentsToSave.cbegin(), end = documentsToSave.cend(); it != end; ++it) { for (auto it = documentsToSave.cbegin(), end = documentsToSave.cend(); it != end; ++it) {
saveDocument(it.key(), Utils::FilePath::fromString(it.value())); saveDocument(it.key(), it.value());
it.key()->checkPermissions(); it.key()->checkPermissions();
} }
@@ -1323,7 +1320,7 @@ void DocumentManager::checkForReload()
\a editorId defaults to the empty ID, which lets \QC figure out \a editorId defaults to the empty ID, which lets \QC figure out
the best editor itself. the best editor itself.
*/ */
void DocumentManager::addToRecentFiles(const Utils::FilePath &filePath, Id editorId) void DocumentManager::addToRecentFiles(const FilePath &filePath, Id editorId)
{ {
if (filePath.isEmpty()) if (filePath.isEmpty())
return; return;
@@ -1417,11 +1414,11 @@ void readSettings()
\sa setFileDialogLastVisitedDirectory(), setDefaultLocationForNewFiles() \sa setFileDialogLastVisitedDirectory(), setDefaultLocationForNewFiles()
*/ */
QString DocumentManager::fileDialogInitialDirectory() FilePath DocumentManager::fileDialogInitialDirectory()
{ {
IDocument *doc = EditorManager::currentDocument(); IDocument *doc = EditorManager::currentDocument();
if (doc && !doc->isTemporary() && !doc->filePath().isEmpty()) if (doc && !doc->isTemporary() && !doc->filePath().isEmpty())
return doc->filePath().absolutePath().path(); return doc->filePath().absolutePath();
if (!d->m_defaultLocationForNewFiles.isEmpty()) if (!d->m_defaultLocationForNewFiles.isEmpty())
return d->m_defaultLocationForNewFiles; return d->m_defaultLocationForNewFiles;
return d->m_lastVisitedDirectory; return d->m_lastVisitedDirectory;
@@ -1433,7 +1430,7 @@ QString DocumentManager::fileDialogInitialDirectory()
\sa fileDialogInitialDirectory() \sa fileDialogInitialDirectory()
*/ */
QString DocumentManager::defaultLocationForNewFiles() FilePath DocumentManager::defaultLocationForNewFiles()
{ {
return d->m_defaultLocationForNewFiles; return d->m_defaultLocationForNewFiles;
} }
@@ -1441,7 +1438,7 @@ QString DocumentManager::defaultLocationForNewFiles()
/*! /*!
Sets the default \a location for new files. Sets the default \a location for new files.
*/ */
void DocumentManager::setDefaultLocationForNewFiles(const QString &location) void DocumentManager::setDefaultLocationForNewFiles(const FilePath &location)
{ {
d->m_defaultLocationForNewFiles = location; d->m_defaultLocationForNewFiles = location;
} }
@@ -1507,7 +1504,7 @@ void DocumentManager::setUseProjectsDirectory(bool useProjectsDirectory)
*/ */
QString DocumentManager::fileDialogLastVisitedDirectory() FilePath DocumentManager::fileDialogLastVisitedDirectory()
{ {
return d->m_lastVisitedDirectory; return d->m_lastVisitedDirectory;
} }
@@ -1521,12 +1518,12 @@ QString DocumentManager::fileDialogLastVisitedDirectory()
*/ */
void DocumentManager::setFileDialogLastVisitedDirectory(const QString &directory) void DocumentManager::setFileDialogLastVisitedDirectory(const FilePath &directory)
{ {
d->m_lastVisitedDirectory = directory; d->m_lastVisitedDirectory = directory;
} }
void DocumentManager::notifyFilesChangedInternally(const Utils::FilePaths &filePaths) void DocumentManager::notifyFilesChangedInternally(const FilePaths &filePaths)
{ {
emit m_instance->filesChangedInternally(filePaths); emit m_instance->filesChangedInternally(filePaths);
} }

View File

@@ -87,13 +87,14 @@ public:
static Utils::FilePaths getOpenFileNames(const QString &filters, static Utils::FilePaths getOpenFileNames(const QString &filters,
const Utils::FilePath &path = {}, const Utils::FilePath &path = {},
QString *selectedFilter = nullptr); QString *selectedFilter = nullptr);
static QString getSaveFileName(const QString &title, static Utils::FilePath getSaveFileName(const QString &title,
const QString &pathIn, const Utils::FilePath &pathIn,
const QString &filter = QString(), const QString &filter = {},
QString *selectedFilter = nullptr); QString *selectedFilter = nullptr);
static QString getSaveFileNameWithExtension(const QString &title, const QString &pathIn, static Utils::FilePath getSaveFileNameWithExtension(const QString &title,
const QString &filter); const Utils::FilePath &pathIn,
static QString getSaveAsFileName(const IDocument *document); const QString &filter);
static Utils::FilePath getSaveAsFileName(const IDocument *document);
static bool saveAllModifiedDocumentsSilently(bool *canceled = nullptr, static bool saveAllModifiedDocumentsSilently(bool *canceled = nullptr,
QList<IDocument *> *failedToClose = nullptr); QList<IDocument *> *failedToClose = nullptr);
@@ -123,13 +124,13 @@ public:
QList<IDocument *> *failedToClose = nullptr); QList<IDocument *> *failedToClose = nullptr);
static void showFilePropertiesDialog(const Utils::FilePath &filePath); static void showFilePropertiesDialog(const Utils::FilePath &filePath);
static QString fileDialogLastVisitedDirectory(); static Utils::FilePath fileDialogLastVisitedDirectory();
static void setFileDialogLastVisitedDirectory(const QString &); static void setFileDialogLastVisitedDirectory(const Utils::FilePath &);
static QString fileDialogInitialDirectory(); static Utils::FilePath fileDialogInitialDirectory();
static QString defaultLocationForNewFiles(); static Utils::FilePath defaultLocationForNewFiles();
static void setDefaultLocationForNewFiles(const QString &location); static void setDefaultLocationForNewFiles(const Utils::FilePath &location);
static bool useProjectsDirectory(); static bool useProjectsDirectory();
static void setUseProjectsDirectory(bool); static void setUseProjectsDirectory(bool);

View File

@@ -2478,7 +2478,7 @@ bool EditorManagerPrivate::saveDocumentAs(IDocument *document)
if (!document) if (!document)
return false; return false;
const auto &absoluteFilePath = FilePath::fromString(DocumentManager::getSaveAsFileName(document)); const FilePath absoluteFilePath = DocumentManager::getSaveAsFileName(document);
if (absoluteFilePath.isEmpty()) if (absoluteFilePath.isEmpty())
return false; return false;

View File

@@ -565,9 +565,9 @@ void IDocument::setTemporary(bool temporary)
\sa fallbackSaveAsFileName() \sa fallbackSaveAsFileName()
*/ */
QString IDocument::fallbackSaveAsPath() const FilePath IDocument::fallbackSaveAsPath() const
{ {
return QString(); return {};
} }
/*! /*!

View File

@@ -108,7 +108,7 @@ public:
bool isTemporary() const; bool isTemporary() const;
void setTemporary(bool temporary); void setTemporary(bool temporary);
virtual QString fallbackSaveAsPath() const; virtual Utils::FilePath fallbackSaveAsPath() const;
virtual QString fallbackSaveAsFileName() const; virtual QString fallbackSaveAsFileName() const;
QString mimeType() const; QString mimeType() const;

View File

@@ -213,7 +213,7 @@ QList<IWizardFactory*> IWizardFactory::allWizardFactories()
connect(newFactory->m_action, &QAction::triggered, newFactory, [newFactory]() { connect(newFactory->m_action, &QAction::triggered, newFactory, [newFactory]() {
if (!ICore::isNewItemDialogRunning()) { if (!ICore::isNewItemDialogRunning()) {
QString path = newFactory->runPath(QString()); FilePath path = newFactory->runPath({});
newFactory->runWizard(path, ICore::dialogParent(), Id(), QVariantMap()); newFactory->runWizard(path, ICore::dialogParent(), Id(), QVariantMap());
} }
}); });
@@ -227,9 +227,9 @@ QList<IWizardFactory*> IWizardFactory::allWizardFactories()
return s_allFactories; return s_allFactories;
} }
QString IWizardFactory::runPath(const QString &defaultPath) const FilePath IWizardFactory::runPath(const FilePath &defaultPath) const
{ {
QString path = defaultPath; FilePath path = defaultPath;
if (path.isEmpty()) { if (path.isEmpty()) {
switch (kind()) { switch (kind()) {
case IWizardFactory::ProjectWizard: case IWizardFactory::ProjectWizard:
@@ -237,7 +237,7 @@ QString IWizardFactory::runPath(const QString &defaultPath) const
// use last visited directory of file dialog. Never start // use last visited directory of file dialog. Never start
// at current. // at current.
path = DocumentManager::useProjectsDirectory() path = DocumentManager::useProjectsDirectory()
? DocumentManager::projectsDirectory().toString() ? DocumentManager::projectsDirectory()
: DocumentManager::fileDialogLastVisitedDirectory(); : DocumentManager::fileDialogLastVisitedDirectory();
break; break;
default: default:
@@ -257,9 +257,9 @@ QString IWizardFactory::runPath(const QString &defaultPath) const
created. The wizard should fill this in its path selection elements as a created. The wizard should fill this in its path selection elements as a
default path. default path.
*/ */
Utils::Wizard *IWizardFactory::runWizard(const QString &path, QWidget *parent, Id platform, Wizard *IWizardFactory::runWizard(const FilePath &path, QWidget *parent, Id platform,
const QVariantMap &variables, const QVariantMap &variables,
bool showWizard) bool showWizard)
{ {
QTC_ASSERT(!s_isWizardRunning, return nullptr); QTC_ASSERT(!s_isWizardRunning, return nullptr);

View File

@@ -90,10 +90,10 @@ public:
void setFlags(WizardFlags flags) { m_flags = flags; } void setFlags(WizardFlags flags) { m_flags = flags; }
void setDetailsPageQmlPath(const QString &filePath); void setDetailsPageQmlPath(const QString &filePath);
QString runPath(const QString &defaultPath) const; Utils::FilePath runPath(const Utils::FilePath &defaultPath) const;
// Does bookkeeping and the calls runWizardImpl. Please implement that. // Does bookkeeping and the calls runWizardImpl. Please implement that.
Utils::Wizard *runWizard(const QString &path, QWidget *parent, Utils::Id platform, Utils::Wizard *runWizard(const Utils::FilePath &path, QWidget *parent, Utils::Id platform,
const QVariantMap &variables, bool showWizard = true); const QVariantMap &variables, bool showWizard = true);
virtual bool isAvailable(Utils::Id platformId) const; virtual bool isAvailable(Utils::Id platformId) const;
@@ -121,8 +121,11 @@ protected:
static QSet<Utils::Id> pluginFeatures(); static QSet<Utils::Id> pluginFeatures();
static QSet<Utils::Id> availableFeatures(Utils::Id platformId); static QSet<Utils::Id> availableFeatures(Utils::Id platformId);
virtual Utils::Wizard *runWizardImpl(const QString &path, QWidget *parent, Utils::Id platform, virtual Utils::Wizard *runWizardImpl(const Utils::FilePath &path,
const QVariantMap &variables, bool showWizard = true) = 0; QWidget *parent,
Utils::Id platform,
const QVariantMap &variables,
bool showWizard = true) = 0;
private: private:
static void initialize(); static void initialize();

View File

@@ -78,7 +78,7 @@ FileSystemFilter::FileSystemFilter()
void FileSystemFilter::prepareSearch(const QString &entry) void FileSystemFilter::prepareSearch(const QString &entry)
{ {
Q_UNUSED(entry) Q_UNUSED(entry)
m_currentDocumentDirectory = DocumentManager::fileDialogInitialDirectory(); m_currentDocumentDirectory = DocumentManager::fileDialogInitialDirectory().toString();
m_currentIncludeHidden = m_includeHidden; m_currentIncludeHidden = m_includeHidden;
} }

View File

@@ -253,11 +253,11 @@ bool DiffEditorDocument::setContents(const QByteArray &contents)
return true; return true;
} }
QString DiffEditorDocument::fallbackSaveAsPath() const FilePath DiffEditorDocument::fallbackSaveAsPath() const
{ {
if (!m_baseDirectory.isEmpty()) if (!m_baseDirectory.isEmpty())
return m_baseDirectory.toString(); return m_baseDirectory;
return QDir::homePath(); return FileUtils::homePath();
} }
bool DiffEditorDocument::isSaveAsAllowed() const bool DiffEditorDocument::isSaveAsAllowed() const

View File

@@ -77,7 +77,7 @@ public:
bool ignoreWhitespace() const; bool ignoreWhitespace() const;
bool setContents(const QByteArray &contents) override; bool setContents(const QByteArray &contents) override;
QString fallbackSaveAsPath() const override; Utils::FilePath fallbackSaveAsPath() const override;
QString fallbackSaveAsFileName() const override; QString fallbackSaveAsFileName() const override;
bool isSaveAsAllowed() const override; bool isSaveAsAllowed() const override;

View File

@@ -176,7 +176,7 @@ void ProjectExplorer::ProjectExplorerPlugin::testJsonWizardsCheckBox()
const FactoryPtr factory(JsonWizardFactory::createWizardFactory(wizardObject.toVariantMap(), QDir(), &errorMessage)); const FactoryPtr factory(JsonWizardFactory::createWizardFactory(wizardObject.toVariantMap(), QDir(), &errorMessage));
QVERIFY2(factory, qPrintable(errorMessage)); QVERIFY2(factory, qPrintable(errorMessage));
Wizard *wizard = factory->runWizard(QString(), &parent, Id(), QVariantMap()); Wizard *wizard = factory->runWizard({}, &parent, Id(), QVariantMap());
QVERIFY(!findCheckBox(wizard, "Default")->isChecked()); QVERIFY(!findCheckBox(wizard, "Default")->isChecked());
QCOMPARE(wizard->field("DefaultCheckBox"), QVariant(false)); QCOMPARE(wizard->field("DefaultCheckBox"), QVariant(false));
@@ -208,7 +208,7 @@ void ProjectExplorer::ProjectExplorerPlugin::testJsonWizardsLineEdit()
const FactoryPtr factory(JsonWizardFactory::createWizardFactory(wizardObject.toVariantMap(), QDir(), &errorMessage)); const FactoryPtr factory(JsonWizardFactory::createWizardFactory(wizardObject.toVariantMap(), QDir(), &errorMessage));
QVERIFY2(factory, qPrintable(errorMessage)); QVERIFY2(factory, qPrintable(errorMessage));
Wizard *wizard = factory->runWizard(QString(), &parent, Id(), QVariantMap()); Wizard *wizard = factory->runWizard({}, &parent, Id(), QVariantMap());
QVERIFY(findLineEdit(wizard, "Default")); QVERIFY(findLineEdit(wizard, "Default"));
QVERIFY(findLineEdit(wizard, "Default")->text().isEmpty()); QVERIFY(findLineEdit(wizard, "Default")->text().isEmpty());
QCOMPARE(qPrintable(findLineEdit(wizard, "WithText")->text()), "some text"); QCOMPARE(qPrintable(findLineEdit(wizard, "WithText")->text()), "some text");
@@ -236,7 +236,7 @@ void ProjectExplorer::ProjectExplorerPlugin::testJsonWizardsComboBox()
const QJsonObject wizardObject = createGeneralWizard(pages); const QJsonObject wizardObject = createGeneralWizard(pages);
const FactoryPtr factory(JsonWizardFactory::createWizardFactory(wizardObject.toVariantMap(), QDir(), &errorMessage)); const FactoryPtr factory(JsonWizardFactory::createWizardFactory(wizardObject.toVariantMap(), QDir(), &errorMessage));
QVERIFY2(factory, qPrintable(errorMessage)); QVERIFY2(factory, qPrintable(errorMessage));
Utils::Wizard *wizard = factory->runWizard(QString(), &parent, Id(), QVariantMap()); Utils::Wizard *wizard = factory->runWizard({}, &parent, Id(), QVariantMap());
QComboBox *defaultComboBox = findComboBox(wizard, "Default"); QComboBox *defaultComboBox = findComboBox(wizard, "Default");
QVERIFY(defaultComboBox); QVERIFY(defaultComboBox);
@@ -294,7 +294,7 @@ void ProjectExplorer::ProjectExplorerPlugin::testJsonWizardsIconList()
const QJsonObject wizardObject = createGeneralWizard(pages); const QJsonObject wizardObject = createGeneralWizard(pages);
const FactoryPtr factory(JsonWizardFactory::createWizardFactory(wizardObject.toVariantMap(), QDir(), &errorMessage)); const FactoryPtr factory(JsonWizardFactory::createWizardFactory(wizardObject.toVariantMap(), QDir(), &errorMessage));
QVERIFY2(factory, qPrintable(errorMessage)); QVERIFY2(factory, qPrintable(errorMessage));
Wizard *wizard = factory->runWizard(QString(), &parent, Id(), QVariantMap()); Wizard *wizard = factory->runWizard({}, &parent, Id(), QVariantMap());
auto view = wizard->findChild<QListView *>("FancyIconList"); auto view = wizard->findChild<QListView *>("FancyIconList");
QCOMPARE(view->model()->rowCount(), 2); QCOMPARE(view->model()->rowCount(), 2);

View File

@@ -54,6 +54,8 @@
#include <QMap> #include <QMap>
#include <QUuid> #include <QUuid>
using namespace Utils;
namespace ProjectExplorer { namespace ProjectExplorer {
static QList<JsonWizardPageFactory *> s_pageFactories; static QList<JsonWizardPageFactory *> s_pageFactories;
@@ -371,7 +373,7 @@ void JsonWizardFactory::registerGeneratorFactory(JsonWizardGeneratorFactory *fac
s_generatorFactories.append(factory); s_generatorFactories.append(factory);
} }
Utils::Wizard *JsonWizardFactory::runWizardImpl(const QString &path, QWidget *parent, Utils::Wizard *JsonWizardFactory::runWizardImpl(const FilePath &path, QWidget *parent,
Utils::Id platform, Utils::Id platform,
const QVariantMap &variables, bool showWizard) const QVariantMap &variables, bool showWizard)
{ {
@@ -394,7 +396,7 @@ Utils::Wizard *JsonWizardFactory::runWizardImpl(const QString &path, QWidget *pa
for (auto i = variables.constBegin(); i != variables.constEnd(); ++i) for (auto i = variables.constBegin(); i != variables.constEnd(); ++i)
wizard->setValue(i.key(), i.value()); wizard->setValue(i.key(), i.value());
wizard->setValue(QStringLiteral("InitialPath"), path); wizard->setValue(QStringLiteral("InitialPath"), path.toString());
wizard->setValue(QStringLiteral("Platform"), platform.toString()); wizard->setValue(QStringLiteral("Platform"), platform.toString());
QString kindStr = QLatin1String(Core::Constants::WIZARD_KIND_UNKNOWN); QString kindStr = QLatin1String(Core::Constants::WIZARD_KIND_UNKNOWN);
@@ -452,7 +454,7 @@ Utils::Wizard *JsonWizardFactory::runWizardImpl(const QString &path, QWidget *pa
return f->canCreate(data.typeId); return f->canCreate(data.typeId);
}); });
QTC_ASSERT(factory, continue); QTC_ASSERT(factory, continue);
JsonWizardGenerator *gen = factory->create(data.typeId, data.data, path, platform, variables); JsonWizardGenerator *gen = factory->create(data.typeId, data.data, path.toString(), platform, variables);
QTC_ASSERT(gen, continue); QTC_ASSERT(gen, continue);
wizard->addGenerator(gen); wizard->addGenerator(gen);
@@ -603,9 +605,9 @@ bool JsonWizardFactory::initialize(const QVariantMap &data, const QDir &baseDir,
setDescriptionImage(strVal); setDescriptionImage(strVal);
} }
strVal = baseDir.absoluteFilePath("detailsPage.qml"); const FilePath detailsPage = baseDir.resolvePath(QString("detailsPage.qml"));
if (QFileInfo::exists(strVal)) if (detailsPage.exists())
setDetailsPageQmlPath(strVal); setDetailsPageQmlPath(detailsPage.toString());
setRequiredFeatures(Utils::Id::fromStringList(data.value(QLatin1String(REQUIRED_FEATURES_KEY)).toStringList())); setRequiredFeatures(Utils::Id::fromStringList(data.value(QLatin1String(REQUIRED_FEATURES_KEY)).toStringList()));
m_preferredFeatures = Utils::Id::fromStringList(data.value(QLatin1String(SUGGESTED_FEATURES_KEY)).toStringList()); m_preferredFeatures = Utils::Id::fromStringList(data.value(QLatin1String(SUGGESTED_FEATURES_KEY)).toStringList());

View File

@@ -88,7 +88,7 @@ public:
bool isAvailable(Utils::Id platformId) const override; bool isAvailable(Utils::Id platformId) const override;
private: private:
Utils::Wizard *runWizardImpl(const QString &path, QWidget *parent, Utils::Id platform, Utils::Wizard *runWizardImpl(const Utils::FilePath &path, QWidget *parent, Utils::Id platform,
const QVariantMap &variables, bool showWizard = true) override; const QVariantMap &variables, bool showWizard = true) override;
// Create all wizards. As other plugins might register factories for derived // Create all wizards. As other plugins might register factories for derived

View File

@@ -240,12 +240,12 @@ void ProjectTree::setCurrent(Node *node, Project *project)
void ProjectTree::sessionChanged() void ProjectTree::sessionChanged()
{ {
if (m_currentProject) { if (m_currentProject) {
Core::DocumentManager::setDefaultLocationForNewFiles(m_currentProject->projectDirectory().toString()); Core::DocumentManager::setDefaultLocationForNewFiles(m_currentProject->projectDirectory());
} else if (Project *project = SessionManager::startupProject()) { } else if (Project *project = SessionManager::startupProject()) {
Core::DocumentManager::setDefaultLocationForNewFiles(project->projectDirectory().toString()); Core::DocumentManager::setDefaultLocationForNewFiles(project->projectDirectory());
updateFromNode(nullptr); // Make startup project current if there is no other current updateFromNode(nullptr); // Make startup project current if there is no other current
} else { } else {
Core::DocumentManager::setDefaultLocationForNewFiles(QString()); Core::DocumentManager::setDefaultLocationForNewFiles({});
} }
update(); update();
} }

View File

@@ -213,18 +213,18 @@ void GenerateResource::generateMenuEntry()
QObject::connect(action, &QAction::triggered, [] () { QObject::connect(action, &QAction::triggered, [] () {
auto currentProject = ProjectExplorer::SessionManager::startupProject(); auto currentProject = ProjectExplorer::SessionManager::startupProject();
QTC_ASSERT(currentProject, return); QTC_ASSERT(currentProject, return);
auto projectPath = currentProject->projectFilePath().parentDir().toString(); const FilePath projectPath = currentProject->projectFilePath().parentDir();
auto projectFileName = Core::DocumentManager::getSaveFileName( auto projectFileName = Core::DocumentManager::getSaveFileName(
QCoreApplication::translate("QmlDesigner::GenerateResource", "Save Project as QRC File"), QCoreApplication::translate("QmlDesigner::GenerateResource", "Save Project as QRC File"),
projectPath + "/" + currentProject->displayName() + ".qrc", projectPath.pathAppended(currentProject->displayName() + ".qrc"),
QCoreApplication::translate("QmlDesigner::GenerateResource", QCoreApplication::translate("QmlDesigner::GenerateResource",
"QML Resource File (*.qrc)")); "QML Resource File (*.qrc)"));
if (projectFileName.isEmpty()) if (projectFileName.isEmpty())
return; return;
QTemporaryFile temp(projectPath + "/XXXXXXX.create.resource.qrc"); QTemporaryFile temp(projectPath.toString() + "/XXXXXXX.create.resource.qrc");
QFile persistentFile(projectFileName); QFile persistentFile(projectFileName.toString());
if (!temp.open()) if (!temp.open())
return; return;
@@ -289,7 +289,7 @@ void GenerateResource::generateMenuEntry()
QByteArray firstLine = temp.readLine(); QByteArray firstLine = temp.readLine();
QList<ResourceFile> fileList = getFilesFromQrc(&temp); QList<ResourceFile> fileList = getFilesFromQrc(&temp);
QFile existingQrcFile(projectFileName); QFile existingQrcFile(projectFileName.toString());
if (existingQrcFile.exists()) { if (existingQrcFile.exists()) {
existingQrcFile.open(QFile::ReadOnly); existingQrcFile.open(QFile::ReadOnly);
fileList = getFilesFromQrc(&existingQrcFile, true); fileList = getFilesFromQrc(&existingQrcFile, true);
@@ -297,7 +297,7 @@ void GenerateResource::generateMenuEntry()
} }
QDir dir; QDir dir;
dir.setCurrent(projectPath); dir.setCurrent(projectPath.toString());
Utils::FilePaths paths = currentProject->files(ProjectExplorer::Project::AllFiles); Utils::FilePaths paths = currentProject->files(ProjectExplorer::Project::AllFiles);
QStringList projectFiles = {}; QStringList projectFiles = {};
@@ -363,11 +363,11 @@ void GenerateResource::generateMenuEntry()
QObject::connect(rccAction, &QAction::triggered, [] () { QObject::connect(rccAction, &QAction::triggered, [] () {
auto currentProject = ProjectExplorer::SessionManager::startupProject(); auto currentProject = ProjectExplorer::SessionManager::startupProject();
QTC_ASSERT(currentProject, return); QTC_ASSERT(currentProject, return);
auto projectPath = currentProject->projectFilePath().parentDir().toString(); const FilePath projectPath = currentProject->projectFilePath().parentDir();
auto resourceFileName = Core::DocumentManager::getSaveFileName( const FilePath resourceFileName = Core::DocumentManager::getSaveFileName(
QCoreApplication::translate("QmlDesigner::GenerateResource", "Save Project as Resource"), QCoreApplication::translate("QmlDesigner::GenerateResource", "Save Project as Resource"),
projectPath + "/" + currentProject->displayName() + ".qmlrc", projectPath.pathAppended(currentProject->displayName() + ".qmlrc"),
QCoreApplication::translate("QmlDesigner::GenerateResource", QCoreApplication::translate("QmlDesigner::GenerateResource",
"QML Resource File (*.qmlrc);;Resource File (*.rcc)")); "QML Resource File (*.qmlrc);;Resource File (*.rcc)"));
if (resourceFileName.isEmpty()) if (resourceFileName.isEmpty())
@@ -376,12 +376,12 @@ void GenerateResource::generateMenuEntry()
Core::MessageManager::writeSilently( Core::MessageManager::writeSilently(
QCoreApplication::translate("QmlDesigner::GenerateResource", QCoreApplication::translate("QmlDesigner::GenerateResource",
"Generate a resource file out of project %1 to %2") "Generate a resource file out of project %1 to %2")
.arg(currentProject->displayName(), QDir::toNativeSeparators(resourceFileName))); .arg(currentProject->displayName(), resourceFileName.toUserOutput()));
QString projectFileName = currentProject->displayName() + ".qrc"; QString projectFileName = currentProject->displayName() + ".qrc";
QFile persistentFile(projectPath + "/" + projectFileName); QFile persistentFile(projectPath.toString() + "/" + projectFileName);
QTemporaryFile temp(projectPath + "/XXXXXXX.create.resource.qrc"); QTemporaryFile temp(projectPath.toString() + "/XXXXXXX.create.resource.qrc");
QtSupport::BaseQtVersion *qtVersion = QtSupport::QtKitAspect::qtVersion( QtSupport::BaseQtVersion *qtVersion = QtSupport::QtKitAspect::qtVersion(
currentProject->activeTarget()->kit()); currentProject->activeTarget()->kit());
@@ -407,7 +407,7 @@ void GenerateResource::generateMenuEntry()
Core::MessageManager::writeDisrupting( Core::MessageManager::writeDisrupting(
QCoreApplication::translate("QmlDesigner::GenerateResource", QCoreApplication::translate("QmlDesigner::GenerateResource",
"Unable to generate resource file: %1") "Unable to generate resource file: %1")
.arg(resourceFileName)); .arg(resourceFileName.toUserOutput()));
return; return;
} }
QByteArray stdOut; QByteArray stdOut;
@@ -477,7 +477,7 @@ void GenerateResource::generateMenuEntry()
} }
QDir dir; QDir dir;
dir.setCurrent(projectPath); dir.setCurrent(projectPath.toString());
Utils::FilePaths paths = currentProject->files(ProjectExplorer::Project::AllFiles); Utils::FilePaths paths = currentProject->files(ProjectExplorer::Project::AllFiles);
QStringList projectFiles = {}; QStringList projectFiles = {};
@@ -508,7 +508,7 @@ void GenerateResource::generateMenuEntry()
temp.close(); temp.close();
persistentFile.close(); persistentFile.close();
QStringList modifiedList = getFileList(fileList); QStringList modifiedList = getFileList(fileList);
QTemporaryFile tempFile(projectPath + "/XXXXXXX.create.modifiedresource.qrc"); QTemporaryFile tempFile(projectPath.toString() + "/XXXXXXX.create.modifiedresource.qrc");
if (!tempFile.open()) if (!tempFile.open())
return; return;
@@ -527,7 +527,7 @@ void GenerateResource::generateMenuEntry()
tempFile.write("\n</RCC>\n"); tempFile.write("\n</RCC>\n");
tempFile.close(); tempFile.close();
const QStringList arguments2 = {"--binary", "--output", resourceFileName, const QStringList arguments2 = {"--binary", "--output", resourceFileName.path(),
tempFile.fileName()}; tempFile.fileName()};
for (const auto &arguments : {arguments2}) { for (const auto &arguments : {arguments2}) {
@@ -537,7 +537,7 @@ void GenerateResource::generateMenuEntry()
Core::MessageManager::writeDisrupting( Core::MessageManager::writeDisrupting(
QCoreApplication::translate("QmlDesigner::GenerateResource", QCoreApplication::translate("QmlDesigner::GenerateResource",
"Unable to generate resource file: %1") "Unable to generate resource file: %1")
.arg(resourceFileName)); .arg(resourceFileName.toUserOutput()));
return; return;
} }
QByteArray stdOut; QByteArray stdOut;

View File

@@ -89,7 +89,7 @@ public:
void updateRevisions(); void updateRevisions();
public: public:
QString m_defaultPath; FilePath m_defaultPath;
QString m_suggestedFileName; QString m_suggestedFileName;
TypingSettings m_typingSettings; TypingSettings m_typingSettings;
StorageSettings m_storageSettings; StorageSettings m_storageSettings;
@@ -571,7 +571,7 @@ bool TextDocument::isSaveAsAllowed() const
return true; return true;
} }
QString TextDocument::fallbackSaveAsPath() const FilePath TextDocument::fallbackSaveAsPath() const
{ {
return d->m_defaultPath; return d->m_defaultPath;
} }
@@ -581,7 +581,7 @@ QString TextDocument::fallbackSaveAsFileName() const
return d->m_suggestedFileName; return d->m_suggestedFileName;
} }
void TextDocument::setFallbackSaveAsPath(const QString &defaultPath) void TextDocument::setFallbackSaveAsPath(const FilePath &defaultPath)
{ {
d->m_defaultPath = defaultPath; d->m_defaultPath = defaultPath;
} }

View File

@@ -122,10 +122,10 @@ public:
void setFilePath(const Utils::FilePath &newName) override; void setFilePath(const Utils::FilePath &newName) override;
ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const override; ReloadBehavior reloadBehavior(ChangeTrigger state, ChangeType type) const override;
QString fallbackSaveAsPath() const override; Utils::FilePath fallbackSaveAsPath() const override;
QString fallbackSaveAsFileName() const override; QString fallbackSaveAsFileName() const override;
void setFallbackSaveAsPath(const QString &fallbackSaveAsPath); void setFallbackSaveAsPath(const Utils::FilePath &fallbackSaveAsPath);
void setFallbackSaveAsFileName(const QString &fallbackSaveAsFileName); void setFallbackSaveAsFileName(const QString &fallbackSaveAsFileName);
OpenResult open(QString *errorString, const Utils::FilePath &filePath, OpenResult open(QString *errorString, const Utils::FilePath &filePath,