2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-02 12:01:29 +01:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** Copyright (C) 2015 The Qt Company Ltd.
|
|
|
|
|
** Contact: http://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
|
2015-01-14 18:07:15 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms and
|
|
|
|
|
** conditions see http://www.qt.io/terms-conditions. For further information
|
2014-10-01 13:21:18 +02:00
|
|
|
** use the contact form at http://www.qt.io/contact-us.
|
2008-12-02 14:17:16 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2012-10-02 09:12:39 +02:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
2014-10-01 13:21:18 +02:00
|
|
|
** General Public License version 2.1 or version 3 as published by the Free
|
|
|
|
|
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
|
|
|
|
|
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
|
|
|
|
|
** following information to ensure the GNU Lesser General Public License
|
|
|
|
|
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
|
|
|
|
|
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2012-10-02 09:12:39 +02:00
|
|
|
**
|
2015-01-14 18:07:15 +01:00
|
|
|
** In addition, as a special exception, The Qt Company gives you certain additional
|
|
|
|
|
** rights. These rights are described in The Qt Company LGPL Exception
|
2010-12-17 16:01:08 +01:00
|
|
|
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-05 12:21:18 +01:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
#ifndef PATHCHOOSER_H
|
|
|
|
|
#define PATHCHOOSER_H
|
|
|
|
|
|
2015-04-28 14:49:56 +02:00
|
|
|
#include "fancylineedit.h"
|
2012-01-13 16:35:53 +01:00
|
|
|
#include "fileutils.h"
|
|
|
|
|
|
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 {
|
|
|
|
|
|
2013-03-18 14:47:33 +01:00
|
|
|
class FancyLineEdit;
|
2010-09-23 11:06:12 +02:00
|
|
|
class Environment;
|
|
|
|
|
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
|
2009-06-29 14:47:04 +02:00
|
|
|
Q_ENUMS(Kind)
|
2013-07-13 14:44:26 +03:00
|
|
|
Q_PROPERTY(QString path READ path WRITE setPath NOTIFY pathChanged 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)
|
2010-09-17 13:59:59 +02:00
|
|
|
Q_PROPERTY(QString 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:
|
|
|
|
|
Q_PROPERTY(Utils::FileName fileName READ fileName WRITE setFileName DESIGNABLE false)
|
2012-03-13 15:23:38 +01:00
|
|
|
Q_PROPERTY(Utils::FileName baseFileName READ baseFileName WRITE setBaseFileName 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
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
explicit PathChooser(QWidget *parent = 0);
|
|
|
|
|
virtual ~PathChooser();
|
|
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Default is <Directory>
|
|
|
|
|
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
|
|
|
|
2008-12-19 18:25:20 +01:00
|
|
|
void setInitialBrowsePathBackup(const QString &path);
|
|
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
bool isValid() const;
|
|
|
|
|
QString errorMessage() const;
|
|
|
|
|
|
|
|
|
|
QString path() const;
|
2010-09-23 11:06:12 +02:00
|
|
|
QString rawPath() const; // The raw unexpanded input.
|
2014-07-15 23:33:17 +03:00
|
|
|
FileName fileName() const;
|
2008-12-02 12:01:29 +01:00
|
|
|
|
2010-09-17 13:59:59 +02:00
|
|
|
QString baseDirectory() const;
|
|
|
|
|
void setBaseDirectory(const QString &directory);
|
2014-05-02 12:53:36 +02:00
|
|
|
|
2014-07-15 23:33:17 +03:00
|
|
|
FileName baseFileName() const;
|
|
|
|
|
void setBaseFileName(const FileName &base);
|
2010-09-17 13:59:59 +02:00
|
|
|
|
2014-07-15 23:33:17 +03:00
|
|
|
void setEnvironment(const Environment &env);
|
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. */
|
2008-12-02 12:01:29 +01:00
|
|
|
static QString homePath();
|
|
|
|
|
|
2015-04-30 15:22:57 +02:00
|
|
|
void addButton(const QString &text, QObject *context, const std::function<void()> &callback);
|
|
|
|
|
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.
|
|
|
|
|
static QString toolVersion(const QString &binary, const QStringList &arguments);
|
|
|
|
|
// 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.
|
|
|
|
|
void setHistoryCompleter(const QString &historyKey);
|
|
|
|
|
|
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
|
|
|
|
|
using AboutToShowContextMenuHandler = std::function<void (Utils::PathChooser *, QMenu *)>;
|
|
|
|
|
static void setAboutToShowContextMenuHandler(AboutToShowContextMenuHandler handler);
|
|
|
|
|
|
2008-12-05 18:51:07 +01:00
|
|
|
private:
|
2015-04-28 14:49:56 +02:00
|
|
|
bool validatePath(FancyLineEdit *edit, QString *errorMessage) const;
|
2008-12-05 18:51:07 +01:00
|
|
|
// Returns overridden title or the one from <title>
|
|
|
|
|
QString makeDialogTitle(const QString &title);
|
2015-04-30 15:22:57 +02:00
|
|
|
void slotBrowse();
|
2015-08-03 12:44:48 +02:00
|
|
|
void contextMenuRequested(const QPoint &pos);
|
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);
|
2009-06-19 17:55:47 +02:00
|
|
|
void changed(const QString &text);
|
2013-07-13 14:44:26 +03:00
|
|
|
void pathChanged(const QString &path);
|
2009-03-19 09:32:09 +01:00
|
|
|
void 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();
|
|
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
void setPath(const QString &);
|
2012-01-13 16:35:53 +01:00
|
|
|
void setFileName(const Utils::FileName &);
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
private:
|
2011-09-07 14:26:11 +02:00
|
|
|
PathChooserPrivate *d;
|
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
|
2009-10-05 11:06:05 +02:00
|
|
|
|
2008-12-02 12:01:29 +01:00
|
|
|
|
|
|
|
|
#endif // PATHCHOOSER_H
|