2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:58:39 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2016-01-15 14:58:39 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-02 14:09:21 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#include "pathchooser.h"
|
|
|
|
|
|
2010-09-23 11:06:12 +02:00
|
|
|
#include "environment.h"
|
2012-12-20 17:14:18 +01:00
|
|
|
#include "hostosinfo.h"
|
2021-05-05 18:21:22 +02:00
|
|
|
#include "macroexpander.h"
|
|
|
|
|
#include "qtcassert.h"
|
|
|
|
|
#include "qtcprocess.h"
|
2016-07-25 00:47:50 +02:00
|
|
|
#include "theme/theme.h"
|
2011-02-22 12:25:19 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QFileDialog>
|
|
|
|
|
#include <QHBoxLayout>
|
2015-08-03 12:44:48 +02:00
|
|
|
#include <QMenu>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QPushButton>
|
2014-08-28 17:33:47 +02:00
|
|
|
#include <QStandardPaths>
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-03-02 17:13:33 +01:00
|
|
|
/*!
|
|
|
|
|
\class Utils::PathChooser
|
2020-05-20 14:40:27 +02:00
|
|
|
\inmodule QtCreator
|
2011-03-02 17:13:33 +01:00
|
|
|
|
2020-05-20 14:40:27 +02:00
|
|
|
\brief The PathChooser class is a control that lets the user choose a path.
|
|
|
|
|
The control consist of a QLineEdit and a "Browse" button, and is optionally
|
|
|
|
|
able to perform variable substitution.
|
2011-03-02 17:13:33 +01:00
|
|
|
|
2013-09-06 13:23:11 +02:00
|
|
|
This class has some validation logic for embedding into QWizardPage.
|
2011-03-02 17:13:33 +01:00
|
|
|
*/
|
|
|
|
|
|
2020-05-20 14:40:27 +02:00
|
|
|
/*!
|
|
|
|
|
\enum Utils::PathChooser::Kind
|
|
|
|
|
\inmodule QtCreator
|
|
|
|
|
|
|
|
|
|
The Kind enum describes the kind of path a PathChooser considers valid.
|
|
|
|
|
|
|
|
|
|
\value ExistingDirectory An existing directory
|
|
|
|
|
\value Directory A directory that does not need to exist
|
|
|
|
|
\value File An existing file
|
|
|
|
|
\value SaveFile A file that does not need to exist
|
|
|
|
|
\value ExistingCommand An executable file that must exist at the time of selection
|
|
|
|
|
\value Command An executable file that may or may not exist at the time of selection (e.g. result of a build)
|
|
|
|
|
\value Any No restriction on the selected path
|
|
|
|
|
|
|
|
|
|
\sa setExpectedKind(), expectedKind()
|
|
|
|
|
*/
|
|
|
|
|
|
2018-07-17 23:21:05 +03:00
|
|
|
namespace Utils {
|
|
|
|
|
|
2015-05-07 13:35:21 +02:00
|
|
|
static QString appBundleExpandedPath(const QString &path)
|
|
|
|
|
{
|
2018-07-17 23:21:05 +03:00
|
|
|
if (HostOsInfo::hostOs() == OsTypeMac && path.endsWith(".app")) {
|
2015-05-07 13:35:21 +02:00
|
|
|
// possibly expand to Foo.app/Contents/MacOS/Foo
|
|
|
|
|
QFileInfo info(path);
|
|
|
|
|
if (info.isDir()) {
|
2017-08-16 22:10:50 +02:00
|
|
|
QString exePath = path + "/Contents/MacOS/" + info.completeBaseName();
|
2017-04-13 16:26:38 +02:00
|
|
|
if (QFileInfo::exists(exePath))
|
2015-05-07 13:35:21 +02:00
|
|
|
return exePath;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-17 23:21:05 +03:00
|
|
|
PathChooser::AboutToShowContextMenuHandler PathChooser::s_aboutToShowContextMenuHandler;
|
2009-04-17 09:03:32 +02:00
|
|
|
|
2011-02-22 12:25:19 +01:00
|
|
|
// ------------------ BinaryVersionToolTipEventFilter
|
|
|
|
|
// Event filter to be installed on a lineedit used for entering
|
|
|
|
|
// executables, taking the arguments to print the version ('--version').
|
|
|
|
|
// On a tooltip event, the version is obtained by running the binary and
|
|
|
|
|
// setting its stdout as tooltip.
|
|
|
|
|
|
|
|
|
|
class BinaryVersionToolTipEventFilter : public QObject
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit BinaryVersionToolTipEventFilter(QLineEdit *le);
|
|
|
|
|
|
2018-07-11 07:31:38 +02:00
|
|
|
bool eventFilter(QObject *, QEvent *) override;
|
2011-02-22 12:25:19 +01:00
|
|
|
|
|
|
|
|
QStringList arguments() const { return m_arguments; }
|
|
|
|
|
void setArguments(const QStringList &arguments) { m_arguments = arguments; }
|
|
|
|
|
|
2019-06-06 16:27:55 +02:00
|
|
|
static QString toolVersion(const CommandLine &cmd);
|
2011-02-22 12:25:19 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// Extension point for concatenating existing tooltips.
|
|
|
|
|
virtual QString defaultToolTip() const { return QString(); }
|
|
|
|
|
|
|
|
|
|
QStringList m_arguments;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
BinaryVersionToolTipEventFilter::BinaryVersionToolTipEventFilter(QLineEdit *le) :
|
|
|
|
|
QObject(le)
|
|
|
|
|
{
|
|
|
|
|
le->installEventFilter(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool BinaryVersionToolTipEventFilter::eventFilter(QObject *o, QEvent *e)
|
|
|
|
|
{
|
|
|
|
|
if (e->type() != QEvent::ToolTip)
|
|
|
|
|
return false;
|
2018-07-19 16:39:41 +02:00
|
|
|
auto le = qobject_cast<QLineEdit *>(o);
|
2012-04-17 08:01:25 +02:00
|
|
|
QTC_ASSERT(le, return false);
|
2011-02-22 12:25:19 +01:00
|
|
|
|
|
|
|
|
const QString binary = le->text();
|
|
|
|
|
if (!binary.isEmpty()) {
|
2019-06-06 16:27:55 +02:00
|
|
|
const QString version = BinaryVersionToolTipEventFilter::toolVersion(
|
2019-07-23 10:17:57 +02:00
|
|
|
CommandLine(QDir::cleanPath(binary), m_arguments));
|
2011-02-22 12:25:19 +01:00
|
|
|
if (!version.isEmpty()) {
|
|
|
|
|
// Concatenate tooltips.
|
2017-08-16 22:10:50 +02:00
|
|
|
QString tooltip = "<html><head/><body>";
|
2011-02-22 12:25:19 +01:00
|
|
|
const QString defaultValue = defaultToolTip();
|
|
|
|
|
if (!defaultValue.isEmpty()) {
|
2017-08-16 22:10:50 +02:00
|
|
|
tooltip += "<p>";
|
2011-02-22 12:25:19 +01:00
|
|
|
tooltip += defaultValue;
|
2017-08-16 22:10:50 +02:00
|
|
|
tooltip += "</p>";
|
2011-02-22 12:25:19 +01:00
|
|
|
}
|
2017-08-16 22:10:50 +02:00
|
|
|
tooltip += "<pre>";
|
2011-02-22 12:25:19 +01:00
|
|
|
tooltip += version;
|
2017-08-16 22:10:50 +02:00
|
|
|
tooltip += "</pre><body></html>";
|
2011-02-22 12:25:19 +01:00
|
|
|
le->setToolTip(tooltip);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2019-06-06 16:27:55 +02:00
|
|
|
QString BinaryVersionToolTipEventFilter::toolVersion(const CommandLine &cmd)
|
2011-02-22 12:25:19 +01:00
|
|
|
{
|
2019-06-06 16:27:55 +02:00
|
|
|
if (cmd.executable().isEmpty())
|
2011-02-22 12:25:19 +01:00
|
|
|
return QString();
|
2016-04-29 16:52:58 +02:00
|
|
|
SynchronousProcess proc;
|
|
|
|
|
proc.setTimeoutS(1);
|
2021-05-17 12:02:42 +02:00
|
|
|
proc.setCommand(cmd);
|
|
|
|
|
proc.runBlocking();
|
2021-05-12 14:25:50 +02:00
|
|
|
if (proc.result() != QtcProcess::Finished)
|
2011-02-22 12:25:19 +01:00
|
|
|
return QString();
|
2021-05-12 14:25:50 +02:00
|
|
|
return proc.allOutput();
|
2011-02-22 12:25:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Extends BinaryVersionToolTipEventFilter to prepend the existing pathchooser
|
|
|
|
|
// tooltip to display the full path.
|
|
|
|
|
class PathChooserBinaryVersionToolTipEventFilter : public BinaryVersionToolTipEventFilter
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit PathChooserBinaryVersionToolTipEventFilter(PathChooser *pe) :
|
|
|
|
|
BinaryVersionToolTipEventFilter(pe->lineEdit()), m_pathChooser(pe) {}
|
|
|
|
|
|
|
|
|
|
private:
|
2018-06-22 15:08:09 +02:00
|
|
|
QString defaultToolTip() const override
|
2011-02-22 12:25:19 +01:00
|
|
|
{ return m_pathChooser->errorMessage(); }
|
|
|
|
|
|
2017-08-16 22:10:50 +02:00
|
|
|
const PathChooser *m_pathChooser = nullptr;
|
2011-02-22 12:25:19 +01:00
|
|
|
};
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
// ------------------ PathChooserPrivate
|
2010-09-23 11:06:12 +02:00
|
|
|
|
|
|
|
|
class PathChooserPrivate
|
2008-12-09 11:27:17 +01:00
|
|
|
{
|
2010-09-23 11:06:12 +02:00
|
|
|
public:
|
2015-04-28 14:49:56 +02:00
|
|
|
PathChooserPrivate();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-09-23 11:06:12 +02:00
|
|
|
QString expandedPath(const QString &path) const;
|
|
|
|
|
|
2017-08-16 22:10:50 +02:00
|
|
|
QHBoxLayout *m_hLayout = nullptr;
|
|
|
|
|
FancyLineEdit *m_lineEdit = nullptr;
|
2011-02-21 12:42:20 +01:00
|
|
|
|
2018-09-21 01:15:38 +03:00
|
|
|
PathChooser::Kind m_acceptingKind = PathChooser::ExistingDirectory;
|
2008-12-05 18:51:07 +01:00
|
|
|
QString m_dialogTitleOverride;
|
2009-06-29 14:47:04 +02:00
|
|
|
QString m_dialogFilter;
|
2008-12-19 18:25:20 +01:00
|
|
|
QString m_initialBrowsePathOverride;
|
2020-08-25 14:41:06 +02:00
|
|
|
QString m_defaultValue;
|
2019-12-17 11:53:58 +01:00
|
|
|
FilePath m_baseDirectory;
|
2010-09-23 11:06:12 +02:00
|
|
|
Environment m_environment;
|
2017-08-16 22:10:50 +02:00
|
|
|
BinaryVersionToolTipEventFilter *m_binaryVersionToolTipEventFilter = nullptr;
|
2012-06-21 16:05:30 +02:00
|
|
|
QList<QAbstractButton *> m_buttons;
|
2020-03-16 10:24:35 +01:00
|
|
|
MacroExpander *m_macroExpander = globalMacroExpander();
|
2020-11-09 15:57:47 +01:00
|
|
|
std::function<void()> m_openTerminal;
|
2020-03-16 10:24:35 +01:00
|
|
|
|
|
|
|
|
bool m_isReadOnly = false;
|
|
|
|
|
bool m_isFileDialogOnly = false;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
2020-03-16 10:24:35 +01:00
|
|
|
PathChooserPrivate::PathChooserPrivate()
|
|
|
|
|
: m_hLayout(new QHBoxLayout)
|
|
|
|
|
, m_lineEdit(new FancyLineEdit)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-23 11:06:12 +02:00
|
|
|
QString PathChooserPrivate::expandedPath(const QString &input) const
|
|
|
|
|
{
|
2010-09-29 11:33:07 +02:00
|
|
|
if (input.isEmpty())
|
|
|
|
|
return input;
|
2018-09-06 09:03:55 +02:00
|
|
|
|
|
|
|
|
QString expandedInput = m_environment.expandVariables(input);
|
|
|
|
|
if (m_macroExpander)
|
|
|
|
|
expandedInput = m_macroExpander->expand(expandedInput);
|
|
|
|
|
|
2019-05-28 13:49:26 +02:00
|
|
|
const QString path = FilePath::fromUserInput(expandedInput).toString();
|
2010-09-29 11:33:07 +02:00
|
|
|
if (path.isEmpty())
|
2010-09-23 11:06:12 +02:00
|
|
|
return path;
|
|
|
|
|
|
2010-09-29 11:33:07 +02:00
|
|
|
switch (m_acceptingKind) {
|
|
|
|
|
case PathChooser::Command:
|
|
|
|
|
case PathChooser::ExistingCommand: {
|
2019-12-17 11:53:58 +01:00
|
|
|
const FilePath expanded = m_environment.searchInPath(path, {m_baseDirectory});
|
2014-07-15 23:32:11 +03:00
|
|
|
return expanded.isEmpty() ? path : expanded.toString();
|
2010-09-29 11:33:07 +02:00
|
|
|
}
|
|
|
|
|
case PathChooser::Any:
|
|
|
|
|
break;
|
|
|
|
|
case PathChooser::Directory:
|
2011-02-21 12:42:20 +01:00
|
|
|
case PathChooser::ExistingDirectory:
|
2010-09-29 11:33:07 +02:00
|
|
|
case PathChooser::File:
|
2013-04-05 09:46:05 -03:00
|
|
|
case PathChooser::SaveFile:
|
2010-09-29 11:33:07 +02:00
|
|
|
if (!m_baseDirectory.isEmpty() && QFileInfo(path).isRelative())
|
2019-12-17 11:53:58 +01:00
|
|
|
return m_baseDirectory.pathAppended(path).toFileInfo().absoluteFilePath();
|
2010-09-29 11:33:07 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2010-09-23 11:06:12 +02:00
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
PathChooser::PathChooser(QWidget *parent) :
|
|
|
|
|
QWidget(parent),
|
2015-04-28 14:49:56 +02:00
|
|
|
d(new PathChooserPrivate)
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
d->m_hLayout->setContentsMargins(0, 0, 0, 0);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2020-03-16 10:24:35 +01:00
|
|
|
setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
|
d->m_lineEdit->setContextMenuPolicy(Qt::NoContextMenu);
|
2015-08-03 12:44:48 +02:00
|
|
|
|
2020-03-16 10:24:35 +01:00
|
|
|
connect(this,
|
|
|
|
|
&FancyLineEdit::customContextMenuRequested,
|
|
|
|
|
this,
|
|
|
|
|
&PathChooser::contextMenuRequested);
|
2015-03-05 22:00:05 +02:00
|
|
|
connect(d->m_lineEdit, &FancyLineEdit::validReturnPressed, this, &PathChooser::returnPressed);
|
2015-08-20 14:56:30 +02:00
|
|
|
connect(d->m_lineEdit, &QLineEdit::textChanged, this,
|
|
|
|
|
[this] { emit rawPathChanged(rawPath()); });
|
2015-03-05 22:00:05 +02:00
|
|
|
connect(d->m_lineEdit, &FancyLineEdit::validChanged, this, &PathChooser::validChanged);
|
|
|
|
|
connect(d->m_lineEdit, &QLineEdit::editingFinished, this, &PathChooser::editingFinished);
|
2018-05-14 10:09:31 +02:00
|
|
|
connect(d->m_lineEdit, &QLineEdit::textChanged, this, [this] { emit pathChanged(d->m_lineEdit->text()); });
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2013-03-14 13:54:45 +01:00
|
|
|
d->m_lineEdit->setMinimumWidth(120);
|
2011-09-07 14:26:11 +02:00
|
|
|
d->m_hLayout->addWidget(d->m_lineEdit);
|
|
|
|
|
d->m_hLayout->setSizeConstraint(QLayout::SetMinimumSize);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2015-04-30 15:22:57 +02:00
|
|
|
addButton(browseButtonLabel(), this, [this] { slotBrowse(); });
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2011-09-07 14:26:11 +02:00
|
|
|
setLayout(d->m_hLayout);
|
|
|
|
|
setFocusProxy(d->m_lineEdit);
|
2011-09-13 13:12:34 +02:00
|
|
|
setFocusPolicy(d->m_lineEdit->focusPolicy());
|
2010-09-23 11:06:12 +02:00
|
|
|
setEnvironment(Environment::systemEnvironment());
|
2015-04-28 14:49:56 +02:00
|
|
|
|
|
|
|
|
d->m_lineEdit->setValidationFunction(defaultValidationFunction());
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
PathChooser::~PathChooser()
|
|
|
|
|
{
|
2015-11-20 12:41:24 +01:00
|
|
|
// Since it is our focusProxy it can receive focus-out and emit the signal
|
|
|
|
|
// even when the possible ancestor-receiver is in mid of its destruction.
|
|
|
|
|
disconnect(d->m_lineEdit, &QLineEdit::editingFinished, this, &PathChooser::editingFinished);
|
|
|
|
|
|
2011-09-07 14:26:11 +02:00
|
|
|
delete d;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2015-04-30 15:22:57 +02:00
|
|
|
void PathChooser::addButton(const QString &text, QObject *context, const std::function<void ()> &callback)
|
2012-06-21 16:05:30 +02:00
|
|
|
{
|
2015-04-30 15:22:57 +02:00
|
|
|
insertButton(d->m_buttons.count(), text, context, callback);
|
2012-06-21 16:05:30 +02:00
|
|
|
}
|
|
|
|
|
|
2015-04-30 15:22:57 +02:00
|
|
|
void PathChooser::insertButton(int index, const QString &text, QObject *context, const std::function<void ()> &callback)
|
2009-04-17 09:03:32 +02:00
|
|
|
{
|
2015-04-30 15:22:57 +02:00
|
|
|
auto button = new QPushButton;
|
2011-02-28 15:29:24 +01:00
|
|
|
button->setText(text);
|
2015-04-30 15:22:57 +02:00
|
|
|
connect(button, &QAbstractButton::clicked, context, callback);
|
2012-06-21 16:05:30 +02:00
|
|
|
d->m_hLayout->insertWidget(index + 1/*line edit*/, button);
|
|
|
|
|
d->m_buttons.insert(index, button);
|
2020-03-16 10:24:35 +01:00
|
|
|
updateReadOnlyStateOfSubwidgets();
|
2009-04-17 09:03:32 +02:00
|
|
|
}
|
|
|
|
|
|
2014-07-15 23:33:17 +03:00
|
|
|
QString PathChooser::browseButtonLabel()
|
2014-02-19 14:46:19 +01:00
|
|
|
{
|
|
|
|
|
return HostOsInfo::isMacHost() ? tr("Choose...") : tr("Browse...");
|
|
|
|
|
}
|
|
|
|
|
|
2009-07-22 15:18:42 +02:00
|
|
|
QAbstractButton *PathChooser::buttonAtIndex(int index) const
|
|
|
|
|
{
|
2012-06-21 16:05:30 +02:00
|
|
|
return d->m_buttons.at(index);
|
2009-07-22 15:18:42 +02:00
|
|
|
}
|
|
|
|
|
|
2019-12-17 11:53:58 +01:00
|
|
|
void PathChooser::setBaseDirectory(const FilePath &base)
|
2010-09-17 13:59:59 +02:00
|
|
|
{
|
2019-12-17 11:53:58 +01:00
|
|
|
if (d->m_baseDirectory == base)
|
2013-04-16 13:12:27 +02:00
|
|
|
return;
|
2019-12-17 11:53:58 +01:00
|
|
|
d->m_baseDirectory = base;
|
2014-03-05 12:37:03 +01:00
|
|
|
triggerChanged();
|
2010-09-17 13:59:59 +02:00
|
|
|
}
|
|
|
|
|
|
2019-12-17 11:53:58 +01:00
|
|
|
FilePath PathChooser::baseDirectory() const
|
2012-03-13 15:23:38 +01:00
|
|
|
{
|
2019-12-17 11:53:58 +01:00
|
|
|
return d->m_baseDirectory;
|
2012-03-13 15:23:38 +01:00
|
|
|
}
|
|
|
|
|
|
2014-07-15 23:33:17 +03:00
|
|
|
void PathChooser::setEnvironment(const Environment &env)
|
2010-09-23 11:06:12 +02:00
|
|
|
{
|
2020-04-09 11:35:12 +02:00
|
|
|
QString oldExpand = filePath().toString();
|
2011-09-07 14:26:11 +02:00
|
|
|
d->m_environment = env;
|
2020-04-09 11:35:12 +02:00
|
|
|
if (filePath().toString() != oldExpand) {
|
2014-03-05 12:35:55 +01:00
|
|
|
triggerChanged();
|
2015-08-20 14:56:30 +02:00
|
|
|
emit rawPathChanged(rawPath());
|
2014-03-05 12:35:55 +01:00
|
|
|
}
|
2010-09-23 11:06:12 +02:00
|
|
|
}
|
|
|
|
|
|
2016-06-24 13:45:51 +02:00
|
|
|
QString PathChooser::rawPath() const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2020-05-20 13:22:10 +02:00
|
|
|
return rawFilePath().toString();
|
2010-09-23 11:06:12 +02:00
|
|
|
}
|
|
|
|
|
|
2020-05-20 13:22:10 +02:00
|
|
|
FilePath PathChooser::rawFilePath() const
|
2016-01-05 15:49:50 +02:00
|
|
|
{
|
2019-05-28 13:49:26 +02:00
|
|
|
return FilePath::fromString(QDir::fromNativeSeparators(d->m_lineEdit->text()));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2020-04-09 11:05:50 +02:00
|
|
|
FilePath PathChooser::filePath() const
|
2012-01-13 16:35:53 +01:00
|
|
|
{
|
2020-05-20 13:22:10 +02:00
|
|
|
return FilePath::fromUserInput(d->expandedPath(rawFilePath().toString()));
|
2012-01-13 16:35:53 +01:00
|
|
|
}
|
|
|
|
|
|
2016-01-07 13:46:54 +01:00
|
|
|
// FIXME: try to remove again
|
|
|
|
|
QString PathChooser::expandedDirectory(const QString &input, const Environment &env,
|
|
|
|
|
const QString &baseDir)
|
|
|
|
|
{
|
|
|
|
|
if (input.isEmpty())
|
|
|
|
|
return input;
|
|
|
|
|
const QString path = QDir::cleanPath(env.expandVariables(input));
|
|
|
|
|
if (path.isEmpty())
|
|
|
|
|
return path;
|
|
|
|
|
if (!baseDir.isEmpty() && QFileInfo(path).isRelative())
|
2017-08-16 22:10:50 +02:00
|
|
|
return QFileInfo(baseDir + '/' + path).absoluteFilePath();
|
2016-01-07 13:46:54 +01:00
|
|
|
return path;
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void PathChooser::setPath(const QString &path)
|
|
|
|
|
{
|
2019-02-07 14:11:31 +01:00
|
|
|
d->m_lineEdit->setTextKeepingActiveCursor(QDir::toNativeSeparators(path));
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2020-04-09 11:05:50 +02:00
|
|
|
void PathChooser::setFilePath(const FilePath &fn)
|
2012-01-13 16:35:53 +01:00
|
|
|
{
|
2019-02-07 14:11:31 +01:00
|
|
|
d->m_lineEdit->setTextKeepingActiveCursor(fn.toUserOutput());
|
2012-01-13 16:35:53 +01:00
|
|
|
}
|
|
|
|
|
|
2011-02-21 12:45:21 +01:00
|
|
|
bool PathChooser::isReadOnly() const
|
|
|
|
|
{
|
2020-03-16 10:24:35 +01:00
|
|
|
return d->m_isReadOnly;
|
2011-02-21 12:45:21 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PathChooser::setReadOnly(bool b)
|
|
|
|
|
{
|
2020-03-16 10:24:35 +01:00
|
|
|
d->m_isReadOnly = b;
|
|
|
|
|
updateReadOnlyStateOfSubwidgets();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool PathChooser::isFileDialogOnly() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_isFileDialogOnly;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PathChooser::setFileDialogOnly(bool b)
|
|
|
|
|
{
|
|
|
|
|
d->m_isFileDialogOnly = b;
|
|
|
|
|
updateReadOnlyStateOfSubwidgets();
|
2011-02-21 12:45:21 +01:00
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
void PathChooser::slotBrowse()
|
|
|
|
|
{
|
2008-12-19 18:25:20 +01:00
|
|
|
emit beforeBrowsing();
|
|
|
|
|
|
2020-04-09 11:35:12 +02:00
|
|
|
QString predefined = filePath().toString();
|
2013-09-21 20:18:12 +03:00
|
|
|
QFileInfo fi(predefined);
|
|
|
|
|
|
|
|
|
|
if (!predefined.isEmpty() && !fi.isDir()) {
|
|
|
|
|
predefined = fi.path();
|
|
|
|
|
fi.setFile(predefined);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ((predefined.isEmpty() || !fi.isDir())
|
2011-09-07 14:26:11 +02:00
|
|
|
&& !d->m_initialBrowsePathOverride.isNull()) {
|
|
|
|
|
predefined = d->m_initialBrowsePathOverride;
|
2013-09-21 20:18:12 +03:00
|
|
|
fi.setFile(predefined);
|
|
|
|
|
if (!fi.isDir()) {
|
2008-12-19 18:25:20 +01:00
|
|
|
predefined.clear();
|
2013-09-21 20:18:12 +03:00
|
|
|
fi.setFile(QString());
|
|
|
|
|
}
|
2008-12-19 18:25:20 +01:00
|
|
|
}
|
2008-12-05 18:51:07 +01:00
|
|
|
|
|
|
|
|
// Prompt for a file/dir
|
|
|
|
|
QString newPath;
|
2011-09-07 14:26:11 +02:00
|
|
|
switch (d->m_acceptingKind) {
|
2008-12-05 18:51:07 +01:00
|
|
|
case PathChooser::Directory:
|
2011-02-21 12:42:20 +01:00
|
|
|
case PathChooser::ExistingDirectory:
|
2008-12-05 18:51:07 +01:00
|
|
|
newPath = QFileDialog::getExistingDirectory(this,
|
2010-05-14 15:45:43 +02:00
|
|
|
makeDialogTitle(tr("Choose Directory")), predefined);
|
2008-12-05 18:51:07 +01:00
|
|
|
break;
|
2010-09-23 11:06:12 +02:00
|
|
|
case PathChooser::ExistingCommand:
|
2008-12-05 18:51:07 +01:00
|
|
|
case PathChooser::Command:
|
2010-09-23 11:06:12 +02:00
|
|
|
newPath = QFileDialog::getOpenFileName(this,
|
|
|
|
|
makeDialogTitle(tr("Choose Executable")), predefined,
|
2011-09-07 14:26:11 +02:00
|
|
|
d->m_dialogFilter);
|
2015-05-07 13:35:21 +02:00
|
|
|
newPath = appBundleExpandedPath(newPath);
|
2010-09-23 11:06:12 +02:00
|
|
|
break;
|
|
|
|
|
case PathChooser::File: // fall through
|
2008-12-05 18:51:07 +01:00
|
|
|
newPath = QFileDialog::getOpenFileName(this,
|
2010-05-14 15:45:43 +02:00
|
|
|
makeDialogTitle(tr("Choose File")), predefined,
|
2011-09-07 14:26:11 +02:00
|
|
|
d->m_dialogFilter);
|
2015-05-07 13:35:21 +02:00
|
|
|
newPath = appBundleExpandedPath(newPath);
|
2008-12-05 18:51:07 +01:00
|
|
|
break;
|
2013-04-05 09:46:05 -03:00
|
|
|
case PathChooser::SaveFile:
|
|
|
|
|
newPath = QFileDialog::getSaveFileName(this,
|
|
|
|
|
makeDialogTitle(tr("Choose File")), predefined,
|
|
|
|
|
d->m_dialogFilter);
|
|
|
|
|
break;
|
2010-08-16 18:23:30 +02:00
|
|
|
case PathChooser::Any: {
|
|
|
|
|
QFileDialog dialog(this);
|
|
|
|
|
dialog.setFileMode(QFileDialog::AnyFile);
|
|
|
|
|
dialog.setWindowTitle(makeDialogTitle(tr("Choose File")));
|
|
|
|
|
if (fi.exists())
|
|
|
|
|
dialog.setDirectory(fi.absolutePath());
|
2010-09-16 12:50:18 +02:00
|
|
|
// FIXME: fix QFileDialog so that it filters properly: lib*.a
|
2011-09-07 14:26:11 +02:00
|
|
|
dialog.setNameFilter(d->m_dialogFilter);
|
2010-09-16 12:50:18 +02:00
|
|
|
if (dialog.exec() == QDialog::Accepted) {
|
|
|
|
|
// probably loop here until the *.framework dir match
|
2010-08-16 18:23:30 +02:00
|
|
|
QStringList paths = dialog.selectedFiles();
|
|
|
|
|
if (!paths.isEmpty())
|
|
|
|
|
newPath = paths.at(0);
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
2008-12-05 18:51:07 +01:00
|
|
|
|
|
|
|
|
default:
|
2010-09-16 12:50:18 +02:00
|
|
|
break;
|
2008-12-05 18:51:07 +01:00
|
|
|
}
|
|
|
|
|
|
2019-09-06 09:44:02 +02:00
|
|
|
// work around QTBUG-61004 / QTCREATORBUG-22906
|
|
|
|
|
window()->raise();
|
|
|
|
|
window()->activateWindow();
|
|
|
|
|
|
2008-12-19 15:32:21 +01:00
|
|
|
// Delete trailing slashes unless it is "/"|"\\", only
|
2008-12-09 11:27:17 +01:00
|
|
|
if (!newPath.isEmpty()) {
|
2008-12-19 15:32:21 +01:00
|
|
|
newPath = QDir::toNativeSeparators(newPath);
|
2008-12-09 11:27:17 +01:00
|
|
|
if (newPath.size() > 1 && newPath.endsWith(QDir::separator()))
|
|
|
|
|
newPath.truncate(newPath.size() - 1);
|
2008-12-02 12:01:29 +01:00
|
|
|
setPath(newPath);
|
|
|
|
|
}
|
2008-12-19 15:32:21 +01:00
|
|
|
|
|
|
|
|
emit browsingFinished();
|
2014-03-05 12:37:03 +01:00
|
|
|
triggerChanged();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2015-08-03 12:44:48 +02:00
|
|
|
void PathChooser::contextMenuRequested(const QPoint &pos)
|
|
|
|
|
{
|
2020-03-16 10:24:35 +01:00
|
|
|
if (!d->m_lineEdit->rect().contains(pos))
|
|
|
|
|
return;
|
|
|
|
|
QMenu *menu = d->m_lineEdit->createStandardContextMenu();
|
|
|
|
|
if (!menu)
|
|
|
|
|
menu = new QMenu;
|
|
|
|
|
if (s_aboutToShowContextMenuHandler)
|
|
|
|
|
s_aboutToShowContextMenuHandler(this, menu);
|
|
|
|
|
if (!menu->actions().isEmpty()) {
|
2015-08-03 12:44:48 +02:00
|
|
|
menu->setAttribute(Qt::WA_DeleteOnClose);
|
2020-03-16 10:24:35 +01:00
|
|
|
menu->popup(mapToGlobal(pos));
|
|
|
|
|
} else {
|
|
|
|
|
delete menu;
|
2015-08-03 12:44:48 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-16 10:24:35 +01:00
|
|
|
void PathChooser::updateReadOnlyStateOfSubwidgets()
|
|
|
|
|
{
|
|
|
|
|
const bool readOnlyLineEdit = d->m_isReadOnly || d->m_isFileDialogOnly;
|
|
|
|
|
d->m_lineEdit->setEnabled(!readOnlyLineEdit);
|
|
|
|
|
d->m_lineEdit->setReadOnly(readOnlyLineEdit);
|
|
|
|
|
setFocusPolicy(d->m_lineEdit->focusPolicy());
|
|
|
|
|
for (QAbstractButton *button : qAsConst(d->m_buttons))
|
|
|
|
|
button->setEnabled(!d->m_isReadOnly);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
bool PathChooser::isValid() const
|
|
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
return d->m_lineEdit->isValid();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString PathChooser::errorMessage() const
|
|
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
return d->m_lineEdit->errorMessage();
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2013-01-15 19:30:42 +01:00
|
|
|
void PathChooser::triggerChanged()
|
|
|
|
|
{
|
2015-10-12 14:57:20 +02:00
|
|
|
d->m_lineEdit->validate();
|
2013-01-15 19:30:42 +01:00
|
|
|
}
|
|
|
|
|
|
2015-08-03 12:44:48 +02:00
|
|
|
void PathChooser::setAboutToShowContextMenuHandler(PathChooser::AboutToShowContextMenuHandler handler)
|
|
|
|
|
{
|
|
|
|
|
s_aboutToShowContextMenuHandler = handler;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-09 15:57:47 +01:00
|
|
|
void PathChooser::setOpenTerminalHandler(const std::function<void ()> &openTerminal)
|
|
|
|
|
{
|
|
|
|
|
d->m_openTerminal = openTerminal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::function<void()> PathChooser::openTerminalHandler() const
|
|
|
|
|
{
|
|
|
|
|
return d->m_openTerminal;
|
|
|
|
|
}
|
|
|
|
|
|
2020-08-25 14:41:06 +02:00
|
|
|
void PathChooser::setDefaultValue(const QString &defaultValue)
|
|
|
|
|
{
|
|
|
|
|
d->m_defaultValue = defaultValue;
|
|
|
|
|
d->m_lineEdit->setPlaceholderText(defaultValue);
|
2020-08-28 10:34:57 +02:00
|
|
|
d->m_lineEdit->validate();
|
2020-08-25 14:41:06 +02:00
|
|
|
}
|
|
|
|
|
|
2015-04-28 14:49:56 +02:00
|
|
|
FancyLineEdit::ValidationFunction PathChooser::defaultValidationFunction() const
|
2015-02-27 16:24:29 +01:00
|
|
|
{
|
2015-04-28 14:49:56 +02:00
|
|
|
return std::bind(&PathChooser::validatePath, this, std::placeholders::_1, std::placeholders::_2);
|
2015-02-27 16:24:29 +01:00
|
|
|
}
|
|
|
|
|
|
2015-04-28 14:49:56 +02:00
|
|
|
bool PathChooser::validatePath(FancyLineEdit *edit, QString *errorMessage) const
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
2020-08-25 14:41:06 +02:00
|
|
|
QString path = edit->text();
|
2010-09-23 11:06:12 +02:00
|
|
|
|
2011-04-01 11:46:10 +02:00
|
|
|
if (path.isEmpty()) {
|
2020-08-25 14:41:06 +02:00
|
|
|
if (!d->m_defaultValue.isEmpty()) {
|
|
|
|
|
path = d->m_defaultValue;
|
|
|
|
|
} else {
|
|
|
|
|
if (errorMessage)
|
|
|
|
|
*errorMessage = tr("The path must not be empty.");
|
|
|
|
|
return false;
|
|
|
|
|
}
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
2008-12-05 18:51:07 +01:00
|
|
|
|
2020-08-25 14:41:06 +02:00
|
|
|
const QString expandedPath = d->expandedPath(path);
|
2011-04-01 11:46:10 +02:00
|
|
|
if (expandedPath.isEmpty()) {
|
|
|
|
|
if (errorMessage)
|
2014-04-17 14:09:47 +02:00
|
|
|
*errorMessage = tr("The path \"%1\" expanded to an empty string.").arg(QDir::toNativeSeparators(path));
|
2011-04-01 11:46:10 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
2010-09-23 11:06:12 +02:00
|
|
|
const QFileInfo fi(expandedPath);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2008-12-05 18:51:07 +01:00
|
|
|
// Check if existing
|
2011-09-07 14:26:11 +02:00
|
|
|
switch (d->m_acceptingKind) {
|
2018-04-25 15:06:37 +02:00
|
|
|
case PathChooser::ExistingDirectory:
|
2011-04-01 11:46:10 +02:00
|
|
|
if (!fi.exists()) {
|
|
|
|
|
if (errorMessage)
|
2014-04-17 14:09:47 +02:00
|
|
|
*errorMessage = tr("The path \"%1\" does not exist.").arg(QDir::toNativeSeparators(expandedPath));
|
2011-04-01 11:46:10 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
if (!fi.isDir()) {
|
|
|
|
|
if (errorMessage)
|
2014-04-17 14:09:47 +02:00
|
|
|
*errorMessage = tr("The path \"%1\" is not a directory.").arg(QDir::toNativeSeparators(expandedPath));
|
2011-04-01 11:46:10 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2018-04-25 15:06:37 +02:00
|
|
|
case PathChooser::File:
|
2011-04-01 11:46:10 +02:00
|
|
|
if (!fi.exists()) {
|
|
|
|
|
if (errorMessage)
|
2014-04-17 14:09:47 +02:00
|
|
|
*errorMessage = tr("The path \"%1\" does not exist.").arg(QDir::toNativeSeparators(expandedPath));
|
2011-04-01 11:46:10 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
2016-03-03 17:17:31 +01:00
|
|
|
if (!fi.isFile()) {
|
|
|
|
|
if (errorMessage)
|
2016-10-07 16:15:02 +02:00
|
|
|
*errorMessage = tr("The path \"%1\" is not a file.").arg(QDir::toNativeSeparators(expandedPath));
|
2016-03-03 17:17:31 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
2011-04-01 11:46:10 +02:00
|
|
|
break;
|
2013-04-05 09:46:05 -03:00
|
|
|
case PathChooser::SaveFile:
|
|
|
|
|
if (!fi.absoluteDir().exists()) {
|
|
|
|
|
if (errorMessage)
|
2014-04-17 14:09:47 +02:00
|
|
|
*errorMessage = tr("The directory \"%1\" does not exist.").arg(QDir::toNativeSeparators(fi.absolutePath()));
|
2013-04-05 09:46:05 -03:00
|
|
|
return false;
|
|
|
|
|
}
|
2016-03-03 17:17:31 +01:00
|
|
|
if (fi.exists() && fi.isDir()) {
|
|
|
|
|
if (errorMessage)
|
2016-10-07 16:15:02 +02:00
|
|
|
*errorMessage = tr("The path \"%1\" is not a file.").arg(QDir::toNativeSeparators(fi.absolutePath()));
|
2016-03-03 17:17:31 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
2013-04-05 09:46:05 -03:00
|
|
|
break;
|
2010-09-23 11:06:12 +02:00
|
|
|
case PathChooser::ExistingCommand:
|
2008-12-05 18:51:07 +01:00
|
|
|
if (!fi.exists()) {
|
|
|
|
|
if (errorMessage)
|
2014-04-17 14:09:47 +02:00
|
|
|
*errorMessage = tr("The path \"%1\" does not exist.").arg(QDir::toNativeSeparators(expandedPath));
|
2008-12-05 18:51:07 +01:00
|
|
|
return false;
|
|
|
|
|
}
|
2016-03-03 17:17:31 +01:00
|
|
|
if (!fi.isFile() || !fi.isExecutable()) {
|
2011-04-01 11:46:10 +02:00
|
|
|
if (errorMessage)
|
2016-10-07 16:15:02 +02:00
|
|
|
*errorMessage = tr("The path \"%1\" is not an executable file.").arg(QDir::toNativeSeparators(expandedPath));
|
2011-04-01 11:46:10 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
2008-12-05 18:51:07 +01:00
|
|
|
break;
|
2011-02-21 12:42:20 +01:00
|
|
|
case PathChooser::Directory:
|
2011-04-01 11:46:10 +02:00
|
|
|
if (fi.exists() && !fi.isDir()) {
|
|
|
|
|
if (errorMessage)
|
2014-04-17 14:09:47 +02:00
|
|
|
*errorMessage = tr("The path \"%1\" is not a directory.").arg(QDir::toNativeSeparators(expandedPath));
|
2011-04-01 11:46:10 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
break;
|
2018-04-25 15:06:37 +02:00
|
|
|
case PathChooser::Command:
|
2011-04-01 11:46:10 +02:00
|
|
|
if (fi.exists() && !fi.isExecutable()) {
|
|
|
|
|
if (errorMessage)
|
2014-04-17 14:09:47 +02:00
|
|
|
*errorMessage = tr("Cannot execute \"%1\".").arg(QDir::toNativeSeparators(expandedPath));
|
2011-04-01 11:46:10 +02:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
2008-12-05 18:51:07 +01:00
|
|
|
default:
|
|
|
|
|
;
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-29 12:03:14 +02:00
|
|
|
if (errorMessage)
|
2016-10-07 16:15:02 +02:00
|
|
|
*errorMessage = tr("Full path: \"%1\"").arg(QDir::toNativeSeparators(expandedPath));
|
2008-12-05 18:51:07 +01:00
|
|
|
return true;
|
2008-12-02 12:01:29 +01:00
|
|
|
}
|
|
|
|
|
|
2015-04-28 14:49:56 +02:00
|
|
|
void PathChooser::setValidationFunction(const FancyLineEdit::ValidationFunction &fn)
|
|
|
|
|
{
|
|
|
|
|
d->m_lineEdit->setValidationFunction(fn);
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
QString PathChooser::label()
|
|
|
|
|
{
|
|
|
|
|
return tr("Path:");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString PathChooser::homePath()
|
|
|
|
|
{
|
|
|
|
|
// Return 'users/<name>/Documents' on Windows, since Windows explorer
|
|
|
|
|
// does not let people actually display the contents of their home
|
|
|
|
|
// directory. Alternatively, create a QtCreator-specific directory?
|
2012-12-20 17:14:18 +01:00
|
|
|
if (HostOsInfo::isWindowsHost())
|
2014-08-28 17:33:47 +02:00
|
|
|
return QStandardPaths::writableLocation(QStandardPaths::DocumentsLocation);
|
2008-12-02 12:01:29 +01:00
|
|
|
return QDir::homePath();
|
|
|
|
|
}
|
|
|
|
|
|
2020-05-20 14:40:27 +02:00
|
|
|
/*!
|
|
|
|
|
Sets the kind of path the PathChooser will consider valid to select
|
|
|
|
|
to \a expected.
|
|
|
|
|
|
|
|
|
|
\sa Utils::PathChooser::Kind, expectedKind()
|
|
|
|
|
*/
|
|
|
|
|
|
2008-12-05 18:51:07 +01:00
|
|
|
void PathChooser::setExpectedKind(Kind expected)
|
|
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
if (d->m_acceptingKind == expected)
|
2011-03-08 18:28:58 +01:00
|
|
|
return;
|
2011-09-07 14:26:11 +02:00
|
|
|
d->m_acceptingKind = expected;
|
2015-10-12 14:57:20 +02:00
|
|
|
d->m_lineEdit->validate();
|
2008-12-05 18:51:07 +01:00
|
|
|
}
|
|
|
|
|
|
2020-05-20 14:40:27 +02:00
|
|
|
/*!
|
|
|
|
|
Returns the kind of path the PathChooser considers valid to select.
|
|
|
|
|
|
|
|
|
|
\sa Utils::PathChooser::Kind, setExpectedKind()
|
|
|
|
|
*/
|
|
|
|
|
|
2009-06-29 14:47:04 +02:00
|
|
|
PathChooser::Kind PathChooser::expectedKind() const
|
|
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
return d->m_acceptingKind;
|
2009-06-29 14:47:04 +02:00
|
|
|
}
|
|
|
|
|
|
2008-12-05 18:51:07 +01:00
|
|
|
void PathChooser::setPromptDialogTitle(const QString &title)
|
|
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
d->m_dialogTitleOverride = title;
|
2008-12-05 18:51:07 +01:00
|
|
|
}
|
|
|
|
|
|
2009-06-29 14:47:04 +02:00
|
|
|
QString PathChooser::promptDialogTitle() const
|
|
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
return d->m_dialogTitleOverride;
|
2009-06-29 14:47:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PathChooser::setPromptDialogFilter(const QString &filter)
|
|
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
d->m_dialogFilter = filter;
|
2018-09-24 12:26:46 +02:00
|
|
|
d->m_lineEdit->validate();
|
2009-06-29 14:47:04 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QString PathChooser::promptDialogFilter() const
|
|
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
return d->m_dialogFilter;
|
2009-06-29 14:47:04 +02:00
|
|
|
}
|
|
|
|
|
|
2008-12-19 18:25:20 +01:00
|
|
|
void PathChooser::setInitialBrowsePathBackup(const QString &path)
|
|
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
d->m_initialBrowsePathOverride = path;
|
2008-12-19 18:25:20 +01:00
|
|
|
}
|
|
|
|
|
|
2008-12-05 18:51:07 +01:00
|
|
|
QString PathChooser::makeDialogTitle(const QString &title)
|
|
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
if (d->m_dialogTitleOverride.isNull())
|
2008-12-05 18:51:07 +01:00
|
|
|
return title;
|
|
|
|
|
else
|
2011-09-07 14:26:11 +02:00
|
|
|
return d->m_dialogTitleOverride;
|
2008-12-05 18:51:07 +01:00
|
|
|
}
|
|
|
|
|
|
2012-08-23 13:55:11 +02:00
|
|
|
FancyLineEdit *PathChooser::lineEdit() const
|
2010-09-16 12:50:18 +02:00
|
|
|
{
|
|
|
|
|
// HACK: Make it work with HistoryCompleter.
|
2011-09-07 14:26:11 +02:00
|
|
|
if (d->m_lineEdit->objectName().isEmpty())
|
2017-08-16 22:10:50 +02:00
|
|
|
d->m_lineEdit->setObjectName(objectName() + "LineEdit");
|
2011-09-07 14:26:11 +02:00
|
|
|
return d->m_lineEdit;
|
2010-09-16 12:50:18 +02:00
|
|
|
}
|
|
|
|
|
|
2011-02-22 12:25:19 +01:00
|
|
|
QString PathChooser::toolVersion(const QString &binary, const QStringList &arguments)
|
|
|
|
|
{
|
2019-07-23 10:17:57 +02:00
|
|
|
return BinaryVersionToolTipEventFilter::toolVersion({binary, arguments});
|
2011-02-22 12:25:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PathChooser::installLineEditVersionToolTip(QLineEdit *le, const QStringList &arguments)
|
|
|
|
|
{
|
2018-07-19 16:39:41 +02:00
|
|
|
auto ef = new BinaryVersionToolTipEventFilter(le);
|
2011-02-22 12:25:19 +01:00
|
|
|
ef->setArguments(arguments);
|
|
|
|
|
}
|
|
|
|
|
|
2015-12-26 21:47:16 +02:00
|
|
|
void PathChooser::setHistoryCompleter(const QString &historyKey, bool restoreLastItemFromHistory)
|
2013-10-28 18:18:03 +01:00
|
|
|
{
|
2015-12-26 21:47:16 +02:00
|
|
|
d->m_lineEdit->setHistoryCompleter(historyKey, restoreLastItemFromHistory);
|
2013-10-28 18:18:03 +01:00
|
|
|
}
|
|
|
|
|
|
2018-09-06 09:03:55 +02:00
|
|
|
void PathChooser::setMacroExpander(MacroExpander *macroExpander)
|
|
|
|
|
{
|
|
|
|
|
d->m_macroExpander = macroExpander;
|
|
|
|
|
}
|
|
|
|
|
|
2011-02-22 12:25:19 +01:00
|
|
|
QStringList PathChooser::commandVersionArguments() const
|
|
|
|
|
{
|
2011-09-07 14:26:11 +02:00
|
|
|
return d->m_binaryVersionToolTipEventFilter ?
|
|
|
|
|
d->m_binaryVersionToolTipEventFilter->arguments() :
|
2011-02-22 12:25:19 +01:00
|
|
|
QStringList();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void PathChooser::setCommandVersionArguments(const QStringList &arguments)
|
|
|
|
|
{
|
|
|
|
|
if (arguments.isEmpty()) {
|
2011-09-07 14:26:11 +02:00
|
|
|
if (d->m_binaryVersionToolTipEventFilter) {
|
|
|
|
|
delete d->m_binaryVersionToolTipEventFilter;
|
2017-08-16 22:10:50 +02:00
|
|
|
d->m_binaryVersionToolTipEventFilter = nullptr;
|
2011-02-22 12:25:19 +01:00
|
|
|
}
|
|
|
|
|
} else {
|
2011-09-07 14:26:11 +02:00
|
|
|
if (!d->m_binaryVersionToolTipEventFilter)
|
|
|
|
|
d->m_binaryVersionToolTipEventFilter = new PathChooserBinaryVersionToolTipEventFilter(this);
|
|
|
|
|
d->m_binaryVersionToolTipEventFilter->setArguments(arguments);
|
2011-02-22 12:25:19 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2008-12-02 14:09:21 +01:00
|
|
|
} // namespace Utils
|