void AddItemsCommand::redo() { KnobItemsTablePtr model = _items.front().item->getModel(); model->beginEditSelection(); model->clearSelection(eTableChangeReasonInternal); for (std::list<ItemToAdd>::const_iterator it = _items.begin(); it != _items.end(); ++it) { bool skipInsert = false; if (_isFirstRedo) { // The item may already be at the correct position in the parent, check it if (!it->parentItem) { if (model->getTopLevelItem(it->indexInParent) == it->item) { skipInsert = true; } } else { if (it->parentItem->getChild(it->indexInParent) == it->item) { skipInsert = true; } } } if (!skipInsert) { model->insertItem(it->indexInParent, it->item, it->parentItem, eTableChangeReasonInternal); } model->addToSelection(it->item, eTableChangeReasonInternal); } model->endEditSelection(eTableChangeReasonInternal); model->getNode()->getApp()->triggerAutoSave(); _isFirstRedo = false; }
RemoveItemsCommand::RemoveItemsCommand(const std::list<KnobTableItemPtr > &items) : UndoCommand() , _items() { assert( !items.empty() ); for (std::list<KnobTableItemPtr >::const_iterator it = items.begin(); it != items.end(); ++it) { ItemToRemove t; t.item = *it; KnobItemsTablePtr model = (*it)->getModel(); t.prevItem = model->getTopLevelItem((*it)->getIndexInParent() - 1); _items.push_back(t); } setText( tr("Remove Item(s)").toStdString() ); }