GH-1047 World management for instances. Removal only currently.
This commit is contained in:
		@@ -177,6 +177,8 @@ SET(MULTIMC_SOURCES
 | 
			
		||||
	pages/LegacyJarModPage.h
 | 
			
		||||
	pages/LegacyUpgradePage.cpp
 | 
			
		||||
	pages/LegacyUpgradePage.h
 | 
			
		||||
	pages/WorldListPage.cpp
 | 
			
		||||
	pages/WorldListPage.h
 | 
			
		||||
 | 
			
		||||
	# GUI - global settings pages
 | 
			
		||||
	pages/global/AccountListPage.cpp
 | 
			
		||||
@@ -272,6 +274,7 @@ SET(MULTIMC_UIS
 | 
			
		||||
	pages/OtherLogsPage.ui
 | 
			
		||||
	pages/LegacyJarModPage.ui
 | 
			
		||||
	pages/LegacyUpgradePage.ui
 | 
			
		||||
	pages/WorldListPage.ui
 | 
			
		||||
 | 
			
		||||
	# Global settings pages
 | 
			
		||||
	pages/global/AccountListPage.ui
 | 
			
		||||
 
 | 
			
		||||
@@ -12,6 +12,7 @@
 | 
			
		||||
#include "pages/OtherLogsPage.h"
 | 
			
		||||
#include "pages/BasePageProvider.h"
 | 
			
		||||
#include "pages/LegacyJarModPage.h"
 | 
			
		||||
#include "pages/WorldListPage.h"
 | 
			
		||||
#include <pathutils.h>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
@@ -39,6 +40,7 @@ public:
 | 
			
		||||
			values.append(new ResourcePackPage(onesix.get()));
 | 
			
		||||
			values.append(new TexturePackPage(onesix.get()));
 | 
			
		||||
			values.append(new NotesPage(onesix.get()));
 | 
			
		||||
			values.append(new WorldListPage(onesix.get(), onesix->worldList(), "worlds", "worlds", tr("Worlds"), "Worlds"));
 | 
			
		||||
			values.append(new ScreenshotsPage(PathCombine(onesix->minecraftRoot(), "screenshots")));
 | 
			
		||||
			values.append(new InstanceSettingsPage(onesix.get()));
 | 
			
		||||
		}
 | 
			
		||||
@@ -54,6 +56,7 @@ public:
 | 
			
		||||
			values.append(new ModFolderPage(legacy.get(), legacy->coreModList(), "coremods", "coremods", tr("Core mods"), "Loader-mods"));
 | 
			
		||||
			values.append(new TexturePackPage(legacy.get()));
 | 
			
		||||
			values.append(new NotesPage(legacy.get()));
 | 
			
		||||
			values.append(new WorldListPage(legacy.get(), legacy->worldList(), "worlds", "worlds", tr("Worlds"), "Worlds"));
 | 
			
		||||
			values.append(new ScreenshotsPage(PathCombine(legacy->minecraftRoot(), "screenshots")));
 | 
			
		||||
			values.append(new InstanceSettingsPage(legacy.get()));
 | 
			
		||||
		}
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										94
									
								
								application/pages/WorldListPage.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								application/pages/WorldListPage.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,94 @@
 | 
			
		||||
//
 | 
			
		||||
// Created by robotbrain on 8/18/15.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#include "WorldListPage.h"
 | 
			
		||||
#include "ui_WorldListPage.h"
 | 
			
		||||
#include "minecraft/WorldList.h"
 | 
			
		||||
#include "dialogs/ModEditDialogCommon.h"
 | 
			
		||||
#include <QEvent>
 | 
			
		||||
#include <QKeyEvent>
 | 
			
		||||
 | 
			
		||||
