MCPcopy Create free account
hub / github.com/ModOrganizer2/modorganizer / rename

Method rename

src/instancemanagerdialog.cpp:411–462  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

409}
410
411void InstanceManagerDialog::rename()
412{
413 auto* i = singleSelection();
414 if (!i) {
415 return;
416 }
417
418 const auto selIndex = singleSelectionIndex();
419
420 auto& m = InstanceManager::singleton();
421 if (i->isActive()) {
422 QMessageBox::information(this, tr("Rename instance"),
423 tr("The active instance cannot be renamed."));
424 return;
425 }
426
427 // getting new name
428 const auto newName = getInstanceName(this, tr("Rename instance"), "",
429 tr("Instance name"), i->displayName());
430
431 if (newName.isEmpty()) {
432 return;
433 }
434
435 // renaming
436 const QString src = i->directory();
437 const QString dest =
438 QDir::toNativeSeparators(QFileInfo(src).dir().path() + "/" + newName);
439
440 log::info("renaming {} to {}", src, dest);
441
442 const auto r = shell::Rename(QFileInfo(src), QFileInfo(dest), false);
443
444 if (!r) {
445 QMessageBox::critical(this, tr("Error"),
446 tr("Failed to rename \"%1\" to \"%2\": %3")
447 .arg(src)
448 .arg(dest)
449 .arg(r.toString()));
450
451 return;
452 }
453
454 // updating ui
455 auto newInstance = std::make_unique<Instance>(dest, false);
456 i = newInstance.get();
457
458 m_model->item(selIndex)->setText(newName);
459 m_instances[selIndex] = std::move(newInstance);
460
461 fillData(*i);
462}
463
464void InstanceManagerDialog::exploreLocation()
465{

Callers

nothing calls this directly

Calls 8

getInstanceNameFunction · 0.85
isActiveMethod · 0.45
displayNameMethod · 0.45
isEmptyMethod · 0.45
directoryMethod · 0.45
toStringMethod · 0.45
getMethod · 0.45
setTextMethod · 0.45

Tested by

no test coverage detected