Added ExportModsToStringDialog
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
9d2516a199
commit
f7d502c68c
@ -911,6 +911,8 @@ SET(LAUNCHER_SOURCES
|
|||||||
ui/dialogs/ExportInstanceDialog.h
|
ui/dialogs/ExportInstanceDialog.h
|
||||||
ui/dialogs/ExportMrPackDialog.cpp
|
ui/dialogs/ExportMrPackDialog.cpp
|
||||||
ui/dialogs/ExportMrPackDialog.h
|
ui/dialogs/ExportMrPackDialog.h
|
||||||
|
ui/dialogs/ExportModsToStringDialog.cpp
|
||||||
|
ui/dialogs/ExportModsToStringDialog.h
|
||||||
ui/dialogs/IconPickerDialog.cpp
|
ui/dialogs/IconPickerDialog.cpp
|
||||||
ui/dialogs/IconPickerDialog.h
|
ui/dialogs/IconPickerDialog.h
|
||||||
ui/dialogs/ImportResourceDialog.cpp
|
ui/dialogs/ImportResourceDialog.cpp
|
||||||
@ -1058,6 +1060,7 @@ qt_wrap_ui(LAUNCHER_UI
|
|||||||
ui/dialogs/SkinUploadDialog.ui
|
ui/dialogs/SkinUploadDialog.ui
|
||||||
ui/dialogs/ExportInstanceDialog.ui
|
ui/dialogs/ExportInstanceDialog.ui
|
||||||
ui/dialogs/ExportMrPackDialog.ui
|
ui/dialogs/ExportMrPackDialog.ui
|
||||||
|
ui/dialogs/ExportModsToStringDialog.ui
|
||||||
ui/dialogs/IconPickerDialog.ui
|
ui/dialogs/IconPickerDialog.ui
|
||||||
ui/dialogs/ImportResourceDialog.ui
|
ui/dialogs/ImportResourceDialog.ui
|
||||||
ui/dialogs/MSALoginDialog.ui
|
ui/dialogs/MSALoginDialog.ui
|
||||||
|
@ -43,6 +43,7 @@
|
|||||||
#include "FileSystem.h"
|
#include "FileSystem.h"
|
||||||
|
|
||||||
#include "MainWindow.h"
|
#include "MainWindow.h"
|
||||||
|
#include "ui/dialogs/ExportModsToStringDialog.h"
|
||||||
#include "ui_MainWindow.h"
|
#include "ui_MainWindow.h"
|
||||||
|
|
||||||
#include <QVariant>
|
#include <QVariant>
|
||||||
@ -205,6 +206,7 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi
|
|||||||
auto exportInstanceMenu = new QMenu(this);
|
auto exportInstanceMenu = new QMenu(this);
|
||||||
exportInstanceMenu->addAction(ui->actionExportInstanceZip);
|
exportInstanceMenu->addAction(ui->actionExportInstanceZip);
|
||||||
exportInstanceMenu->addAction(ui->actionExportInstanceMrPack);
|
exportInstanceMenu->addAction(ui->actionExportInstanceMrPack);
|
||||||
|
exportInstanceMenu->addAction(ui->actionExportInstanceToString);
|
||||||
ui->actionExportInstance->setMenu(exportInstanceMenu);
|
ui->actionExportInstance->setMenu(exportInstanceMenu);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1416,6 +1418,14 @@ void MainWindow::on_actionExportInstanceMrPack_triggered()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MainWindow::on_actionExportInstanceToString_triggered()
|
||||||
|
{
|
||||||
|
if (m_selectedInstance) {
|
||||||
|
ExportModsToStringDialog dlg(m_selectedInstance, this);
|
||||||
|
dlg.exec();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MainWindow::on_actionRenameInstance_triggered()
|
void MainWindow::on_actionRenameInstance_triggered()
|
||||||
{
|
{
|
||||||
if (m_selectedInstance)
|
if (m_selectedInstance)
|
||||||
|
@ -157,6 +157,7 @@ private slots:
|
|||||||
inline void on_actionExportInstance_triggered() { on_actionExportInstanceZip_triggered(); }
|
inline void on_actionExportInstance_triggered() { on_actionExportInstanceZip_triggered(); }
|
||||||
void on_actionExportInstanceZip_triggered();
|
void on_actionExportInstanceZip_triggered();
|
||||||
void on_actionExportInstanceMrPack_triggered();
|
void on_actionExportInstanceMrPack_triggered();
|
||||||
|
void on_actionExportInstanceToString_triggered();
|
||||||
|
|
||||||
void on_actionRenameInstance_triggered();
|
void on_actionRenameInstance_triggered();
|
||||||
|
|
||||||
|
@ -479,6 +479,14 @@
|
|||||||
<string>Modrinth (mrpack)</string>
|
<string>Modrinth (mrpack)</string>
|
||||||
</property>
|
</property>
|
||||||
</action>
|
</action>
|
||||||
|
<action name="actionExportInstanceToString">
|
||||||
|
<property name="icon">
|
||||||
|
<iconset theme="new"/>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Text</string>
|
||||||
|
</property>
|
||||||
|
</action>
|
||||||
<action name="actionCreateInstanceShortcut">
|
<action name="actionCreateInstanceShortcut">
|
||||||
<property name="icon">
|
<property name="icon">
|
||||||
<iconset theme="shortcut">
|
<iconset theme="shortcut">
|
||||||
|
119
launcher/ui/dialogs/ExportModsToStringDialog.cpp
Normal file
119
launcher/ui/dialogs/ExportModsToStringDialog.cpp
Normal file
@ -0,0 +1,119 @@
|
|||||||
|
// 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include "ExportModsToStringDialog.h"
|
||||||
|
#include <QCheckBox>
|
||||||
|
#include <QComboBox>
|
||||||
|
#include <QTextEdit>
|
||||||
|
#include "minecraft/MinecraftInstance.h"
|
||||||
|
#include "minecraft/mod/ModFolderModel.h"
|
||||||
|
#include "modplatform/helpers/ExportModsToStringTask.h"
|
||||||
|
#include "ui_ExportModsToStringDialog.h"
|
||||||
|
|
||||||
|
#include <QFileDialog>
|
||||||
|
#include <QFileSystemModel>
|
||||||
|
#include <QJsonDocument>
|
||||||
|
#include <QMessageBox>
|
||||||
|
#include <QPushButton>
|
||||||
|
|
||||||
|
ExportModsToStringDialog::ExportModsToStringDialog(InstancePtr instance, QWidget* parent)
|
||||||
|
: QDialog(parent), m_template_selected(false), ui(new Ui::ExportModsToStringDialog)
|
||||||
|
{
|
||||||
|
ui->setupUi(this);
|
||||||
|
ui->templateGroup->setDisabled(true);
|
||||||
|
|
||||||
|
MinecraftInstance* mcInstance = dynamic_cast<MinecraftInstance*>(instance.get());
|
||||||
|
if (mcInstance) {
|
||||||
|
mcInstance->loaderModList()->update();
|
||||||
|
connect(mcInstance->loaderModList().get(), &ModFolderModel::updateFinished, this, [this, mcInstance]() {
|
||||||
|
m_allMods = mcInstance->loaderModList()->allMods();
|
||||||
|
trigger();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
connect(ui->formatComboBox, &QComboBox::currentIndexChanged, this, &ExportModsToStringDialog::formatChanged);
|
||||||
|
connect(ui->authorsCheckBox, &QCheckBox::stateChanged, this, &ExportModsToStringDialog::trigger);
|
||||||
|
connect(ui->versionCheckBox, &QCheckBox::stateChanged, this, &ExportModsToStringDialog::trigger);
|
||||||
|
connect(ui->urlCheckBox, &QCheckBox::stateChanged, this, &ExportModsToStringDialog::trigger);
|
||||||
|
connect(ui->templateText, &QTextEdit::textChanged, this, &ExportModsToStringDialog::trigger);
|
||||||
|
connect(ui->copyButton, &QPushButton::clicked, this, [this]() {
|
||||||
|
this->ui->finalText->selectAll();
|
||||||
|
this->ui->finalText->copy();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
ExportModsToStringDialog::~ExportModsToStringDialog()
|
||||||
|
{
|
||||||
|
delete ui;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExportModsToStringDialog::formatChanged(int index)
|
||||||
|
{
|
||||||
|
switch (index) {
|
||||||
|
case 0: {
|
||||||
|
ui->templateGroup->setDisabled(true);
|
||||||
|
ui->optionsGroup->setDisabled(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 1: {
|
||||||
|
ui->templateGroup->setDisabled(true);
|
||||||
|
ui->optionsGroup->setDisabled(false);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 2: {
|
||||||
|
ui->templateGroup->setDisabled(false);
|
||||||
|
ui->optionsGroup->setDisabled(true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
trigger();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ExportModsToStringDialog::trigger()
|
||||||
|
{
|
||||||
|
ExportToString::Formats format;
|
||||||
|
switch (ui->formatComboBox->currentIndex()) {
|
||||||
|
case 2: {
|
||||||
|
m_template_selected = true;
|
||||||
|
ui->finalText->setPlainText(ExportToString::ExportModsToStringTask(m_allMods, ui->templateText->toPlainText()));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
case 0: {
|
||||||
|
format = ExportToString::HTML;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case 1: {
|
||||||
|
format = ExportToString::MARKDOWN;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
auto opt = 0;
|
||||||
|
if (ui->authorsCheckBox->isChecked())
|
||||||
|
opt |= ExportToString::Authors;
|
||||||
|
if (ui->versionCheckBox->isChecked())
|
||||||
|
opt |= ExportToString::Version;
|
||||||
|
if (ui->urlCheckBox->isChecked())
|
||||||
|
opt |= ExportToString::Url;
|
||||||
|
ui->finalText->setPlainText(ExportToString::ExportModsToStringTask(m_allMods, format, static_cast<ExportToString::OptionalData>(opt)));
|
||||||
|
if (!m_template_selected) {
|
||||||
|
auto exampleLine = format == ExportToString::HTML ? "<ul><a href=\"{url}\">{name}</a>[{version}] by {authors}</ul>"
|
||||||
|
: "[{name}]({url})[{version}] by {authors}";
|
||||||
|
if (ui->templateText->toPlainText() != exampleLine)
|
||||||
|
ui->templateText->setPlainText(exampleLine);
|
||||||
|
}
|
||||||
|
}
|
45
launcher/ui/dialogs/ExportModsToStringDialog.h
Normal file
45
launcher/ui/dialogs/ExportModsToStringDialog.h
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
// 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/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <QDialog>
|
||||||
|
#include <QList>
|
||||||
|
#include "BaseInstance.h"
|
||||||
|
#include "minecraft/mod/Mod.h"
|
||||||
|
|
||||||
|
namespace Ui {
|
||||||
|
class ExportModsToStringDialog;
|
||||||
|
}
|
||||||
|
|
||||||
|
class ExportModsToStringDialog : public QDialog {
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
explicit ExportModsToStringDialog(InstancePtr instance, QWidget* parent = nullptr);
|
||||||
|
~ExportModsToStringDialog();
|
||||||
|
|
||||||
|
protected slots:
|
||||||
|
void formatChanged(int index);
|
||||||
|
void trigger();
|
||||||
|
|
||||||
|
private:
|
||||||
|
QList<Mod*> m_allMods;
|
||||||
|
bool m_template_selected;
|
||||||
|
Ui::ExportModsToStringDialog* ui;
|
||||||
|
};
|
171
launcher/ui/dialogs/ExportModsToStringDialog.ui
Normal file
171
launcher/ui/dialogs/ExportModsToStringDialog.ui
Normal file
@ -0,0 +1,171 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<ui version="4.0">
|
||||||
|
<class>ExportModsToStringDialog</class>
|
||||||
|
<widget class="QDialog" name="ExportModsToStringDialog">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>650</width>
|
||||||
|
<height>446</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="windowTitle">
|
||||||
|
<string>Export Modrinth Pack</string>
|
||||||
|
</property>
|
||||||
|
<property name="sizeGripEnabled">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
|
<item>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0">
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="groupBox_3">
|
||||||
|
<property name="title">
|
||||||
|
<string>Settings</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QGridLayout" name="gridLayout">
|
||||||
|
<item row="0" column="0">
|
||||||
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="frameShape">
|
||||||
|
<enum>QFrame::NoFrame</enum>
|
||||||
|
</property>
|
||||||
|
<property name="frameShadow">
|
||||||
|
<enum>QFrame::Plain</enum>
|
||||||
|
</property>
|
||||||
|
<property name="lineWidth">
|
||||||
|
<number>1</number>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Format</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="0" column="1">
|
||||||
|
<widget class="QComboBox" name="formatComboBox">
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>HTML</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Markdown</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<property name="text">
|
||||||
|
<string>Custom</string>
|
||||||
|
</property>
|
||||||
|
</item>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QGroupBox" name="templateGroup">
|
||||||
|
<property name="title">
|
||||||
|
<string>Template</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||||
|
<item>
|
||||||
|
<widget class="QTextEdit" name="templateText"/>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="1">
|
||||||
|
<widget class="QGroupBox" name="optionsGroup">
|
||||||
|
<property name="title">
|
||||||
|
<string>Optional Info</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QVBoxLayout" name="verticalLayout_5">
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="versionCheckBox">
|
||||||
|
<property name="text">
|
||||||
|
<string>Version</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="authorsCheckBox">
|
||||||
|
<property name="text">
|
||||||
|
<string>Authors</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="urlCheckBox">
|
||||||
|
<property name="text">
|
||||||
|
<string>URL</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QGroupBox" name="groupBox_4">
|
||||||
|
<property name="title">
|
||||||
|
<string>Result</string>
|
||||||
|
</property>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<widget class="QPlainTextEdit" name="finalText">
|
||||||
|
<property name="minimumSize">
|
||||||
|
<size>
|
||||||
|
<width>0</width>
|
||||||
|
<height>143</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
<property name="readOnly">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_2">
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="copyButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>Copy</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QDialogButtonBox" name="buttonBox">
|
||||||
|
<property name="standardButtons">
|
||||||
|
<set>QDialogButtonBox::Ok</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</widget>
|
||||||
|
<resources/>
|
||||||
|
<connections>
|
||||||
|
<connection>
|
||||||
|
<sender>buttonBox</sender>
|
||||||
|
<signal>accepted()</signal>
|
||||||
|
<receiver>ExportModsToStringDialog</receiver>
|
||||||
|
<slot>accept()</slot>
|
||||||
|
<hints>
|
||||||
|
<hint type="sourcelabel">
|
||||||
|
<x>334</x>
|
||||||
|
<y>435</y>
|
||||||
|
</hint>
|
||||||
|
<hint type="destinationlabel">
|
||||||
|
<x>324</x>
|
||||||
|
<y>206</y>
|
||||||
|
</hint>
|
||||||
|
</hints>
|
||||||
|
</connection>
|
||||||
|
</connections>
|
||||||
|
</ui>
|
Loading…
Reference in New Issue
Block a user