void RemoveItemsCommand::redo() { KnobItemsTablePtr model = _items.begin()->item->getModel(); KnobTableItemPtr nextItem; { KnobTableItemPtr item = _items.back().item; assert(item); int index = item->getIndexInParent(); std::vector<KnobTableItemPtr> topLevel = model->getTopLevelItems(); if (!topLevel.empty()) { if (index + 1 < (int)topLevel.size()) { nextItem = topLevel[index + 1]; } else { if (topLevel[0] != item) { nextItem = topLevel[0]; } } } } model->beginEditSelection(); model->clearSelection(eTableChangeReasonInternal); for (std::list<ItemToRemove>::const_iterator it = _items.begin(); it != _items.end(); ++it) { model->removeItem(it->item, eTableChangeReasonInternal); } if (nextItem) { model->addToSelection(nextItem, eTableChangeReasonInternal); } model->endEditSelection(eTableChangeReasonInternal); model->getNode()->getApp()->triggerAutoSave(); }
void AddItemsCommand::undo() { KnobItemsTablePtr model = _items.front().item->getModel(); model->beginEditSelection(); for (std::list<ItemToAdd>::const_iterator it = _items.begin(); it != _items.end(); ++it) { model->removeItem(it->item, eTableChangeReasonInternal); } model->endEditSelection(eTableChangeReasonInternal); model->getNode()->getApp()->triggerAutoSave(); }