forked from qt-creator/qt-creator
SelectableFiles: Introduce a common widget
Introduce a SelectableFilesWidget and use it in the FileSelectionWizardPage as well as in the two FileSelectionDialogs we have. Change-Id: I56acaa7a9776ac2c0c16c548e95794a662b9cd27 Reviewed-by: Niels Weber <niels.weber@theqtcompany.com>
This commit is contained in:
@@ -45,129 +45,29 @@
|
||||
namespace GenericProjectManager {
|
||||
namespace Internal {
|
||||
|
||||
FilesSelectionWizardPage::FilesSelectionWizardPage(GenericProjectWizardDialog *genericProjectWizard, QWidget *parent)
|
||||
: QWizardPage(parent), m_genericProjectWizardDialog(genericProjectWizard), m_model(0), m_finished(false)
|
||||
FilesSelectionWizardPage::FilesSelectionWizardPage(GenericProjectWizardDialog *genericProjectWizard,
|
||||
QWidget *parent) :
|
||||
QWizardPage(parent),
|
||||
m_genericProjectWizardDialog(genericProjectWizard),
|
||||
m_filesWidget(new ProjectExplorer::SelectableFilesWidget(this))
|
||||
{
|
||||
QVBoxLayout *layout = new QVBoxLayout(this);
|
||||
|
||||
createShowFileFilterControls(layout);
|
||||
createHideFileFilterControls(layout);
|
||||
createApplyButton(layout);
|
||||
|
||||
m_view = new QTreeView;
|
||||
m_view->setMinimumSize(500, 400);
|
||||
m_view->setHeaderHidden(true);
|
||||
m_view->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::MinimumExpanding);
|
||||
m_label = new QLabel;
|
||||
m_label->setMaximumWidth(500);
|
||||
|
||||
layout->addWidget(m_view);
|
||||
layout->addWidget(m_label);
|
||||
layout->addWidget(m_filesWidget);
|
||||
m_filesWidget->setBaseDirEditable(false);
|
||||
|
||||
setProperty(Utils::SHORT_TITLE_PROPERTY, tr("Files"));
|
||||
}
|
||||
|
||||
void FilesSelectionWizardPage::createHideFileFilterControls(QVBoxLayout *layout)
|
||||
{
|
||||
QHBoxLayout *hbox = new QHBoxLayout;
|
||||
m_hideFilesFilterLabel = new QLabel;
|
||||
m_hideFilesFilterLabel->setText(tr("Hide files matching:"));
|
||||
|
||||
m_hideFilesFilterLabel->hide();
|
||||
hbox->addWidget(m_hideFilesFilterLabel);
|
||||
m_hideFilesfilterLineEdit = new QLineEdit;
|
||||
|
||||
const QString filter = Core::ICore::settings()->value(QLatin1String(Constants::HIDE_FILE_FILTER_SETTING),
|
||||
QLatin1String(Constants::HIDE_FILE_FILTER_DEFAULT)).toString();
|
||||
m_hideFilesfilterLineEdit->setText(filter);
|
||||
m_hideFilesfilterLineEdit->hide();
|
||||
hbox->addWidget(m_hideFilesfilterLineEdit);
|
||||
layout->addLayout(hbox);
|
||||
}
|
||||
|
||||
void FilesSelectionWizardPage::createShowFileFilterControls(QVBoxLayout *layout)
|
||||
{
|
||||
QHBoxLayout *hbox = new QHBoxLayout;
|
||||
m_showFilesFilterLabel = new QLabel;
|
||||
m_showFilesFilterLabel->setText(tr("Show files matching:"));
|
||||
m_showFilesFilterLabel->hide();
|
||||
hbox->addWidget(m_showFilesFilterLabel);
|
||||
m_showFilesfilterLineEdit = new QLineEdit;
|
||||
|
||||
const QString filter = Core::ICore::settings()->value(QLatin1String(Constants::SHOW_FILE_FILTER_SETTING),
|
||||
QLatin1String(Constants::SHOW_FILE_FILTER_DEFAULT)).toString();
|
||||
m_showFilesfilterLineEdit->setText(filter);
|
||||
m_showFilesfilterLineEdit->hide();
|
||||
hbox->addWidget(m_showFilesfilterLineEdit);
|
||||
layout->addLayout(hbox);
|
||||
}
|
||||
|
||||
void FilesSelectionWizardPage::createApplyButton(QVBoxLayout *layout)
|
||||
{
|
||||
QHBoxLayout *hbox = new QHBoxLayout;
|
||||
|
||||
QSpacerItem *horizontalSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
|
||||
hbox->addItem(horizontalSpacer);
|
||||
|
||||
m_applyFilterButton = new QPushButton(tr("Apply Filter"), this);
|
||||
m_applyFilterButton->hide();
|
||||
hbox->addWidget(m_applyFilterButton);
|
||||
layout->addLayout(hbox);
|
||||
|
||||
connect(m_applyFilterButton, &QPushButton::clicked, this, &FilesSelectionWizardPage::applyFilter);
|
||||
}
|
||||
|
||||
void FilesSelectionWizardPage::initializePage()
|
||||
{
|
||||
m_view->setModel(0);
|
||||
delete m_model;
|
||||
m_model = new ProjectExplorer::SelectableFilesModel(this);
|
||||
connect(m_model, &ProjectExplorer::SelectableFilesModel::parsingProgress,
|
||||
this, &FilesSelectionWizardPage::parsingProgress);
|
||||
connect(m_model, &ProjectExplorer::SelectableFilesModel::parsingFinished,
|
||||
this, &FilesSelectionWizardPage::parsingFinished);
|
||||
m_model->startParsing(Utils::FileName::fromString(m_genericProjectWizardDialog->path()));
|
||||
|
||||
m_hideFilesFilterLabel->setVisible(false);
|
||||
m_hideFilesfilterLineEdit->setVisible(false);
|
||||
|
||||
m_showFilesFilterLabel->setVisible(false);
|
||||
m_showFilesfilterLineEdit->setVisible(false);
|
||||
|
||||
m_applyFilterButton->setVisible(false);
|
||||
m_view->setVisible(false);
|
||||
m_label->setVisible(true);
|
||||
m_view->setModel(m_model);
|
||||
m_filesWidget->resetModel(Utils::FileName::fromString(m_genericProjectWizardDialog->path()),
|
||||
Utils::FileNameList());
|
||||
}
|
||||
|
||||
void FilesSelectionWizardPage::cleanupPage()
|
||||
{
|
||||
m_model->cancel();
|
||||
}
|
||||
|
||||
void FilesSelectionWizardPage::parsingProgress(const Utils::FileName &text)
|
||||
{
|
||||
m_label->setText(tr("Generating file list...\n\n%1").arg(text.toUserOutput()));
|
||||
}
|
||||
|
||||
void FilesSelectionWizardPage::parsingFinished()
|
||||
{
|
||||
m_finished = true;
|
||||
|
||||
m_hideFilesFilterLabel->setVisible(true);
|
||||
m_hideFilesfilterLineEdit->setVisible(true);
|
||||
|
||||
m_showFilesFilterLabel->setVisible(true);
|
||||
m_showFilesfilterLineEdit->setVisible(true);
|
||||
|
||||
m_applyFilterButton->setVisible(true);
|
||||
m_view->setVisible(true);
|
||||
m_label->setVisible(false);
|
||||
m_view->expand(m_view->model()->index(0,0, QModelIndex()));
|
||||
emit completeChanged();
|
||||
applyFilter();
|
||||
// work around qt
|
||||
m_genericProjectWizardDialog->setTitleFormat(m_genericProjectWizardDialog->titleFormat());
|
||||
m_filesWidget->cancelParsing();
|
||||
}
|
||||
|
||||
bool FilesSelectionWizardPage::isComplete() const
|
||||
@@ -177,23 +77,12 @@ bool FilesSelectionWizardPage::isComplete() const
|
||||
|
||||
Utils::FileNameList FilesSelectionWizardPage::selectedPaths() const
|
||||
{
|
||||
return m_model ? m_model->selectedPaths() : Utils::FileNameList();
|
||||
return m_filesWidget->selectedPaths();
|
||||
}
|
||||
|
||||
Utils::FileNameList FilesSelectionWizardPage::selectedFiles() const
|
||||
{
|
||||
return m_model ? m_model->selectedFiles() : Utils::FileNameList();
|
||||
}
|
||||
|
||||
void FilesSelectionWizardPage::applyFilter()
|
||||
{
|
||||
const QString showFilesFilter = m_showFilesfilterLineEdit->text();
|
||||
Core::ICore::settings()->setValue(QLatin1String(Constants::SHOW_FILE_FILTER_SETTING), showFilesFilter);
|
||||
|
||||
const QString hideFilesFilter = m_hideFilesfilterLineEdit->text();
|
||||
Core::ICore::settings()->setValue(QLatin1String(Constants::HIDE_FILE_FILTER_SETTING), hideFilesFilter);
|
||||
|
||||
m_model->applyFilter(showFilesFilter, hideFilesFilter);
|
||||
return m_filesWidget->selectedFiles();
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
Reference in New Issue
Block a user