forked from qt-creator/qt-creator
Utils: Use more FilePath in PathChooser
Change-Id: I0a59cb7b8c613a5533e02ad29088f58de02ff578 Reviewed-by: Artem Sokolovskii <artem.sokolovskii@qt.io> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -70,14 +70,13 @@
|
|||||||
|
|
||||||
namespace Utils {
|
namespace Utils {
|
||||||
|
|
||||||
static QString appBundleExpandedPath(const QString &path)
|
static FilePath appBundleExpandedPath(const FilePath &path)
|
||||||
{
|
{
|
||||||
if (HostOsInfo::hostOs() == OsTypeMac && path.endsWith(".app")) {
|
if (path.osType() == OsTypeMac && path.endsWith(".app")) {
|
||||||
// possibly expand to Foo.app/Contents/MacOS/Foo
|
// possibly expand to Foo.app/Contents/MacOS/Foo
|
||||||
QFileInfo info(path);
|
if (path.isDir()) {
|
||||||
if (info.isDir()) {
|
const FilePath exePath = path / "Contents/MacOS" / path.completeBaseName();
|
||||||
QString exePath = path + "/Contents/MacOS/" + info.completeBaseName();
|
if (exePath.exists())
|
||||||
if (QFileInfo::exists(exePath))
|
|
||||||
return exePath;
|
return exePath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -168,8 +167,7 @@ public:
|
|||||||
BinaryVersionToolTipEventFilter(pe->lineEdit()), m_pathChooser(pe) {}
|
BinaryVersionToolTipEventFilter(pe->lineEdit()), m_pathChooser(pe) {}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QString defaultToolTip() const override
|
QString defaultToolTip() const override { return m_pathChooser->errorMessage(); }
|
||||||
{ return m_pathChooser->errorMessage(); }
|
|
||||||
|
|
||||||
const PathChooser *m_pathChooser = nullptr;
|
const PathChooser *m_pathChooser = nullptr;
|
||||||
};
|
};
|
||||||
@@ -415,30 +413,27 @@ void PathChooser::slotBrowse()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Prompt for a file/dir
|
// Prompt for a file/dir
|
||||||
QString newPath;
|
FilePath newPath;
|
||||||
switch (d->m_acceptingKind) {
|
switch (d->m_acceptingKind) {
|
||||||
case PathChooser::Directory:
|
case PathChooser::Directory:
|
||||||
case PathChooser::ExistingDirectory:
|
case PathChooser::ExistingDirectory:
|
||||||
newPath = QFileDialog::getExistingDirectory(this,
|
newPath = FileUtils::getExistingDirectory(this,
|
||||||
makeDialogTitle(tr("Choose Directory")), predefined.toUserOutput());
|
makeDialogTitle(tr("Choose Directory")), predefined);
|
||||||
break;
|
break;
|
||||||
case PathChooser::ExistingCommand:
|
case PathChooser::ExistingCommand:
|
||||||
case PathChooser::Command:
|
case PathChooser::Command:
|
||||||
newPath = QFileDialog::getOpenFileName(this,
|
newPath = FileUtils::getOpenFilePath(this,
|
||||||
makeDialogTitle(tr("Choose Executable")), predefined.toUserOutput(),
|
makeDialogTitle(tr("Choose Executable")), predefined, d->m_dialogFilter);
|
||||||
d->m_dialogFilter);
|
|
||||||
newPath = appBundleExpandedPath(newPath);
|
newPath = appBundleExpandedPath(newPath);
|
||||||
break;
|
break;
|
||||||
case PathChooser::File: // fall through
|
case PathChooser::File: // fall through
|
||||||
newPath = QFileDialog::getOpenFileName(this,
|
newPath = FileUtils::getOpenFilePath(this,
|
||||||
makeDialogTitle(tr("Choose File")), predefined.toUserOutput(),
|
makeDialogTitle(tr("Choose File")), predefined, d->m_dialogFilter);
|
||||||
d->m_dialogFilter);
|
|
||||||
newPath = appBundleExpandedPath(newPath);
|
newPath = appBundleExpandedPath(newPath);
|
||||||
break;
|
break;
|
||||||
case PathChooser::SaveFile:
|
case PathChooser::SaveFile:
|
||||||
newPath = QFileDialog::getSaveFileName(this,
|
newPath = FileUtils::getSaveFilePath(this,
|
||||||
makeDialogTitle(tr("Choose File")), predefined.toUserOutput(),
|
makeDialogTitle(tr("Choose File")), predefined, d->m_dialogFilter);
|
||||||
d->m_dialogFilter);
|
|
||||||
break;
|
break;
|
||||||
case PathChooser::Any: {
|
case PathChooser::Any: {
|
||||||
QFileDialog dialog(this);
|
QFileDialog dialog(this);
|
||||||
@@ -452,7 +447,7 @@ void PathChooser::slotBrowse()
|
|||||||
// probably loop here until the *.framework dir match
|
// probably loop here until the *.framework dir match
|
||||||
QStringList paths = dialog.selectedFiles();
|
QStringList paths = dialog.selectedFiles();
|
||||||
if (!paths.isEmpty())
|
if (!paths.isEmpty())
|
||||||
newPath = paths.at(0);
|
newPath = FilePath::fromString(paths.at(0));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -465,13 +460,12 @@ void PathChooser::slotBrowse()
|
|||||||
window()->raise();
|
window()->raise();
|
||||||
window()->activateWindow();
|
window()->activateWindow();
|
||||||
|
|
||||||
// Delete trailing slashes unless it is "/"|"\\", only
|
// Delete trailing slashes unless it is "/" only.
|
||||||
if (!newPath.isEmpty()) {
|
if (newPath.endsWith("/") && newPath.path().size() > 1) {
|
||||||
newPath = QDir::toNativeSeparators(newPath);
|
newPath = newPath.withNewPath(newPath.path().chopped(1));
|
||||||
if (newPath.size() > 1 && newPath.endsWith(QDir::separator()))
|
setFilePath(newPath);
|
||||||
newPath.truncate(newPath.size() - 1);
|
|
||||||
setPath(newPath);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
emit browsingFinished();
|
emit browsingFinished();
|
||||||
triggerChanged();
|
triggerChanged();
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user