Merge pull request #1119 from Trial97/mods_txt
Added dynamic page extra info
This commit is contained in:
commit
ca659136e2
@ -35,15 +35,16 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <QString>
|
|
||||||
#include <QIcon>
|
#include <QIcon>
|
||||||
|
#include <QString>
|
||||||
|
#include <functional>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
||||||
#include "BasePageContainer.h"
|
#include "BasePageContainer.h"
|
||||||
|
|
||||||
class BasePage
|
class BasePage {
|
||||||
{
|
public:
|
||||||
public:
|
using updateExtraInfoFunc = std::function<void(QString)>;
|
||||||
virtual ~BasePage() {}
|
virtual ~BasePage() {}
|
||||||
virtual QString id() const = 0;
|
virtual QString id() const = 0;
|
||||||
virtual QString displayName() const = 0;
|
virtual QString displayName() const = 0;
|
||||||
@ -63,17 +64,16 @@ public:
|
|||||||
}
|
}
|
||||||
virtual void openedImpl() {}
|
virtual void openedImpl() {}
|
||||||
virtual void closedImpl() {}
|
virtual void closedImpl() {}
|
||||||
virtual void setParentContainer(BasePageContainer * container)
|
virtual void setParentContainer(BasePageContainer* container) { m_container = container; };
|
||||||
{
|
virtual void retranslate() {}
|
||||||
m_container = container;
|
|
||||||
};
|
|
||||||
virtual void retranslate() { }
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int stackIndex = -1;
|
int stackIndex = -1;
|
||||||
int listIndex = -1;
|
int listIndex = -1;
|
||||||
protected:
|
updateExtraInfoFunc updateExtraInfo;
|
||||||
BasePageContainer * m_container = nullptr;
|
|
||||||
|
protected:
|
||||||
|
BasePageContainer* m_container = nullptr;
|
||||||
bool isOpened = false;
|
bool isOpened = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -1,3 +1,38 @@
|
|||||||
|
// SPDX-License-Identifier: GPL-3.0-only
|
||||||
|
/*
|
||||||
|
* Prism Launcher - Minecraft Launcher
|
||||||
|
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation, version 3.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*
|
||||||
|
* This file incorporates work covered by the following copyright and
|
||||||
|
* permission notice:
|
||||||
|
*
|
||||||
|
* Copyright 2013-2021 MultiMC Contributors
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and
|
||||||
|
* limitations under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
#include "ExternalResourcesPage.h"
|
#include "ExternalResourcesPage.h"
|
||||||
#include "ui/dialogs/CustomMessageBox.h"
|
#include "ui/dialogs/CustomMessageBox.h"
|
||||||
#include "ui_ExternalResourcesPage.h"
|
#include "ui_ExternalResourcesPage.h"
|
||||||
@ -9,6 +44,7 @@
|
|||||||
|
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
#include <QMenu>
|
#include <QMenu>
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
ExternalResourcesPage::ExternalResourcesPage(BaseInstance* instance, std::shared_ptr<ResourceFolderModel> model, QWidget* parent)
|
ExternalResourcesPage::ExternalResourcesPage(BaseInstance* instance, std::shared_ptr<ResourceFolderModel> model, QWidget* parent)
|
||||||
: QMainWindow(parent), m_instance(instance), ui(new Ui::ExternalResourcesPage), m_model(model)
|
: QMainWindow(parent), m_instance(instance), ui(new Ui::ExternalResourcesPage), m_model(model)
|
||||||
@ -43,6 +79,13 @@ ExternalResourcesPage::ExternalResourcesPage(BaseInstance* instance, std::shared
|
|||||||
|
|
||||||
auto selection_model = ui->treeView->selectionModel();
|
auto selection_model = ui->treeView->selectionModel();
|
||||||
connect(selection_model, &QItemSelectionModel::currentChanged, this, &ExternalResourcesPage::current);
|
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);
|
connect(ui->filterEdit, &QLineEdit::textChanged, this, &ExternalResourcesPage::filterTextChanged);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -248,6 +291,15 @@ bool ExternalResourcesPage::onSelectionChanged(const QModelIndex& current, const
|
|||||||
int row = sourceCurrent.row();
|
int row = sourceCurrent.row();
|
||||||
Resource const& resource = m_model->at(row);
|
Resource const& resource = m_model->at(row);
|
||||||
ui->frame->updateWithResource(resource);
|
ui->frame->updateWithResource(resource);
|
||||||
|
|
||||||
return true;
|
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);
|
||||||
|
}
|
||||||
|
return tr(" (%1 installed)").arg(m_model->size());
|
||||||
|
}
|
||||||
|
@ -29,6 +29,7 @@ class ExternalResourcesPage : public QMainWindow, public BasePage {
|
|||||||
virtual QString helpPage() const override = 0;
|
virtual QString helpPage() const override = 0;
|
||||||
|
|
||||||
virtual bool shouldDisplay() const override = 0;
|
virtual bool shouldDisplay() const override = 0;
|
||||||
|
QString extraHeaderInfoString();
|
||||||
|
|
||||||
void openedImpl() override;
|
void openedImpl() override;
|
||||||
void closedImpl() override;
|
void closedImpl() override;
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
|
* Copyright (c) 2022 Jamie Mansfield <jmansfield@cadixdev.org>
|
||||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||||
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
* Copyright (C) 2022 TheKodeToad <TheKodeToad@proton.me>
|
||||||
|
* Copyright (c) 2023 Trial97 <alexandru.tripon97@gmail.com>
|
||||||
*
|
*
|
||||||
* This program is free software: you can redistribute it and/or modify
|
* This program is free software: you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -86,28 +87,20 @@ ModFolderPage::ModFolderPage(BaseInstance* inst, std::shared_ptr<ModFolderModel>
|
|||||||
connect(ui->actionUpdateItem, &QAction::triggered, this, &ModFolderPage::updateMods);
|
connect(ui->actionUpdateItem, &QAction::triggered, this, &ModFolderPage::updateMods);
|
||||||
|
|
||||||
auto check_allow_update = [this] {
|
auto check_allow_update = [this] {
|
||||||
return (!m_instance || !m_instance->isRunning()) &&
|
return (!m_instance || !m_instance->isRunning()) && (ui->treeView->selectionModel()->hasSelection() || !m_model->empty());
|
||||||
(ui->treeView->selectionModel()->hasSelection() || !m_model->empty());
|
|
||||||
};
|
};
|
||||||
|
|
||||||
connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this, [this, check_allow_update] {
|
connect(ui->treeView->selectionModel(), &QItemSelectionModel::selectionChanged, this,
|
||||||
ui->actionUpdateItem->setEnabled(check_allow_update());
|
[this, check_allow_update] { ui->actionUpdateItem->setEnabled(check_allow_update()); });
|
||||||
});
|
|
||||||
|
|
||||||
connect(mods.get(), &ModFolderModel::rowsInserted, this, [this, check_allow_update] {
|
connect(mods.get(), &ModFolderModel::rowsInserted, this,
|
||||||
ui->actionUpdateItem->setEnabled(check_allow_update());
|
[this, check_allow_update] { ui->actionUpdateItem->setEnabled(check_allow_update()); });
|
||||||
});
|
|
||||||
|
|
||||||
connect(mods.get(), &ModFolderModel::rowsRemoved, this, [this, check_allow_update] {
|
connect(mods.get(), &ModFolderModel::rowsRemoved, this,
|
||||||
ui->actionUpdateItem->setEnabled(check_allow_update());
|
[this, check_allow_update] { ui->actionUpdateItem->setEnabled(check_allow_update()); });
|
||||||
});
|
|
||||||
|
|
||||||
connect(mods.get(), &ModFolderModel::updateFinished, this, [this, check_allow_update, mods] {
|
connect(mods.get(), &ModFolderModel::updateFinished, this,
|
||||||
ui->actionUpdateItem->setEnabled(check_allow_update());
|
[this, check_allow_update] { ui->actionUpdateItem->setEnabled(check_allow_update()); });
|
||||||
|
|
||||||
// Prevent a weird crash when trying to open the mods page twice in a session o.O
|
|
||||||
disconnect(mods.get(), &ModFolderModel::updateFinished, this, 0);
|
|
||||||
});
|
|
||||||
|
|
||||||
connect(m_instance, &BaseInstance::runningStatusChanged, this, &ModFolderPage::runningStateChanged);
|
connect(m_instance, &BaseInstance::runningStatusChanged, this, &ModFolderPage::runningStateChanged);
|
||||||
ModFolderPage::runningStateChanged(m_instance && m_instance->isRunning());
|
ModFolderPage::runningStateChanged(m_instance && m_instance->isRunning());
|
||||||
|
@ -93,6 +93,10 @@ PageContainer::PageContainer(BasePageProvider *pageProvider, QString defaultId,
|
|||||||
page->listIndex = counter;
|
page->listIndex = counter;
|
||||||
page->setParentContainer(this);
|
page->setParentContainer(this);
|
||||||
counter++;
|
counter++;
|
||||||
|
page->updateExtraInfo = [this](QString info) {
|
||||||
|
if (m_currentPage)
|
||||||
|
m_header->setText(m_currentPage->displayName() + info);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
m_model->setPages(pages);
|
m_model->setPages(pages);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user