WorldListPage::WorldListPage(BaseInstance *inst, std::shared_ptr<WorldList> worlds, QString id,
 | 
			
		||||
							 QString iconName, QString displayName, QString helpPage,
 | 
			
		||||
							 QWidget *parent)
 | 
			
		||||
	: QWidget(parent), ui(new Ui::WorldListPage)
 | 
			
		||||
{
 | 
			
		||||
	ui->setupUi(this);
 | 
			
		||||
	ui->tabWidget->tabBar()->hide();
 | 
			
		||||
	m_inst = inst;
 | 
			
		||||
	m_worlds = worlds;
 | 
			
		||||
	m_id = id;
 | 
			
		||||
	m_displayName = displayName;
 | 
			
		||||
	m_iconName = iconName;
 | 
			
		||||
	m_helpName = helpPage;
 | 
			
		||||
	ui->worldTreeView->setModel(m_worlds.get());
 | 
			
		||||
	ui->worldTreeView->installEventFilter(this);
 | 
			
		||||
	auto smodel = ui->worldTreeView->selectionModel();
 | 
			
		||||
	connect(smodel, SIGNAL(currentChanged(QModelIndex, QModelIndex)),
 | 
			
		||||
			SLOT(modCurrent(QModelIndex, QModelIndex)));
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void WorldListPage::opened()
 | 
			
		||||
{
 | 
			
		||||
	m_worlds->startWatching();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void WorldListPage::closed()
 | 
			
		||||
{
 | 
			
		||||
	m_worlds->stopWatching();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
WorldListPage::~WorldListPage()
 | 
			
		||||
{
 | 
			
		||||
	m_worlds->stopWatching();
 | 
			
		||||
	delete ui;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool WorldListPage::shouldDisplay() const
 | 
			
		||||
{
 | 
			
		||||
	if (m_inst)
 | 
			
		||||
		return !m_inst->isRunning();
 | 
			
		||||
	return true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool WorldListPage::worldListFilter(QKeyEvent *keyEvent)
 | 
			
		||||
{
 | 
			
		||||
	switch (keyEvent->key())
 | 
			
		||||
	{
 | 
			
		||||
	case Qt::Key_Delete:
 | 
			
		||||
		on_rmWorldBtn_clicked();
 | 
			
		||||
		return true;
 | 
			
		||||
	default:
 | 
			
		||||
		break;
 | 
			
		||||
	}
 | 
			
		||||
	return QWidget::eventFilter(ui->worldTreeView, keyEvent);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool WorldListPage::eventFilter(QObject *obj, QEvent *ev)
 | 
			
		||||
{
 | 
			
		||||
	if (ev->type() != QEvent::KeyPress)
 | 
			
		||||
	{
 | 
			
		||||
		return QWidget::eventFilter(obj, ev);
 | 
			
		||||
	}
 | 
			
		||||
	QKeyEvent *keyEvent = static_cast<QKeyEvent *>(ev);
 | 
			
		||||
	if (obj == ui->worldTreeView)
 | 
			
		||||
		return worldListFilter(keyEvent);
 | 
			
		||||
	return QWidget::eventFilter(obj, ev);
 | 
			
		||||
}
 | 
			
		||||
void WorldListPage::on_rmWorldBtn_clicked()
 | 
			
		||||
{
 | 
			
		||||
	int first, last;
 | 
			
		||||
	auto list = ui->worldTreeView->selectionModel()->selectedRows();
 | 
			
		||||
 | 
			
		||||
	if (!lastfirst(list, first, last))
 | 
			
		||||
		return;
 | 
			
		||||
	m_worlds->stopWatching();
 | 
			
		||||
	m_worlds->deleteWorlds(first, last);
 | 
			
		||||
	m_worlds->startWatching();
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void WorldListPage::on_viewFolderBtn_clicked()
 | 
			
		||||
{
 | 
			
		||||
	openDirInDefaultProgram(m_worlds->dir().absolutePath(), true);
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										69
									
								
								application/pages/WorldListPage.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										69
									
								
								application/pages/WorldListPage.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,69 @@
 | 
			
		||||
//
 | 
			
		||||
// Created by robotbrain on 8/18/15.
 | 
			
		||||
//
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <QWidget>
 | 
			
		||||
 | 
			
		||||
#include "minecraft/OneSixInstance.h"
 | 
			
		||||
#include "BasePage.h"
 | 
			
		||||
#include <MultiMC.h>
 | 
			
		||||
#include <pathutils.h>
 | 
			
		||||
 | 
			
		||||
class WorldList;
 | 
			
		||||
namespace Ui
 | 
			
		||||
{
 | 
			
		||||
class WorldListPage;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
class WorldListPage : public QWidget, public BasePage
 | 
			
		||||
{
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
	explicit WorldListPage(BaseInstance *inst, std::shared_ptr<WorldList> worlds, QString id,
 | 
			
		||||
						   QString iconName, QString displayName, QString helpPage = "",
 | 
			
		||||
						   QWidget *parent = 0);
 | 
			
		||||
	virtual ~WorldListPage();
 | 
			
		||||
 | 
			
		||||
	virtual QString displayName() const override
 | 
			
		||||
	{
 | 
			
		||||
		return m_displayName;
 | 
			
		||||
	}
 | 
			
		||||
	virtual QIcon icon() const override
 | 
			
		||||
	{
 | 
			
		||||
		return MMC->getThemedIcon(m_iconName);
 | 
			
		||||
	}
 | 
			
		||||
	virtual QString id() const override
 | 
			
		||||
	{
 | 
			
		||||
		return m_id;
 | 
			
		||||
	}
 | 
			
		||||
	virtual QString helpPage() const override
 | 
			
		||||
	{
 | 
			
		||||
		return m_helpName;
 | 
			
		||||
	}
 | 
			
		||||
	virtual bool shouldDisplay() const;
 | 
			
		||||
 | 
			
		||||
	virtual void opened();
 | 
			
		||||
	virtual void closed();
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
	bool eventFilter(QObject *obj, QEvent *ev);
 | 
			
		||||
	bool worldListFilter(QKeyEvent *ev);
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
	BaseInstance *m_inst;
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
	Ui::WorldListPage *ui;
 | 
			
		||||
	std::shared_ptr<WorldList> m_worlds;
 | 
			
		||||
	QString m_iconName;
 | 
			
		||||
	QString m_id;
 | 
			
		||||
	QString m_displayName;
 | 
			
		||||
	QString m_helpName;
 | 
			
		||||
 | 
			
		||||
private slots:
 | 
			
		||||
	void on_rmWorldBtn_clicked();
 | 
			
		||||
	void on_viewFolderBtn_clicked();
 | 
			
		||||
};
 | 
			
		||||
							
								
								
									
										94
									
								
								application/pages/WorldListPage.ui
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								application/pages/WorldListPage.ui
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,94 @@
 | 
			
		||||
<?xml version="1.0" encoding="UTF-8"?>
 | 
			
		||||
<ui version="4.0">
 | 
			
		||||
    <class>WorldListPage</class>
 | 
			
		||||
    <widget class="QWidget" name="WorldListPage">
 | 
			
		||||
        <property name="geometry">
 | 
			
		||||
            <rect>
 | 
			
		||||
                <x>0</x>
 | 
			
		||||
                <y>0</y>
 | 
			
		||||
                <width>723</width>
 | 
			
		||||
                <height>532</height>
 | 
			
		||||
            </rect>
 | 
			
		||||
        </property>
 | 
			
		||||
        <property name="windowTitle">
 | 
			
		||||
            <string>Mods</string>
 | 
			
		||||
        </property>
 | 
			
		||||
        <layout class="QVBoxLayout" name="verticalLayout">
 | 
			
		||||
            <property name="leftMargin">
 | 
			
		||||
                <number>0</number>
 | 
			
		||||
            </property>
 | 
			
		||||
            <property name="topMargin">
 | 
			
		||||
                <number>0</number>
 | 
			
		||||
            </property>
 | 
			
		||||
            <property name="rightMargin">
 | 
			
		||||
                <number>0</number>
 | 
			
		||||
            </property>
 | 
			
		||||
            <property name="bottomMargin">
 | 
			
		||||
                <number>0</number>
 | 
			
		||||
            </property>
 | 
			
		||||
            <item>
 | 
			
		||||
                <widget class="QTabWidget" name="tabWidget">
 | 
			
		||||
                    <property name="currentIndex">
 | 
			
		||||
                        <number>0</number>
 | 
			
		||||
                    </property>
 | 
			
		||||
                    <widget class="QWidget" name="tab">
 | 
			
		||||
                        <attribute name="title">
 | 
			
		||||
                            <string>Tab 1</string>
 | 
			
		||||
                        </attribute>
 | 
			
		||||
                        <layout class="QGridLayout" name="gridLayout">
 | 
			
		||||
                            <item row="0" column="0">
 | 
			
		||||
                                <widget class="QTreeView" name="worldTreeView">
 | 
			
		||||
                                    <property name="sizePolicy">
 | 
			
		||||
                                        <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
 | 
			
		||||
                                            <horstretch>0</horstretch>
 | 
			
		||||
                                            <verstretch>0</verstretch>
 | 
			
		||||
                                        </sizepolicy>
 | 
			
		||||
                                    </property>
 | 
			
		||||
                                    <property name="acceptDrops">
 | 
			
		||||
                                        <bool>true</bool>
 | 
			
		||||
                                    </property>
 | 
			
		||||
                                    <property name="dragDropMode">
 | 
			
		||||
                                        <enum>QAbstractItemView::DropOnly</enum>
 | 
			
		||||
                                    </property>
 | 
			
		||||
                                </widget>
 | 
			
		||||
                            </item>
 | 
			
		||||
                            <item row="0" column="1">
 | 
			
		||||
                                <layout class="QVBoxLayout" name="verticalLayout_2">
 | 
			
		||||
                                    <item>
 | 
			
		||||
                                        <widget class="QPushButton" name="rmWorldBtn">
 | 
			
		||||
                                            <property name="text">
 | 
			
		||||
                                                <string>&Remove</string>
 | 
			
		||||
                                            </property>
 | 
			
		||||
                                        </widget>
 | 
			
		||||
                                    </item>
 | 
			
		||||
                                    <item>
 | 
			
		||||
                                        <spacer name="verticalSpacer">
 | 
			
		||||
                                            <property name="orientation">
 | 
			
		||||
                                                <enum>Qt::Vertical</enum>
 | 
			
		||||
                                            </property>
 | 
			
		||||
                                            <property name="sizeHint" stdset="0">
 | 
			
		||||
                                                <size>
 | 
			
		||||
                                                    <width>20</width>
 | 
			
		||||
                                                    <height>40</height>
 | 
			
		||||
                                                </size>
 | 
			
		||||
                                            </property>
 | 
			
		||||
                                        </spacer>
 | 
			
		||||
                                    </item>
 | 
			
		||||
                                    <item>
 | 
			
		||||
                                        <widget class="QPushButton" name="viewFolderBtn">
 | 
			
		||||
                                            <property name="text">
 | 
			
		||||
                                                <string>&View Folder</string>
 | 
			
		||||
                                            </property>
 | 
			
		||||
                                        </widget>
 | 
			
		||||
                                    </item>
 | 
			
		||||
                                </layout>
 | 
			
		||||
                            </item>
 | 
			
		||||
                        </layout>
 | 
			
		||||
                    </widget>
 | 
			
		||||
                </widget>
 | 
			
		||||
            </item>
 | 
			
		||||
        </layout>
 | 
			
		||||
    </widget>
 | 
			
		||||
    <resources/>
 | 
			
		||||
    <connections/>
 | 
			
		||||
</ui>
 | 
			
		||||
		Reference in New Issue
	
	Block a user