mirror of
https://github.com/TES3MP/openmw-tes3mp.git
synced 2025-01-29 06:15:32 +00:00
fixed local variable caching issue in automatic error checking (Fixes #2927)
(cherry picked from commit 7bef97bf33
)
This commit is contained in:
parent
14708e181c
commit
69e6328507
6 changed files with 55 additions and 3 deletions
|
@ -39,8 +39,6 @@ char CSMWorld::ScriptContext::getGlobalType (const std::string& name) const
|
|||
std::pair<char, bool> CSMWorld::ScriptContext::getMemberType (const std::string& name,
|
||||
const std::string& id) const
|
||||
{
|
||||
/// \todo invalidate locals cache on change to scripts
|
||||
|
||||
std::string id2 = Misc::StringUtils::lowerCase (id);
|
||||
|
||||
int index = mData.getScripts().searchId (id2);
|
||||
|
@ -120,3 +118,18 @@ void CSMWorld::ScriptContext::clear()
|
|||
mIdsUpdated = false;
|
||||
mLocals.clear();
|
||||
}
|
||||
|
||||
bool CSMWorld::ScriptContext::clearLocals (const std::string& script)
|
||||
{
|
||||
std::map<std::string, Compiler::Locals>::iterator iter =
|
||||
mLocals.find (Misc::StringUtils::lowerCase (script));
|
||||
|
||||
if (iter!=mLocals.end())
|
||||
{
|
||||
mLocals.erase (iter);
|
||||
mIdsUpdated = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -46,6 +46,9 @@ namespace CSMWorld
|
|||
|
||||
void clear();
|
||||
///< Remove all cached data.
|
||||
|
||||
/// \return Were there any locals that needed clearing?
|
||||
bool clearLocals (const std::string& script);
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -131,6 +131,11 @@ void CSVWorld::ScriptErrorTable::clear()
|
|||
setRowCount (0);
|
||||
}
|
||||
|
||||
bool CSVWorld::ScriptErrorTable::clearLocals (const std::string& script)
|
||||
{
|
||||
return mContext.clearLocals (script);
|
||||
}
|
||||
|
||||
void CSVWorld::ScriptErrorTable::cellClicked (int row, int column)
|
||||
{
|
||||
if (item (row, 1))
|
||||
|
|
|
@ -44,6 +44,11 @@ namespace CSVWorld
|
|||
|
||||
void clear();
|
||||
|
||||
/// Clear local variable cache for \a script.
|
||||
///
|
||||
/// \return Were there any locals that needed clearing?
|
||||
bool clearLocals (const std::string& script);
|
||||
|
||||
private slots:
|
||||
|
||||
void cellClicked (int row, int column);
|
||||
|
|
|
@ -89,6 +89,7 @@ CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc:
|
|||
*document.getData().getTableModel (CSMWorld::UniversalId::Type_Scripts));
|
||||
|
||||
mColumn = mModel->findColumnIndex (CSMWorld::Columns::ColumnId_ScriptText);
|
||||
mIdColumn = mModel->findColumnIndex (CSMWorld::Columns::ColumnId_Id);
|
||||
mStateColumn = mModel->findColumnIndex (CSMWorld::Columns::ColumnId_Modification);
|
||||
|
||||
QString source = mModel->data (mModel->getModelIndex (id.getId(), mColumn)).toString();
|
||||
|
@ -241,6 +242,15 @@ void CSVWorld::ScriptSubView::dataChanged (const QModelIndex& topLeft, const QMo
|
|||
|
||||
ScriptEdit::ChangeLock lock (*mEditor);
|
||||
|
||||
bool updateRequired = false;
|
||||
|
||||
for (int i=topLeft.row(); i<=bottomRight.row(); ++i)
|
||||
{
|
||||
std::string id = mModel->data (mModel->index (i, mIdColumn)).toString().toUtf8().constData();
|
||||
if (mErrors->clearLocals (id))
|
||||
updateRequired = true;
|
||||
}
|
||||
|
||||
QModelIndex index = mModel->getModelIndex (getUniversalId().getId(), mColumn);
|
||||
|
||||
if (index.row()>=topLeft.row() && index.row()<=bottomRight.row())
|
||||
|
@ -256,13 +266,28 @@ void CSVWorld::ScriptSubView::dataChanged (const QModelIndex& topLeft, const QMo
|
|||
mEditor->setPlainText (source);
|
||||
mEditor->setTextCursor (cursor);
|
||||
|
||||
recompile();
|
||||
updateRequired = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (updateRequired)
|
||||
recompile();
|
||||
}
|
||||
|
||||
void CSVWorld::ScriptSubView::rowsAboutToBeRemoved (const QModelIndex& parent, int start, int end)
|
||||
{
|
||||
bool updateRequired = false;
|
||||
|
||||
for (int i=start; i<=end; ++i)
|
||||
{
|
||||
std::string id = mModel->data (mModel->index (i, mIdColumn)).toString().toUtf8().constData();
|
||||
if (mErrors->clearLocals (id))
|
||||
updateRequired = true;
|
||||
}
|
||||
|
||||
if (updateRequired)
|
||||
recompile();
|
||||
|
||||
QModelIndex index = mModel->getModelIndex (getUniversalId().getId(), mColumn);
|
||||
|
||||
if (!parent.isValid() && index.row()>=start && index.row()<=end)
|
||||
|
|
|
@ -38,6 +38,7 @@ namespace CSVWorld
|
|||
CSMDoc::Document& mDocument;
|
||||
CSMWorld::IdTable *mModel;
|
||||
int mColumn;
|
||||
int mIdColumn;
|
||||
int mStateColumn;
|
||||
TableBottomBox *mBottom;
|
||||
RecordButtonBar *mButtons;
|
||||
|
|
Loading…
Reference in a new issue