From 8d3f13c4478f7e99a32a0804d57ac2ece05d7e92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Mon, 14 Sep 2015 23:49:32 +0200 Subject: GH-1227 add world copy and rename --- application/pages/WorldListPage.cpp | 43 ++++++++++++++++++++++++++++++++++++- application/pages/WorldListPage.h | 2 ++ application/pages/WorldListPage.ui | 16 ++++++++++++++ 3 files changed, 60 insertions(+), 1 deletion(-) (limited to 'application') diff --git a/application/pages/WorldListPage.cpp b/application/pages/WorldListPage.cpp index 30981978..3b531d5d 100644 --- a/application/pages/WorldListPage.cpp +++ b/application/pages/WorldListPage.cpp @@ -22,6 +22,7 @@ #include #include #include +#include #include "MultiMC.h" @@ -35,6 +36,7 @@ WorldListPage::WorldListPage(BaseInstance *inst, std::shared_ptr worl ui->setupUi(this); ui->tabWidget->tabBar()->hide(); QSortFilterProxyModel * proxy = new QSortFilterProxyModel(this); + proxy->setSortCaseSensitivity(Qt::CaseInsensitive); proxy->setSourceModel(m_worlds.get()); ui->worldTreeView->setSortingEnabled(true); ui->worldTreeView->setModel(proxy); @@ -207,6 +209,8 @@ void WorldListPage::worldChanged(const QModelIndex ¤t, const QModelIndex & ui->copySeedBtn->setEnabled(enable); ui->mcEditBtn->setEnabled(enable); ui->rmWorldBtn->setEnabled(enable); + ui->copyBtn->setEnabled(enable); + ui->renameBtn->setEnabled(enable); } void WorldListPage::on_addBtn_clicked() @@ -224,4 +228,41 @@ void WorldListPage::on_addBtn_clicked() } m_worlds->startWatching(); } -} \ No newline at end of file +} + +void WorldListPage::on_copyBtn_clicked() +{ + QModelIndex index = getSelectedWorld(); + if (!index.isValid()) + { + return; + } + auto worldVariant = m_worlds->data(index, WorldList::ObjectRole); + auto world = (World *) worldVariant.value(); + bool ok = false; + QString name = QInputDialog::getText(this, tr("World name"), tr("Enter a new name for the copy."), QLineEdit::Normal, world->name(), &ok); + + if (ok && name.length() > 0) + { + world->install(m_worlds->dir().absolutePath(), name); + } +} + +void WorldListPage::on_renameBtn_clicked() +{ + QModelIndex index = getSelectedWorld(); + if (!index.isValid()) + { + return; + } + auto worldVariant = m_worlds->data(index, WorldList::ObjectRole); + auto world = (World *) worldVariant.value(); + + bool ok = false; + QString name = QInputDialog::getText(this, tr("World name"), tr("Enter a new world name."), QLineEdit::Normal, world->name(), &ok); + + if (ok && name.length() > 0) + { + world->rename(name); + } +} diff --git a/application/pages/WorldListPage.h b/application/pages/WorldListPage.h index f3111f93..f0b0e7e9 100644 --- a/application/pages/WorldListPage.h +++ b/application/pages/WorldListPage.h @@ -82,6 +82,8 @@ private slots: void on_mcEditBtn_clicked(); void on_rmWorldBtn_clicked(); void on_addBtn_clicked(); + void on_copyBtn_clicked(); + void on_renameBtn_clicked(); void on_viewFolderBtn_clicked(); void worldChanged(const QModelIndex ¤t, const QModelIndex &previous); }; diff --git a/application/pages/WorldListPage.ui b/application/pages/WorldListPage.ui index ecd9709f..b5fd33da 100644 --- a/application/pages/WorldListPage.ui +++ b/application/pages/WorldListPage.ui @@ -70,6 +70,20 @@ + + + + Copy + + + + + + + Rename + + + @@ -134,6 +148,8 @@ tabWidget worldTreeView addBtn + copyBtn + renameBtn rmWorldBtn mcEditBtn copySeedBtn -- cgit v1.2.3