From 20e2c70464059dec07f875b9cb703bacdcfeee57 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Sun, 16 Jul 2023 23:23:33 +0100 Subject: [PATCH 1/4] Rename groups and janky reference counting map Signed-off-by: TheKodeToad --- launcher/InstanceList.cpp | 93 ++++++++++++++++------ launcher/InstanceList.h | 46 ++++++++--- launcher/ui/MainWindow.cpp | 73 +++++++++-------- launcher/ui/MainWindow.h | 3 +- launcher/ui/dialogs/CopyInstanceDialog.cpp | 25 +++--- launcher/ui/dialogs/NewInstanceDialog.cpp | 28 +++---- 6 files changed, 166 insertions(+), 102 deletions(-) diff --git a/launcher/InstanceList.cpp b/launcher/InstanceList.cpp index b4c520cd9..6bc906ebd 100644 --- a/launcher/InstanceList.cpp +++ b/launcher/InstanceList.cpp @@ -1,7 +1,8 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 Sefa Eyeoglu + * Copyright (C) 2023 TheKodeToad * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -237,8 +238,11 @@ GroupId InstanceList::getInstanceGroup(const InstanceId& id) const return GroupId(); } -void InstanceList::setInstanceGroup(const InstanceId& id, const GroupId& name) +void InstanceList::setInstanceGroup(const InstanceId& id, GroupId name) { + if (name.isEmpty() && !name.isNull()) + name = QString(); + auto inst = getInstanceById(id); if (!inst) { qDebug() << "Attempt to set a null instance's group"; @@ -249,6 +253,9 @@ void InstanceList::setInstanceGroup(const InstanceId& id, const GroupId& name) auto iter = m_instanceGroupIndex.find(inst->id()); if (iter != m_instanceGroupIndex.end()) { if (*iter != name) { + if (!iter->isEmpty() && --m_groupNameCache[*iter] == 0) + m_groupNameCache.remove(*iter); + *iter = name; changed = true; } @@ -258,7 +265,9 @@ void InstanceList::setInstanceGroup(const InstanceId& id, const GroupId& name) } if (changed) { - m_groupNameCache.insert(name); + if (!name.isEmpty()) + m_groupNameCache[name]++; + auto idx = getInstIndex(inst.get()); emit dataChanged(index(idx), index(idx), { GroupRole }); saveGroupList(); @@ -267,29 +276,55 @@ void InstanceList::setInstanceGroup(const InstanceId& id, const GroupId& name) QStringList InstanceList::getGroups() { - return m_groupNameCache.values(); + return m_groupNameCache.keys(); } -void InstanceList::deleteGroup(const QString& name) +void InstanceList::deleteGroup(const GroupId& name) { + m_groupNameCache.remove(name); + m_collapsedGroups.remove(name); + bool removed = false; qDebug() << "Delete group" << name; for (auto& instance : m_instances) { - const auto& instID = instance->id(); - auto instGroupName = getInstanceGroup(instID); + const QString& instID = instance->id(); + const QString instGroupName = getInstanceGroup(instID); if (instGroupName == name) { m_instanceGroupIndex.remove(instID); qDebug() << "Remove" << instID << "from group" << name; removed = true; auto idx = getInstIndex(instance.get()); - if (idx > 0) { + if (idx > 0) emit dataChanged(index(idx), index(idx), { GroupRole }); - } } } - if (removed) { + if (removed) saveGroupList(); +} + +void InstanceList::renameGroup(const QString& src, const QString& dst) +{ + m_groupNameCache.remove(src); + if (m_collapsedGroups.remove(src)) + m_collapsedGroups.insert(dst); + + bool modified = false; + qDebug() << "Rename group" << src << "to" << dst; + for (auto& instance : m_instances) { + const QString& instID = instance->id(); + const QString instGroupName = getInstanceGroup(instID); + if (instGroupName == src) { + m_instanceGroupIndex[instID] = dst; + m_groupNameCache[dst]++; + qDebug() << "Set" << instID << "group to" << dst; + modified = true; + auto idx = getInstIndex(instance.get()); + if (idx > 0) + emit dataChanged(index(idx), index(idx), { GroupRole }); + } } + if (modified) + saveGroupList(); } bool InstanceList::isGroupCollapsed(const QString& group) @@ -305,12 +340,15 @@ bool InstanceList::trashInstance(const InstanceId& id) return false; } - auto cachedGroupId = m_instanceGroupIndex[id]; + QString cachedGroupId = m_instanceGroupIndex[id]; qDebug() << "Will trash instance" << id; QString trashedLoc; if (m_instanceGroupIndex.remove(id)) { + if (!cachedGroupId.isEmpty() && --m_groupNameCache[cachedGroupId] == 0) + m_groupNameCache.remove(cachedGroupId); + saveGroupList(); } @@ -346,7 +384,8 @@ void InstanceList::undoTrashInstance() { QFile(top.trashPath).rename(top.polyPath); m_instanceGroupIndex[top.id] = top.groupName; - m_groupNameCache.insert(top.groupName); + if (!top.groupName.isEmpty()) + m_groupNameCache[top.groupName]++; saveGroupList(); emit instancesChanged(); @@ -360,7 +399,12 @@ void InstanceList::deleteInstance(const InstanceId& id) return; } + QString cachedGroupId = m_instanceGroupIndex[id]; + if (m_instanceGroupIndex.remove(id)) { + if (!cachedGroupId.isEmpty() && --m_groupNameCache[cachedGroupId] == 0) + m_groupNameCache.remove(cachedGroupId); + saveGroupList(); } @@ -621,7 +665,7 @@ void InstanceList::saveGroupList() QString groupFileName = m_instDir + "/instgroups.json"; QMap> reverseGroupMap; for (auto iter = m_instanceGroupIndex.begin(); iter != m_instanceGroupIndex.end(); iter++) { - QString id = iter.key(); + const QString& id = iter.key(); QString group = iter.value(); if (group.isEmpty()) continue; @@ -711,17 +755,22 @@ void InstanceList::loadGroupList() return; } - QSet groupSet; m_instanceGroupIndex.clear(); + m_groupNameCache.clear(); // Iterate through all the groups. QJsonObject groupMapping = rootObj.value("groups").toObject(); for (QJsonObject::iterator iter = groupMapping.begin(); iter != groupMapping.end(); iter++) { QString groupName = iter.key(); + if (iter.key().isEmpty()) { + qWarning() << "Redundant empty group found"; + continue; + } + // If not an object, complain and skip to the next one. if (!iter.value().isObject()) { - qWarning() << QString("Group '%1' in the group list should be an object.").arg(groupName).toUtf8(); + qWarning() << QString("Group '%1' in the group list should be an object").arg(groupName).toUtf8(); continue; } @@ -734,22 +783,19 @@ void InstanceList::loadGroupList() } // keep a list/set of groups for choosing - groupSet.insert(groupName); + m_groupNameCache[groupName]++; auto hidden = groupObj.value("hidden").toBool(false); - if (hidden) { + if (hidden) m_collapsedGroups.insert(groupName); - } // Iterate through the list of instances in the group. QJsonArray instancesArray = groupObj.value("instances").toArray(); - for (QJsonArray::iterator iter2 = instancesArray.begin(); iter2 != instancesArray.end(); iter2++) { - m_instanceGroupIndex[(*iter2).toString()] = groupName; - } + for (auto value : instancesArray) + m_instanceGroupIndex[value.toString()] = groupName; } m_groupsLoaded = true; - m_groupNameCache.unite(groupSet); qDebug() << "Group list loaded."; } @@ -924,7 +970,8 @@ bool InstanceList::commitStagedInstance(const QString& path, InstanceName const& } m_instanceGroupIndex[instID] = groupName; - m_groupNameCache.insert(groupName); + if (!groupName.isEmpty()) + m_groupNameCache[groupName]++; } instanceSet.insert(instID); diff --git a/launcher/InstanceList.h b/launcher/InstanceList.h index 48bede07d..61795d86c 100644 --- a/launcher/InstanceList.h +++ b/launcher/InstanceList.h @@ -1,16 +1,36 @@ -/* Copyright 2013-2021 MultiMC Contributors +// SPDX-License-Identifier: GPL-3.0-only +/* + * Prism Launcher - Minecraft Launcher + * Copyright (C) 2023 TheKodeToad * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, version 3. * - * http://www.apache.org/licenses/LICENSE-2.0 + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + * This file incorporates work covered by the following copyright and + * permission notice: + * + * Copyright 2013-2021 MultiMC Contributors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ #pragma once @@ -110,9 +130,10 @@ public: bool isGroupCollapsed(const QString &groupName); GroupId getInstanceGroup(const InstanceId & id) const; - void setInstanceGroup(const InstanceId & id, const GroupId& name); + void setInstanceGroup(const InstanceId & id, GroupId name); void deleteGroup(const GroupId & name); + void renameGroup(const GroupId& src, const GroupId& dst); bool trashInstance(const InstanceId &id); bool trashedSomething(); void undoTrashInstance(); @@ -187,7 +208,8 @@ private: int totalPlayTime = 0; bool m_dirty = false; QList m_instances; - QSet m_groupNameCache; + // id -> refs + QMap m_groupNameCache; SettingsObjectPtr m_globalSettings; QString m_instDir; diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index da572fc34..70a76e218 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -509,10 +509,10 @@ void MainWindow::showInstanceContextMenu(const QPoint& pos) } else { auto group = view->groupNameAt(pos); - QAction* actionVoid = new QAction(BuildConfig.LAUNCHER_DISPLAYNAME, this); + QAction* actionVoid = new QAction(group.isNull() ? BuildConfig.LAUNCHER_DISPLAYNAME : group, this); actionVoid->setEnabled(false); - QAction* actionCreateInstance = new QAction(tr("Create instance"), this); + QAction* actionCreateInstance = new QAction(tr("&Create instance"), this); actionCreateInstance->setToolTip(ui->actionAddInstance->toolTip()); if (!group.isNull()) { QVariantMap data; @@ -526,12 +526,13 @@ void MainWindow::showInstanceContextMenu(const QPoint& pos) actions.prepend(actionVoid); actions.append(actionCreateInstance); if (!group.isNull()) { - QAction* actionDeleteGroup = new QAction(tr("Delete group '%1'").arg(group), this); - QVariantMap data; - data["group"] = group; - actionDeleteGroup->setData(data); - connect(actionDeleteGroup, SIGNAL(triggered(bool)), SLOT(deleteGroup())); + QAction* actionDeleteGroup = new QAction(tr("&Delete group"), this); + connect(actionDeleteGroup, &QAction::triggered, this, [this, group] { deleteGroup(group); }); actions.append(actionDeleteGroup); + + QAction* actionRenameGroup = new QAction(tr("&Rename group"), this); + connect(actionRenameGroup, &QAction::triggered, this, [this, group] { renameGroup(group); }); + actions.append(actionRenameGroup); } } QMenu myMenu; @@ -1092,40 +1093,50 @@ void MainWindow::on_actionChangeInstGroup_triggered() if (!m_selectedInstance) return; - bool ok = false; InstanceId instId = m_selectedInstance->id(); - QString name(APPLICATION->instances()->getInstanceGroup(instId)); - auto groups = APPLICATION->instances()->getGroups(); - groups.insert(0, ""); - groups.sort(Qt::CaseInsensitive); - int foo = groups.indexOf(name); + QString src(APPLICATION->instances()->getInstanceGroup(instId)); + + QStringList groups = APPLICATION->instances()->getGroups(); + if (!groups.isEmpty()) + groups.prepend(""); + + int index = groups.indexOf(src); + bool ok = false; + QString dst = QInputDialog::getItem(this, tr("Group name"), tr("Enter a new group name."), groups, index, true, &ok); + dst = dst.simplified(); - name = QInputDialog::getItem(this, tr("Group name"), tr("Enter a new group name."), groups, foo, true, &ok); - name = name.simplified(); if (ok) { - APPLICATION->instances()->setInstanceGroup(instId, name); + APPLICATION->instances()->setInstanceGroup(instId, dst); } } -void MainWindow::deleteGroup() +void MainWindow::deleteGroup(QString group) { - QObject* obj = sender(); - if (!obj) + Q_ASSERT(!group.isEmpty()); + + const int reply = QMessageBox::question(this, tr("Delete group"), tr("Are you sure you want to delete the group '%1'?").arg(group), + QMessageBox::Yes | QMessageBox::No); + if (reply == QMessageBox::Yes) + APPLICATION->instances()->deleteGroup(group); +} + +void MainWindow::renameGroup(QString group) { + Q_ASSERT(!group.isEmpty()); + + QString name = QInputDialog::getText(this, tr("Rename group"), tr("Enter a new group name."), QLineEdit::Normal, group); + name = name.simplified(); + if (name.isNull() || name == group) return; - QAction* action = qobject_cast(obj); - if (!action) + + const bool empty = name.isEmpty(); + const bool duplicate = APPLICATION->instances()->getGroups().contains(name, Qt::CaseInsensitive) && group.toLower() != name.toLower(); + + if (empty || duplicate) { + QMessageBox::warning(this, tr("Cannot rename group"), empty ? tr("Cannot set empty name.") : tr("Group already exists. :/")); return; - auto map = action->data().toMap(); - if (!map.contains("group")) - return; - QString groupName = map["group"].toString(); - if (!groupName.isEmpty()) { - auto reply = QMessageBox::question(this, tr("Delete group"), tr("Are you sure you want to delete the group %1?").arg(groupName), - QMessageBox::Yes | QMessageBox::No); - if (reply == QMessageBox::Yes) { - APPLICATION->instances()->deleteGroup(groupName); - } } + + APPLICATION->instances()->renameGroup(group, name); } void MainWindow::undoTrashInstance() diff --git a/launcher/ui/MainWindow.h b/launcher/ui/MainWindow.h index 27c2756f6..77ed72a45 100644 --- a/launcher/ui/MainWindow.h +++ b/launcher/ui/MainWindow.h @@ -151,7 +151,8 @@ private slots: void on_actionDeleteInstance_triggered(); - void deleteGroup(); + void deleteGroup(QString group); + void renameGroup(QString group); void undoTrashInstance(); inline void on_actionExportInstance_triggered() { on_actionExportInstanceZip_triggered(); } diff --git a/launcher/ui/dialogs/CopyInstanceDialog.cpp b/launcher/ui/dialogs/CopyInstanceDialog.cpp index d75bb5fe3..ce12f605b 100644 --- a/launcher/ui/dialogs/CopyInstanceDialog.cpp +++ b/launcher/ui/dialogs/CopyInstanceDialog.cpp @@ -1,7 +1,8 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 Sefa Eyeoglu + * Copyright (C) 2023 TheKodeToad * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -61,22 +62,14 @@ CopyInstanceDialog::CopyInstanceDialog(InstancePtr original, QWidget* parent) ui->iconButton->setIcon(APPLICATION->icons()->getIcon(InstIconKey)); ui->instNameTextBox->setText(original->name()); ui->instNameTextBox->setFocus(); -#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) - auto groupList = APPLICATION->instances()->getGroups(); - QSet groups(groupList.begin(), groupList.end()); - groupList = QStringList(groups.values()); -#else - auto groups = APPLICATION->instances()->getGroups().toSet(); - auto groupList = QStringList(groups.toList()); -#endif - groupList.sort(Qt::CaseInsensitive); - groupList.removeOne(""); - groupList.push_front(""); - ui->groupBox->addItems(groupList); - int index = groupList.indexOf(APPLICATION->instances()->getInstanceGroup(m_original->id())); - if (index == -1) { + + QStringList groups = APPLICATION->instances()->getGroups(); + groups.prepend(""); + ui->groupBox->addItems(groups); + int index = groups.indexOf(APPLICATION->instances()->getInstanceGroup(m_original->id())); + if (index == -1) index = 0; - } + ui->groupBox->setCurrentIndex(index); ui->groupBox->lineEdit()->setPlaceholderText(tr("No group")); ui->copySavesCheckbox->setChecked(m_selectedOptions.isCopySavesEnabled()); diff --git a/launcher/ui/dialogs/NewInstanceDialog.cpp b/launcher/ui/dialogs/NewInstanceDialog.cpp index 7b9bb944c..30e41c09d 100644 --- a/launcher/ui/dialogs/NewInstanceDialog.cpp +++ b/launcher/ui/dialogs/NewInstanceDialog.cpp @@ -1,7 +1,8 @@ // SPDX-License-Identifier: GPL-3.0-only /* - * PolyMC - Minecraft Launcher + * Prism Launcher - Minecraft Launcher * Copyright (C) 2022 Sefa Eyeoglu + * Copyright (C) 2023 TheKodeToad * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -74,28 +75,17 @@ NewInstanceDialog::NewInstanceDialog(const QString & initialGroup, const QString InstIconKey = "default"; ui->iconButton->setIcon(APPLICATION->icons()->getIcon(InstIconKey)); -#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0) - auto groupList = APPLICATION->instances()->getGroups(); - auto groups = QSet(groupList.begin(), groupList.end()); - groupList = groups.values(); -#else - auto groups = APPLICATION->instances()->getGroups().toSet(); - auto groupList = QStringList(groups.toList()); -#endif - groupList.sort(Qt::CaseInsensitive); - groupList.removeOne(""); - groupList.push_front(initialGroup); - groupList.push_front(""); - ui->groupBox->addItems(groupList); - int index = groupList.indexOf(initialGroup); - if(index == -1) - { - index = 0; + QStringList groups = APPLICATION->instances()->getGroups(); + groups.prepend(""); + int index = groups.indexOf(initialGroup); + if (index == -1) { + index = 1; + groups.insert(index, initialGroup); } + ui->groupBox->addItems(groups); ui->groupBox->setCurrentIndex(index); ui->groupBox->lineEdit()->setPlaceholderText(tr("No group")); - // NOTE: m_buttons must be initialized before PageContainer, because it indirectly accesses m_buttons through setSuggestedPack! Do not move this below. m_buttons = new QDialogButtonBox(QDialogButtonBox::Help | QDialogButtonBox::Ok | QDialogButtonBox::Cancel); From fb5aefffb2f12562910a85f67cb1c8ca3f2ed369 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Sun, 16 Jul 2023 23:36:01 +0100 Subject: [PATCH 2/4] Reduce bugginess Signed-off-by: TheKodeToad --- launcher/InstanceList.cpp | 51 +++++++++++++++++++++++---------------- launcher/InstanceList.h | 3 +++ 2 files changed, 33 insertions(+), 21 deletions(-) diff --git a/launcher/InstanceList.cpp b/launcher/InstanceList.cpp index 6bc906ebd..d6faaaf1a 100644 --- a/launcher/InstanceList.cpp +++ b/launcher/InstanceList.cpp @@ -253,9 +253,7 @@ void InstanceList::setInstanceGroup(const InstanceId& id, GroupId name) auto iter = m_instanceGroupIndex.find(inst->id()); if (iter != m_instanceGroupIndex.end()) { if (*iter != name) { - if (!iter->isEmpty() && --m_groupNameCache[*iter] == 0) - m_groupNameCache.remove(*iter); - + decreaseGroupCount(*iter); *iter = name; changed = true; } @@ -265,9 +263,7 @@ void InstanceList::setInstanceGroup(const InstanceId& id, GroupId name) } if (changed) { - if (!name.isEmpty()) - m_groupNameCache[name]++; - + increaseGroupCount(name); auto idx = getInstIndex(inst.get()); emit dataChanged(index(idx), index(idx), { GroupRole }); saveGroupList(); @@ -315,7 +311,7 @@ void InstanceList::renameGroup(const QString& src, const QString& dst) const QString instGroupName = getInstanceGroup(instID); if (instGroupName == src) { m_instanceGroupIndex[instID] = dst; - m_groupNameCache[dst]++; + increaseGroupCount(dst); qDebug() << "Set" << instID << "group to" << dst; modified = true; auto idx = getInstIndex(instance.get()); @@ -346,9 +342,7 @@ bool InstanceList::trashInstance(const InstanceId& id) QString trashedLoc; if (m_instanceGroupIndex.remove(id)) { - if (!cachedGroupId.isEmpty() && --m_groupNameCache[cachedGroupId] == 0) - m_groupNameCache.remove(cachedGroupId); - + decreaseGroupCount(cachedGroupId); saveGroupList(); } @@ -384,8 +378,7 @@ void InstanceList::undoTrashInstance() { QFile(top.trashPath).rename(top.polyPath); m_instanceGroupIndex[top.id] = top.groupName; - if (!top.groupName.isEmpty()) - m_groupNameCache[top.groupName]++; + increaseGroupCount(top.groupName); saveGroupList(); emit instancesChanged(); @@ -402,9 +395,7 @@ void InstanceList::deleteInstance(const InstanceId& id) QString cachedGroupId = m_instanceGroupIndex[id]; if (m_instanceGroupIndex.remove(id)) { - if (!cachedGroupId.isEmpty() && --m_groupNameCache[cachedGroupId] == 0) - m_groupNameCache.remove(cachedGroupId); - + decreaseGroupCount(cachedGroupId); saveGroupList(); } @@ -654,6 +645,26 @@ InstancePtr InstanceList::loadInstance(const InstanceId& id) return inst; } + +void InstanceList::increaseGroupCount(const QString& group) +{ + if (group.isEmpty()) + return; + + ++m_groupNameCache[group]; +} + +void InstanceList::decreaseGroupCount(const QString& group) +{ + if (group.isEmpty()) + return; + + if (--m_groupNameCache[group] < 1) { + m_groupNameCache.remove(group); + m_collapsedGroups.remove(group); + } +} + void InstanceList::saveGroupList() { qDebug() << "Will save group list now."; @@ -782,9 +793,6 @@ void InstanceList::loadGroupList() continue; } - // keep a list/set of groups for choosing - m_groupNameCache[groupName]++; - auto hidden = groupObj.value("hidden").toBool(false); if (hidden) m_collapsedGroups.insert(groupName); @@ -792,8 +800,10 @@ void InstanceList::loadGroupList() // Iterate through the list of instances in the group. QJsonArray instancesArray = groupObj.value("instances").toArray(); - for (auto value : instancesArray) + for (auto value : instancesArray) { m_instanceGroupIndex[value.toString()] = groupName; + increaseGroupCount(groupName); + } } m_groupsLoaded = true; qDebug() << "Group list loaded."; @@ -970,8 +980,7 @@ bool InstanceList::commitStagedInstance(const QString& path, InstanceName const& } m_instanceGroupIndex[instID] = groupName; - if (!groupName.isEmpty()) - m_groupNameCache[groupName]++; + increaseGroupCount(groupName); } instanceSet.insert(instID); diff --git a/launcher/InstanceList.h b/launcher/InstanceList.h index 61795d86c..aaee3bb44 100644 --- a/launcher/InstanceList.h +++ b/launcher/InstanceList.h @@ -203,6 +203,9 @@ private: QList discoverInstances(); InstancePtr loadInstance(const InstanceId& id); + void increaseGroupCount(const QString& group); + void decreaseGroupCount(const QString& group); + private: int m_watchLevel = 0; int totalPlayTime = 0; From 49cebc2da48b4228d0e729298b2301c7ff281bc6 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Mon, 17 Jul 2023 12:49:12 +0100 Subject: [PATCH 3/4] More consistent behaviour Signed-off-by: TheKodeToad --- launcher/ui/MainWindow.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index 70a76e218..d1ea95d1f 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -1097,9 +1097,7 @@ void MainWindow::on_actionChangeInstGroup_triggered() QString src(APPLICATION->instances()->getInstanceGroup(instId)); QStringList groups = APPLICATION->instances()->getGroups(); - if (!groups.isEmpty()) - groups.prepend(""); - + groups.prepend(""); int index = groups.indexOf(src); bool ok = false; QString dst = QInputDialog::getItem(this, tr("Group name"), tr("Enter a new group name."), groups, index, true, &ok); From 8c30cb370676970f62a56e9f5615b22f646eb2e3 Mon Sep 17 00:00:00 2001 From: TheKodeToad Date: Tue, 29 Aug 2023 13:27:06 +0100 Subject: [PATCH 4/4] Fix CI Signed-off-by: TheKodeToad --- launcher/InstanceList.cpp | 1 - launcher/InstanceList.h | 2 +- launcher/ui/MainWindow.cpp | 5 +++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/launcher/InstanceList.cpp b/launcher/InstanceList.cpp index ef3707ec9..756ff93dd 100644 --- a/launcher/InstanceList.cpp +++ b/launcher/InstanceList.cpp @@ -645,7 +645,6 @@ InstancePtr InstanceList::loadInstance(const InstanceId& id) return inst; } - void InstanceList::increaseGroupCount(const QString& group) { if (group.isEmpty()) diff --git a/launcher/InstanceList.h b/launcher/InstanceList.h index 26aea6556..6b0bcd810 100644 --- a/launcher/InstanceList.h +++ b/launcher/InstanceList.h @@ -106,7 +106,7 @@ class InstanceList : public QAbstractListModel { bool isGroupCollapsed(const QString& groupName); GroupId getInstanceGroup(const InstanceId& id) const; - void setInstanceGroup(const InstanceId& id, const GroupId& name); + void setInstanceGroup(const InstanceId& id, GroupId name); void deleteGroup(const GroupId& name); void renameGroup(const GroupId& src, const GroupId& dst); diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index eabfe7a49..3f0e4fb2a 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -1149,12 +1149,13 @@ void MainWindow::deleteGroup(QString group) Q_ASSERT(!group.isEmpty()); const int reply = QMessageBox::question(this, tr("Delete group"), tr("Are you sure you want to delete the group '%1'?").arg(group), - QMessageBox::Yes | QMessageBox::No); + QMessageBox::Yes | QMessageBox::No); if (reply == QMessageBox::Yes) APPLICATION->instances()->deleteGroup(group); } -void MainWindow::renameGroup(QString group) { +void MainWindow::renameGroup(QString group) +{ Q_ASSERT(!group.isEmpty()); QString name = QInputDialog::getText(this, tr("Rename group"), tr("Enter a new group name."), QLineEdit::Normal, group);