forked from mirror/openmw-tes3mp
do not allow editing of deleted scripts
This commit is contained in:
parent
8763a3b3c3
commit
f1ac440b78
4 changed files with 51 additions and 20 deletions
|
@ -100,7 +100,7 @@ void CSVWorld::ScriptErrorTable::updateUserSetting (const QString& name, const Q
|
||||||
|
|
||||||
void CSVWorld::ScriptErrorTable::update (const std::string& source)
|
void CSVWorld::ScriptErrorTable::update (const std::string& source)
|
||||||
{
|
{
|
||||||
setRowCount (0);
|
clear();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -122,6 +122,11 @@ void CSVWorld::ScriptErrorTable::update (const std::string& source)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CSVWorld::ScriptErrorTable::clear()
|
||||||
|
{
|
||||||
|
setRowCount (0);
|
||||||
|
}
|
||||||
|
|
||||||
void CSVWorld::ScriptErrorTable::cellClicked (int row, int column)
|
void CSVWorld::ScriptErrorTable::cellClicked (int row, int column)
|
||||||
{
|
{
|
||||||
if (item (row, 1))
|
if (item (row, 1))
|
||||||
|
|
|
@ -42,6 +42,8 @@ namespace CSVWorld
|
||||||
|
|
||||||
void update (const std::string& source);
|
void update (const std::string& source);
|
||||||
|
|
||||||
|
void clear();
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void cellClicked (int row, int column);
|
void cellClicked (int row, int column);
|
||||||
|
|
|
@ -38,11 +38,31 @@ void CSVWorld::ScriptSubView::addButtonBar()
|
||||||
|
|
||||||
void CSVWorld::ScriptSubView::recompile()
|
void CSVWorld::ScriptSubView::recompile()
|
||||||
{
|
{
|
||||||
if (!mCompileDelay->isActive())
|
if (!mCompileDelay->isActive() && !isDeleted())
|
||||||
mCompileDelay->start (
|
mCompileDelay->start (
|
||||||
CSMSettings::UserSettings::instance().setting ("script-editor/compile-delay").toInt());
|
CSMSettings::UserSettings::instance().setting ("script-editor/compile-delay").toInt());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool CSVWorld::ScriptSubView::isDeleted() const
|
||||||
|
{
|
||||||
|
return mModel->data (mModel->getModelIndex (getUniversalId().getId(), mStateColumn)).toInt()
|
||||||
|
==CSMWorld::RecordBase::State_Deleted;
|
||||||
|
}
|
||||||
|
|
||||||
|
void CSVWorld::ScriptSubView::updateDeletedState()
|
||||||
|
{
|
||||||
|
if (isDeleted())
|
||||||
|
{
|
||||||
|
mErrors->clear();
|
||||||
|
mEditor->setEnabled (false);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
mEditor->setEnabled (true);
|
||||||
|
recompile();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document)
|
CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document)
|
||||||
: SubView (id), mDocument (document), mColumn (-1), mBottom(0), mButtons (0),
|
: SubView (id), mDocument (document), mColumn (-1), mBottom(0), mButtons (0),
|
||||||
mCommandDispatcher (document, CSMWorld::UniversalId::getParentType (id.getType()))
|
mCommandDispatcher (document, CSMWorld::UniversalId::getParentType (id.getType()))
|
||||||
|
@ -68,16 +88,8 @@ CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc:
|
||||||
mModel = &dynamic_cast<CSMWorld::IdTable&> (
|
mModel = &dynamic_cast<CSMWorld::IdTable&> (
|
||||||
*document.getData().getTableModel (CSMWorld::UniversalId::Type_Scripts));
|
*document.getData().getTableModel (CSMWorld::UniversalId::Type_Scripts));
|
||||||
|
|
||||||
for (int i=0; i<mModel->columnCount(); ++i)
|
mColumn = mModel->findColumnIndex (CSMWorld::Columns::ColumnId_ScriptText);
|
||||||
if (mModel->headerData (i, Qt::Horizontal, CSMWorld::ColumnBase::Role_Display)==
|
mStateColumn = mModel->findColumnIndex (CSMWorld::Columns::ColumnId_Modification);
|
||||||
CSMWorld::ColumnBase::Display_ScriptFile)
|
|
||||||
{
|
|
||||||
mColumn = i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mColumn==-1)
|
|
||||||
throw std::logic_error ("Can't find script column");
|
|
||||||
|
|
||||||
QString source = mModel->data (mModel->getModelIndex (id.getId(), mColumn)).toString();
|
QString source = mModel->data (mModel->getModelIndex (id.getId(), mColumn)).toString();
|
||||||
|
|
||||||
|
@ -114,7 +126,7 @@ CSVWorld::ScriptSubView::ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc:
|
||||||
mCompileDelay->setSingleShot (true);
|
mCompileDelay->setSingleShot (true);
|
||||||
connect (mCompileDelay, SIGNAL (timeout()), this, SLOT (updateRequest()));
|
connect (mCompileDelay, SIGNAL (timeout()), this, SLOT (updateRequest()));
|
||||||
|
|
||||||
recompile();
|
updateDeletedState();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVWorld::ScriptSubView::updateUserSetting (const QString& name, const QStringList& value)
|
void CSVWorld::ScriptSubView::updateUserSetting (const QString& name, const QStringList& value)
|
||||||
|
@ -231,16 +243,21 @@ void CSVWorld::ScriptSubView::dataChanged (const QModelIndex& topLeft, const QMo
|
||||||
|
|
||||||
QModelIndex index = mModel->getModelIndex (getUniversalId().getId(), mColumn);
|
QModelIndex index = mModel->getModelIndex (getUniversalId().getId(), mColumn);
|
||||||
|
|
||||||
if (index.row()>=topLeft.row() && index.row()<=bottomRight.row() &&
|
if (index.row()>=topLeft.row() && index.row()<=bottomRight.row())
|
||||||
index.column()>=topLeft.column() && index.column()<=bottomRight.column())
|
|
||||||
{
|
{
|
||||||
QString source = mModel->data (index).toString();
|
if (mStateColumn>=topLeft.column() && mStateColumn<=bottomRight.column())
|
||||||
|
updateDeletedState();
|
||||||
|
|
||||||
QTextCursor cursor = mEditor->textCursor();
|
if (mColumn>=topLeft.column() && mColumn<=bottomRight.column())
|
||||||
mEditor->setPlainText (source);
|
{
|
||||||
mEditor->setTextCursor (cursor);
|
QString source = mModel->data (index).toString();
|
||||||
|
|
||||||
recompile();
|
QTextCursor cursor = mEditor->textCursor();
|
||||||
|
mEditor->setPlainText (source);
|
||||||
|
mEditor->setTextCursor (cursor);
|
||||||
|
|
||||||
|
recompile();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -262,6 +279,8 @@ void CSVWorld::ScriptSubView::switchToRow (int row)
|
||||||
|
|
||||||
std::vector<std::string> selection (1, id);
|
std::vector<std::string> selection (1, id);
|
||||||
mCommandDispatcher.setSelection (selection);
|
mCommandDispatcher.setSelection (selection);
|
||||||
|
|
||||||
|
updateDeletedState();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CSVWorld::ScriptSubView::switchToId (const std::string& id)
|
void CSVWorld::ScriptSubView::switchToId (const std::string& id)
|
||||||
|
|
|
@ -38,6 +38,7 @@ namespace CSVWorld
|
||||||
CSMDoc::Document& mDocument;
|
CSMDoc::Document& mDocument;
|
||||||
CSMWorld::IdTable *mModel;
|
CSMWorld::IdTable *mModel;
|
||||||
int mColumn;
|
int mColumn;
|
||||||
|
int mStateColumn;
|
||||||
TableBottomBox *mBottom;
|
TableBottomBox *mBottom;
|
||||||
RecordButtonBar *mButtons;
|
RecordButtonBar *mButtons;
|
||||||
CSMWorld::CommandDispatcher mCommandDispatcher;
|
CSMWorld::CommandDispatcher mCommandDispatcher;
|
||||||
|
@ -52,6 +53,10 @@ namespace CSVWorld
|
||||||
|
|
||||||
void recompile();
|
void recompile();
|
||||||
|
|
||||||
|
bool isDeleted() const;
|
||||||
|
|
||||||
|
void updateDeletedState();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document);
|
ScriptSubView (const CSMWorld::UniversalId& id, CSMDoc::Document& document);
|
||||||
|
|
Loading…
Reference in a new issue