Remove button additions

Signed-off-by: Yihe Li <winmikedows@hotmail.com>
This commit is contained in:
Yihe Li 2025-05-19 01:33:15 +08:00
parent 4839595a11
commit 46c9eb1d5f
No known key found for this signature in database
8 changed files with 2 additions and 278 deletions

View File

@ -46,9 +46,6 @@
#include <QUuid> #include <QUuid>
#include <Qt> #include <Qt>
#include <DesktopServices.h>
#include "minecraft/ShortcutUtils.h"
WorldList::WorldList(const QString& dir, BaseInstance* instance) : QAbstractListModel(), m_instance(instance), m_dir(dir) WorldList::WorldList(const QString& dir, BaseInstance* instance) : QAbstractListModel(), m_instance(instance), m_dir(dir)
{ {
FS::ensureFolderPathExists(m_dir.absolutePath()); FS::ensureFolderPathExists(m_dir.absolutePath());
@ -457,39 +454,4 @@ void WorldList::loadWorldsAsync()
} }
} }
void WorldList::createWorldShortcut(const QModelIndex& index, QWidget* parent) const
{
if (!m_instance)
return;
if (DesktopServices::isFlatpak())
createWorldShortcutInOther(index, parent);
else
createWorldShortcutOnDesktop(index, parent);
}
void WorldList::createWorldShortcutOnDesktop(const QModelIndex& index, QWidget* parent) const
{
const auto& world = allWorlds().at(index.row());
QString name = QString(tr("%1 - %2")).arg(m_instance->name(), world.name());
QStringList extraArgs{ "--world", world.name() };
ShortcutUtils::createInstanceShortcutOnDesktop({ m_instance, name, tr("world"), parent, extraArgs });
}
void WorldList::createWorldShortcutInApplications(const QModelIndex& index, QWidget* parent) const
{
const auto& world = allWorlds().at(index.row());
QString name = QString(tr("%1 - %2")).arg(m_instance->name(), world.name());
QStringList extraArgs{ "--world", world.name() };
ShortcutUtils::createInstanceShortcutInApplications({ m_instance, name, tr("world"), parent, extraArgs });
}
void WorldList::createWorldShortcutInOther(const QModelIndex& index, QWidget* parent) const
{
const auto& world = allWorlds().at(index.row());
QString name = QString(tr("%1 - %2")).arg(m_instance->name(), world.name());
QStringList extraArgs{ "--world", world.name() };
ShortcutUtils::createInstanceShortcutInOther({ m_instance, name, tr("world"), parent, extraArgs });
}
#include "WorldList.moc" #include "WorldList.moc"

View File

