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 */
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
72 this = SelectByExtension(value);
76 public property bool isFolder
78 get { return this >= folder && this <= share; }
81 public property bool isFile
83 get { return this >= normalFile && this <= opticalMediaImageFile; }
86 _FileType ::SelectByExtension(char * extension)
88 if(!strcmpi(extension, "ews"))
90 else if(!strcmpi(extension, "epj"))
92 else if(!strcmpi(extension, "ec"))
94 else if(!strcmpi(extension, "eh"))
96 else if(!strcmpi(extension, "cpp") ||
97 !strcmpi(extension, "cc") || !strcmpi(extension, "cxx"))
99 else if(!strcmpi(extension, "hpp") ||
100 !strcmpi(extension, "hh") || !strcmpi(extension, "hxx"))
102 else if(!strcmpi(extension, "c"))
104 else if(!strcmpi(extension, "h"))
106 else if(!strcmpi(extension, "txt") || !strcmpi(extension, "text") ||
107 !strcmpi(extension, "nfo") || !strcmpi(extension, "info"))
109 else if(!strcmpi(extension, "htm") || !strcmpi(extension, "html") ||
110 !strcmpi(extension, "css") || !strcmpi(extension, "php") ||
111 !strcmpi(extension, "js"))
113 else if(!strcmpi(extension, "bmp") || !strcmpi(extension, "pcx") ||
114 !strcmpi(extension, "jpg") || !strcmpi(extension, "jpeg") ||
115 !strcmpi(extension, "gif") || !strcmpi(extension, "png") ||
116 !strcmpi(extension, "ico"))
118 else if(!strcmpi(extension, "wav") || !strcmpi(extension, "mp3") ||
119 !strcmpi(extension, "ogg") || !strcmpi(extension, "snd"))
121 else if(!strcmpi(extension, "ear") || !strcmpi(extension, "7z") ||
122 !strcmpi(extension, "rar") || !strcmpi(extension, "zip") ||
123 !strcmpi(extension, "gz") || !strcmpi(extension, "bz2") ||
124 !strcmpi(extension, "tar") || !strcmpi(extension, "arj") ||
125 !strcmpi(extension, "lza") || !strcmpi(extension, "lzh") ||
126 !strcmpi(extension, "cpio") || !strcmpi(extension, "z"))
128 else if(!strcmpi(extension, "cab") || !strcmpi(extension, "deb") ||
129 !strcmpi(extension, "rpm"))
131 else if(!strcmpi(extension, "iso") || !strcmpi(extension, "mds") ||
132 !strcmpi(extension, "cue") || !strcmpi(extension, "bin") ||
133 !strcmpi(extension, "ccd") || !strcmpi(extension, "bwt") ||
134 !strcmpi(extension, "cdi") || !strcmpi(extension, "nrg"))
135 return opticalMediaImageFile;
140 class ExplorerControl : Window
142 bool previewPictures;
144 BitmapResource fileIcons[_FileType];
149 for(c = 0; c < _FileType::enumSize; c++)
151 fileIcons[c] = BitmapResource { fileIconNames[c], alphaBlend = true };
152 AddResource(fileIcons[c]);
158 class ExplorerView : ExplorerControl
161 hasHorzScroll = false;
162 hasVertScroll = false;
164 virtual void Load(FileSystemNode parent);
165 virtual void Refresh();
167 virtual void LaunchNotifyItemSelect(Window master, ExplorerView view, ExplorerFileItem item, ExplorerFileItemArray selectedItems)
169 view.NotifyItemSelect(master, view, item, selectedItems);
172 virtual bool Window::NotifyItemSelect(ExplorerView view, ExplorerFileItem item, ExplorerFileItemArray selectedItems);
173 virtual bool Window::NotifyItemOpen(ExplorerView view, ExplorerFileItem item);
177 master = master, parent = this;
180 hasHorzScroll = true;
181 hasVertScroll = true;
184 fullRowSelect = false;
187 anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
189 bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
191 ExplorerView view = (ExplorerView)listBox.parent;
192 if(listBox.currentRow)
195 ExplorerFileItemArray selectedItems { growingFactor = 16 };
196 for(listRow = listBox.firstRow; listRow; listRow = listRow.next)
198 selectedItems.Add((ExplorerFileItem)listRow.tag);
199 //view.NotifyItemSelect(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
200 view.LaunchNotifyItemSelect(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag, selectedItems);
205 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
207 ExplorerView view = (ExplorerView)listBox.parent;
208 view.NotifyItemOpen(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
212 bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
214 if((SmartKey)key == enter)
216 ExplorerView view = (ExplorerView)listBox.parent;
217 view.NotifyItemOpen(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
230 class ExplorerViewList : ExplorerView
233 FileSystemNode location;
237 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
239 ExplorerViewDetails()
241 list.AddField(nameField);
249 void Load(FileSystemNode location)
251 char path[MAX_LOCATION];
252 this.location = location;
253 location.GetPath(path);
255 FileListing listing { path };
257 ExplorerFileItem item;
262 while(listing.Find())
264 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
268 row.SetData(nameField, item);
270 list.Sort(nameField, 1);
277 class ExplorerViewDetails : ExplorerView
279 list.hasHeader = true;
280 list.moveFields = true;
281 list.resizable = true;
282 list.sortable = true;
284 FileSystemNode location;
288 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
289 DataField typeField { header = "Type", dataType = /*"String"*/ "char *", width = 40 };
290 DataField sizeField { header = "Size", dataType = "FileSize", width = 96, alignment = right };
292 ExplorerViewDetails()
294 list.AddField(nameField);
295 list.AddField(typeField);
296 list.AddField(sizeField);
304 void Load(FileSystemNode location)
306 char path[MAX_LOCATION];
307 this.location = location;
308 location.GetPath(path);
310 FileListing listing { path };
312 ExplorerFileItem item;
317 while(listing.Find())
319 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
323 row.SetData(nameField, item);
324 row.SetData(typeField, CopyString(item.extension));
325 row.SetData(sizeField, (uint)listing.stats.size);
327 list.Sort(nameField, 1);
334 class ExplorerViewIcons : ExplorerView
337 FileSystemNode location;
341 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
343 ExplorerViewDetails()
345 list.AddField(nameField);
353 void Load(FileSystemNode location)
355 char path[MAX_LOCATION];
356 this.location = location;
357 location.GetPath(path);
359 FileListing listing { path };
361 ExplorerFileItem item;
366 while(listing.Find())
368 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
372 row.SetData(nameField, item);
374 list.Sort(nameField, 1);
381 class ExplorerViewCards : ExplorerView
384 FileSystemNode location;
388 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
390 ExplorerViewDetails()
392 list.AddField(nameField);
400 void Load(FileSystemNode location)
402 char path[MAX_LOCATION];
403 this.location = location;
404 location.GetPath(path);
406 FileListing listing { path };
408 ExplorerFileItem item;
413 while(listing.Find())
415 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
419 row.SetData(nameField, item);
421 list.Sort(nameField, 1);
428 public class BitmapArray : RedjArray
430 type = class(Bitmap);
433 Bitmap * Add(Bitmap bitmap)
440 Bitmap * AddBefore(uint position, Bitmap bitmap)
443 _[position] = bitmap;
449 for(c = 0; c < _count; c++)
461 class ExplorerViewShowcase : ExplorerView
463 list.anchor = Anchor { left = 0, top = 0, bottom = 0 };
464 list.size = Size { w = 200 };
466 FileSystemNode location;
470 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 180, editable = true, userData = this };
473 BitmapArray bitmaps { growingFactor = 16 };
479 anchor = Anchor { top = 0, right = 0, bottom = 0 };
481 void OnRedraw(Surface surface)
483 ExplorerViewShowcase view = (ExplorerViewShowcase)parent;
486 int wBmp = view.bitmap.width;
487 int hBmp = view.bitmap.height;
488 int wWnd = clientSize.w;
489 int hWnd = clientSize.h;
491 int wList = view.list.size.w + view.split.size.w;
493 float scale = Min((float)(wWnd - 10) / wBmp, (float)(hWnd - 10) / hBmp);
495 int wDraw = (int)(wBmp * scale);
496 int hDraw = (int)(hBmp * scale);
499 surface.Filter(view.bitmap, (wWnd - wDraw) / 2, (hWnd - hDraw) / 2, 0, 0, wDraw, hDraw, wBmp, hBmp);
501 // Until Filter / Stretch works with X
502 surface.Blit(view.bitmap, (wWnd - wDraw) / 2, (hWnd - hDraw) / 2, 0, 0, wDraw, hDraw);
507 surface.SetForeground(white);
508 surface.Area(0, 0, view.clientSize.w - 1, view.clientSize.h - 1);
522 ExplorerViewDetails()
524 list.AddField(nameField);
527 void LaunchNotifyItemSelect(Window master, ExplorerViewShowcase view, ExplorerFileItem item, ExplorerFileItemArray selectedItems)
530 ExplorerFileItem selItem;
534 if(item && item.type == pictureFile)
536 view.bitmap = Bitmap { };
537 view.bitmap.Load(item.path, null, displaySystem);
540 view.bitmaps.Clear();
541 view.bitmaps = BitmapArray { };
542 for(pos = 0; pos < selectedItems.count; pos++)
545 selItem = (ExplorerFileItem)selectedItems._[pos];
546 bitmap.Load(selItem.path, null, displaySystem);
547 //view.bitmaps.Add(bitmap);
549 if(item && item.type == pictureFile)
551 view.bitmap = Bitmap { };
552 view.bitmap.Load(item.path, null, displaySystem);
555 view.show.Update(null);
556 view.NotifyItemSelect(master, view, item, selectedItems);
564 void Load(FileSystemNode location)
566 char path[MAX_LOCATION];
567 this.location = location;
568 location.GetPath(path);
570 FileListing listing { path };
572 ExplorerFileItem item;
577 while(listing.Find())
579 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
583 row.SetData(nameField, item);
585 list.Sort(nameField, 1);
592 class ExplorerTree : ExplorerControl
594 hasHorzScroll = false;
595 hasVertScroll = false;
601 DataField nameField { dataType = "FileSystemNode", width = 240, userData = this };
604 FileSystemNode selection;
606 virtual bool Window::NotifyNodeSelect(ExplorerTree tree, FileSystemNode node);
608 property FileSystemNode node
616 if(!tree.currentRow.tag)
618 return (FileSystemNode)tree.currentRow.tag;
622 void Select(FileSystemNode node)
626 node.EnsureVisible(false);
627 tree.SelectRow(node.row);
631 FileSystemNode Find(const char * name, FileSystemNode parent)
634 FileSystemNode start = parent ? parent : root;
635 if(!start.loaded || !start.childrenLoaded)
636 NodeLoad(start, tree);
637 for(node = start.children.first; node; node = node.next)
638 if(node.name && !strcmpi(node.name, name))
645 master = master, parent = this;
648 hasHorzScroll = true;
649 hasVertScroll = true;
650 fullRowSelect = false;
652 collapseControl = true;
653 rootCollapseButton = true;
655 anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
657 // WHY is this not working ?
658 /*void OnResize(int width, int height)
660 if(vertScroll.visible)
661 nameField.width = width - vertScroll.size.w;
663 nameField.width = width;
666 bool NotifyCollapse(ListBox listBox, DataRow row, bool collapsed)
670 FileSystemNode node = (FileSystemNode)row.tag;
671 FileSystemNode child;
675 for(child = node.children.last; child; child = node.children.last)
677 listBox.DeleteRow(child.row);
681 node.childrenLoaded = false;
686 if(!node.loaded || !node.childrenLoaded)
687 NodeLoad(node, tree);
688 for(child = node.children.first; child && child.next; child = child.next);
690 child.EnsureVisible(false);
696 bool NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods)
698 DataRow row = listBox.currentRow;
701 FileSystemNode node = (FileSystemNode)row.tag;
707 MenuItem { menu, "Cut\tCtrl+X", t, NotifySelect = null, disabled = false };
708 MenuItem { menu, "Copy\tCtrl+C", c, NotifySelect = null, disabled = false };
709 MenuItem { menu, "Paste\tCtrl+V", p, NotifySelect = null, disabled = false /*!clipboard*/ };
710 MenuItem { menu, "Delete\tDel", d, NotifySelect = null, disabled = false };
711 //MenuDivider { menu };
715 master = this, menu = menu,
717 x + clientStart.x + absPosition.x - guiApp.desktop.position.x,
718 y + clientStart.y + absPosition.y - guiApp.desktop.position.y }
726 bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
730 FileSystemNode node = (FileSystemNode)row.tag;
731 NotifyNodeSelect(listBox.parent.master, this, node);
737 bool NotifyEditing(ListBox listBox, DataRow row)
741 FileSystemNode node = (FileSystemNode)row.tag;
746 bool NotifyEdited(ListBox listBox, DataRow row)
750 FileSystemNode node = (FileSystemNode)row.tag;
755 bool NotifyEditDone(ListBox listBox, DataRow row)
759 FileSystemNode node = (FileSystemNode)row.tag;
766 Menu editMenu { menu, "Edit", e };
769 editMenu, "Cut\tCtrl+X", t, disabled = true;
771 bool NotifySelect(MenuItem selection, Modifiers mods)
777 MenuItem itemEditCopy
779 editMenu, "Copy\tCtrl+C", c, disabled = true;
781 bool NotifySelect(MenuItem selection, Modifiers mods)
787 MenuItem itemEditPaste
789 editMenu, "Paste\tCtrl+V", p;
791 bool NotifySelect(MenuItem selection, Modifiers mods)
797 MenuItem itemEditDelete
799 editMenu, "Delete\tDel", d, disabled = true;
801 bool NotifySelect(MenuItem selection, Modifiers mods)
808 // WHY is this crashing ?
809 /*void OnResize(int width, int height)
811 if(this && nameField)
812 nameField.width = width - 80;
817 tree.AddField(nameField);
822 FileSystemNode parent;
824 FileListing listing { "/" };
828 root = FileSystemNode { type = computer, loaded = true, childrenLoaded = true };
830 root.name = rootName;
834 AddNode(root, true, false, null, tree);
836 // How can this make sense for linux?
838 while(listing.Find())
840 int len = strlen(listing.name);
841 char info[MAX_LOCATION];
842 char name[MAX_LOCATION];
843 if(listing.stats.attribs.isDrive &&
844 len > 3 && !strncmp(&listing.name[1], ": [", 3))
846 strncpy(name, listing.name, 2);
848 strncpy(info, &listing.name[4], len - 5);
853 strcpy(name, listing.name);
857 parent = MakeFileNode(listing.stats, name);
859 parent.info = CopyString(info);
860 parent.loaded = true;
861 AddNode(parent, !listing.stats.attribs.isDirectory, listing.stats.attribs.isDirectory, root, tree);
862 if(!listing.stats.attribs.isDirectory)
863 parent.childrenLoaded = true;
866 node = FileSystemNode { name = msNetwork, type = network };
867 AddNode(node, false, true, null, tree);
868 node.row.collapsed = true;
869 tree.Sort(nameField, 1);
870 tree.SelectRow(root.row);
875 public class ClipBoardFiles
889 int size = SelSize();
892 // Try to allocate memory
893 ClipBoard clipBoard { };
894 if(clipBoard.Allocate(size+1))
896 GetSel(clipBoard.memory, true);
909 ClipBoard clipBoard { };
911 PutS(clipBoard.memory);
922 SetViewToCursor(true);
927 Private Type DROPFILES
933 For iCounter = 0 To filelist.ListCount - 1
934 If filelist.Selected(iCounter) = True Then
935 strFiles = strFiles & FixPath(filelist.Path) & filelist.List(iCounter) & vbNullChar
938 'all selected items are now put in strFiles
940 hGlobal = GlobalAlloc(GHND, Len(DF) + Len(strFiles)) 'put all files to a exclusive number
941 If hGlobal Then 'if the globalalloc worked
942 lpGlobal = GlobalLock(hGlobal) 'lock the hGlobal
943 DF.pFiles = Len(DF) 'set the size of the files
945 Call CopyMem(ByVal lpGlobal, DF, Len(DF)) 'copy df to the lpglobal
946 Call CopyMem(ByVal (lpGlobal + Len(DF)), ByVal strFiles, Len(strFiles)) 'copy strfiles to lpglobal
947 Call GlobalUnlock(hGlobal) 'unlock hglobal again
949 SetClipboardData CF_HDROP, hGlobal 'put files to the clipboard
952 bool SaveFile(const char * filePath)
961 public class FileTreeNodeBSArray : ArrayBinarySorted
963 type = class(FileSystemNode);
965 FileSystemNode * const _;
966 BSloc Add(FileSystemNode item)
968 BSloc result = Find(item);
971 Insert(result.pos, 1);
972 _[result.pos] = item;
976 BSloc Remove(FileSystemNode item)
984 public class FileTreeNodeArray : RedjArray
986 type = class(FileSystemNode);
988 FileSystemNode * const _;
989 FileSystemNode * Add(FileSystemNode item)
996 FileSystemNode * AddBefore(uint position, FileSystemNode item)
1000 return &_[position];
1006 public class ExplorerFileItem : struct
1017 void OnDisplay(Surface surface, int x, int y, int width, ExplorerControl control, Alignment alignment, DataDisplayFlags displayFlags)
1019 int indentSize = (displayFlags.dropBox) ? 0 : 10;
1022 char label[MAX_FILENAME];
1024 //float scale = Min((float)clientSize.w / (float)bitmap.width, (float)clientSize.h / (float)bitmap.height);
1025 int w = 16; //(int)(bitmap.width * scale);
1026 int h = 16; //(int)(bitmap.height * scale);
1030 icon = control.fileIcons[type].bitmap;
1033 if(type == folder || type == folderOpen)
1034 surface.SetForeground(red); //Color { 170, 170, 0 } // REDJ What is that color?
1037 textOffset = indent * indentSize + (icon ? (icon.width + 6) : 0);
1040 sprintf(label, "%s [%s]", name, info);
1042 strcpy(label, name);
1043 len = strlen(label);
1045 surface.WriteTextDots
1046 (alignment, x + textOffset, y + 2, width - textOffset, label, len);
1047 if(type == pictureFile && control.previewPictures && bitmap)
1050 //surface.Filter(bitmap, (clientSize.w - w) / 2,(clientSize.h - h) / 2, 0,0, w, h, bitmap.width, bitmap.height);
1051 surface.Filter(bitmap, x + indent * indentSize + 2, y, 0, 0, w, h, bitmap.width, bitmap.height);
1053 // Until Filter / Stretch works with X
1054 //surface.Blit(bitmap, (clientSize.w - bitmap.width) / 2,(clientSize.h - bitmap.height) / 2, 0,0, bitmap.width, bitmap.height);
1055 surface.blend = true;
1056 surface.Blit(bitmap, x + indent * indentSize + 2, y,0,0, w, h);
1062 surface.Blit(icon, x + indent * indentSize + 2, y,0,0, icon.width, icon.height);
1065 int OnCompare(ExplorerFileItem b)
1068 if(type == b.type || (type < folder && b.type < folder) || (type >= drive))
1069 result = strcmpi(name, b.name);
1072 if(type == folder && b.type < folder) result = -1;
1073 else if(type < folder && b.type == folder) result = 1;
1078 void OnCopy(ExplorerFileItem newData)
1080 type = newData.type;
1081 indent = newData.indent;
1084 int len = strlen(newData.name) + 1;
1085 name = new char[len];
1086 CopyBytes(name, newData.name, len);
1090 bool OnGetDataFromString(char * string)
1092 int len = strlen(string) + 1;
1093 name = new char[len];
1094 CopyBytes(name, string, len);
1108 char * OnGetString(char * string, void * fieldData, bool * needClass)
1114 public class ExplorerFileItemArray : RedjArray
1116 type = class(ExplorerFileItem);
1118 ExplorerFileItem * const _;
1119 ExplorerFileItem * Add(ExplorerFileItem item)
1126 ExplorerFileItem * AddBefore(uint position, ExplorerFileItem item)
1128 Insert(position, 1);
1130 return &_[position];
1135 for(c = 0; c < _count; c++)
1145 ExplorerFileItem MakeFileItem(const FileAttribs attribs, const char * fileName, const char * filePath, const bool previewPicture, const DisplaySystem displaySystem)
1147 int len = strlen(fileName);
1148 char info[MAX_LOCATION];
1149 char name[MAX_LOCATION];
1150 char extension[MAX_EXTENSION];
1152 ExplorerFileItem item { };
1154 //if(attribs.isFile) // TODO fix this in ecere
1155 if(attribs.isDirectory)
1159 item.type = (attribs.isDrive) ? drive : folder;
1160 if(attribs.isServer)
1166 if(attribs.isRemote)
1167 item.type = netDrive;
1168 if(attribs.isRemovable)
1170 if(fileName[0] == 'A' || fileName[0] == 'B')
1173 item.type = removable;
1178 GetExtension(fileName, extension);
1179 //strupr(extension);
1182 item.type = _FileType::SelectByExtension(extension);
1185 if(attribs.isDrive &&
1186 len > 3 && !strncmp(&fileName[1], ": [", 3))
1188 strncpy(name, fileName, 2);
1190 strncpy(info, &fileName[4], len - 5);
1195 strcpy(name, fileName);
1199 item.path = CopyString(filePath);
1200 item.name = CopyString(name);
1202 item.info = CopyString(info);
1203 item.extension = CopyString(extension);
1205 if(item.type == pictureFile && previewPicture)
1207 item.bitmap = Bitmap { };
1208 item.bitmap.Load(filePath, null, displaySystem);
1215 public class FileSystemNode : struct
1217 FileSystemNode prev, next;
1219 bool loaded, childrenLoaded;
1226 FileSystemNode parent;
1230 void GetPath(String outputPath)
1235 strcpy(outputPath, name);
1236 for(up = parent; up; up = up.parent)
1238 char temp[MAX_LOCATION];
1239 strcpy(temp, up.name);
1240 PathCat(temp, outputPath);
1241 strcpy(outputPath, temp);
1246 strcpy(outputPath, "/");
1248 strcpy(outputPath, name);
1253 bool IsChildOf(FileSystemNode node)
1255 FileSystemNode test;
1256 for(test = parent; test; test = test.parent)
1262 void DuplicateChildren(bool recursive, bool forceExpanded, FileSystemNode addTo, ListBox tree)
1266 FileSystemNode child;
1268 for(child = children.first; child; child = child.next)
1270 FileSystemNode copy { };
1271 copy.name = CopyString(child.name);
1272 copy.type = child.type;
1273 AddNode(copy, child.loaded, false, addTo, tree);
1275 copy.row.collapsed = false;
1277 child.DuplicateChildren(recursive, forceExpanded, copy, tree);
1282 void EnsureVisible(bool expand)
1285 parent.EnsureVisible(true);
1287 row.collapsed = false;
1288 // TODO: row.EnsureVisible(); // making the row visible by scrolling
1298 FileSystemNode child;
1299 for(; (child = children.first); )
1302 children.Delete(child);
1313 parent.children.Delete(this);
1316 void OnDisplay(Surface surface, int x, int y, int width, ExplorerControl control, Alignment alignment, DataDisplayFlags displayFlags)
1318 //int indentSize = (displayFlags.dropBox) ? 0 : 10;
1324 char label[MAX_FILENAME];
1331 icon = control.fileIcons[type].bitmap;
1332 //xStart = indent * indent + x + (icon ? (icon.width + 5) : 0);
1333 xStart = x + (icon ? (icon.width + 5) : 0);
1339 sprintf(label, "%s [%s]", name, info);
1341 strcpy(label, name);
1342 len = strlen(label);
1346 if(type == folder || type == folderOpen)
1347 surface.SetForeground(yellow);
1351 //textOffset = indent * indentSize + (icon ? (icon.width + 4) : 0);
1353 surface.TextOpacity(false);
1354 surface.TextExtent(label, len, &w, &h);
1357 // Draw the current row stipple
1358 if(displayFlags.selected)
1359 //surface.Area(xStart - 1, y, xStart - 1, y + h - 1);
1360 //surface.Area(xStart + w - 1, y, xStart + w + 1, y + h - 1);
1361 surface.Area(xStart - 3, y, xStart + w + 1, y + h - 1);
1363 //surface.WriteTextDots(alignment, x + textOffset, y + 2, width - textOffset, name, strlen(name));
1364 surface.WriteTextDots(alignment, xStart, y + 2, width, label, len);
1366 if(!guiApp.textMode)
1368 if(displayFlags.current)
1370 if(displayFlags.active)
1372 surface.LineStipple(0x5555);
1373 if(displayFlags.selected)
1374 surface.SetForeground(0xFFFFFF80);
1376 surface.SetForeground(black);
1380 surface.SetForeground(selectionColor);
1382 surface.Rectangle(xStart - 3, y, xStart + w + 1, y + h - 1);
1383 surface.LineStipple(0);
1388 //surface.blend = true;
1389 //surface.alphaWrite = blend;
1390 surface.SetForeground(white);
1391 //surface.Blit(icon, x + indent * indentSize, y,0,0, icon.width, icon.height);
1392 surface.Blit(icon, x,y,0,0, icon.width, icon.height);
1397 int OnCompare(FileSystemNode b)
1400 if(type == b.type || (type < folder && b.type < folder) || (type >= drive))
1401 result = strcmpi(name, b.name);
1404 if(type == folder && b.type < folder) result = -1;
1405 else if(type < folder && b.type == folder) result = 1;
1410 char * OnGetString(char * tempString, FileSystemToolWindow fileSysToolWnd, bool * needClass)
1412 return name ? name : "";
1416 FileSystemNode MakeFileNode(const FileStats stats, const char * name)
1418 FileSystemNode fileTreeNode { stats = stats };
1419 fileTreeNode.name = CopyString(name);
1420 if(!fileTreeNode.name)
1421 fileTreeNode.name = null;
1422 if(stats.attribs.isDirectory)
1424 fileTreeNode.type = (stats.attribs.isDrive) ? drive : folder;
1425 if(stats.attribs.isServer) fileTreeNode.type = server;
1426 if(stats.attribs.isShare) fileTreeNode.type = share;
1427 if(stats.attribs.isCDROM) fileTreeNode.type = cdrom;
1428 if(stats.attribs.isRemote) fileTreeNode.type = netDrive;
1429 if(stats.attribs.isRemovable)
1431 if(name[0] == 'A' || name[0] == 'B')
1432 fileTreeNode.type = floppy;
1434 fileTreeNode.type = removable;
1439 char extension[MAX_EXTENSION];
1440 GetExtension(fileTreeNode.name, extension);
1441 fileTreeNode.type = _FileType::SelectByExtension(extension);
1443 return fileTreeNode;
1446 void AddNode(FileSystemNode node, bool loaded, bool addLoader, FileSystemNode addTo, ListBox tree)
1448 DataRow row = (addTo && addTo.row) ? addTo.row.AddRow() : tree.AddRow();
1451 node.parent = addTo;
1452 node.indent = addTo.indent + 1;
1453 addTo.children.Add(node);
1455 row.tag = (int)node;
1457 row.SetData(null, node);
1459 node.loaded = loaded;
1461 //AddNode(FileSystemNode { }, false, false, node, tree); // why would this create a compile error?
1462 AddNode(FileSystemNode { type = none }, false, false, node, tree);
1465 row.collapsed = true;
1466 else if(node.type == folder)
1467 node.type = folderOpen;
1470 void NodeLoad(FileSystemNode node, ListBox tree)
1474 char path[MAX_LOCATION];
1477 FileListing listing { path };
1478 if(node.children.count == 1)
1479 DeleteNode(node.children.first, tree);
1481 while(listing.Find())
1483 if(listing.stats.attribs.isDirectory)
1485 FileSystemNode child = MakeFileNode(listing.stats, listing.name);
1486 AddNode(child, true, false, node, tree);
1487 NodeChildLoad(child, node, tree);
1491 node.childrenLoaded = true;
1493 node.row.SortSubRows(false);
1495 else if(!node.childrenLoaded)
1497 FileSystemNode child;
1498 if(node.children.first)
1500 for(child = node.children.first; child; child = child.next)
1503 NodeLoad(child, tree);
1504 else if(!child.childrenLoaded)
1505 NodeChildLoad(child, node, tree);
1507 node.childrenLoaded = true;
1508 node.row.SortSubRows(false);
1513 static void NodeChildLoad(FileSystemNode parent, FileSystemNode node, ListBox tree)
1515 char path[MAX_LOCATION];
1516 parent.GetPath(path);
1519 FileListing listing { path };
1520 while(listing.Find())
1522 if(listing.stats.attribs.isDirectory)
1524 FileSystemNode child = MakeFileNode(listing.stats, listing.name);
1525 AddNode(child, true, false, parent, tree);
1532 //parent.childrenLoaded = true;
1535 void DeleteNode(FileSystemNode node, ListBox tree)
1537 FileSystemNode child;
1538 for(; (child = node.children.first); )
1539 DeleteNode(child, tree);
1540 tree.DeleteRow(node.row);