bunch of changes, unfortunate lack of commits
[ede] / libede / src / FileSystemBox.ec
index 151df78..fda27fa 100644 (file)
@@ -8,7 +8,7 @@ static char * rootName = "File System";
 #endif
 
 private:
-define guiApp = ((GuiApplication)__thisModule);
+define guiApp = (GuiApplication)((__thisModule).application);
 define selectionColor = guiApp.currentSkin.selectionColor; //Color { 10, 36, 106 };
 
 static char * fileIconNames[] = 
@@ -50,7 +50,7 @@ static char * fileIconNames[] =
    ""
 };
 
-public enum ExplorerFileType
+public enum _FileType
 {
    none,
    
@@ -65,106 +65,945 @@ public enum ExplorerFileType
    treeLoader,
    lineNumbers;
 
+   /*property char * 
+   {
+      set
+      {
+         this = SelectByExtension(value);
+      }
+   }*/
+
+   public property bool isFolder
+   {
+      get { return this >= folder && this <= share; }
+   }
+
+   public property bool isFile
+   {
+      get { return this >= normalFile && this <= opticalMediaImageFile; }
+   }
+
+   _FileType ::SelectByExtension(char * extension)
+   {
+      if(!strcmpi(extension, "ews"))
+         return ewsFile;
+      else if(!strcmpi(extension, "epj"))
+         return epjFile;
+      else if(!strcmpi(extension, "ec"))
+         return ecFile;
+      else if(!strcmpi(extension, "eh"))
+         return ehFile;
+      else if(!strcmpi(extension, "cpp") ||
+            !strcmpi(extension, "cc") || !strcmpi(extension, "cxx"))
+         return cppFile;
+      else if(!strcmpi(extension, "hpp") ||
+            !strcmpi(extension, "hh") || !strcmpi(extension, "hxx"))
+         return hppFile;
+      else if(!strcmpi(extension, "c"))
+         return cFile;
+      else if(!strcmpi(extension, "h"))
+         return hFile;
+      else if(!strcmpi(extension, "txt") || !strcmpi(extension, "text") ||
+            !strcmpi(extension, "nfo") || !strcmpi(extension, "info"))
+         return textFile;
+      else if(!strcmpi(extension, "htm") || !strcmpi(extension, "html") ||
+            !strcmpi(extension, "css") || !strcmpi(extension, "php") ||
+            !strcmpi(extension, "js"))
+         return webFile;
+      else if(!strcmpi(extension, "bmp") || !strcmpi(extension, "pcx") ||
+            !strcmpi(extension, "jpg") || !strcmpi(extension, "jpeg") ||
+            !strcmpi(extension, "gif") || !strcmpi(extension, "png") ||
+            !strcmpi(extension, "ico"))
+         return pictureFile;
+      else if(!strcmpi(extension, "wav") || !strcmpi(extension, "mp3") ||
+            !strcmpi(extension, "ogg") || !strcmpi(extension, "snd"))
+         return soundFile;
+      else if(!strcmpi(extension, "ear") || !strcmpi(extension, "7z") ||
+            !strcmpi(extension, "rar") || !strcmpi(extension, "zip") ||
+            !strcmpi(extension, "gz") || !strcmpi(extension, "bz2") ||
+            !strcmpi(extension, "tar") || !strcmpi(extension, "arj") ||
+            !strcmpi(extension, "lza") || !strcmpi(extension, "lzh") ||
+            !strcmpi(extension, "cpio") || !strcmpi(extension, "z"))
+         return archiveFile;
+      else if(!strcmpi(extension, "cab") || !strcmpi(extension, "deb") ||
+            !strcmpi(extension, "rpm"))
+         return packageFile;
+      else if(!strcmpi(extension, "iso") || !strcmpi(extension, "mds") ||
+            !strcmpi(extension, "cue") || !strcmpi(extension, "bin") ||
+            !strcmpi(extension, "ccd") || !strcmpi(extension, "bwt") ||
+            !strcmpi(extension, "cdi") || !strcmpi(extension, "nrg"))
+         return opticalMediaImageFile;
+      return normalFile;
+   }
+};
+
+class FileSystemBoxBits
+{
+   bool foldersOnly:1, filesOnly:1, details:1, pathColumn:1, treeBranches:1, previewPictures:1, navigateFolders:1, autoLoad:1;
+   bool preview:1;
+   //bool header:1, freeSelect:1, fullRowSelect:1, multiSelect:1, autoScroll:1, alwaysHL : 1, moveRows:1, resizable:1;
+   //bool moveFields:1, clearHeader:1, alwaysEdit:1, collapse:1, treeBranch:1, rootCollapse:1, heightSet:1;
+   //bool sortable:1, noDragging:1, fillLastField:1, expandOnAdd:1;
+};
+
+public class FileSystemBox : Window // should we not derive from ListBox instead?
+                                    // I say we should, but we can't right now...
+                                    // because ListBox (inside ecere library) is
+                                    // not exposing enough internal machinery...
+                                    // could we not have a different private and
+                                    // public mechanism when deriving a class than
+                                    // we do when simply instanciating a class?
+/*
+   this stuff from the listbox would be nicely exposed...
+      fullRowSelect = false;
+      treeBranches = true;
+      collapseControl = true;
+      rootCollapseButton = true;
+      sortable = true;
+*/
+{
+   borderStyle = deep;
+   hasHorzScroll = false;
+   hasVertScroll = false;
+
+   menu = Menu { };
+
+public:
+   FileSystemNode root;
+   FileSystemBoxSelection selection { };
+
+   virtual bool Window::NotifyNodeSelect(FileSystemBox box, FileSystemBoxSelection selection);
+   //virtual bool Window::NotifyNodeNavigate(FileSystemBox box, FileSystemNode node);
+   virtual bool Window::NotifyNodeOpen(FileSystemBox box, FileSystemBoxSelection selection);
+   
+   property char * path
+   {
+      set
+      {
+         delete path;
+         if(value && value[0])
+            path = CopyString(value);
+         if(locationBox)
+            locationBox.path = value;
+         if(created)
+            Load();
+      }
+
+      get { return path; }
+      //isset { return path && path[0]; }
+   }
+
+   property bool foldersOnly { set { bits.foldersOnly = value; bits.filesOnly = !value; } get { return bits.foldersOnly; } };
+   property bool filesOnly { set { bits.filesOnly = value; bits.foldersOnly = !value; } get { return bits.filesOnly; } };
+   property bool previewPictures { set { bits.previewPictures = value; } get { return bits.previewPictures; } };
+   property char * extensions { set { delete extensions; if(value && value[0]) extensions = CopyString(value); } get { return extensions; } }
+   property bool details { set { bits.details = value; ChangeViewType(); } get { return bits.details; } };
+   property bool pathColumn { set { bits.pathColumn = value; ChangeViewType(); } get { return bits.pathColumn; } };
+   property bool treeBranches
+   {
+      set
+      {
+         bits.treeBranches = value;
+         list.treeBranches = value;
+         list.collapseControl = value;
+         list.rootCollapseButton = value;
+      }
+      get { return bits.treeBranches; }
+   };
+   property Color selectionColor { set { list.selectionColor = value; } get { return list.selectionColor; }/* isset { return selectionColor ? true : false; }*/ };
+   property Color selectionText  { set { list.selectionText = value; } get { return list.selectionText; }/* isset { return selectionText ? true : false; }*/ };
+   property bool navigateFolders { set { bits.navigateFolders = value; bits.filesOnly = !value; } get { return bits.navigateFolders; } };
+   property bool multiSelect { set { list.multiSelect = value; } get { return list.multiSelect; } };
+   property bool autoLoad { set { bits.autoLoad = value; } get { return bits.autoLoad; } };
+   property bool hasHeader { set { list.hasHeader = value; } get { return list.hasHeader; } };
+   property bool preview
+   {
+      set
+      {
+         bits.preview = value;
+         split.leftPane = value ? list : null;
+         split.visible = value;
+         show.visible = value;
+      }
+      get { return bits.preview; }
+   };
+   
+   property FileSystemNode node
+   {
+      get
+      {
+         if(!list)
+            return null;
+         if(!list.currentRow)
+            return null;
+         if(!list.currentRow.tag)
+            return null;
+         return (FileSystemNode)list.currentRow.tag;
+      }
+   }
+
+   PathBox locationBox;
+
+   void Select(FileSystemNode node)
+   {
+      if(node.row)
+      {
+         node.EnsureVisible(false);
+         list.SelectRow(node.row);
+      }
+   }
+
+   void SelectMultipleByPath(Array<String> paths)
+   {
+      DataRow row;
+      bool firstRow = false;
+      Map<String, bool> map { };
+      for(path : paths)
+         map[path] = true;
+      for(row = list.firstRow; row; row = row.next)
+      {
+         FileSystemNode node = (FileSystemNode)row.tag;
+         if(map[node.path])
+         {
+            if(!firstRow)
+            {
+               list.SelectRow(row);
+               firstRow = true;
+            }
+            else
+               row.selected = true;
+         }
+         else
+            row.selected = false;
+      }
+      delete map;
+   }
+
+   FileSystemNode SelectLocation(char * location)
+   {
+      int c;
+      char * temp;
+      char step[MAX_LOCATION];
+
+      //StringArray steps { growingFactor = 4 };
+      Array<String> steps { };
+      FileSystemNode result = null;
+      FileSystemNode node = null;
+
+      temp = CopyString(location);
+      while(temp[0])
+      {
+         GetLastDirectory(temp, step);
+         StripLastDirectory(temp, temp);
+         steps.Add(CopyString(step));
+      }
+
+      for(c = steps.count - 1; c >= 0; c--)
+      {
+         char * t = steps[c];
+         node = Find(steps[c], node);
+         if(!node)
+            break;
+         //Select(node);
+      }
+      if(node)
+      {
+         result = node;
+         Select(result);
+      }
+
+      steps.Free();
+      delete temp;
+      delete steps;
+
+      return result;
+   }
+
+   FileSystemNode Find(const char * name, FileSystemNode parent)
+   {
+      FileSystemNode node = null;
+      FileSystemNode result = null;
+      if(!parent/* && !strcmp(name, "/")*/)
+      {
+         DataRow row;
+         for(row = list.firstRow; row; row = row.next)
+         {
+            node = (FileSystemNode)row.tag;
+            if(node.name && !fstrcmp(node.name, name))
+               break;
+         }
+         if(node)
+            result = node;
+         //result = root;
+      }
+      else
+      {
+         FileSystemNode start = parent ? parent : root;
+         if(!start.bits.loaded || !start.bits.childrenLoaded)
+            LoadTreeNode(start);
+         for(node = start.children.first; node; node = node.next)
+            if(node.name && !fstrcmp(node.name, name))
+               break;
+         if(node)
+            result = node;
+      }
+      return result;
+   }
+
+   void Clear()
+   {
+      list.Clear();
+   }
+
+   void Refresh()
+   {
+      Load();
+   }
+
+private:
+   FileSystemBoxBits bits;
+
+   char * path;
+   char * extensions;
+
+   BitmapResource fileIcons[_FileType];
+
+   Bitmap bitmap;
+   //BitmapArray bitmaps { growingFactor = 16 };
+
+   FileSystemBox()
+   {
+      char wd[MAX_LOCATION];
+      GetWorkingDir(wd, sizeof(wd));
+      property::path = wd;
+      
+      InitFileIcons();
+      list.AddField(nameField);
+      bits.autoLoad = true;
+   }
+
+   ~FileSystemBox()
+   {
+      delete extensions;
+      delete path;
+   }
+
+   watch(background)
+   {
+      list.background = background;
+   };
+
+   void InitFileIcons()
+   {
+      _FileType c;
+      for(c = 0; c < _FileType::enumSize; c++)
+      {
+         fileIcons[c] = BitmapResource { fileIconNames[c], alphaBlend = true };
+         AddResource(fileIcons[c]);
+      }
+   }
+
+   DataField nameField { header = "Name", dataType = "FileSystemNode", width = 240, userData = this, freeData = false };
+   DataField pathField { header = "Location", dataType = /*"String"*/ "char *", width = 300, freeData = false };
+   DataField typeField { header = "Type", dataType = /*"String"*/ "char *", width = 40, freeData = false };
+   DataField sizeField { header = "Size", dataType = "FileSize", width = 96, alignment = right, freeData = false };
+   DataField modifiedField { header = "Modified", dataType = "SecSince1970", width = 96, alignment = right, freeData = false };
+
+   bool OnPostCreate()
+   {
+      if(bits.autoLoad)
+         Load();
+      return true;
+   }
+
+   ListBox list
+   {
+      this;
+
+      borderStyle = none;
+      hasHorzScroll = true;
+      hasVertScroll = true;
+      fullRowSelect = false;
+      sortable = true;
+      alwaysHighLight = true;
+
+      anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
+
+      // WHY is this not working ?
+      /*void OnResize(int width, int height)
+      {
+         if(vertScroll.visible)
+            nameField.width = width - vertScroll.size.w;
+         else
+            nameField.width = width;
+      }*/
+
+      bool NotifyCollapse(ListBox listBox, DataRow row, bool collapsed)
+      {
+         if(row)
+         {
+            FileSystemNode node = (FileSystemNode)row.tag;
+            FileSystemNode child;
+            if(collapsed)
+            {
+               /*
+               for(child = node.children.last; child; child = node.children.last)
+               {
+                  listBox.DeleteRow(child.row);
+                  child.Free();
+                  delete child;
+               }
+               node.childrenLoaded = false;
+               */
+            }
+            else
+            {
+               if(!node.bits.loaded || !node.bits.childrenLoaded)
+               {
+                  LoadTreeNode(node);
+                  //list.Sort(nameField, 1);
+                  //node.
+               }
+               for(child = node.children.first; child && child.next; child = child.next);
+               if(child)
+                  child.EnsureVisible(false);
+            }
+         }
+         return true;
+      }
+      
+      bool NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods)
+      {
+         DataRow row = listBox.currentRow;
+         if(row)
+         {
+            FileSystemNode node = (FileSystemNode)row.tag;
+            if(node)
+            {
+               char * text;
+
+               PopupMenu popup;
+               Menu menu { };
+
+               text = PrintString("Open ", node.path);
+
+               MenuItem { menu, text, o, NotifySelect = MenuOpen, disabled = false };
+               MenuItem { menu, "Cut\tCtrl+X", t, NotifySelect = null, disabled = false };
+               MenuItem { menu, "Copy\tCtrl+C", c, NotifySelect = null, disabled = false };
+               MenuItem { menu, "Paste\tCtrl+V", p, NotifySelect = null, disabled = false /*!clipboard*/ };
+               MenuItem { menu, "Delete\tDel", d, NotifySelect = null, disabled = false };
+               //MenuDivider { menu };
+
+               popup = PopupMenu
+                  {
+                     master = this, menu = menu,
+                     position = { 
+                        x + clientStart.x + absPosition.x - guiApp.desktop.position.x, 
+                        y + clientStart.y + absPosition.y - guiApp.desktop.position.y }
+                  };
+               popup.Create();
+            }
+         }
+         return true;
+      }
+
+      bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
+      {
+         OldList rows;
+         OldLink item;
+
+         selection.nodes.Free();
+         list.GetMultiSelection(rows);
+         for(item = rows.first; item; item = item.next)
+         {
+            DataRow row = item.data;
+            FileSystemNode node = (FileSystemNode)row.tag;
+            selection.nodes.Add(node);
+            incref node;
+         }
+         rows.Free(null);
+         if(row)
+            selection.node = (FileSystemNode)row.tag;
+         else
+            selection.node = null;
+
+         if(selection.node && bits.preview)
+         {
+            //int pos;
+            FileSystemNode node = selection.node;
+            /*if(bitmap)
+               bitmap.Free();*/
+            delete bitmap;
+            if(node && node.type == pictureFile)
+            {
+               bitmap = Bitmap { };
+               bitmap.Load(node.path, null, displaySystem);
+            }
+
+            /*bitmaps.Clear();
+            bitmaps = BitmapArray { };
+            for(pos = 0; pos < selectedItems.count; pos++)
+            {
+               Bitmap bitmap { };
+               selItem = (ExplorerFileItem)selectedItems._[pos];
+               bitmap.Load(selItem.path, null, displaySystem);
+               //bitmaps.Add(bitmap);
+            }
+            if(node && node.type == pictureFile)
+            {
+               bitmap = Bitmap { };
+               bitmap.Load(node.path, null, displaySystem);
+            }*/
+
+            show.Update(null);
+            //NotifyItemSelect(master, view, item, selectedItems);
+         }
+
+         NotifyNodeSelect(listBox.parent.master, this, selection);
+         return true;
+      }
+
+      bool NotifyEditing(ListBox listBox, DataRow row)
+      {
+         if(row)
+         {
+            FileSystemNode node = (FileSystemNode)row.tag;
+         }
+         return true;
+      }
+
+      bool NotifyEdited(ListBox listBox, DataRow row)
+      {
+         if(row)
+         {
+            FileSystemNode node = (FileSystemNode)row.tag;
+         }
+         return true;
+      }
+
+      bool NotifyEditDone(ListBox listBox, DataRow row)
+      {
+         if(row)
+         {
+            FileSystemNode node = (FileSystemNode)row.tag;
+         }
+         return true;
+      }
+
+      bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
+      {
+         bool result = !(selection.node && selection.node.type.isFolder && bits.navigateFolders);
+         OpenNode();
+         return result;
+      }
+
+      bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
+      {
+         bool result;
+         if((SmartKey)key == enter)
+            result = OpenNode();
+         else
+            result = true;
+         return true;
+      }
+   };
+
+   PaneSplitter split
+   {
+      this;
+      //leftPane = list;
+      rightPane = show;
+      //split = 200;
+      scaleSplit = 0.5f;
+      tabCycle = true;
+      visible = false;
+   };
+
+   Window show
+   {
+      this;
+      visible = false;
+      borderStyle = none;
+      anchor = Anchor { top = 0, right = 0, bottom = 0 };
+
+      void OnRedraw(Surface surface)
+      {
+         FileSystemBox fsb = (FileSystemBox)parent;
+         if(fsb.bitmap)
+         {
+            int wBmp = fsb.bitmap.width;
+            int hBmp = fsb.bitmap.height;
+            int wWnd = fsb.show.clientSize.w;
+            int hWnd = fsb.show.clientSize.h;
+
+            int wList = 0;//fsb.list.size.w + fsb.split.size.w;
+
+            float scale = Min((float)(wWnd - 10) / wBmp, (float)(hWnd - 10) / hBmp);
+
+            int wDraw = (int)(wBmp * scale);
+            int hDraw = (int)(hBmp * scale);
+
+      #ifndef __linux__
+            surface.Filter(fsb.bitmap, (wWnd - wDraw) / 2, (hWnd - hDraw) / 2, 0, 0, wDraw, hDraw, wBmp, hBmp);
+      #else
+            // Until Filter / Stretch works with X
+            surface.Blit(fsb.bitmap, (wWnd - wBmp) / 2, (hWnd - hBmp) / 2, 0, 0, wBmp, hBmp);
+      #endif
+         }
+         else
+         {
+            surface.SetForeground(white);
+            surface.Area(0, 0, fsb.clientSize.w - 1, fsb.clientSize.h - 1);
+         }
+      }
+   }
+
+   bool MenuOpen(MenuItem selection, Modifiers mods)
+   {
+      OpenNode();
+   }
+
+   bool OpenNode()
+   {
+      bool result;
+      FileSystemBoxSelection selection = this.selection.Copy();
+      FileSystemNode node = selection.node;
+      if(node && node.type.isFolder && bits.navigateFolders)
+         property::path = node.path;
+      result = NotifyNodeOpen(this.master, this, selection);
+      return result;
+   }
+
+   // Edit Menu
+   Menu editMenu { menu, "Edit", e };
+   MenuItem itemEditCut
+   {
+      editMenu, "Cut\tCtrl+X", t, disabled = true;
+
+      bool NotifySelect(MenuItem selection, Modifiers mods)
+      {
+         //EditCut();
+         return true;
+      }
+   };
+   MenuItem itemEditCopy
+   {
+      editMenu, "Copy\tCtrl+C", c, disabled = true;
+
+      bool NotifySelect(MenuItem selection, Modifiers mods)
+      {
+         //EditCopy();
+         return true;
+      }
+   };
+   MenuItem itemEditPaste
+   {
+      editMenu, "Paste\tCtrl+V", p;
+   
+      bool NotifySelect(MenuItem selection, Modifiers mods)
+      {
+         //EditPaste();
+         return true;
+      }
+   };
+   MenuItem itemEditDelete
+   {
+      editMenu, "Delete\tDel", d, disabled = true;
+
+      bool NotifySelect(MenuItem selection, Modifiers mods)
+      {
+         //EditDelete();
+         return true;
+      }
+   };
+
+   // WHY is this crashing ? 
+   /*void OnResize(int width, int height)
+   {
+      if(this && nameField)
+         nameField.width = width - 80;
+   }*/
+
+   void ChangeViewType()
+   {
+      list.Clear();
+      list.ClearFields();
+      list.resizable = bits.details || bits.pathColumn;
+      list.moveFields = bits.details || bits.pathColumn;
+      list.hasHeader = bits.details || bits.pathColumn;
+      list.AddField(nameField);
+      if(bits.pathColumn)
+         list.AddField(pathField);
+      if(bits.details)
+      {
+         list.AddField(typeField);
+         list.AddField(sizeField);
+         list.AddField(modifiedField);
+      }
+   }
+
+   void Load()
+   {
+      // TODO: fix this!
+      // this is crashing in for designer when details = true // can't save the file, always yields a crash
+      /*if(list && created)
+      {
+         list.ClearFields();
+         list.AddField(nameField);
+         if(bits.details)
+         {
+            list.AddField(typeField);
+            list.AddField(sizeField);
+         }
+      }*/
+      if(bits.treeBranches)
+         LoadTree();
+      else
+         LoadList();
+   }
+
+   void LoadList()
+   {
+      FileListing listing { path, extensions = extensions };
+
+      list.Clear();
+      while(listing.Find())
+      {
+         if((!bits.foldersOnly && !bits.filesOnly) ||
+            (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
+            (bits.filesOnly && listing.stats.attribs.isFile))
+         {
+            FileSystemNode node = MakeFileSystemNode(listing.stats, listing.name, listing.path, false, bits.previewPictures, displaySystem);
+            AddNode(node);
+         }
+      }
+      list.Sort(nameField, 1);
+   }
+
+   void LoadTree()
+   {
+      bool isRoot = !strcmp(path, "/");
+      char name[MAX_LOCATION];
+      FileSystemNode parent;
+      FileSystemNode node;
+      FileListing listing { path, extensions = extensions };
+
+      if(!isRoot)
+         GetLastDirectory(path, name);
+      else
+         name[0] = '\0';
+      
+      /*if(!path)
+         GetWorkingDir(startPath, sizeof(startPath));
+      else
+         strcpy(path, startPath);*/
+      
+      list.Clear();
+
+      delete root;
+   #ifdef __WIN32__
+      if(isRoot)
+      {
+         root = FileSystemNode { bits.loaded = true, bits.childrenLoaded = true };
+         AddTreeNode(root, true, false, null);
+         while(listing.Find())
+         {
+            int len = strlen(listing.name);
+            char info[MAX_LOCATION];
+            char name[MAX_LOCATION];
+            if(listing.stats.attribs.isDrive &&
+                  len > 3 && !strncmp(&listing.name[1], ": [", 3))
+            {
+               strncpy(name, listing.name, 2);
+               name[2] = 0;
+               strncpy(info, &listing.name[4], len - 5);
+               info[len - 5] = 0;
+            }
+            else
+            {
+               strcpy(name, listing.name);
+               info[0] = 0;
+            }
+
+            parent = MakeFileSystemNode(listing.stats, name, listing.path, false, bits.previewPictures, displaySystem);
+            if(info[0])
+               parent.info = info; //CopyString(info);
+            parent.bits.loaded = true;
+            AddTreeNode(parent, !listing.stats.attribs.isDirectory, listing.stats.attribs.isDirectory, root);
+            if(!listing.stats.attribs.isDirectory)
+               parent.bits.childrenLoaded = true;
+         }
+
+         node = FileSystemNode { name = msNetwork, type = network };
+         AddTreeNode(node, false, true, null);
+         node.row.collapsed = true;
+      }
+      else
+   #endif
+      {
+         root = MakeFileSystemNode(FileStats { attribs = FileExists(path)}, name, path, false, bits.previewPictures, displaySystem);
+         AddTreeNode(root, false, true, null);
+         LoadTreeNode(root);
+      }
 
-   /*property char * 
-   {
-      set
+      if(isRoot)
       {
-         this = SelectByExtension(value);
+         root.type = computer;
+         root.label = rootName;
       }
-   }*/
 
-   public property bool isFolderType
+      list.Sort(nameField, 1);
+      list.SelectRow(root.row);
+   }
+
+   void LoadTreeNode(FileSystemNode node)
    {
-      get { return this >= folder && this <= share; }
+      if(!node.bits.loaded)
+      {
+         char path[MAX_LOCATION];
+         node.GetPath(path);
+         {
+            FileListing listing { path, extensions = extensions };
+            if(node.children.count == 1)
+               DeleteNode(node.children.first);
+
+            while(listing.Find())
+            {
+               if(!listing.stats.attribs.isRemovable && ((!bits.foldersOnly && !bits.filesOnly) ||
+                  (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
+                  (bits.filesOnly && listing.stats.attribs.isFile)))
+               {
+                  FileSystemNode child = MakeFileSystemNode(listing.stats, listing.name, listing.path, false, bits.previewPictures, displaySystem);
+                  AddTreeNode(child, true, false, node);
+                  NodeChildLoad(child, node);
+               }
+            }
+         }
+         node.bits.childrenLoaded = true;
+         node.bits.loaded = true;
+         node.row.SortSubRows(false);
+      }
+      else if(!node.bits.childrenLoaded)
+      {
+         FileSystemNode child;
+         if(node.children.first)
+         {
+            for(child = node.children.first; child; child = child.next)
+            {
+               if(!child.bits.loaded)
+                  LoadTreeNode(child);
+               else if(!child.bits.childrenLoaded)
+                  NodeChildLoad(child, node);
+            }
+            node.bits.childrenLoaded = true;
+            node.row.SortSubRows(false);
+         }
+      }
    }
 
-   public property bool isFileType
+   void NodeChildLoad(FileSystemNode parent, FileSystemNode node)
    {
-      get { return this >= normalFile && this <= opticalMediaImageFile; }
+      char path[MAX_LOCATION];
+      parent.GetPath(path);
+      {
+         bool added = false;
+         FileListing listing { path, extensions = extensions };
+         while(listing.Find())
+         {
+            if((!bits.foldersOnly && !bits.filesOnly) ||
+               (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
+               (bits.filesOnly && listing.stats.attribs.isFile))
+            {
+               FileSystemNode child = MakeFileSystemNode(listing.stats, listing.name, listing.path, false, bits.previewPictures, displaySystem);
+               AddTreeNode(child, listing.stats.attribs.isFile, !listing.stats.attribs.isFile, parent);
+               added = true;
+            }
+         }
+         if(!added)
+            added = true;
+      }
+      parent.bits.childrenLoaded = true;
    }
 
-   ExplorerFileType ::SelectByExtension(char * extension)
+   void AddNode(FileSystemNode node)
    {
-      if(!strcmpi(extension, "ews"))
-         return ewsFile;
-      else if(!strcmpi(extension, "epj"))
-         return epjFile;
-      else if(!strcmpi(extension, "ec"))
-         return ecFile;
-      else if(!strcmpi(extension, "eh"))
-         return ehFile;
-      else if(!strcmpi(extension, "cpp") ||
-            !strcmpi(extension, "cc") || !strcmpi(extension, "cxx"))
-         return cppFile;
-      else if(!strcmpi(extension, "hpp") ||
-            !strcmpi(extension, "hh") || !strcmpi(extension, "hxx"))
-         return hppFile;
-      else if(!strcmpi(extension, "c"))
-         return cFile;
-      else if(!strcmpi(extension, "h"))
-         return hFile;
-      else if(!strcmpi(extension, "txt") || !strcmpi(extension, "text") ||
-            !strcmpi(extension, "nfo") || !strcmpi(extension, "info"))
-         return textFile;
-      else if(!strcmpi(extension, "htm") || !strcmpi(extension, "html") ||
-            !strcmpi(extension, "css") || !strcmpi(extension, "php") ||
-            !strcmpi(extension, "js"))
-         return webFile;
-      else if(!strcmpi(extension, "bmp") || !strcmpi(extension, "pcx") ||
-            !strcmpi(extension, "jpg") || !strcmpi(extension, "jpeg") ||
-            !strcmpi(extension, "gif") || !strcmpi(extension, "png") ||
-            !strcmpi(extension, "ico"))
-         return pictureFile;
-      else if(!strcmpi(extension, "wav") || !strcmpi(extension, "mp3") ||
-            !strcmpi(extension, "ogg") || !strcmpi(extension, "snd"))
-         return soundFile;
-      else if(!strcmpi(extension, "ear") || !strcmpi(extension, "7z") ||
-            !strcmpi(extension, "rar") || !strcmpi(extension, "zip") ||
-            !strcmpi(extension, "gz") || !strcmpi(extension, "bz2") ||
-            !strcmpi(extension, "tar") || !strcmpi(extension, "arj") ||
-            !strcmpi(extension, "lza") || !strcmpi(extension, "lzh") ||
-            !strcmpi(extension, "cpio") || !strcmpi(extension, "z"))
-         return archiveFile;
-      else if(!strcmpi(extension, "cab") || !strcmpi(extension, "deb") ||
-            !strcmpi(extension, "rpm"))
-         return packageFile;
-      else if(!strcmpi(extension, "iso") || !strcmpi(extension, "mds") ||
-            !strcmpi(extension, "cue") || !strcmpi(extension, "bin") ||
-            !strcmpi(extension, "ccd") || !strcmpi(extension, "bwt") ||
-            !strcmpi(extension, "cdi") || !strcmpi(extension, "nrg"))
-         return opticalMediaImageFile;
-      return normalFile;
+      DataRow row = list.AddRow();
+      row.tag = (int)node;
+      node.row = row;
+      incref node;
+      row.SetData(nameField, node);
+      if(bits.pathColumn)
+         row.SetData(pathField, node.path);
+      if(bits.details)
+      {
+         if(node.type.isFile)
+         {
+            row.SetData(typeField, node.extension);
+            row.SetData(sizeField, /*(void *)*/node.stats.size);
+         }
+         row.SetData(modifiedField, node.stats.modified);
+      }
    }
-};
 
-#if 0
-class ExplorerControl : Window
-{
-   bool previewPictures;
+   void AddTreeNode(FileSystemNode node, bool loaded, bool addLoader, FileSystemNode addTo)
+   {
+      DataRow row = (addTo && addTo.row) ? addTo.row.AddRow() : list.AddRow();
+      if(addTo)
+      {
+         node.parent = addTo;
+         node.indent = addTo.indent + 1;
+         addTo.children.Add(node);
+      }
+      row.tag = (int)node;
+      node.row = row;
+      row.SetData(null, node);
+      if(bits.pathColumn)
+         row.SetData(pathField, node.path);
+      if(bits.details)
+      {
+         if(node.type.isFile)
+         {
+            row.SetData(typeField, node.extension);
+            row.SetData(sizeField, /*(void *)*/node.stats.size);
+         }
+         row.SetData(modifiedField, node.stats.modified);
+      }
+
+      node.bits.loaded = loaded;
+      if(addLoader)
+         //AddTreeNode(FileSystemNode { }, false, false, node); // why would this create a compile error?
+         AddTreeNode(FileSystemNode { type = none }, false, false, node);
 
-   BitmapResource fileIcons[ExplorerFileType];
+      if(node.indent > 0)
+         row.collapsed = true;
+      else if(node.type == folder)
+         node.type = folderOpen;
+   }
 
-   ExplorerControl()
+   void DeleteNode(FileSystemNode node)
    {
-      ExplorerFileType c;
-      for(c = 0; c < ExplorerFileType::enumSize; c++)
+      FileSystemNode child;
+      if(treeBranches)
       {
-         fileIcons[c] = BitmapResource { fileIconNames[c], alphaBlend = true };
-         AddResource(fileIcons[c]);
+         for(; (child = node.children.first); )
+            DeleteNode(child);
       }
+      list.DeleteRow(node.row);
+      node.Delete();
+      //delete node;
+      //Update(null);
    }
 }
-#endif
 
+/*
 #if 0
-class ExplorerView : ExplorerControl
+class ExplorerView : FileSystemBox
 {
    borderStyle = none;
    hasHorzScroll = false;
    hasVertScroll = false;
 
-   virtual void Load(ExplorerFileBranch parent);
+   virtual void Load(FileSystemNode parent);
    virtual void Refresh();
 
    virtual void LaunchNotifyItemSelect(Window master, ExplorerView view, ExplorerFileItem item, ExplorerFileItemArray selectedItems)
@@ -233,7 +1072,7 @@ class ExplorerView : ExplorerControl
 class ExplorerViewList : ExplorerView
 {
 
-   ExplorerFileBranch location;
+   FileSystemNode location;
 
 public:
 
@@ -249,7 +1088,7 @@ public:
       Load(location);
    }
 
-   void Load(ExplorerFileBranch location)
+   void Load(FileSystemNode location)
    {
       char path[MAX_LOCATION];
       this.location = location;
@@ -284,12 +1123,12 @@ class ExplorerViewDetails : ExplorerView
    list.resizable = true;
    list.sortable = true;
 
-   ExplorerFileBranch location;
+   FileSystemNode location;
 
 public:
 
    DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
-   DataField typeField { header = "Type", dataType = /*"String"*/ "char *", width = 40 };
+   DataField typeField { header = "Type", dataType = /-*"String"*-/ "char *", width = 40 };
    DataField sizeField { header = "Size", dataType = "FileSize", width = 96, alignment = right };
 
    ExplorerViewDetails()
@@ -304,7 +1143,7 @@ public:
       Load(location);
    }
 
