2023-06-15 10:32:48 +01:00
|
|
|
// 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.
|
|
|
|
*/
|
|
|
|
|
refactor: Create a more clear hierarchy for some instance pages
Previously, the Shaders, Texture packs and Resource packs tabs had as
parent the ModFolderPage, making it so that making changes only to the
Mods page would require checking the id of the page for the correct one.
This was hackish and error-prone.
Now, those pages all inherit from a single class, ExternalResourcesPage,
that handles the basic behaviour of all of them, while allowing for
individual modification in code.
This is still not a clear separation, since internally, all those
resources are derived from Mods, so for now there's still some awkward
common code :/
2022-03-11 21:03:21 +00:00
|
|
|
#include "ExternalResourcesPage.h"
|
2022-12-14 15:02:04 +00:00
|
|
|
#include "ui/dialogs/CustomMessageBox.h"
|
refactor: Create a more clear hierarchy for some instance pages
Previously, the Shaders, Texture packs and Resource packs tabs had as
parent the ModFolderPage, making it so that making changes only to the
Mods page would require checking the id of the page for the correct one.
This was hackish and error-prone.
Now, those pages all inherit from a single class, ExternalResourcesPage,
that handles the basic behaviour of all of them, while allowing for
individual modification in code.
This is still not a clear separation, since internally, all those
resources are derived from Mods, so for now there's still some awkward
common code :/
2022-03-11 21:03:21 +00:00
|
|
|
#include "ui_ExternalResourcesPage.h"
|
|
|
|
|
|
|
|
#include "DesktopServices.h"
|
|
|
|
#include "Version.h"
|
2022-08-10 18:48:34 +01:00
|
|
|
#include "minecraft/mod/ResourceFolderModel.h"
|
refactor: Create a more clear hierarchy for some instance pages
Previously, the Shaders, Texture packs and Resource packs tabs had as
parent the ModFolderPage, making it so that making changes only to the
Mods page would require checking the id of the page for the correct one.
This was hackish and error-prone.
Now, those pages all inherit from a single class, ExternalResourcesPage,
that handles the basic behaviour of all of them, while allowing for
individual modification in code.
This is still not a clear separation, since internally, all those
resources are derived from Mods, so for now there's still some awkward
common code :/
2022-03-11 21:03:21 +00:00
|
|
|
#include "ui/GuiUtil.h"
|
|
|
|
|
|
|
|
#include <QKeyEvent>
|
|
|
|
#include <QMenu>
|
2023-06-06 22:16:23 +01:00
|
|
|
#include <algorithm>
|
refactor: Create a more clear hierarchy for some instance pages
Previously, the Shaders, Texture packs and Resource packs tabs had as
parent the ModFolderPage, making it so that making changes only to the
Mods page would require checking the id of the page for the correct one.
This was hackish and error-prone.
Now, those pages all inherit from a single class, ExternalResourcesPage,
that handles the basic behaviour of all of them, while allowing for
individual modification in code.
This is still not a clear separation, since internally, all those
resources are derived from Mods, so for now there's still some awkward
common code :/
2022-03-11 21:03:21 +00:00
|
|
|
|
2022-08-10 18:48:34 +01:00
|
|
|
ExternalResourcesPage::ExternalResourcesPage(BaseInstance* instance, std::shared_ptr<ResourceFolderModel> model, QWidget* parent)
|
refactor: Create a more clear hierarchy for some instance pages
Previously, the Shaders, Texture packs and Resource packs tabs had as
parent the ModFolderPage, making it so that making changes only to the
Mods page would require checking the id of the page for the correct one.
This was hackish and error-prone.
Now, those pages all inherit from a single class, ExternalResourcesPage,
that handles the basic behaviour of all of them, while allowing for
individual modification in code.
This is still not a clear separation, since internally, all those
resources are derived from Mods, so for now there's still some awkward
common code :/
2022-03-11 21:03:21 +00:00
|
|
|
: QMainWindow(parent), m_instance(instance), ui(new Ui::ExternalResourcesPage), m_model(model)
|
|
|
|
{
|
|
|
|
ui->setupUi(this);
|
|
|
|
|
|
|
|
ui->actionsToolbar->insertSpacer(ui->actionViewConfigs);
|
|
|
|
|
2022-08-10 18:48:34 +01:00
|
|
|
m_filterModel = model->createFilterProxyModel(this);
|
refactor: Create a more clear hierarchy for some instance pages
Previously, the Shaders, Texture packs and Resource packs tabs had as
parent the ModFolderPage, making it so that making changes only to the
Mods page would require checking the id of the page for the correct one.
This was hackish and error-prone.
Now, those pages all inherit from a single class, ExternalResourcesPage,
that handles the basic behaviour of all of them, while allowing for
individual modification in code.
This is still not a clear separation, since internally, all those
resources are derived from Mods, so for now there's still some awkward
common code :/
2022-03-11 21:03:21 +00:00
|
|
|
m_filterModel->setDynamicSortFilter(true);
|
|
|
|
m_filterModel->setFilterCaseSensitivity(Qt::CaseInsensitive);
|
|
|
|
m_filterModel->setSortCaseSensitivity(Qt::CaseInsensitive);
|
|
|
|
m_filterModel->setSourceModel(m_model.get());
|
|
|
|
m_filterModel->setFilterKeyColumn(-1);
|
|
|
|
ui->treeView->setModel(m_filterModel);
|
2023-05-25 04:15:34 +01:00
|
|
|
// must come after setModel
|
|
|
|
ui->treeView->setResizeModes(m_model->columnResizeModes());
|
refactor: Create a more clear hierarchy for some instance pages
Previously, the Shaders, Texture packs and Resource packs tabs had as
parent the ModFolderPage, making it so that making changes only to the
Mods page would require checking the id of the page for the correct one.
This was hackish and error-prone.
Now, those pages all inherit from a single class, ExternalResourcesPage,
that handles the basic behaviour of all of them, while allowing for
individual modification in code.
This is still not a clear separation, since internally, all those
resources are derived from Mods, so for now there's still some awkward
common code :/
2022-03-11 21:03:21 +00:00
|
|
|
|
|
|
|
ui->treeView->installEventFilter(this);
|
|
|
|
ui->treeView->sortByColumn(1, Qt::AscendingOrder);
|
|
|
|
ui->treeView->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
|
|
|
|
// The default function names by Qt are pretty ugly, so let's just connect the actions manually,
|
|
|
|
// to make it easier to read :)
|
|
|
|
connect(ui->actionAddItem, &QAction::triggered, this, &ExternalResourcesPage::addItem);
|
|
|
|
connect(ui->actionRemoveItem, &QAction::triggered, this, &ExternalResourcesPage::removeItem);
|
|
|
|
connect(ui->actionEnableItem, &QAction::triggered, this, &ExternalResourcesPage::enableItem);
|
|
|
|
connect(ui->actionDisableItem, &QAction::triggered, this, &ExternalResourcesPage::disableItem);
|
|
|
|
connect(ui->actionViewConfigs, &QAction::triggered, this, &ExternalResourcesPage::viewConfigs);
|
|
|
|
connect(ui->actionViewFolder, &QAction::triggered, this, &ExternalResourcesPage::viewFolder);
|
|
|
|
|
|
|
|
connect(ui->treeView, &ModListView::customContextMenuRequested, this, &ExternalResourcesPage::ShowContextMenu);
|
2022-08-13 15:58:39 +01:00
|
|
|
connect(ui->treeView, &ModListView::activated, this, &ExternalResourcesPage::itemActivated);
|
refactor: Create a more clear hierarchy for some instance pages
Previously, the Shaders, Texture packs and Resource packs tabs had as
parent the ModFolderPage, making it so that making changes only to the
Mods page would require checking the id of the page for the correct one.
This was hackish and error-prone.
Now, those pages all inherit from a single class, ExternalResourcesPage,
that handles the basic behaviour of all of them, while allowing for
individual modification in code.
This is still not a clear separation, since internally, all those
resources are derived from Mods, so for now there's still some awkward
common code :/
2022-03-11 21:03:21 +00:00
|
|
|
|
|
|
|
auto selection_model = ui->treeView->selectionModel();
|
|
|
|
connect(selection_model, &QItemSelectionModel::currentChanged, this, &ExternalResourcesPage::current);
|
2023-06-06 22:16:23 +01:00
|
|
|
auto updateExtra = [this]() {
|
|
|
|
if (updateExtraInfo)
|
2023-06-25 20:00:33 +01:00
|
|
|
updateExtraInfo(id(), extraHeaderInfoString());
|
2023-06-06 22:16:23 +01:00
|
|
|
};
|
|
|
|
connect(selection_model, &QItemSelectionModel::selectionChanged, this, updateExtra);
|
|
|
|
connect(model.get(), &ResourceFolderModel::updateFinished, this, updateExtra);
|
|
|
|
|
refactor: Create a more clear hierarchy for some instance pages
Previously, the Shaders, Texture packs and Resource packs tabs had as
parent the ModFolderPage, making it so that making changes only to the
Mods page would require checking the id of the page for the correct one.
This was hackish and error-prone.
Now, those pages all inherit from a single class, ExternalResourcesPage,
that handles the basic behaviour of all of them, while allowing for
individual modification in code.
This is still not a clear separation, since internally, all those
resources are derived from Mods, so for now there's still some awkward
common code :/
2022-03-11 21:03:21 +00:00
|
|
|
connect(ui->filterEdit, &QLineEdit::textChanged, this, &ExternalResourcesPage::filterTextChanged);
|
2023-05-25 04:15:34 +01:00
|
|
|
|
|
|
|
auto viewHeader = ui->treeView->header();
|
|
|
|
viewHeader->setContextMenuPolicy(Qt::CustomContextMenu);
|
|
|
|
|
|
|
|
connect(viewHeader, &QHeaderView::customContextMenuRequested, this, &ExternalResourcesPage::ShowHeaderContextMenu);
|
|
|
|
|
|
|
|
m_model->loadHiddenColumns(ui->treeView);
|
refactor: Create a more clear hierarchy for some instance pages
Previously, the Shaders, Texture packs and Resource packs tabs had as
parent the ModFolderPage, making it so that making changes only to the
Mods page would require checking the id of the page for the correct one.
This was hackish and error-prone.
Now, those pages all inherit from a single class, ExternalResourcesPage,
that handles the basic behaviour of all of them, while allowing for
individual modification in code.
This is still not a clear separation, since internally, all those
resources are derived from Mods, so for now there's still some awkward
common code :/
2022-03-11 21:03:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ExternalResourcesPage::~ExternalResourcesPage()
|
|
|
|
{
|
|
|
|
delete ui;
|
|
|
|
}
|
|
|
|
|
|
|
|
QMenu* ExternalResourcesPage::createPopupMenu()
|
|
|
|
{
|
|
|
|
QMenu* filteredMenu = QMainWindow::createPopupMenu();
|
|
|
|
filteredMenu->removeAction(ui->actionsToolbar->toggleViewAction());
|
|
|
|
return filteredMenu;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExternalResourcesPage::ShowContextMenu(const QPoint& pos)
|
|
|
|
{
|
|
|
|
auto menu = ui->actionsToolbar->createContextMenu(this, tr("Context menu"));
|
|
|
|
menu->exec(ui->treeView->mapToGlobal(pos));
|
|
|
|
delete menu;
|
|
|
|
}
|
|
|
|
|
2023-05-25 04:15:34 +01:00
|
|
|
void ExternalResourcesPage::ShowHeaderContextMenu(const QPoint& pos)
|
|
|
|
{
|
2023-05-28 22:53:15 +01:00
|
|
|
auto menu = m_model->createHeaderContextMenu(ui->treeView);
|
2023-05-25 04:15:34 +01:00
|
|
|
menu->exec(ui->treeView->mapToGlobal(pos));
|
2023-05-28 22:53:15 +01:00
|
|
|
menu->deleteLater();
|
2023-05-25 04:15:34 +01:00
|
|
|
}
|
|
|
|
|
refactor: Create a more clear hierarchy for some instance pages
Previously, the Shaders, Texture packs and Resource packs tabs had as
parent the ModFolderPage, making it so that making changes only to the
Mods page would require checking the id of the page for the correct one.
This was hackish and error-prone.
Now, those pages all inherit from a single class, ExternalResourcesPage,
that handles the basic behaviour of all of them, while allowing for
individual modification in code.
This is still not a clear separation, since internally, all those
resources are derived from Mods, so for now there's still some awkward
common code :/
2022-03-11 21:03:21 +00:00
|
|
|
void ExternalResourcesPage::openedImpl()
|
|
|
|
{
|
|
|
|
m_model->startWatching();
|
2022-11-19 20:12:31 +00:00
|
|
|
|
|
|
|
auto const setting_name = QString("WideBarVisibility_%1").arg(id());
|
|
|
|
if (!APPLICATION->settings()->contains(setting_name))
|
|
|
|
m_wide_bar_setting = APPLICATION->settings()->registerSetting(setting_name);
|
|
|
|
else
|
|
|
|
m_wide_bar_setting = APPLICATION->settings()->getSetting(setting_name);
|
|
|
|
|
|
|
|
ui->actionsToolbar->setVisibilityState(m_wide_bar_setting->get().toByteArray());
|
refactor: Create a more clear hierarchy for some instance pages
Previously, the Shaders, Texture packs and Resource packs tabs had as
parent the ModFolderPage, making it so that making changes only to the
Mods page would require checking the id of the page for the correct one.
This was hackish and error-prone.
Now, those pages all inherit from a single class, ExternalResourcesPage,
that handles the basic behaviour of all of them, while allowing for
individual modification in code.
This is still not a clear separation, since internally, all those
resources are derived from Mods, so for now there's still some awkward
common code :/
2022-03-11 21:03:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExternalResourcesPage::closedImpl()
|
|
|
|
{
|
|
|
|
m_model->stopWatching();
|
2022-11-19 20:12:31 +00:00
|
|
|
|
|
|
|
m_wide_bar_setting->set(ui->actionsToolbar->getVisibilityState());
|
refactor: Create a more clear hierarchy for some instance pages
Previously, the Shaders, Texture packs and Resource packs tabs had as
parent the ModFolderPage, making it so that making changes only to the
Mods page would require checking the id of the page for the correct one.
This was hackish and error-prone.
Now, those pages all inherit from a single class, ExternalResourcesPage,
that handles the basic behaviour of all of them, while allowing for
individual modification in code.
This is still not a clear separation, since internally, all those
resources are derived from Mods, so for now there's still some awkward
common code :/
2022-03-11 21:03:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ExternalResourcesPage::retranslate()
|
|
|
|
{
|
|
|
|
ui->retranslateUi(this);
|
|
|
|
}
|
|
|
|
|
2022-08-13 15:58:39 +01:00
|
|
|
void ExternalResourcesPage::itemActivated(const QModelIndex&)
|
|
|
|
{
|
|
|
|
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection());
|
2023-08-21 13:55:28 +01:00
|
|
|
m_model->setResourceEnabled(selection.indexes(), EnableAction::TOGGLE);
|
2022-08-13 15:58:39 +01:00
|
|
|
}
|
|
|
|
|
refactor: Create a more clear hierarchy for some instance pages
Previously, the Shaders, Texture packs and Resource packs tabs had as
parent the ModFolderPage, making it so that making changes only to the
Mods page would require checking the id of the page for the correct one.
This was hackish and error-prone.
Now, those pages all inherit from a single class, ExternalResourcesPage,
that handles the basic behaviour of all of them, while allowing for
individual modification in code.
This is still not a clear separation, since internally, all those
resources are derived from Mods, so for now there's still some awkward
common code :/
2022-03-11 21:03:21 +00:00
|
|
|
void ExternalResourcesPage::filterTextChanged(const QString& newContents)
|
|
|
|
{
|
|
|
|
m_viewFilter = newContents;
|
2022-07-24 03:50:56 +01:00
|
|
|
m_filterModel->setFilterRegularExpression(m_viewFilter);
|
refactor: Create a more clear hierarchy for some instance pages
Previously, the Shaders, Texture packs and Resource packs tabs had as
parent the ModFolderPage, making it so that making changes only to the
Mods page would require checking the id of the page for the correct one.
This was hackish and error-prone.
Now, those pages all inherit from a single class, ExternalResourcesPage,
that handles the basic behaviour of all of them, while allowing for
individual modification in code.
This is still not a clear separation, since internally, all those
resources are derived from Mods, so for now there's still some awkward
common code :/
2022-03-11 21:03:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ExternalResourcesPage::shouldDisplay() const
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ExternalResourcesPage::listFilter(QKeyEvent* keyEvent)
|
|
|
|
{
|
|
|
|
switch (keyEvent->key()) {
|
|
|
|
case Qt::Key_Delete:
|
|
|
|
removeItem();
|
|
|
|
return true;
|
|
|
|
case Qt::Key_Plus:
|
|
|
|
addItem();
|
|
|
|
return true;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return QWidget::eventFilter(ui->treeView, keyEvent);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ExternalResourcesPage::eventFilter(QObject* obj, QEvent* ev)
|
|
|
|
{
|
|
|
|
if (ev->type() != QEvent::KeyPress)
|
|
|
|
return QWidget::eventFilter(obj, ev);
|
2022-12-14 15:02:04 +00:00
|
|
|
|
refactor: Create a more clear hierarchy for some instance pages
Previously, the Shaders, Texture packs and Resource packs tabs had as
parent the ModFolderPage, making it so that making changes only to the
Mods page would require checking the id of the page for the correct one.
This was hackish and error-prone.
Now, those pages all inherit from a single class, ExternalResourcesPage,
that handles the basic behaviour of all of them, while allowing for
individual modification in code.
This is still not a clear separation, since internally, all those
resources are derived from Mods, so for now there's still some awkward
common code :/
2022-03-11 21:03:21 +00:00
|
|
|
QKeyEvent* keyEvent = static_cast<QKeyEvent*>(ev);
|
|
|
|
if (obj == ui->treeView)
|
|
|
|
return listFilter(keyEvent);
|
|
|
|
|
|
|
|
return QWidget::eventFilter(obj, ev);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExternalResourcesPage::addItem()
|
|
|
|
{
|
|
|
|
auto list = GuiUtil::BrowseForFiles(
|
|
|
|
helpPage(), tr("Select %1", "Select whatever type of files the page contains. Example: 'Loader Mods'").arg(displayName()),
|
|
|
|
m_fileSelectionFilter.arg(displayName()), APPLICATION->settings()->get("CentralModsDir").toString(), this->parentWidget());
|
|
|
|
|
|
|
|
if (!list.isEmpty()) {
|
|
|
|
for (auto filename : list) {
|
2022-08-10 18:48:34 +01:00
|
|
|
m_model->installResource(filename);
|
refactor: Create a more clear hierarchy for some instance pages
Previously, the Shaders, Texture packs and Resource packs tabs had as
parent the ModFolderPage, making it so that making changes only to the
Mods page would require checking the id of the page for the correct one.
This was hackish and error-prone.
Now, those pages all inherit from a single class, ExternalResourcesPage,
that handles the basic behaviour of all of them, while allowing for
individual modification in code.
This is still not a clear separation, since internally, all those
resources are derived from Mods, so for now there's still some awkward
common code :/
2022-03-11 21:03:21 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExternalResourcesPage::removeItem()
|
|
|
|
{
|
|
|
|
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection());
|
2022-12-14 15:02:04 +00:00
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
bool folder = false;
|
2022-12-17 09:26:06 +00:00
|
|
|
for (auto& i : selection.indexes()) {
|
2022-12-14 15:02:04 +00:00
|
|
|
if (i.column() == 0) {
|
|
|
|
count++;
|
|
|
|
|
|
|
|
// if a folder is selected, show the confirmation dialog
|
|
|
|
if (m_model->at(i.row()).fileinfo().isDir())
|
|
|
|
folder = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-17 09:26:06 +00:00
|
|
|
QString text;
|
|
|
|
bool multiple = count > 1;
|
|
|
|
|
|
|
|
if (multiple) {
|
2022-12-26 14:33:50 +00:00
|
|
|
text = tr("You are about to remove %1 items.\n"
|
2022-12-17 09:26:06 +00:00
|
|
|
"This may be permanent and they will be gone from the folder.\n\n"
|
|
|
|
"Are you sure?")
|
|
|
|
.arg(count);
|
|
|
|
} else if (folder) {
|
2022-12-26 14:33:50 +00:00
|
|
|
text = tr("You are about to remove the folder \"%1\".\n"
|
2022-12-17 09:26:06 +00:00
|
|
|
"This may be permanent and it will be gone from the parent folder.\n\n"
|
|
|
|
"Are you sure?")
|
|
|
|
.arg(m_model->at(selection.indexes().at(0).row()).fileinfo().fileName());
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!text.isEmpty()) {
|
|
|
|
auto response = CustomMessageBox::selectable(this, tr("Confirm Removal"), text, QMessageBox::Warning,
|
|
|
|
QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
|
2022-12-14 15:02:04 +00:00
|
|
|
->exec();
|
|
|
|
|
|
|
|
if (response != QMessageBox::Yes)
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
removeItems(selection);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExternalResourcesPage::removeItems(const QItemSelection& selection)
|
|
|
|
{
|
2023-06-28 16:28:25 +01:00
|
|
|
if (m_instance != nullptr && m_instance->isRunning()) {
|
|
|
|
auto response = CustomMessageBox::selectable(this, "Confirm Delete",
|
|
|
|
"If you remove this resource while the game is running it may crash your game.\n"
|
|
|
|
"Are you sure you want to do this?",
|
|
|
|
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
|
|
|
|
->exec();
|
|
|
|
|
|
|
|
if (response != QMessageBox::Yes)
|
|
|
|
return;
|
|
|
|
}
|
2022-08-10 18:48:34 +01:00
|
|
|
m_model->deleteResources(selection.indexes());
|
refactor: Create a more clear hierarchy for some instance pages
Previously, the Shaders, Texture packs and Resource packs tabs had as
parent the ModFolderPage, making it so that making changes only to the
Mods page would require checking the id of the page for the correct one.
This was hackish and error-prone.
Now, those pages all inherit from a single class, ExternalResourcesPage,
that handles the basic behaviour of all of them, while allowing for
individual modification in code.
This is still not a clear separation, since internally, all those
resources are derived from Mods, so for now there's still some awkward
common code :/
2022-03-11 21:03:21 +00:00
|
|
|
}
|
|
|
|
|
2022-08-13 15:58:39 +01:00
|
|
|
void ExternalResourcesPage::enableItem()
|
|
|
|
{
|
|
|
|
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection());
|
|
|
|
m_model->setResourceEnabled(selection.indexes(), EnableAction::ENABLE);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExternalResourcesPage::disableItem()
|
|
|
|
{
|
2023-06-28 16:28:25 +01:00
|
|
|
if (m_instance != nullptr && m_instance->isRunning()) {
|
|
|
|
auto response = CustomMessageBox::selectable(this, "Confirm disable",
|
|
|
|
"If you disable this resource while the game is running it may crash your game.\n"
|
|
|
|
"Are you sure you want to do this?",
|
|
|
|
QMessageBox::Warning, QMessageBox::Yes | QMessageBox::No, QMessageBox::No)
|
|
|
|
->exec();
|
2022-08-13 15:58:39 +01:00
|
|
|
|
2023-06-28 16:28:25 +01:00
|
|
|
if (response != QMessageBox::Yes)
|
|
|
|
return;
|
|
|
|
}
|
2022-08-13 15:58:39 +01:00
|
|
|
auto selection = m_filterModel->mapSelectionToSource(ui->treeView->selectionModel()->selection());
|
|
|
|
m_model->setResourceEnabled(selection.indexes(), EnableAction::DISABLE);
|
|
|
|
}
|
|
|
|
|
refactor: Create a more clear hierarchy for some instance pages
Previously, the Shaders, Texture packs and Resource packs tabs had as
parent the ModFolderPage, making it so that making changes only to the
Mods page would require checking the id of the page for the correct one.
This was hackish and error-prone.
Now, those pages all inherit from a single class, ExternalResourcesPage,
that handles the basic behaviour of all of them, while allowing for
individual modification in code.
This is still not a clear separation, since internally, all those
resources are derived from Mods, so for now there's still some awkward
common code :/
2022-03-11 21:03:21 +00:00
|
|
|
void ExternalResourcesPage::viewConfigs()
|
|
|
|
{
|
|
|
|
DesktopServices::openDirectory(m_instance->instanceConfigFolder(), true);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExternalResourcesPage::viewFolder()
|
|
|
|
{
|
|
|
|
DesktopServices::openDirectory(m_model->dir().absolutePath(), true);
|
|
|
|
}
|
|
|
|
|
2022-08-10 18:48:34 +01:00
|
|
|
bool ExternalResourcesPage::current(const QModelIndex& current, const QModelIndex& previous)
|
refactor: Create a more clear hierarchy for some instance pages
Previously, the Shaders, Texture packs and Resource packs tabs had as
parent the ModFolderPage, making it so that making changes only to the
Mods page would require checking the id of the page for the correct one.
This was hackish and error-prone.
Now, those pages all inherit from a single class, ExternalResourcesPage,
that handles the basic behaviour of all of them, while allowing for
individual modification in code.
This is still not a clear separation, since internally, all those
resources are derived from Mods, so for now there's still some awkward
common code :/
2022-03-11 21:03:21 +00:00
|
|
|
{
|
|
|
|
if (!current.isValid()) {
|
|
|
|
ui->frame->clear();
|
2022-08-10 18:48:34 +01:00
|
|
|
return false;
|
refactor: Create a more clear hierarchy for some instance pages
Previously, the Shaders, Texture packs and Resource packs tabs had as
parent the ModFolderPage, making it so that making changes only to the
Mods page would require checking the id of the page for the correct one.
This was hackish and error-prone.
Now, those pages all inherit from a single class, ExternalResourcesPage,
that handles the basic behaviour of all of them, while allowing for
individual modification in code.
This is still not a clear separation, since internally, all those
resources are derived from Mods, so for now there's still some awkward
common code :/
2022-03-11 21:03:21 +00:00
|
|
|
}
|
|
|
|
|
2022-08-10 18:48:34 +01:00
|
|
|
return onSelectionChanged(current, previous);
|
|
|
|
}
|
|
|
|
|
2023-07-01 07:51:15 +01:00
|
|
|
bool ExternalResourcesPage::onSelectionChanged(const QModelIndex& current, [[maybe_unused]] const QModelIndex& previous)
|
2022-08-10 18:48:34 +01:00
|
|
|
{
|
refactor: Create a more clear hierarchy for some instance pages
Previously, the Shaders, Texture packs and Resource packs tabs had as
parent the ModFolderPage, making it so that making changes only to the
Mods page would require checking the id of the page for the correct one.
This was hackish and error-prone.
Now, those pages all inherit from a single class, ExternalResourcesPage,
that handles the basic behaviour of all of them, while allowing for
individual modification in code.
This is still not a clear separation, since internally, all those
resources are derived from Mods, so for now there's still some awkward
common code :/
2022-03-11 21:03:21 +00:00
|
|
|
auto sourceCurrent = m_filterModel->mapToSource(current);
|
|
|
|
int row = sourceCurrent.row();
|
2022-08-10 18:48:34 +01:00
|
|
|
Resource const& resource = m_model->at(row);
|
|
|
|
ui->frame->updateWithResource(resource);
|
|
|
|
return true;
|
refactor: Create a more clear hierarchy for some instance pages
Previously, the Shaders, Texture packs and Resource packs tabs had as
parent the ModFolderPage, making it so that making changes only to the
Mods page would require checking the id of the page for the correct one.
This was hackish and error-prone.
Now, those pages all inherit from a single class, ExternalResourcesPage,
that handles the basic behaviour of all of them, while allowing for
individual modification in code.
This is still not a clear separation, since internally, all those
resources are derived from Mods, so for now there's still some awkward
common code :/
2022-03-11 21:03:21 +00:00
|
|
|
}
|
2023-06-06 22:16:23 +01:00
|
|
|
|
|
|
|
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)
|
2023-06-15 10:32:48 +01:00
|
|
|
return tr(" (%1 installed, %2 selected)").arg(m_model->size()).arg(count);
|
2023-06-06 22:16:23 +01:00
|
|
|
}
|
2023-06-15 10:32:48 +01:00
|
|
|
return tr(" (%1 installed)").arg(m_model->size());
|
2023-06-06 22:16:23 +01:00
|
|
|
}
|