forked from qt-creator/qt-creator
Utils: filepathify pathchooser
Change-Id: Ib8e8493a5f7883bead353f015ef476ba0bfc3e0e Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -188,7 +188,7 @@ public:
|
|||||||
PathChooser::Kind m_acceptingKind = PathChooser::ExistingDirectory;
|
PathChooser::Kind m_acceptingKind = PathChooser::ExistingDirectory;
|
||||||
QString m_dialogTitleOverride;
|
QString m_dialogTitleOverride;
|
||||||
QString m_dialogFilter;
|
QString m_dialogFilter;
|
||||||
QString m_initialBrowsePathOverride;
|
FilePath m_initialBrowsePathOverride;
|
||||||
QString m_defaultValue;
|
QString m_defaultValue;
|
||||||
FilePath m_baseDirectory;
|
FilePath m_baseDirectory;
|
||||||
Environment m_environment;
|
Environment m_environment;
|
||||||
@@ -381,22 +381,16 @@ void PathChooser::slotBrowse()
|
|||||||
{
|
{
|
||||||
emit beforeBrowsing();
|
emit beforeBrowsing();
|
||||||
|
|
||||||
QString predefined = filePath().toString();
|
FilePath predefined = filePath();
|
||||||
QFileInfo fi(predefined);
|
|
||||||
|
|
||||||
if (!predefined.isEmpty() && !fi.isDir()) {
|
if (!predefined.isEmpty() && !predefined.isDir()) {
|
||||||
predefined = fi.path();
|
predefined = predefined.parentDir();
|
||||||
fi.setFile(predefined);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((predefined.isEmpty() || !fi.isDir())
|
if ((predefined.isEmpty() || !predefined.isDir()) && !d->m_initialBrowsePathOverride.isEmpty()) {
|
||||||
&& !d->m_initialBrowsePathOverride.isNull()) {
|
|
||||||
predefined = d->m_initialBrowsePathOverride;
|
predefined = d->m_initialBrowsePathOverride;
|
||||||
fi.setFile(predefined);
|
if (!predefined.isDir())
|
||||||
if (!fi.isDir()) {
|
|
||||||
predefined.clear();
|
predefined.clear();
|
||||||
fi.setFile(QString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Prompt for a file/dir
|
// Prompt for a file/dir
|
||||||
@@ -405,32 +399,32 @@ void PathChooser::slotBrowse()
|
|||||||
case PathChooser::Directory:
|
case PathChooser::Directory:
|
||||||
case PathChooser::ExistingDirectory:
|
case PathChooser::ExistingDirectory:
|
||||||
newPath = QFileDialog::getExistingDirectory(this,
|
newPath = QFileDialog::getExistingDirectory(this,
|
||||||
makeDialogTitle(tr("Choose Directory")), predefined);
|
makeDialogTitle(tr("Choose Directory")), predefined.toUserOutput());
|
||||||
break;
|
break;
|
||||||
case PathChooser::ExistingCommand:
|
case PathChooser::ExistingCommand:
|
||||||
case PathChooser::Command:
|
case PathChooser::Command:
|
||||||
newPath = QFileDialog::getOpenFileName(this,
|
newPath = QFileDialog::getOpenFileName(this,
|
||||||
makeDialogTitle(tr("Choose Executable")), predefined,
|
makeDialogTitle(tr("Choose Executable")), predefined.toUserOutput(),
|
||||||
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 = QFileDialog::getOpenFileName(this,
|
||||||
makeDialogTitle(tr("Choose File")), predefined,
|
makeDialogTitle(tr("Choose File")), predefined.toUserOutput(),
|
||||||
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 = QFileDialog::getSaveFileName(this,
|
||||||
makeDialogTitle(tr("Choose File")), predefined,
|
makeDialogTitle(tr("Choose File")), predefined.toUserOutput(),
|
||||||
d->m_dialogFilter);
|
d->m_dialogFilter);
|
||||||
break;
|
break;
|
||||||
case PathChooser::Any: {
|
case PathChooser::Any: {
|
||||||
QFileDialog dialog(this);
|
QFileDialog dialog(this);
|
||||||
dialog.setFileMode(QFileDialog::AnyFile);
|
dialog.setFileMode(QFileDialog::AnyFile);
|
||||||
dialog.setWindowTitle(makeDialogTitle(tr("Choose File")));
|
dialog.setWindowTitle(makeDialogTitle(tr("Choose File")));
|
||||||
if (fi.exists())
|
if (predefined.exists())
|
||||||
dialog.setDirectory(fi.absolutePath());
|
dialog.setDirectory(predefined.absolutePath().toDir());
|
||||||
// FIXME: fix QFileDialog so that it filters properly: lib*.a
|
// FIXME: fix QFileDialog so that it filters properly: lib*.a
|
||||||
dialog.setNameFilter(d->m_dialogFilter);
|
dialog.setNameFilter(d->m_dialogFilter);
|
||||||
if (dialog.exec() == QDialog::Accepted) {
|
if (dialog.exec() == QDialog::Accepted) {
|
||||||
@@ -457,7 +451,6 @@ void PathChooser::slotBrowse()
|
|||||||
newPath.truncate(newPath.size() - 1);
|
newPath.truncate(newPath.size() - 1);
|
||||||
setPath(newPath);
|
setPath(newPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
emit browsingFinished();
|
emit browsingFinished();
|
||||||
triggerChanged();
|
triggerChanged();
|
||||||
}
|
}
|
||||||
@@ -679,7 +672,7 @@ QString PathChooser::promptDialogFilter() const
|
|||||||
return d->m_dialogFilter;
|
return d->m_dialogFilter;
|
||||||
}
|
}
|
||||||
|
|
||||||
void PathChooser::setInitialBrowsePathBackup(const QString &path)
|
void PathChooser::setInitialBrowsePathBackup(const FilePath &path)
|
||||||
{
|
{
|
||||||
d->m_initialBrowsePathOverride = path;
|
d->m_initialBrowsePathOverride = path;
|
||||||
}
|
}
|
||||||
|
@@ -83,7 +83,7 @@ public:
|
|||||||
void setPromptDialogFilter(const QString &filter);
|
void setPromptDialogFilter(const QString &filter);
|
||||||
QString promptDialogFilter() const;
|
QString promptDialogFilter() const;
|
||||||
|
|
||||||
void setInitialBrowsePathBackup(const QString &path);
|
void setInitialBrowsePathBackup(const FilePath &path);
|
||||||
|
|
||||||
bool isValid() const;
|
bool isValid() const;
|
||||||
QString errorMessage() const;
|
QString errorMessage() const;
|
||||||
|
@@ -225,7 +225,7 @@ QWidget *AndroidBuildApkWidget::createSignPackageGroup()
|
|||||||
keystoreLocationChooser->setExpectedKind(PathChooser::File);
|
keystoreLocationChooser->setExpectedKind(PathChooser::File);
|
||||||
keystoreLocationChooser->lineEdit()->setReadOnly(true);
|
keystoreLocationChooser->lineEdit()->setReadOnly(true);
|
||||||
keystoreLocationChooser->setPath(m_step->keystorePath().toUserOutput());
|
keystoreLocationChooser->setPath(m_step->keystorePath().toUserOutput());
|
||||||
keystoreLocationChooser->setInitialBrowsePathBackup(QDir::homePath());
|
keystoreLocationChooser->setInitialBrowsePathBackup(FileUtils::homePath());
|
||||||
keystoreLocationChooser->setPromptDialogFilter(tr("Keystore files (*.keystore *.jks)"));
|
keystoreLocationChooser->setPromptDialogFilter(tr("Keystore files (*.keystore *.jks)"));
|
||||||
keystoreLocationChooser->setPromptDialogTitle(tr("Select Keystore File"));
|
keystoreLocationChooser->setPromptDialogTitle(tr("Select Keystore File"));
|
||||||
connect(keystoreLocationChooser, &PathChooser::pathChanged, this, [this](const QString &path) {
|
connect(keystoreLocationChooser, &PathChooser::pathChanged, this, [this](const QString &path) {
|
||||||
|
@@ -1439,7 +1439,7 @@ QString 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().toFileInfo().absolutePath();
|
return doc->filePath().absolutePath().path();
|
||||||
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;
|
||||||
|
@@ -191,7 +191,7 @@ bool UnstartedAppWatcherDialog::event(QEvent *e)
|
|||||||
|
|
||||||
void UnstartedAppWatcherDialog::selectExecutable()
|
void UnstartedAppWatcherDialog::selectExecutable()
|
||||||
{
|
{
|
||||||
QString path;
|
Utils::FilePath path;
|
||||||
|
|
||||||
Project *project = ProjectTree::currentProject();
|
Project *project = ProjectTree::currentProject();
|
||||||
Target *activeTarget = project ? project->activeTarget() : nullptr;
|
Target *activeTarget = project ? project->activeTarget() : nullptr;
|
||||||
@@ -200,16 +200,15 @@ void UnstartedAppWatcherDialog::selectExecutable()
|
|||||||
if (RunConfiguration *runConfig = activeTarget->activeRunConfiguration()) {
|
if (RunConfiguration *runConfig = activeTarget->activeRunConfiguration()) {
|
||||||
const Runnable runnable = runConfig->runnable();
|
const Runnable runnable = runConfig->runnable();
|
||||||
if (isLocal(runConfig))
|
if (isLocal(runConfig))
|
||||||
path = runnable.executable.toFileInfo().path();
|
path = runnable.executable.parentDir();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (path.isEmpty()) {
|
if (path.isEmpty()) {
|
||||||
if (activeTarget && activeTarget->activeBuildConfiguration()) {
|
if (activeTarget && activeTarget->activeBuildConfiguration())
|
||||||
path = activeTarget->activeBuildConfiguration()->buildDirectory().toString();
|
path = activeTarget->activeBuildConfiguration()->buildDirectory();
|
||||||
} else if (project) {
|
else if (project)
|
||||||
path = project->projectDirectory().toString();
|
path = project->projectDirectory();
|
||||||
}
|
|
||||||
}
|
}
|
||||||
m_pathChooser->setInitialBrowsePathBackup(path);
|
m_pathChooser->setInitialBrowsePathBackup(path);
|
||||||
}
|
}
|
||||||
|
@@ -64,7 +64,8 @@ void ExtPropertiesMView::visitMPackage(const qmt::MPackage *package)
|
|||||||
m_configPath->setValidationFunction([=](Utils::FancyLineEdit *edit, QString *errorMessage) {
|
m_configPath->setValidationFunction([=](Utils::FancyLineEdit *edit, QString *errorMessage) {
|
||||||
return edit->text().isEmpty() || m_configPath->defaultValidationFunction()(edit, errorMessage);
|
return edit->text().isEmpty() || m_configPath->defaultValidationFunction()(edit, errorMessage);
|
||||||
});
|
});
|
||||||
m_configPath->setInitialBrowsePathBackup(QFileInfo(project->fileName()).absolutePath());
|
m_configPath->setInitialBrowsePathBackup(
|
||||||
|
Utils::FilePath::fromString(project->fileName()).absolutePath());
|
||||||
addRow(tr("Config path:"), m_configPath, "configpath");
|
addRow(tr("Config path:"), m_configPath, "configpath");
|
||||||
connect(m_configPath, &Utils::PathChooser::pathChanged,
|
connect(m_configPath, &Utils::PathChooser::pathChanged,
|
||||||
this, &ExtPropertiesMView::onConfigPathChanged);
|
this, &ExtPropertiesMView::onConfigPathChanged);
|
||||||
|
@@ -83,7 +83,7 @@ WebAssemblyOptionsWidget::WebAssemblyOptionsWidget()
|
|||||||
layout->addWidget(instruction);
|
layout->addWidget(instruction);
|
||||||
m_emSdkPathChooser = new PathChooser(this);
|
m_emSdkPathChooser = new PathChooser(this);
|
||||||
m_emSdkPathChooser->setExpectedKind(PathChooser::Directory);
|
m_emSdkPathChooser->setExpectedKind(PathChooser::Directory);
|
||||||
m_emSdkPathChooser->setInitialBrowsePathBackup(QDir::homePath());
|
m_emSdkPathChooser->setInitialBrowsePathBackup(FileUtils::homePath());
|
||||||
m_emSdkPathChooser->setFilePath(WebAssemblyEmSdk::registeredEmSdk());
|
m_emSdkPathChooser->setFilePath(WebAssemblyEmSdk::registeredEmSdk());
|
||||||
connect(m_emSdkPathChooser, &PathChooser::pathChanged, [this](){ updateStatus(); });
|
connect(m_emSdkPathChooser, &PathChooser::pathChanged, [this](){ updateStatus(); });
|
||||||
layout->addWidget(m_emSdkPathChooser);
|
layout->addWidget(m_emSdkPathChooser);
|
||||||
|
Reference in New Issue
Block a user