Core: Rename ExternalTool::fileName() to filePath()

Also, setFilePath(), and some code cosmetics.

Change-Id: If24aa2d75276eafac4d7494153c5fc223be1ee8b
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
hjk
2022-11-24 17:29:55 +01:00
parent 67e9c2d7a0
commit ef97774122
3 changed files with 23 additions and 21 deletions

View File

@@ -323,7 +323,7 @@ void ExternalToolModel::revertTool(const QModelIndex &modelIndex)
{ {
ExternalTool *tool = toolForIndex(modelIndex); ExternalTool *tool = toolForIndex(modelIndex);
QTC_ASSERT(tool, return); QTC_ASSERT(tool, return);
QTC_ASSERT(tool->preset() && !tool->preset()->fileName().isEmpty(), return); QTC_ASSERT(tool->preset() && !tool->preset()->filePath().isEmpty(), return);
auto resetTool = new ExternalTool(tool->preset().data()); auto resetTool = new ExternalTool(tool->preset().data());
resetTool->setPreset(tool->preset()); resetTool->setPreset(tool->preset());
(*tool) = (*resetTool); (*tool) = (*resetTool);
@@ -832,23 +832,23 @@ void ExternalToolConfig::apply()
// case 1: tool is changed preset // case 1: tool is changed preset
if (tool->preset() && (*tool) != (*(tool->preset()))) { if (tool->preset() && (*tool) != (*(tool->preset()))) {
// check if we need to choose a new file name // check if we need to choose a new file name
if (tool->preset()->fileName() == tool->fileName()) { if (tool->preset()->filePath() == tool->filePath()) {
const QString &fileName = tool->preset()->fileName().fileName(); const QString &fileName = tool->preset()->filePath().fileName();
const FilePath &newFilePath = getUserFilePath(fileName); const FilePath &newFilePath = getUserFilePath(fileName);
// TODO error handling if newFilePath.isEmpty() (i.e. failed to find a unused name) // TODO error handling if newFilePath.isEmpty() (i.e. failed to find a unused name)
tool->setFileName(newFilePath); tool->setFilePath(newFilePath);
} }
// TODO error handling // TODO error handling
tool->save(); tool->save();
// case 2: tool is previously changed preset but now same as preset // case 2: tool is previously changed preset but now same as preset
} else if (tool->preset() && (*tool) == (*(tool->preset()))) { } else if (tool->preset() && (*tool) == (*(tool->preset()))) {
// check if we need to delete the changed description // check if we need to delete the changed description
if (originalTool->fileName() != tool->preset()->fileName() if (originalTool->filePath() != tool->preset()->filePath()
&& originalTool->fileName().exists()) { && originalTool->filePath().exists()) {
// TODO error handling // TODO error handling
originalTool->fileName().removeFile(); originalTool->filePath().removeFile();
} }
tool->setFileName(tool->preset()->fileName()); tool->setFilePath(tool->preset()->filePath());
// no need to save, it's the same as the preset // no need to save, it's the same as the preset
// case 3: tool is custom tool // case 3: tool is custom tool
} else { } else {
@@ -865,7 +865,7 @@ void ExternalToolConfig::apply()
id = findUnusedId(id, newToolsMap); id = findUnusedId(id, newToolsMap);
tool->setId(id); tool->setId(id);
// TODO error handling if newFilePath.isEmpty() (i.e. failed to find a unused name) // TODO error handling if newFilePath.isEmpty() (i.e. failed to find a unused name)
tool->setFileName(getUserFilePath(id + QLatin1String(".xml"))); tool->setFilePath(getUserFilePath(id + QLatin1String(".xml")));
// TODO error handling // TODO error handling
tool->save(); tool->save();
toolToAdd = new ExternalTool(tool); toolToAdd = new ExternalTool(tool);
@@ -879,7 +879,7 @@ void ExternalToolConfig::apply()
for (const ExternalTool *tool : std::as_const(originalTools)) { for (const ExternalTool *tool : std::as_const(originalTools)) {
QTC_ASSERT(!tool->preset(), continue); QTC_ASSERT(!tool->preset(), continue);
// TODO error handling // TODO error handling
tool->fileName().removeFile(); tool->filePath().removeFile();
} }
ExternalToolManager::setToolsByCategory(resultMap); ExternalToolManager::setToolsByCategory(resultMap);

View File

@@ -187,9 +187,9 @@ bool ExternalTool::modifiesCurrentDocument() const
return m_modifiesCurrentDocument; return m_modifiesCurrentDocument;
} }
void ExternalTool::setFileName(const Utils::FilePath &fileName) void ExternalTool::setFilePath(const FilePath &filePath)
{ {
m_filePath = fileName; m_filePath = filePath;
} }
void ExternalTool::setPreset(QSharedPointer<ExternalTool> preset) void ExternalTool::setPreset(QSharedPointer<ExternalTool> preset)
@@ -197,7 +197,7 @@ void ExternalTool::setPreset(QSharedPointer<ExternalTool> preset)
m_presetTool = preset; m_presetTool = preset;
} }
Utils::FilePath ExternalTool::fileName() const FilePath ExternalTool::filePath() const
{ {
return m_filePath; return m_filePath;
} }
@@ -440,9 +440,10 @@ ExternalTool * ExternalTool::createFromXml(const QByteArray &xml, QString *error
return tool; return tool;
} }
ExternalTool * ExternalTool::createFromFile(const Utils::FilePath &fileName, QString *errorMessage, const QString &locale) ExternalTool * ExternalTool::createFromFile(const FilePath &fileName, QString *errorMessage,
const QString &locale)
{ {
Utils::FilePath absFileName = fileName.absoluteFilePath(); FilePath absFileName = fileName.absoluteFilePath();
FileReader reader; FileReader reader;
if (!reader.fetch(absFileName, errorMessage)) if (!reader.fetch(absFileName, errorMessage))
return nullptr; return nullptr;

View File

@@ -10,13 +10,12 @@
#include <utils/id.h> #include <utils/id.h>
#include <QObject> #include <QObject>
#include <QStringList>
#include <QProcess>
#include <QSharedPointer> #include <QSharedPointer>
#include <QTextCodec> #include <QTextCodec>
#include <QMetaType> #include <QMetaType>
namespace Utils { class QtcProcess; } namespace Utils { class QtcProcess; }
namespace Core { namespace Core {
class CORE_EXPORT ExternalTool : public QObject class CORE_EXPORT ExternalTool : public QObject
@@ -51,15 +50,16 @@ public:
Utils::Environment baseEnvironment() const; Utils::Environment baseEnvironment() const;
Utils::EnvironmentItems environmentUserChanges() const; Utils::EnvironmentItems environmentUserChanges() const;
void setFileName(const Utils::FilePath &fileName); void setFilePath(const Utils::FilePath &filePath);
void setPreset(QSharedPointer<ExternalTool> preset); void setPreset(QSharedPointer<ExternalTool> preset);
Utils::FilePath fileName() const; Utils::FilePath filePath() const;
// all tools that are preset (changed or unchanged) have the original value here: // all tools that are preset (changed or unchanged) have the original value here:
QSharedPointer<ExternalTool> preset() const; QSharedPointer<ExternalTool> preset() const;
static ExternalTool *createFromXml(const QByteArray &xml, QString *errorMessage = nullptr, const QString &locale = QString()); static ExternalTool *createFromXml(const QByteArray &xml, QString *errorMessage = nullptr,
const QString &locale = {});
static ExternalTool *createFromFile(const Utils::FilePath &fileName, QString *errorMessage = nullptr, static ExternalTool *createFromFile(const Utils::FilePath &fileName, QString *errorMessage = nullptr,
const QString &locale = QString()); const QString &locale = {});
bool save(QString *errorMessage = nullptr) const; bool save(QString *errorMessage = nullptr) const;
@@ -105,6 +105,7 @@ private:
class CORE_EXPORT ExternalToolRunner : public QObject class CORE_EXPORT ExternalToolRunner : public QObject
{ {
Q_OBJECT Q_OBJECT
public: public:
ExternalToolRunner(const ExternalTool *tool); ExternalToolRunner(const ExternalTool *tool);
~ExternalToolRunner() override; ~ExternalToolRunner() override;