Revert "libede: FileSystemBox: added filesOnly option"
[ede] / libede / src / FileSystemBox.ec
1 public import "ecere"
2
3 static char * fileIconNames[] = 
4 {
5    "<:ecere>mimeTypes/file.png",         /* none */
6
7    "<:ecere>mimeTypes/file.png",         /* normalFile */
8    "<:ecere>mimeTypes/textEcereWorkspace.png",          /* ewsFile */
9    "<:ecere>mimeTypes/textEcereProject.png",      /* epjFile */
10    "<:ecere>mimeTypes/textEcereSource.png",         /* ecFile */
11    "<:ecere>mimeTypes/textEcereHeader.png",         /* ehFile */
12    "<:ecere>mimeTypes/textCSource.png",          /* cFile */
13    "<:ecere>mimeTypes/textCHeader.png",          /* hFile */
14    "<:ecere>mimeTypes/textC++Source.png",        /* cppFile */
15    "<:ecere>mimeTypes/textC++Header.png",        /* hppFile */
16    "<:ecere>mimeTypes/text.png",         /* textFile */
17    "<:ecere>mimeTypes/textHyperTextMarkup.png",              /* webFile */
18    "<:ecere>mimeTypes/image.png",        /* pictureFile */
19    "<:ecere>status/audioVolumeHigh.png",         /* soundFile */
20    "<:ecere>mimeTypes/package.png",      /* archiveFile */
21    "<:ecere>mimeTypes/packageSoftware.png",     /* packageFile */
22    "<:ecere>mimeTypes/packageOpticalDisc.png", /* opticalMediaImageFile */
23
24    "<:ecere>places/folder.png",                    /* folder */
25    "<:ecere>status/folderOpen.png",               /* folderOpen */
26    "<:ecere>devices/computer.png",                 /* computer */
27    "<:ecere>devices/driveHardDisk.png",           /* drive */
28    "<:ecere>places/driveRemote.png",              /* netDrive */
29    "<:ecere>devices/mediaOptical.png",            /* cdrom */
30    "<:ecere>devices/driveRemovableMedia.png",    /* removable */
31    "<:ecere>devices/mediaFloppy.png",             /* floppy */
32    "<:ecere>places/networkWorkgroup.png",         /* network */
33    "<:ecere>places/networkServer.png",            /* server */
34    "<:ecere>places/folderRemote.png",             /* share */
35
36    "<:ecere>mimeTypes/package.png",      /* treeLoader */
37    "<:ecere>places/startHere.png",                /* lineNumbers */
38    
39    ""
40 };
41
42 //define guiApp = ((GuiApplication)__thisModule);
43 //define selectionColor = guiApp.currentSkin.selectionColor; //Color { 10, 36, 106 };
44
45 public enum __FileType
46 {
47    none,
48    
49    normalFile, ewsFile, epjFile, ecFile, ehFile, cFile, hFile, cppFile, hppFile,
50    textFile, webFile, pictureFile, soundFile,
51    archiveFile, packageFile, opticalMediaImageFile, /* these (all previous) are sort equal */
52    
53    folder, folderOpen, computer,
54    drive, netDrive, cdrom, removable, floppy, network, server, share, // these are sort equal
55    
56    // utilities
57    treeLoader,
58    lineNumbers;
59
60    /*property char * 
61    {
62       set
63       {
64          this = SelectByExtension(value);
65       }
66    }*/
67
68    public property bool isFolder
69    {
70       get { return this >= folder && this <= share; }
71    }
72
73    public property bool isFile
74    {
75       get { return this >= normalFile && this <= opticalMediaImageFile; }
76    }
77
78    __FileType ::SelectByExtension(char * extension)
79    {
80       if(!strcmpi(extension, "ews"))
81          return ewsFile;
82       else if(!strcmpi(extension, "epj"))
83          return epjFile;
84       else if(!strcmpi(extension, "ec"))
85          return ecFile;
86       else if(!strcmpi(extension, "eh"))
87          return ehFile;
88       else if(!strcmpi(extension, "cpp") ||
89             !strcmpi(extension, "cc") || !strcmpi(extension, "cxx"))
90          return cppFile;
91       else if(!strcmpi(extension, "hpp") ||
92             !strcmpi(extension, "hh") || !strcmpi(extension, "hxx"))
93          return hppFile;
94       else if(!strcmpi(extension, "c"))
95          return cFile;
96       else if(!strcmpi(extension, "h"))
97          return hFile;
98       else if(!strcmpi(extension, "txt") || !strcmpi(extension, "text") ||
99             !strcmpi(extension, "nfo") || !strcmpi(extension, "info"))
100          return textFile;
101       else if(!strcmpi(extension, "htm") || !strcmpi(extension, "html") ||
102             !strcmpi(extension, "css") || !strcmpi(extension, "php") ||
103             !strcmpi(extension, "js"))
104          return webFile;
105       else if(!strcmpi(extension, "bmp") || !strcmpi(extension, "pcx") ||
106             !strcmpi(extension, "jpg") || !strcmpi(extension, "jpeg") ||
107             !strcmpi(extension, "gif") || !strcmpi(extension, "png") ||
108             !strcmpi(extension, "ico"))
109          return pictureFile;
110       else if(!strcmpi(extension, "wav") || !strcmpi(extension, "mp3") ||
111             !strcmpi(extension, "ogg") || !strcmpi(extension, "snd"))
112          return soundFile;
113       else if(!strcmpi(extension, "ear") || !strcmpi(extension, "7z") ||
114             !strcmpi(extension, "rar") || !strcmpi(extension, "zip") ||
115             !strcmpi(extension, "gz") || !strcmpi(extension, "bz2") ||
116             !strcmpi(extension, "tar") || !strcmpi(extension, "arj") ||
117             !strcmpi(extension, "lza") || !strcmpi(extension, "lzh") ||
118             !strcmpi(extension, "cpio") || !strcmpi(extension, "z"))
119          return archiveFile;
120       else if(!strcmpi(extension, "cab") || !strcmpi(extension, "deb") ||
121             !strcmpi(extension, "rpm"))
122          return packageFile;
123       else if(!strcmpi(extension, "iso") || !strcmpi(extension, "mds") ||
124             !strcmpi(extension, "cue") || !strcmpi(extension, "bin") ||
125             !strcmpi(extension, "ccd") || !strcmpi(extension, "bwt") ||
126             !strcmpi(extension, "cdi") || !strcmpi(extension, "nrg"))
127          return opticalMediaImageFile;
128       return normalFile;
129    }
130 };
131
132 //public enum FileSystemNodeType { file, folder, system };
133
134 define guiApp = ((GuiApplication)__thisModule);  // how to do this in a dll?
135 define selectionColor = guiApp.currentSkin.selectionColor; //Color { 10, 36, 106 };
136
137 public class FileSystemNode : struct // : struct
138 {
139 public:
140    /*//LinkElement<FileSystemNode> link;
141    FileSystemNode parent;
142
143    FileSystemNodeType type;
144
145    char * name;*/
146
147    FileSystemNode prev, next;
148
149    bool loaded, childrenLoaded;
150    int indent;
151    char * path;
152    char * name;
153    char * extension;
154    char * info;
155    DataRow row;
156    OldList children;
157    __FileType type;
158    FileSystemNode parent;
159
160    FileStats stats;
161
162    Bitmap bitmap;
163
164    void GetPath(String outputPath)
165    {  
166       FileSystemNode up;
167       if(parent)
168       {
169          strcpy(outputPath, name);
170          for(up = parent; up; up = up.parent)
171          {
172             char temp[MAX_LOCATION];
173             strcpy(temp, up.name);
174             PathCat(temp, outputPath);
175             strcpy(outputPath, temp);
176          }
177       }
178       else
179 #ifdef __WIN32__
180          strcpy(outputPath, "/");
181 #else
182          strcpy(outputPath, name);
183 #endif
184
185    }
186
187    bool IsChildOf(FileSystemNode node)
188    {
189       FileSystemNode test;
190       for(test = parent; test; test = test.parent)
191          if(test == node)
192             return true;
193       return false;
194    }
195
196    void DuplicateChildren(bool recursive, bool forceExpanded, FileSystemNode addTo, FileSystemBox fsb)
197    {
198       if(children.first)
199       {
200          FileSystemNode child;
201          
202          for(child = children.first; child; child = child.next)
203          {
204             FileSystemNode copy { };
205             copy.name = CopyString(child.name);
206             copy.type = child.type;
207             fsb.AddTreeNode(copy, child.loaded, false, addTo);
208             if(forceExpanded)
209                copy.row.collapsed = false;
210             if(recursive)
211                child.DuplicateChildren(recursive, forceExpanded, copy, fsb);
212          }
213       }
214    }
215    
216    void EnsureVisible(bool expand)
217    {
218       if(parent)
219          parent.EnsureVisible(true);
220       if(expand)
221          row.collapsed = false;
222       // TODO: row.EnsureVisible(); // making the row visible by scrolling
223    }
224
225    void OnFree()
226    {
227       //delete name;
228    }
229
230    void Free()
231    {
232       FileSystemNode child;
233       for(; (child = children.first); )
234       {
235          child.Free();
236          children.Delete(child);
237       }
238       //if(name)
239       delete name;
240       delete info;
241    }
242
243    void Delete()
244    {
245       Free();
246       if(parent)
247          parent.children.Delete(this);
248    }
249
250    void OnDisplay(Surface surface, int x, int y, int width, FileSystemBox fsb, Alignment alignment, DataDisplayFlags displayFlags)
251    {
252       //int indentSize = (displayFlags.dropBox) ? 0 : 10;
253       int indent = 16;
254       int xStart;
255       int len;
256       int w, h;
257       //int textOffset;
258       char label[MAX_FILENAME];
259
260       Bitmap icon;
261
262       if(!this)
263          return;
264       
265       icon = fsb.fileIcons[type].bitmap;
266       /*if(type == normalFile)
267          PrintLn("dd");*/
268       //xStart = indent * indent + x + (icon ? (icon.width + 5) : 0);
269       xStart = x + (icon ? (icon.width + 5) : 0);
270
271       if(!name)
272          return;
273
274       if(info)
275          sprintf(label, "%s [%s]", name, info);
276       else
277          strcpy(label, name);
278       len = strlen(label);
279       
280       if(!icon)
281       {
282          if(type == folder || type == folderOpen)
283             surface.SetForeground(yellow);
284          //indentSize = 8;
285          indent = 8;
286       }
287       //textOffset = indent * indentSize + (icon ? (icon.width + 4) : 0);
288       
289       surface.TextOpacity(false);
290       surface.TextExtent(label, len, &w, &h);
291       h = Max(h, 16);
292     
293       // Draw the current row stipple
294       if(displayFlags.selected)
295          //surface.Area(xStart - 1, y, xStart - 1, y + h - 1);
296          //surface.Area(xStart + w - 1, y, xStart + w + 1, y + h - 1);
297          surface.Area(xStart - 3, y, xStart + w + 1, y + h - 1);
298       
299       //surface.WriteTextDots(alignment, x + textOffset, y + 2, width - textOffset, name, strlen(name));
300       surface.WriteTextDots(alignment, xStart, y + 2, width, label, len);
301
302       //if(!guiApp.textMode) -- how to do this in a dll?
303       {
304          if(displayFlags.current)
305          {
306             if(displayFlags.active)
307             {
308                surface.LineStipple(0x5555);
309                if(displayFlags.selected)
310                   surface.SetForeground(0xFFFFFF80);
311                else
312                   surface.SetForeground(black);
313             }
314             else
315             {
316                surface.SetForeground(selectionColor);
317             }
318             surface.Rectangle(xStart - 3, y, xStart + w + 1, y + h - 1);
319             surface.LineStipple(0);
320          }
321
322          if(icon)
323          {
324             //surface.blend = true;
325             //surface.alphaWrite = blend;
326             surface.SetForeground(white);
327             //surface.Blit(icon, x + indent * indentSize, y,0,0, icon.width, icon.height);
328             surface.Blit(icon, x,y,0,0, icon.width, icon.height);
329          }
330       }
331    }
332
333    int OnCompare(FileSystemNode b)
334    {
335       int result;
336       FileSystemNode a = this;
337       if(a.type == b.type || (a.type < folder && b.type < folder) || (a.type >= drive))
338          result = strcmpi(a.name, b.name);
339       else
340       {
341          if(a.type == folder && b.type < folder) result = -1;
342          else if(a.type < folder && b.type == folder) result = 1;
343          else result = 0;
344       }
345       return result;
346    }
347
348    /*int OnCompare(FileSystemNode b)
349    {
350       int result;
351       FileSystemNode a = this;
352       if(a.parent < b.parent) result = -1;
353       else if(a.parent > b.parent) result = 1;
354       else
355          result = fstrcmp(a.name, b.name);
356       return result;
357    }*/
358
359    char * OnGetString(char * tempString, FileSystemToolWindow fileSysToolWnd, bool * needClass)
360    {
361       return name ? name : "";
362    }
363 }
364
365 /*FileSystemNode MakeFileSystemNode(const FileStats stats, const char * name)
366 {
367    FileSystemNode node { stats = stats };
368    node.name = CopyString(name);
369    if(!node.name)
370       node.name = null;
371    if(stats.attribs.isDirectory)
372    {
373       node.type = (stats.attribs.isDrive) ? drive : folder;
374       if(stats.attribs.isServer) node.type = server;
375       if(stats.attribs.isShare) node.type = share;
376       if(stats.attribs.isCDROM) node.type = cdrom;
377       if(stats.attribs.isRemote) node.type = netDrive;
378       if(stats.attribs.isRemovable) 
379       {
380          if(name[0] == 'A' || name[0] == 'B')
381             node.type = floppy;
382          else
383             node.type = removable;
384       }
385    }
386    else
387    {
388       char extension[MAX_EXTENSION];
389       GetExtension(node.name, extension);
390       node.type = __FileType::SelectByExtension(extension);
391    }
392    return node;
393 }*/
394 static FileSystemNode MakeFileSystemNode(const FileStats stats, const char * fileName, const char * filePath, const bool previewPicture, const DisplaySystem displaySystem)
395 {
396    int len = strlen(fileName);
397    char info[MAX_LOCATION];
398    char name[MAX_LOCATION];
399    char extension[MAX_EXTENSION];
400    
401    FileSystemNode node { stats = stats };
402
403    //if(stats.attribs.isFile) // TODO fix this in ecere
404    if(stats.attribs.isDirectory)
405    {
406       extension[0] = '\0';
407
408       node.type = (stats.attribs.isDrive) ? drive : folder;
409       if(stats.attribs.isServer) node.type = server;
410       if(stats.attribs.isShare) node.type = share;
411       if(stats.attribs.isCDROM) node.type = cdrom;
412       if(stats.attribs.isRemote) node.type = netDrive;
413       if(stats.attribs.isRemovable) 
414       {
415          if(fileName[0] == 'A' || fileName[0] == 'B')
416             node.type = floppy;
417          else
418             node.type = removable;
419       }
420    }
421    else
422    {
423       GetExtension(fileName, extension);
424       strlwr(extension);
425       
426       node.type = __FileType::SelectByExtension(extension);
427    }
428
429    if(stats.attribs.isDrive && 
430          len > 3 && !strncmp(&fileName[1], ": [", 3))
431    {
432       strncpy(name, fileName, 2);
433       name[2] = 0;
434       strncpy(info, &fileName[4], len - 5);
435       info[len - 5] = 0;
436    }
437    else
438    {
439       strcpy(name, fileName);
440       info[0] = 0;
441    }
442
443    node.path = CopyString(filePath);
444    node.name = CopyString(name);
445    if(info[0])
446       node.info = CopyString(info);
447    node.extension = CopyString(extension);
448
449    if(node.type == pictureFile && previewPicture)
450    {
451       node.bitmap = Bitmap { };
452       node.bitmap.Load(filePath, null, displaySystem);
453    }
454
455    return node;
456 }
457
458 class FileSystemBoxBits
459 {
460    bool foldersOnly:1, details:1, treeBranches:1, previewPictures:1;
461    //bool header:1, freeSelect:1, fullRowSelect:1, multiSelect:1, autoScroll:1, alwaysHL : 1, moveRows:1, resizable:1;
462    //bool moveFields:1, clearHeader:1, alwaysEdit:1, collapse:1, treeBranch:1, rootCollapse:1, heightSet:1;
463    //bool sortable:1, noDragging:1, fillLastField:1, expandOnAdd:1;
464 };
465
466 public class FileSystemBox : Window // should we not derive from ListBox instead?
467 /*
468    this stuff from the listbox would be nicely exposed...
469       fullRowSelect = false;
470       treeBranches = true;
471       collapseControl = true;
472       rootCollapseButton = true;
473       sortable = true;
474 */
475 {
476    borderStyle = deep;
477    hasHorzScroll = false;
478    hasVertScroll = false;
479
480    menu = Menu { };
481
482 public:
483    FileSystemNode root;
484    FileSystemNode selection;
485
486    virtual bool Window::NotifyNodeSelect(FileSystemBox box, FileSystemNode node);
487    
488    property char * path
489    {
490       set
491       {
492          delete path;
493          if(value && value[0])
494             path = CopyString(value);
495          if(created)
496             Load();
497       }
498
499       get { return path; }
500       //isset { return path && path[0]; }
501    }
502
503    property bool foldersOnly { set { bits.foldersOnly = value; } get { return bits.foldersOnly; } };
504    property bool previewPictures { set { bits.previewPictures = value; } get { return bits.previewPictures; } };
505    property char * extensions { set { delete extensions; if(value && value[0]) extensions = CopyString(value); } get { return extensions; } }
506    property bool details { set { bits.details = value; } get { return bits.details; } };
507    property bool treeBranches
508    {
509       set
510       {
511          bits.treeBranches = value;
512          list.treeBranches = value;
513          list.collapseControl = value;
514          list.rootCollapseButton = value;
515       }
516       get { return bits.treeBranches; }
517    };
518    
519    property FileSystemNode node
520    {
521       get
522       {
523          if(!list)
524             return null;
525          if(!list.currentRow)
526             return null;
527          if(!list.currentRow.tag)
528             return null;
529          return (FileSystemNode)list.currentRow.tag;
530       }
531    }
532
533    void Select(FileSystemNode node)
534    {
535       if(node.row)
536       {
537          node.EnsureVisible(false);
538          list.SelectRow(node.row);
539       }
540    }
541
542    FileSystemNode Find(const char * name, FileSystemNode parent)
543    {
544       FileSystemNode node;
545       FileSystemNode start = parent ? parent : root;
546       if(!start.loaded || !start.childrenLoaded)
547          LoadTreeNode(start);
548       for(node = start.children.first; node; node = node.next)
549          if(node.name && !strcmpi(node.name, name))
550             return node;
551       return null;
552    }
553
554 private:
555    FileSystemBoxBits bits;
556
557    char * path;
558    char * extensions;
559
560    BitmapResource fileIcons[__FileType];
561
562    FileSystemBox()
563    {
564       char wd[MAX_LOCATION];
565       GetWorkingDir(wd, sizeof(wd));
566       property::path = wd;
567       
568       InitFileIcons();
569       list.AddField(nameField);
570    }
571    ~FileSystemBox()
572    {
573       delete extensions;
574       delete path;
575    }
576    void InitFileIcons()
577    {
578       __FileType c;
579       for(c = 0; c < __FileType::enumSize; c++)
580       {
581          fileIcons[c] = BitmapResource { fileIconNames[c], alphaBlend = true };
582          AddResource(fileIcons[c]);
583       }
584    }
585
586    DataField nameField { dataType = "FileSystemNode", width = 240, userData = this };
587    DataField typeField { header = "Type", dataType = /*"String"*/ "char *", width = 40, freeData = false };
588    DataField sizeField { header = "Size", dataType = "FileSize", width = 96, alignment = right };
589
590    bool OnPostCreate()
591    {
592       Load();
593       return true;
594    }
595
596    ListBox list
597    {
598       this;
599
600       borderStyle = none;
601       hasHorzScroll = true;
602       hasVertScroll = true;
603       fullRowSelect = false;
604       sortable = true;
605
606       anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
607
608       // WHY is this not working ?
609       /*void OnResize(int width, int height)
610       {
611          if(vertScroll.visible)
612             nameField.width = width - vertScroll.size.w;
613          else
614             nameField.width = width;
615       }*/
616
617       bool NotifyCollapse(ListBox listBox, DataRow row, bool collapsed)
618       {
619          if(row)
620          {
621             FileSystemNode node = (FileSystemNode)row.tag;
622             FileSystemNode child;
623             if(collapsed)
624             {
625                /*
626                for(child = node.children.last; child; child = node.children.last)
627                {
628                   listBox.DeleteRow(child.row);
629                   child.Free();
630                   delete child;
631                }
632                node.childrenLoaded = false;
633                */
634             }
635             else
636             {
637                if(!node.loaded || !node.childrenLoaded)
638                {
639                   LoadTreeNode(node);
640                   //list.Sort(nameField, 1);
641                   //node.
642                }
643                for(child = node.children.first; child && child.next; child = child.next);
644                if(child)
645                   child.EnsureVisible(false);
646             }
647          }
648          return true;
649       }
650       
651       bool NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods)
652       {
653          DataRow row = listBox.currentRow;
654          if(row)
655          {
656             FileSystemNode node = (FileSystemNode)row.tag;
657             if(node)
658             {
659                PopupMenu popup;
660                Menu menu { };
661
662                MenuItem { menu, "Cut\tCtrl+X", t, NotifySelect = null, disabled = false };
663                MenuItem { menu, "Copy\tCtrl+C", c, NotifySelect = null, disabled = false };
664                MenuItem { menu, "Paste\tCtrl+V", p, NotifySelect = null, disabled = false /*!clipboard*/ };
665                MenuItem { menu, "Delete\tDel", d, NotifySelect = null, disabled = false };
666                //MenuDivider { menu };
667
668                popup = PopupMenu
669                   {
670                      master = this, menu = menu,
671                      position = { 
672                         x + clientStart.x + absPosition.x - guiApp.desktop.position.x, 
673                         y + clientStart.y + absPosition.y - guiApp.desktop.position.y }
674                   };
675                popup.Create();
676             }
677          }
678          return true;
679       }
680
681       bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
682       {
683          if(row)
684          {
685             FileSystemNode node = (FileSystemNode)row.tag;
686             NotifyNodeSelect(listBox.parent.master, this, node);
687             selection = node;
688          }
689          return true;
690       }
691
692       bool NotifyEditing(ListBox listBox, DataRow row)
693       {
694          if(row)
695          {
696             FileSystemNode node = (FileSystemNode)row.tag;
697          }
698          return true;
699       }
700
701       bool NotifyEdited(ListBox listBox, DataRow row)
702       {
703          if(row)
704          {
705             FileSystemNode node = (FileSystemNode)row.tag;
706          }
707          return true;
708       }
709
710       bool NotifyEditDone(ListBox listBox, DataRow row)
711       {
712          if(row)
713          {
714             FileSystemNode node = (FileSystemNode)row.tag;
715          }
716          return true;
717       }
718
719    };
720
721    // Edit Menu
722    Menu editMenu { menu, "Edit", e };
723    MenuItem itemEditCut
724    {
725       editMenu, "Cut\tCtrl+X", t, disabled = true;
726
727       bool NotifySelect(MenuItem selection, Modifiers mods)
728       {
729          //EditCut();
730          return true;
731       }
732    };
733    MenuItem itemEditCopy
734    {
735       editMenu, "Copy\tCtrl+C", c, disabled = true;
736
737       bool NotifySelect(MenuItem selection, Modifiers mods)
738       {
739          //EditCopy();
740          return true;
741       }
742    };
743    MenuItem itemEditPaste
744    {
745       editMenu, "Paste\tCtrl+V", p;
746    
747       bool NotifySelect(MenuItem selection, Modifiers mods)
748       {
749          //EditPaste();
750          return true;
751       }
752    };
753    MenuItem itemEditDelete
754    {
755       editMenu, "Delete\tDel", d, disabled = true;
756
757       bool NotifySelect(MenuItem selection, Modifiers mods)
758       {
759          //EditDelete();
760          return true;
761       }
762    };
763
764    // WHY is this crashing ? 
765    /*void OnResize(int width, int height)
766    {
767       if(this && nameField)
768          nameField.width = width - 80;
769    }*/
770
771    void Load()
772    {
773       // TODO: fix this!
774       // this is crashing in for designer when details = true // can't save the file, always yields a crash
775       /*if(list && created)
776       {
777          list.ClearFields();
778          list.AddField(nameField);
779          if(bits.details)
780          {
781             list.AddField(typeField);
782             list.AddField(sizeField);
783          }
784       }*/
785       if(bits.treeBranches)
786          LoadTree();
787       else
788          LoadList();
789    }
790
791    void LoadList()
792    {
793       FileListing listing { path, extensions = extensions };
794
795       list.Clear();
796       while(listing.Find())
797       {
798          if(!bits.foldersOnly || listing.stats.attribs.isDirectory)
799          {
800             FileSystemNode node = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
801             DataRow row = list.AddRow();
802             row.tag = (int)node;
803             row.SetData(nameField, node);
804             if(bits.details)
805             {
806                row.SetData(typeField, node.extension);
807                row.SetData(sizeField, (void *)node.stats.size);
808             }
809          }
810       }
811       list.Sort(nameField, 1);
812    }
813
814    void LoadTree()
815    {
816       //char startPath[MAX_LOCATION];
817       FileSystemNode parent;
818       FileSystemNode node;
819       FileListing listing { path, extensions = extensions };
820       
821       /*if(!path)
822          GetWorkingDir(startPath, sizeof(startPath));
823       else
824          strcpy(path, startPath);*/
825       
826       list.Clear();
827
828       delete root;
829       //root = FileSystemNode { type = computer, loaded = true, childrenLoaded = true };
830       root = MakeFileSystemNode(FileStats { attribs = FileExists(path)}, path, path, bits.previewPictures, displaySystem);
831    #ifdef __WIN32__
832       //root.name = rootName;
833       AddTreeNode(root, true, false, null, list);
834    #else
835       //root.name = "/";
836    #endif
837       AddTreeNode(root, false, true, null);
838
839    // How can this make sense for linux? 
840    #ifdef __WIN32__
841       while(listing.Find())
842       {
843          int len = strlen(listing.name);
844          char info[MAX_LOCATION];
845          char name[MAX_LOCATION];
846          if(listing.stats.attribs.isDrive && 
847                len > 3 && !strncmp(&listing.name[1], ": [", 3))
848          {
849             strncpy(name, listing.name, 2);
850             name[2] = 0;
851             strncpy(info, &listing.name[4], len - 5);
852             info[len - 5] = 0;
853          }
854          else
855          {
856             strcpy(name, listing.name);
857             info[0] = 0;
858          }
859
860          parent = MakeFileSystemNode(listing.stats, name);
861          if(info[0])
862             parent.info = CopyString(info);
863          parent.loaded = true;
864          AddTreeNode(parent, !listing.stats.attribs.isDirectory, listing.stats.attribs.isDirectory, root, this);
865          if(!listing.stats.attribs.isDirectory)
866             parent.childrenLoaded = true;
867       }
868
869       node = FileSystemNode { name = msNetwork, type = network };
870       AddTreeNode(node, false, true, null, this);
871       node.row.collapsed = true;
872       Sort(nameField, 1);
873       SelectRow(root.row);
874    #endif
875       LoadTreeNode(root);
876       list.Sort(nameField, 1);
877    }
878
879    void LoadTreeNode(FileSystemNode node)
880    {
881       if(!node.loaded)
882       {
883          char path[MAX_LOCATION];
884          node.GetPath(path);
885          {
886             FileListing listing { path, extensions = extensions };
887             if(node.children.count == 1)
888             DeleteNode(node.children.first);
889
890             while(listing.Find())
891             {
892                if(!bits.foldersOnly || listing.stats.attribs.isDirectory)
893                {
894                   FileSystemNode child = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
895                   AddTreeNode(child, true, false, node);
896                   NodeChildLoad(child, node);
897                }
898             }
899          }
900          node.childrenLoaded = true;
901          node.loaded = true;
902          node.row.SortSubRows(false);
903       }
904       else if(!node.childrenLoaded)
905       {
906          FileSystemNode child;
907          if(node.children.first)
908          {
909             for(child = node.children.first; child; child = child.next)
910             {
911                if(!child.loaded)
912                   LoadTreeNode(child);
913                else if(!child.childrenLoaded)
914                   NodeChildLoad(child, node);
915             }
916             node.childrenLoaded = true;
917             node.row.SortSubRows(false);
918          }
919       }
920    }
921
922    void NodeChildLoad(FileSystemNode parent, FileSystemNode node)
923    {
924       char path[MAX_LOCATION];
925       parent.GetPath(path);
926       {
927          bool added = false;
928          FileListing listing { path, extensions = extensions };
929          while(listing.Find())
930          {
931             if(!bits.foldersOnly || listing.stats.attribs.isDirectory)
932             {
933                FileSystemNode child = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
934                AddTreeNode(child, true, false, parent);
935                added = true;
936             }
937          }
938          if(!added)
939             added = true;
940       }
941       //parent.childrenLoaded = true;
942    }
943
944    void AddTreeNode(FileSystemNode node, bool loaded, bool addLoader, FileSystemNode addTo)
945    {
946       DataRow row = (addTo && addTo.row) ? addTo.row.AddRow() : list.AddRow();
947       if(addTo)
948       {
949          node.parent = addTo;
950          node.indent = addTo.indent + 1;
951          addTo.children.Add(node);
952       }
953       row.tag = (int)node;
954       node.row = row;
955       row.SetData(null, node);
956
957       node.loaded = loaded;
958       if(addLoader)
959          //AddTreeNode(FileSystemNode { }, false, false, node); // why would this create a compile error?
960          AddTreeNode(FileSystemNode { type = none }, false, false, node);
961
962       if(node.indent > 0)
963          row.collapsed = true;
964       else if(node.type == folder)
965          node.type = folderOpen;
966    }
967
968    void DeleteNode(FileSystemNode node)
969    {
970       FileSystemNode child;
971       for(; (child = node.children.first); )
972          DeleteNode(child);
973       list.DeleteRow(node.row);
974       node.Delete();
975    }
976 /*
977 public class ClipBoardFiles
978 {
979
980 public:
981
982    property
983
984 }
985
986    // CLIPBOARD
987    void Copy()
988    {
989       if(this)
990       {
991          int size = SelSize();
992          if(size)
993          {
994             // Try to allocate memory
995             ClipBoard clipBoard { };
996             if(clipBoard.Allocate(size+1))
997             {
998                GetSel(clipBoard.memory, true);   
999                // Save clipboard
1000                clipBoard.Save();
1001             }
1002             delete clipBoard;
1003          }
1004       }
1005    }
1006
1007    void Paste()
1008    {
1009       if(this)
1010       {
1011          ClipBoard clipBoard { };
1012          if(clipBoard.Load())
1013             PutS(clipBoard.memory);
1014          delete clipBoard;
1015       }
1016    }
1017
1018    void Cut()
1019    {
1020       if(this)
1021       {
1022          Copy();
1023          DelSel();
1024          SetViewToCursor(true);
1025          Modified();
1026       }
1027    }
1028
1029 Private Type DROPFILES
1030    pFiles As Long
1031    pt As POINTAPI
1032    fNC As Long
1033    fWide As Long
1034 End Type
1035 For iCounter = 0 To filelist.ListCount - 1
1036   If filelist.Selected(iCounter) = True Then
1037     strFiles = strFiles & FixPath(filelist.Path) & filelist.List(iCounter) & vbNullChar
1038   End If
1039 Next
1040 'all selected items are now put in strFiles
1041
1042 hGlobal = GlobalAlloc(GHND, Len(DF) + Len(strFiles)) 'put all files to a exclusive number
1043 If hGlobal Then 'if the globalalloc worked
1044   lpGlobal = GlobalLock(hGlobal) 'lock the hGlobal
1045   DF.pFiles = Len(DF) 'set the size of the files
1046   
1047   Call CopyMem(ByVal lpGlobal, DF, Len(DF)) 'copy df to the lpglobal
1048   Call CopyMem(ByVal (lpGlobal + Len(DF)), ByVal strFiles, Len(strFiles)) 'copy strfiles to lpglobal
1049   Call GlobalUnlock(hGlobal) 'unlock hglobal again
1050   
1051   SetClipboardData CF_HDROP, hGlobal 'put files to the clipboard
1052 End If
1053
1054    bool SaveFile(const char * filePath)
1055    {
1056    }
1057 */
1058
1059 }