diff --git a/apps/opencs/view/world/table.cpp b/apps/opencs/view/world/table.cpp index 31f7d22eda..593dc85633 100644 --- a/apps/opencs/view/world/table.cpp +++ b/apps/opencs/view/world/table.cpp @@ -113,14 +113,19 @@ void CSVWorld::Table::contextMenuEvent (QContextMenuEvent *event) QMenu menu (this); - if (mCreateAction) - menu.addAction (mCreateAction); + /// \todo add menu items for select all and clear selection - if (listRevertableSelectedIds().size()>0) - menu.addAction (mRevertAction); + if (!mEditLock) + { + if (mCreateAction) + menu.addAction (mCreateAction); - if (listDeletableSelectedIds().size()>0) - menu.addAction (mDeleteAction); + if (listRevertableSelectedIds().size()>0) + menu.addAction (mRevertAction); + + if (listDeletableSelectedIds().size()>0) + menu.addAction (mDeleteAction); + } menu.exec (event->globalPos()); } @@ -167,7 +172,7 @@ std::vector CSVWorld::Table::listDeletableSelectedIds() const CSVWorld::Table::Table (const CSMWorld::UniversalId& id, CSMWorld::Data& data, QUndoStack& undoStack, bool createAndDelete) -: mUndoStack (undoStack), mCreateAction (0) +: mUndoStack (undoStack), mCreateAction (0), mEditLock (false) { mModel = &dynamic_cast (*data.getTableModel (id)); @@ -212,50 +217,61 @@ void CSVWorld::Table::setEditLock (bool locked) { for (std::vector::iterator iter (mDelegates.begin()); iter!=mDelegates.end(); ++iter) (*iter)->setEditLock (locked); + + mEditLock = locked; } #include /// \todo remove void CSVWorld::Table::createRecord() { - /// \todo ask the user for an ID instead. - static int index = 0; + if (!mEditLock) + { + /// \todo ask the user for an ID instead. + static int index = 0; - std::ostringstream stream; - stream << "id" << index++; + std::ostringstream stream; + stream << "id" << index++; - mUndoStack.push (new CSMWorld::CreateCommand (*mProxyModel, stream.str())); + mUndoStack.push (new CSMWorld::CreateCommand (*mProxyModel, stream.str())); + } } void CSVWorld::Table::revertRecord() { - std::vector revertableIds = listRevertableSelectedIds(); - - if (revertableIds.size()>0) + if (!mEditLock) { - if (revertableIds.size()>1) - mUndoStack.beginMacro (tr ("Revert multiple records")); + std::vector revertableIds = listRevertableSelectedIds(); - for (std::vector::const_iterator iter (revertableIds.begin()); iter!=revertableIds.end(); ++iter) - mUndoStack.push (new CSMWorld::RevertCommand (*mModel, *iter)); + if (revertableIds.size()>0) + { + if (revertableIds.size()>1) + mUndoStack.beginMacro (tr ("Revert multiple records")); - if (revertableIds.size()>1) - mUndoStack.endMacro(); + for (std::vector::const_iterator iter (revertableIds.begin()); iter!=revertableIds.end(); ++iter) + mUndoStack.push (new CSMWorld::RevertCommand (*mModel, *iter)); + + if (revertableIds.size()>1) + mUndoStack.endMacro(); + } } } void CSVWorld::Table::deleteRecord() { - std::vector deletableIds = listDeletableSelectedIds(); - - if (deletableIds.size()>0) + if (!mEditLock) { - if (deletableIds.size()>1) - mUndoStack.beginMacro (tr ("Delete multiple records")); + std::vector deletableIds = listDeletableSelectedIds(); - for (std::vector::const_iterator iter (deletableIds.begin()); iter!=deletableIds.end(); ++iter) - mUndoStack.push (new CSMWorld::DeleteCommand (*mModel, *iter)); + if (deletableIds.size()>0) + { + if (deletableIds.size()>1) + mUndoStack.beginMacro (tr ("Delete multiple records")); - if (deletableIds.size()>1) - mUndoStack.endMacro(); + for (std::vector::const_iterator iter (deletableIds.begin()); iter!=deletableIds.end(); ++iter) + mUndoStack.push (new CSMWorld::DeleteCommand (*mModel, *iter)); + + if (deletableIds.size()>1) + mUndoStack.endMacro(); + } } } \ No newline at end of file diff --git a/apps/opencs/view/world/table.hpp b/apps/opencs/view/world/table.hpp index 264d2bc5c2..b58ba8328a 100644 --- a/apps/opencs/view/world/table.hpp +++ b/apps/opencs/view/world/table.hpp @@ -33,6 +33,7 @@ namespace CSVWorld QAction *mDeleteAction; CSMWorld::IdTableProxyModel *mProxyModel; CSMWorld::IdTable *mModel; + bool mEditLock; private: