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

Method renameMod

src/modlist.cpp:478–509  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

476}
477
478bool ModList::renameMod(int index, const QString& newName)
479{
480 QString nameFixed = newName;
481 if (!fixDirectoryName(nameFixed) || nameFixed.isEmpty()) {
482 MessageDialog::showMessage(tr("Invalid name"), nullptr);
483 return false;
484 }
485
486 if (ModList::allMods().contains(nameFixed, Qt::CaseInsensitive) &&
487 nameFixed.toLower() != ModInfo::getByIndex(index)->name().toLower()) {
488 MessageDialog::showMessage(tr("Name is already in use by another mod"), nullptr);
489 return false;
490 }
491
492 ModInfo::Ptr modInfo = ModInfo::getByIndex(index);
493 QString oldName = modInfo->name();
494 if (nameFixed != oldName) {
495 // before we rename, ensure there is no scheduled asynchronous to rewrite
496 m_Profile->cancelModlistWrite();
497
498 if (modInfo->setName(nameFixed)) {
499 // Notice there is a good chance that setName() updated the modinfo indexes
500 // the modRenamed() call will refresh the indexes in the current profile
501 // and update the modlists in all profiles
502 emit modRenamed(oldName, nameFixed);
503 }
504
505 // invalidate the currently displayed state of this list
506 notifyChange(-1);
507 }
508 return true;
509}
510
511bool ModList::setData(const QModelIndex& index, const QVariant& value, int role)
512{

Callers 2

addSeparatorActionsMethod · 0.45
addRegularActionsMethod · 0.45

Calls 5

cancelModlistWriteMethod · 0.80
isEmptyMethod · 0.45
nameMethod · 0.45
setNameMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected