Example #1
0
void InventoryWindow::UpdateActions()
{
    ///\todo Cut, Copy, Paste: actionCut, actionCopy, actionCut
    InventoryAction *actionNewFolder = 0, *actionDelete = 0, *actionRename = 0,
                     *actionCopyAssetReference = 0, *actionOpen = 0, *actionProperties = 0;

    actionNewFolder = findChild<InventoryAction *>("NewFolder");
    actionDelete = findChild<InventoryAction *>("Delete");
    actionRename = findChild<InventoryAction *>("Rename");
    actionCopyAssetReference = findChild<InventoryAction *>("CopyAssetReference");
    actionOpen = findChild<InventoryAction *>("Open");
    actionProperties = findChild<InventoryAction *>("Properties");

    QModelIndex index = treeView_->selectionModel()->currentIndex();

    bool canAddFolder = !inventoryItemModel_->IsLibraryItem(index);
    if (actionNewFolder)
        actionNewFolder->setEnabled(canAddFolder);

    bool editable = treeView_->model()->flags(index) & Qt::ItemIsEditable;
    if (actionDelete)
        actionDelete->setEnabled(editable);
    if (actionRename)
        actionRename->setEnabled(editable);

    bool is_asset = inventoryItemModel_->GetItemType(index) == AbstractInventoryItem::Type_Asset;
    if (actionCopyAssetReference)
        actionCopyAssetReference->setEnabled(is_asset);
    if (actionOpen)
        actionOpen->setEnabled(is_asset);
    if (actionProperties)
        actionProperties->setEnabled(is_asset);

    bool hasCurrent = treeView_->selectionModel()->currentIndex().isValid();

    if (hasCurrent)
        treeView_->closePersistentEditor(treeView_->selectionModel()->currentIndex());
}