GH-1227: World import using drag and drop - zip files and folders
This commit is contained in:
@ -51,14 +51,13 @@ void GuiUtil::setClipboardText(const QString &text)
|
||||
QApplication::clipboard()->setText(text);
|
||||
}
|
||||
|
||||
QStringList GuiUtil::BrowseForMods(QString context, QString caption, QString filter,
|
||||
QWidget *parentWidget)
|
||||
|
||||
QStringList GuiUtil::BrowseForFiles(QString context, QString caption, QString filter, QString defaultPath, QWidget *parentWidget)
|
||||
{
|
||||
static QMap<QString, QString> savedPaths;
|
||||
|
||||
QFileDialog w(parentWidget, caption);
|
||||
QSet<QString> locations;
|
||||
QString modsFolder = MMC->settings()->get("CentralModsDir").toString();
|
||||
auto f = [&](QStandardPaths::StandardLocation l)
|
||||
{
|
||||
QString location = QStandardPaths::writableLocation(l);
|
||||
@ -76,19 +75,30 @@ QStringList GuiUtil::BrowseForMods(QString context, QString caption, QString fil
|
||||
{
|
||||
urls.append(QUrl::fromLocalFile(location));
|
||||
}
|
||||
urls.append(QUrl::fromLocalFile(modsFolder));
|
||||
urls.append(QUrl::fromLocalFile(defaultPath));
|
||||
|
||||
w.setFileMode(QFileDialog::ExistingFiles);
|
||||
w.setAcceptMode(QFileDialog::AcceptOpen);
|
||||
w.setNameFilter(filter);
|
||||
|
||||
QString pathToOpen;
|
||||
if(savedPaths.contains(context))
|
||||
{
|
||||
w.setDirectory(savedPaths[context]);
|
||||
pathToOpen = savedPaths[context];
|
||||
}
|
||||
else
|
||||
{
|
||||
w.setDirectory(modsFolder);
|
||||
pathToOpen = defaultPath;
|
||||
}
|
||||
if(!pathToOpen.isEmpty())
|
||||
{
|
||||
QFileInfo finfo(pathToOpen);
|
||||
if(finfo.exists() && finfo.isDir())
|
||||
{
|
||||
w.setDirectory(finfo.absoluteFilePath());
|
||||
}
|
||||
}
|
||||
|
||||
w.setSidebarUrls(urls);
|
||||
|
||||
if (w.exec())
|
||||
|
@ -6,5 +6,5 @@ namespace GuiUtil
|
||||
{
|
||||
void uploadPaste(const QString &text, QWidget *parentWidget);
|
||||
void setClipboardText(const QString &text);
|
||||
QStringList BrowseForMods(QString context, QString caption, QString filter, QWidget *parentWidget);
|
||||
QStringList BrowseForFiles(QString context, QString caption, QString filter, QString defaultPath, QWidget *parentWidget);
|
||||
}
|
||||
|
@ -100,7 +100,7 @@ bool LegacyJarModPage::eventFilter(QObject *obj, QEvent *ev)
|
||||
|
||||
void LegacyJarModPage::on_addJarBtn_clicked()
|
||||
{
|
||||
auto list = GuiUtil::BrowseForMods("jarmod", tr("Select jar mods"), tr("Minecraft.jar mods (*.zip *.jar)"), this->parentWidget());
|
||||
auto list = GuiUtil::BrowseForFiles("jarmod", tr("Select jar mods"), tr("Minecraft.jar mods (*.zip *.jar)"), MMC->settings()->get("CentralModsDir").toString(), this->parentWidget());
|
||||
if(!list.empty())
|
||||
{
|
||||
m_jarmods->stopWatching();
|
||||
|
@ -131,12 +131,13 @@ bool ModFolderPage::eventFilter(QObject *obj, QEvent *ev)
|
||||
|
||||
void ModFolderPage::on_addModBtn_clicked()
|
||||
{
|
||||
auto list = GuiUtil::BrowseForMods(
|
||||
auto list = GuiUtil::BrowseForFiles(
|
||||
m_helpName,
|
||||
tr("Select %1",
|
||||
"Select whatever type of files the page contains. Example: 'Loader Mods'")
|
||||
.arg(m_displayName),
|
||||
m_filter.arg(m_displayName), this->parentWidget());
|
||||
m_filter.arg(m_displayName), MMC->settings()->get("CentralModsDir").toString(),
|
||||
this->parentWidget());
|
||||
if (!list.empty())
|
||||
{
|
||||
m_mods->stopWatching();
|
||||
@ -146,8 +147,8 @@ void ModFolderPage::on_addModBtn_clicked()
|
||||
}
|
||||
m_mods->startWatching();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
void ModFolderPage::on_rmModBtn_clicked()
|
||||
{
|
||||
int first, last;
|
||||
|
@ -180,7 +180,7 @@ void VersionPage::on_jarmodBtn_clicked()
|
||||
nagShown = true;
|
||||
}
|
||||
}
|
||||
auto list = GuiUtil::BrowseForMods("jarmod", tr("Select jar mods"), tr("Minecraft.jar mods (*.zip *.jar)"), this->parentWidget());
|
||||
auto list = GuiUtil::BrowseForFiles("jarmod", tr("Select jar mods"), tr("Minecraft.jar mods (*.zip *.jar)"), MMC->settings()->get("CentralModsDir").toString(), this->parentWidget());
|
||||
if(!list.empty())
|
||||
{
|
||||
m_version->installJarMods(list);
|
||||
|
@ -25,6 +25,7 @@
|
||||
|
||||
|
||||
#include "MultiMC.h"
|
||||
#include <GuiUtil.h>
|
||||
|
||||
WorldListPage::WorldListPage(BaseInstance *inst, std::shared_ptr<WorldList> worlds, QString id,
|
||||
QString iconName, QString displayName, QString helpPage,
|
||||
@ -67,8 +68,6 @@ WorldListPage::~WorldListPage()
|
||||
|
||||
bool WorldListPage::shouldDisplay() const
|
||||
{
|
||||
if (m_inst)
|
||||
return !m_inst->isRunning();
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -200,3 +199,20 @@ void WorldListPage::worldChanged(const QModelIndex ¤t, const QModelIndex &
|
||||
ui->mcEditBtn->setEnabled(enable);
|
||||
ui->rmWorldBtn->setEnabled(enable);
|
||||
}
|
||||
|
||||
void WorldListPage::on_addBtn_clicked()
|
||||
{
|
||||
auto list = GuiUtil::BrowseForFiles(
|
||||
m_helpName,
|
||||
tr("Select a Minecraft world zip"),
|
||||
tr("Minecraft World Zip File (*.zip)"), QString(), this->parentWidget());
|
||||
if (!list.empty())
|
||||
{
|
||||
m_worlds->stopWatching();
|
||||
for (auto filename : list)
|
||||
{
|
||||
m_worlds->installWorld(QFileInfo(filename));
|
||||
}
|
||||
m_worlds->startWatching();
|
||||
}
|
||||
}
|
@ -81,6 +81,7 @@ private slots:
|
||||
void on_copySeedBtn_clicked();
|
||||
void on_mcEditBtn_clicked();
|
||||
void on_rmWorldBtn_clicked();
|
||||
void on_addBtn_clicked();
|
||||
void on_viewFolderBtn_clicked();
|
||||
void worldChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||
};
|
||||
|
@ -48,7 +48,7 @@
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="dragDropMode">
|
||||
<enum>QAbstractItemView::DropOnly</enum>
|
||||
<enum>QAbstractItemView::DragDrop</enum>
|
||||
</property>
|
||||
<property name="sortingEnabled">
|
||||
<bool>true</bool>
|
||||
@ -63,6 +63,23 @@
|
||||
</item>
|
||||
<item row="0" column="1">
|
||||
<layout class="QVBoxLayout" name="verticalLayout_2">
|
||||
<item>
|
||||
<widget class="QPushButton" name="addBtn">
|
||||
<property name="text">
|
||||
<string>Add</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="rmWorldBtn">
|
||||
<property name="text">
|
||||
<string>&Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="LineSeparator" name="separator" native="true"/>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="mcEditBtn">
|
||||
<property name="text">
|
||||
@ -77,13 +94,6 @@
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QPushButton" name="rmWorldBtn">
|
||||
<property name="text">
|
||||
<string>&Remove</string>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<spacer name="verticalSpacer">
|
||||
<property name="orientation">
|
||||
@ -112,12 +122,21 @@
|
||||
</item>
|
||||
</layout>
|
||||
</widget>
|
||||
<customwidgets>
|
||||
<customwidget>
|
||||
<class>LineSeparator</class>
|
||||
<extends>QWidget</extends>
|
||||
<header>widgets/LineSeparator.h</header>
|
||||
<container>1</container>
|
||||
</customwidget>
|
||||
</customwidgets>
|
||||
<tabstops>
|
||||
<tabstop>tabWidget</tabstop>
|
||||
<tabstop>worldTreeView</tabstop>
|
||||
<tabstop>addBtn</tabstop>
|
||||
<tabstop>rmWorldBtn</tabstop>
|
||||
<tabstop>mcEditBtn</tabstop>
|
||||
<tabstop>copySeedBtn</tabstop>
|
||||
<tabstop>rmWorldBtn</tabstop>
|
||||
<tabstop>viewFolderBtn</tabstop>
|
||||
</tabstops>
|
||||
<resources/>
|
||||
|
Reference in New Issue
Block a user