-   void Load(ExplorerFileBranch location)
+   void Load(FileSystemNode location)
    {
       char path[MAX_LOCATION];
       this.location = location;
@@ -337,7 +1176,7 @@ public:
 class ExplorerViewIcons : ExplorerView
 {
 
-   ExplorerFileBranch location;
+   FileSystemNode location;
 
 public:
 
@@ -353,7 +1192,7 @@ public:
       Load(location);
    }
 
-   void Load(ExplorerFileBranch location)
+   void Load(FileSystemNode location)
    {
       char path[MAX_LOCATION];
       this.location = location;
@@ -384,7 +1223,7 @@ public:
 class ExplorerViewCards : ExplorerView
 {
 
-   ExplorerFileBranch location;
+   FileSystemNode location;
 
 public:
 
@@ -400,7 +1239,7 @@ public:
       Load(location);
    }
 
-   void Load(ExplorerFileBranch location)
+   void Load(FileSystemNode location)
    {
       char path[MAX_LOCATION];
       this.location = location;
@@ -466,7 +1305,7 @@ class ExplorerViewShowcase : ExplorerView
    list.anchor = Anchor { left = 0, top = 0, bottom = 0 };
    list.size = Size { w = 200 };
 
-   ExplorerFileBranch location;
+   FileSystemNode location;
 
 public:
 
@@ -564,7 +1403,7 @@ public:
       Load(location);
    }
 
-   void Load(ExplorerFileBranch location)
+   void Load(FileSystemNode location)
    {
       char path[MAX_LOCATION];
       this.location = location;
@@ -592,7 +1431,7 @@ public:
 #endif
 
 #if 0
-class ExplorerTree : ExplorerControl
+class ExplorerTree : FileSystemBox
 {
    hasHorzScroll = false;
    hasVertScroll = false;
@@ -601,14 +1440,14 @@ class ExplorerTree : ExplorerControl
 
 public:
 
-   DataField nameField { dataType = "ExplorerFileBranch", width = 240, userData = this };
+   DataField nameField { dataType = "FileSystemNode", width = 240, userData = this };
 
-   ExplorerFileBranch root;
-   ExplorerFileBranch selection;
+   FileSystemNode root;
+   FileSystemNode selection;
 
-   virtual bool Window::NotifyBranchSelect(ExplorerTree tree, ExplorerFileBranch branch);
+   virtual bool Window::NotifyNodeSelect(ExplorerTree tree, FileSystemNode node);
    
-   property ExplorerFileBranch branch
+   property FileSystemNode node
    {
       get
       {
@@ -618,28 +1457,28 @@ public:
             return null;
          if(!tree.currentRow.tag)
             return null;
-         return (ExplorerFileBranch)tree.currentRow.tag;
+         return (FileSystemNode)tree.currentRow.tag;
       }
    }
 
-   void Select(ExplorerFileBranch branch)
+   void Select(FileSystemNode node)
    {
-      if(branch.row)
+      if(node.row)
       {
-         branch.EnsureVisible(false);
-         tree.SelectRow(branch.row);
+         node.EnsureVisible(false);
+         tree.SelectRow(node.row);
       }
    }
 
-   ExplorerFileBranch Find(const char * name, ExplorerFileBranch parent)
+   FileSystemNode Find(const char * name, FileSystemNode parent)
    {
-      ExplorerFileBranch branch;
-      ExplorerFileBranch start = parent ? parent : root;
+      FileSystemNode node;
+      FileSystemNode start = parent ? parent : root;
       if(!start.loaded || !start.childrenLoaded)
-         BranchLoad(start, tree);
-      for(branch = start.children.first; branch; branch = branch.next)
-         if(branch.name && !strcmpi(branch.name, name))
-            return branch;
+         LoadTreeNode(start, tree);
+      for(node = start.children.first; node; node = node.next)
+         if(node.name && !strcmpi(node.name, name))
+            return node;
       return null;
    }
 
@@ -651,44 +1490,44 @@ public:
       hasHorzScroll = true;
       hasVertScroll = true;
       fullRowSelect = false;
-      treeBranches = true;
+      treeNodees = true;
       collapseControl = true;
       rootCollapseButton = true;
 
       anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
 
       // WHY is this not working ?
-      /*void OnResize(int width, int height)
+      /-*void OnResize(int width, int height)
       {
          if(vertScroll.visible)
             nameField.width = width - vertScroll.size.w;
          else
             nameField.width = width;
-      }*/
+      }*-/
 
       bool NotifyCollapse(ListBox listBox, DataRow row, bool collapsed)
       {
          if(row)
          {
-            ExplorerFileBranch branch = (ExplorerFileBranch)row.tag;
-            ExplorerFileBranch child;
+            FileSystemNode node = (FileSystemNode)row.tag;
+            FileSystemNode child;
             if(collapsed)
             {
-               /*
-               for(child = branch.children.last; child; child = branch.children.last)
+               /-*
+               for(child = node.children.last; child; child = node.children.last)
                {
                   listBox.DeleteRow(child.row);
                   child.Free();
                   delete child;
                }
-               branch.childrenLoaded = false;
-               */
+               node.childrenLoaded = false;
+               *-/
             }
             else
             {
-               if(!branch.loaded || !branch.childrenLoaded)
-                  BranchLoad(branch, tree);
-               for(child = branch.children.first; child && child.next; child = child.next);
+               if(!node.loaded || !node.childrenLoaded)
+                  LoadTreeNode(node, tree);
+               for(child = node.children.first; child && child.next; child = child.next);
                if(child)
                   child.EnsureVisible(false);
             }
@@ -701,15 +1540,15 @@ public:
          DataRow row = listBox.currentRow;
          if(row)
          {
-            ExplorerFileBranch branch = (ExplorerFileBranch)row.tag;
-            if(branch)
+            FileSystemNode node = (FileSystemNode)row.tag;
+            if(node)
             {
                PopupMenu popup;
                Menu menu { };
 
                MenuItem { menu, "Cut\tCtrl+X", t, NotifySelect = null, disabled = false };
                MenuItem { menu, "Copy\tCtrl+C", c, NotifySelect = null, disabled = false };
-               MenuItem { menu, "Paste\tCtrl+V", p, NotifySelect = null, disabled = false /*!clipboard*/ };
+               MenuItem { menu, "Paste\tCtrl+V", p, NotifySelect = null, disabled = false /-*!clipboard*-/ };
                MenuItem { menu, "Delete\tDel", d, NotifySelect = null, disabled = false };
                //MenuDivider { menu };
 
@@ -730,9 +1569,9 @@ public:
       {
          if(row)
          {
-            ExplorerFileBranch branch = (ExplorerFileBranch)row.tag;
-            NotifyBranchSelect(listBox.parent.master, this, branch);
-            selection = branch;
+            FileSystemNode node = (FileSystemNode)row.tag;
+            NotifyNodeSelect(listBox.parent.master, this, node);
+            selection = node;
          }
          return true;
       }
@@ -741,7 +1580,7 @@ public:
       {
          if(row)
          {
-            ExplorerFileBranch branch = (ExplorerFileBranch)row.tag;
+            FileSystemNode node = (FileSystemNode)row.tag;
          }
          return true;
       }
@@ -750,7 +1589,7 @@ public:
       {
          if(row)
          {
-            ExplorerFileBranch branch = (ExplorerFileBranch)row.tag;
+            FileSystemNode node = (FileSystemNode)row.tag;
          }
          return true;
       }
@@ -759,7 +1598,7 @@ public:
       {
          if(row)
          {
-            ExplorerFileBranch branch = (ExplorerFileBranch)row.tag;
+            FileSystemNode node = (FileSystemNode)row.tag;
          }
          return true;
       }
@@ -809,11 +1648,11 @@ public:
    };
 
    // WHY is this crashing ? 
-   /*void OnResize(int width, int height)
+   /-*void OnResize(int width, int height)
    {
       if(this && nameField)
          nameField.width = width - 80;
-   }*/
+   }*-/
 
    ExplorerTree()
    {
@@ -822,19 +1661,19 @@ public:
 
    void Load()
    {
-      ExplorerFileBranch parent;
-      ExplorerFileBranch branch;
+      FileSystemNode parent;
+      FileSystemNode node;
       FileListing listing { "/" };
 
       tree.Clear();
 
-      root = ExplorerFileBranch { type = computer, loaded = true, childrenLoaded = true };
+      root = FileSystemNode { type = computer, loaded = true, childrenLoaded = true };
    #ifdef __WIN32__
       root.name = rootName;
    #else
       root.name = "/";
    #endif
-      AddBranch(root, true, false, null, tree);
+      AddTreeNode(root, true, false, null, tree);
 
    // How can this make sense for linux? 
    #ifdef __WIN32__
@@ -857,24 +1696,24 @@ public:
             info[0] = 0;
          }
 
-         parent = MakeFileBranch(listing.stats, name);
+         parent = MakeFileSystemNode(listing.stats, name);
          if(info[0])
             parent.info = CopyString(info);
          parent.loaded = true;
-         AddBranch(parent, !listing.stats.attribs.isDirectory, listing.stats.attribs.isDirectory, root, tree);
+         AddTreeNode(parent, !listing.stats.attribs.isDirectory, listing.stats.attribs.isDirectory, root, tree);
          if(!listing.stats.attribs.isDirectory)
             parent.childrenLoaded = true;
       }
-
-      branch = ExplorerFileBranch { name = msNetwork, type = network };
-      AddBranch(branch, false, true, null, tree);
-      branch.row.collapsed = true;
+   #endif
+      node = FileSystemNode { name = msNetwork, type = network };
+      AddTreeNode(node, false, true, null, tree);
+      node.row.collapsed = true;
       tree.Sort(nameField, 1);
       tree.SelectRow(root.row);
-   #endif
    }
+}
 
-/*
+#if 0
 public class ClipBoardFiles
 {
 
@@ -927,6 +1766,7 @@ public:
       }
    }
 
+/-*
 Private Type DROPFILES
    pFiles As Long
    pt As POINTAPI
@@ -951,22 +1791,19 @@ If hGlobal Then 'if the globalalloc worked
   
   SetClipboardData CF_HDROP, hGlobal 'put files to the clipboard
 End If
-
+*-/
    bool SaveFile(const char * filePath)
    {
    }
-*/
-
-}
 #endif
 
 #if 0
-public class FileTreeBranchBSArray : ArrayBinarySorted
+public class FileTreeNodeBSArray : ArrayBinarySorted
 {
-   type = class(ExplorerFileBranch);
+   type = class(FileSystemNode);
 public:
-   ExplorerFileBranch * const _;
-   BSloc Add(ExplorerFileBranch item)
+   FileSystemNode * const _;
+   BSloc Add(FileSystemNode item)
    {
       BSloc result = Find(item);
       if(!result.valid)
@@ -976,7 +1813,7 @@ public:
       }
       return result;
    }
-   BSloc Remove(ExplorerFileBranch item)
+   BSloc Remove(FileSystemNode item)
    {
       
    }
@@ -984,19 +1821,19 @@ public:
 #endif
 
 #if 0
-public class FileTreeBranchArray : RedjArray
+public class FileTreeNodeArray : RedjArray
 {
-   type = class(ExplorerFileBranch);
+   type = class(FileSystemNode);
 public:
-   ExplorerFileBranch * const _;
-   ExplorerFileBranch * Add(ExplorerFileBranch item)
+   FileSystemNode * const _;
+   FileSystemNode * Add(FileSystemNode item)
    {
       uint pos = _count;
       Append(1);
       _[pos] = item;
       return &_[pos];
    }
-   ExplorerFileBranch * AddBefore(uint position, ExplorerFileBranch item)
+   FileSystemNode * AddBefore(uint position, FileSystemNode item)
    {
       Insert(position, 1);
       _[position] = item;
@@ -1012,12 +1849,12 @@ public class ExplorerFileItem : struct
    char * name;
    char * info;
    char * extension;
-   ExplorerFileType type;
+   _FileType type;
    int indent;
 
    Bitmap bitmap;
 
-   void OnDisplay(Surface surface, int x, int y, int width, ExplorerControl control, Alignment alignment, DataDisplayFlags displayFlags)
+   void OnDisplay(Surface surface, int x, int y, int width, FileSystemBox control, Alignment alignment, DataDisplayFlags displayFlags)
    {
       int indentSize = (displayFlags.dropBox) ? 0 : 10;
       int textOffset;
@@ -1154,7 +1991,7 @@ ExplorerFileItem MakeFileItem(const FileAttribs attribs, const char * fileName,
    
    ExplorerFileItem item { };
 
-   //if(attribs.isFile) // TODO fix this in ecere
+   //if(stats.attribs.isFile) // -- should work now
    if(attribs.isDirectory)
    {
       extension[0] = 0;
@@ -1182,7 +2019,7 @@ ExplorerFileItem MakeFileItem(const FileAttribs attribs, const char * fileName,
       //strupr(extension);
       strlwr(extension);
       
-      item.type = ExplorerFileType::SelectByExtension(extension);
+      item.type = _FileType::SelectByExtension(extension);
    }
 
    if(attribs.isDrive && 
@@ -1214,29 +2051,109 @@ ExplorerFileItem MakeFileItem(const FileAttribs attribs, const char * fileName,
    return item;
 }
 #endif
+*/
 
-#if 0
-public class ExplorerFileBranch : struct
+public class FileSystemBoxSelection
 {
-   ExplorerFileBranch prev, next;
+public:
+   FileSystemNode node;
+   Array<FileSystemNode> nodes { };
 
-   bool loaded, childrenLoaded;
-   int indent;
+private:
+   FileSystemBoxSelection Copy()
+   {
+      FileSystemBoxSelection copy { node = node };
+      for(node : nodes)
+      {
+         copy.nodes.Add(node);
+         incref node;
+      }
+      return copy;
+   }
+
+   ~FileSystemBoxSelection()
+   {
+      nodes.Free();
+   }
+}
+
+class FileSystemNodeBits
+{
+   bool loaded:1, childrenLoaded:1, displayPath:1;
+};
+
+public class FileSystemNode
+{
+
+private:
+   FileSystemNodeBits bits;
+   char * path;
    char * name;
+   char * extension;
+   char * label;
    char * info;
+
+   ~FileSystemNode()
+   {
+      Free();
+   }
+
+public:
+   /*//LinkElement<FileSystemNode> link;
+   FileSystemNode parent;
+
+   FileSystemNodeType type;
+
+   char * name;*/
+
+   FileSystemNode prev, next;
+
+   int indent;
+
+   property char * path
+   {
+      set { delete path; if(value && value[0]) path = CopyString(value); }
+      get { return path; } isset { return path && path[0]; }
+   }
+   property char * name
+   {
+      set { delete name; if(value && value[0]) name = CopyString(value); }
+      get { return name; } isset { return name && name[0]; }
+   }
+   property char * extension
+   {
+      set { delete extension; if(value && value[0]) extension = CopyString(value); }
+      get { return extension; } isset { return extension && extension[0]; }
+   }
+   property char * label
+   {
+      set { delete label; if(value && value[0]) label = CopyString(value); }
+      get { return label; } isset { return label && label[0]; }
+   }
+   property char * info
+   {
+      set { delete info; if(value && value[0]) info = CopyString(value); }
+      get { return info; } isset { return info && info[0]; }
+   }
+
    DataRow row;
    OldList children;
-   ExplorerFileType type;
-   ExplorerFileBranch parent;
+   _FileType type;
+   FileSystemNode parent;
 
    FileStats stats;
 
+   Bitmap bitmap;
+
    void GetPath(String outputPath)
    {  
-      ExplorerFileBranch up;
-      if(parent)
+      if(path)
+         strcpy(outputPath, path);
+      else if(parent)
       {
-         strcpy(outputPath, name);
+         FileSystemNode up;
+         if(name)
+            strcpy(outputPath, name);
          for(up = parent; up; up = up.parent)
          {
             char temp[MAX_LOCATION];
@@ -1244,41 +2161,44 @@ public class ExplorerFileBranch : struct
             PathCat(temp, outputPath);
             strcpy(outputPath, temp);
          }
+         /*else
+         {
+   /-*#ifdef __WIN32__
+            strcpy(outputPath, "/");
+   #else*-/
+            //strcpy(outputPath, name);
+            strcpy(outputPath, path);
+            PathCat(outputPath, name);
+   //#endif
+         }*/
       }
-      else
-#ifdef __WIN32__
-         strcpy(outputPath, "/");
-#else
-         strcpy(outputPath, name);
-#endif
-
    }
 
-   bool IsChildOf(ExplorerFileBranch branch)
+   bool IsChildOf(FileSystemNode node)
    {
-      ExplorerFileBranch test;
+      FileSystemNode test;
       for(test = parent; test; test = test.parent)
-         if(test == branch)
+         if(test == node)
             return true;
       return false;
    }
 
-   void DuplicateChildren(bool recursive, bool forceExpanded, ExplorerFileBranch addTo, ListBox tree)
+   void DuplicateChildren(bool recursive, bool forceExpanded, FileSystemNode addTo, FileSystemBox fsb)
    {
       if(children.first)
       {
-         ExplorerFileBranch child;
+         FileSystemNode child;
          
          for(child = children.first; child; child = child.next)
          {
-            ExplorerFileBranch copy { };
-            copy.name = CopyString(child.name);
+            FileSystemNode copy { };
+            copy.name = child.name; //CopyString(child.name);
             copy.type = child.type;
-            AddBranch(copy, child.loaded, false, addTo, tree);
+            fsb.AddTreeNode(copy, child.bits.loaded, false, addTo);
             if(forceExpanded)
                copy.row.collapsed = false;
             if(recursive)
-               child.DuplicateChildren(recursive, forceExpanded, copy, tree);
+               child.DuplicateChildren(recursive, forceExpanded, copy, fsb);
          }
       }
    }
@@ -1299,14 +2219,17 @@ public class ExplorerFileBranch : struct
 
    void Free()
    {
-      ExplorerFileBranch child;
+      FileSystemNode child;
       for(; (child = children.first); )
       {
          child.Free();
          children.Delete(child);
       }
       //if(name)
+      delete path;
       delete name;
+      delete extension;
+      delete label;
       delete info;
    }
 
@@ -1317,7 +2240,7 @@ public class ExplorerFileBranch : struct
          parent.children.Delete(this);
    }
 
-   void OnDisplay(Surface surface, int x, int y, int width, ExplorerControl control, Alignment alignment, DataDisplayFlags displayFlags)
+   void OnDisplay(Surface surface, int x, int y, int width, FileSystemBox fsb, Alignment alignment, DataDisplayFlags displayFlags)
    {
       //int indentSize = (displayFlags.dropBox) ? 0 : 10;
       int indent = 16;
@@ -1325,14 +2248,14 @@ public class ExplorerFileBranch : struct
       int len;
       int w, h;
       //int textOffset;
-      char label[MAX_FILENAME];
+      char string[MAX_FILENAME];
 
       Bitmap icon;
 
       if(!this)
          return;
       
-      icon = control.fileIcons[type].bitmap;
+      icon = fsb.fileIcons[type].bitmap;
       //xStart = indent * indent + x + (icon ? (icon.width + 5) : 0);
       xStart = x + (icon ? (icon.width + 5) : 0);
 
@@ -1340,10 +2263,10 @@ public class ExplorerFileBranch : struct
          return;
 
       if(info)
-         sprintf(label, "%s [%s]", name, info);
+         sprintf(string, "%s [%s]", label ? label : name, info);
       else
-         strcpy(label, name);
-      len = strlen(label);
+         strcpy(string, label ? label : name);
+      len = strlen(string);
       
       if(!icon)
       {
@@ -1354,8 +2277,9 @@ public class ExplorerFileBranch : struct
       }
       //textOffset = indent * indentSize + (icon ? (icon.width + 4) : 0);
       
+      surface.SetForeground(displayFlags.selected ? fsb.selectionText : fsb.foreground);
       surface.TextOpacity(false);
-      surface.TextExtent(label, len, &w, &h);
+      surface.TextExtent(string, len, &w, &h);
       h = Max(h, 16);
     
       // Draw the current row stipple
@@ -1365,7 +2289,7 @@ public class ExplorerFileBranch : struct
          surface.Area(xStart - 3, y, xStart + w + 1, y + h - 1);
       
       //surface.WriteTextDots(alignment, x + textOffset, y + 2, width - textOffset, name, strlen(name));
-      surface.WriteTextDots(alignment, xStart, y + 2, width, label, len);
+      surface.WriteTextDots(alignment, xStart, y + 2, width, string, len);
 
       if(!guiApp.textMode)
       {
@@ -1389,6 +2313,29 @@ public class ExplorerFileBranch : struct
 
          if(icon)
          {
+            w = icon.width;
+            h = icon.height;
+         }
+         if(type == pictureFile && fsb.previewPictures && bitmap)
+         {
+            surface.SetForeground(white);
+            surface.blend = true;
+   //#ifndef __linux__
+            //surface.Filter(bitmap, (clientSize.w - w) / 2,(clientSize.h - h) / 2, 0,0, w, h, bitmap.width, bitmap.height);
+            //surface.Filter(bitmap, x + indent/* * indentSize*/ + 2, y, 0, 0, w, h, bitmap.width, bitmap.height);
+            surface.Filter(bitmap, x,y,0,0, w, h, bitmap.width, bitmap.height);
+   //#else
+            // Until Filter / Stretch works with X
+            //surface.Blit(bitmap, (clientSize.w - bitmap.width) / 2,(clientSize.h - bitmap.height) / 2, 0,0, bitmap.width, bitmap.height);
+   //         surface.blend = true;
+            //surface.Blit(bitmap, x + indent/* * indentSize*/ + 2, y,0,0, w, h);
+            //surface.Blit(bitmap, x,y,0,0, bitmap.width, bitmap.height);
+   //#endif
+            //bitmap.Free();
+            //delete bitmap;
+         }
+         else if(icon)
+         {
             //surface.blend = true;
             //surface.alphaWrite = blend;
             surface.SetForeground(white);
@@ -1398,150 +2345,154 @@ public class ExplorerFileBranch : struct
       }
    }
 
-   int OnCompare(ExplorerFileBranch b)
+   int OnCompare(FileSystemNode b)
    {
       int result;
-      if(type == b.type || (type < folder && b.type < folder) || (type >= drive))
-         result = strcmpi(name, b.name);
+      FileSystemNode a = this;
+      if(a.type == b.type || (a.type < folder && b.type < folder) || (a.type >= drive))
+         result = strcmpi(a.name, b.name);
       else
       {
-         if(type == folder && b.type < folder) result = -1;
-         else if(type < folder && b.type == folder) result = 1;
+         if(a.type == folder && b.type < folder) result = -1;
+         else if(a.type < folder && b.type == folder) result = 1;
+         else result = 0;
       }
       return result;
    }
 
+   /*int OnCompare(FileSystemNode b)
+   {
+      int result;
+      FileSystemNode a = this;
+      if(a.parent < b.parent) result = -1;
+      else if(a.parent > b.parent) result = 1;
+      else
+         result = fstrcmp(a.name, b.name);
+      return result;
+   }*/
+
    char * OnGetString(char * tempString, FileSystemToolWindow fileSysToolWnd, bool * needClass)
    {
       return name ? name : "";
    }
-};
+}
 
-ExplorerFileBranch MakeFileBranch(const FileStats stats, const char * name)
+/*FileSystemNode MakeFileSystemNode(const FileStats stats, const char * name)
 {
-   ExplorerFileBranch fileTreeBranch { stats = stats };
-   fileTreeBranch.name = CopyString(name);
-   if(!fileTreeBranch.name)
-      fileTreeBranch.name = null;
+   FileSystemNode node { stats = stats };
+   node.name = CopyString(name);
+   if(!node.name)
+      node.name = null;
    if(stats.attribs.isDirectory)
    {
-      fileTreeBranch.type = (stats.attribs.isDrive) ? drive : folder;
-      if(stats.attribs.isServer) fileTreeBranch.type = server;
-      if(stats.attribs.isShare) fileTreeBranch.type = share;
-      if(stats.attribs.isCDROM) fileTreeBranch.type = cdrom;
-      if(stats.attribs.isRemote) fileTreeBranch.type = netDrive;
+      node.type = (stats.attribs.isDrive) ? drive : folder;
+      if(stats.attribs.isServer) node.type = server;
+      if(stats.attribs.isShare) node.type = share;
+      if(stats.attribs.isCDROM) node.type = cdrom;
+      if(stats.attribs.isRemote) node.type = netDrive;
       if(stats.attribs.isRemovable) 
       {
          if(name[0] == 'A' || name[0] == 'B')
-            fileTreeBranch.type = floppy;
+            node.type = floppy;
          else
-            fileTreeBranch.type = removable;
+            node.type = removable;
       }
    }
    else
    {
       char extension[MAX_EXTENSION];
-      GetExtension(fileTreeBranch.name, extension);
-      fileTreeBranch.type = ExplorerFileType::SelectByExtension(extension);
-   }
-   return fileTreeBranch;
-}
-
-void AddBranch(ExplorerFileBranch branch, bool loaded, bool addLoader, ExplorerFileBranch addTo, ListBox tree)
+      GetExtension(node.name, extension);
+      node.type = _FileType::SelectByExtension(extension);
+   }
+   return node;
+}*/
+
+FileSystemNode MakeFileSystemNode(
+   const FileStats stats,
+   const char * name,
+   const char * path,
+   const bool pathAddName,
+   const bool previewPicture,
+   const DisplaySystem displaySystem)
 {
-   DataRow row = (addTo && addTo.row) ? addTo.row.AddRow() : tree.AddRow();
-   if(addTo)
-   {
-      branch.parent = addTo;
-      branch.indent = addTo.indent + 1;
-      addTo.children.Add(branch);
-   }
-   row.tag = (int)branch;
-   branch.row = row;
-   row.SetData(null, branch);
-
-   branch.loaded = loaded;
-   if(addLoader)
-      //AddBranch(ExplorerFileBranch { }, false, false, branch, tree); // why would this create a compile error?
-      AddBranch(ExplorerFileBranch { type = none }, false, false, branch, tree);
-
-   if(branch.indent > 0)
-      row.collapsed = true;
-   else if(branch.type == folder)
-      branch.type = folderOpen;
-}
+   int len = strlen(name);
+   char info[MAX_LOCATION];
+   char name2[MAX_LOCATION];
+   char extension[MAX_EXTENSION];
+   
+   FileSystemNode node { stats = stats };
 
-void BranchLoad(ExplorerFileBranch branch, ListBox tree)
-{
-   if(!branch.loaded)
+   /*if(!pathAddName)
    {
-      char path[MAX_LOCATION];
-      branch.GetPath(path);
-      {
-         FileListing listing { path };
-         if(branch.children.count == 1)
-         DeleteBranch(branch.children.first, tree);
+      char o[MAX_LOCATION];
+      //char r[MAX_LOCATION];
+      //StripLastDirectory(path, o);
+      GetLastDirectory(path, o);
+      if(fstrcmp(name, o))
+      //if(!FileExists(path))
+         PrintLn("Stop!");
+   }*/
+   //if(stats.attribs.isFile) // TODO fix this in ecere -- WTH -- this has been fixed :/
+   if(stats.attribs.isDirectory)
+   {
+      extension[0] = '\0';
 
-         while(listing.Find())
-         {
-            if(listing.stats.attribs.isDirectory)
-            {
-               ExplorerFileBranch child = MakeFileBranch(listing.stats, listing.name);
-               AddBranch(child, true, false, branch, tree);
-               BranchChildLoad(child, branch, tree);
-            }
-         }
+      node.type = (stats.attribs.isDrive) ? drive : folder;
+      if(stats.attribs.isServer) node.type = server;
+      if(stats.attribs.isShare) node.type = share;
+      if(stats.attribs.isCDROM) node.type = cdrom;
+      if(stats.attribs.isRemote) node.type = netDrive;
+      if(stats.attribs.isRemovable) 
+      {
+         if(name[0] == 'A' || name[0] == 'B')
+            node.type = floppy;
+         else
+            node.type = removable;
       }
-      branch.childrenLoaded = true;
-      branch.loaded = true;
-      branch.row.SortSubRows(false);
    }
-   else if(!branch.childrenLoaded)
+   else
    {
-      ExplorerFileBranch child;
-      if(branch.children.first)
-      {
-         for(child = branch.children.first; child; child = child.next)
-         {
-            if(!child.loaded)
-               BranchLoad(child, tree);
-            else if(!child.childrenLoaded)
-               BranchChildLoad(child, branch, tree);
-         }
-         branch.childrenLoaded = true;
-         branch.row.SortSubRows(false);
-      }
+      GetExtension(name, extension);
+      strlwr(extension);
+      
+      node.type = _FileType::SelectByExtension(extension);
    }
-}
 
-static void BranchChildLoad(ExplorerFileBranch parent, ExplorerFileBranch branch, ListBox tree)
-{
-   char path[MAX_LOCATION];
-   parent.GetPath(path);
+   if(stats.attribs.isDrive && 
+         len > 3 && !strncmp(&name[1], ": [", 3))
    {
-      bool added = false;
-      FileListing listing { path };
-      while(listing.Find())
-      {
-         if(listing.stats.attribs.isDirectory)
-         {
-            ExplorerFileBranch child = MakeFileBranch(listing.stats, listing.name);
-            AddBranch(child, true, false, parent, tree);
-            added = true;
-         }
-      }
-      if(!added)
-         added = true;
+      strncpy(name2, name, 2);
+      name2[2] = 0;
+      strncpy(info, &name[4], len - 5);
+      info[len - 5] = 0;
+   }
+   else
+   {
+      strcpy(name2, name);
+      info[0] = 0;
    }
-   //parent.childrenLoaded = true;
-}
 
-void DeleteBranch(ExplorerFileBranch branch, ListBox tree)
-{
-   ExplorerFileBranch child;
-   for(; (child = branch.children.first); )
-      DeleteBranch(child, tree);
-   tree.DeleteRow(branch.row);
-   branch.Delete();
+   if(pathAddName)
+   {
+      bool isFile = stats.attribs.isFile;
+      bool isFolder = stats.attribs.isDirectory;
+      char full[MAX_LOCATION];
+      strcpy(full, path);
+      PathCat(full, name);
+      node.path = full; //CopyString(full);
+   }
+   else
+      node.path = path; //CopyString(path);
+   node.name = name2; //CopyString(name2);
+   if(info[0])
+      node.info = info; //CopyString(info);
+   node.extension = extension; //CopyString(extension);
+
+   if(node.type == pictureFile && previewPicture)
+   {
+      node.bitmap = Bitmap { alphaBlend = true };
+      node.bitmap.Load(path, null, displaySystem);
+   }
+
+   return node;
 }
-#endif