libede:FilesystemBox: added public Refresh method
[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    void Refresh()
564    {
565       Load();
566    }
567
568 private:
569    FileSystemBoxBits bits;
570
571    char * path;
572    char * extensions;
573
574    BitmapResource fileIcons[__FileType];
575
576    FileSystemBox()
577    {
578       char wd[MAX_LOCATION];
579       GetWorkingDir(wd, sizeof(wd));
580       property::path = wd;
581       
582       InitFileIcons();
583       list.AddField(nameField);
584    }
585    ~FileSystemBox()
586    {
587       delete extensions;
588       delete path;
589    }
590    void InitFileIcons()
591    {
592       __FileType c;
593       for(c = 0; c < __FileType::enumSize; c++)
594       {
595          fileIcons[c] = BitmapResource { fileIconNames[c], alphaBlend = true };
596          AddResource(fileIcons[c]);
597       }
598    }
599
600    DataField nameField { dataType = "FileSystemNode", width = 240, userData = this };
601    DataField typeField { header = "Type", dataType = /*"String"*/ "char *", width = 40, freeData = false };
602    DataField sizeField { header = "Size", dataType = "FileSize", width = 96, alignment = right };
603
604    bool OnPostCreate()
605    {
606       Load();
607       return true;
608    }
609
610    ListBox list
611    {
612       this;
613
614       borderStyle = none;
615       hasHorzScroll = true;
616       hasVertScroll = true;
617       fullRowSelect = false;
618       sortable = true;
619
620       anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
621
622       // WHY is this not working ?
623       /*void OnResize(int width, int height)
624       {
625          if(vertScroll.visible)
626             nameField.width = width - vertScroll.size.w;
627          else
628             nameField.width = width;
629       }*/
630
631       bool NotifyCollapse(ListBox listBox, DataRow row, bool collapsed)
632       {
633          if(row)
634          {
635             FileSystemNode node = (FileSystemNode)row.tag;
636             FileSystemNode child;
637             if(collapsed)
638             {
639                /*
640                for(child = node.children.last; child; child = node.children.last)
641                {
642                   listBox.DeleteRow(child.row);
643                   child.Free();
644                   delete child;
645                }
646                node.childrenLoaded = false;
647                */
648             }
649             else
650             {
651                if(!node.loaded || !node.childrenLoaded)
652                {
653                   LoadTreeNode(node);
654                   //list.Sort(nameField, 1);
655                   //node.
656                }
657                for(child = node.children.first; child && child.next; child = child.next);
658                if(child)
659                   child.EnsureVisible(false);
660             }
661          }
662          return true;
663       }
664       
665       bool NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods)
666       {
667          DataRow row = listBox.currentRow;
668          if(row)
669          {
670             FileSystemNode node = (FileSystemNode)row.tag;
671             if(node)
672             {
673                PopupMenu popup;
674                Menu menu { };
675
676                MenuItem { menu, "Cut\tCtrl+X", t, NotifySelect = null, disabled = false };
677                MenuItem { menu, "Copy\tCtrl+C", c, NotifySelect = null, disabled = false };
678                MenuItem { menu, "Paste\tCtrl+V", p, NotifySelect = null, disabled = false /*!clipboard*/ };
679                MenuItem { menu, "Delete\tDel", d, NotifySelect = null, disabled = false };
680                //MenuDivider { menu };
681
682                popup = PopupMenu
683                   {
684                      master = this, menu = menu,
685                      position = { 
686                         x + clientStart.x + absPosition.x - guiApp.desktop.position.x, 
687                         y + clientStart.y + absPosition.y - guiApp.desktop.position.y }
688                   };
689                popup.Create();
690             }
691          }
692          return true;
693       }
694
695       bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
696       {
697          if(row)
698          {
699             FileSystemNode node = (FileSystemNode)row.tag;
700             NotifyNodeSelect(listBox.parent.master, this, node);
701             selection = node;
702          }
703          return true;
704       }
705
706       bool NotifyEditing(ListBox listBox, DataRow row)
707       {
708          if(row)
709          {
710             FileSystemNode node = (FileSystemNode)row.tag;
711          }
712          return true;
713       }
714
715       bool NotifyEdited(ListBox listBox, DataRow row)
716       {
717          if(row)
718          {
719             FileSystemNode node = (FileSystemNode)row.tag;
720          }
721          return true;
722       }
723
724       bool NotifyEditDone(ListBox listBox, DataRow row)
725       {
726          if(row)
727          {
728             FileSystemNode node = (FileSystemNode)row.tag;
729          }
730          return true;
731       }
732
733       bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
734       {
735          return OpenNode();
736       }
737
738       bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
739       {
740          bool result;
741          if((SmartKey)key == enter)
742             result = OpenNode();
743          else
744             result = true;
745          return true;
746       }
747    };
748
749    bool OpenNode()
750    {
751       bool result;
752       if(selection && selection.type.isFolder && bits.navigateFolders)
753       {
754          property::path = selection.path;
755          result = true;
756       }
757       else
758          result = NotifyNodeOpen(this.master, this, selection);
759       return result;
760    }
761
762    // Edit Menu
763    Menu editMenu { menu, "Edit", e };
764    MenuItem itemEditCut
765    {
766       editMenu, "Cut\tCtrl+X", t, disabled = true;
767
768       bool NotifySelect(MenuItem selection, Modifiers mods)
769       {
770          //EditCut();
771          return true;
772       }
773    };
774    MenuItem itemEditCopy
775    {
776       editMenu, "Copy\tCtrl+C", c, disabled = true;
777
778       bool NotifySelect(MenuItem selection, Modifiers mods)
779       {
780          //EditCopy();
781          return true;
782       }
783    };
784    MenuItem itemEditPaste
785    {
786       editMenu, "Paste\tCtrl+V", p;
787    
788       bool NotifySelect(MenuItem selection, Modifiers mods)
789       {
790          //EditPaste();
791          return true;
792       }
793    };
794    MenuItem itemEditDelete
795    {
796       editMenu, "Delete\tDel", d, disabled = true;
797
798       bool NotifySelect(MenuItem selection, Modifiers mods)
799       {
800          //EditDelete();
801          return true;
802       }
803    };
804
805    // WHY is this crashing ? 
806    /*void OnResize(int width, int height)
807    {
808       if(this && nameField)
809          nameField.width = width - 80;
810    }*/
811
812    void Load()
813    {
814       // TODO: fix this!
815       // this is crashing in for designer when details = true // can't save the file, always yields a crash
816       /*if(list && created)
817       {
818          list.ClearFields();
819          list.AddField(nameField);
820          if(bits.details)
821          {
822             list.AddField(typeField);
823             list.AddField(sizeField);
824          }
825       }*/
826       if(bits.treeBranches)
827          LoadTree();
828       else
829          LoadList();
830    }
831
832    void LoadList()
833    {
834       FileListing listing { path, extensions = extensions };
835
836       list.Clear();
837       while(listing.Find())
838       {
839          if((!bits.foldersOnly && !bits.filesOnly) ||
840             (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
841             (bits.filesOnly && !listing.stats.attribs.isDirectory/*listing.stats.attribs.isFile*/)) // TOCHECK: isFile broken?
842          {
843             FileSystemNode node = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
844             DataRow row = list.AddRow();
845             row.tag = (int)node;
846             row.SetData(nameField, node);
847             if(bits.details)
848             {
849                row.SetData(typeField, node.extension);
850                row.SetData(sizeField, (void *)node.stats.size);
851             }
852          }
853       }
854       list.Sort(nameField, 1);
855    }
856
857    void LoadTree()
858    {
859       //char startPath[MAX_LOCATION];
860       FileSystemNode parent;
861       FileSystemNode node;
862       FileListing listing { path, extensions = extensions };
863       
864       /*if(!path)
865          GetWorkingDir(startPath, sizeof(startPath));
866       else
867          strcpy(path, startPath);*/
868       
869       list.Clear();
870
871       delete root;
872       //root = FileSystemNode { type = computer, loaded = true, childrenLoaded = true };
873       root = MakeFileSystemNode(FileStats { attribs = FileExists(path)}, path, path, bits.previewPictures, displaySystem);
874    #ifdef __WIN32__
875       //root.name = rootName;
876       AddTreeNode(root, true, false, null, list);
877    #else
878       //root.name = "/";
879    #endif
880       AddTreeNode(root, false, true, null);
881
882    // How can this make sense for linux? 
883    #ifdef __WIN32__
884       while(listing.Find())
885       {
886          int len = strlen(listing.name);
887          char info[MAX_LOCATION];
888          char name[MAX_LOCATION];
889          if(listing.stats.attribs.isDrive && 
890                len > 3 && !strncmp(&listing.name[1], ": [", 3))
891          {
892             strncpy(name, listing.name, 2);
893             name[2] = 0;
894             strncpy(info, &listing.name[4], len - 5);
895             info[len - 5] = 0;
896          }
897          else
898          {
899             strcpy(name, listing.name);
900             info[0] = 0;
901          }
902
903          parent = MakeFileSystemNode(listing.stats, name);
904          if(info[0])
905             parent.info = CopyString(info);
906          parent.loaded = true;
907          AddTreeNode(parent, !listing.stats.attribs.isDirectory, listing.stats.attribs.isDirectory, root, this);
908          if(!listing.stats.attribs.isDirectory)
909             parent.childrenLoaded = true;
910       }
911
912       node = FileSystemNode { name = msNetwork, type = network };
913       AddTreeNode(node, false, true, null, this);
914       node.row.collapsed = true;
915       Sort(nameField, 1);
916       SelectRow(root.row);
917    #endif
918       LoadTreeNode(root);
919       list.Sort(nameField, 1);
920    }
921
922    void LoadTreeNode(FileSystemNode node)
923    {
924       if(!node.loaded)
925       {
926          char path[MAX_LOCATION];
927          node.GetPath(path);
928          {
929             FileListing listing { path, extensions = extensions };
930             if(node.children.count == 1)
931             DeleteNode(node.children.first);
932
933             while(listing.Find())
934             {
935                if((!bits.foldersOnly && !bits.filesOnly) ||
936                   (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
937                   (bits.filesOnly && !listing.stats.attribs.isDirectory/*listing.stats.attribs.isFile*/)) // TOCHECK: isFile broken?
938                {
939                   FileSystemNode child = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
940                   AddTreeNode(child, true, false, node);
941                   NodeChildLoad(child, node);
942                }
943             }
944          }
945          node.childrenLoaded = true;
946          node.loaded = true;
947          node.row.SortSubRows(false);
948       }
949       else if(!node.childrenLoaded)
950       {
951          FileSystemNode child;
952          if(node.children.first)
953          {
954             for(child = node.children.first; child; child = child.next)
955             {
956                if(!child.loaded)
957                   LoadTreeNode(child);
958                else if(!child.childrenLoaded)
959                   NodeChildLoad(child, node);
960             }
961             node.childrenLoaded = true;
962             node.row.SortSubRows(false);
963          }
964       }
965    }
966
967    void NodeChildLoad(FileSystemNode parent, FileSystemNode node)
968    {
969       char path[MAX_LOCATION];
970       parent.GetPath(path);
971       {
972          bool added = false;
973          FileListing listing { path, extensions = extensions };
974          while(listing.Find())
975          {
976             if((!bits.foldersOnly && !bits.filesOnly) ||
977                (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
978                (bits.filesOnly && !listing.stats.attribs.isDirectory/*listing.stats.attribs.isFile*/)) // TOCHECK: isFile broken?
979             {
980                FileSystemNode child = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
981                AddTreeNode(child, true, false, parent);
982                added = true;
983             }
984          }
985          if(!added)
986             added = true;
987       }
988       //parent.childrenLoaded = true;
989    }
990
991    void AddTreeNode(FileSystemNode node, bool loaded, bool addLoader, FileSystemNode addTo)
992    {
993       DataRow row = (addTo && addTo.row) ? addTo.row.AddRow() : list.AddRow();
994       if(addTo)
995       {
996          node.parent = addTo;
997          node.indent = addTo.indent + 1;
998          addTo.children.Add(node);
999       }
1000       row.tag = (int)node;
1001       node.row = row;
1002       row.SetData(null, node);
1003
1004       node.loaded = loaded;
1005       if(addLoader)
1006          //AddTreeNode(FileSystemNode { }, false, false, node); // why would this create a compile error?
1007          AddTreeNode(FileSystemNode { type = none }, false, false, node);
1008
1009       if(node.indent > 0)
1010          row.collapsed = true;
1011       else if(node.type == folder)
1012          node.type = folderOpen;
1013    }
1014
1015    void DeleteNode(FileSystemNode node)
1016    {
1017       FileSystemNode child;
1018       for(; (child = node.children.first); )
1019          DeleteNode(child);
1020       list.DeleteRow(node.row);
1021       node.Delete();
1022    }
1023 /*
1024 public class ClipBoardFiles
1025 {
1026
1027 public:
1028
1029    property
1030
1031 }
1032
1033    // CLIPBOARD
1034    void Copy()
1035    {
1036       if(this)
1037       {
1038          int size = SelSize();
1039          if(size)
1040          {
1041             // Try to allocate memory
1042             ClipBoard clipBoard { };
1043             if(clipBoard.Allocate(size+1))
1044             {
1045                GetSel(clipBoard.memory, true);   
1046                // Save clipboard
1047                clipBoard.Save();
1048             }
1049             delete clipBoard;
1050          }
1051       }
1052    }
1053
1054    void Paste()
1055    {
1056       if(this)
1057       {
1058          ClipBoard clipBoard { };
1059          if(clipBoard.Load())
1060             PutS(clipBoard.memory);
1061          delete clipBoard;
1062       }
1063    }
1064
1065    void Cut()
1066    {
1067       if(this)
1068       {
1069          Copy();
1070          DelSel();
1071          SetViewToCursor(true);
1072          Modified();
1073       }
1074    }
1075
1076 Private Type DROPFILES
1077    pFiles As Long
1078    pt As POINTAPI
1079    fNC As Long
1080    fWide As Long
1081 End Type
1082 For iCounter = 0 To filelist.ListCount - 1
1083   If filelist.Selected(iCounter) = True Then
1084     strFiles = strFiles & FixPath(filelist.Path) & filelist.List(iCounter) & vbNullChar
1085   End If
1086 Next
1087 'all selected items are now put in strFiles
1088
1089 hGlobal = GlobalAlloc(GHND, Len(DF) + Len(strFiles)) 'put all files to a exclusive number
1090 If hGlobal Then 'if the globalalloc worked
1091   lpGlobal = GlobalLock(hGlobal) 'lock the hGlobal
1092   DF.pFiles = Len(DF) 'set the size of the files
1093   
1094   Call CopyMem(ByVal lpGlobal, DF, Len(DF)) 'copy df to the lpglobal
1095   Call CopyMem(ByVal (lpGlobal + Len(DF)), ByVal strFiles, Len(strFiles)) 'copy strfiles to lpglobal
1096   Call GlobalUnlock(hGlobal) 'unlock hglobal again
1097   
1098   SetClipboardData CF_HDROP, hGlobal 'put files to the clipboard
1099 End If
1100
1101    bool SaveFile(const char * filePath)
1102    {
1103    }
1104 */
1105
1106 }