diff --git a/launcher/BaseInstance.cpp b/launcher/BaseInstance.cpp index 0087b44f0..5ffbb809b 100644 --- a/launcher/BaseInstance.cpp +++ b/launcher/BaseInstance.cpp @@ -388,6 +388,17 @@ void BaseInstance::setName(QString val) emit propertiesChanged(this); } +bool BaseInstance::syncInstanceDirName() const +{ + auto oldRoot = instanceRoot(); + auto newRoot = FS::PathCombine(QFileInfo(oldRoot).dir().absolutePath(), name()); + if (oldRoot == newRoot) + return true; + if (!QFile::rename(oldRoot, newRoot)) + return false; + return true; +} + QString BaseInstance::name() const { return m_settings->get("name").toString(); diff --git a/launcher/BaseInstance.h b/launcher/BaseInstance.h index 9827a08b4..b19f1fd27 100644 --- a/launcher/BaseInstance.h +++ b/launcher/BaseInstance.h @@ -126,6 +126,9 @@ class BaseInstance : public QObject, public std::enable_shared_from_thissyncInstanceDirName()) { QMessageBox::warning(parent, QObject::tr("Cannot rename instance"), QObject::tr("An error occurred when performing the following renaming operation:
" " - Old instance root: %1
" diff --git a/launcher/ui/MainWindow.cpp b/launcher/ui/MainWindow.cpp index d5a2b477d..f357b0765 100644 --- a/launcher/ui/MainWindow.cpp +++ b/launcher/ui/MainWindow.cpp @@ -1428,6 +1428,13 @@ void MainWindow::on_actionExportInstanceFlamePack_triggered() void MainWindow::on_actionRenameInstance_triggered() { if (m_selectedInstance) { + connect(view->itemDelegate(), &QAbstractItemDelegate::closeEditor, this, [this] { + if (askToUpdateInstanceDirName(m_selectedInstance, this)) { + auto newID = m_selectedInstance->name(); + refreshInstances(); + setSelectedInstanceById(newID); + } + }, Qt::SingleShotConnection); view->edit(view->currentIndex()); } } @@ -1693,11 +1700,6 @@ void MainWindow::instanceDataChanged(const QModelIndex& topLeft, const QModelInd QItemSelection test(topLeft, bottomRight); if (test.contains(current)) { instanceChanged(current, current); - if (m_selectedInstance && askToUpdateInstanceDirName(m_selectedInstance, this)) { - auto newID = m_selectedInstance->name(); - refreshInstances(); - setSelectedInstanceById(newID); - } } }