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;
141 class ExplorerControl : Window
143 bool previewPictures;
145 BitmapResource fileIcons[ExplorerFileType];
150 for(c = 0; c < ExplorerFileType::enumSize; c++)
152 fileIcons[c] = BitmapResource { fileIconNames[c], alphaBlend = true };
153 AddResource(fileIcons[c]);
158 class ExplorerView : ExplorerControl
161 hasHorzScroll = false;
162 hasVertScroll = false;
164 virtual void Load(ExplorerFileBranch 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);
228 class ExplorerViewList : ExplorerView
231 ExplorerFileBranch location;
235 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
237 ExplorerViewDetails()
239 list.AddField(nameField);
247 void Load(ExplorerFileBranch location)
249 char path[MAX_LOCATION];
250 this.location = location;
251 location.GetPath(path);
253 FileListing listing { path };
255 ExplorerFileItem item;
260 while(listing.Find())
262 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
266 row.SetData(nameField, item);
268 list.Sort(nameField, 1);
273 class ExplorerViewDetails : ExplorerView
275 list.hasHeader = true;
276 list.moveFields = true;
277 list.resizable = true;
278 list.sortable = true;
280 ExplorerFileBranch location;
284 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
285 DataField typeField { header = "Type", dataType = /*"String"*/ "char *", width = 40 };
286 DataField sizeField { header = "Size", dataType = "FileSize", width = 96, alignment = right };
288 ExplorerViewDetails()
290 list.AddField(nameField);
291 list.AddField(typeField);
292 list.AddField(sizeField);
300 void Load(ExplorerFileBranch location)
302 char path[MAX_LOCATION];
303 this.location = location;
304 location.GetPath(path);
306 FileListing listing { path };
308 ExplorerFileItem item;
313 while(listing.Find())
315 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
319 row.SetData(nameField, item);
320 row.SetData(typeField, CopyString(item.extension));
321 row.SetData(sizeField, (uint)listing.stats.size);
323 list.Sort(nameField, 1);
328 class ExplorerViewIcons : ExplorerView
331 ExplorerFileBranch location;
335 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
337 ExplorerViewDetails()
339 list.AddField(nameField);
347 void Load(ExplorerFileBranch location)
349 char path[MAX_LOCATION];
350 this.location = location;
351 location.GetPath(path);
353 FileListing listing { path };
355 ExplorerFileItem item;
360 while(listing.Find())
362 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
366 row.SetData(nameField, item);
368 list.Sort(nameField, 1);
373 class ExplorerViewCards : ExplorerView
376 ExplorerFileBranch location;
380 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
382 ExplorerViewDetails()
384 list.AddField(nameField);
392 void Load(ExplorerFileBranch location)
394 char path[MAX_LOCATION];
395 this.location = location;
396 location.GetPath(path);
398 FileListing listing { path };
400 ExplorerFileItem item;
405 while(listing.Find())
407 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
411 row.SetData(nameField, item);
413 list.Sort(nameField, 1);
418 public class BitmapArray : RedjArray
420 type = class(Bitmap);
423 Bitmap * Add(Bitmap bitmap)
430 Bitmap * AddBefore(uint position, Bitmap bitmap)
433 _[position] = bitmap;
439 for(c = 0; c < _count; c++)
449 class ExplorerViewShowcase : ExplorerView
451 list.anchor = Anchor { left = 0, top = 0, bottom = 0 };
452 list.size = Size { w = 200 };
454 ExplorerFileBranch location;
458 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 180, editable = true, userData = this };
461 BitmapArray bitmaps { growingFactor = 16 };
467 anchor = Anchor { top = 0, right = 0, bottom = 0 };
469 void OnRedraw(Surface surface)
471 ExplorerViewShowcase view = (ExplorerViewShowcase)parent;
474 int wBmp = view.bitmap.width;
475 int hBmp = view.bitmap.height;
476 int wWnd = clientSize.w;
477 int hWnd = clientSize.h;
479 int wList = view.list.size.w + view.split.size.w;
481 float scale = Min((float)(wWnd - 10) / wBmp, (float)(hWnd - 10) / hBmp);
483 int wDraw = (int)(wBmp * scale);
484 int hDraw = (int)(hBmp * scale);
487 surface.Filter(view.bitmap, (wWnd - wDraw) / 2, (hWnd - hDraw) / 2, 0, 0, wDraw, hDraw, wBmp, hBmp);
489 // Until Filter / Stretch works with X
490 surface.Blit(view.bitmap, (wWnd - wDraw) / 2, (hWnd - hDraw) / 2, 0, 0, wDraw, hDraw);
495 surface.SetForeground(white);
496 surface.Area(0, 0, view.clientSize.w - 1, view.clientSize.h - 1);
510 ExplorerViewDetails()
512 list.AddField(nameField);
515 void LaunchNotifyItemSelect(Window master, ExplorerViewShowcase view, ExplorerFileItem item, ExplorerFileItemArray selectedItems)
518 ExplorerFileItem selItem;
522 if(item && item.type == pictureFile)
524 view.bitmap = Bitmap { };
525 view.bitmap.Load(item.path, null, displaySystem);
528 view.bitmaps.Clear();
529 view.bitmaps = BitmapArray { };
530 for(pos = 0; pos < selectedItems.count; pos++)
533 selItem = (ExplorerFileItem)selectedItems._[pos];
534 bitmap.Load(selItem.path, null, displaySystem);
535 //view.bitmaps.Add(bitmap);
537 if(item && item.type == pictureFile)
539 view.bitmap = Bitmap { };
540 view.bitmap.Load(item.path, null, displaySystem);
543 view.show.Update(null);
544 view.NotifyItemSelect(master, view, item, selectedItems);
552 void Load(ExplorerFileBranch location)
554 char path[MAX_LOCATION];
555 this.location = location;
556 location.GetPath(path);
558 FileListing listing { path };
560 ExplorerFileItem item;
565 while(listing.Find())
567 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
571 row.SetData(nameField, item);
573 list.Sort(nameField, 1);
578 class ExplorerTree : ExplorerControl
580 hasHorzScroll = false;
581 hasVertScroll = false;
587 DataField nameField { dataType = "ExplorerFileBranch", width = 240, userData = this };
589 ExplorerFileBranch root;
590 ExplorerFileBranch selection;
592 virtual bool Window::NotifyBranchSelect(ExplorerTree tree, ExplorerFileBranch branch);
594 property ExplorerFileBranch branch
602 if(!tree.currentRow.tag)
604 return (ExplorerFileBranch)tree.currentRow.tag;
608 void Select(ExplorerFileBranch branch)
612 branch.EnsureVisible(false);
613 tree.SelectRow(branch.row);
617 ExplorerFileBranch Find(const char * name, ExplorerFileBranch parent)
619 ExplorerFileBranch branch;
620 ExplorerFileBranch start = parent ? parent : root;
621 if(!start.loaded || !start.childrenLoaded)
622 BranchLoad(start, tree);
623 for(branch = start.children.first; branch; branch = branch.next)
624 if(branch.name && !strcmpi(branch.name, name))
631 master = master, parent = this;
634 hasHorzScroll = true;
635 hasVertScroll = true;
636 fullRowSelect = false;
638 collapseControl = true;
639 rootCollapseButton = true;
641 anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
643 // WHY is this not working ?
644 /*void OnResize(int width, int height)
646 if(vertScroll.visible)
647 nameField.width = width - vertScroll.size.w;
649 nameField.width = width;
652 bool NotifyCollapse(ListBox listBox, DataRow row, bool collapsed)
656 ExplorerFileBranch branch = (ExplorerFileBranch)row.tag;
657 ExplorerFileBranch child;
661 for(child = branch.children.last; child; child = branch.children.last)
663 listBox.DeleteRow(child.row);
667 branch.childrenLoaded = false;
672 if(!branch.loaded || !branch.childrenLoaded)
673 BranchLoad(branch, tree);
674 for(child = branch.children.first; child && child.next; child = child.next);
676 child.EnsureVisible(false);
682 bool NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods)
684 DataRow row = listBox.currentRow;
687 ExplorerFileBranch branch = (ExplorerFileBranch)row.tag;
693 MenuItem { menu, "Cut\tCtrl+X", t, NotifySelect = null, disabled = false };
694 MenuItem { menu, "Copy\tCtrl+C", c, NotifySelect = null, disabled = false };
695 MenuItem { menu, "Paste\tCtrl+V", p, NotifySelect = null, disabled = false /*!clipboard*/ };
696 MenuItem { menu, "Delete\tDel", d, NotifySelect = null, disabled = false };
697 //MenuDivider { menu };
701 master = this, menu = menu,
703 x + clientStart.x + absPosition.x - guiApp.desktop.position.x,
704 y + clientStart.y + absPosition.y - guiApp.desktop.position.y }
712 bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
716 ExplorerFileBranch branch = (ExplorerFileBranch)row.tag;
717 NotifyBranchSelect(listBox.parent.master, this, branch);
723 bool NotifyEditing(ListBox listBox, DataRow row)
727 ExplorerFileBranch branch = (ExplorerFileBranch)row.tag;
732 bool NotifyEdited(ListBox listBox, DataRow row)
736 ExplorerFileBranch branch = (ExplorerFileBranch)row.tag;
741 bool NotifyEditDone(ListBox listBox, DataRow row)
745 ExplorerFileBranch branch = (ExplorerFileBranch)row.tag;
752 Menu editMenu { menu, "Edit", e };
755 editMenu, "Cut\tCtrl+X", t, disabled = true;
757 bool NotifySelect(MenuItem selection, Modifiers mods)
763 MenuItem itemEditCopy
765 editMenu, "Copy\tCtrl+C", c, disabled = true;
767 bool NotifySelect(MenuItem selection, Modifiers mods)
773 MenuItem itemEditPaste
775 editMenu, "Paste\tCtrl+V", p;
777 bool NotifySelect(MenuItem selection, Modifiers mods)
783 MenuItem itemEditDelete
785 editMenu, "Delete\tDel", d, disabled = true;
787 bool NotifySelect(MenuItem selection, Modifiers mods)
794 // WHY is this crashing ?
795 /*void OnResize(int width, int height)
797 if(this && nameField)
798 nameField.width = width - 80;
803 tree.AddField(nameField);
808 ExplorerFileBranch parent;
809 ExplorerFileBranch branch;
810 FileListing listing { "/" };
814 root = ExplorerFileBranch { type = computer, loaded = true, childrenLoaded = true };
816 root.name = rootName;
820 AddBranch(root, true, false, null, tree);
822 // How can this make sense for linux?
824 while(listing.Find())
826 int len = strlen(listing.name);
827 char info[MAX_LOCATION];
828 char name[MAX_LOCATION];
829 if(listing.stats.attribs.isDrive &&
830 len > 3 && !strncmp(&listing.name[1], ": [", 3))
832 strncpy(name, listing.name, 2);
834 strncpy(info, &listing.name[4], len - 5);
839 strcpy(name, listing.name);
843 parent = MakeFileBranch(listing.stats, name);
845 parent.info = CopyString(info);
846 parent.loaded = true;
847 AddBranch(parent, !listing.stats.attribs.isDirectory, listing.stats.attribs.isDirectory, root, tree);
848 if(!listing.stats.attribs.isDirectory)
849 parent.childrenLoaded = true;
852 branch = ExplorerFileBranch { name = msNetwork, type = network };
853 AddBranch(branch, false, true, null, tree);
854 branch.row.collapsed = true;
855 tree.Sort(nameField, 1);
856 tree.SelectRow(root.row);
861 public class ClipBoardFiles
875 int size = SelSize();
878 // Try to allocate memory
879 ClipBoard clipBoard { };
880 if(clipBoard.Allocate(size+1))
882 GetSel(clipBoard.memory, true);
895 ClipBoard clipBoard { };
897 PutS(clipBoard.memory);
908 SetViewToCursor(true);
913 Private Type DROPFILES
919 For iCounter = 0 To filelist.ListCount - 1
920 If filelist.Selected(iCounter) = True Then
921 strFiles = strFiles & FixPath(filelist.Path) & filelist.List(iCounter) & vbNullChar
924 'all selected items are now put in strFiles
926 hGlobal = GlobalAlloc(GHND, Len(DF) + Len(strFiles)) 'put all files to a exclusive number
927 If hGlobal Then 'if the globalalloc worked
928 lpGlobal = GlobalLock(hGlobal) 'lock the hGlobal
929 DF.pFiles = Len(DF) 'set the size of the files
931 Call CopyMem(ByVal lpGlobal, DF, Len(DF)) 'copy df to the lpglobal
932 Call CopyMem(ByVal (lpGlobal + Len(DF)), ByVal strFiles, Len(strFiles)) 'copy strfiles to lpglobal
933 Call GlobalUnlock(hGlobal) 'unlock hglobal again
935 SetClipboardData CF_HDROP, hGlobal 'put files to the clipboard
938 bool SaveFile(const char * filePath)
945 /*public class FileTreeBranchBSArray : ArrayBinarySorted
947 type = class(ExplorerFileBranch);
949 ExplorerFileBranch * const _;
950 BSloc Add(ExplorerFileBranch item)
952 BSloc result = Find(item);
955 Insert(result.pos, 1);
956 _[result.pos] = item;
960 BSloc Remove(ExplorerFileBranch item)
966 /*public class FileTreeBranchArray : RedjArray
968 type = class(ExplorerFileBranch);
970 ExplorerFileBranch * const _;
971 ExplorerFileBranch * Add(ExplorerFileBranch item)
978 ExplorerFileBranch * AddBefore(uint position, ExplorerFileBranch item)
986 public class ExplorerFileItem : struct
992 ExplorerFileType type;
997 void OnDisplay(Surface surface, int x, int y, int width, ExplorerControl control, Alignment alignment, DataDisplayFlags displayFlags)
999 int indentSize = (displayFlags.dropBox) ? 0 : 10;
1002 char label[MAX_FILENAME];
1004 //float scale = Min((float)clientSize.w / (float)bitmap.width, (float)clientSize.h / (float)bitmap.height);
1005 int w = 16; //(int)(bitmap.width * scale);
1006 int h = 16; //(int)(bitmap.height * scale);
1010 icon = control.fileIcons[type].bitmap;
1013 if(type == folder || type == folderOpen)
1014 surface.SetForeground(red); //Color { 170, 170, 0 } // REDJ What is that color?
1017 textOffset = indent * indentSize + (icon ? (icon.width + 6) : 0);
1020 sprintf(label, "%s [%s]", name, info);
1022 strcpy(label, name);
1023 len = strlen(label);
1025 surface.WriteTextDots
1026 (alignment, x + textOffset, y + 2, width - textOffset, label, len);
1027 if(type == pictureFile && control.previewPictures && bitmap)
1030 //surface.Filter(bitmap, (clientSize.w - w) / 2,(clientSize.h - h) / 2, 0,0, w, h, bitmap.width, bitmap.height);
1031 surface.Filter(bitmap, x + indent * indentSize + 2, y, 0, 0, w, h, bitmap.width, bitmap.height);
1033 // Until Filter / Stretch works with X
1034 //surface.Blit(bitmap, (clientSize.w - bitmap.width) / 2,(clientSize.h - bitmap.height) / 2, 0,0, bitmap.width, bitmap.height);
1035 surface.blend = true;
1036 surface.Blit(bitmap, x + indent * indentSize + 2, y,0,0, w, h);
1042 surface.Blit(icon, x + indent * indentSize + 2, y,0,0, icon.width, icon.height);
1045 int OnCompare(ExplorerFileItem b)
1048 if(type == b.type || (type < folder && b.type < folder) || (type >= drive))
1049 result = strcmpi(name, b.name);
1052 if(type == folder && b.type < folder) result = -1;
1053 else if(type < folder && b.type == folder) result = 1;
1058 void OnCopy(ExplorerFileItem newData)
1060 type = newData.type;
1061 indent = newData.indent;
1064 int len = strlen(newData.name) + 1;
1065 name = new char[len];
1066 CopyBytes(name, newData.name, len);
1070 bool OnGetDataFromString(char * string)
1072 int len = strlen(string) + 1;
1073 name = new char[len];
1074 CopyBytes(name, string, len);
1088 char * OnGetString(char * string, void * fieldData, bool * needClass)
1094 public class ExplorerFileItemArray : RedjArray
1096 type = class(ExplorerFileItem);
1098 ExplorerFileItem * const _;
1099 ExplorerFileItem * Add(ExplorerFileItem item)
1106 ExplorerFileItem * AddBefore(uint position, ExplorerFileItem item)
1108 Insert(position, 1);
1110 return &_[position];
1115 for(c = 0; c < _count; c++)
1125 ExplorerFileItem MakeFileItem(const FileAttribs attribs, const char * fileName, const char * filePath, const bool previewPicture, const DisplaySystem displaySystem)
1127 int len = strlen(fileName);
1128 char info[MAX_LOCATION];
1129 char name[MAX_LOCATION];
1130 char extension[MAX_EXTENSION];
1132 ExplorerFileItem item { };
1134 //if(attribs.isFile) // TODO fix this in ecere
1135 if(attribs.isDirectory)
1139 item.type = (attribs.isDrive) ? drive : folder;
1140 if(attribs.isServer)
1146 if(attribs.isRemote)
1147 item.type = netDrive;
1148 if(attribs.isRemovable)
1150 if(fileName[0] == 'A' || fileName[0] == 'B')
1153 item.type = removable;
1158 GetExtension(fileName, extension);
1159 //strupr(extension);
1162 item.type = ExplorerFileType::SelectByExtension(extension);
1165 if(attribs.isDrive &&
1166 len > 3 && !strncmp(&fileName[1], ": [", 3))
1168 strncpy(name, fileName, 2);
1170 strncpy(info, &fileName[4], len - 5);
1175 strcpy(name, fileName);
1179 item.path = CopyString(filePath);
1180 item.name = CopyString(name);
1182 item.info = CopyString(info);
1183 item.extension = CopyString(extension);
1185 if(item.type == pictureFile && previewPicture)
1187 item.bitmap = Bitmap { };
1188 item.bitmap.Load(filePath, null, displaySystem);
1194 public class ExplorerFileBranch : struct
1196 ExplorerFileBranch prev, next;
1198 bool loaded, childrenLoaded;
1204 ExplorerFileType type;
1205 ExplorerFileBranch parent;
1209 void GetPath(String outputPath)
1211 ExplorerFileBranch up;
1214 strcpy(outputPath, name);
1215 for(up = parent; up; up = up.parent)
1217 char temp[MAX_LOCATION];
1218 strcpy(temp, up.name);
1219 PathCat(temp, outputPath);
1220 strcpy(outputPath, temp);
1225 strcpy(outputPath, "/");
1227 strcpy(outputPath, name);
1232 bool IsChildOf(ExplorerFileBranch branch)
1234 ExplorerFileBranch test;
1235 for(test = parent; test; test = test.parent)
1241 void DuplicateChildren(bool recursive, bool forceExpanded, ExplorerFileBranch addTo, ListBox tree)
1245 ExplorerFileBranch child;
1247 for(child = children.first; child; child = child.next)
1249 ExplorerFileBranch copy { };
1250 copy.name = CopyString(child.name);
1251 copy.type = child.type;
1252 AddBranch(copy, child.loaded, false, addTo, tree);
1254 copy.row.collapsed = false;
1256 child.DuplicateChildren(recursive, forceExpanded, copy, tree);
1261 void EnsureVisible(bool expand)
1264 parent.EnsureVisible(true);
1266 row.collapsed = false;
1267 // TODO: row.EnsureVisible(); // making the row visible by scrolling
1277 ExplorerFileBranch child;
1278 for(; (child = children.first); )
1281 children.Delete(child);
1292 parent.children.Delete(this);
1295 void OnDisplay(Surface surface, int x, int y, int width, ExplorerControl control, Alignment alignment, DataDisplayFlags displayFlags)
1297 //int indentSize = (displayFlags.dropBox) ? 0 : 10;
1303 char label[MAX_FILENAME];
1310 icon = control.fileIcons[type].bitmap;
1311 //xStart = indent * indent + x + (icon ? (icon.width + 5) : 0);
1312 xStart = x + (icon ? (icon.width + 5) : 0);
1318 sprintf(label, "%s [%s]", name, info);
1320 strcpy(label, name);
1321 len = strlen(label);
1325 if(type == folder || type == folderOpen)
1326 surface.SetForeground(yellow);
1330 //textOffset = indent * indentSize + (icon ? (icon.width + 4) : 0);
1332 surface.TextOpacity(false);
1333 surface.TextExtent(label, len, &w, &h);
1336 // Draw the current row stipple
1337 if(displayFlags.selected)
1338 //surface.Area(xStart - 1, y, xStart - 1, y + h - 1);
1339 //surface.Area(xStart + w - 1, y, xStart + w + 1, y + h - 1);
1340 surface.Area(xStart - 3, y, xStart + w + 1, y + h - 1);
1342 //surface.WriteTextDots(alignment, x + textOffset, y + 2, width - textOffset, name, strlen(name));
1343 surface.WriteTextDots(alignment, xStart, y + 2, width, label, len);
1345 if(!guiApp.textMode)
1347 if(displayFlags.current)
1349 if(displayFlags.active)
1351 surface.LineStipple(0x5555);
1352 if(displayFlags.selected)
1353 surface.SetForeground(0xFFFFFF80);
1355 surface.SetForeground(black);
1359 surface.SetForeground(selectionColor);
1361 surface.Rectangle(xStart - 3, y, xStart + w + 1, y + h - 1);
1362 surface.LineStipple(0);
1367 //surface.blend = true;
1368 //surface.alphaWrite = blend;
1369 surface.SetForeground(white);
1370 //surface.Blit(icon, x + indent * indentSize, y,0,0, icon.width, icon.height);
1371 surface.Blit(icon, x,y,0,0, icon.width, icon.height);
1376 int OnCompare(ExplorerFileBranch b)
1379 if(type == b.type || (type < folder && b.type < folder) || (type >= drive))
1380 result = strcmpi(name, b.name);
1383 if(type == folder && b.type < folder) result = -1;
1384 else if(type < folder && b.type == folder) result = 1;
1389 char * OnGetString(char * tempString, FileSystemToolWindow fileSysToolWnd, bool * needClass)
1391 return name ? name : "";
1395 ExplorerFileBranch MakeFileBranch(const FileStats stats, const char * name)
1397 ExplorerFileBranch fileTreeBranch { stats = stats };
1398 fileTreeBranch.name = CopyString(name);
1399 if(!fileTreeBranch.name)
1400 fileTreeBranch.name = null;
1401 if(stats.attribs.isDirectory)
1403 fileTreeBranch.type = (stats.attribs.isDrive) ? drive : folder;
1404 if(stats.attribs.isServer) fileTreeBranch.type = server;
1405 if(stats.attribs.isShare) fileTreeBranch.type = share;
1406 if(stats.attribs.isCDROM) fileTreeBranch.type = cdrom;
1407 if(stats.attribs.isRemote) fileTreeBranch.type = netDrive;
1408 if(stats.attribs.isRemovable)
1410 if(name[0] == 'A' || name[0] == 'B')
1411 fileTreeBranch.type = floppy;
1413 fileTreeBranch.type = removable;
1418 char extension[MAX_EXTENSION];
1419 GetExtension(fileTreeBranch.name, extension);
1420 fileTreeBranch.type = ExplorerFileType::SelectByExtension(extension);
1422 return fileTreeBranch;
1425 void AddBranch(ExplorerFileBranch branch, bool loaded, bool addLoader, ExplorerFileBranch addTo, ListBox tree)
1427 DataRow row = (addTo && addTo.row) ? addTo.row.AddRow() : tree.AddRow();
1430 branch.parent = addTo;
1431 branch.indent = addTo.indent + 1;
1432 addTo.children.Add(branch);
1434 row.tag = (int)branch;
1436 row.SetData(null, branch);
1438 branch.loaded = loaded;
1440 //AddBranch(ExplorerFileBranch { }, false, false, branch, tree); // why would this create a compile error?
1441 AddBranch(ExplorerFileBranch { type = none }, false, false, branch, tree);
1443 if(branch.indent > 0)
1444 row.collapsed = true;
1445 else if(branch.type == folder)
1446 branch.type = folderOpen;
1449 void BranchLoad(ExplorerFileBranch branch, ListBox tree)
1453 char path[MAX_LOCATION];
1454 branch.GetPath(path);
1456 FileListing listing { path };
1457 if(branch.children.count == 1)
1458 DeleteBranch(branch.children.first, tree);
1460 while(listing.Find())
1462 if(listing.stats.attribs.isDirectory)
1464 ExplorerFileBranch child = MakeFileBranch(listing.stats, listing.name);
1465 AddBranch(child, true, false, branch, tree);
1466 BranchChildLoad(child, branch, tree);
1470 branch.childrenLoaded = true;
1471 branch.loaded = true;
1472 branch.row.SortSubRows(false);
1474 else if(!branch.childrenLoaded)
1476 ExplorerFileBranch child;
1477 if(branch.children.first)
1479 for(child = branch.children.first; child; child = child.next)
1482 BranchLoad(child, tree);
1483 else if(!child.childrenLoaded)
1484 BranchChildLoad(child, branch, tree);
1486 branch.childrenLoaded = true;
1487 branch.row.SortSubRows(false);
1492 static void BranchChildLoad(ExplorerFileBranch parent, ExplorerFileBranch branch, ListBox tree)
1494 char path[MAX_LOCATION];
1495 parent.GetPath(path);
1498 FileListing listing { path };
1499 while(listing.Find())
1501 if(listing.stats.attribs.isDirectory)
1503 ExplorerFileBranch child = MakeFileBranch(listing.stats, listing.name);
1504 AddBranch(child, true, false, parent, tree);
1511 //parent.childrenLoaded = true;
1514 void DeleteBranch(ExplorerFileBranch branch, ListBox tree)
1516 ExplorerFileBranch child;
1517 for(; (child = branch.children.first); )
1518 DeleteBranch(child, tree);
1519 tree.DeleteRow(branch.row);