b880c7570eff15c3641b0a737c28020bc4511920
[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,
395       const char * fileName, const char * filePath,
396       const bool previewPicture, const DisplaySystem displaySystem)
397 {
398    int len = strlen(fileName);
399    char info[MAX_LOCATION];
400    char name[MAX_LOCATION];
401    char extension[MAX_EXTENSION];
402    
403    FileSystemNode node { stats = stats };
404
405    //if(stats.attribs.isFile) // TODO fix this in ecere
406    if(stats.attribs.isDirectory)
407    {
408       extension[0] = '\0';
409
410       node.type = (stats.attribs.isDrive) ? drive : folder;
411       if(stats.attribs.isServer) node.type = server;
412       if(stats.attribs.isShare) node.type = share;
413       if(stats.attribs.isCDROM) node.type = cdrom;
414       if(stats.attribs.isRemote) node.type = netDrive;
415       if(stats.attribs.isRemovable) 
416       {
417          if(fileName[0] == 'A' || fileName[0] == 'B')
418             node.type = floppy;
419          else
420             node.type = removable;
421       }
422    }
423    else
424    {
425       GetExtension(fileName, extension);
426       strlwr(extension);
427       
428       node.type = __FileType::SelectByExtension(extension);
429    }
430
431    if(stats.attribs.isDrive && 
432          len > 3 && !strncmp(&fileName[1], ": [", 3))
433    {
434       strncpy(name, fileName, 2);
435       name[2] = 0;
436       strncpy(info, &fileName[4], len - 5);
437       info[len - 5] = 0;
438    }
439    else
440    {
441       strcpy(name, fileName);
442       info[0] = 0;
443    }
444
445    node.path = CopyString(filePath);
446    node.name = CopyString(name);
447    if(info[0])
448       node.info = CopyString(info);
449    node.extension = CopyString(extension);
450
451    if(node.type == pictureFile && previewPicture)
452    {
453       node.bitmap = Bitmap { };
454       node.bitmap.Load(filePath, null, displaySystem);
455    }
456
457    return node;
458 }
459
460 class FileSystemBoxBits
461 {
462    bool foldersOnly:1, filesOnly:1, details:1, treeBranches:1, previewPictures:1, navigateFolders:1;
463    //bool header:1, freeSelect:1, fullRowSelect:1, multiSelect:1, autoScroll:1, alwaysHL : 1, moveRows:1, resizable:1;
464    //bool moveFields:1, clearHeader:1, alwaysEdit:1, collapse:1, treeBranch:1, rootCollapse:1, heightSet:1;
465    //bool sortable:1, noDragging:1, fillLastField:1, expandOnAdd:1;
466 };
467
468 public class FileSystemBox : Window // should we not derive from ListBox instead?
469 /*
470    this stuff from the listbox would be nicely exposed...
471       fullRowSelect = false;
472       treeBranches = true;
473       collapseControl = true;
474       rootCollapseButton = true;
475       sortable = true;
476 */
477 {
478    borderStyle = deep;
479    hasHorzScroll = false;
480    hasVertScroll = false;
481
482    menu = Menu { };
483
484 public:
485    FileSystemNode root;
486    FileSystemNode selection;
487
488    virtual bool Window::NotifyNodeSelect(FileSystemBox box, FileSystemNode node);
489    virtual bool Window::NotifyNodeOpen(FileSystemBox box, FileSystemNode node);
490    
491    property char * path
492    {
493       set
494       {
495          delete path;
496          if(value && value[0])
497             path = CopyString(value);
498          if(locationBox)
499             locationBox.path = value;
500          if(created)
501             Load();
502       }
503
504       get { return path; }
505       //isset { return path && path[0]; }
506    }
507
508    property bool foldersOnly { set { bits.foldersOnly = value; bits.filesOnly = !value; } get { return bits.foldersOnly; } };
509    property bool filesOnly { set { bits.filesOnly = value; bits.foldersOnly = !value; } get { return bits.filesOnly; } };
510    property bool previewPictures { set { bits.previewPictures = value; } get { return bits.previewPictures; } };
511    property char * extensions { set { delete extensions; if(value && value[0]) extensions = CopyString(value); } get { return extensions; } }
512    property bool details { set { bits.details = value; } get { return bits.details; } };
513    property bool treeBranches
514    {
515       set
516       {
517          bits.treeBranches = value;
518          list.treeBranches = value;
519          list.collapseControl = value;
520          list.rootCollapseButton = value;
521       }
522       get { return bits.treeBranches; }
523    };
524    property bool navigateFolders { set { bits.navigateFolders = value; bits.foldersOnly = !value; } get { return bits.navigateFolders; } };
525    
526    property FileSystemNode node
527    {
528       get
529       {
530          if(!list)
531             return null;
532          if(!list.currentRow)
533             return null;
534          if(!list.currentRow.tag)
535             return null;
536          return (FileSystemNode)list.currentRow.tag;
537       }
538    }
539
540    PathBox locationBox;
541
542    void Select(FileSystemNode node)
543    {
544       if(node.row)
545       {
546          node.EnsureVisible(false);
547          list.SelectRow(node.row);
548       }
549    }
550
551    FileSystemNode Find(const char * name, FileSystemNode parent)
552    {
553       FileSystemNode node;
554       FileSystemNode start = parent ? parent : root;
555       if(!start.loaded || !start.childrenLoaded)
556          LoadTreeNode(start);
557       for(node = start.children.first; node; node = node.next)
558          if(node.name && !strcmpi(node.name, name))
559             return node;
560       return null;
561    }
562
563 private:
564    FileSystemBoxBits bits;
565
566    char * path;
567    char * extensions;
568
569    BitmapResource fileIcons[__FileType];
570
571    FileSystemBox()
572    {
573       char wd[MAX_LOCATION];
574       GetWorkingDir(wd, sizeof(wd));
575       property::path = wd;
576       
577       InitFileIcons();
578       list.AddField(nameField);
579    }
580    ~FileSystemBox()
581    {
582       delete extensions;
583       delete path;
584    }
585    void InitFileIcons()
586    {
587       __FileType c;
588       for(c = 0; c < __FileType::enumSize; c++)
589       {
590          fileIcons[c] = BitmapResource { fileIconNames[c], alphaBlend = true };
591          AddResource(fileIcons[c]);
592       }
593    }
594
595    DataField nameField { dataType = "FileSystemNode", width = 240, userData = this };
596    DataField typeField { header = "Type", dataType = /*"String"*/ "char *", width = 40, freeData = false };
597    DataField sizeField { header = "Size", dataType = "FileSize", width = 96, alignment = right };
598
599    bool OnPostCreate()
600    {
601       Load();
602       return true;
603    }
604
605    ListBox list
606    {
607       this;
608
609       borderStyle = none;
610       hasHorzScroll = true;
611       hasVertScroll = true;
612       fullRowSelect = false;
613       sortable = true;
614
615       anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
616
617       // WHY is this not working ?
618       /*void OnResize(int width, int height)
619       {
620          if(vertScroll.visible)
621             nameField.width = width - vertScroll.size.w;
622          else
623             nameField.width = width;
624       }*/
625
626       bool NotifyCollapse(ListBox listBox, DataRow row, bool collapsed)
627       {
628          if(row)
629          {
630             FileSystemNode node = (FileSystemNode)row.tag;
631             FileSystemNode child;
632             if(collapsed)
633             {
634                /*
635                for(child = node.children.last; child; child = node.children.last)
636                {
637                   listBox.DeleteRow(child.row);
638                   child.Free();
639                   delete child;
640                }
641                node.childrenLoaded = false;
642                */
643             }
644             else
645             {
646                if(!node.loaded || !node.childrenLoaded)
647                {
648                   LoadTreeNode(node);
649                   //list.Sort(nameField, 1);
650                   //node.
651                }
652                for(child = node.children.first; child && child.next; child = child.next);
653                if(child)
654                   child.EnsureVisible(false);
655             }
656          }
657          return true;
658       }
659       
660       bool NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods)
661       {
662          DataRow row = listBox.currentRow;
663          if(row)
664          {
665             FileSystemNode node = (FileSystemNode)row.tag;
666             if(node)
667             {
668                PopupMenu popup;
669                Menu menu { };
670
671                MenuItem { menu, "Cut\tCtrl+X", t, NotifySelect = null, disabled = false };
672                MenuItem { menu, "Copy\tCtrl+C", c, NotifySelect = null, disabled = false };
673                MenuItem { menu, "Paste\tCtrl+V", p, NotifySelect = null, disabled = false /*!clipboard*/ };
674                MenuItem { menu, "Delete\tDel", d, NotifySelect = null, disabled = false };
675                //MenuDivider { menu };
676
677                popup = PopupMenu
678                   {
679                      master = this, menu = menu,
680                      position = { 
681                         x + clientStart.x + absPosition.x - guiApp.desktop.position.x, 
682                         y + clientStart.y + absPosition.y - guiApp.desktop.position.y }
683                   };
684                popup.Create();
685             }
686          }
687          return true;
688       }
689
690       bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
691       {
692          if(row)
693          {
694             FileSystemNode node = (FileSystemNode)row.tag;
695             NotifyNodeSelect(listBox.parent.master, this, node);
696             selection = node;
697          }
698          return true;
699       }
700
701       bool NotifyEditing(ListBox listBox, DataRow row)
702       {
703          if(row)
704          {
705             FileSystemNode node = (FileSystemNode)row.tag;
706          }
707          return true;
708       }
709
710       bool NotifyEdited(ListBox listBox, DataRow row)
711       {
712          if(row)
713          {
714             FileSystemNode node = (FileSystemNode)row.tag;
715          }
716          return true;
717       }
718
719       bool NotifyEditDone(ListBox listBox, DataRow row)
720       {
721          if(row)
722          {
723             FileSystemNode node = (FileSystemNode)row.tag;
724          }
725          return true;
726       }
727
728       bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
729       {
730          return OpenNode();
731       }
732
733       bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
734       {
735          bool result;
736          if((SmartKey)key == enter)
737             result = OpenNode();
738          else
739             result = true;
740          return true;
741       }
742    };
743
744    bool OpenNode()
745    {
746       bool result;
747       if(selection && selection.type.isFolder && bits.navigateFolders)
748       {
749          property::path = selection.path;
750          result = true;
751       }
752       else
753          result = NotifyNodeOpen(this.master, this, selection);
754       return result;
755    }
756
757    // Edit Menu
758    Menu editMenu { menu, "Edit", e };
759    MenuItem itemEditCut
760    {
761       editMenu, "Cut\tCtrl+X", t, disabled = true;
762
763       bool NotifySelect(MenuItem selection, Modifiers mods)
764       {
765          //EditCut();
766          return true;
767       }
768    };
769    MenuItem itemEditCopy
770    {
771       editMenu, "Copy\tCtrl+C", c, disabled = true;
772
773       bool NotifySelect(MenuItem selection, Modifiers mods)
774       {
775          //EditCopy();
776          return true;
777       }
778    };
779    MenuItem itemEditPaste
780    {
781       editMenu, "Paste\tCtrl+V", p;
782    
783       bool NotifySelect(MenuItem selection, Modifiers mods)
784       {
785          //EditPaste();
786          return true;
787       }
788    };
789    MenuItem itemEditDelete
790    {
791       editMenu, "Delete\tDel", d, disabled = true;
792
793       bool NotifySelect(MenuItem selection, Modifiers mods)
794       {
795          //EditDelete();
796          return true;
797       }
798    };
799
800    // WHY is this crashing ? 
801    /*void OnResize(int width, int height)
802    {
803       if(this && nameField)
804          nameField.width = width - 80;
805    }*/
806
807    void Load()
808    {
809       // TODO: fix this!
810       // this is crashing in for designer when details = true // can't save the file, always yields a crash
811       /*if(list && created)
812       {
813          list.ClearFields();
814          list.AddField(nameField);
815          if(bits.details)
816          {
817             list.AddField(typeField);
818             list.AddField(sizeField);
819          }
820       }*/
821       if(bits.treeBranches)
822          LoadTree();
823       else
824          LoadList();
825    }
826
827    void LoadList()
828    {
829       FileListing listing { path, extensions = extensions };
830
831       list.Clear();
832       while(listing.Find())
833       {
834          if((!bits.foldersOnly && !bits.filesOnly) ||
835             (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
836             (bits.filesOnly && !listing.stats.attribs.isDirectory/*listing.stats.attribs.isFile*/)) // TOCHECK: isFile broken?
837          {
838             FileSystemNode node = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
839             DataRow row = list.AddRow();
840             row.tag = (int)node;
841             row.SetData(nameField, node);
842             if(bits.details)
843             {
844                row.SetData(typeField, node.extension);
845                row.SetData(sizeField, (void *)node.stats.size);
846             }
847          }
848       }
849       list.Sort(nameField, 1);
850    }
851
852    void LoadTree()
853    {
854       //char startPath[MAX_LOCATION];
855       FileSystemNode parent;
856       FileSystemNode node;
857       FileListing listing { path, extensions = extensions };
858       
859       /*if(!path)
860          GetWorkingDir(startPath, sizeof(startPath));
861       else
862          strcpy(path, startPath);*/
863       
864       list.Clear();
865
866       delete root;
867       //root = FileSystemNode { type = computer, loaded = true, childrenLoaded = true };
868       root = MakeFileSystemNode(FileStats { attribs = FileExists(path)}, path, path, bits.previewPictures, displaySystem);
869    #ifdef __WIN32__
870       //root.name = rootName;
871       AddTreeNode(root, true, false, null, list);
872    #else
873       //root.name = "/";
874    #endif
875       AddTreeNode(root, false, true, null);
876
877    // How can this make sense for linux? 
878    #ifdef __WIN32__
879       while(listing.Find())
880       {
881          int len = strlen(listing.name);
882          char info[MAX_LOCATION];
883          char name[MAX_LOCATION];
884          if(listing.stats.attribs.isDrive && 
885                len > 3 && !strncmp(&listing.name[1], ": [", 3))
886          {
887             strncpy(name, listing.name, 2);
888             name[2] = 0;
889             strncpy(info, &listing.name[4], len - 5);
890             info[len - 5] = 0;
891          }
892          else
893          {
894             strcpy(name, listing.name);
895             info[0] = 0;
896          }
897
898          parent = MakeFileSystemNode(listing.stats, name);
899          if(info[0])
900             parent.info = CopyString(info);
901          parent.loaded = true;
902          AddTreeNode(parent, !listing.stats.attribs.isDirectory, listing.stats.attribs.isDirectory, root, this);
903          if(!listing.stats.attribs.isDirectory)
904             parent.childrenLoaded = true;
905       }
906
907       node = FileSystemNode { name = msNetwork, type = network };
908       AddTreeNode(node, false, true, null, this);
909       node.row.collapsed = true;
910       Sort(nameField, 1);
911       SelectRow(root.row);
912    #endif
913       LoadTreeNode(root);
914       list.Sort(nameField, 1);
915    }
916
917    void LoadTreeNode(FileSystemNode node)
918    {
919       if(!node.loaded)
920       {
921          char path[MAX_LOCATION];
922          node.GetPath(path);
923          {
924             FileListing listing { path, extensions = extensions };
925             if(node.children.count == 1)
926             DeleteNode(node.children.first);
927
928             while(listing.Find())
929             {
930                if((!bits.foldersOnly && !bits.filesOnly) ||
931                   (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
932                   (bits.filesOnly && !listing.stats.attribs.isDirectory/*listing.stats.attribs.isFile*/)) // TOCHECK: isFile broken?
933                {
934                   FileSystemNode child = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
935                   AddTreeNode(child, true, false, node);
936                   NodeChildLoad(child, node);
937                }
938             }
939          }
940          node.childrenLoaded = true;
941          node.loaded = true;
942          node.row.SortSubRows(false);
943       }
944       else if(!node.childrenLoaded)
945       {
946          FileSystemNode child;
947          if(node.children.first)
948          {
949             for(child = node.children.first; child; child = child.next)
950             {
951                if(!child.loaded)
952                   LoadTreeNode(child);
953                else if(!child.childrenLoaded)
954                   NodeChildLoad(child, node);
955             }
956             node.childrenLoaded = true;
957             node.row.SortSubRows(false);
958          }
959       }
960    }
961
962    void NodeChildLoad(FileSystemNode parent, FileSystemNode node)
963    {
964       char path[MAX_LOCATION];
965       parent.GetPath(path);
966       {
967          bool added = false;
968          FileListing listing { path, extensions = extensions };
969          while(listing.Find())
970          {
971             if((!bits.foldersOnly && !bits.filesOnly) ||
972                (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
973                (bits.filesOnly && !listing.stats.attribs.isDirectory/*listing.stats.attribs.isFile*/)) // TOCHECK: isFile broken?
974             {
975                FileSystemNode child = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
976                AddTreeNode(child, true, false, parent);
977                added = true;
978             }
979          }
980          if(!added)
981             added = true;
982       }
983       //parent.childrenLoaded = true;
984    }
985
986    void AddTreeNode(FileSystemNode node, bool loaded, bool addLoader, FileSystemNode addTo)
987    {
988       DataRow row = (addTo && addTo.row) ? addTo.row.AddRow() : list.AddRow();
989       if(addTo)
990       {
991          node.parent = addTo;
992          node.indent = addTo.indent + 1;
993          addTo.children.Add(node);
994       }
995       row.tag = (int)node;
996       node.row = row;
997       row.SetData(null, node);
998
999       node.loaded = loaded;
1000       if(addLoader)
1001          //AddTreeNode(FileSystemNode { }, false, false, node); // why would this create a compile error?
1002          AddTreeNode(FileSystemNode { type = none }, false, false, node);
1003
1004       if(node.indent > 0)
1005          row.collapsed = true;
1006       else if(node.type == folder)
1007          node.type = folderOpen;
1008    }
1009
1010    void DeleteNode(FileSystemNode node)
1011    {
1012       FileSystemNode child;
1013       for(; (child = node.children.first); )
1014          DeleteNode(child);
1015       list.DeleteRow(node.row);
1016       node.Delete();
1017    }
1018 /*
1019 public class ClipBoardFiles
1020 {
1021
1022 public:
1023
1024    property
1025
1026 }
1027
1028    // CLIPBOARD
1029    void Copy()
1030    {
1031       if(this)
1032       {
1033          int size = SelSize();
1034          if(size)
1035          {
1036             // Try to allocate memory
1037             ClipBoard clipBoard { };
1038             if(clipBoard.Allocate(size+1))
1039             {
1040                GetSel(clipBoard.memory, true);   
1041                // Save clipboard
1042                clipBoard.Save();
1043             }
1044             delete clipBoard;
1045          }
1046       }
1047    }
1048
1049    void Paste()
1050    {
1051       if(this)
1052       {
1053          ClipBoard clipBoard { };
1054          if(clipBoard.Load())
1055             PutS(clipBoard.memory);
1056          delete clipBoard;
1057       }
1058    }
1059
1060    void Cut()
1061    {
1062       if(this)
1063       {
1064          Copy();
1065          DelSel();
1066          SetViewToCursor(true);
1067          Modified();
1068       }
1069    }
1070
1071 Private Type DROPFILES
1072    pFiles As Long
1073    pt As POINTAPI
1074    fNC As Long
1075    fWide As Long
1076 End Type
1077 For iCounter = 0 To filelist.ListCount - 1
1078   If filelist.Selected(iCounter) = True Then
1079     strFiles = strFiles & FixPath(filelist.Path) & filelist.List(iCounter) & vbNullChar
1080   End If
1081 Next
1082 'all selected items are now put in strFiles
1083
1084 hGlobal = GlobalAlloc(GHND, Len(DF) + Len(strFiles)) 'put all files to a exclusive number
1085 If hGlobal Then 'if the globalalloc worked
1086   lpGlobal = GlobalLock(hGlobal) 'lock the hGlobal
1087   DF.pFiles = Len(DF) 'set the size of the files
1088   
1089   Call CopyMem(ByVal lpGlobal, DF, Len(DF)) 'copy df to the lpglobal
1090   Call CopyMem(ByVal (lpGlobal + Len(DF)), ByVal strFiles, Len(strFiles)) 'copy strfiles to lpglobal
1091   Call GlobalUnlock(hGlobal) 'unlock hglobal again
1092   
1093   SetClipboardData CF_HDROP, hGlobal 'put files to the clipboard
1094 End If
1095
1096    bool SaveFile(const char * filePath)
1097    {
1098    }
1099 */
1100
1101 }