forked from qt-creator/qt-creator
CorePlugin: Use FilePath istead of QString
Task-number: QTCREATORBUG-2616 Change-Id: Iaa5bc7946a7bddfd8adffe51906d90b2e76f5837 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
@@ -254,7 +254,7 @@ BaseFileWizardFactory::OverwriteResult BaseFileWizardFactory::promptOverwrite(Ge
|
||||
|
||||
if (oddStuffFound) {
|
||||
*errorMessage = tr("The project directory %1 contains files which cannot be overwritten:\n%2.")
|
||||
.arg(QDir::toNativeSeparators(commonExistingPath)).arg(fileNamesMsgPart);
|
||||
.arg(QDir::toNativeSeparators(commonExistingPath), fileNamesMsgPart);
|
||||
return OverwriteError;
|
||||
}
|
||||
// Prompt to overwrite existing files.
|
||||
|
@@ -404,11 +404,11 @@ void CorePlugin::warnAboutCrashReporing()
|
||||
"To enable this feature go to %2.");
|
||||
|
||||
if (Utils::HostOsInfo::isMacHost()) {
|
||||
warnStr = warnStr.arg(Core::Constants::IDE_DISPLAY_NAME)
|
||||
.arg(Core::Constants::IDE_DISPLAY_NAME + tr(" > Preferences > Environment > System"));
|
||||
warnStr = warnStr.arg(Core::Constants::IDE_DISPLAY_NAME,
|
||||
Core::Constants::IDE_DISPLAY_NAME + tr(" > Preferences > Environment > System"));
|
||||
} else {
|
||||
warnStr = warnStr.arg(Core::Constants::IDE_DISPLAY_NAME)
|
||||
.arg(tr("Tools > Options > Environment > System"));
|
||||
warnStr = warnStr.arg(Core::Constants::IDE_DISPLAY_NAME,
|
||||
tr("Tools > Options > Environment > System"));
|
||||
}
|
||||
|
||||
Utils::InfoBarEntry info(kWarnCrashReportingSetting, warnStr,
|
||||
|
@@ -630,7 +630,7 @@ void ExternalToolConfig::showInfoForItem(const QModelIndex &index)
|
||||
updateEffectiveArguments();
|
||||
}
|
||||
|
||||
static QString getUserFilePath(const QString &proposalFileName)
|
||||
static FilePath getUserFilePath(const QString &proposalFileName)
|
||||
{
|
||||
const QDir resourceDir(ICore::userResourcePath().toDir());
|
||||
if (!resourceDir.exists(QLatin1String("externaltools")))
|
||||
@@ -642,12 +642,12 @@ static QString getUserFilePath(const QString &proposalFileName)
|
||||
FilePath tryPath = newFilePath + suffix;
|
||||
while (tryPath.exists()) {
|
||||
if (++count > 15)
|
||||
return QString();
|
||||
return {};
|
||||
// add random number
|
||||
const int number = QRandomGenerator::global()->generate() % 1000;
|
||||
tryPath = newFilePath + QString::number(number) + suffix;
|
||||
}
|
||||
return tryPath.toString();
|
||||
return tryPath;
|
||||
}
|
||||
|
||||
static QString idFromDisplayName(const QString &displayName)
|
||||
@@ -709,8 +709,8 @@ void ExternalToolConfig::apply()
|
||||
if (tool->preset() && (*tool) != (*(tool->preset()))) {
|
||||
// check if we need to choose a new file name
|
||||
if (tool->preset()->fileName() == tool->fileName()) {
|
||||
const QString &fileName = FilePath::fromString(tool->preset()->fileName()).fileName();
|
||||
const QString &newFilePath = getUserFilePath(fileName);
|
||||
const QString &fileName = tool->preset()->fileName().fileName();
|
||||
const FilePath &newFilePath = getUserFilePath(fileName);
|
||||
// TODO error handling if newFilePath.isEmpty() (i.e. failed to find a unused name)
|
||||
tool->setFileName(newFilePath);
|
||||
}
|
||||
@@ -720,9 +720,9 @@ void ExternalToolConfig::apply()
|
||||
} else if (tool->preset() && (*tool) == (*(tool->preset()))) {
|
||||
// check if we need to delete the changed description
|
||||
if (originalTool->fileName() != tool->preset()->fileName()
|
||||
&& QFile::exists(originalTool->fileName())) {
|
||||
&& originalTool->fileName().exists()) {
|
||||
// TODO error handling
|
||||
QFile::remove(originalTool->fileName());
|
||||
originalTool->fileName().removeFile();
|
||||
}
|
||||
tool->setFileName(tool->preset()->fileName());
|
||||
// no need to save, it's the same as the preset
|
||||
@@ -755,7 +755,7 @@ void ExternalToolConfig::apply()
|
||||
foreach (ExternalTool *tool, originalTools) {
|
||||
QTC_ASSERT(!tool->preset(), continue);
|
||||
// TODO error handling
|
||||
QFile::remove(tool->fileName());
|
||||
tool->fileName().removeFile();
|
||||
}
|
||||
|
||||
ExternalToolManager::setToolsByCategory(resultMap);
|
||||
|
@@ -32,11 +32,11 @@
|
||||
using namespace Core;
|
||||
using namespace Core::Internal;
|
||||
|
||||
OpenWithDialog::OpenWithDialog(const QString &fileName, QWidget *parent)
|
||||
OpenWithDialog::OpenWithDialog(const Utils::FilePath &filePath, QWidget *parent)
|
||||
: QDialog(parent)
|
||||
{
|
||||
setupUi(this);
|
||||
label->setText(tr("Open file \"%1\" with:").arg(Utils::FilePath::fromString(fileName).fileName()));
|
||||
label->setText(tr("Open file \"%1\" with:").arg(filePath.fileName()));
|
||||
buttonBox->button(QDialogButtonBox::Ok)->setDefault(true);
|
||||
|
||||
connect(buttonBox->button(QDialogButtonBox::Ok), &QAbstractButton::clicked,
|
||||
|
@@ -28,6 +28,8 @@
|
||||
#include <QDialog>
|
||||
#include "ui_openwithdialog.h"
|
||||
|
||||
namespace Utils { class FilePath; }
|
||||
|
||||
namespace Core {
|
||||
namespace Internal {
|
||||
|
||||
@@ -38,7 +40,7 @@ class OpenWithDialog : public QDialog, public Ui::OpenWithDialog
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
OpenWithDialog(const QString &fileName, QWidget *parent);
|
||||
OpenWithDialog(const Utils::FilePath &filePath, QWidget *parent);
|
||||
|
||||
void setEditors(const QStringList &);
|
||||
int editor() const;
|
||||
|
@@ -1146,14 +1146,14 @@ void EditorManagerPrivate::showPopupOrSelectDocument()
|
||||
|
||||
// Run the OpenWithDialog and return the editor id
|
||||
// selected by the user.
|
||||
Id EditorManagerPrivate::getOpenWithEditorId(const QString &fileName, bool *isExternalEditor)
|
||||
Id EditorManagerPrivate::getOpenWithEditorId(const Utils::FilePath &fileName, bool *isExternalEditor)
|
||||
{
|
||||
// Collect editors that can open the file
|
||||
QList<Id> allEditorIds;
|
||||
QStringList allEditorDisplayNames;
|
||||
QList<Id> externalEditorIds;
|
||||
// Built-in
|
||||
const EditorFactoryList editors = IEditorFactory::preferredEditorFactories(FilePath::fromString(fileName));
|
||||
const EditorFactoryList editors = IEditorFactory::preferredEditorFactories(fileName);
|
||||
const int size = editors.size();
|
||||
allEditorDisplayNames.reserve(size);
|
||||
for (int i = 0; i < size; i++) {
|
||||
@@ -3073,7 +3073,6 @@ IEditor *EditorManager::openEditor(const FilePath &filePath, Id editorId,
|
||||
IEditor *EditorManager::openEditor(const QString &fileName, Id editorId,
|
||||
OpenEditorFlags flags, bool *newEditor)
|
||||
{
|
||||
QFileInfo fi(fileName);
|
||||
return openEditor(FilePath::fromString(fileName), editorId, flags, newEditor);
|
||||
}
|
||||
|
||||
|
@@ -108,7 +108,7 @@ public:
|
||||
static MakeWritableResult makeFileWritable(IDocument *document);
|
||||
static void doEscapeKeyFocusMoveMagic();
|
||||
|
||||
static Utils::Id getOpenWithEditorId(const QString &fileName, bool *isExternalEditor = nullptr);
|
||||
static Utils::Id getOpenWithEditorId(const Utils::FilePath &fileName, bool *isExternalEditor = nullptr);
|
||||
|
||||
static void saveSettings();
|
||||
static void readSettings();
|
||||
|
@@ -101,7 +101,7 @@ ExternalTool::ExternalTool(const ExternalTool *other)
|
||||
m_outputHandling(other->m_outputHandling),
|
||||
m_errorHandling(other->m_errorHandling),
|
||||
m_modifiesCurrentDocument(other->m_modifiesCurrentDocument),
|
||||
m_fileName(other->m_fileName),
|
||||
m_filePath(other->m_filePath),
|
||||
m_presetTool(other->m_presetTool)
|
||||
{
|
||||
}
|
||||
@@ -121,7 +121,7 @@ ExternalTool &ExternalTool::operator=(const ExternalTool &other)
|
||||
m_outputHandling = other.m_outputHandling;
|
||||
m_errorHandling = other.m_errorHandling;
|
||||
m_modifiesCurrentDocument = other.m_modifiesCurrentDocument;
|
||||
m_fileName = other.m_fileName;
|
||||
m_filePath = other.m_filePath;
|
||||
m_presetFileName = other.m_presetFileName;
|
||||
m_presetTool = other.m_presetTool;
|
||||
return *this;
|
||||
@@ -210,9 +210,9 @@ bool ExternalTool::modifiesCurrentDocument() const
|
||||
return m_modifiesCurrentDocument;
|
||||
}
|
||||
|
||||
void ExternalTool::setFileName(const QString &fileName)
|
||||
void ExternalTool::setFileName(const Utils::FilePath &fileName)
|
||||
{
|
||||
m_fileName = fileName;
|
||||
m_filePath = fileName;
|
||||
}
|
||||
|
||||
void ExternalTool::setPreset(QSharedPointer<ExternalTool> preset)
|
||||
@@ -220,9 +220,9 @@ void ExternalTool::setPreset(QSharedPointer<ExternalTool> preset)
|
||||
m_presetTool = preset;
|
||||
}
|
||||
|
||||
QString ExternalTool::fileName() const
|
||||
Utils::FilePath ExternalTool::fileName() const
|
||||
{
|
||||
return m_fileName;
|
||||
return m_filePath;
|
||||
}
|
||||
|
||||
QSharedPointer<ExternalTool> ExternalTool::preset() const
|
||||
@@ -470,16 +470,16 @@ ExternalTool * ExternalTool::createFromXml(const QByteArray &xml, QString *error
|
||||
return tool;
|
||||
}
|
||||
|
||||
ExternalTool * ExternalTool::createFromFile(const QString &fileName, QString *errorMessage, const QString &locale)
|
||||
ExternalTool * ExternalTool::createFromFile(const Utils::FilePath &fileName, QString *errorMessage, const QString &locale)
|
||||
{
|
||||
QString absFileName = QFileInfo(fileName).absoluteFilePath();
|
||||
Utils::FilePath absFileName = fileName.absoluteFilePath();
|
||||
FileReader reader;
|
||||
if (!reader.fetch(FilePath::fromString(absFileName), errorMessage))
|
||||
if (!reader.fetch(absFileName, errorMessage))
|
||||
return nullptr;
|
||||
ExternalTool *tool = ExternalTool::createFromXml(reader.data(), errorMessage, locale);
|
||||
if (!tool)
|
||||
return nullptr;
|
||||
tool->m_fileName = absFileName;
|
||||
tool->m_filePath = absFileName;
|
||||
return tool;
|
||||
}
|
||||
|
||||
@@ -498,9 +498,9 @@ static QString stringForOutputHandling(ExternalTool::OutputHandling handling)
|
||||
|
||||
bool ExternalTool::save(QString *errorMessage) const
|
||||
{
|
||||
if (m_fileName.isEmpty())
|
||||
if (m_filePath.isEmpty())
|
||||
return false;
|
||||
FileSaver saver(FilePath::fromString(m_fileName));
|
||||
FileSaver saver(m_filePath);
|
||||
if (!saver.hasError()) {
|
||||
QXmlStreamWriter out(saver.file());
|
||||
out.setAutoFormatting(true);
|
||||
@@ -560,7 +560,7 @@ bool ExternalTool::operator==(const ExternalTool &other) const
|
||||
&& m_outputHandling == other.m_outputHandling
|
||||
&& m_modifiesCurrentDocument == other.m_modifiesCurrentDocument
|
||||
&& m_errorHandling == other.m_errorHandling
|
||||
&& m_fileName == other.m_fileName;
|
||||
&& m_filePath == other.m_filePath;
|
||||
}
|
||||
|
||||
// #pragma mark -- ExternalToolRunner
|
||||
|
@@ -72,14 +72,14 @@ public:
|
||||
Utils::Environment baseEnvironment() const;
|
||||
Utils::EnvironmentItems environmentUserChanges() const;
|
||||
|
||||
void setFileName(const QString &fileName);
|
||||
void setFileName(const Utils::FilePath &fileName);
|
||||
void setPreset(QSharedPointer<ExternalTool> preset);
|
||||
QString fileName() const;
|
||||
Utils::FilePath fileName() const;
|
||||
// all tools that are preset (changed or unchanged) have the original value here:
|
||||
QSharedPointer<ExternalTool> preset() const;
|
||||
|
||||
static ExternalTool *createFromXml(const QByteArray &xml, QString *errorMessage = nullptr, const QString &locale = QString());
|
||||
static ExternalTool *createFromFile(const QString &fileName, QString *errorMessage = nullptr,
|
||||
static ExternalTool *createFromFile(const Utils::FilePath &fileName, QString *errorMessage = nullptr,
|
||||
const QString &locale = QString());
|
||||
|
||||
bool save(QString *errorMessage = nullptr) const;
|
||||
@@ -118,8 +118,8 @@ private:
|
||||
OutputHandling m_errorHandling = ShowInPane;
|
||||
bool m_modifiesCurrentDocument = false;
|
||||
|
||||
QString m_fileName;
|
||||
QString m_presetFileName;
|
||||
Utils::FilePath m_filePath;
|
||||
Utils::FilePath m_presetFileName;
|
||||
QSharedPointer<ExternalTool> m_presetTool;
|
||||
};
|
||||
|
||||
|
@@ -131,7 +131,7 @@ static void parseDirectory(const QString &directory,
|
||||
foreach (const QFileInfo &info, dir.entryInfoList()) {
|
||||
const QString &fileName = info.absoluteFilePath();
|
||||
QString error;
|
||||
ExternalTool *tool = ExternalTool::createFromFile(fileName, &error, ICore::userInterfaceLanguage());
|
||||
ExternalTool *tool = ExternalTool::createFromFile(Utils::FilePath::fromString(fileName), &error, ICore::userInterfaceLanguage());
|
||||
if (!tool) {
|
||||
qWarning() << ExternalTool::tr("Error while parsing external tool %1: %2").arg(fileName, error);
|
||||
continue;
|
||||
|
@@ -55,16 +55,23 @@ class GeneratedFilePrivate : public QSharedData
|
||||
{
|
||||
public:
|
||||
GeneratedFilePrivate() = default;
|
||||
explicit GeneratedFilePrivate(const QString &p);
|
||||
QString path;
|
||||
explicit GeneratedFilePrivate(const Utils::FilePath &path);
|
||||
explicit GeneratedFilePrivate(const QString &path);
|
||||
Utils::FilePath path;
|
||||
QByteArray contents;
|
||||
Id editorId;
|
||||
bool binary = false;
|
||||
GeneratedFile::Attributes attributes;
|
||||
};
|
||||
|
||||
GeneratedFilePrivate::GeneratedFilePrivate(const QString &p) :
|
||||
path(QDir::cleanPath(p)),
|
||||
GeneratedFilePrivate::GeneratedFilePrivate(const QString &path) : // FIXME Don't use - Remove when possible
|
||||
path(FilePath::fromString(path).cleanPath()),
|
||||
attributes({})
|
||||
{
|
||||
}
|
||||
|
||||
GeneratedFilePrivate::GeneratedFilePrivate(const Utils::FilePath &path) :
|
||||
path(path.cleanPath()),
|
||||
attributes({})
|
||||
{
|
||||
}
|
||||
@@ -74,8 +81,13 @@ GeneratedFile::GeneratedFile() :
|
||||
{
|
||||
}
|
||||
|
||||
GeneratedFile::GeneratedFile(const QString &p) :
|
||||
m_d(new GeneratedFilePrivate(p))
|
||||
GeneratedFile::GeneratedFile(const QString &path) : // FIXME Don't use - Remove when possible
|
||||
m_d(new GeneratedFilePrivate(path))
|
||||
{
|
||||
}
|
||||
|
||||
GeneratedFile::GeneratedFile(const Utils::FilePath &path) :
|
||||
m_d(new GeneratedFilePrivate(path))
|
||||
{
|
||||
}
|
||||
|
||||
@@ -92,17 +104,23 @@ GeneratedFile::~GeneratedFile() = default;
|
||||
|
||||
QString GeneratedFile::path() const
|
||||
{
|
||||
return m_d->path;
|
||||
return m_d->path.toString();
|
||||
}
|
||||
|
||||
FilePath GeneratedFile::filePath() const
|
||||
{
|
||||
return FilePath::fromString(m_d->path);
|
||||
return m_d->path;
|
||||
}
|
||||
|
||||
void GeneratedFile::setPath(const QString &p)
|
||||
{
|
||||
m_d->path = QDir::cleanPath(p);
|
||||
m_d->path = Utils::FilePath::fromString(p).cleanPath();
|
||||
}
|
||||
|
||||
|
||||
void GeneratedFile::setFilePath(const Utils::FilePath &p)
|
||||
{
|
||||
m_d->path = p;
|
||||
}
|
||||
|
||||
QString GeneratedFile::contents() const
|
||||
@@ -148,8 +166,7 @@ void GeneratedFile::setEditorId(Id id)
|
||||
bool GeneratedFile::write(QString *errorMessage) const
|
||||
{
|
||||
// Ensure the directory
|
||||
const QFileInfo info(m_d->path);
|
||||
const QDir dir = info.absoluteDir();
|
||||
const QDir dir = m_d->path.parentDir().toDir();
|
||||
if (!dir.exists()) {
|
||||
if (!dir.mkpath(dir.absolutePath())) {
|
||||
*errorMessage = QCoreApplication::translate("BaseFileWizard",
|
||||
@@ -162,7 +179,7 @@ bool GeneratedFile::write(QString *errorMessage) const
|
||||
// Write out
|
||||
if (isBinary()) {
|
||||
QIODevice::OpenMode flags = QIODevice::WriteOnly | QIODevice::Truncate;
|
||||
Utils::FileSaver saver(FilePath::fromString(m_d->path), flags);
|
||||
Utils::FileSaver saver(m_d->path, flags);
|
||||
saver.write(m_d->contents);
|
||||
return saver.finalize(errorMessage);
|
||||
}
|
||||
@@ -170,7 +187,7 @@ bool GeneratedFile::write(QString *errorMessage) const
|
||||
Utils::TextFileFormat format;
|
||||
format.codec = EditorManager::defaultTextCodec();
|
||||
format.lineTerminationMode = EditorManager::defaultLineEnding();
|
||||
return format.writeFile(Utils::FilePath::fromString(m_d->path), contents(), errorMessage);
|
||||
return format.writeFile(m_d->path, contents(), errorMessage);
|
||||
}
|
||||
|
||||
GeneratedFile::Attributes GeneratedFile::attributes() const
|
||||
|
@@ -57,6 +57,7 @@ public:
|
||||
Q_DECLARE_FLAGS(Attributes, Attribute)
|
||||
|
||||
GeneratedFile();
|
||||
explicit GeneratedFile(const Utils::FilePath &path);
|
||||
explicit GeneratedFile(const QString &path);
|
||||
GeneratedFile(const GeneratedFile &);
|
||||
GeneratedFile &operator=(const GeneratedFile &);
|
||||
@@ -65,6 +66,7 @@ public:
|
||||
// Full path of the file should be created, or the suggested file name
|
||||
QString path() const;
|
||||
void setPath(const QString &p);
|
||||
void setFilePath(const Utils::FilePath &p);
|
||||
Utils::FilePath filePath() const;
|
||||
|
||||
// Contents of the file (UTF8)
|
||||
|
@@ -954,7 +954,7 @@ void MainWindow::openFileWith()
|
||||
const FilePaths filePaths = EditorManager::getOpenFilePaths();
|
||||
for (const FilePath &filePath : filePaths) {
|
||||
bool isExternal;
|
||||
const Id editorId = EditorManagerPrivate::getOpenWithEditorId(filePath.toString(), &isExternal);
|
||||
const Id editorId = EditorManagerPrivate::getOpenWithEditorId(filePath, &isExternal);
|
||||
if (!editorId.isValid())
|
||||
continue;
|
||||
if (isExternal)
|
||||
|
@@ -201,7 +201,7 @@ GeneratedFiles generateQmakeFiles(const SimpleProjectWizardDialog *wizard,
|
||||
const QString projectPath = wizard->path();
|
||||
const QDir dir(projectPath);
|
||||
const QString projectName = wizard->projectName();
|
||||
const QString proFileName = QFileInfo(dir, projectName + ".pro").absoluteFilePath();
|
||||
const FilePath proFileName = Utils::FilePath::fromFileInfo(QFileInfo(dir, projectName + ".pro").absoluteFilePath());
|
||||
const QStringList paths = Utils::transform(wizard->selectedPaths(), &FilePath::toString);
|
||||
|
||||
MimeType headerType = Utils::mimeTypeForName("text/x-chdr");
|
||||
@@ -259,7 +259,7 @@ GeneratedFiles generateCmakeFiles(const SimpleProjectWizardDialog *wizard,
|
||||
const QString projectPath = wizard->path();
|
||||
const QDir dir(projectPath);
|
||||
const QString projectName = wizard->projectName();
|
||||
const QString projectFileName = QFileInfo(dir, "CMakeLists.txt").absoluteFilePath();
|
||||
const FilePath projectFileName = Utils::FilePath::fromFileInfo(QFileInfo(dir, "CMakeLists.txt").absoluteFilePath());
|
||||
const QStringList paths = Utils::transform(wizard->selectedPaths(), &FilePath::toString);
|
||||
|
||||
MimeType headerType = Utils::mimeTypeForName("text/x-chdr");
|
||||
|
Reference in New Issue
Block a user