mirror of
https://github.com/PrismLauncher/PrismLauncher.git
synced 2025-04-29 22:24:26 +02:00
Only call on interactive uses
Signed-off-by: Yihe Li <winmikedows@hotmail.com>
This commit is contained in:
parent
ea44c2465c
commit
8fea37b8b7
@ -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();
|
||||
|
@ -126,6 +126,9 @@ class BaseInstance : public QObject, public std::enable_shared_from_this<BaseIns
|
||||
QString name() const;
|
||||
void setName(QString val);
|
||||
|
||||
/// Sync name and rename instance dir accordingly; returns true if successful
|
||||
bool syncInstanceDirName() const;
|
||||
|
||||
/// Value used for instance window titles
|
||||
QString windowTitle() const;
|
||||
|
||||
|
@ -93,8 +93,7 @@ bool askToUpdateInstanceDirName(InstancePtr instance, QWidget* parent)
|
||||
return false;
|
||||
|
||||
// Now we can confirm that a renaming is happening
|
||||
auto ret = QFile::rename(oldRoot, newRoot);
|
||||
if (!ret) {
|
||||
if (!instance->syncInstanceDirName()) {
|
||||
QMessageBox::warning(parent, QObject::tr("Cannot rename instance"),
|
||||
QObject::tr("An error occurred when performing the following renaming operation: <br/>"
|
||||
" - Old instance root: %1<br/>"
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user