3 import "ArrayFactoredGrowth"
5 //import "ArrayFactoredGrowth"
6 //import "ArrayBinarySorted"
9 static char * rootName = "Entire Computer";
10 static char * msNetwork = "Microsoft Windows Network";
12 static char * rootName = "File System";
16 define guiApp = ((GuiApplication)__thisModule);
17 define selectionColor = guiApp.currentSkin.selectionColor; //Color { 10, 36, 106 };
19 static char * fileIconNames[] =
21 "<:ecere>mimeTypes/file.png", /* none */
23 "<:ecere>mimeTypes/file.png", /* normalFile */
24 "<:ecere>mimeTypes/textEcereWorkspace.png", /* ewsFile */
25 "<:ecere>mimeTypes/textEcereProject.png", /* epjFile */
26 "<:ecere>mimeTypes/textEcereSource.png", /* ecFile */
27 "<:ecere>mimeTypes/textEcereHeader.png", /* ehFile */
28 "<:ecere>mimeTypes/textCSource.png", /* cFile */
29 "<:ecere>mimeTypes/textCHeader.png", /* hFile */
30 "<:ecere>mimeTypes/textC++Source.png", /* cppFile */
31 "<:ecere>mimeTypes/textC++Header.png", /* hppFile */
32 "<:ecere>mimeTypes/text.png", /* textFile */
33 "<:ecere>mimeTypes/textHyperTextMarkup.png", /* webFile */
34 "<:ecere>mimeTypes/image.png", /* pictureFile */
35 "<:ecere>status/audioVolumeHigh.png", /* soundFile */
36 "<:ecere>mimeTypes/package.png", /* archiveFile */
37 "<:ecere>mimeTypes/packageSoftware.png", /* packageFile */
38 "<:ecere>mimeTypes/packageOpticalDisc.png", /* opticalMediaImageFile */
40 "<:ecere>places/folder.png", /* folder */
41 "<:ecere>status/folderOpen.png", /* folderOpen */
42 "<:ecere>devices/computer.png", /* computer */
43 "<:ecere>devices/driveHardDisk.png", /* drive */
44 "<:ecere>places/driveRemote.png", /* netDrive */
45 "<:ecere>devices/mediaOptical.png", /* cdrom */
46 "<:ecere>devices/driveRemovableMedia.png", /* removable */
47 "<:ecere>devices/mediaFloppy.png", /* floppy */
48 "<:ecere>places/networkWorkgroup.png", /* network */
49 "<:ecere>places/networkServer.png", /* server */
50 "<:ecere>places/folderRemote.png", /* share */
52 "<:ecere>mimeTypes/package.png", /* treeLoader */
53 "<:ecere>places/startHere.png", /* lineNumbers */
58 public enum ExplorerFileType
62 normalFile, ewsFile, epjFile, ecFile, ehFile, cFile, hFile, cppFile, hppFile,
63 textFile, webFile, pictureFile, soundFile,
64 archiveFile, packageFile, opticalMediaImageFile, /* these (all previous) are sort equal */
66 folder, folderOpen, computer,
67 drive, netDrive, cdrom, removable, floppy, network, server, share, // these are sort equal
78 this = SelectByExtension(value);
82 public property bool isFolderType
84 get { return this >= folder && this <= share; }
87 public property bool isFileType
89 get { return this >= normalFile && this <= opticalMediaImageFile; }
92 ExplorerFileType ::SelectByExtension(char * extension)
94 if(!strcmpi(extension, "ews"))
96 else if(!strcmpi(extension, "epj"))
98 else if(!strcmpi(extension, "ec"))
100 else if(!strcmpi(extension, "eh"))
102 else if(!strcmpi(extension, "cpp") ||
103 !strcmpi(extension, "cc") || !strcmpi(extension, "cxx"))
105 else if(!strcmpi(extension, "hpp") ||
106 !strcmpi(extension, "hh") || !strcmpi(extension, "hxx"))
108 else if(!strcmpi(extension, "c"))
110 else if(!strcmpi(extension, "h"))
112 else if(!strcmpi(extension, "txt") || !strcmpi(extension, "text") ||
113 !strcmpi(extension, "nfo") || !strcmpi(extension, "info"))
115 else if(!strcmpi(extension, "htm") || !strcmpi(extension, "html") ||
116 !strcmpi(extension, "css") || !strcmpi(extension, "php") ||
117 !strcmpi(extension, "js"))
119 else if(!strcmpi(extension, "bmp") || !strcmpi(extension, "pcx") ||
120 !strcmpi(extension, "jpg") || !strcmpi(extension, "jpeg") ||
121 !strcmpi(extension, "gif") || !strcmpi(extension, "png") ||
122 !strcmpi(extension, "ico"))
124 else if(!strcmpi(extension, "wav") || !strcmpi(extension, "mp3") ||
125 !strcmpi(extension, "ogg") || !strcmpi(extension, "snd"))
127 else if(!strcmpi(extension, "ear") || !strcmpi(extension, "7z") ||
128 !strcmpi(extension, "rar") || !strcmpi(extension, "zip") ||
129 !strcmpi(extension, "gz") || !strcmpi(extension, "bz2") ||
130 !strcmpi(extension, "tar") || !strcmpi(extension, "arj") ||
131 !strcmpi(extension, "lza") || !strcmpi(extension, "lzh") ||
132 !strcmpi(extension, "cpio") || !strcmpi(extension, "z"))
134 else if(!strcmpi(extension, "cab") || !strcmpi(extension, "deb") ||
135 !strcmpi(extension, "rpm"))
137 else if(!strcmpi(extension, "iso") || !strcmpi(extension, "mds") ||
138 !strcmpi(extension, "cue") || !strcmpi(extension, "bin") ||
139 !strcmpi(extension, "ccd") || !strcmpi(extension, "bwt") ||
140 !strcmpi(extension, "cdi") || !strcmpi(extension, "nrg"))
141 return opticalMediaImageFile;
146 class ExplorerControl : Window
148 bool previewPictures;
150 BitmapResource fileIcons[ExplorerFileType];
155 for(c = 0; c < ExplorerFileType::enumSize; c++)
157 fileIcons[c] = BitmapResource { fileIconNames[c], alphaBlend = true };
158 AddResource(fileIcons[c]);
163 class ExplorerView : ExplorerControl
166 hasHorzScroll = false;
167 hasVertScroll = false;
169 virtual void Load(ExplorerFileBranch parent);
170 virtual void Refresh();
172 virtual void LaunchNotifyItemSelect(Window master, ExplorerView view, ExplorerFileItem item, ExplorerFileItemArray selectedItems)
174 view.NotifyItemSelect(master, view, item, selectedItems);
177 virtual bool Window::NotifyItemSelect(ExplorerView view, ExplorerFileItem item, ExplorerFileItemArray selectedItems);
178 virtual bool Window::NotifyItemOpen(ExplorerView view, ExplorerFileItem item);
182 master = master, parent = this;
185 hasHorzScroll = true;
186 hasVertScroll = true;
189 fullRowSelect = false;
192 anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
194 bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
196 ExplorerView view = (ExplorerView)listBox.parent;
197 if(listBox.currentRow)
200 ExplorerFileItemArray selectedItems { growingFactor = 16 };
201 for(listRow = listBox.firstRow; listRow; listRow = listRow.next)
203 selectedItems.Add((ExplorerFileItem)listRow.tag);
204 //view.NotifyItemSelect(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
205 view.LaunchNotifyItemSelect(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag, selectedItems);
210 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
212 ExplorerView view = (ExplorerView)listBox.parent;
213 view.NotifyItemOpen(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
217 bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
219 if((SmartKey)key == enter)
221 ExplorerView view = (ExplorerView)listBox.parent;
222 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);
278 class ExplorerViewDetails : ExplorerView
280 list.hasHeader = true;
281 list.moveFields = true;
282 list.resizable = true;
283 list.sortable = true;
285 ExplorerFileBranch 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(ExplorerFileBranch 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);
333 class ExplorerViewIcons : ExplorerView
336 ExplorerFileBranch location;
340 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
342 ExplorerViewDetails()
344 list.AddField(nameField);
352 void Load(ExplorerFileBranch location)
354 char path[MAX_LOCATION];
355 this.location = location;
356 location.GetPath(path);
358 FileListing listing { path };
360 ExplorerFileItem item;
365 while(listing.Find())
367 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
371 row.SetData(nameField, item);
373 list.Sort(nameField, 1);
378 class ExplorerViewCards : ExplorerView
381 ExplorerFileBranch location;
385 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
387 ExplorerViewDetails()
389 list.AddField(nameField);
397 void Load(ExplorerFileBranch location)
399 char path[MAX_LOCATION];
400 this.location = location;
401 location.GetPath(path);
403 FileListing listing { path };
405 ExplorerFileItem item;
410 while(listing.Find())
412 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
416 row.SetData(nameField, item);
418 list.Sort(nameField, 1);
423 public class BitmapArray : RedjArray
425 type = class(Bitmap);
428 Bitmap * Add(Bitmap bitmap)
435 Bitmap * AddBefore(uint position, Bitmap bitmap)
438 _[position] = bitmap;
444 for(c = 0; c < _count; c++)
454 class ExplorerViewShowcase : ExplorerView
456 list.anchor = Anchor { left = 0, top = 0, bottom = 0 };
457 list.size = Size { w = 200 };
459 ExplorerFileBranch location;
463 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 180, editable = true, userData = this };
466 BitmapArray bitmaps { growingFactor = 16 };
472 anchor = Anchor { top = 0, right = 0, bottom = 0 };
474 void OnRedraw(Surface surface)
476 ExplorerViewShowcase view = (ExplorerViewShowcase)parent;
479 int wBmp = view.bitmap.width;
480 int hBmp = view.bitmap.height;
481 int wWnd = clientSize.w;
482 int hWnd = clientSize.h;
484 int wList = view.list.size.w + view.split.size.w;
486 float scale = Min((float)(wWnd - 10) / wBmp, (float)(hWnd - 10) / hBmp);
488 int wDraw = (int)(wBmp * scale);
489 int hDraw = (int)(hBmp * scale);
492 surface.Filter(view.bitmap, (wWnd - wDraw) / 2, (hWnd - hDraw) / 2, 0, 0, wDraw, hDraw, wBmp, hBmp);
494 // Until Filter / Stretch works with X
495 surface.Blit(view.bitmap, (wWnd - wDraw) / 2, (hWnd - hDraw) / 2, 0, 0, wDraw, hDraw);
500 surface.SetForeground(white);
501 surface.Area(0, 0, view.clientSize.w - 1, view.clientSize.h - 1);
515 ExplorerViewDetails()
517 list.AddField(nameField);
520 void LaunchNotifyItemSelect(Window master, ExplorerViewShowcase view, ExplorerFileItem item, ExplorerFileItemArray selectedItems)
523 ExplorerFileItem selItem;
527 if(item && item.type == pictureFile)
529 view.bitmap = Bitmap { };
530 view.bitmap.Load(item.path, null, displaySystem);
533 view.bitmaps.Clear();
534 view.bitmaps = BitmapArray { };
535 for(pos = 0; pos < selectedItems.count; pos++)
538 selItem = (ExplorerFileItem)selectedItems._[pos];
539 bitmap.Load(selItem.path, null, displaySystem);
540 //view.bitmaps.Add(bitmap);
542 if(item && item.type == pictureFile)
544 view.bitmap = Bitmap { };
545 view.bitmap.Load(item.path, null, displaySystem);
548 view.show.Update(null);
549 view.NotifyItemSelect(master, view, item, selectedItems);
557 void Load(ExplorerFileBranch location)
559 char path[MAX_LOCATION];
560 this.location = location;
561 location.GetPath(path);
563 FileListing listing { path };
565 ExplorerFileItem item;
570 while(listing.Find())
572 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
576 row.SetData(nameField, item);
578 list.Sort(nameField, 1);
583 class ExplorerTree : ExplorerControl
585 hasHorzScroll = false;
586 hasVertScroll = false;
592 DataField nameField { dataType = "ExplorerFileBranch", width = 240, userData = this };
594 ExplorerFileBranch root;
595 ExplorerFileBranch selection;
597 virtual bool Window::NotifyBranchSelect(ExplorerTree tree, ExplorerFileBranch branch);
599 property ExplorerFileBranch branch
607 if(!tree.currentRow.tag)
609 return (ExplorerFileBranch)tree.currentRow.tag;
613 void Select(ExplorerFileBranch branch)
617 branch.EnsureVisible(false);
618 tree.SelectRow(branch.row);
622 ExplorerFileBranch Find(const char * name, ExplorerFileBranch parent)
624 ExplorerFileBranch branch;
625 ExplorerFileBranch start = parent ? parent : root;
626 if(!start.loaded || !start.childrenLoaded)
627 BranchLoad(start, tree);
628 for(branch = start.children.first; branch; branch = branch.next)
629 if(branch.name && !strcmpi(branch.name, name))
636 master = master, parent = this;
639 hasHorzScroll = true;
640 hasVertScroll = true;
641 fullRowSelect = false;
643 collapseControl = true;
644 rootCollapseButton = true;
646 anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
648 // WHY is this not working ?
649 /*void OnResize(int width, int height)
651 if(vertScroll.visible)
652 nameField.width = width - vertScroll.size.w;
654 nameField.width = width;
657 bool NotifyCollapse(ListBox listBox, DataRow row, bool collapsed)
661 ExplorerFileBranch branch = (ExplorerFileBranch)row.tag;
662 ExplorerFileBranch child;
666 for(child = branch.children.last; child; child = branch.children.last)
668 listBox.DeleteRow(child.row);
672 branch.childrenLoaded = false;
677 if(!branch.loaded || !branch.childrenLoaded)
678 BranchLoad(branch, tree);
679 for(child = branch.children.first; child && child.next; child = child.next);
681 child.EnsureVisible(false);
687 bool NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods)
689 DataRow row = listBox.currentRow;
692 ExplorerFileBranch branch = (ExplorerFileBranch)row.tag;
698 MenuItem { menu, "Cut\tCtrl+X", t, NotifySelect = null, disabled = false };
699 MenuItem { menu, "Copy\tCtrl+C", c, NotifySelect = null, disabled = false };
700 MenuItem { menu, "Paste\tCtrl+V", p, NotifySelect = null, disabled = false /*!clipboard*/ };
701 MenuItem { menu, "Delete\tDel", d, NotifySelect = null, disabled = false };
702 //MenuDivider { menu };
706 master = this, menu = menu,
708 x + clientStart.x + absPosition.x - guiApp.desktop.position.x,
709 y + clientStart.y + absPosition.y - guiApp.desktop.position.y }
717 bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
721 ExplorerFileBranch branch = (ExplorerFileBranch)row.tag;
722 NotifyBranchSelect(listBox.parent.master, this, branch);
728 bool NotifyEditing(ListBox listBox, DataRow row)
732 ExplorerFileBranch branch = (ExplorerFileBranch)row.tag;
737 bool NotifyEdited(ListBox listBox, DataRow row)
741 ExplorerFileBranch branch = (ExplorerFileBranch)row.tag;
746 bool NotifyEditDone(ListBox listBox, DataRow row)
750 ExplorerFileBranch branch = (ExplorerFileBranch)row.tag;
757 Menu editMenu { menu, "Edit", e };
760 editMenu, "Cut\tCtrl+X", t, disabled = true;
762 bool NotifySelect(MenuItem selection, Modifiers mods)
768 MenuItem itemEditCopy
770 editMenu, "Copy\tCtrl+C", c, disabled = true;
772 bool NotifySelect(MenuItem selection, Modifiers mods)
778 MenuItem itemEditPaste
780 editMenu, "Paste\tCtrl+V", p;
782 bool NotifySelect(MenuItem selection, Modifiers mods)
788 MenuItem itemEditDelete
790 editMenu, "Delete\tDel", d, disabled = true;
792 bool NotifySelect(MenuItem selection, Modifiers mods)
799 // WHY is this crashing ?
800 /*void OnResize(int width, int height)
802 if(this && nameField)
803 nameField.width = width - 80;
808 tree.AddField(nameField);
813 ExplorerFileBranch parent;
814 ExplorerFileBranch branch;
815 FileListing listing { "/" };
819 root = ExplorerFileBranch { type = computer, loaded = true, childrenLoaded = true };
821 root.name = rootName;
825 AddBranch(root, true, false, null, tree);
827 // How can this make sense for linux?
829 while(listing.Find())
831 int len = strlen(listing.name);
832 char info[MAX_LOCATION];
833 char name[MAX_LOCATION];
834 if(listing.stats.attribs.isDrive &&
835 len > 3 && !strncmp(&listing.name[1], ": [", 3))
837 strncpy(name, listing.name, 2);
839 strncpy(info, &listing.name[4], len - 5);
844 strcpy(name, listing.name);
848 parent = MakeFileBranch(listing.stats, name);
850 parent.info = CopyString(info);
851 parent.loaded = true;
852 AddBranch(parent, !listing.stats.attribs.isDirectory, listing.stats.attribs.isDirectory, root, tree);
853 if(!listing.stats.attribs.isDirectory)
854 parent.childrenLoaded = true;
857 branch = ExplorerFileBranch { name = msNetwork, type = network };
858 AddBranch(branch, false, true, null, tree);
859 branch.row.collapsed = true;
860 tree.Sort(nameField, 1);
861 tree.SelectRow(root.row);
866 public class ClipBoardFiles
880 int size = SelSize();
883 // Try to allocate memory
884 ClipBoard clipBoard { };
885 if(clipBoard.Allocate(size+1))
887 GetSel(clipBoard.memory, true);
900 ClipBoard clipBoard { };
902 PutS(clipBoard.memory);
913 SetViewToCursor(true);
918 Private Type DROPFILES
924 For iCounter = 0 To filelist.ListCount - 1
925 If filelist.Selected(iCounter) = True Then
926 strFiles = strFiles & FixPath(filelist.Path) & filelist.List(iCounter) & vbNullChar
929 'all selected items are now put in strFiles
931 hGlobal = GlobalAlloc(GHND, Len(DF) + Len(strFiles)) 'put all files to a exclusive number
932 If hGlobal Then 'if the globalalloc worked
933 lpGlobal = GlobalLock(hGlobal) 'lock the hGlobal
934 DF.pFiles = Len(DF) 'set the size of the files
936 Call CopyMem(ByVal lpGlobal, DF, Len(DF)) 'copy df to the lpglobal
937 Call CopyMem(ByVal (lpGlobal + Len(DF)), ByVal strFiles, Len(strFiles)) 'copy strfiles to lpglobal
938 Call GlobalUnlock(hGlobal) 'unlock hglobal again
940 SetClipboardData CF_HDROP, hGlobal 'put files to the clipboard
943 bool SaveFile(const char * filePath)
950 /*public class FileTreeBranchBSArray : ArrayBinarySorted
952 type = class(ExplorerFileBranch);
954 ExplorerFileBranch * const _;
955 BSloc Add(ExplorerFileBranch item)
957 BSloc result = Find(item);
960 Insert(result.pos, 1);
961 _[result.pos] = item;
965 BSloc Remove(ExplorerFileBranch item)
971 /*public class FileTreeBranchArray : RedjArray
973 type = class(ExplorerFileBranch);
975 ExplorerFileBranch * const _;
976 ExplorerFileBranch * Add(ExplorerFileBranch item)
983 ExplorerFileBranch * AddBefore(uint position, ExplorerFileBranch item)
991 public class ExplorerFileItem : struct
997 ExplorerFileType type;
1002 void OnDisplay(Surface surface, int x, int y, int width, ExplorerControl control, Alignment alignment, DataDisplayFlags displayFlags)
1004 int indentSize = (displayFlags.dropBox) ? 0 : 10;
1007 char label[MAX_FILENAME];
1009 //float scale = Min((float)clientSize.w / (float)bitmap.width, (float)clientSize.h / (float)bitmap.height);
1010 int w = 16; //(int)(bitmap.width * scale);
1011 int h = 16; //(int)(bitmap.height * scale);
1015 icon = control.fileIcons[type].bitmap;
1018 if(type == folder || type == folderOpen)
1019 surface.SetForeground(red); //Color { 170, 170, 0 } // REDJ What is that color?
1022 textOffset = indent * indentSize + (icon ? (icon.width + 6) : 0);
1025 sprintf(label, "%s [%s]", name, info);
1027 strcpy(label, name);
1028 len = strlen(label);
1030 surface.WriteTextDots
1031 (alignment, x + textOffset, y + 2, width - textOffset, label, len);
1032 if(type == pictureFile && control.previewPictures && bitmap)
1035 //surface.Filter(bitmap, (clientSize.w - w) / 2,(clientSize.h - h) / 2, 0,0, w, h, bitmap.width, bitmap.height);
1036 surface.Filter(bitmap, x + indent * indentSize + 2, y, 0, 0, w, h, bitmap.width, bitmap.height);
1038 // Until Filter / Stretch works with X
1039 //surface.Blit(bitmap, (clientSize.w - bitmap.width) / 2,(clientSize.h - bitmap.height) / 2, 0,0, bitmap.width, bitmap.height);
1040 surface.blend = true;
1041 surface.Blit(bitmap, x + indent * indentSize + 2, y,0,0, w, h);
1047 surface.Blit(icon, x + indent * indentSize + 2, y,0,0, icon.width, icon.height);
1050 int OnCompare(ExplorerFileItem b)
1053 if(type == b.type || (type < folder && b.type < folder) || (type >= drive))
1054 result = strcmpi(name, b.name);
1057 if(type == folder && b.type < folder) result = -1;
1058 else if(type < folder && b.type == folder) result = 1;
1063 void OnCopy(ExplorerFileItem newData)
1065 type = newData.type;
1066 indent = newData.indent;
1069 int len = strlen(newData.name) + 1;
1070 name = new char[len];
1071 CopyBytes(name, newData.name, len);
1075 bool OnGetDataFromString(char * string)
1077 int len = strlen(string) + 1;
1078 name = new char[len];
1079 CopyBytes(name, string, len);
1093 char * OnGetString(char * string, void * fieldData, bool * needClass)
1099 public class ExplorerFileItemArray : RedjArray
1101 type = class(ExplorerFileItem);
1103 ExplorerFileItem * const _;
1104 ExplorerFileItem * Add(ExplorerFileItem item)
1111 ExplorerFileItem * AddBefore(uint position, ExplorerFileItem item)
1113 Insert(position, 1);
1115 return &_[position];
1120 for(c = 0; c < _count; c++)
1130 ExplorerFileItem MakeFileItem(const FileAttribs attribs, const char * fileName, const char * filePath, const bool previewPicture, const DisplaySystem displaySystem)
1132 int len = strlen(fileName);
1133 char info[MAX_LOCATION];
1134 char name[MAX_LOCATION];
1135 char extension[MAX_EXTENSION];
1137 ExplorerFileItem item { };
1139 //if(attribs.isFile) // TODO fix this in ecere
1140 if(attribs.isDirectory)
1144 item.type = (attribs.isDrive) ? drive : folder;
1145 if(attribs.isServer)
1151 if(attribs.isRemote)
1152 item.type = netDrive;
1153 if(attribs.isRemovable)
1155 if(fileName[0] == 'A' || fileName[0] == 'B')
1158 item.type = removable;
1163 GetExtension(fileName, extension);
1164 //strupr(extension);
1167 item.type = ExplorerFileType::SelectByExtension(extension);
1170 if(attribs.isDrive &&
1171 len > 3 && !strncmp(&fileName[1], ": [", 3))
1173 strncpy(name, fileName, 2);
1175 strncpy(info, &fileName[4], len - 5);
1180 strcpy(name, fileName);
1184 item.path = CopyString(filePath);
1185 item.name = CopyString(name);
1187 item.info = CopyString(info);
1188 item.extension = CopyString(extension);
1190 if(item.type == pictureFile && previewPicture)
1192 item.bitmap = Bitmap { };
1193 item.bitmap.Load(filePath, null, displaySystem);
1199 public class ExplorerFileBranch : struct
1201 ExplorerFileBranch prev, next;
1203 bool loaded, childrenLoaded;
1209 ExplorerFileType type;
1210 ExplorerFileBranch parent;
1214 void GetPath(String outputPath)
1216 ExplorerFileBranch up;
1219 strcpy(outputPath, name);
1220 for(up = parent; up; up = up.parent)
1222 char temp[MAX_LOCATION];
1223 strcpy(temp, up.name);
1224 PathCat(temp, outputPath);
1225 strcpy(outputPath, temp);
1230 strcpy(outputPath, "/");
1232 strcpy(outputPath, name);
1237 bool IsChildOf(ExplorerFileBranch branch)
1239 ExplorerFileBranch test;
1240 for(test = parent; test; test = test.parent)
1246 void DuplicateChildren(bool recursive, bool forceExpanded, ExplorerFileBranch addTo, ListBox tree)
1250 ExplorerFileBranch child;
1252 for(child = children.first; child; child = child.next)
1254 ExplorerFileBranch copy { };
1255 copy.name = CopyString(child.name);
1256 copy.type = child.type;
1257 AddBranch(copy, child.loaded, false, addTo, tree);
1259 copy.row.collapsed = false;
1261 child.DuplicateChildren(recursive, forceExpanded, copy, tree);
1266 void EnsureVisible(bool expand)
1269 parent.EnsureVisible(true);
1271 row.collapsed = false;
1272 // TODO: row.EnsureVisible(); // making the row visible by scrolling
1282 ExplorerFileBranch child;
1283 for(; (child = children.first); )
1286 children.Delete(child);
1297 parent.children.Delete(this);
1300 void OnDisplay(Surface surface, int x, int y, int width, ExplorerControl control, Alignment alignment, DataDisplayFlags displayFlags)
1302 //int indentSize = (displayFlags.dropBox) ? 0 : 10;
1308 char label[MAX_FILENAME];
1315 icon = control.fileIcons[type].bitmap;
1316 //xStart = indent * indent + x + (icon ? (icon.width + 5) : 0);
1317 xStart = x + (icon ? (icon.width + 5) : 0);
1323 sprintf(label, "%s [%s]", name, info);
1325 strcpy(label, name);
1326 len = strlen(label);
1330 if(type == folder || type == folderOpen)
1331 surface.SetForeground(yellow);
1335 //textOffset = indent * indentSize + (icon ? (icon.width + 4) : 0);
1337 surface.TextOpacity(false);
1338 surface.TextExtent(label, len, &w, &h);
1341 // Draw the current row stipple
1342 if(displayFlags.selected)
1343 //surface.Area(xStart - 1, y, xStart - 1, y + h - 1);
1344 //surface.Area(xStart + w - 1, y, xStart + w + 1, y + h - 1);
1345 surface.Area(xStart - 3, y, xStart + w + 1, y + h - 1);
1347 //surface.WriteTextDots(alignment, x + textOffset, y + 2, width - textOffset, name, strlen(name));
1348 surface.WriteTextDots(alignment, xStart, y + 2, width, label, len);
1350 if(!guiApp.textMode)
1352 if(displayFlags.current)
1354 if(displayFlags.active)
1356 surface.LineStipple(0x5555);
1357 if(displayFlags.selected)
1358 surface.SetForeground(0xFFFFFF80);
1360 surface.SetForeground(black);
1364 surface.SetForeground(selectionColor);
1366 surface.Rectangle(xStart - 3, y, xStart + w + 1, y + h - 1);
1367 surface.LineStipple(0);
1372 //surface.blend = true;
1373 //surface.alphaWrite = blend;
1374 surface.SetForeground(white);
1375 //surface.Blit(icon, x + indent * indentSize, y,0,0, icon.width, icon.height);
1376 surface.Blit(icon, x,y,0,0, icon.width, icon.height);
1381 int OnCompare(ExplorerFileBranch b)
1384 if(type == b.type || (type < folder && b.type < folder) || (type >= drive))
1385 result = strcmpi(name, b.name);
1388 if(type == folder && b.type < folder) result = -1;
1389 else if(type < folder && b.type == folder) result = 1;
1394 char * OnGetString(char * tempString, FileSystemToolWindow fileSysToolWnd, bool * needClass)
1396 return name ? name : "";
1400 ExplorerFileBranch MakeFileBranch(const FileStats stats, const char * name)
1402 ExplorerFileBranch fileTreeBranch { stats = stats };
1403 fileTreeBranch.name = CopyString(name);
1404 if(!fileTreeBranch.name)
1405 fileTreeBranch.name = null;
1406 if(stats.attribs.isDirectory)
1408 fileTreeBranch.type = (stats.attribs.isDrive) ? drive : folder;
1409 if(stats.attribs.isServer) fileTreeBranch.type = server;
1410 if(stats.attribs.isShare) fileTreeBranch.type = share;
1411 if(stats.attribs.isCDROM) fileTreeBranch.type = cdrom;
1412 if(stats.attribs.isRemote) fileTreeBranch.type = netDrive;
1413 if(stats.attribs.isRemovable)
1415 if(name[0] == 'A' || name[0] == 'B')
1416 fileTreeBranch.type = floppy;
1418 fileTreeBranch.type = removable;
1423 char extension[MAX_EXTENSION];
1424 GetExtension(fileTreeBranch.name, extension);
1425 fileTreeBranch.type = ExplorerFileType::SelectByExtension(extension);
1427 return fileTreeBranch;
1430 void AddBranch(ExplorerFileBranch branch, bool loaded, bool addLoader, ExplorerFileBranch addTo, ListBox tree)
1432 DataRow row = (addTo && addTo.row) ? addTo.row.AddRow() : tree.AddRow();
1435 branch.parent = addTo;
1436 branch.indent = addTo.indent + 1;
1437 addTo.children.Add(branch);
1439 row.tag = (int)branch;
1441 row.SetData(null, branch);
1443 branch.loaded = loaded;
1445 //AddBranch(ExplorerFileBranch { }, false, false, branch, tree); // why would this create a compile error?
1446 AddBranch(ExplorerFileBranch { type = none }, false, false, branch, tree);
1448 if(branch.indent > 0)
1449 row.collapsed = true;
1450 else if(branch.type == folder)
1451 branch.type = folderOpen;
1454 void BranchLoad(ExplorerFileBranch branch, ListBox tree)
1458 char path[MAX_LOCATION];
1459 branch.GetPath(path);
1461 FileListing listing { path };
1462 if(branch.children.count == 1)
1463 DeleteBranch(branch.children.first, tree);
1465 while(listing.Find())
1467 if(listing.stats.attribs.isDirectory)
1469 ExplorerFileBranch child = MakeFileBranch(listing.stats, listing.name);
1470 AddBranch(child, true, false, branch, tree);
1471 BranchChildLoad(child, branch, tree);
1475 branch.childrenLoaded = true;
1476 branch.loaded = true;
1477 branch.row.SortSubRows(false);
1479 else if(!branch.childrenLoaded)
1481 ExplorerFileBranch child;
1482 if(branch.children.first)
1484 for(child = branch.children.first; child; child = child.next)
1487 BranchLoad(child, tree);
1488 else if(!child.childrenLoaded)
1489 BranchChildLoad(child, branch, tree);
1491 branch.childrenLoaded = true;
1492 branch.row.SortSubRows(false);
1497 static void BranchChildLoad(ExplorerFileBranch parent, ExplorerFileBranch branch, ListBox tree)
1499 char path[MAX_LOCATION];
1500 parent.GetPath(path);
1503 FileListing listing { path };
1504 while(listing.Find())
1506 if(listing.stats.attribs.isDirectory)
1508 ExplorerFileBranch child = MakeFileBranch(listing.stats, listing.name);
1509 AddBranch(child, true, false, parent, tree);
1516 //parent.childrenLoaded = true;
1519 void DeleteBranch(ExplorerFileBranch branch, ListBox tree)
1521 ExplorerFileBranch child;
1522 for(; (child = branch.children.first); )
1523 DeleteBranch(child, tree);
1524 tree.DeleteRow(branch.row);