PathChooser: Allow for chooser-only selection of files/directories

Makes the line edit disabled and read-only in that case.
We also need to change the custom context menu from the line edit to the
path chooser itself, because disabled widgets do not show a context
menu, but we still want to see the select & copy, and the special
items for opening explorer or terminal.

Task-number: QTCREATORBUG-23798
Change-Id: Ib653b4eaaedfbe54c614377795ddc52d21ac12c0
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Tobias Hunger <tobias.hunger@qt.io>
This commit is contained in:
Tobias Hunger
2020-03-16 10:24:35 +01:00
committed by Eike Ziller
parent 5838b40c6d
commit 69b0a2cafc
5 changed files with 66 additions and 18 deletions

View File

@@ -109,6 +109,7 @@ public:
Utils::FilePath m_baseFileName;
bool m_readOnly = false;
bool m_showToolTipOnLabel = false;
bool m_fileDialogOnly = false;
template<class Widget> void updateWidgetFromCheckStatus(Widget *w)
{
@@ -257,6 +258,13 @@ void BaseStringAspect::setExpectedKind(const PathChooser::Kind expectedKind)
d->m_pathChooserDisplay->setExpectedKind(expectedKind);
}
void BaseStringAspect::setFileDialogOnly(bool requireFileDialog)
{
d->m_fileDialogOnly = requireFileDialog;
if (d->m_pathChooserDisplay)
d->m_pathChooserDisplay->setFileDialogOnly(requireFileDialog);
}
void BaseStringAspect::setEnvironment(const Environment &env)
{
d->m_environment = env;
@@ -337,6 +345,7 @@ void BaseStringAspect::addToLayout(LayoutBuilder &builder)
connect(d->m_pathChooserDisplay, &PathChooser::pathChanged,
this, &BaseStringAspect::setValue);
builder.addItem(d->m_pathChooserDisplay.data());
d->m_pathChooserDisplay->setFileDialogOnly(d->m_fileDialogOnly);
break;
case LineEditDisplay:
d->m_lineEditDisplay = new FancyLineEdit;