2022-08-19 15:59:36 +02:00
|
|
|
// Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0+ OR GPL-3.0 WITH Qt-GPL-exception-1.0
|
2008-12-05 12:21:18 +01:00
|
|
|
|
2016-03-18 07:55:01 +01:00
|
|
|
#pragma once
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2022-05-24 12:14:24 +02:00
|
|
|
#include "utils_global.h"
|
|
|
|
|
|
2015-04-28 14:49:56 +02:00
|
|
|
#include "fancylineedit.h"
|
2022-05-24 12:14:24 +02:00
|
|
|
#include "filepath.h"
|
2012-01-13 16:35:53 +01:00
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QWidget>
|
2010-07-02 16:42:34 +02:00
|
|
|
|
2010-09-16 12:50:18 +02:00
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
class QAbstractButton;
|
|
|
|
|
class QLineEdit;
|
|
|
|
|
QT_END_NAMESPACE
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
namespace Utils {
|
|
|
|
|
|
2021-08-12 08:23:23 +02:00
|
|
|
class CommandLine;
|
2018-09-06 09:03:55 +02:00
|
|
|
class MacroExpander;
|
2010-09-23 11:06:12 +02:00
|
|
|
class Environment;
|
2021-08-03 15:12:24 +02:00
|
|
|
class EnvironmentChange;
|
2010-09-23 11:06:12 +02:00
|
|
|
class PathChooserPrivate;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-05-08 12:09:21 +02:00
|
|
|
class QTCREATOR_UTILS_EXPORT PathChooser : public QWidget
|
2008-12-02 12:01:29 +01:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
2022-09-02 11:49:36 +02:00
|
|
|
Q_PROPERTY(QString path READ path WRITE setPath NOTIFY textChanged DESIGNABLE true)
|
2009-06-29 14:47:04 +02:00
|
|
|
Q_PROPERTY(QString promptDialogTitle READ promptDialogTitle WRITE setPromptDialogTitle DESIGNABLE true)
|
2013-07-13 14:44:26 +03:00
|
|
|
Q_PROPERTY(QString promptDialogFilter READ promptDialogFilter WRITE setPromptDialogFilter DESIGNABLE true)
|
2009-06-29 14:47:04 +02:00
|
|
|
Q_PROPERTY(Kind expectedKind READ expectedKind WRITE setExpectedKind DESIGNABLE true)
|
2019-12-17 11:53:58 +01:00
|
|
|
Q_PROPERTY(Utils::FilePath baseDirectory READ baseDirectory WRITE setBaseDirectory DESIGNABLE true)
|
2011-02-22 12:25:19 +01:00
|
|
|
Q_PROPERTY(QStringList commandVersionArguments READ commandVersionArguments WRITE setCommandVersionArguments)
|
2011-02-21 12:45:21 +01:00
|
|
|
Q_PROPERTY(bool readOnly READ isReadOnly WRITE setReadOnly DESIGNABLE true)
|
2012-03-27 15:02:03 +02:00
|
|
|
// Designer does not know this type, so force designable to false:
|
2020-04-09 11:05:50 +02:00
|
|
|
Q_PROPERTY(Utils::FilePath filePath READ filePath WRITE setFilePath DESIGNABLE false)
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
public:
|
2014-02-19 14:46:19 +01:00
|
|
|
static QString browseButtonLabel();
|
2008-12-05 18:51:07 +01:00
|
|
|
|
2017-08-16 22:10:50 +02:00
|
|
|
explicit PathChooser(QWidget *parent = nullptr);
|
2018-05-07 15:07:21 +02:00
|
|
|
~PathChooser() override;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2008-12-05 18:51:07 +01:00
|
|
|
enum Kind {
|
2011-02-21 12:42:20 +01:00
|
|
|
ExistingDirectory,
|
|
|
|
|
Directory, // A directory, doesn't need to exist
|
2008-12-05 18:51:07 +01:00
|
|
|
File,
|
2013-04-05 09:46:05 -03:00
|
|
|
SaveFile,
|
2010-09-23 11:06:12 +02:00
|
|
|
ExistingCommand, // A command that must exist at the time of selection
|
|
|
|
|
Command, // A command that may or may not exist at the time of selection (e.g. result of a build)
|
2010-08-16 18:23:30 +02:00
|
|
|
Any
|
2008-12-05 18:51:07 +01:00
|
|
|
};
|
2020-12-08 17:32:27 +01:00
|
|
|
Q_ENUM(Kind)
|
2008-12-05 18:51:07 +01:00
|
|
|
|
2022-11-23 16:52:14 +01:00
|
|
|
// Default is <ExistingDirectory>
|
2008-12-05 18:51:07 +01:00
|
|
|
void setExpectedKind(Kind expected);
|
2009-06-29 14:47:04 +02:00
|
|
|
Kind expectedKind() const;
|
2008-12-05 18:51:07 +01:00
|
|
|
|
|
|
|
|
void setPromptDialogTitle(const QString &title);
|
2009-06-29 14:47:04 +02:00
|
|
|
QString promptDialogTitle() const;
|
|
|
|
|
|
|
|
|
|
void setPromptDialogFilter(const QString &filter);
|
|
|
|
|
QString promptDialogFilter() const;
|
2008-12-05 18:51:07 +01:00
|
|
|
|
2021-06-08 14:10:12 +02:00
|
|
|
void setInitialBrowsePathBackup(const FilePath &path);
|
2008-12-19 18:25:20 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
bool isValid() const;
|
|
|
|
|
QString errorMessage() const;
|
|
|
|
|
|
2021-09-09 17:08:32 +02:00
|
|
|
FilePath filePath() const; // Close to what's in the line edit.
|
|
|
|
|
FilePath absoluteFilePath() const; // Relative paths resolved wrt the specified base dir.
|
2020-04-09 11:05:50 +02:00
|
|
|
|
2020-05-20 13:22:10 +02:00
|
|
|
FilePath rawFilePath() const; // The raw unexpanded input as FilePath.
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2018-07-17 23:21:05 +03:00
|
|
|
static QString expandedDirectory(const QString &input, const Environment &env,
|
2016-01-07 13:46:54 +01:00
|
|
|
const QString &baseDir);
|
|
|
|
|
|
2019-12-17 11:53:58 +01:00
|
|
|
FilePath baseDirectory() const;
|
|
|
|
|
void setBaseDirectory(const FilePath &base);
|
2010-09-17 13:59:59 +02:00
|
|
|
|
2021-08-03 15:12:24 +02:00
|
|
|
void setEnvironmentChange(const EnvironmentChange &change);
|
2010-09-23 11:06:12 +02:00
|
|
|
|
2009-03-19 16:33:44 +01:00
|
|
|
/** Returns the suggested label title when used in a form layout. */
|
2008-12-02 12:01:29 +01:00
|
|
|
static QString label();
|
|
|
|
|
|
2015-04-28 14:49:56 +02:00
|
|
|
FancyLineEdit::ValidationFunction defaultValidationFunction() const;
|
|
|
|
|
void setValidationFunction(const FancyLineEdit::ValidationFunction &fn);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2009-03-19 16:33:44 +01:00
|
|
|
/** Return the home directory, which needs some fixing under Windows. */
|
2021-08-16 09:43:03 +02:00
|
|
|
static FilePath homePath();
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2015-04-30 15:22:57 +02:00
|
|
|
void addButton(const QString &text, QObject *context, const std::function<void()> &callback);
|
2022-11-22 11:33:24 +01:00
|
|
|
void insertButton(int index, QAbstractButton *button);
|
2015-04-30 15:22:57 +02:00
|
|
|
void insertButton(int index, const QString &text, QObject *context, const std::function<void()> &callback);
|
2009-07-22 15:18:42 +02:00
|
|
|
QAbstractButton *buttonAtIndex(int index) const;
|
2009-04-17 09:03:32 +02:00
|
|
|
|
2012-08-23 13:55:11 +02:00
|
|
|
FancyLineEdit *lineEdit() const;
|
2010-09-16 12:50:18 +02:00
|
|
|
|
2011-02-22 12:25:19 +01:00
|
|
|
// For PathChoosers of 'Command' type, this property specifies the arguments
|
|
|
|
|
// required to obtain the tool version (commonly, '--version'). Setting them
|
|
|
|
|
// causes the version to be displayed as a tooltip.
|
|
|
|
|
QStringList commandVersionArguments() const;
|
|
|
|
|
void setCommandVersionArguments(const QStringList &arguments);
|
|
|
|
|
|
|
|
|
|
// Utility to run a tool and return its stdout.
|
2022-05-24 12:14:24 +02:00
|
|
|
static QString toolVersion(const CommandLine &cmd);
|
2011-02-22 12:25:19 +01:00
|
|
|
// Install a tooltip on lineedits used for binaries showing the version.
|
|
|
|
|
static void installLineEditVersionToolTip(QLineEdit *le, const QStringList &arguments);
|
|
|
|
|
|
2013-10-28 18:18:03 +01:00
|
|
|
// Enable a history completer with a history of entries.
|
2015-12-26 21:47:16 +02:00
|
|
|
void setHistoryCompleter(const QString &historyKey, bool restoreLastItemFromHistory = false);
|
2013-10-28 18:18:03 +01:00
|
|
|
|
2018-09-06 09:03:55 +02:00
|
|
|
// Sets a macro expander that is used when producing path and fileName.
|
|
|
|
|
// By default, the global expander is used.
|
|
|
|
|
// nullptr can be passed to disable macro expansion.
|
2022-05-30 14:56:20 +02:00
|
|
|
void setMacroExpander(const MacroExpander *macroExpander);
|
2018-09-06 09:03:55 +02:00
|
|
|
|
2011-02-21 12:45:21 +01:00
|
|
|
bool isReadOnly() const;
|
|
|
|
|
void setReadOnly(bool b);
|
|
|
|
|
|
2013-01-15 19:30:42 +01:00
|
|
|
void triggerChanged();
|
2015-02-27 16:24:29 +01:00
|
|
|
|
2015-08-03 12:44:48 +02:00
|
|
|
// global handler for adding context menus to ALL pathchooser
|
|
|
|
|
// used by the coreplugin to add "Open in Terminal" and "Open in Explorer" context menu actions
|
2018-07-17 23:21:05 +03:00
|
|
|
using AboutToShowContextMenuHandler = std::function<void (PathChooser *, QMenu *)>;
|
2015-08-03 12:44:48 +02:00
|
|
|
static void setAboutToShowContextMenuHandler(AboutToShowContextMenuHandler handler);
|
|
|
|
|
|
2020-11-09 15:57:47 +01:00
|
|
|
void setOpenTerminalHandler(const std::function<void()> &openTerminal);
|
|
|
|
|
std::function<void()> openTerminalHandler() const;
|
|
|
|
|
|
2020-08-25 14:41:06 +02:00
|
|
|
// this sets the placeHolderText to defaultValue and enables to use this as
|
|
|
|
|
// input value during validation if the real value is empty
|
|
|
|
|
// setting an empty QString will disable this and clear the placeHolderText
|
|
|
|
|
void setDefaultValue(const QString &defaultValue);
|
2022-06-29 15:20:34 +02:00
|
|
|
|
2022-05-31 11:16:44 +02:00
|
|
|
void setAllowPathFromDevice(bool allow);
|
|
|
|
|
bool allowPathFromDevice() const;
|
|
|
|
|
|
2022-09-02 14:59:45 +02:00
|
|
|
public slots:
|
|
|
|
|
void setPath(const QString &);
|
|
|
|
|
void setFilePath(const FilePath &);
|
2008-12-05 18:51:07 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
signals:
|
2009-10-22 17:57:16 +02:00
|
|
|
void validChanged(bool validState);
|
2022-09-02 14:59:45 +02:00
|
|
|
void rawPathChanged();
|
2022-09-02 11:49:36 +02:00
|
|
|
void textChanged(const QString &text); // Triggered from the line edit's textChanged()
|
|
|
|
|
void editingFinished(); // Triggered from the line edit's editingFinished()
|
2008-12-19 18:25:20 +01:00
|
|
|
void beforeBrowsing();
|
2008-12-19 15:32:21 +01:00
|
|
|
void browsingFinished();
|
2008-12-02 12:01:29 +01:00
|
|
|
void returnPressed();
|
|
|
|
|
|
|
|
|
|
private:
|
2022-09-19 13:41:57 +02:00
|
|
|
// Deprecated, only used in property getter.
|
|
|
|
|
// Use filePath().toString() or better suitable conversions.
|
|
|
|
|
QString path() const { return filePath().toString(); }
|
|
|
|
|
|
2022-09-02 14:59:45 +02:00
|
|
|
bool validatePath(FancyLineEdit *edit, QString *errorMessage) const;
|
|
|
|
|
// Returns overridden title or the one from <title>
|
|
|
|
|
QString makeDialogTitle(const QString &title);
|
2022-11-22 11:33:24 +01:00
|
|
|
void slotBrowse(bool remote);
|
2022-09-02 14:59:45 +02:00
|
|
|
void contextMenuRequested(const QPoint &pos);
|
|
|
|
|
|
2017-08-16 22:10:50 +02:00
|
|
|
PathChooserPrivate *d = nullptr;
|
2015-08-03 12:44:48 +02:00
|
|
|
static AboutToShowContextMenuHandler s_aboutToShowContextMenuHandler;
|
2008-12-02 12:01:29 +01:00
|
|
|
};
|
|
|
|
|
|
2008-12-02 14:09:21 +01:00
|
|
|
} // namespace Utils
|