import ClientFolderNode from "./ClientFolderNode.js";
import FileClipboard from "./FileClipboard.js";
import FileTree from "../../shared/FileTree.mjs";

export default class ClientFileManager extends FileTree
{
  constructor(session)
  {
    super();
    this.addEvent("click");
    this.session = session;

    this.root = new ClientFolderNode("", undefined, this);
    this.clipboard = new FileClipboard(this);
    this.listeners = [];

    this.element = document.getElementById("filetree");

    this.root.controlElement.className += " root";
    this.root.toggleDisplay();

    this.element.appendChild(this.root.controlElement);
    this.element.appendChild(this.root.listElement);
  }

  reset()
  {
    while(this.root.children.length > 0)
      this.root.children[0].destroy();
  }

  messageReceived(e)
  {
    let folder, node;

    switch(e.action) {
    case "add":
      node = this.registerNode(e.path, e.isFile);

      node.controlElement.addEventListener("click", () => this.triggerEvent("click", node));
      break;
    case "remove":
      node = this.getNode(e.path, e.isFile);

      if(node)
        node.markDeleted();
      break;
    case "move":
      folder = this.getFolder(e.parentPath);
      node = this.getNode(e.oldPath, e.isFile);
      node.name = e.newName;

      // folder might be undefined due to renaming the root node
      if(folder) {
        // detach the element for the node,
        // and orphanize it
        node.destroy();

        node.parentFolder = folder;
        folder.insertNode(node);
        node.append();
      }

      node.triggerEvent("move", e.oldPath);
      break;
    }
  }
}

@@ -834,16 +834,22 @@
 eceived(
+messag
 e)%0D%0A  %7B%0D
@@ -885,16 +885,22 @@
  switch(
+messag
 e.action
@@ -948,32 +948,38 @@
 egisterNode(
+messag
 e.path, 
 e.isFile);%0D%0A
@@ -958,32 +958,38 @@
 e(message.path, 
+messag
 e.isFile);%0D%0A%0D%0A  
@@ -1140,24 +1140,30 @@
 getNode(
+messag
 e.path, 
 e.isFile
@@ -1150,24 +1150,30 @@
 ssage.path, 
+messag
 e.isFile);%0D%0A
@@ -1281,16 +1281,22 @@
 tFolder(
+messag
 e.parent
@@ -1329,16 +1329,22 @@
 getNode(
+messag
 e.oldPat
@@ -1346,16 +1346,22 @@
 ldPath, 
+messag
 e.isFile
@@ -1721,16 +1721,22 @@
 %22move%22, 
+messag
 e.oldPat

Rename "e" to "message" in messagedReceived on the ClientFileManager for consistency