change: preserve search term across different mod providers
Signed-off-by: flow <flowlnlnln@gmail.com>
This commit is contained in:
parent
a8bcd85c93
commit
5936c7b65c
@ -55,6 +55,8 @@ ModDownloadDialog::ModDownloadDialog(const std::shared_ptr<ModFolderModel>& mods
|
|||||||
|
|
||||||
m_container->addButtons(m_buttons);
|
m_container->addButtons(m_buttons);
|
||||||
|
|
||||||
|
connect(m_container, &PageContainer::selectedPageChanged, this, &ModDownloadDialog::selectedPageChanged);
|
||||||
|
|
||||||
// Bonk Qt over its stupid head and make sure it understands which button is the default one...
|
// Bonk Qt over its stupid head and make sure it understands which button is the default one...
|
||||||
// See: https://stackoverflow.com/questions/24556831/qbuttonbox-set-default-button
|
// See: https://stackoverflow.com/questions/24556831/qbuttonbox-set-default-button
|
||||||
auto OkButton = m_buttons->button(QDialogButtonBox::Ok);
|
auto OkButton = m_buttons->button(QDialogButtonBox::Ok);
|
||||||
@ -163,3 +165,21 @@ const QList<ModDownloadTask*> ModDownloadDialog::getTasks()
|
|||||||
{
|
{
|
||||||
return modTask.values();
|
return modTask.values();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModDownloadDialog::selectedPageChanged(BasePage* previous, BasePage* selected)
|
||||||
|
{
|
||||||
|
auto* prev_page = dynamic_cast<ModPage*>(previous);
|
||||||
|
if (!prev_page) {
|
||||||
|
qCritical() << "Page '" << previous->displayName() << "' in ModDownloadDialog is not a ModPage!";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto* selected_page = dynamic_cast<ModPage*>(selected);
|
||||||
|
if (!selected_page) {
|
||||||
|
qCritical() << "Page '" << selected->displayName() << "' in ModDownloadDialog is not a ModPage!";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Same effect as having a global search bar
|
||||||
|
selected_page->setSearchTerm(prev_page->getSearchTerm());
|
||||||
|
}
|
||||||
|
@ -34,7 +34,7 @@ class PageContainer;
|
|||||||
class QDialogButtonBox;
|
class QDialogButtonBox;
|
||||||
class ModrinthModPage;
|
class ModrinthModPage;
|
||||||
|
|
||||||
class ModDownloadDialog : public QDialog, public BasePageProvider
|
class ModDownloadDialog final : public QDialog, public BasePageProvider
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
@ -58,6 +58,9 @@ public slots:
|
|||||||
void accept() override;
|
void accept() override;
|
||||||
void reject() override;
|
void reject() override;
|
||||||
|
|
||||||
|
private slots:
|
||||||
|
void selectedPageChanged(BasePage* previous, BasePage* selected);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
Ui::ModDownloadDialog *ui = nullptr;
|
Ui::ModDownloadDialog *ui = nullptr;
|
||||||
PageContainer * m_container = nullptr;
|
PageContainer * m_container = nullptr;
|
||||||
|
@ -138,7 +138,16 @@ void ModPage::triggerSearch()
|
|||||||
updateSelectionButton();
|
updateSelectionButton();
|
||||||
}
|
}
|
||||||
|
|
||||||
listModel->searchWithTerm(ui->searchEdit->text(), ui->sortByBox->currentIndex(), changed);
|
listModel->searchWithTerm(getSearchTerm(), ui->sortByBox->currentIndex(), changed);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString ModPage::getSearchTerm() const
|
||||||
|
{
|
||||||
|
return ui->searchEdit->text();
|
||||||
|
}
|
||||||
|
void ModPage::setSearchTerm(QString term)
|
||||||
|
{
|
||||||
|
ui->searchEdit->setText(term);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ModPage::onSelectionChanged(QModelIndex first, QModelIndex second)
|
void ModPage::onSelectionChanged(QModelIndex first, QModelIndex second)
|
||||||
|
@ -45,6 +45,11 @@ class ModPage : public QWidget, public BasePage {
|
|||||||
auto getFilter() const -> const std::shared_ptr<ModFilterWidget::Filter> { return m_filter; }
|
auto getFilter() const -> const std::shared_ptr<ModFilterWidget::Filter> { return m_filter; }
|
||||||
auto getDialog() const -> const ModDownloadDialog* { return dialog; }
|
auto getDialog() const -> const ModDownloadDialog* { return dialog; }
|
||||||
|
|
||||||
|
/** Get the current term in the search bar. */
|
||||||
|
auto getSearchTerm() const -> QString;
|
||||||
|
/** Programatically set the term in the search bar. */
|
||||||
|
void setSearchTerm(QString);
|
||||||
|
|
||||||
auto getCurrent() -> ModPlatform::IndexedPack& { return current; }
|
auto getCurrent() -> ModPlatform::IndexedPack& { return current; }
|
||||||
void updateModVersions(int prev_count = -1);
|
void updateModVersions(int prev_count = -1);
|
||||||
|
|
||||||
|
@ -244,7 +244,14 @@ void PageContainer::help()
|
|||||||
|
|
||||||
void PageContainer::currentChanged(const QModelIndex ¤t)
|
void PageContainer::currentChanged(const QModelIndex ¤t)
|
||||||
{
|
{
|
||||||
showPage(current.isValid() ? m_proxyModel->mapToSource(current).row() : -1);
|
int selected_index = current.isValid() ? m_proxyModel->mapToSource(current).row() : -1;
|
||||||
|
|
||||||
|
auto* selected = m_model->pages().at(selected_index);
|
||||||
|
auto* previous = m_currentPage;
|
||||||
|
|
||||||
|
emit selectedPageChanged(previous, selected);
|
||||||
|
|
||||||
|
showPage(selected_index);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PageContainer::prepareToClose()
|
bool PageContainer::prepareToClose()
|
||||||
|
@ -95,6 +95,10 @@ private:
|
|||||||
public slots:
|
public slots:
|
||||||
void help();
|
void help();
|
||||||
|
|
||||||
|
signals:
|
||||||
|
/** Emitted when the currently selected page is changed */
|
||||||
|
void selectedPageChanged(BasePage* previous, BasePage* selected);
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void currentChanged(const QModelIndex ¤t);
|
void currentChanged(const QModelIndex ¤t);
|
||||||
void showPage(int row);
|
void showPage(int row);
|
||||||
|
Loading…
Reference in New Issue
Block a user