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
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 _FileType ::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;
141 class ExplorerControl : Window
143 bool previewPictures;
145 BitmapResource fileIcons[_FileType];
150 for(c = 0; c < _FileType::enumSize; c++)
152 fileIcons[c] = BitmapResource { fileIconNames[c], alphaBlend = true };
153 AddResource(fileIcons[c]);
159 class ExplorerView : ExplorerControl
162 hasHorzScroll = false;
163 hasVertScroll = false;
165 virtual void Load(FileSystemNode parent);
166 virtual void Refresh();
168 virtual void LaunchNotifyItemSelect(Window master, ExplorerView view, ExplorerFileItem item, ExplorerFileItemArray selectedItems)
170 view.NotifyItemSelect(master, view, item, selectedItems);
173 virtual bool Window::NotifyItemSelect(ExplorerView view, ExplorerFileItem item, ExplorerFileItemArray selectedItems);
174 virtual bool Window::NotifyItemOpen(ExplorerView view, ExplorerFileItem item);
178 master = master, parent = this;
181 hasHorzScroll = true;
182 hasVertScroll = true;
185 fullRowSelect = false;
188 anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
190 bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
192 ExplorerView view = (ExplorerView)listBox.parent;
193 if(listBox.currentRow)
196 ExplorerFileItemArray selectedItems { growingFactor = 16 };
197 for(listRow = listBox.firstRow; listRow; listRow = listRow.next)
199 selectedItems.Add((ExplorerFileItem)listRow.tag);
200 //view.NotifyItemSelect(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
201 view.LaunchNotifyItemSelect(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag, selectedItems);
206 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
208 ExplorerView view = (ExplorerView)listBox.parent;
209 view.NotifyItemOpen(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
213 bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
215 if((SmartKey)key == enter)
217 ExplorerView view = (ExplorerView)listBox.parent;
218 view.NotifyItemOpen(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
231 class ExplorerViewList : ExplorerView
234 FileSystemNode location;
238 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
240 ExplorerViewDetails()
242 list.AddField(nameField);
250 void Load(FileSystemNode location)
252 char path[MAX_LOCATION];
253 this.location = location;
254 location.GetPath(path);
256 FileListing listing { path };
258 ExplorerFileItem item;
263 while(listing.Find())
265 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
269 row.SetData(nameField, item);
271 list.Sort(nameField, 1);
278 class ExplorerViewDetails : ExplorerView
280 list.hasHeader = true;
281 list.moveFields = true;
282 list.resizable = true;
283 list.sortable = true;
285 FileSystemNode location;
289 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
290 DataField typeField { header = "Type", dataType = /*"String"*/ "char *", width = 40 };
291 DataField sizeField { header = "Size", dataType = "FileSize", width = 96, alignment = right };
293 ExplorerViewDetails()
295 list.AddField(nameField);
296 list.AddField(typeField);
297 list.AddField(sizeField);
305 void Load(FileSystemNode location)
307 char path[MAX_LOCATION];
308 this.location = location;
309 location.GetPath(path);
311 FileListing listing { path };
313 ExplorerFileItem item;
318 while(listing.Find())
320 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
324 row.SetData(nameField, item);
325 row.SetData(typeField, CopyString(item.extension));
326 row.SetData(sizeField, (uint)listing.stats.size);
328 list.Sort(nameField, 1);
335 class ExplorerViewIcons : ExplorerView
338 FileSystemNode location;
342 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
344 ExplorerViewDetails()
346 list.AddField(nameField);
354 void Load(FileSystemNode location)
356 char path[MAX_LOCATION];
357 this.location = location;
358 location.GetPath(path);
360 FileListing listing { path };
362 ExplorerFileItem item;
367 while(listing.Find())
369 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
373 row.SetData(nameField, item);
375 list.Sort(nameField, 1);
382 class ExplorerViewCards : ExplorerView
385 FileSystemNode location;
389 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
391 ExplorerViewDetails()
393 list.AddField(nameField);
401 void Load(FileSystemNode location)
403 char path[MAX_LOCATION];
404 this.location = location;
405 location.GetPath(path);
407 FileListing listing { path };
409 ExplorerFileItem item;
414 while(listing.Find())
416 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
420 row.SetData(nameField, item);
422 list.Sort(nameField, 1);
429 public class BitmapArray : RedjArray
431 type = class(Bitmap);
434 Bitmap * Add(Bitmap bitmap)
441 Bitmap * AddBefore(uint position, Bitmap bitmap)
444 _[position] = bitmap;
450 for(c = 0; c < _count; c++)
462 class ExplorerViewShowcase : ExplorerView
464 list.anchor = Anchor { left = 0, top = 0, bottom = 0 };
465 list.size = Size { w = 200 };
467 FileSystemNode location;
471 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 180, editable = true, userData = this };
474 BitmapArray bitmaps { growingFactor = 16 };
480 anchor = Anchor { top = 0, right = 0, bottom = 0 };
482 void OnRedraw(Surface surface)
484 ExplorerViewShowcase view = (ExplorerViewShowcase)parent;
487 int wBmp = view.bitmap.width;
488 int hBmp = view.bitmap.height;
489 int wWnd = clientSize.w;
490 int hWnd = clientSize.h;
492 int wList = view.list.size.w + view.split.size.w;
494 float scale = Min((float)(wWnd - 10) / wBmp, (float)(hWnd - 10) / hBmp);
496 int wDraw = (int)(wBmp * scale);
497 int hDraw = (int)(hBmp * scale);
500 surface.Filter(view.bitmap, (wWnd - wDraw) / 2, (hWnd - hDraw) / 2, 0, 0, wDraw, hDraw, wBmp, hBmp);
502 // Until Filter / Stretch works with X
503 surface.Blit(view.bitmap, (wWnd - wDraw) / 2, (hWnd - hDraw) / 2, 0, 0, wDraw, hDraw);
508 surface.SetForeground(white);
509 surface.Area(0, 0, view.clientSize.w - 1, view.clientSize.h - 1);
523 ExplorerViewDetails()
525 list.AddField(nameField);
528 void LaunchNotifyItemSelect(Window master, ExplorerViewShowcase view, ExplorerFileItem item, ExplorerFileItemArray selectedItems)
531 ExplorerFileItem selItem;
535 if(item && item.type == pictureFile)
537 view.bitmap = Bitmap { };
538 view.bitmap.Load(item.path, null, displaySystem);
541 view.bitmaps.Clear();
542 view.bitmaps = BitmapArray { };
543 for(pos = 0; pos < selectedItems.count; pos++)
546 selItem = (ExplorerFileItem)selectedItems._[pos];
547 bitmap.Load(selItem.path, null, displaySystem);
548 //view.bitmaps.Add(bitmap);
550 if(item && item.type == pictureFile)
552 view.bitmap = Bitmap { };
553 view.bitmap.Load(item.path, null, displaySystem);
556 view.show.Update(null);
557 view.NotifyItemSelect(master, view, item, selectedItems);
565 void Load(FileSystemNode location)
567 char path[MAX_LOCATION];
568 this.location = location;
569 location.GetPath(path);
571 FileListing listing { path };
573 ExplorerFileItem item;
578 while(listing.Find())
580 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
584 row.SetData(nameField, item);
586 list.Sort(nameField, 1);
593 class ExplorerTree : ExplorerControl
595 hasHorzScroll = false;
596 hasVertScroll = false;
602 DataField nameField { dataType = "FileSystemNode", width = 240, userData = this };
605 FileSystemNode selection;
607 virtual bool Window::NotifyNodeSelect(ExplorerTree tree, FileSystemNode node);
609 property FileSystemNode node
617 if(!tree.currentRow.tag)
619 return (FileSystemNode)tree.currentRow.tag;
623 void Select(FileSystemNode node)
627 node.EnsureVisible(false);
628 tree.SelectRow(node.row);
632 FileSystemNode Find(const char * name, FileSystemNode parent)
635 FileSystemNode start = parent ? parent : root;
636 if(!start.loaded || !start.childrenLoaded)
637 NodeLoad(start, tree);
638 for(node = start.children.first; node; node = node.next)
639 if(node.name && !strcmpi(node.name, name))
646 master = master, parent = this;
649 hasHorzScroll = true;
650 hasVertScroll = true;
651 fullRowSelect = false;
653 collapseControl = true;
654 rootCollapseButton = true;
656 anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
658 // WHY is this not working ?
659 /*void OnResize(int width, int height)
661 if(vertScroll.visible)
662 nameField.width = width - vertScroll.size.w;
664 nameField.width = width;
667 bool NotifyCollapse(ListBox listBox, DataRow row, bool collapsed)
671 FileSystemNode node = (FileSystemNode)row.tag;
672 FileSystemNode child;
676 for(child = node.children.last; child; child = node.children.last)
678 listBox.DeleteRow(child.row);
682 node.childrenLoaded = false;
687 if(!node.loaded || !node.childrenLoaded)
688 NodeLoad(node, tree);
689 for(child = node.children.first; child && child.next; child = child.next);
691 child.EnsureVisible(false);
697 bool NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods)
699 DataRow row = listBox.currentRow;
702 FileSystemNode node = (FileSystemNode)row.tag;
708 MenuItem { menu, "Cut\tCtrl+X", t, NotifySelect = null, disabled = false };
709 MenuItem { menu, "Copy\tCtrl+C", c, NotifySelect = null, disabled = false };
710 MenuItem { menu, "Paste\tCtrl+V", p, NotifySelect = null, disabled = false /*!clipboard*/ };
711 MenuItem { menu, "Delete\tDel", d, NotifySelect = null, disabled = false };
712 //MenuDivider { menu };
716 master = this, menu = menu,
718 x + clientStart.x + absPosition.x - guiApp.desktop.position.x,
719 y + clientStart.y + absPosition.y - guiApp.desktop.position.y }
727 bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
731 FileSystemNode node = (FileSystemNode)row.tag;
732 NotifyNodeSelect(listBox.parent.master, this, node);
738 bool NotifyEditing(ListBox listBox, DataRow row)
742 FileSystemNode node = (FileSystemNode)row.tag;
747 bool NotifyEdited(ListBox listBox, DataRow row)
751 FileSystemNode node = (FileSystemNode)row.tag;
756 bool NotifyEditDone(ListBox listBox, DataRow row)
760 FileSystemNode node = (FileSystemNode)row.tag;
767 Menu editMenu { menu, "Edit", e };
770 editMenu, "Cut\tCtrl+X", t, disabled = true;
772 bool NotifySelect(MenuItem selection, Modifiers mods)
778 MenuItem itemEditCopy
780 editMenu, "Copy\tCtrl+C", c, disabled = true;
782 bool NotifySelect(MenuItem selection, Modifiers mods)
788 MenuItem itemEditPaste
790 editMenu, "Paste\tCtrl+V", p;
792 bool NotifySelect(MenuItem selection, Modifiers mods)
798 MenuItem itemEditDelete
800 editMenu, "Delete\tDel", d, disabled = true;
802 bool NotifySelect(MenuItem selection, Modifiers mods)
809 // WHY is this crashing ?
810 /*void OnResize(int width, int height)
812 if(this && nameField)
813 nameField.width = width - 80;
818 tree.AddField(nameField);
823 FileSystemNode parent;
825 FileListing listing { "/" };
829 root = FileSystemNode { type = computer, loaded = true, childrenLoaded = true };
831 root.name = rootName;
835 AddNode(root, true, false, null, tree);
837 // How can this make sense for linux?
839 while(listing.Find())
841 int len = strlen(listing.name);
842 char info[MAX_LOCATION];
843 char name[MAX_LOCATION];
844 if(listing.stats.attribs.isDrive &&
845 len > 3 && !strncmp(&listing.name[1], ": [", 3))
847 strncpy(name, listing.name, 2);
849 strncpy(info, &listing.name[4], len - 5);
854 strcpy(name, listing.name);
858 parent = MakeFileNode(listing.stats, name);
860 parent.info = CopyString(info);
861 parent.loaded = true;
862 AddNode(parent, !listing.stats.attribs.isDirectory, listing.stats.attribs.isDirectory, root, tree);
863 if(!listing.stats.attribs.isDirectory)
864 parent.childrenLoaded = true;
867 node = FileSystemNode { name = msNetwork, type = network };
868 AddNode(node, false, true, null, tree);
869 node.row.collapsed = true;
870 tree.Sort(nameField, 1);
871 tree.SelectRow(root.row);
876 public class ClipBoardFiles
890 int size = SelSize();
893 // Try to allocate memory
894 ClipBoard clipBoard { };
895 if(clipBoard.Allocate(size+1))
897 GetSel(clipBoard.memory, true);
910 ClipBoard clipBoard { };
912 PutS(clipBoard.memory);
923 SetViewToCursor(true);
928 Private Type DROPFILES
934 For iCounter = 0 To filelist.ListCount - 1
935 If filelist.Selected(iCounter) = True Then
936 strFiles = strFiles & FixPath(filelist.Path) & filelist.List(iCounter) & vbNullChar
939 'all selected items are now put in strFiles
941 hGlobal = GlobalAlloc(GHND, Len(DF) + Len(strFiles)) 'put all files to a exclusive number
942 If hGlobal Then 'if the globalalloc worked
943 lpGlobal = GlobalLock(hGlobal) 'lock the hGlobal
944 DF.pFiles = Len(DF) 'set the size of the files
946 Call CopyMem(ByVal lpGlobal, DF, Len(DF)) 'copy df to the lpglobal
947 Call CopyMem(ByVal (lpGlobal + Len(DF)), ByVal strFiles, Len(strFiles)) 'copy strfiles to lpglobal
948 Call GlobalUnlock(hGlobal) 'unlock hglobal again
950 SetClipboardData CF_HDROP, hGlobal 'put files to the clipboard
953 bool SaveFile(const char * filePath)
962 public class FileTreeNodeBSArray : ArrayBinarySorted
964 type = class(FileSystemNode);
966 FileSystemNode * const _;
967 BSloc Add(FileSystemNode item)
969 BSloc result = Find(item);
972 Insert(result.pos, 1);
973 _[result.pos] = item;
977 BSloc Remove(FileSystemNode item)
985 public class FileTreeNodeArray : RedjArray
987 type = class(FileSystemNode);
989 FileSystemNode * const _;
990 FileSystemNode * Add(FileSystemNode item)
997 FileSystemNode * AddBefore(uint position, FileSystemNode item)
1001 return &_[position];
1007 public class ExplorerFileItem : struct
1018 void OnDisplay(Surface surface, int x, int y, int width, ExplorerControl control, Alignment alignment, DataDisplayFlags displayFlags)
1020 int indentSize = (displayFlags.dropBox) ? 0 : 10;
1023 char label[MAX_FILENAME];
1025 //float scale = Min((float)clientSize.w / (float)bitmap.width, (float)clientSize.h / (float)bitmap.height);
1026 int w = 16; //(int)(bitmap.width * scale);
1027 int h = 16; //(int)(bitmap.height * scale);
1031 icon = control.fileIcons[type].bitmap;
1034 if(type == folder || type == folderOpen)
1035 surface.SetForeground(red); //Color { 170, 170, 0 } // REDJ What is that color?
1038 textOffset = indent * indentSize + (icon ? (icon.width + 6) : 0);
1041 sprintf(label, "%s [%s]", name, info);
1043 strcpy(label, name);
1044 len = strlen(label);
1046 surface.WriteTextDots
1047 (alignment, x + textOffset, y + 2, width - textOffset, label, len);
1048 if(type == pictureFile && control.previewPictures && bitmap)
1051 //surface.Filter(bitmap, (clientSize.w - w) / 2,(clientSize.h - h) / 2, 0,0, w, h, bitmap.width, bitmap.height);
1052 surface.Filter(bitmap, x + indent * indentSize + 2, y, 0, 0, w, h, bitmap.width, bitmap.height);
1054 // Until Filter / Stretch works with X
1055 //surface.Blit(bitmap, (clientSize.w - bitmap.width) / 2,(clientSize.h - bitmap.height) / 2, 0,0, bitmap.width, bitmap.height);
1056 surface.blend = true;
1057 surface.Blit(bitmap, x + indent * indentSize + 2, y,0,0, w, h);
1063 surface.Blit(icon, x + indent * indentSize + 2, y,0,0, icon.width, icon.height);
1066 int OnCompare(ExplorerFileItem b)
1069 if(type == b.type || (type < folder && b.type < folder) || (type >= drive))
1070 result = strcmpi(name, b.name);
1073 if(type == folder && b.type < folder) result = -1;
1074 else if(type < folder && b.type == folder) result = 1;
1079 void OnCopy(ExplorerFileItem newData)
1081 type = newData.type;
1082 indent = newData.indent;
1085 int len = strlen(newData.name) + 1;
1086 name = new char[len];
1087 CopyBytes(name, newData.name, len);
1091 bool OnGetDataFromString(char * string)
1093 int len = strlen(string) + 1;
1094 name = new char[len];
1095 CopyBytes(name, string, len);
1109 char * OnGetString(char * string, void * fieldData, bool * needClass)
1115 public class ExplorerFileItemArray : RedjArray
1117 type = class(ExplorerFileItem);
1119 ExplorerFileItem * const _;
1120 ExplorerFileItem * Add(ExplorerFileItem item)
1127 ExplorerFileItem * AddBefore(uint position, ExplorerFileItem item)
1129 Insert(position, 1);
1131 return &_[position];
1136 for(c = 0; c < _count; c++)
1146 ExplorerFileItem MakeFileItem(const FileAttribs attribs, const char * fileName, const char * filePath, const bool previewPicture, const DisplaySystem displaySystem)
1148 int len = strlen(fileName);
1149 char info[MAX_LOCATION];
1150 char name[MAX_LOCATION];
1151 char extension[MAX_EXTENSION];
1153 ExplorerFileItem item { };
1155 //if(attribs.isFile) // TODO fix this in ecere
1156 if(attribs.isDirectory)
1160 item.type = (attribs.isDrive) ? drive : folder;
1161 if(attribs.isServer)
1167 if(attribs.isRemote)
1168 item.type = netDrive;
1169 if(attribs.isRemovable)
1171 if(fileName[0] == 'A' || fileName[0] == 'B')
1174 item.type = removable;
1179 GetExtension(fileName, extension);
1180 //strupr(extension);
1183 item.type = _FileType::SelectByExtension(extension);
1186 if(attribs.isDrive &&
1187 len > 3 && !strncmp(&fileName[1], ": [", 3))
1189 strncpy(name, fileName, 2);
1191 strncpy(info, &fileName[4], len - 5);
1196 strcpy(name, fileName);
1200 item.path = CopyString(filePath);
1201 item.name = CopyString(name);
1203 item.info = CopyString(info);
1204 item.extension = CopyString(extension);
1206 if(item.type == pictureFile && previewPicture)
1208 item.bitmap = Bitmap { };
1209 item.bitmap.Load(filePath, null, displaySystem);
1216 public class FileSystemNode : struct
1218 FileSystemNode prev, next;
1220 bool loaded, childrenLoaded;
1227 FileSystemNode parent;
1231 void GetPath(String outputPath)
1236 strcpy(outputPath, name);
1237 for(up = parent; up; up = up.parent)
1239 char temp[MAX_LOCATION];
1240 strcpy(temp, up.name);
1241 PathCat(temp, outputPath);
1242 strcpy(outputPath, temp);
1247 strcpy(outputPath, "/");
1249 strcpy(outputPath, name);
1254 bool IsChildOf(FileSystemNode node)
1256 FileSystemNode test;
1257 for(test = parent; test; test = test.parent)
1263 void DuplicateChildren(bool recursive, bool forceExpanded, FileSystemNode addTo, ListBox tree)
1267 FileSystemNode child;
1269 for(child = children.first; child; child = child.next)
1271 FileSystemNode copy { };
1272 copy.name = CopyString(child.name);
1273 copy.type = child.type;
1274 AddNode(copy, child.loaded, false, addTo, tree);
1276 copy.row.collapsed = false;
1278 child.DuplicateChildren(recursive, forceExpanded, copy, tree);
1283 void EnsureVisible(bool expand)
1286 parent.EnsureVisible(true);
1288 row.collapsed = false;
1289 // TODO: row.EnsureVisible(); // making the row visible by scrolling
1299 FileSystemNode child;
1300 for(; (child = children.first); )
1303 children.Delete(child);
1314 parent.children.Delete(this);
1317 void OnDisplay(Surface surface, int x, int y, int width, ExplorerControl control, Alignment alignment, DataDisplayFlags displayFlags)
1319 //int indentSize = (displayFlags.dropBox) ? 0 : 10;
1325 char label[MAX_FILENAME];
1332 icon = control.fileIcons[type].bitmap;
1333 //xStart = indent * indent + x + (icon ? (icon.width + 5) : 0);
1334 xStart = x + (icon ? (icon.width + 5) : 0);
1340 sprintf(label, "%s [%s]", name, info);
1342 strcpy(label, name);
1343 len = strlen(label);
1347 if(type == folder || type == folderOpen)
1348 surface.SetForeground(yellow);
1352 //textOffset = indent * indentSize + (icon ? (icon.width + 4) : 0);
1354 surface.TextOpacity(false);
1355 surface.TextExtent(label, len, &w, &h);
1358 // Draw the current row stipple
1359 if(displayFlags.selected)
1360 //surface.Area(xStart - 1, y, xStart - 1, y + h - 1);
1361 //surface.Area(xStart + w - 1, y, xStart + w + 1, y + h - 1);
1362 surface.Area(xStart - 3, y, xStart + w + 1, y + h - 1);
1364 //surface.WriteTextDots(alignment, x + textOffset, y + 2, width - textOffset, name, strlen(name));
1365 surface.WriteTextDots(alignment, xStart, y + 2, width, label, len);
1367 if(!guiApp.textMode)
1369 if(displayFlags.current)
1371 if(displayFlags.active)
1373 surface.LineStipple(0x5555);
1374 if(displayFlags.selected)
1375 surface.SetForeground(0xFFFFFF80);
1377 surface.SetForeground(black);
1381 surface.SetForeground(selectionColor);
1383 surface.Rectangle(xStart - 3, y, xStart + w + 1, y + h - 1);
1384 surface.LineStipple(0);
1389 //surface.blend = true;
1390 //surface.alphaWrite = blend;
1391 surface.SetForeground(white);
1392 //surface.Blit(icon, x + indent * indentSize, y,0,0, icon.width, icon.height);
1393 surface.Blit(icon, x,y,0,0, icon.width, icon.height);
1398 int OnCompare(FileSystemNode b)
1401 if(type == b.type || (type < folder && b.type < folder) || (type >= drive))
1402 result = strcmpi(name, b.name);
1405 if(type == folder && b.type < folder) result = -1;
1406 else if(type < folder && b.type == folder) result = 1;
1411 char * OnGetString(char * tempString, FileSystemToolWindow fileSysToolWnd, bool * needClass)
1413 return name ? name : "";
1417 FileSystemNode MakeFileNode(const FileStats stats, const char * name)
1419 FileSystemNode fileTreeNode { stats = stats };
1420 fileTreeNode.name = CopyString(name);
1421 if(!fileTreeNode.name)
1422 fileTreeNode.name = null;
1423 if(stats.attribs.isDirectory)
1425 fileTreeNode.type = (stats.attribs.isDrive) ? drive : folder;
1426 if(stats.attribs.isServer) fileTreeNode.type = server;
1427 if(stats.attribs.isShare) fileTreeNode.type = share;
1428 if(stats.attribs.isCDROM) fileTreeNode.type = cdrom;
1429 if(stats.attribs.isRemote) fileTreeNode.type = netDrive;
1430 if(stats.attribs.isRemovable)
1432 if(name[0] == 'A' || name[0] == 'B')
1433 fileTreeNode.type = floppy;
1435 fileTreeNode.type = removable;
1440 char extension[MAX_EXTENSION];
1441 GetExtension(fileTreeNode.name, extension);
1442 fileTreeNode.type = _FileType::SelectByExtension(extension);
1444 return fileTreeNode;
1447 void AddNode(FileSystemNode node, bool loaded, bool addLoader, FileSystemNode addTo, ListBox tree)
1449 DataRow row = (addTo && addTo.row) ? addTo.row.AddRow() : tree.AddRow();
1452 node.parent = addTo;
1453 node.indent = addTo.indent + 1;
1454 addTo.children.Add(node);
1456 row.tag = (int)node;
1458 row.SetData(null, node);
1460 node.loaded = loaded;
1462 //AddNode(FileSystemNode { }, false, false, node, tree); // why would this create a compile error?
1463 AddNode(FileSystemNode { type = none }, false, false, node, tree);
1466 row.collapsed = true;
1467 else if(node.type == folder)
1468 node.type = folderOpen;
1471 void NodeLoad(FileSystemNode node, ListBox tree)
1475 char path[MAX_LOCATION];
1478 FileListing listing { path };
1479 if(node.children.count == 1)
1480 DeleteNode(node.children.first, tree);
1482 while(listing.Find())
1484 if(listing.stats.attribs.isDirectory)
1486 FileSystemNode child = MakeFileNode(listing.stats, listing.name);
1487 AddNode(child, true, false, node, tree);
1488 NodeChildLoad(child, node, tree);
1492 node.childrenLoaded = true;
1494 node.row.SortSubRows(false);
1496 else if(!node.childrenLoaded)
1498 FileSystemNode child;
1499 if(node.children.first)
1501 for(child = node.children.first; child; child = child.next)
1504 NodeLoad(child, tree);
1505 else if(!child.childrenLoaded)
1506 NodeChildLoad(child, node, tree);
1508 node.childrenLoaded = true;
1509 node.row.SortSubRows(false);
1514 static void NodeChildLoad(FileSystemNode parent, FileSystemNode node, ListBox tree)
1516 char path[MAX_LOCATION];
1517 parent.GetPath(path);
1520 FileListing listing { path };
1521 while(listing.Find())
1523 if(listing.stats.attribs.isDirectory)
1525 FileSystemNode child = MakeFileNode(listing.stats, listing.name);
1526 AddNode(child, true, false, parent, tree);
1533 //parent.childrenLoaded = true;
1536 void DeleteNode(FileSystemNode node, ListBox tree)
1538 FileSystemNode child;
1539 for(; (child = node.children.first); )
1540 DeleteNode(child, tree);
1541 tree.DeleteRow(node.row);