@ -84,11 +84,6 @@ class WorldList : public QAbstractListModel {
const QList<World>& allWorlds() const { return m_worlds; } const QList<World>& allWorlds() const { return m_worlds; }
void createWorldShortcut(const QModelIndex& index, QWidget* parent = nullptr) const;
void createWorldShortcutOnDesktop(const QModelIndex& index, QWidget* parent = nullptr) const;
void createWorldShortcutInApplications(const QModelIndex& index, QWidget* parent = nullptr) const;
void createWorldShortcutInOther(const QModelIndex& index, QWidget* parent = nullptr) const;
private slots: private slots:
void directoryChanged(QString path); void directoryChanged(QString path);
void loadWorldsAsync(); void loadWorldsAsync();

View File

@ -40,10 +40,8 @@
#include "ui/dialogs/CustomMessageBox.h" #include "ui/dialogs/CustomMessageBox.h"
#include "ui_ServersPage.h" #include "ui_ServersPage.h"
#include <DesktopServices.h>
#include <FileSystem.h> #include <FileSystem.h>
#include <io/stream_reader.h> #include <io/stream_reader.h>
#include <minecraft/ShortcutUtils.h>
#include <minecraft/MinecraftInstance.h> #include <minecraft/MinecraftInstance.h>
#include <tag_compound.h> #include <tag_compound.h>
#include <tag_list.h> #include <tag_list.h>
@ -104,38 +102,6 @@ struct Server {
} }
} }
void createServerShortcut(BaseInstance* instance, QWidget* parent = nullptr) const
{
if (!instance)
return;
if (DesktopServices::isFlatpak())
createServerShortcutInOther(instance, parent);
else
createServerShortcutOnDesktop(instance, parent);
}
void createServerShortcutOnDesktop(BaseInstance* instance, QWidget* parent = nullptr) const
{
QString name = QString(QObject::tr("%1 - Server %2")).arg(instance->name(), m_name);
QStringList extraArgs{ "--server", m_address };
ShortcutUtils::createInstanceShortcutOnDesktop({ instance, name, QObject::tr("server"), parent, extraArgs });
}
void createServerShortcutInApplications(BaseInstance* instance, QWidget* parent = nullptr) const
{
QString name = QString(QObject::tr("%1 - Server %2")).arg(instance->name(), m_name);
QStringList extraArgs{ "--server", m_address };
ShortcutUtils::createInstanceShortcutInApplications({ instance, name, QObject::tr("server"), parent, extraArgs });
}
void createServerShortcutInOther(BaseInstance* instance, QWidget* parent = nullptr) const
{
QString name = QString(QObject::tr("%1 - Server %2")).arg(instance->name(), m_name);
QStringList extraArgs{ "--server", m_address };
ShortcutUtils::createInstanceShortcutInOther({ instance, name, QObject::tr("server"), parent, extraArgs });
}
// Data - persistent and user changeable // Data - persistent and user changeable
QString m_name; QString m_name;
QString m_address; QString m_address;
@ -615,26 +581,6 @@ ServersPage::ServersPage(InstancePtr inst, QWidget* parent) : QMainWindow(parent
connect(ui->resourceComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(resourceIndexChanged(int))); connect(ui->resourceComboBox, SIGNAL(currentIndexChanged(int)), this, SLOT(resourceIndexChanged(int)));
connect(m_model, &QAbstractItemModel::rowsRemoved, this, &ServersPage::rowsRemoved); connect(m_model, &QAbstractItemModel::rowsRemoved, this, &ServersPage::rowsRemoved);
QList<QAction*> shortcutActions = { ui->actionCreateServerShortcutOther };
if (!DesktopServices::isFlatpak()) {
QString desktopDir = FS::getDesktopDir();
QString applicationDir = FS::getApplicationsDir();
if (!applicationDir.isEmpty())
shortcutActions.push_front(ui->actionCreateServerShortcutApplications);
if (!desktopDir.isEmpty())
shortcutActions.push_front(ui->actionCreateServerShortcutDesktop);
}
if (shortcutActions.length() > 1) {
auto shortcutInstanceMenu = new QMenu(this);
for (auto action : shortcutActions)
shortcutInstanceMenu->addAction(action);
ui->actionCreateServerShortcut->setMenu(shortcutInstanceMenu);
}
m_locked = m_inst->isRunning(); m_locked = m_inst->isRunning();
if (m_locked) { if (m_locked) {
m_model->lock(); m_model->lock();
@ -738,7 +684,6 @@ void ServersPage::updateState()
ui->actionMove_Up->setEnabled(serverEditEnabled); ui->actionMove_Up->setEnabled(serverEditEnabled);
ui->actionRemove->setEnabled(serverEditEnabled); ui->actionRemove->setEnabled(serverEditEnabled);
ui->actionJoin->setEnabled(serverEditEnabled); ui->actionJoin->setEnabled(serverEditEnabled);
ui->actionCreateServerShortcut->setEnabled(serverEditEnabled);
if (server) { if (server) {
ui->addressLine->setText(server->m_address); ui->addressLine->setText(server->m_address);
@ -822,26 +767,6 @@ void ServersPage::on_actionJoin_triggered()
APPLICATION->launch(m_inst, true, false, std::make_shared<MinecraftTarget>(MinecraftTarget::parse(address, false))); APPLICATION->launch(m_inst, true, false, std::make_shared<MinecraftTarget>(MinecraftTarget::parse(address, false)));
} }
void ServersPage::on_actionCreateServerShortcut_triggered()
{
m_model->at(currentServer)->createServerShortcut(m_inst.get(), this);
}
void ServersPage::on_actionCreateServerShortcutDesktop_triggered()
{
m_model->at(currentServer)->createServerShortcutOnDesktop(m_inst.get(), this);
}
void ServersPage::on_actionCreateServerShortcutApplications_triggered()
{
m_model->at(currentServer)->createServerShortcutInApplications(m_inst.get(), this);
}
void ServersPage::on_actionCreateServerShortcutOther_triggered()
{
m_model->at(currentServer)->createServerShortcutInOther(m_inst.get(), this);
}
void ServersPage::on_actionRefresh_triggered() void ServersPage::on_actionRefresh_triggered()
{ {
m_model->queryServersStatus(); m_model->queryServersStatus();

View File

@ -85,10 +85,6 @@ class ServersPage : public QMainWindow, public BasePage {
void on_actionMove_Up_triggered(); void on_actionMove_Up_triggered();
void on_actionMove_Down_triggered(); void on_actionMove_Down_triggered();
void on_actionJoin_triggered(); void on_actionJoin_triggered();
void on_actionCreateServerShortcut_triggered();
void on_actionCreateServerShortcutDesktop_triggered();
void on_actionCreateServerShortcutApplications_triggered();
void on_actionCreateServerShortcutOther_triggered();
void on_actionRefresh_triggered(); void on_actionRefresh_triggered();
void runningStateChanged(bool running); void runningStateChanged(bool running);

View File

@ -135,9 +135,6 @@
<property name="toolButtonStyle"> <property name="toolButtonStyle">
<enum>Qt::ToolButtonTextOnly</enum> <enum>Qt::ToolButtonTextOnly</enum>
</property> </property>
<property name="useDefaultAction" stdset="0">
<bool>true</bool>
</property>
<property name="floatable"> <property name="floatable">
<bool>false</bool> <bool>false</bool>
</property> </property>
@ -148,12 +145,10 @@
<bool>false</bool> <bool>false</bool>
</attribute> </attribute>
<addaction name="actionAdd"/> <addaction name="actionAdd"/>
<addaction name="separator"/>
<addaction name="actionJoin"/>
<addaction name="actionRemove"/> <addaction name="actionRemove"/>
<addaction name="actionMove_Up"/> <addaction name="actionMove_Up"/>
<addaction name="actionMove_Down"/> <addaction name="actionMove_Down"/>
<addaction name="actionCreateServerShortcut"/> <addaction name="actionJoin"/>
<addaction name="separator"/> <addaction name="separator"/>
<addaction name="actionRefresh"/> <addaction name="actionRefresh"/>
</widget> </widget>
@ -182,47 +177,6 @@
<string>Join</string> <string>Join</string>
</property> </property>
</action> </action>
<action name="actionCreateServerShortcut">
<property name="text">
<string>Create Shortcut</string>
</property>
<property name="toolTip">
<string>Creates a shortcut on a selected folder to join the selected server.</string>
</property>
</action>
<action name="actionCreateServerShortcutDesktop">
<property name="text">
<string>Desktop</string>
</property>
<property name="toolTip">
<string>Creates a shortcut to this server on your desktop</string>
</property>
<property name="menuRole">
<enum>QAction::TextHeuristicRole</enum>
</property>
</action>
<action name="actionCreateServerShortcutApplications">
<property name="text">
<string>Applications</string>
</property>
<property name="toolTip">
<string>Create a shortcut of this server on your start menu</string>
</property>
<property name="menuRole">
<enum>QAction::TextHeuristicRole</enum>
</property>
</action>
<action name="actionCreateServerShortcutOther">
<property name="text">
<string>Other...</string>
</property>
<property name="toolTip">
<string>Creates a shortcut in a folder selected by you</string>
</property>
<property name="menuRole">
<enum>QAction::TextHeuristicRole</enum>
</property>
</action>
<action name="actionRefresh"> <action name="actionRefresh">
<property name="text"> <property name="text">
<string>Refresh</string> <string>Refresh</string>

View File

@ -89,26 +89,6 @@ WorldListPage::WorldListPage(InstancePtr inst, std::shared_ptr<WorldList> worlds
ui->toolBar->insertSpacer(ui->actionRefresh); ui->toolBar->insertSpacer(ui->actionRefresh);
QList<QAction*> shortcutActions = { ui->actionCreateWorldShortcutOther };
if (!DesktopServices::isFlatpak()) {
QString desktopDir = FS::getDesktopDir();
QString applicationDir = FS::getApplicationsDir();
if (!applicationDir.isEmpty())
shortcutActions.push_front(ui->actionCreateWorldShortcutApplications);
if (!desktopDir.isEmpty())
shortcutActions.push_front(ui->actionCreateWorldShortcutDesktop);
}
if (shortcutActions.length() > 1) {
auto shortcutInstanceMenu = new QMenu(this);
for (auto action : shortcutActions)
shortcutInstanceMenu->addAction(action);
ui->actionCreateWorldShortcut->setMenu(shortcutInstanceMenu);
}
WorldListProxyModel* proxy = new WorldListProxyModel(this); WorldListProxyModel* proxy = new WorldListProxyModel(this);
proxy->setSortCaseSensitivity(Qt::CaseInsensitive); proxy->setSortCaseSensitivity(Qt::CaseInsensitive);
proxy->setSourceModel(m_worlds.get()); proxy->setSourceModel(m_worlds.get());
@ -365,9 +345,6 @@ void WorldListPage::worldChanged([[maybe_unused]] const QModelIndex& current, [[
if (!supportsJoin) { if (!supportsJoin) {
ui->toolBar->removeAction(ui->actionJoin); ui->toolBar->removeAction(ui->actionJoin);
ui->toolBar->removeAction(ui->actionCreateWorldShortcut);
} else {
ui->actionCreateWorldShortcut->setEnabled(enable);
} }
} }
@ -443,42 +420,6 @@ void WorldListPage::on_actionRename_triggered()
} }
} }
void WorldListPage::on_actionCreateWorldShortcut_triggered()
{
QModelIndex index = getSelectedWorld();
if (!index.isValid()) {
return;
}
m_worlds->createWorldShortcut(index, this);
}
void WorldListPage::on_actionCreateWorldShortcutDesktop_triggered()
{
QModelIndex index = getSelectedWorld();
if (!index.isValid()) {
return;
}
m_worlds->createWorldShortcutOnDesktop(index, this);
}
void WorldListPage::on_actionCreateWorldShortcutApplications_triggered()
{
QModelIndex index = getSelectedWorld();
if (!index.isValid()) {
return;
}
m_worlds->createWorldShortcutInApplications(index, this);
}
void WorldListPage::on_actionCreateWorldShortcutOther_triggered()
{
QModelIndex index = getSelectedWorld();
if (!index.isValid()) {
return;
}
m_worlds->createWorldShortcutInOther(index, this);
}
void WorldListPage::on_actionRefresh_triggered() void WorldListPage::on_actionRefresh_triggered()
{ {
m_worlds->update(); m_worlds->update();

View File

@ -95,10 +95,6 @@ class WorldListPage : public QMainWindow, public BasePage {
void on_actionAdd_triggered(); void on_actionAdd_triggered();
void on_actionCopy_triggered(); void on_actionCopy_triggered();
void on_actionRename_triggered(); void on_actionRename_triggered();
void on_actionCreateWorldShortcut_triggered();
void on_actionCreateWorldShortcutDesktop_triggered();
void on_actionCreateWorldShortcutApplications_triggered();
void on_actionCreateWorldShortcutOther_triggered();
void on_actionRefresh_triggered(); void on_actionRefresh_triggered();
void on_actionView_Folder_triggered(); void on_actionView_Folder_triggered();
void on_actionDatapacks_triggered(); void on_actionDatapacks_triggered();

View File

@ -70,9 +70,6 @@
<property name="toolButtonStyle"> <property name="toolButtonStyle">
<enum>Qt::ToolButtonTextOnly</enum> <enum>Qt::ToolButtonTextOnly</enum>
</property> </property>
<property name="useDefaultAction" stdset="0">
<bool>true</bool>
</property>
<property name="floatable"> <property name="floatable">
<bool>false</bool> <bool>false</bool>
</property> </property>
@ -88,11 +85,10 @@
<addaction name="actionRename"/> <addaction name="actionRename"/>
<addaction name="actionCopy"/> <addaction name="actionCopy"/>
<addaction name="actionRemove"/> <addaction name="actionRemove"/>
<addaction name="actionCreateWorldShortcut"/>
<addaction name="separator"/>
<addaction name="actionMCEdit"/> <addaction name="actionMCEdit"/>
<addaction name="actionDatapacks"/> <addaction name="actionDatapacks"/>
<addaction name="actionReset_Icon"/> <addaction name="actionReset_Icon"/>
<addaction name="separator"/>
<addaction name="actionCopy_Seed"/> <addaction name="actionCopy_Seed"/>
<addaction name="actionRefresh"/> <addaction name="actionRefresh"/>
<addaction name="actionView_Folder"/> <addaction name="actionView_Folder"/>
@ -122,14 +118,6 @@
<string>Delete</string> <string>Delete</string>
</property> </property>
</action> </action>
<action name="actionCreateWorldShortcut">
<property name="text">
<string>Create Shortcut</string>
</property>
<property name="toolTip">
<string>Creates a shortcut on a selected folder to join the selected world.</string>
</property>
</action>
<action name="actionMCEdit"> <action name="actionMCEdit">
<property name="text"> <property name="text">
<string>MCEdit</string> <string>MCEdit</string>
@ -166,39 +154,6 @@
<string>Manage datapacks inside the world.</string> <string>Manage datapacks inside the world.</string>
</property> </property>
</action> </action>
<action name="actionCreateWorldShortcutDesktop">
<property name="text">
<string>Desktop</string>
</property>
<property name="toolTip">
<string>Creates a shortcut to this world on your desktop</string>
</property>
<property name="menuRole">
<enum>QAction::TextHeuristicRole</enum>
</property>
</action>
<action name="actionCreateWorldShortcutApplications">
<property name="text">
<string>Applications</string>
</property>
<property name="toolTip">
<string>Create a shortcut of this world on your start menu</string>
</property>
<property name="menuRole">
<enum>QAction::TextHeuristicRole</enum>
</property>
</action>
<action name="actionCreateWorldShortcutOther">
<property name="text">
<string>Other...</string>
</property>
<property name="toolTip">
<string>Creates a shortcut in a folder selected by you</string>
</property>
<property name="menuRole">
<enum>QAction::TextHeuristicRole</enum>
</property>
</action>
</widget> </widget>
<customwidgets> <customwidgets>
<customwidget> <customwidget>