Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mod count to mods page #1119

Merged
merged 6 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
24 changes: 12 additions & 12 deletions launcher/ui/pages/BasePage.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,16 @@

#pragma once

#include <QString>
#include <QIcon>
#include <QString>
#include <functional>
#include <memory>

#include "BasePageContainer.h"

class BasePage
{
public:
class BasePage {
public:
using updateExtraInfoFunc = std::function<void(QString)>;
virtual ~BasePage() {}
virtual QString id() const = 0;
virtual QString displayName() const = 0;
Expand All @@ -63,17 +64,16 @@ class BasePage
}
virtual void openedImpl() {}
virtual void closedImpl() {}
virtual void setParentContainer(BasePageContainer * container)
{
m_container = container;
};
virtual void retranslate() { }
virtual void setParentContainer(BasePageContainer* container) { m_container = container; };
virtual void retranslate() {}

public:
public:
int stackIndex = -1;
int listIndex = -1;
protected:
BasePageContainer * m_container = nullptr;
updateExtraInfoFunc updateExtraInfo;

protected:
BasePageContainer* m_container = nullptr;
bool isOpened = false;
};

Expand Down
19 changes: 18 additions & 1 deletion launcher/ui/pages/instance/ExternalResourcesPage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include <QKeyEvent>
#include <QMenu>
#include <algorithm>

ExternalResourcesPage::ExternalResourcesPage(BaseInstance* instance, std::shared_ptr<ResourceFolderModel> model, QWidget* parent)
: QMainWindow(parent), m_instance(instance), ui(new Ui::ExternalResourcesPage), m_model(model)
Expand Down Expand Up @@ -43,6 +44,13 @@ ExternalResourcesPage::ExternalResourcesPage(BaseInstance* instance, std::shared

auto selection_model = ui->treeView->selectionModel();
connect(selection_model, &QItemSelectionModel::currentChanged, this, &ExternalResourcesPage::current);
auto updateExtra = [this]() {
if (updateExtraInfo)
updateExtraInfo(extraHeaderInfoString());
};
connect(selection_model, &QItemSelectionModel::selectionChanged, this, updateExtra);
connect(model.get(), &ResourceFolderModel::updateFinished, this, updateExtra);

connect(ui->filterEdit, &QLineEdit::textChanged, this, &ExternalResourcesPage::filterTextChanged);
}

Expand Down Expand Up @@ -248,6 +256,15 @@ bool ExternalResourcesPage::onSelectionChanged(const QModelIndex& current, const
int row = sourceCurrent.row();
Resource const& resource = m_model->at(row);
ui->frame->updateWithResource(resource);

return true;
}

QString ExternalResourcesPage::extraHeaderInfoString()
{
if (ui && ui->treeView && ui->treeView->selectionModel()) {
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection()).indexes();
if (auto count = std::count_if(selection.cbegin(), selection.cend(), [](auto v) { return v.column() == 0; }); count != 0)
return tr("[%1 installed, %2 selected]").arg(m_model->size()).arg(count);
Trial97 marked this conversation as resolved.
Show resolved Hide resolved
}
return tr("[%1 installed]").arg(m_model->size());
}
1 change: 1 addition & 0 deletions launcher/ui/pages/instance/ExternalResourcesPage.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class ExternalResourcesPage : public QMainWindow, public BasePage {
virtual QString helpPage() const override = 0;

virtual bool shouldDisplay() const override = 0;
QString extraHeaderInfoString();

void openedImpl() override;
void closedImpl() override;
Expand Down
4 changes: 4 additions & 0 deletions launcher/ui/widgets/PageContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ PageContainer::PageContainer(BasePageProvider *pageProvider, QString defaultId,
page->listIndex = counter;
page->setParentContainer(this);
counter++;
page->updateExtraInfo = [this](QString info) {
if (m_currentPage)
m_header->setText(m_currentPage->displayName() + info);
};
}
m_model->setPages(pages);

Expand Down