     UpdateSceneWindowNode(0, editorScene);
 
     // Clear copybuffer when whole window refreshed
-    copyBuffer.CreateRoot("none");
+    copyBuffer.Clear();
 }
 
 uint UpdateSceneWindowNode(uint itemIndex, Node@ node)


bool SceneCopy()
{
    /// \todo allow multi-copy
    if (editNode is null || !CheckSceneWindowFocus())
        return false;
    Component@ editComponent = editComponents.length == 1 ? editComponents[0] : null;

    ListView@ list = sceneWindow.GetChild("NodeList", true);

    // Copy component
    if (editNode !is null && editComponent !is null)
    {
        XMLElement rootElem = copyBuffer.CreateRoot("component");
        editComponent.SaveXML(rootElem);
        // Note: component type has to be saved manually
        rootElem.SetString("type", editComponent.typeName);
        copyBufferLocal = editComponent.id >= FIRST_LOCAL_ID;
        return true;
    }
    // Copy node. The root node can not be copied
    else if (editNode !is null && editComponent is null && editNode !is editorScene)
    {
        XMLElement rootElem = copyBuffer.CreateRoot("node");
        editNode.SaveXML(rootElem);
        copyBufferLocal = editNode.id >= FIRST_LOCAL_ID;
        copyBufferExpanded = SaveExpandedStatus(GetNodeListIndex(editNode));
        return true;
    }
    
    return false;
}

bool ScenePaste()
{
    /// \todo allow multi-paste
    if (editNode is null || !CheckSceneWindowFocus())
        return false;

    ListView@ list = sceneWindow.GetChild("NodeList", true);
    XMLElement rootElem = copyBuffer.root;
    String mode = rootElem.name;

    if (mode == "component")
    {
        BeginModify(editNode.id);

        // If this is the root node, do not allow to create duplicate scene-global components
        if (editNode is editorScene && CheckForExistingGlobalComponent(editNode, rootElem.GetAttribute("type")))
            return false;

        // If copied component was local, make the new local too
        Component@ newComponent = editNode.CreateComponent(rootElem.GetAttribute("type"), copyBufferLocal ? LOCAL :
            REPLICATED);
        if (newComponent is null)
        {
            EndModify(editNode.id);
            return false;
        }
        newComponent.LoadXML(rootElem);
        newComponent.ApplyAttributes();
        EndModify(editNode.id);

        UpdateSceneWindowNode(editNode);
        list.selection = GetComponentListIndex(newComponent);
        return true;
    }
    else if (mode == "node")
    {
        // Make the paste go always to the root node, no matter of the selected node
        BeginModify(editorScene.id);
        // If copied node was local, make the new local too
        Node@ newNode = editorScene.CreateChild("", copyBufferLocal ? LOCAL : REPLICATED);
        BeginModify(newNode.id);
        newNode.LoadXML(rootElem);
        newNode.ApplyAttributes();
        EndModify(newNode.id);
        EndModify(editorScene.id);

        uint addIndex = GetParentAddIndex(newNode);
        UpdateSceneWindowNode(addIndex, newNode);
        RestoreExpandedStatus(addIndex, copyBufferExpanded);
        list.selection = addIndex;
        return true;
    }
    
    return false;
}

bool SaveExpandedStatus(uint itemIndex)

const uint NO_ITEM = 0xffffffff;

Window@ sceneWindow;
Array<XMLFile@> copyBuffer;
bool copyBufferLocal = false;
bool copyBufferExpanded = false;

