4 static char * rootName = "Entire Computer";
5 static char * msNetwork = "Microsoft Windows Network";
7 static char * rootName = "File System";
11 define guiApp = ((GuiApplication)__thisModule); // how to do this in a dll?
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 FileSystemBoxBits
142 bool foldersOnly:1, filesOnly:1, details:1, treeBranches:1, previewPictures:1, navigateFolders:1;
143 //bool header:1, freeSelect:1, fullRowSelect:1, multiSelect:1, autoScroll:1, alwaysHL : 1, moveRows:1, resizable:1;
144 //bool moveFields:1, clearHeader:1, alwaysEdit:1, collapse:1, treeBranch:1, rootCollapse:1, heightSet:1;
145 //bool sortable:1, noDragging:1, fillLastField:1, expandOnAdd:1;
148 public class FileSystemBox : Window // should we not derive from ListBox instead?
150 this stuff from the listbox would be nicely exposed...
151 fullRowSelect = false;
153 collapseControl = true;
154 rootCollapseButton = true;
159 hasHorzScroll = false;
160 hasVertScroll = false;
166 FileSystemNode selection;
168 virtual bool Window::NotifyNodeSelect(FileSystemBox box, FileSystemNode node);
169 virtual bool Window::NotifyNodeOpen(FileSystemBox box, FileSystemNode node);
176 if(value && value[0])
177 path = CopyString(value);
179 locationBox.path = value;
185 //isset { return path && path[0]; }
188 property bool foldersOnly { set { bits.foldersOnly = value; bits.filesOnly = !value; } get { return bits.foldersOnly; } };
189 property bool filesOnly { set { bits.filesOnly = value; bits.foldersOnly = !value; } get { return bits.filesOnly; } };
190 property bool previewPictures { set { bits.previewPictures = value; } get { return bits.previewPictures; } };
191 property char * extensions { set { delete extensions; if(value && value[0]) extensions = CopyString(value); } get { return extensions; } }
192 property bool details { set { bits.details = value; } get { return bits.details; } };
193 property bool treeBranches
197 bits.treeBranches = value;
198 list.treeBranches = value;
199 list.collapseControl = value;
200 list.rootCollapseButton = value;
202 get { return bits.treeBranches; }
204 property bool navigateFolders { set { bits.navigateFolders = value; bits.foldersOnly = !value; } get { return bits.navigateFolders; } };
206 property FileSystemNode node
214 if(!list.currentRow.tag)
216 return (FileSystemNode)list.currentRow.tag;
222 void Select(FileSystemNode node)
226 node.EnsureVisible(false);
227 list.SelectRow(node.row);
231 FileSystemNode Find(const char * name, FileSystemNode parent)
234 FileSystemNode start = parent ? parent : root;
235 if(!start.loaded || !start.childrenLoaded)
237 for(node = start.children.first; node; node = node.next)
238 if(node.name && !strcmpi(node.name, name))
249 FileSystemBoxBits bits;
254 BitmapResource fileIcons[_FileType];
258 char wd[MAX_LOCATION];
259 GetWorkingDir(wd, sizeof(wd));
263 list.AddField(nameField);
273 for(c = 0; c < _FileType::enumSize; c++)
275 fileIcons[c] = BitmapResource { fileIconNames[c], alphaBlend = true };
276 AddResource(fileIcons[c]);
280 DataField nameField { dataType = "FileSystemNode", width = 240, userData = this, freeData = false };
281 DataField typeField { header = "Type", dataType = /*"String"*/ "char *", width = 40, freeData = false };
282 DataField sizeField { header = "Size", dataType = "FileSize", width = 96, alignment = right, freeData = false };
295 hasHorzScroll = true;
296 hasVertScroll = true;
297 fullRowSelect = false;
300 anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
302 // WHY is this not working ?
303 /*void OnResize(int width, int height)
305 if(vertScroll.visible)
306 nameField.width = width - vertScroll.size.w;
308 nameField.width = width;
311 bool NotifyCollapse(ListBox listBox, DataRow row, bool collapsed)
315 FileSystemNode node = (FileSystemNode)row.tag;
316 FileSystemNode child;
320 for(child = node.children.last; child; child = node.children.last)
322 listBox.DeleteRow(child.row);
326 node.childrenLoaded = false;
331 if(!node.loaded || !node.childrenLoaded)
334 //list.Sort(nameField, 1);
337 for(child = node.children.first; child && child.next; child = child.next);
339 child.EnsureVisible(false);
345 bool NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods)
347 DataRow row = listBox.currentRow;
350 FileSystemNode node = (FileSystemNode)row.tag;
356 MenuItem { menu, "Cut\tCtrl+X", t, NotifySelect = null, disabled = false };
357 MenuItem { menu, "Copy\tCtrl+C", c, NotifySelect = null, disabled = false };
358 MenuItem { menu, "Paste\tCtrl+V", p, NotifySelect = null, disabled = false /*!clipboard*/ };
359 MenuItem { menu, "Delete\tDel", d, NotifySelect = null, disabled = false };
360 //MenuDivider { menu };
364 master = this, menu = menu,
366 x + clientStart.x + absPosition.x - guiApp.desktop.position.x,
367 y + clientStart.y + absPosition.y - guiApp.desktop.position.y }
375 bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
379 FileSystemNode node = (FileSystemNode)row.tag;
380 NotifyNodeSelect(listBox.parent.master, this, node);
386 bool NotifyEditing(ListBox listBox, DataRow row)
390 FileSystemNode node = (FileSystemNode)row.tag;
395 bool NotifyEdited(ListBox listBox, DataRow row)
399 FileSystemNode node = (FileSystemNode)row.tag;
404 bool NotifyEditDone(ListBox listBox, DataRow row)
408 FileSystemNode node = (FileSystemNode)row.tag;
413 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
418 bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
421 if((SmartKey)key == enter)
432 if(selection && selection.type.isFolder && bits.navigateFolders)
434 property::path = selection.path;
438 result = NotifyNodeOpen(this.master, this, selection);
443 Menu editMenu { menu, "Edit", e };
446 editMenu, "Cut\tCtrl+X", t, disabled = true;
448 bool NotifySelect(MenuItem selection, Modifiers mods)
454 MenuItem itemEditCopy
456 editMenu, "Copy\tCtrl+C", c, disabled = true;
458 bool NotifySelect(MenuItem selection, Modifiers mods)
464 MenuItem itemEditPaste
466 editMenu, "Paste\tCtrl+V", p;
468 bool NotifySelect(MenuItem selection, Modifiers mods)
474 MenuItem itemEditDelete
476 editMenu, "Delete\tDel", d, disabled = true;
478 bool NotifySelect(MenuItem selection, Modifiers mods)
485 // WHY is this crashing ?
486 /*void OnResize(int width, int height)
488 if(this && nameField)
489 nameField.width = width - 80;
495 // this is crashing in for designer when details = true // can't save the file, always yields a crash
496 /*if(list && created)
499 list.AddField(nameField);
502 list.AddField(typeField);
503 list.AddField(sizeField);
506 if(bits.treeBranches)
514 FileListing listing { path, extensions = extensions };
517 while(listing.Find())
519 if((!bits.foldersOnly && !bits.filesOnly) ||
520 (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
521 (bits.filesOnly && !listing.stats.attribs.isDirectory/*listing.stats.attribs.isFile*/)) // TOCHECK: isFile broken?
523 FileSystemNode node = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
524 DataRow row = list.AddRow();
526 row.SetData(nameField, node);
529 row.SetData(typeField, node.extension);
530 row.SetData(sizeField, (void *)node.stats.size);
534 list.Sort(nameField, 1);
539 bool isRoot = !strcmp(path, "/");
540 //char startPath[MAX_LOCATION];
541 FileSystemNode parent;
543 FileListing listing { path, extensions = extensions };
546 GetWorkingDir(startPath, sizeof(startPath));
548 strcpy(path, startPath);*/
556 root = FileSystemNode { loaded = true, childrenLoaded = true };
557 AddTreeNode(root, true, false, null);
558 while(listing.Find())
560 int len = strlen(listing.name);
561 char info[MAX_LOCATION];
562 char name[MAX_LOCATION];
563 if(listing.stats.attribs.isDrive &&
564 len > 3 && !strncmp(&listing.name[1], ": [", 3))
566 strncpy(name, listing.name, 2);
568 strncpy(info, &listing.name[4], len - 5);
573 strcpy(name, listing.name);
577 parent = MakeFileSystemNode(listing.stats, name, listing.path, bits.previewPictures, displaySystem);
579 parent.info = CopyString(info);
580 parent.loaded = true;
581 AddTreeNode(parent, !listing.stats.attribs.isDirectory, listing.stats.attribs.isDirectory, root);
582 if(!listing.stats.attribs.isDirectory)
583 parent.childrenLoaded = true;
586 node = FileSystemNode { name = msNetwork, type = network };
587 AddTreeNode(node, false, true, null);
588 node.row.collapsed = true;
593 root = MakeFileSystemNode(FileStats { attribs = FileExists(path)}, path, path, bits.previewPictures, displaySystem);
594 AddTreeNode(root, false, true, null);
600 root.type = computer;
601 root.name = rootName;
604 list.Sort(nameField, 1);
605 list.SelectRow(root.row);
608 void LoadTreeNode(FileSystemNode node)
612 char path[MAX_LOCATION];
615 FileListing listing { path, extensions = extensions };
616 if(node.children.count == 1)
617 DeleteNode(node.children.first);
619 while(listing.Find())
621 if((!bits.foldersOnly && !bits.filesOnly) ||
622 (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
623 (bits.filesOnly && !listing.stats.attribs.isDirectory/*listing.stats.attribs.isFile*/)) // TOCHECK: isFile broken?
625 FileSystemNode child = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
626 AddTreeNode(child, true, false, node);
627 NodeChildLoad(child, node);
631 node.childrenLoaded = true;
633 node.row.SortSubRows(false);
635 else if(!node.childrenLoaded)
637 FileSystemNode child;
638 if(node.children.first)
640 for(child = node.children.first; child; child = child.next)
644 else if(!child.childrenLoaded)
645 NodeChildLoad(child, node);
647 node.childrenLoaded = true;
648 node.row.SortSubRows(false);
653 void NodeChildLoad(FileSystemNode parent, FileSystemNode node)
655 char path[MAX_LOCATION];
656 parent.GetPath(path);
659 FileListing listing { path, extensions = extensions };
660 while(listing.Find())
662 if((!bits.foldersOnly && !bits.filesOnly) ||
663 (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
664 (bits.filesOnly && !listing.stats.attribs.isDirectory/*listing.stats.attribs.isFile*/)) // TOCHECK: isFile broken?
666 FileSystemNode child = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
667 AddTreeNode(child, true, false, parent);
674 //parent.childrenLoaded = true;
677 void AddTreeNode(FileSystemNode node, bool loaded, bool addLoader, FileSystemNode addTo)
679 DataRow row = (addTo && addTo.row) ? addTo.row.AddRow() : list.AddRow();
683 node.indent = addTo.indent + 1;
684 addTo.children.Add(node);
688 row.SetData(null, node);
690 node.loaded = loaded;
692 //AddTreeNode(FileSystemNode { }, false, false, node); // why would this create a compile error?
693 AddTreeNode(FileSystemNode { type = none }, false, false, node);
696 row.collapsed = true;
697 else if(node.type == folder)
698 node.type = folderOpen;
701 void DeleteNode(FileSystemNode node)
703 FileSystemNode child;
704 for(; (child = node.children.first); )
706 list.DeleteRow(node.row);
713 class ExplorerView : FileSystemBox
716 hasHorzScroll = false;
717 hasVertScroll = false;
719 virtual void Load(FileSystemNode parent);
720 virtual void Refresh();
722 virtual void LaunchNotifyItemSelect(Window master, ExplorerView view, ExplorerFileItem item, ExplorerFileItemArray selectedItems)
724 view.NotifyItemSelect(master, view, item, selectedItems);
727 virtual bool Window::NotifyItemSelect(ExplorerView view, ExplorerFileItem item, ExplorerFileItemArray selectedItems);
728 virtual bool Window::NotifyItemOpen(ExplorerView view, ExplorerFileItem item);
732 master = master, parent = this;
735 hasHorzScroll = true;
736 hasVertScroll = true;
739 fullRowSelect = false;
742 anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
744 bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
746 ExplorerView view = (ExplorerView)listBox.parent;
747 if(listBox.currentRow)
750 ExplorerFileItemArray selectedItems { growingFactor = 16 };
751 for(listRow = listBox.firstRow; listRow; listRow = listRow.next)
753 selectedItems.Add((ExplorerFileItem)listRow.tag);
754 //view.NotifyItemSelect(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
755 view.LaunchNotifyItemSelect(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag, selectedItems);
760 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
762 ExplorerView view = (ExplorerView)listBox.parent;
763 view.NotifyItemOpen(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
767 bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
769 if((SmartKey)key == enter)
771 ExplorerView view = (ExplorerView)listBox.parent;
772 view.NotifyItemOpen(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
785 class ExplorerViewList : ExplorerView
788 FileSystemNode location;
792 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
794 ExplorerViewDetails()
796 list.AddField(nameField);
804 void Load(FileSystemNode location)
806 char path[MAX_LOCATION];
807 this.location = location;
808 location.GetPath(path);
810 FileListing listing { path };
812 ExplorerFileItem item;
817 while(listing.Find())
819 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
823 row.SetData(nameField, item);
825 list.Sort(nameField, 1);
832 class ExplorerViewDetails : ExplorerView
834 list.hasHeader = true;
835 list.moveFields = true;
836 list.resizable = true;
837 list.sortable = true;
839 FileSystemNode location;
843 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
844 DataField typeField { header = "Type", dataType = /-*"String"*-/ "char *", width = 40 };
845 DataField sizeField { header = "Size", dataType = "FileSize", width = 96, alignment = right };
847 ExplorerViewDetails()
849 list.AddField(nameField);
850 list.AddField(typeField);
851 list.AddField(sizeField);
859 void Load(FileSystemNode location)
861 char path[MAX_LOCATION];
862 this.location = location;
863 location.GetPath(path);
865 FileListing listing { path };
867 ExplorerFileItem item;
872 while(listing.Find())
874 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
878 row.SetData(nameField, item);
879 row.SetData(typeField, CopyString(item.extension));
880 row.SetData(sizeField, (uint)listing.stats.size);
882 list.Sort(nameField, 1);
889 class ExplorerViewIcons : ExplorerView
892 FileSystemNode location;
896 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
898 ExplorerViewDetails()
900 list.AddField(nameField);
908 void Load(FileSystemNode location)
910 char path[MAX_LOCATION];
911 this.location = location;
912 location.GetPath(path);
914 FileListing listing { path };
916 ExplorerFileItem item;
921 while(listing.Find())
923 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
927 row.SetData(nameField, item);
929 list.Sort(nameField, 1);
936 class ExplorerViewCards : ExplorerView
939 FileSystemNode location;
943 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
945 ExplorerViewDetails()
947 list.AddField(nameField);
955 void Load(FileSystemNode location)
957 char path[MAX_LOCATION];
958 this.location = location;
959 location.GetPath(path);
961 FileListing listing { path };
963 ExplorerFileItem item;
968 while(listing.Find())
970 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
974 row.SetData(nameField, item);
976 list.Sort(nameField, 1);
983 public class BitmapArray : RedjArray
985 type = class(Bitmap);
988 Bitmap * Add(Bitmap bitmap)
995 Bitmap * AddBefore(uint position, Bitmap bitmap)
998 _[position] = bitmap;
1004 for(c = 0; c < _count; c++)
1016 class ExplorerViewShowcase : ExplorerView
1018 list.anchor = Anchor { left = 0, top = 0, bottom = 0 };
1019 list.size = Size { w = 200 };
1021 FileSystemNode location;
1025 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 180, editable = true, userData = this };
1028 BitmapArray bitmaps { growingFactor = 16 };
1034 anchor = Anchor { top = 0, right = 0, bottom = 0 };
1036 void OnRedraw(Surface surface)
1038 ExplorerViewShowcase view = (ExplorerViewShowcase)parent;
1041 int wBmp = view.bitmap.width;
1042 int hBmp = view.bitmap.height;
1043 int wWnd = clientSize.w;
1044 int hWnd = clientSize.h;
1046 int wList = view.list.size.w + view.split.size.w;
1048 float scale = Min((float)(wWnd - 10) / wBmp, (float)(hWnd - 10) / hBmp);
1050 int wDraw = (int)(wBmp * scale);
1051 int hDraw = (int)(hBmp * scale);
1054 surface.Filter(view.bitmap, (wWnd - wDraw) / 2, (hWnd - hDraw) / 2, 0, 0, wDraw, hDraw, wBmp, hBmp);
1056 // Until Filter / Stretch works with X
1057 surface.Blit(view.bitmap, (wWnd - wDraw) / 2, (hWnd - hDraw) / 2, 0, 0, wDraw, hDraw);
1062 surface.SetForeground(white);
1063 surface.Area(0, 0, view.clientSize.w - 1, view.clientSize.h - 1);
1077 ExplorerViewDetails()
1079 list.AddField(nameField);
1082 void LaunchNotifyItemSelect(Window master, ExplorerViewShowcase view, ExplorerFileItem item, ExplorerFileItemArray selectedItems)
1085 ExplorerFileItem selItem;
1089 if(item && item.type == pictureFile)
1091 view.bitmap = Bitmap { };
1092 view.bitmap.Load(item.path, null, displaySystem);
1095 view.bitmaps.Clear();
1096 view.bitmaps = BitmapArray { };
1097 for(pos = 0; pos < selectedItems.count; pos++)
1100 selItem = (ExplorerFileItem)selectedItems._[pos];
1101 bitmap.Load(selItem.path, null, displaySystem);
1102 //view.bitmaps.Add(bitmap);
1104 if(item && item.type == pictureFile)
1106 view.bitmap = Bitmap { };
1107 view.bitmap.Load(item.path, null, displaySystem);
1110 view.show.Update(null);
1111 view.NotifyItemSelect(master, view, item, selectedItems);
1119 void Load(FileSystemNode location)
1121 char path[MAX_LOCATION];
1122 this.location = location;
1123 location.GetPath(path);
1125 FileListing listing { path };
1127 ExplorerFileItem item;
1132 while(listing.Find())
1134 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
1136 row = list.AddRow();
1137 row.tag = (int)item;
1138 row.SetData(nameField, item);
1140 list.Sort(nameField, 1);
1147 class ExplorerTree : FileSystemBox
1149 hasHorzScroll = false;
1150 hasVertScroll = false;
1156 DataField nameField { dataType = "FileSystemNode", width = 240, userData = this };
1158 FileSystemNode root;
1159 FileSystemNode selection;
1161 virtual bool Window::NotifyNodeSelect(ExplorerTree tree, FileSystemNode node);
1163 property FileSystemNode node
1169 if(!tree.currentRow)
1171 if(!tree.currentRow.tag)
1173 return (FileSystemNode)tree.currentRow.tag;
1177 void Select(FileSystemNode node)
1181 node.EnsureVisible(false);
1182 tree.SelectRow(node.row);
1186 FileSystemNode Find(const char * name, FileSystemNode parent)
1188 FileSystemNode node;
1189 FileSystemNode start = parent ? parent : root;
1190 if(!start.loaded || !start.childrenLoaded)
1191 LoadTreeNode(start, tree);
1192 for(node = start.children.first; node; node = node.next)
1193 if(node.name && !strcmpi(node.name, name))
1200 master = master, parent = this;
1203 hasHorzScroll = true;
1204 hasVertScroll = true;
1205 fullRowSelect = false;
1207 collapseControl = true;
1208 rootCollapseButton = true;
1210 anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
1212 // WHY is this not working ?
1213 /-*void OnResize(int width, int height)
1215 if(vertScroll.visible)
1216 nameField.width = width - vertScroll.size.w;
1218 nameField.width = width;
1221 bool NotifyCollapse(ListBox listBox, DataRow row, bool collapsed)
1225 FileSystemNode node = (FileSystemNode)row.tag;
1226 FileSystemNode child;
1230 for(child = node.children.last; child; child = node.children.last)
1232 listBox.DeleteRow(child.row);
1236 node.childrenLoaded = false;
1241 if(!node.loaded || !node.childrenLoaded)
1242 LoadTreeNode(node, tree);
1243 for(child = node.children.first; child && child.next; child = child.next);
1245 child.EnsureVisible(false);
1251 bool NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods)
1253 DataRow row = listBox.currentRow;
1256 FileSystemNode node = (FileSystemNode)row.tag;
1262 MenuItem { menu, "Cut\tCtrl+X", t, NotifySelect = null, disabled = false };
1263 MenuItem { menu, "Copy\tCtrl+C", c, NotifySelect = null, disabled = false };
1264 MenuItem { menu, "Paste\tCtrl+V", p, NotifySelect = null, disabled = false /-*!clipboard*-/ };
1265 MenuItem { menu, "Delete\tDel", d, NotifySelect = null, disabled = false };
1266 //MenuDivider { menu };
1270 master = this, menu = menu,
1272 x + clientStart.x + absPosition.x - guiApp.desktop.position.x,
1273 y + clientStart.y + absPosition.y - guiApp.desktop.position.y }
1281 bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
1285 FileSystemNode node = (FileSystemNode)row.tag;
1286 NotifyNodeSelect(listBox.parent.master, this, node);
1292 bool NotifyEditing(ListBox listBox, DataRow row)
1296 FileSystemNode node = (FileSystemNode)row.tag;
1301 bool NotifyEdited(ListBox listBox, DataRow row)
1305 FileSystemNode node = (FileSystemNode)row.tag;
1310 bool NotifyEditDone(ListBox listBox, DataRow row)
1314 FileSystemNode node = (FileSystemNode)row.tag;
1321 Menu editMenu { menu, "Edit", e };
1322 MenuItem itemEditCut
1324 editMenu, "Cut\tCtrl+X", t, disabled = true;
1326 bool NotifySelect(MenuItem selection, Modifiers mods)
1332 MenuItem itemEditCopy
1334 editMenu, "Copy\tCtrl+C", c, disabled = true;
1336 bool NotifySelect(MenuItem selection, Modifiers mods)
1342 MenuItem itemEditPaste
1344 editMenu, "Paste\tCtrl+V", p;
1346 bool NotifySelect(MenuItem selection, Modifiers mods)
1352 MenuItem itemEditDelete
1354 editMenu, "Delete\tDel", d, disabled = true;
1356 bool NotifySelect(MenuItem selection, Modifiers mods)
1363 // WHY is this crashing ?
1364 /-*void OnResize(int width, int height)
1366 if(this && nameField)
1367 nameField.width = width - 80;
1372 tree.AddField(nameField);
1377 FileSystemNode parent;
1378 FileSystemNode node;
1379 FileListing listing { "/" };
1383 root = FileSystemNode { type = computer, loaded = true, childrenLoaded = true };
1385 root.name = rootName;
1389 AddTreeNode(root, true, false, null, tree);
1391 // How can this make sense for linux?
1393 while(listing.Find())
1395 int len = strlen(listing.name);
1396 char info[MAX_LOCATION];
1397 char name[MAX_LOCATION];
1398 if(listing.stats.attribs.isDrive &&
1399 len > 3 && !strncmp(&listing.name[1], ": [", 3))
1401 strncpy(name, listing.name, 2);
1403 strncpy(info, &listing.name[4], len - 5);
1408 strcpy(name, listing.name);
1412 parent = MakeFileSystemNode(listing.stats, name);
1414 parent.info = CopyString(info);
1415 parent.loaded = true;
1416 AddTreeNode(parent, !listing.stats.attribs.isDirectory, listing.stats.attribs.isDirectory, root, tree);
1417 if(!listing.stats.attribs.isDirectory)
1418 parent.childrenLoaded = true;
1421 node = FileSystemNode { name = msNetwork, type = network };
1422 AddTreeNode(node, false, true, null, tree);
1423 node.row.collapsed = true;
1424 tree.Sort(nameField, 1);
1425 tree.SelectRow(root.row);
1430 public class ClipBoardFiles
1444 int size = SelSize();
1447 // Try to allocate memory
1448 ClipBoard clipBoard { };
1449 if(clipBoard.Allocate(size+1))
1451 GetSel(clipBoard.memory, true);
1464 ClipBoard clipBoard { };
1465 if(clipBoard.Load())
1466 PutS(clipBoard.memory);
1477 SetViewToCursor(true);
1483 Private Type DROPFILES
1489 For iCounter = 0 To filelist.ListCount - 1
1490 If filelist.Selected(iCounter) = True Then
1491 strFiles = strFiles & FixPath(filelist.Path) & filelist.List(iCounter) & vbNullChar
1494 'all selected items are now put in strFiles
1496 hGlobal = GlobalAlloc(GHND, Len(DF) + Len(strFiles)) 'put all files to a exclusive number
1497 If hGlobal Then 'if the globalalloc worked
1498 lpGlobal = GlobalLock(hGlobal) 'lock the hGlobal
1499 DF.pFiles = Len(DF) 'set the size of the files
1501 Call CopyMem(ByVal lpGlobal, DF, Len(DF)) 'copy df to the lpglobal
1502 Call CopyMem(ByVal (lpGlobal + Len(DF)), ByVal strFiles, Len(strFiles)) 'copy strfiles to lpglobal
1503 Call GlobalUnlock(hGlobal) 'unlock hglobal again
1505 SetClipboardData CF_HDROP, hGlobal 'put files to the clipboard
1508 bool SaveFile(const char * filePath)
1514 public class FileTreeNodeBSArray : ArrayBinarySorted
1516 type = class(FileSystemNode);
1518 FileSystemNode * const _;
1519 BSloc Add(FileSystemNode item)
1521 BSloc result = Find(item);
1524 Insert(result.pos, 1);
1525 _[result.pos] = item;
1529 BSloc Remove(FileSystemNode item)
1537 public class FileTreeNodeArray : RedjArray
1539 type = class(FileSystemNode);
1541 FileSystemNode * const _;
1542 FileSystemNode * Add(FileSystemNode item)
1549 FileSystemNode * AddBefore(uint position, FileSystemNode item)
1551 Insert(position, 1);
1553 return &_[position];
1559 public class ExplorerFileItem : struct
1570 void OnDisplay(Surface surface, int x, int y, int width, FileSystemBox control, Alignment alignment, DataDisplayFlags displayFlags)
1572 int indentSize = (displayFlags.dropBox) ? 0 : 10;
1575 char label[MAX_FILENAME];
1577 //float scale = Min((float)clientSize.w / (float)bitmap.width, (float)clientSize.h / (float)bitmap.height);
1578 int w = 16; //(int)(bitmap.width * scale);
1579 int h = 16; //(int)(bitmap.height * scale);
1583 icon = control.fileIcons[type].bitmap;
1586 if(type == folder || type == folderOpen)
1587 surface.SetForeground(red); //Color { 170, 170, 0 } // REDJ What is that color?
1590 textOffset = indent * indentSize + (icon ? (icon.width + 6) : 0);
1593 sprintf(label, "%s [%s]", name, info);
1595 strcpy(label, name);
1596 len = strlen(label);
1598 surface.WriteTextDots
1599 (alignment, x + textOffset, y + 2, width - textOffset, label, len);
1600 if(type == pictureFile && control.previewPictures && bitmap)
1603 //surface.Filter(bitmap, (clientSize.w - w) / 2,(clientSize.h - h) / 2, 0,0, w, h, bitmap.width, bitmap.height);
1604 surface.Filter(bitmap, x + indent * indentSize + 2, y, 0, 0, w, h, bitmap.width, bitmap.height);
1606 // Until Filter / Stretch works with X
1607 //surface.Blit(bitmap, (clientSize.w - bitmap.width) / 2,(clientSize.h - bitmap.height) / 2, 0,0, bitmap.width, bitmap.height);
1608 surface.blend = true;
1609 surface.Blit(bitmap, x + indent * indentSize + 2, y,0,0, w, h);
1615 surface.Blit(icon, x + indent * indentSize + 2, y,0,0, icon.width, icon.height);
1618 int OnCompare(ExplorerFileItem b)
1621 if(type == b.type || (type < folder && b.type < folder) || (type >= drive))
1622 result = strcmpi(name, b.name);
1625 if(type == folder && b.type < folder) result = -1;
1626 else if(type < folder && b.type == folder) result = 1;
1631 void OnCopy(ExplorerFileItem newData)
1633 type = newData.type;
1634 indent = newData.indent;
1637 int len = strlen(newData.name) + 1;
1638 name = new char[len];
1639 CopyBytes(name, newData.name, len);
1643 bool OnGetDataFromString(char * string)
1645 int len = strlen(string) + 1;
1646 name = new char[len];
1647 CopyBytes(name, string, len);
1661 char * OnGetString(char * string, void * fieldData, bool * needClass)
1667 public class ExplorerFileItemArray : RedjArray
1669 type = class(ExplorerFileItem);
1671 ExplorerFileItem * const _;
1672 ExplorerFileItem * Add(ExplorerFileItem item)
1679 ExplorerFileItem * AddBefore(uint position, ExplorerFileItem item)
1681 Insert(position, 1);
1683 return &_[position];
1688 for(c = 0; c < _count; c++)
1698 ExplorerFileItem MakeFileItem(const FileAttribs attribs, const char * fileName, const char * filePath, const bool previewPicture, const DisplaySystem displaySystem)
1700 int len = strlen(fileName);
1701 char info[MAX_LOCATION];
1702 char name[MAX_LOCATION];
1703 char extension[MAX_EXTENSION];
1705 ExplorerFileItem item { };
1707 //if(attribs.isFile) // TODO fix this in ecere
1708 if(attribs.isDirectory)
1712 item.type = (attribs.isDrive) ? drive : folder;
1713 if(attribs.isServer)
1719 if(attribs.isRemote)
1720 item.type = netDrive;
1721 if(attribs.isRemovable)
1723 if(fileName[0] == 'A' || fileName[0] == 'B')
1726 item.type = removable;
1731 GetExtension(fileName, extension);
1732 //strupr(extension);
1735 item.type = _FileType::SelectByExtension(extension);
1738 if(attribs.isDrive &&
1739 len > 3 && !strncmp(&fileName[1], ": [", 3))
1741 strncpy(name, fileName, 2);
1743 strncpy(info, &fileName[4], len - 5);
1748 strcpy(name, fileName);
1752 item.path = CopyString(filePath);
1753 item.name = CopyString(name);
1755 item.info = CopyString(info);
1756 item.extension = CopyString(extension);
1758 if(item.type == pictureFile && previewPicture)
1760 item.bitmap = Bitmap { };
1761 item.bitmap.Load(filePath, null, displaySystem);
1769 public class FileSystemNode : struct
1772 /*//LinkElement<FileSystemNode> link;
1773 FileSystemNode parent;
1775 FileSystemNodeType type;
1779 FileSystemNode prev, next;
1781 bool loaded, childrenLoaded;
1790 FileSystemNode parent;
1796 void GetPath(String outputPath)
1801 strcpy(outputPath, name);
1802 for(up = parent; up; up = up.parent)
1804 char temp[MAX_LOCATION];
1805 strcpy(temp, up.name);
1806 PathCat(temp, outputPath);
1807 strcpy(outputPath, temp);
1812 strcpy(outputPath, "/");
1814 strcpy(outputPath, name);
1819 bool IsChildOf(FileSystemNode node)
1821 FileSystemNode test;
1822 for(test = parent; test; test = test.parent)
1828 void DuplicateChildren(bool recursive, bool forceExpanded, FileSystemNode addTo, FileSystemBox fsb)
1832 FileSystemNode child;
1834 for(child = children.first; child; child = child.next)
1836 FileSystemNode copy { };
1837 copy.name = CopyString(child.name);
1838 copy.type = child.type;
1839 fsb.AddTreeNode(copy, child.loaded, false, addTo);
1841 copy.row.collapsed = false;
1843 child.DuplicateChildren(recursive, forceExpanded, copy, fsb);
1848 void EnsureVisible(bool expand)
1851 parent.EnsureVisible(true);
1853 row.collapsed = false;
1854 // TODO: row.EnsureVisible(); // making the row visible by scrolling
1864 FileSystemNode child;
1865 for(; (child = children.first); )
1868 children.Delete(child);
1879 parent.children.Delete(this);
1882 void OnDisplay(Surface surface, int x, int y, int width, FileSystemBox fsb, Alignment alignment, DataDisplayFlags displayFlags)
1884 //int indentSize = (displayFlags.dropBox) ? 0 : 10;
1890 char label[MAX_FILENAME];
1897 icon = fsb.fileIcons[type].bitmap;
1898 //xStart = indent * indent + x + (icon ? (icon.width + 5) : 0);
1899 xStart = x + (icon ? (icon.width + 5) : 0);
1905 sprintf(label, "%s [%s]", name, info);
1907 strcpy(label, name);
1908 len = strlen(label);
1912 if(type == folder || type == folderOpen)
1913 surface.SetForeground(yellow);
1917 //textOffset = indent * indentSize + (icon ? (icon.width + 4) : 0);
1919 surface.TextOpacity(false);
1920 surface.TextExtent(label, len, &w, &h);
1923 // Draw the current row stipple
1924 if(displayFlags.selected)
1925 //surface.Area(xStart - 1, y, xStart - 1, y + h - 1);
1926 //surface.Area(xStart + w - 1, y, xStart + w + 1, y + h - 1);
1927 surface.Area(xStart - 3, y, xStart + w + 1, y + h - 1);
1929 //surface.WriteTextDots(alignment, x + textOffset, y + 2, width - textOffset, name, strlen(name));
1930 surface.WriteTextDots(alignment, xStart, y + 2, width, label, len);
1932 //if(!guiApp.textMode) -- how to do this in a dll?
1934 if(displayFlags.current)
1936 if(displayFlags.active)
1938 surface.LineStipple(0x5555);
1939 if(displayFlags.selected)
1940 surface.SetForeground(0xFFFFFF80);
1942 surface.SetForeground(black);
1946 surface.SetForeground(selectionColor);
1948 surface.Rectangle(xStart - 3, y, xStart + w + 1, y + h - 1);
1949 surface.LineStipple(0);
1957 if(type == pictureFile && fsb.previewPictures && bitmap)
1959 surface.SetForeground(white);
1960 surface.blend = true;
1962 //surface.Filter(bitmap, (clientSize.w - w) / 2,(clientSize.h - h) / 2, 0,0, w, h, bitmap.width, bitmap.height);
1963 //surface.Filter(bitmap, x + indent/* * indentSize*/ + 2, y, 0, 0, w, h, bitmap.width, bitmap.height);
1964 surface.Filter(bitmap, x,y,0,0, w, h, bitmap.width, bitmap.height);
1966 // Until Filter / Stretch works with X
1967 //surface.Blit(bitmap, (clientSize.w - bitmap.width) / 2,(clientSize.h - bitmap.height) / 2, 0,0, bitmap.width, bitmap.height);
1968 // surface.blend = true;
1969 //surface.Blit(bitmap, x + indent/* * indentSize*/ + 2, y,0,0, w, h);
1970 //surface.Blit(bitmap, x,y,0,0, bitmap.width, bitmap.height);
1977 //surface.blend = true;
1978 //surface.alphaWrite = blend;
1979 surface.SetForeground(white);
1980 //surface.Blit(icon, x + indent * indentSize, y,0,0, icon.width, icon.height);
1981 surface.Blit(icon, x,y,0,0, icon.width, icon.height);
1986 int OnCompare(FileSystemNode b)
1989 FileSystemNode a = this;
1990 if(a.type == b.type || (a.type < folder && b.type < folder) || (a.type >= drive))
1991 result = strcmpi(a.name, b.name);
1994 if(a.type == folder && b.type < folder) result = -1;
1995 else if(a.type < folder && b.type == folder) result = 1;
2001 /*int OnCompare(FileSystemNode b)
2004 FileSystemNode a = this;
2005 if(a.parent < b.parent) result = -1;
2006 else if(a.parent > b.parent) result = 1;
2008 result = fstrcmp(a.name, b.name);
2012 char * OnGetString(char * tempString, FileSystemToolWindow fileSysToolWnd, bool * needClass)
2014 return name ? name : "";
2018 /*FileSystemNode MakeFileSystemNode(const FileStats stats, const char * name)
2020 FileSystemNode node { stats = stats };
2021 node.name = CopyString(name);
2024 if(stats.attribs.isDirectory)
2026 node.type = (stats.attribs.isDrive) ? drive : folder;
2027 if(stats.attribs.isServer) node.type = server;
2028 if(stats.attribs.isShare) node.type = share;
2029 if(stats.attribs.isCDROM) node.type = cdrom;
2030 if(stats.attribs.isRemote) node.type = netDrive;
2031 if(stats.attribs.isRemovable)
2033 if(name[0] == 'A' || name[0] == 'B')
2036 node.type = removable;
2041 char extension[MAX_EXTENSION];
2042 GetExtension(node.name, extension);
2043 node.type = _FileType::SelectByExtension(extension);
2047 static FileSystemNode MakeFileSystemNode(const FileStats stats,
2048 const char * fileName, const char * filePath,
2049 const bool previewPicture, const DisplaySystem displaySystem)
2051 int len = strlen(fileName);
2052 char info[MAX_LOCATION];
2053 char name[MAX_LOCATION];
2054 char extension[MAX_EXTENSION];
2056 FileSystemNode node { stats = stats };
2058 //if(stats.attribs.isFile) // TODO fix this in ecere
2059 if(stats.attribs.isDirectory)
2061 extension[0] = '\0';
2063 node.type = (stats.attribs.isDrive) ? drive : folder;
2064 if(stats.attribs.isServer) node.type = server;
2065 if(stats.attribs.isShare) node.type = share;
2066 if(stats.attribs.isCDROM) node.type = cdrom;
2067 if(stats.attribs.isRemote) node.type = netDrive;
2068 if(stats.attribs.isRemovable)
2070 if(fileName[0] == 'A' || fileName[0] == 'B')
2073 node.type = removable;
2078 GetExtension(fileName, extension);
2081 node.type = _FileType::SelectByExtension(extension);
2084 if(stats.attribs.isDrive &&
2085 len > 3 && !strncmp(&fileName[1], ": [", 3))
2087 strncpy(name, fileName, 2);
2089 strncpy(info, &fileName[4], len - 5);
2094 strcpy(name, fileName);
2098 node.path = CopyString(filePath);
2099 node.name = CopyString(name);
2101 node.info = CopyString(info);
2102 node.extension = CopyString(extension);
2104 if(node.type == pictureFile && previewPicture)
2106 node.bitmap = Bitmap { alphaBlend = true };
2107 node.bitmap.Load(filePath, null, displaySystem);