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