Made custom template enabled all time
Signed-off-by: Trial97 <alexandru.tripon97@gmail.com>
This commit is contained in:
parent
9b02c31f8d
commit
1495bfb73e
@ -16,7 +16,7 @@
|
|||||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <qlist.h>
|
#include <QList>
|
||||||
#include <QString>
|
#include <QString>
|
||||||
#include "minecraft/mod/Mod.h"
|
#include "minecraft/mod/Mod.h"
|
||||||
|
|
||||||
|
@ -33,11 +33,19 @@
|
|||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
|
|
||||||
|
const QHash<ExportToModList::Formats, QString> ExportToModListDialog::exampleLines = {
|
||||||
|
{ ExportToModList::HTML, "<li><a href=\"{url}\">{name}</a> [{version}] by {authors}</li>" },
|
||||||
|
{ ExportToModList::MARKDOWN, "[{name}]({url}) [{version}] by {authors}" },
|
||||||
|
{ ExportToModList::PLAINTXT, "{name} ({url}) [{version}] by {authors}" },
|
||||||
|
{ ExportToModList::JSON, "{\"name\":\"{name}\",\"url\":\"{url}\",\"version\":\"{version}\",\"authors\":\"{authors}\"}," },
|
||||||
|
{ ExportToModList::CSV, "{name},{url},{version},\"{authors}\"" },
|
||||||
|
};
|
||||||
|
|
||||||
ExportToModListDialog::ExportToModListDialog(InstancePtr instance, QWidget* parent)
|
ExportToModListDialog::ExportToModListDialog(InstancePtr instance, QWidget* parent)
|
||||||
: QDialog(parent), m_template_selected(false), name(instance->name()), ui(new Ui::ExportToModListDialog)
|
: QDialog(parent), m_template_changed(false), name(instance->name()), ui(new Ui::ExportToModListDialog)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
ui->templateGroup->setDisabled(true);
|
ui->optionsGroup->setDisabled(false);
|
||||||
|
|
||||||
MinecraftInstance* mcInstance = dynamic_cast<MinecraftInstance*>(instance.get());
|
MinecraftInstance* mcInstance = dynamic_cast<MinecraftInstance*>(instance.get());
|
||||||
if (mcInstance) {
|
if (mcInstance) {
|
||||||
@ -52,7 +60,12 @@ ExportToModListDialog::ExportToModListDialog(InstancePtr instance, QWidget* pare
|
|||||||
connect(ui->authorsCheckBox, &QCheckBox::stateChanged, this, &ExportToModListDialog::trigger);
|
connect(ui->authorsCheckBox, &QCheckBox::stateChanged, this, &ExportToModListDialog::trigger);
|
||||||
connect(ui->versionCheckBox, &QCheckBox::stateChanged, this, &ExportToModListDialog::trigger);
|
connect(ui->versionCheckBox, &QCheckBox::stateChanged, this, &ExportToModListDialog::trigger);
|
||||||
connect(ui->urlCheckBox, &QCheckBox::stateChanged, this, &ExportToModListDialog::trigger);
|
connect(ui->urlCheckBox, &QCheckBox::stateChanged, this, &ExportToModListDialog::trigger);
|
||||||
connect(ui->templateText, &QTextEdit::textChanged, this, &ExportToModListDialog::triggerImp);
|
connect(ui->templateText, &QTextEdit::textChanged, this, [this] {
|
||||||
|
if (ui->templateText->toPlainText() != exampleLines[format])
|
||||||
|
ui->formatComboBox->setCurrentIndex(5);
|
||||||
|
else
|
||||||
|
triggerImp();
|
||||||
|
});
|
||||||
connect(ui->copyButton, &QPushButton::clicked, this, [this](bool) {
|
connect(ui->copyButton, &QPushButton::clicked, this, [this](bool) {
|
||||||
this->ui->finalText->selectAll();
|
this->ui->finalText->selectAll();
|
||||||
this->ui->finalText->copy();
|
this->ui->finalText->copy();
|
||||||
@ -68,42 +81,37 @@ void ExportToModListDialog::formatChanged(int index)
|
|||||||
{
|
{
|
||||||
switch (index) {
|
switch (index) {
|
||||||
case 0: {
|
case 0: {
|
||||||
ui->templateGroup->setDisabled(true);
|
|
||||||
ui->optionsGroup->setDisabled(false);
|
ui->optionsGroup->setDisabled(false);
|
||||||
ui->resultText->show();
|
ui->resultText->show();
|
||||||
format = ExportToModList::HTML;
|
format = ExportToModList::HTML;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 1: {
|
case 1: {
|
||||||
ui->templateGroup->setDisabled(true);
|
|
||||||
ui->optionsGroup->setDisabled(false);
|
ui->optionsGroup->setDisabled(false);
|
||||||
ui->resultText->show();
|
ui->resultText->show();
|
||||||
format = ExportToModList::MARKDOWN;
|
format = ExportToModList::MARKDOWN;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 2: {
|
case 2: {
|
||||||
ui->templateGroup->setDisabled(true);
|
|
||||||
ui->optionsGroup->setDisabled(false);
|
ui->optionsGroup->setDisabled(false);
|
||||||
ui->resultText->hide();
|
ui->resultText->hide();
|
||||||
format = ExportToModList::PLAINTXT;
|
format = ExportToModList::PLAINTXT;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 3: {
|
case 3: {
|
||||||
ui->templateGroup->setDisabled(true);
|
|
||||||
ui->optionsGroup->setDisabled(false);
|
ui->optionsGroup->setDisabled(false);
|
||||||
ui->resultText->hide();
|
ui->resultText->hide();
|
||||||
format = ExportToModList::JSON;
|
format = ExportToModList::JSON;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 4: {
|
case 4: {
|
||||||
ui->templateGroup->setDisabled(true);
|
|
||||||
ui->optionsGroup->setDisabled(false);
|
ui->optionsGroup->setDisabled(false);
|
||||||
ui->resultText->hide();
|
ui->resultText->hide();
|
||||||
format = ExportToModList::CSV;
|
format = ExportToModList::CSV;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case 5: {
|
case 5: {
|
||||||
ui->templateGroup->setDisabled(false);
|
m_template_changed = true;
|
||||||
ui->optionsGroup->setDisabled(true);
|
ui->optionsGroup->setDisabled(true);
|
||||||
ui->resultText->hide();
|
ui->resultText->hide();
|
||||||
format = ExportToModList::CUSTOM;
|
format = ExportToModList::CUSTOM;
|
||||||
@ -116,7 +124,6 @@ void ExportToModListDialog::formatChanged(int index)
|
|||||||
void ExportToModListDialog::triggerImp()
|
void ExportToModListDialog::triggerImp()
|
||||||
{
|
{
|
||||||
if (format == ExportToModList::CUSTOM) {
|
if (format == ExportToModList::CUSTOM) {
|
||||||
m_template_selected = true;
|
|
||||||
ui->finalText->setPlainText(ExportToModList::ExportToModList(m_allMods, ui->templateText->toPlainText()));
|
ui->finalText->setPlainText(ExportToModList::ExportToModList(m_allMods, ui->templateText->toPlainText()));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -129,35 +136,25 @@ void ExportToModListDialog::triggerImp()
|
|||||||
opt |= ExportToModList::Url;
|
opt |= ExportToModList::Url;
|
||||||
auto txt = ExportToModList::ExportToModList(m_allMods, format, static_cast<ExportToModList::OptionalData>(opt));
|
auto txt = ExportToModList::ExportToModList(m_allMods, format, static_cast<ExportToModList::OptionalData>(opt));
|
||||||
ui->finalText->setPlainText(txt);
|
ui->finalText->setPlainText(txt);
|
||||||
QString exampleLine;
|
|
||||||
switch (format) {
|
switch (format) {
|
||||||
case ExportToModList::HTML: {
|
|
||||||
exampleLine = "<li><a href=\"{url}\">{name}</a> [{version}] by {authors}</li>";
|
|
||||||
ui->resultText->setHtml(txt);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ExportToModList::MARKDOWN: {
|
|
||||||
exampleLine = "[{name}]({url}) [{version}] by {authors}";
|
|
||||||
ui->resultText->setHtml(markdownToHTML(txt));
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ExportToModList::PLAINTXT: {
|
|
||||||
exampleLine = "{name} ({url}) [{version}] by {authors}";
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case ExportToModList::CUSTOM:
|
case ExportToModList::CUSTOM:
|
||||||
return;
|
return;
|
||||||
|
case ExportToModList::HTML:
|
||||||
|
ui->resultText->setHtml(txt);
|
||||||
|
break;
|
||||||
|
case ExportToModList::MARKDOWN:
|
||||||
|
ui->resultText->setHtml(markdownToHTML(txt));
|
||||||
|
break;
|
||||||
|
case ExportToModList::PLAINTXT:
|
||||||
|
break;
|
||||||
case ExportToModList::JSON:
|
case ExportToModList::JSON:
|
||||||
exampleLine = "{\"name\":\"{name}\",\"url\":\"{url}\",\"version\":\"{version}\",\"authors\":\"{authors}\"},";
|
|
||||||
break;
|
break;
|
||||||
case ExportToModList::CSV:
|
case ExportToModList::CSV:
|
||||||
exampleLine = "{name},{url},{version},\"{authors}\"";
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (!m_template_selected) {
|
auto exampleLine = exampleLines[format];
|
||||||
if (ui->templateText->toPlainText() != exampleLine)
|
if (!m_template_changed && ui->templateText->toPlainText() != exampleLine)
|
||||||
ui->templateText->setPlainText(exampleLine);
|
ui->templateText->setPlainText(exampleLine);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ExportToModListDialog::done(int result)
|
void ExportToModListDialog::done(int result)
|
||||||
|
@ -45,8 +45,9 @@ class ExportToModListDialog : public QDialog {
|
|||||||
private:
|
private:
|
||||||
QString extension();
|
QString extension();
|
||||||
QList<Mod*> m_allMods;
|
QList<Mod*> m_allMods;
|
||||||
bool m_template_selected;
|
bool m_template_changed;
|
||||||
QString name;
|
QString name;
|
||||||
ExportToModList::Formats format = ExportToModList::Formats::HTML;
|
ExportToModList::Formats format = ExportToModList::Formats::HTML;
|
||||||
Ui::ExportToModListDialog* ui;
|
Ui::ExportToModListDialog* ui;
|
||||||
|
static const QHash<ExportToModList::Formats, QString> exampleLines;
|
||||||
};
|
};
|
||||||
|
@ -18,7 +18,7 @@
|
|||||||
</property>
|
</property>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||||
<item>
|
<item>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0">
|
<layout class="QVBoxLayout" name="verticalLayout" stretch="0,0,0">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QGroupBox" name="groupBox_3">
|
<widget class="QGroupBox" name="groupBox_3">
|
||||||
<property name="title">
|
<property name="title">
|
||||||
@ -149,6 +149,16 @@
|
|||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="warningLabel">
|
||||||
|
<property name="text">
|
||||||
|
<string>This depends on the mods meta data. To ensure the meta data run at least one time the mods update on the selected instance(no need to update the mods).</string>
|
||||||
|
</property>
|
||||||
|
<property name="wordWrap">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item>
|
<item>
|
||||||
|
Loading…
Reference in New Issue
Block a user