forked from teamnwah/openmw-tes3coop
implemented additional check before performing replace (make sure data hasn't been changed since the search)
This commit is contained in:
parent
6fac4c5dd9
commit
ae5de0cb2b
3 changed files with 40 additions and 7 deletions
|
@ -276,4 +276,21 @@ void CSMTools::Search::replace (CSMDoc::Document& document, CSMWorld::IdTableBas
|
||||||
new CSMWorld::ModifyCommand (*model, index, QString::fromUtf8 (newText.c_str())));
|
new CSMWorld::ModifyCommand (*model, index, QString::fromUtf8 (newText.c_str())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CSMTools::Search::verify (CSMDoc::Document& document, CSMWorld::IdTableBase *model,
|
||||||
|
const CSMWorld::UniversalId& id, const std::string& messageHint) const
|
||||||
|
{
|
||||||
|
CSMDoc::Messages messages;
|
||||||
|
|
||||||
|
int row = model->getModelIndex (id.getId(),
|
||||||
|
model->findColumnIndex (CSMWorld::Columns::ColumnId_Id)).row();
|
||||||
|
|
||||||
|
searchRow (model, row, messages);
|
||||||
|
|
||||||
|
for (CSMDoc::Messages::Iterator iter (messages.begin()); iter!=messages.end(); ++iter)
|
||||||
|
if (iter->mHint==messageHint)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -88,6 +88,10 @@ namespace CSMTools
|
||||||
void replace (CSMDoc::Document& document, CSMWorld::IdTableBase *model,
|
void replace (CSMDoc::Document& document, CSMWorld::IdTableBase *model,
|
||||||
const CSMWorld::UniversalId& id, const std::string& messageHint,
|
const CSMWorld::UniversalId& id, const std::string& messageHint,
|
||||||
const std::string& replaceText) const;
|
const std::string& replaceText) const;
|
||||||
|
|
||||||
|
// Check if model still matches search results.
|
||||||
|
bool verify (CSMDoc::Document& document, CSMWorld::IdTableBase *model,
|
||||||
|
const CSMWorld::UniversalId& id, const std::string& messageHint) const;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -26,6 +26,9 @@ void CSVTools::SearchSubView::replace (bool selection)
|
||||||
|
|
||||||
bool autoDelete = CSMSettings::UserSettings::instance().setting (
|
bool autoDelete = CSMSettings::UserSettings::instance().setting (
|
||||||
"search/auto-delete", QString ("true"))=="true";
|
"search/auto-delete", QString ("true"))=="true";
|
||||||
|
|
||||||
|
CSMTools::Search search (mSearch);
|
||||||
|
CSMWorld::IdTableBase *currentTable = 0;
|
||||||
|
|
||||||
// We are running through the indices in reverse order to avoid messing up multiple results
|
// We are running through the indices in reverse order to avoid messing up multiple results
|
||||||
// in a single string.
|
// in a single string.
|
||||||
|
@ -37,14 +40,23 @@ void CSVTools::SearchSubView::replace (bool selection)
|
||||||
|
|
||||||
CSMWorld::IdTableBase *table = &dynamic_cast<CSMWorld::IdTableBase&> (
|
CSMWorld::IdTableBase *table = &dynamic_cast<CSMWorld::IdTableBase&> (
|
||||||
*mDocument.getData().getTableModel (type));
|
*mDocument.getData().getTableModel (type));
|
||||||
|
|
||||||
std::string hint = model.getHint (*iter);
|
|
||||||
|
|
||||||
mSearch.replace (mDocument, table, id, hint, replace);
|
|
||||||
mTable->flagAsReplaced (*iter);
|
|
||||||
|
|
||||||
if (autoDelete)
|
if (table!=currentTable)
|
||||||
mTable->model()->removeRows (*iter, 1);
|
{
|
||||||
|
search.configure (table);
|
||||||
|
currentTable = table;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string hint = model.getHint (*iter);
|
||||||
|
|
||||||
|
if (search.verify (mDocument, table, id, hint))
|
||||||
|
{
|
||||||
|
search.replace (mDocument, table, id, hint, replace);
|
||||||
|
mTable->flagAsReplaced (*iter);
|
||||||
|
|
||||||
|
if (autoDelete)
|
||||||
|
mTable->model()->removeRows (*iter, 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue