bunch of changes, unfortunate lack of commits
[ede] / libede / src / FileSystemBox.ec
index 09466a9..fda27fa 100644 (file)
@@ -8,7 +8,7 @@ static char * rootName = "File System";
 #endif
 
 private:
-define guiApp = ((GuiApplication)__thisModule);  // how to do this in a dll?
+define guiApp = (GuiApplication)((__thisModule).application);
 define selectionColor = guiApp.currentSkin.selectionColor; //Color { 10, 36, 106 };
 
 static char * fileIconNames[] = 
@@ -139,13 +139,20 @@ public enum _FileType
 
 class FileSystemBoxBits
 {
-   bool foldersOnly:1, filesOnly:1, details:1, treeBranches:1, previewPictures:1, navigateFolders:1;
+   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;
@@ -163,10 +170,11 @@ public class FileSystemBox : Window // should we not derive from ListBox instead
 
 public:
    FileSystemNode root;
-   FileSystemNode selection;
+   FileSystemBoxSelection selection { };
 
-   virtual bool Window::NotifyNodeSelect(FileSystemBox box, FileSystemNode node);
-   virtual bool Window::NotifyNodeOpen(FileSystemBox box, FileSystemNode node);
+   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
    {
@@ -189,7 +197,8 @@ public:
    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; } get { return bits.details; } };
+   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
@@ -201,7 +210,23 @@ public:
       }
       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
    {
@@ -228,16 +253,106 @@ public:
       }
    }
 
+   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;
-      FileSystemNode start = parent ? parent : root;
-      if(!start.loaded || !start.childrenLoaded)
-         LoadTreeNode(start);
-      for(node = start.children.first; node; node = node.next)
-         if(node.name && !strcmpi(node.name, name))
-            return node;
-      return null;
+      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()
@@ -253,6 +368,9 @@ private:
 
    BitmapResource fileIcons[_FileType];
 
+   Bitmap bitmap;
+   //BitmapArray bitmaps { growingFactor = 16 };
+
    FileSystemBox()
    {
       char wd[MAX_LOCATION];
@@ -261,12 +379,20 @@ private:
       
       InitFileIcons();
       list.AddField(nameField);
+      bits.autoLoad = true;
    }
+
    ~FileSystemBox()
    {
       delete extensions;
       delete path;
    }
+
+   watch(background)
+   {
+      list.background = background;
+   };
+
    void InitFileIcons()
    {
       _FileType c;
@@ -277,13 +403,16 @@ private:
       }
    }
 
-   DataField nameField { dataType = "FileSystemNode", width = 240, userData = this, freeData = false };
+   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()
    {
-      Load();
+      if(bits.autoLoad)
+         Load();
       return true;
    }
 
@@ -296,6 +425,7 @@ private:
       hasVertScroll = true;
       fullRowSelect = false;
       sortable = true;
+      alwaysHighLight = true;
 
       anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
 
@@ -328,7 +458,7 @@ private:
             }
             else
             {
-               if(!node.loaded || !node.childrenLoaded)
+               if(!node.bits.loaded || !node.bits.childrenLoaded)
                {
                   LoadTreeNode(node);
                   //list.Sort(nameField, 1);
@@ -350,9 +480,14 @@ private:
             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*/ };
@@ -374,12 +509,57 @@ private:
 
       bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
       {
-         if(row)
+         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;
-            NotifyNodeSelect(listBox.parent.master, this, node);
-            selection = node;
+            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;
       }
 
@@ -412,7 +592,9 @@ private:
 
       bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
       {
-         return OpenNode();
+         bool result = !(selection.node && selection.node.type.isFolder && bits.navigateFolders);
+         OpenNode();
+         return result;
       }
 
       bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
@@ -426,16 +608,69 @@ private:
       }
    };
 
-   bool OpenNode()
+   PaneSplitter split
    {
-      bool result;
-      if(selection && selection.type.isFolder && bits.navigateFolders)
+      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)
       {
-         property::path = selection.path;
-         result = true;
+         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);
+         }
       }
-      else
-         result = NotifyNodeOpen(this.master, this, selection);
+   }
+
+   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;
    }
 
@@ -489,6 +724,24 @@ private:
          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!
@@ -518,17 +771,10 @@ private:
       {
          if((!bits.foldersOnly && !bits.filesOnly) ||
             (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
-            (bits.filesOnly && !listing.stats.attribs.isDirectory/*listing.stats.attribs.isFile*/)) // TOCHECK: isFile broken?
+            (bits.filesOnly && listing.stats.attribs.isFile))
          {
-            FileSystemNode node = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
-            DataRow row = list.AddRow();
-            row.tag = (int)node;
-            row.SetData(nameField, node);
-            if(bits.details)
-            {
-               row.SetData(typeField, node.extension);
-               row.SetData(sizeField, (void *)node.stats.size);
-            }
+            FileSystemNode node = MakeFileSystemNode(listing.stats, listing.name, listing.path, false, bits.previewPictures, displaySystem);
+            AddNode(node);
          }
       }
       list.Sort(nameField, 1);
@@ -537,10 +783,15 @@ private:
    void LoadTree()
    {
       bool isRoot = !strcmp(path, "/");
-      //char startPath[MAX_LOCATION];
+      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));
@@ -553,7 +804,7 @@ private:
    #ifdef __WIN32__
       if(isRoot)
       {
-         root = FileSystemNode { loaded = true, childrenLoaded = true };
+         root = FileSystemNode { bits.loaded = true, bits.childrenLoaded = true };
          AddTreeNode(root, true, false, null);
          while(listing.Find())
          {
@@ -574,13 +825,13 @@ private:
                info[0] = 0;
             }
 
-            parent = MakeFileSystemNode(listing.stats, name, listing.path, bits.previewPictures, displaySystem);
+            parent = MakeFileSystemNode(listing.stats, name, listing.path, false, bits.previewPictures, displaySystem);
             if(info[0])
-               parent.info = CopyString(info);
-            parent.loaded = true;
+               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.childrenLoaded = true;
+               parent.bits.childrenLoaded = true;
          }
 
          node = FileSystemNode { name = msNetwork, type = network };
@@ -590,7 +841,7 @@ private:
       else
    #endif
       {
-         root = MakeFileSystemNode(FileStats { attribs = FileExists(path)}, path, path, bits.previewPictures, displaySystem);
+         root = MakeFileSystemNode(FileStats { attribs = FileExists(path)}, name, path, false, bits.previewPictures, displaySystem);
          AddTreeNode(root, false, true, null);
          LoadTreeNode(root);
       }
@@ -598,7 +849,7 @@ private:
       if(isRoot)
       {
          root.type = computer;
-         root.name = rootName;
+         root.label = rootName;
       }
 
       list.Sort(nameField, 1);
@@ -607,44 +858,44 @@ private:
 
    void LoadTreeNode(FileSystemNode node)
    {
-      if(!node.loaded)
+      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);
+               DeleteNode(node.children.first);
 
             while(listing.Find())
             {
-               if((!bits.foldersOnly && !bits.filesOnly) ||
+               if(!listing.stats.attribs.isRemovable && ((!bits.foldersOnly && !bits.filesOnly) ||
                   (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
-                  (bits.filesOnly && !listing.stats.attribs.isDirectory/*listing.stats.attribs.isFile*/)) // TOCHECK: isFile broken?
+                  (bits.filesOnly && listing.stats.attribs.isFile)))
                {
-                  FileSystemNode child = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
+                  FileSystemNode child = MakeFileSystemNode(listing.stats, listing.name, listing.path, false, bits.previewPictures, displaySystem);
                   AddTreeNode(child, true, false, node);
                   NodeChildLoad(child, node);
                }
             }
          }
-         node.childrenLoaded = true;
-         node.loaded = true;
+         node.bits.childrenLoaded = true;
+         node.bits.loaded = true;
          node.row.SortSubRows(false);
       }
-      else if(!node.childrenLoaded)
+      else if(!node.bits.childrenLoaded)
       {
          FileSystemNode child;
          if(node.children.first)
          {
             for(child = node.children.first; child; child = child.next)
             {
-               if(!child.loaded)
+               if(!child.bits.loaded)
                   LoadTreeNode(child);
-               else if(!child.childrenLoaded)
+               else if(!child.bits.childrenLoaded)
                   NodeChildLoad(child, node);
             }
-            node.childrenLoaded = true;
+            node.bits.childrenLoaded = true;
             node.row.SortSubRows(false);
          }
       }
@@ -661,17 +912,37 @@ private:
          {
             if((!bits.foldersOnly && !bits.filesOnly) ||
                (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
-               (bits.filesOnly && !listing.stats.attribs.isDirectory/*listing.stats.attribs.isFile*/)) // TOCHECK: isFile broken?
+               (bits.filesOnly && listing.stats.attribs.isFile))
             {
-               FileSystemNode child = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
-               AddTreeNode(child, true, false, parent);
+               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.childrenLoaded = true;
+      parent.bits.childrenLoaded = true;
+   }
+
+   void AddNode(FileSystemNode node)
+   {
+      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);
+      }
    }
 
    void AddTreeNode(FileSystemNode node, bool loaded, bool addLoader, FileSystemNode addTo)
@@ -686,8 +957,19 @@ private:
       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.loaded = loaded;
+      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);
@@ -701,10 +983,15 @@ private:
    void DeleteNode(FileSystemNode node)
    {
       FileSystemNode child;
-      for(; (child = node.children.first); )
-         DeleteNode(child);
+      if(treeBranches)
+      {
+         for(; (child = node.children.first); )
+            DeleteNode(child);
+      }
       list.DeleteRow(node.row);
       node.Delete();
+      //delete node;
+      //Update(null);
    }
 }
 
@@ -1704,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;
@@ -1766,9 +2053,52 @@ ExplorerFileItem MakeFileItem(const FileAttribs attribs, const char * fileName,
 #endif
 */
 
-public class FileSystemNode : struct
+public class FileSystemBoxSelection
 {
 public:
+   FileSystemNode node;
+   Array<FileSystemNode> nodes { };
+
+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;
 
@@ -1778,12 +2108,34 @@ public:
 
    FileSystemNode prev, next;
 
-   bool loaded, childrenLoaded;
    int indent;
-   char * path;
-   char * name;
-   char * extension;
-   char * info;
+
+   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;
    _FileType type;
@@ -1795,10 +2147,13 @@ public:
 
    void GetPath(String outputPath)
    {  
-      FileSystemNode 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];
@@ -1806,14 +2161,17 @@ public:
             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(FileSystemNode node)
@@ -1834,9 +2192,9 @@ public:
          for(child = children.first; child; child = child.next)
          {
             FileSystemNode copy { };
-            copy.name = CopyString(child.name);
+            copy.name = child.name; //CopyString(child.name);
             copy.type = child.type;
-            fsb.AddTreeNode(copy, child.loaded, false, addTo);
+            fsb.AddTreeNode(copy, child.bits.loaded, false, addTo);
             if(forceExpanded)
                copy.row.collapsed = false;
             if(recursive)
@@ -1868,7 +2226,10 @@ public:
          children.Delete(child);
       }
       //if(name)
+      delete path;
       delete name;
+      delete extension;
+      delete label;
       delete info;
    }
 
@@ -1887,7 +2248,7 @@ public:
       int len;
       int w, h;
       //int textOffset;
-      char label[MAX_FILENAME];
+      char string[MAX_FILENAME];
 
       Bitmap icon;
 
@@ -1902,10 +2263,10 @@ public:
          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)
       {
@@ -1916,8 +2277,9 @@ public:
       }
       //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
@@ -1927,9 +2289,9 @@ public:
          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) -- how to do this in a dll?
+      if(!guiApp.textMode)
       {
          if(displayFlags.current)
          {
@@ -2044,18 +2406,33 @@ public:
    }
    return node;
 }*/
-static FileSystemNode MakeFileSystemNode(const FileStats stats,
-      const char * fileName, const char * filePath,
-      const bool previewPicture, const DisplaySystem displaySystem)
+
+FileSystemNode MakeFileSystemNode(
+   const FileStats stats,
+   const char * name,
+   const char * path,
+   const bool pathAddName,
+   const bool previewPicture,
+   const DisplaySystem displaySystem)
 {
-   int len = strlen(fileName);
+   int len = strlen(name);
    char info[MAX_LOCATION];
-   char name[MAX_LOCATION];
+   char name2[MAX_LOCATION];
    char extension[MAX_EXTENSION];
    
    FileSystemNode node { stats = stats };
 
-   //if(stats.attribs.isFile) // TODO fix this in ecere
+   /*if(!pathAddName)
+   {
+      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';
@@ -2067,7 +2444,7 @@ static FileSystemNode MakeFileSystemNode(const FileStats stats,
       if(stats.attribs.isRemote) node.type = netDrive;
       if(stats.attribs.isRemovable) 
       {
-         if(fileName[0] == 'A' || fileName[0] == 'B')
+         if(name[0] == 'A' || name[0] == 'B')
             node.type = floppy;
          else
             node.type = removable;
@@ -2075,36 +2452,46 @@ static FileSystemNode MakeFileSystemNode(const FileStats stats,
    }
    else
    {
-      GetExtension(fileName, extension);
+      GetExtension(name, extension);
       strlwr(extension);
       
       node.type = _FileType::SelectByExtension(extension);
    }
 
    if(stats.attribs.isDrive && 
-         len > 3 && !strncmp(&fileName[1], ": [", 3))
+         len > 3 && !strncmp(&name[1], ": [", 3))
    {
-      strncpy(name, fileName, 2);
-      name[2] = 0;
-      strncpy(info, &fileName[4], len - 5);
+      strncpy(name2, name, 2);
+      name2[2] = 0;
+      strncpy(info, &name[4], len - 5);
       info[len - 5] = 0;
    }
    else
    {
-      strcpy(name, fileName);
+      strcpy(name2, name);
       info[0] = 0;
    }
 
-   node.path = CopyString(filePath);
-   node.name = CopyString(name);
+   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 = CopyString(info);
-   node.extension = CopyString(extension);
+      node.info = info; //CopyString(info);
+   node.extension = extension; //CopyString(extension);
 
    if(node.type == pictureFile && previewPicture)
    {
       node.bitmap = Bitmap { alphaBlend = true };
-      node.bitmap.Load(filePath, null, displaySystem);
+      node.bitmap.Load(path, null, displaySystem);
    }
 
    return node;