4 static char * rootName = "Entire Computer";
5 static char * msNetwork = "Microsoft Windows Network";
7 static char * rootName = "File System";
11 define guiApp = ((GuiApplication)__thisModule);
12 define selectionColor = guiApp.currentSkin.selectionColor; //Color { 10, 36, 106 };
14 static char * fileIconNames[] =
16 "<:ecere>mimeTypes/file.png", /* none */
18 "<:ecere>mimeTypes/file.png", /* normalFile */
19 "<:ecere>mimeTypes/textEcereWorkspace.png", /* ewsFile */
20 "<:ecere>mimeTypes/textEcereProject.png", /* epjFile */
21 "<:ecere>mimeTypes/textEcereSource.png", /* ecFile */
22 "<:ecere>mimeTypes/textEcereHeader.png", /* ehFile */
23 "<:ecere>mimeTypes/textCSource.png", /* cFile */
24 "<:ecere>mimeTypes/textCHeader.png", /* hFile */
25 "<:ecere>mimeTypes/textC++Source.png", /* cppFile */
26 "<:ecere>mimeTypes/textC++Header.png", /* hppFile */
27 "<:ecere>mimeTypes/text.png", /* textFile */
28 "<:ecere>mimeTypes/textHyperTextMarkup.png", /* webFile */
29 "<:ecere>mimeTypes/image.png", /* pictureFile */
30 "<:ecere>status/audioVolumeHigh.png", /* soundFile */
31 "<:ecere>mimeTypes/package.png", /* archiveFile */
32 "<:ecere>mimeTypes/packageSoftware.png", /* packageFile */
33 "<:ecere>mimeTypes/packageOpticalDisc.png", /* opticalMediaImageFile */
35 "<:ecere>places/folder.png", /* folder */
36 "<:ecere>status/folderOpen.png", /* folderOpen */
37 "<:ecere>devices/computer.png", /* computer */
38 "<:ecere>devices/driveHardDisk.png", /* drive */
39 "<:ecere>places/driveRemote.png", /* netDrive */
40 "<:ecere>devices/mediaOptical.png", /* cdrom */
41 "<:ecere>devices/driveRemovableMedia.png", /* removable */
42 "<:ecere>devices/mediaFloppy.png", /* floppy */
43 "<:ecere>places/networkWorkgroup.png", /* network */
44 "<:ecere>places/networkServer.png", /* server */
45 "<:ecere>places/folderRemote.png", /* share */
47 "<:ecere>mimeTypes/package.png", /* treeLoader */
48 "<:ecere>places/startHere.png", /* lineNumbers */
53 public enum ExplorerFileType
57 normalFile, ewsFile, epjFile, ecFile, ehFile, cFile, hFile, cppFile, hppFile,
58 textFile, webFile, pictureFile, soundFile,
59 archiveFile, packageFile, opticalMediaImageFile, /* these (all previous) are sort equal */
61 folder, folderOpen, computer,
62 drive, netDrive, cdrom, removable, floppy, network, server, share, // these are sort equal
73 this = SelectByExtension(value);
77 public property bool isFolderType
79 get { return this >= folder && this <= share; }
82 public property bool isFileType
84 get { return this >= normalFile && this <= opticalMediaImageFile; }
87 ExplorerFileType ::SelectByExtension(char * extension)
89 if(!strcmpi(extension, "ews"))
91 else if(!strcmpi(extension, "epj"))
93 else if(!strcmpi(extension, "ec"))
95 else if(!strcmpi(extension, "eh"))
97 else if(!strcmpi(extension, "cpp") ||
98 !strcmpi(extension, "cc") || !strcmpi(extension, "cxx"))
100 else if(!strcmpi(extension, "hpp") ||
101 !strcmpi(extension, "hh") || !strcmpi(extension, "hxx"))
103 else if(!strcmpi(extension, "c"))
105 else if(!strcmpi(extension, "h"))
107 else if(!strcmpi(extension, "txt") || !strcmpi(extension, "text") ||
108 !strcmpi(extension, "nfo") || !strcmpi(extension, "info"))
110 else if(!strcmpi(extension, "htm") || !strcmpi(extension, "html") ||
111 !strcmpi(extension, "css") || !strcmpi(extension, "php") ||
112 !strcmpi(extension, "js"))
114 else if(!strcmpi(extension, "bmp") || !strcmpi(extension, "pcx") ||
115 !strcmpi(extension, "jpg") || !strcmpi(extension, "jpeg") ||
116 !strcmpi(extension, "gif") || !strcmpi(extension, "png") ||
117 !strcmpi(extension, "ico"))
119 else if(!strcmpi(extension, "wav") || !strcmpi(extension, "mp3") ||
120 !strcmpi(extension, "ogg") || !strcmpi(extension, "snd"))
122 else if(!strcmpi(extension, "ear") || !strcmpi(extension, "7z") ||
123 !strcmpi(extension, "rar") || !strcmpi(extension, "zip") ||
124 !strcmpi(extension, "gz") || !strcmpi(extension, "bz2") ||
125 !strcmpi(extension, "tar") || !strcmpi(extension, "arj") ||
126 !strcmpi(extension, "lza") || !strcmpi(extension, "lzh") ||
127 !strcmpi(extension, "cpio") || !strcmpi(extension, "z"))
129 else if(!strcmpi(extension, "cab") || !strcmpi(extension, "deb") ||
130 !strcmpi(extension, "rpm"))
132 else if(!strcmpi(extension, "iso") || !strcmpi(extension, "mds") ||
133 !strcmpi(extension, "cue") || !strcmpi(extension, "bin") ||
134 !strcmpi(extension, "ccd") || !strcmpi(extension, "bwt") ||
135 !strcmpi(extension, "cdi") || !strcmpi(extension, "nrg"))
136 return opticalMediaImageFile;
142 class ExplorerControl : Window
144 bool previewPictures;
146 BitmapResource fileIcons[ExplorerFileType];
151 for(c = 0; c < ExplorerFileType::enumSize; c++)
153 fileIcons[c] = BitmapResource { fileIconNames[c], alphaBlend = true };
154 AddResource(fileIcons[c]);
161 class ExplorerView : ExplorerControl
164 hasHorzScroll = false;
165 hasVertScroll = false;
167 virtual void Load(ExplorerFileBranch parent);
168 virtual void Refresh();
170 virtual void LaunchNotifyItemSelect(Window master, ExplorerView view, ExplorerFileItem item, ExplorerFileItemArray selectedItems)
172 view.NotifyItemSelect(master, view, item, selectedItems);
175 virtual bool Window::NotifyItemSelect(ExplorerView view, ExplorerFileItem item, ExplorerFileItemArray selectedItems);
176 virtual bool Window::NotifyItemOpen(ExplorerView view, ExplorerFileItem item);
180 master = master, parent = this;
183 hasHorzScroll = true;
184 hasVertScroll = true;
187 fullRowSelect = false;
190 anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
192 bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
194 ExplorerView view = (ExplorerView)listBox.parent;
195 if(listBox.currentRow)
198 ExplorerFileItemArray selectedItems { growingFactor = 16 };
199 for(listRow = listBox.firstRow; listRow; listRow = listRow.next)
201 selectedItems.Add((ExplorerFileItem)listRow.tag);
202 //view.NotifyItemSelect(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
203 view.LaunchNotifyItemSelect(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag, selectedItems);
208 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
210 ExplorerView view = (ExplorerView)listBox.parent;
211 view.NotifyItemOpen(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
215 bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
217 if((SmartKey)key == enter)
219 ExplorerView view = (ExplorerView)listBox.parent;
220 view.NotifyItemOpen(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
233 class ExplorerViewList : ExplorerView
236 ExplorerFileBranch location;
240 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
242 ExplorerViewDetails()
244 list.AddField(nameField);
252 void Load(ExplorerFileBranch location)
254 char path[MAX_LOCATION];
255 this.location = location;
256 location.GetPath(path);
258 FileListing listing { path };
260 ExplorerFileItem item;
265 while(listing.Find())
267 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
271 row.SetData(nameField, item);
273 list.Sort(nameField, 1);
280 class ExplorerViewDetails : ExplorerView
282 list.hasHeader = true;
283 list.moveFields = true;
284 list.resizable = true;
285 list.sortable = true;
287 ExplorerFileBranch location;
291 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
292 DataField typeField { header = "Type", dataType = /*"String"*/ "char *", width = 40 };
293 DataField sizeField { header = "Size", dataType = "FileSize", width = 96, alignment = right };
295 ExplorerViewDetails()
297 list.AddField(nameField);
298 list.AddField(typeField);
299 list.AddField(sizeField);
307 void Load(ExplorerFileBranch location)
309 char path[MAX_LOCATION];
310 this.location = location;
311 location.GetPath(path);
313 FileListing listing { path };
315 ExplorerFileItem item;
320 while(listing.Find())
322 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
326 row.SetData(nameField, item);
327 row.SetData(typeField, CopyString(item.extension));
328 row.SetData(sizeField, (uint)listing.stats.size);
330 list.Sort(nameField, 1);
337 class ExplorerViewIcons : ExplorerView
340 ExplorerFileBranch location;
344 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
346 ExplorerViewDetails()
348 list.AddField(nameField);
356 void Load(ExplorerFileBranch location)
358 char path[MAX_LOCATION];
359 this.location = location;
360 location.GetPath(path);
362 FileListing listing { path };
364 ExplorerFileItem item;
369 while(listing.Find())
371 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
375 row.SetData(nameField, item);
377 list.Sort(nameField, 1);
384 class ExplorerViewCards : ExplorerView
387 ExplorerFileBranch location;
391 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
393 ExplorerViewDetails()
395 list.AddField(nameField);
403 void Load(ExplorerFileBranch location)
405 char path[MAX_LOCATION];
406 this.location = location;
407 location.GetPath(path);
409 FileListing listing { path };
411 ExplorerFileItem item;
416 while(listing.Find())
418 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
422 row.SetData(nameField, item);
424 list.Sort(nameField, 1);
431 public class BitmapArray : RedjArray
433 type = class(Bitmap);
436 Bitmap * Add(Bitmap bitmap)
443 Bitmap * AddBefore(uint position, Bitmap bitmap)
446 _[position] = bitmap;
452 for(c = 0; c < _count; c++)
464 class ExplorerViewShowcase : ExplorerView
466 list.anchor = Anchor { left = 0, top = 0, bottom = 0 };
467 list.size = Size { w = 200 };
469 ExplorerFileBranch location;
473 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 180, editable = true, userData = this };
476 BitmapArray bitmaps { growingFactor = 16 };
482 anchor = Anchor { top = 0, right = 0, bottom = 0 };
484 void OnRedraw(Surface surface)
486 ExplorerViewShowcase view = (ExplorerViewShowcase)parent;
489 int wBmp = view.bitmap.width;
490 int hBmp = view.bitmap.height;
491 int wWnd = clientSize.w;
492 int hWnd = clientSize.h;
494 int wList = view.list.size.w + view.split.size.w;
496 float scale = Min((float)(wWnd - 10) / wBmp, (float)(hWnd - 10) / hBmp);
498 int wDraw = (int)(wBmp * scale);
499 int hDraw = (int)(hBmp * scale);
502 surface.Filter(view.bitmap, (wWnd - wDraw) / 2, (hWnd - hDraw) / 2, 0, 0, wDraw, hDraw, wBmp, hBmp);
504 // Until Filter / Stretch works with X
505 surface.Blit(view.bitmap, (wWnd - wDraw) / 2, (hWnd - hDraw) / 2, 0, 0, wDraw, hDraw);
510 surface.SetForeground(white);
511 surface.Area(0, 0, view.clientSize.w - 1, view.clientSize.h - 1);
525 ExplorerViewDetails()
527 list.AddField(nameField);
530 void LaunchNotifyItemSelect(Window master, ExplorerViewShowcase view, ExplorerFileItem item, ExplorerFileItemArray selectedItems)
533 ExplorerFileItem selItem;
537 if(item && item.type == pictureFile)
539 view.bitmap = Bitmap { };
540 view.bitmap.Load(item.path, null, displaySystem);
543 view.bitmaps.Clear();
544 view.bitmaps = BitmapArray { };
545 for(pos = 0; pos < selectedItems.count; pos++)
548 selItem = (ExplorerFileItem)selectedItems._[pos];
549 bitmap.Load(selItem.path, null, displaySystem);
550 //view.bitmaps.Add(bitmap);
552 if(item && item.type == pictureFile)
554 view.bitmap = Bitmap { };
555 view.bitmap.Load(item.path, null, displaySystem);
558 view.show.Update(null);
559 view.NotifyItemSelect(master, view, item, selectedItems);
567 void Load(ExplorerFileBranch location)
569 char path[MAX_LOCATION];
570 this.location = location;
571 location.GetPath(path);
573 FileListing listing { path };
575 ExplorerFileItem item;
580 while(listing.Find())
582 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
586 row.SetData(nameField, item);
588 list.Sort(nameField, 1);
595 class ExplorerTree : ExplorerControl
597 hasHorzScroll = false;
598 hasVertScroll = false;
604 DataField nameField { dataType = "ExplorerFileBranch", width = 240, userData = this };
606 ExplorerFileBranch root;
607 ExplorerFileBranch selection;
609 virtual bool Window::NotifyBranchSelect(ExplorerTree tree, ExplorerFileBranch branch);
611 property ExplorerFileBranch branch
619 if(!tree.currentRow.tag)
621 return (ExplorerFileBranch)tree.currentRow.tag;
625 void Select(ExplorerFileBranch branch)
629 branch.EnsureVisible(false);
630 tree.SelectRow(branch.row);
634 ExplorerFileBranch Find(const char * name, ExplorerFileBranch parent)
636 ExplorerFileBranch branch;
637 ExplorerFileBranch start = parent ? parent : root;
638 if(!start.loaded || !start.childrenLoaded)
639 BranchLoad(start, tree);
640 for(branch = start.children.first; branch; branch = branch.next)
641 if(branch.name && !strcmpi(branch.name, name))
648 master = master, parent = this;
651 hasHorzScroll = true;
652 hasVertScroll = true;
653 fullRowSelect = false;
655 collapseControl = true;
656 rootCollapseButton = true;
658 anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
660 // WHY is this not working ?
661 /*void OnResize(int width, int height)
663 if(vertScroll.visible)
664 nameField.width = width - vertScroll.size.w;
666 nameField.width = width;
669 bool NotifyCollapse(ListBox listBox, DataRow row, bool collapsed)
673 ExplorerFileBranch branch = (ExplorerFileBranch)row.tag;
674 ExplorerFileBranch child;
678 for(child = branch.children.last; child; child = branch.children.last)
680 listBox.DeleteRow(child.row);
684 branch.childrenLoaded = false;
689 if(!branch.loaded || !branch.childrenLoaded)
690 BranchLoad(branch, tree);
691 for(child = branch.children.first; child && child.next; child = child.next);
693 child.EnsureVisible(false);
699 bool NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods)
701 DataRow row = listBox.currentRow;
704 ExplorerFileBranch branch = (ExplorerFileBranch)row.tag;
710 MenuItem { menu, "Cut\tCtrl+X", t, NotifySelect = null, disabled = false };
711 MenuItem { menu, "Copy\tCtrl+C", c, NotifySelect = null, disabled = false };
712 MenuItem { menu, "Paste\tCtrl+V", p, NotifySelect = null, disabled = false /*!clipboard*/ };
713 MenuItem { menu, "Delete\tDel", d, NotifySelect = null, disabled = false };
714 //MenuDivider { menu };
718 master = this, menu = menu,
720 x + clientStart.x + absPosition.x - guiApp.desktop.position.x,
721 y + clientStart.y + absPosition.y - guiApp.desktop.position.y }
729 bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
733 ExplorerFileBranch branch = (ExplorerFileBranch)row.tag;
734 NotifyBranchSelect(listBox.parent.master, this, branch);
740 bool NotifyEditing(ListBox listBox, DataRow row)
744 ExplorerFileBranch branch = (ExplorerFileBranch)row.tag;
749 bool NotifyEdited(ListBox listBox, DataRow row)
753 ExplorerFileBranch branch = (ExplorerFileBranch)row.tag;
758 bool NotifyEditDone(ListBox listBox, DataRow row)
762 ExplorerFileBranch branch = (ExplorerFileBranch)row.tag;
769 Menu editMenu { menu, "Edit", e };
772 editMenu, "Cut\tCtrl+X", t, disabled = true;
774 bool NotifySelect(MenuItem selection, Modifiers mods)
780 MenuItem itemEditCopy
782 editMenu, "Copy\tCtrl+C", c, disabled = true;
784 bool NotifySelect(MenuItem selection, Modifiers mods)
790 MenuItem itemEditPaste
792 editMenu, "Paste\tCtrl+V", p;
794 bool NotifySelect(MenuItem selection, Modifiers mods)
800 MenuItem itemEditDelete
802 editMenu, "Delete\tDel", d, disabled = true;
804 bool NotifySelect(MenuItem selection, Modifiers mods)
811 // WHY is this crashing ?
812 /*void OnResize(int width, int height)
814 if(this && nameField)
815 nameField.width = width - 80;
820 tree.AddField(nameField);
825 ExplorerFileBranch parent;
826 ExplorerFileBranch branch;
827 FileListing listing { "/" };
831 root = ExplorerFileBranch { type = computer, loaded = true, childrenLoaded = true };
833 root.name = rootName;
837 AddBranch(root, true, false, null, tree);
839 // How can this make sense for linux?
841 while(listing.Find())
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))
849 strncpy(name, listing.name, 2);
851 strncpy(info, &listing.name[4], len - 5);
856 strcpy(name, listing.name);
860 parent = MakeFileBranch(listing.stats, name);
862 parent.info = CopyString(info);
863 parent.loaded = true;
864 AddBranch(parent, !listing.stats.attribs.isDirectory, listing.stats.attribs.isDirectory, root, tree);
865 if(!listing.stats.attribs.isDirectory)
866 parent.childrenLoaded = true;
869 branch = ExplorerFileBranch { name = msNetwork, type = network };
870 AddBranch(branch, false, true, null, tree);
871 branch.row.collapsed = true;
872 tree.Sort(nameField, 1);
873 tree.SelectRow(root.row);
878 public class ClipBoardFiles
892 int size = SelSize();
895 // Try to allocate memory
896 ClipBoard clipBoard { };
897 if(clipBoard.Allocate(size+1))
899 GetSel(clipBoard.memory, true);
912 ClipBoard clipBoard { };
914 PutS(clipBoard.memory);
925 SetViewToCursor(true);
930 Private Type DROPFILES
936 For iCounter = 0 To filelist.ListCount - 1
937 If filelist.Selected(iCounter) = True Then
938 strFiles = strFiles & FixPath(filelist.Path) & filelist.List(iCounter) & vbNullChar
941 'all selected items are now put in strFiles
943 hGlobal = GlobalAlloc(GHND, Len(DF) + Len(strFiles)) 'put all files to a exclusive number
944 If hGlobal Then 'if the globalalloc worked
945 lpGlobal = GlobalLock(hGlobal) 'lock the hGlobal
946 DF.pFiles = Len(DF) 'set the size of the files
948 Call CopyMem(ByVal lpGlobal, DF, Len(DF)) 'copy df to the lpglobal
949 Call CopyMem(ByVal (lpGlobal + Len(DF)), ByVal strFiles, Len(strFiles)) 'copy strfiles to lpglobal
950 Call GlobalUnlock(hGlobal) 'unlock hglobal again
952 SetClipboardData CF_HDROP, hGlobal 'put files to the clipboard
955 bool SaveFile(const char * filePath)
964 public class FileTreeBranchBSArray : ArrayBinarySorted
966 type = class(ExplorerFileBranch);
968 ExplorerFileBranch * const _;
969 BSloc Add(ExplorerFileBranch item)
971 BSloc result = Find(item);
974 Insert(result.pos, 1);
975 _[result.pos] = item;
979 BSloc Remove(ExplorerFileBranch item)
987 public class FileTreeBranchArray : RedjArray
989 type = class(ExplorerFileBranch);
991 ExplorerFileBranch * const _;
992 ExplorerFileBranch * Add(ExplorerFileBranch item)
999 ExplorerFileBranch * AddBefore(uint position, ExplorerFileBranch item)
1001 Insert(position, 1);
1003 return &_[position];
1009 public class ExplorerFileItem : struct
1015 ExplorerFileType type;
1020 void OnDisplay(Surface surface, int x, int y, int width, ExplorerControl control, Alignment alignment, DataDisplayFlags displayFlags)
1022 int indentSize = (displayFlags.dropBox) ? 0 : 10;
1025 char label[MAX_FILENAME];
1027 //float scale = Min((float)clientSize.w / (float)bitmap.width, (float)clientSize.h / (float)bitmap.height);
1028 int w = 16; //(int)(bitmap.width * scale);
1029 int h = 16; //(int)(bitmap.height * scale);
1033 icon = control.fileIcons[type].bitmap;
1036 if(type == folder || type == folderOpen)
1037 surface.SetForeground(red); //Color { 170, 170, 0 } // REDJ What is that color?
1040 textOffset = indent * indentSize + (icon ? (icon.width + 6) : 0);
1043 sprintf(label, "%s [%s]", name, info);
1045 strcpy(label, name);
1046 len = strlen(label);
1048 surface.WriteTextDots
1049 (alignment, x + textOffset, y + 2, width - textOffset, label, len);
1050 if(type == pictureFile && control.previewPictures && bitmap)
1053 //surface.Filter(bitmap, (clientSize.w - w) / 2,(clientSize.h - h) / 2, 0,0, w, h, bitmap.width, bitmap.height);
1054 surface.Filter(bitmap, x + indent * indentSize + 2, y, 0, 0, w, h, bitmap.width, bitmap.height);
1056 // Until Filter / Stretch works with X
1057 //surface.Blit(bitmap, (clientSize.w - bitmap.width) / 2,(clientSize.h - bitmap.height) / 2, 0,0, bitmap.width, bitmap.height);
1058 surface.blend = true;
1059 surface.Blit(bitmap, x + indent * indentSize + 2, y,0,0, w, h);
1065 surface.Blit(icon, x + indent * indentSize + 2, y,0,0, icon.width, icon.height);
1068 int OnCompare(ExplorerFileItem b)
1071 if(type == b.type || (type < folder && b.type < folder) || (type >= drive))
1072 result = strcmpi(name, b.name);
1075 if(type == folder && b.type < folder) result = -1;
1076 else if(type < folder && b.type == folder) result = 1;
1081 void OnCopy(ExplorerFileItem newData)
1083 type = newData.type;
1084 indent = newData.indent;
1087 int len = strlen(newData.name) + 1;
1088 name = new char[len];
1089 CopyBytes(name, newData.name, len);
1093 bool OnGetDataFromString(char * string)
1095 int len = strlen(string) + 1;
1096 name = new char[len];
1097 CopyBytes(name, string, len);
1111 char * OnGetString(char * string, void * fieldData, bool * needClass)
1117 public class ExplorerFileItemArray : RedjArray
1119 type = class(ExplorerFileItem);
1121 ExplorerFileItem * const _;
1122 ExplorerFileItem * Add(ExplorerFileItem item)
1129 ExplorerFileItem * AddBefore(uint position, ExplorerFileItem item)
1131 Insert(position, 1);
1133 return &_[position];
1138 for(c = 0; c < _count; c++)
1148 ExplorerFileItem MakeFileItem(const FileAttribs attribs, const char * fileName, const char * filePath, const bool previewPicture, const DisplaySystem displaySystem)
1150 int len = strlen(fileName);
1151 char info[MAX_LOCATION];
1152 char name[MAX_LOCATION];
1153 char extension[MAX_EXTENSION];
1155 ExplorerFileItem item { };
1157 //if(attribs.isFile) // TODO fix this in ecere
1158 if(attribs.isDirectory)
1162 item.type = (attribs.isDrive) ? drive : folder;
1163 if(attribs.isServer)
1169 if(attribs.isRemote)
1170 item.type = netDrive;
1171 if(attribs.isRemovable)
1173 if(fileName[0] == 'A' || fileName[0] == 'B')
1176 item.type = removable;
1181 GetExtension(fileName, extension);
1182 //strupr(extension);
1185 item.type = ExplorerFileType::SelectByExtension(extension);
1188 if(attribs.isDrive &&
1189 len > 3 && !strncmp(&fileName[1], ": [", 3))
1191 strncpy(name, fileName, 2);
1193 strncpy(info, &fileName[4], len - 5);
1198 strcpy(name, fileName);
1202 item.path = CopyString(filePath);
1203 item.name = CopyString(name);
1205 item.info = CopyString(info);
1206 item.extension = CopyString(extension);
1208 if(item.type == pictureFile && previewPicture)
1210 item.bitmap = Bitmap { };
1211 item.bitmap.Load(filePath, null, displaySystem);
1219 public class ExplorerFileBranch : struct
1221 ExplorerFileBranch prev, next;
1223 bool loaded, childrenLoaded;
1229 ExplorerFileType type;
1230 ExplorerFileBranch parent;
1234 void GetPath(String outputPath)
1236 ExplorerFileBranch up;
1239 strcpy(outputPath, name);
1240 for(up = parent; up; up = up.parent)
1242 char temp[MAX_LOCATION];
1243 strcpy(temp, up.name);
1244 PathCat(temp, outputPath);
1245 strcpy(outputPath, temp);
1250 strcpy(outputPath, "/");
1252 strcpy(outputPath, name);
1257 bool IsChildOf(ExplorerFileBranch branch)
1259 ExplorerFileBranch test;
1260 for(test = parent; test; test = test.parent)
1266 void DuplicateChildren(bool recursive, bool forceExpanded, ExplorerFileBranch addTo, ListBox tree)
1270 ExplorerFileBranch child;
1272 for(child = children.first; child; child = child.next)
1274 ExplorerFileBranch copy { };
1275 copy.name = CopyString(child.name);
1276 copy.type = child.type;
1277 AddBranch(copy, child.loaded, false, addTo, tree);
1279 copy.row.collapsed = false;
1281 child.DuplicateChildren(recursive, forceExpanded, copy, tree);
1286 void EnsureVisible(bool expand)
1289 parent.EnsureVisible(true);
1291 row.collapsed = false;
1292 // TODO: row.EnsureVisible(); // making the row visible by scrolling
1302 ExplorerFileBranch child;
1303 for(; (child = children.first); )
1306 children.Delete(child);
1317 parent.children.Delete(this);
1320 void OnDisplay(Surface surface, int x, int y, int width, ExplorerControl control, Alignment alignment, DataDisplayFlags displayFlags)
1322 //int indentSize = (displayFlags.dropBox) ? 0 : 10;
1328 char label[MAX_FILENAME];
1335 icon = control.fileIcons[type].bitmap;
1336 //xStart = indent * indent + x + (icon ? (icon.width + 5) : 0);
1337 xStart = x + (icon ? (icon.width + 5) : 0);
1343 sprintf(label, "%s [%s]", name, info);
1345 strcpy(label, name);
1346 len = strlen(label);
1350 if(type == folder || type == folderOpen)
1351 surface.SetForeground(yellow);
1355 //textOffset = indent * indentSize + (icon ? (icon.width + 4) : 0);
1357 surface.TextOpacity(false);
1358 surface.TextExtent(label, len, &w, &h);
1361 // Draw the current row stipple
1362 if(displayFlags.selected)
1363 //surface.Area(xStart - 1, y, xStart - 1, y + h - 1);
1364 //surface.Area(xStart + w - 1, y, xStart + w + 1, y + h - 1);
1365 surface.Area(xStart - 3, y, xStart + w + 1, y + h - 1);
1367 //surface.WriteTextDots(alignment, x + textOffset, y + 2, width - textOffset, name, strlen(name));
1368 surface.WriteTextDots(alignment, xStart, y + 2, width, label, len);
1370 if(!guiApp.textMode)
1372 if(displayFlags.current)
1374 if(displayFlags.active)
1376 surface.LineStipple(0x5555);
1377 if(displayFlags.selected)
1378 surface.SetForeground(0xFFFFFF80);
1380 surface.SetForeground(black);
1384 surface.SetForeground(selectionColor);
1386 surface.Rectangle(xStart - 3, y, xStart + w + 1, y + h - 1);
1387 surface.LineStipple(0);
1392 //surface.blend = true;
1393 //surface.alphaWrite = blend;
1394 surface.SetForeground(white);
1395 //surface.Blit(icon, x + indent * indentSize, y,0,0, icon.width, icon.height);
1396 surface.Blit(icon, x,y,0,0, icon.width, icon.height);
1401 int OnCompare(ExplorerFileBranch b)
1404 if(type == b.type || (type < folder && b.type < folder) || (type >= drive))
1405 result = strcmpi(name, b.name);
1408 if(type == folder && b.type < folder) result = -1;
1409 else if(type < folder && b.type == folder) result = 1;
1414 char * OnGetString(char * tempString, FileSystemToolWindow fileSysToolWnd, bool * needClass)
1416 return name ? name : "";
1420 ExplorerFileBranch MakeFileBranch(const FileStats stats, const char * name)
1422 ExplorerFileBranch fileTreeBranch { stats = stats };
1423 fileTreeBranch.name = CopyString(name);
1424 if(!fileTreeBranch.name)
1425 fileTreeBranch.name = null;
1426 if(stats.attribs.isDirectory)
1428 fileTreeBranch.type = (stats.attribs.isDrive) ? drive : folder;
1429 if(stats.attribs.isServer) fileTreeBranch.type = server;
1430 if(stats.attribs.isShare) fileTreeBranch.type = share;
1431 if(stats.attribs.isCDROM) fileTreeBranch.type = cdrom;
1432 if(stats.attribs.isRemote) fileTreeBranch.type = netDrive;
1433 if(stats.attribs.isRemovable)
1435 if(name[0] == 'A' || name[0] == 'B')
1436 fileTreeBranch.type = floppy;
1438 fileTreeBranch.type = removable;
1443 char extension[MAX_EXTENSION];
1444 GetExtension(fileTreeBranch.name, extension);
1445 fileTreeBranch.type = ExplorerFileType::SelectByExtension(extension);
1447 return fileTreeBranch;
1450 void AddBranch(ExplorerFileBranch branch, bool loaded, bool addLoader, ExplorerFileBranch addTo, ListBox tree)
1452 DataRow row = (addTo && addTo.row) ? addTo.row.AddRow() : tree.AddRow();
1455 branch.parent = addTo;
1456 branch.indent = addTo.indent + 1;
1457 addTo.children.Add(branch);
1459 row.tag = (int)branch;
1461 row.SetData(null, branch);
1463 branch.loaded = loaded;
1465 //AddBranch(ExplorerFileBranch { }, false, false, branch, tree); // why would this create a compile error?
1466 AddBranch(ExplorerFileBranch { type = none }, false, false, branch, tree);
1468 if(branch.indent > 0)
1469 row.collapsed = true;
1470 else if(branch.type == folder)
1471 branch.type = folderOpen;
1474 void BranchLoad(ExplorerFileBranch branch, ListBox tree)
1478 char path[MAX_LOCATION];
1479 branch.GetPath(path);
1481 FileListing listing { path };
1482 if(branch.children.count == 1)
1483 DeleteBranch(branch.children.first, tree);
1485 while(listing.Find())
1487 if(listing.stats.attribs.isDirectory)
1489 ExplorerFileBranch child = MakeFileBranch(listing.stats, listing.name);
1490 AddBranch(child, true, false, branch, tree);
1491 BranchChildLoad(child, branch, tree);
1495 branch.childrenLoaded = true;
1496 branch.loaded = true;
1497 branch.row.SortSubRows(false);
1499 else if(!branch.childrenLoaded)
1501 ExplorerFileBranch child;
1502 if(branch.children.first)
1504 for(child = branch.children.first; child; child = child.next)
1507 BranchLoad(child, tree);
1508 else if(!child.childrenLoaded)
1509 BranchChildLoad(child, branch, tree);
1511 branch.childrenLoaded = true;
1512 branch.row.SortSubRows(false);
1517 static void BranchChildLoad(ExplorerFileBranch parent, ExplorerFileBranch branch, ListBox tree)
1519 char path[MAX_LOCATION];
1520 parent.GetPath(path);
1523 FileListing listing { path };
1524 while(listing.Find())
1526 if(listing.stats.attribs.isDirectory)
1528 ExplorerFileBranch child = MakeFileBranch(listing.stats, listing.name);
1529 AddBranch(child, true, false, parent, tree);
1536 //parent.childrenLoaded = true;
1539 void DeleteBranch(ExplorerFileBranch branch, ListBox tree)
1541 ExplorerFileBranch child;
1542 for(; (child = branch.children.first); )
1543 DeleteBranch(child, tree);
1544 tree.DeleteRow(branch.row);