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.filesOnly = !value; } get { return bits.navigateFolders; } };
205 property bool multiSelect { set { list.multiSelect = value; } get { return list.multiSelect; } };
207 property FileSystemNode node
215 if(!list.currentRow.tag)
217 return (FileSystemNode)list.currentRow.tag;
223 void Select(FileSystemNode node)
227 node.EnsureVisible(false);
228 list.SelectRow(node.row);
232 FileSystemNode Find(const char * name, FileSystemNode parent)
235 FileSystemNode start = parent ? parent : root;
236 if(!start.loaded || !start.childrenLoaded)
238 for(node = start.children.first; node; node = node.next)
239 if(node.name && !strcmpi(node.name, name))
250 FileSystemBoxBits bits;
255 BitmapResource fileIcons[_FileType];
259 char wd[MAX_LOCATION];
260 GetWorkingDir(wd, sizeof(wd));
264 list.AddField(nameField);
274 for(c = 0; c < _FileType::enumSize; c++)
276 fileIcons[c] = BitmapResource { fileIconNames[c], alphaBlend = true };
277 AddResource(fileIcons[c]);
281 DataField nameField { dataType = "FileSystemNode", width = 240, userData = this, freeData = false };
282 DataField typeField { header = "Type", dataType = /*"String"*/ "char *", width = 40, freeData = false };
283 DataField sizeField { header = "Size", dataType = "FileSize", width = 96, alignment = right, freeData = false };
296 hasHorzScroll = true;
297 hasVertScroll = true;
298 fullRowSelect = false;
301 anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
303 // WHY is this not working ?
304 /*void OnResize(int width, int height)
306 if(vertScroll.visible)
307 nameField.width = width - vertScroll.size.w;
309 nameField.width = width;
312 bool NotifyCollapse(ListBox listBox, DataRow row, bool collapsed)
316 FileSystemNode node = (FileSystemNode)row.tag;
317 FileSystemNode child;
321 for(child = node.children.last; child; child = node.children.last)
323 listBox.DeleteRow(child.row);
327 node.childrenLoaded = false;
332 if(!node.loaded || !node.childrenLoaded)
335 //list.Sort(nameField, 1);
338 for(child = node.children.first; child && child.next; child = child.next);
340 child.EnsureVisible(false);
346 bool NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods)
348 DataRow row = listBox.currentRow;
351 FileSystemNode node = (FileSystemNode)row.tag;
357 MenuItem { menu, "Cut\tCtrl+X", t, NotifySelect = null, disabled = false };
358 MenuItem { menu, "Copy\tCtrl+C", c, NotifySelect = null, disabled = false };
359 MenuItem { menu, "Paste\tCtrl+V", p, NotifySelect = null, disabled = false /*!clipboard*/ };
360 MenuItem { menu, "Delete\tDel", d, NotifySelect = null, disabled = false };
361 //MenuDivider { menu };
365 master = this, menu = menu,
367 x + clientStart.x + absPosition.x - guiApp.desktop.position.x,
368 y + clientStart.y + absPosition.y - guiApp.desktop.position.y }
376 bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
380 FileSystemNode node = (FileSystemNode)row.tag;
381 NotifyNodeSelect(listBox.parent.master, this, node);
387 bool NotifyEditing(ListBox listBox, DataRow row)
391 FileSystemNode node = (FileSystemNode)row.tag;
396 bool NotifyEdited(ListBox listBox, DataRow row)
400 FileSystemNode node = (FileSystemNode)row.tag;
405 bool NotifyEditDone(ListBox listBox, DataRow row)
409 FileSystemNode node = (FileSystemNode)row.tag;
414 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
419 bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
422 if((SmartKey)key == enter)
433 if(selection && selection.type.isFolder && bits.navigateFolders)
435 property::path = selection.path;
439 result = NotifyNodeOpen(this.master, this, selection);
444 Menu editMenu { menu, "Edit", e };
447 editMenu, "Cut\tCtrl+X", t, disabled = true;
449 bool NotifySelect(MenuItem selection, Modifiers mods)
455 MenuItem itemEditCopy
457 editMenu, "Copy\tCtrl+C", c, disabled = true;
459 bool NotifySelect(MenuItem selection, Modifiers mods)
465 MenuItem itemEditPaste
467 editMenu, "Paste\tCtrl+V", p;
469 bool NotifySelect(MenuItem selection, Modifiers mods)
475 MenuItem itemEditDelete
477 editMenu, "Delete\tDel", d, disabled = true;
479 bool NotifySelect(MenuItem selection, Modifiers mods)
486 // WHY is this crashing ?
487 /*void OnResize(int width, int height)
489 if(this && nameField)
490 nameField.width = width - 80;
496 // this is crashing in for designer when details = true // can't save the file, always yields a crash
497 /*if(list && created)
500 list.AddField(nameField);
503 list.AddField(typeField);
504 list.AddField(sizeField);
507 if(bits.treeBranches)
515 FileListing listing { path, extensions = extensions };
518 while(listing.Find())
520 if((!bits.foldersOnly && !bits.filesOnly) ||
521 (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
522 (bits.filesOnly && listing.stats.attribs.isFile))
524 FileSystemNode node = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
525 DataRow row = list.AddRow();
527 row.SetData(nameField, node);
530 row.SetData(typeField, node.extension);
531 row.SetData(sizeField, (void *)node.stats.size);
535 list.Sort(nameField, 1);
540 bool isRoot = !strcmp(path, "/");
541 //char startPath[MAX_LOCATION];
542 FileSystemNode parent;
544 FileListing listing { path, extensions = extensions };
547 GetWorkingDir(startPath, sizeof(startPath));
549 strcpy(path, startPath);*/
557 root = FileSystemNode { loaded = true, childrenLoaded = true };
558 AddTreeNode(root, true, false, null);
559 while(listing.Find())
561 int len = strlen(listing.name);
562 char info[MAX_LOCATION];
563 char name[MAX_LOCATION];
564 if(listing.stats.attribs.isDrive &&
565 len > 3 && !strncmp(&listing.name[1], ": [", 3))
567 strncpy(name, listing.name, 2);
569 strncpy(info, &listing.name[4], len - 5);
574 strcpy(name, listing.name);
578 parent = MakeFileSystemNode(listing.stats, name, listing.path, bits.previewPictures, displaySystem);
580 parent.info = CopyString(info);
581 parent.loaded = true;
582 AddTreeNode(parent, !listing.stats.attribs.isDirectory, listing.stats.attribs.isDirectory, root);
583 if(!listing.stats.attribs.isDirectory)
584 parent.childrenLoaded = true;
587 node = FileSystemNode { name = msNetwork, type = network };
588 AddTreeNode(node, false, true, null);
589 node.row.collapsed = true;
594 root = MakeFileSystemNode(FileStats { attribs = FileExists(path)}, path, path, bits.previewPictures, displaySystem);
595 AddTreeNode(root, false, true, null);
601 root.type = computer;
602 root.name = rootName;
605 list.Sort(nameField, 1);
606 list.SelectRow(root.row);
609 void LoadTreeNode(FileSystemNode node)
613 char path[MAX_LOCATION];
616 FileListing listing { path, extensions = extensions };
617 if(node.children.count == 1)
618 DeleteNode(node.children.first);
620 while(listing.Find())
622 if(!listing.stats.attribs.isRemovable && ((!bits.foldersOnly && !bits.filesOnly) ||
623 (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
624 (bits.filesOnly && listing.stats.attribs.isFile)))
626 FileSystemNode child = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
627 AddTreeNode(child, true, false, node);
628 NodeChildLoad(child, node);
632 node.childrenLoaded = true;
634 node.row.SortSubRows(false);
636 else if(!node.childrenLoaded)
638 FileSystemNode child;
639 if(node.children.first)
641 for(child = node.children.first; child; child = child.next)
645 else if(!child.childrenLoaded)
646 NodeChildLoad(child, node);
648 node.childrenLoaded = true;
649 node.row.SortSubRows(false);
654 void NodeChildLoad(FileSystemNode parent, FileSystemNode node)
656 char path[MAX_LOCATION];
657 parent.GetPath(path);
660 FileListing listing { path, extensions = extensions };
661 while(listing.Find())
663 if((!bits.foldersOnly && !bits.filesOnly) ||
664 (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
665 (bits.filesOnly && listing.stats.attribs.isFile))
667 FileSystemNode child = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
668 AddTreeNode(child, true, false, parent);
675 //parent.childrenLoaded = true;
678 void AddTreeNode(FileSystemNode node, bool loaded, bool addLoader, FileSystemNode addTo)
680 DataRow row = (addTo && addTo.row) ? addTo.row.AddRow() : list.AddRow();
684 node.indent = addTo.indent + 1;
685 addTo.children.Add(node);
689 row.SetData(null, node);
691 node.loaded = loaded;
693 //AddTreeNode(FileSystemNode { }, false, false, node); // why would this create a compile error?
694 AddTreeNode(FileSystemNode { type = none }, false, false, node);
697 row.collapsed = true;
698 else if(node.type == folder)
699 node.type = folderOpen;
702 void DeleteNode(FileSystemNode node)
704 FileSystemNode child;
705 for(; (child = node.children.first); )
707 list.DeleteRow(node.row);
714 class ExplorerView : FileSystemBox
717 hasHorzScroll = false;
718 hasVertScroll = false;
720 virtual void Load(FileSystemNode parent);
721 virtual void Refresh();
723 virtual void LaunchNotifyItemSelect(Window master, ExplorerView view, ExplorerFileItem item, ExplorerFileItemArray selectedItems)
725 view.NotifyItemSelect(master, view, item, selectedItems);
728 virtual bool Window::NotifyItemSelect(ExplorerView view, ExplorerFileItem item, ExplorerFileItemArray selectedItems);
729 virtual bool Window::NotifyItemOpen(ExplorerView view, ExplorerFileItem item);
733 master = master, parent = this;
736 hasHorzScroll = true;
737 hasVertScroll = true;
740 fullRowSelect = false;
743 anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
745 bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
747 ExplorerView view = (ExplorerView)listBox.parent;
748 if(listBox.currentRow)
751 ExplorerFileItemArray selectedItems { growingFactor = 16 };
752 for(listRow = listBox.firstRow; listRow; listRow = listRow.next)
754 selectedItems.Add((ExplorerFileItem)listRow.tag);
755 //view.NotifyItemSelect(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
756 view.LaunchNotifyItemSelect(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag, selectedItems);
761 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
763 ExplorerView view = (ExplorerView)listBox.parent;
764 view.NotifyItemOpen(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
768 bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
770 if((SmartKey)key == enter)
772 ExplorerView view = (ExplorerView)listBox.parent;
773 view.NotifyItemOpen(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
786 class ExplorerViewList : ExplorerView
789 FileSystemNode location;
793 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
795 ExplorerViewDetails()
797 list.AddField(nameField);
805 void Load(FileSystemNode location)
807 char path[MAX_LOCATION];
808 this.location = location;
809 location.GetPath(path);
811 FileListing listing { path };
813 ExplorerFileItem item;
818 while(listing.Find())
820 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
824 row.SetData(nameField, item);
826 list.Sort(nameField, 1);
833 class ExplorerViewDetails : ExplorerView
835 list.hasHeader = true;
836 list.moveFields = true;
837 list.resizable = true;
838 list.sortable = true;
840 FileSystemNode location;
844 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
845 DataField typeField { header = "Type", dataType = /-*"String"*-/ "char *", width = 40 };
846 DataField sizeField { header = "Size", dataType = "FileSize", width = 96, alignment = right };
848 ExplorerViewDetails()
850 list.AddField(nameField);
851 list.AddField(typeField);
852 list.AddField(sizeField);
860 void Load(FileSystemNode location)
862 char path[MAX_LOCATION];
863 this.location = location;
864 location.GetPath(path);
866 FileListing listing { path };
868 ExplorerFileItem item;
873 while(listing.Find())
875 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
879 row.SetData(nameField, item);
880 row.SetData(typeField, CopyString(item.extension));
881 row.SetData(sizeField, (uint)listing.stats.size);
883 list.Sort(nameField, 1);
890 class ExplorerViewIcons : ExplorerView
893 FileSystemNode location;
897 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
899 ExplorerViewDetails()
901 list.AddField(nameField);
909 void Load(FileSystemNode location)
911 char path[MAX_LOCATION];
912 this.location = location;
913 location.GetPath(path);
915 FileListing listing { path };
917 ExplorerFileItem item;
922 while(listing.Find())
924 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
928 row.SetData(nameField, item);
930 list.Sort(nameField, 1);
937 class ExplorerViewCards : ExplorerView
940 FileSystemNode location;
944 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
946 ExplorerViewDetails()
948 list.AddField(nameField);
956 void Load(FileSystemNode location)
958 char path[MAX_LOCATION];
959 this.location = location;
960 location.GetPath(path);
962 FileListing listing { path };
964 ExplorerFileItem item;
969 while(listing.Find())
971 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
975 row.SetData(nameField, item);
977 list.Sort(nameField, 1);
984 public class BitmapArray : RedjArray
986 type = class(Bitmap);
989 Bitmap * Add(Bitmap bitmap)
996 Bitmap * AddBefore(uint position, Bitmap bitmap)
999 _[position] = bitmap;
1000 return &_[position];
1005 for(c = 0; c < _count; c++)
1017 class ExplorerViewShowcase : ExplorerView
1019 list.anchor = Anchor { left = 0, top = 0, bottom = 0 };
1020 list.size = Size { w = 200 };
1022 FileSystemNode location;
1026 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 180, editable = true, userData = this };
1029 BitmapArray bitmaps { growingFactor = 16 };
1035 anchor = Anchor { top = 0, right = 0, bottom = 0 };
1037 void OnRedraw(Surface surface)
1039 ExplorerViewShowcase view = (ExplorerViewShowcase)parent;
1042 int wBmp = view.bitmap.width;
1043 int hBmp = view.bitmap.height;
1044 int wWnd = clientSize.w;
1045 int hWnd = clientSize.h;
1047 int wList = view.list.size.w + view.split.size.w;
1049 float scale = Min((float)(wWnd - 10) / wBmp, (float)(hWnd - 10) / hBmp);
1051 int wDraw = (int)(wBmp * scale);
1052 int hDraw = (int)(hBmp * scale);
1055 surface.Filter(view.bitmap, (wWnd - wDraw) / 2, (hWnd - hDraw) / 2, 0, 0, wDraw, hDraw, wBmp, hBmp);
1057 // Until Filter / Stretch works with X
1058 surface.Blit(view.bitmap, (wWnd - wDraw) / 2, (hWnd - hDraw) / 2, 0, 0, wDraw, hDraw);
1063 surface.SetForeground(white);
1064 surface.Area(0, 0, view.clientSize.w - 1, view.clientSize.h - 1);
1078 ExplorerViewDetails()
1080 list.AddField(nameField);
1083 void LaunchNotifyItemSelect(Window master, ExplorerViewShowcase view, ExplorerFileItem item, ExplorerFileItemArray selectedItems)
1086 ExplorerFileItem selItem;
1090 if(item && item.type == pictureFile)
1092 view.bitmap = Bitmap { };
1093 view.bitmap.Load(item.path, null, displaySystem);
1096 view.bitmaps.Clear();
1097 view.bitmaps = BitmapArray { };
1098 for(pos = 0; pos < selectedItems.count; pos++)
1101 selItem = (ExplorerFileItem)selectedItems._[pos];
1102 bitmap.Load(selItem.path, null, displaySystem);
1103 //view.bitmaps.Add(bitmap);
1105 if(item && item.type == pictureFile)
1107 view.bitmap = Bitmap { };
1108 view.bitmap.Load(item.path, null, displaySystem);
1111 view.show.Update(null);
1112 view.NotifyItemSelect(master, view, item, selectedItems);
1120 void Load(FileSystemNode location)
1122 char path[MAX_LOCATION];
1123 this.location = location;
1124 location.GetPath(path);
1126 FileListing listing { path };
1128 ExplorerFileItem item;
1133 while(listing.Find())
1135 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
1137 row = list.AddRow();
1138 row.tag = (int)item;
1139 row.SetData(nameField, item);
1141 list.Sort(nameField, 1);
1148 class ExplorerTree : FileSystemBox
1150 hasHorzScroll = false;
1151 hasVertScroll = false;
1157 DataField nameField { dataType = "FileSystemNode", width = 240, userData = this };
1159 FileSystemNode root;
1160 FileSystemNode selection;
1162 virtual bool Window::NotifyNodeSelect(ExplorerTree tree, FileSystemNode node);
1164 property FileSystemNode node
1170 if(!tree.currentRow)
1172 if(!tree.currentRow.tag)
1174 return (FileSystemNode)tree.currentRow.tag;
1178 void Select(FileSystemNode node)
1182 node.EnsureVisible(false);
1183 tree.SelectRow(node.row);
1187 FileSystemNode Find(const char * name, FileSystemNode parent)
1189 FileSystemNode node;
1190 FileSystemNode start = parent ? parent : root;
1191 if(!start.loaded || !start.childrenLoaded)
1192 LoadTreeNode(start, tree);
1193 for(node = start.children.first; node; node = node.next)
1194 if(node.name && !strcmpi(node.name, name))
1201 master = master, parent = this;
1204 hasHorzScroll = true;
1205 hasVertScroll = true;
1206 fullRowSelect = false;
1208 collapseControl = true;
1209 rootCollapseButton = true;
1211 anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
1213 // WHY is this not working ?
1214 /-*void OnResize(int width, int height)
1216 if(vertScroll.visible)
1217 nameField.width = width - vertScroll.size.w;
1219 nameField.width = width;
1222 bool NotifyCollapse(ListBox listBox, DataRow row, bool collapsed)
1226 FileSystemNode node = (FileSystemNode)row.tag;
1227 FileSystemNode child;
1231 for(child = node.children.last; child; child = node.children.last)
1233 listBox.DeleteRow(child.row);
1237 node.childrenLoaded = false;
1242 if(!node.loaded || !node.childrenLoaded)
1243 LoadTreeNode(node, tree);
1244 for(child = node.children.first; child && child.next; child = child.next);
1246 child.EnsureVisible(false);
1252 bool NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods)
1254 DataRow row = listBox.currentRow;
1257 FileSystemNode node = (FileSystemNode)row.tag;
1263 MenuItem { menu, "Cut\tCtrl+X", t, NotifySelect = null, disabled = false };
1264 MenuItem { menu, "Copy\tCtrl+C", c, NotifySelect = null, disabled = false };
1265 MenuItem { menu, "Paste\tCtrl+V", p, NotifySelect = null, disabled = false /-*!clipboard*-/ };
1266 MenuItem { menu, "Delete\tDel", d, NotifySelect = null, disabled = false };
1267 //MenuDivider { menu };
1271 master = this, menu = menu,
1273 x + clientStart.x + absPosition.x - guiApp.desktop.position.x,
1274 y + clientStart.y + absPosition.y - guiApp.desktop.position.y }
1282 bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
1286 FileSystemNode node = (FileSystemNode)row.tag;
1287 NotifyNodeSelect(listBox.parent.master, this, node);
1293 bool NotifyEditing(ListBox listBox, DataRow row)
1297 FileSystemNode node = (FileSystemNode)row.tag;
1302 bool NotifyEdited(ListBox listBox, DataRow row)
1306 FileSystemNode node = (FileSystemNode)row.tag;
1311 bool NotifyEditDone(ListBox listBox, DataRow row)
1315 FileSystemNode node = (FileSystemNode)row.tag;
1322 Menu editMenu { menu, "Edit", e };
1323 MenuItem itemEditCut
1325 editMenu, "Cut\tCtrl+X", t, disabled = true;
1327 bool NotifySelect(MenuItem selection, Modifiers mods)
1333 MenuItem itemEditCopy
1335 editMenu, "Copy\tCtrl+C", c, disabled = true;
1337 bool NotifySelect(MenuItem selection, Modifiers mods)
1343 MenuItem itemEditPaste
1345 editMenu, "Paste\tCtrl+V", p;
1347 bool NotifySelect(MenuItem selection, Modifiers mods)
1353 MenuItem itemEditDelete
1355 editMenu, "Delete\tDel", d, disabled = true;
1357 bool NotifySelect(MenuItem selection, Modifiers mods)
1364 // WHY is this crashing ?
1365 /-*void OnResize(int width, int height)
1367 if(this && nameField)
1368 nameField.width = width - 80;
1373 tree.AddField(nameField);
1378 FileSystemNode parent;
1379 FileSystemNode node;
1380 FileListing listing { "/" };
1384 root = FileSystemNode { type = computer, loaded = true, childrenLoaded = true };
1386 root.name = rootName;
1390 AddTreeNode(root, true, false, null, tree);
1392 // How can this make sense for linux?
1394 while(listing.Find())
1396 int len = strlen(listing.name);
1397 char info[MAX_LOCATION];
1398 char name[MAX_LOCATION];
1399 if(listing.stats.attribs.isDrive &&
1400 len > 3 && !strncmp(&listing.name[1], ": [", 3))
1402 strncpy(name, listing.name, 2);
1404 strncpy(info, &listing.name[4], len - 5);
1409 strcpy(name, listing.name);
1413 parent = MakeFileSystemNode(listing.stats, name);
1415 parent.info = CopyString(info);
1416 parent.loaded = true;
1417 AddTreeNode(parent, !listing.stats.attribs.isDirectory, listing.stats.attribs.isDirectory, root, tree);
1418 if(!listing.stats.attribs.isDirectory)
1419 parent.childrenLoaded = true;
1422 node = FileSystemNode { name = msNetwork, type = network };
1423 AddTreeNode(node, false, true, null, tree);
1424 node.row.collapsed = true;
1425 tree.Sort(nameField, 1);
1426 tree.SelectRow(root.row);
1431 public class ClipBoardFiles
1445 int size = SelSize();
1448 // Try to allocate memory
1449 ClipBoard clipBoard { };
1450 if(clipBoard.Allocate(size+1))
1452 GetSel(clipBoard.memory, true);
1465 ClipBoard clipBoard { };
1466 if(clipBoard.Load())
1467 PutS(clipBoard.memory);
1478 SetViewToCursor(true);
1484 Private Type DROPFILES
1490 For iCounter = 0 To filelist.ListCount - 1
1491 If filelist.Selected(iCounter) = True Then
1492 strFiles = strFiles & FixPath(filelist.Path) & filelist.List(iCounter) & vbNullChar
1495 'all selected items are now put in strFiles
1497 hGlobal = GlobalAlloc(GHND, Len(DF) + Len(strFiles)) 'put all files to a exclusive number
1498 If hGlobal Then 'if the globalalloc worked
1499 lpGlobal = GlobalLock(hGlobal) 'lock the hGlobal
1500 DF.pFiles = Len(DF) 'set the size of the files
1502 Call CopyMem(ByVal lpGlobal, DF, Len(DF)) 'copy df to the lpglobal
1503 Call CopyMem(ByVal (lpGlobal + Len(DF)), ByVal strFiles, Len(strFiles)) 'copy strfiles to lpglobal
1504 Call GlobalUnlock(hGlobal) 'unlock hglobal again
1506 SetClipboardData CF_HDROP, hGlobal 'put files to the clipboard
1509 bool SaveFile(const char * filePath)
1515 public class FileTreeNodeBSArray : ArrayBinarySorted
1517 type = class(FileSystemNode);
1519 FileSystemNode * const _;
1520 BSloc Add(FileSystemNode item)
1522 BSloc result = Find(item);
1525 Insert(result.pos, 1);
1526 _[result.pos] = item;
1530 BSloc Remove(FileSystemNode item)
1538 public class FileTreeNodeArray : RedjArray
1540 type = class(FileSystemNode);
1542 FileSystemNode * const _;
1543 FileSystemNode * Add(FileSystemNode item)
1550 FileSystemNode * AddBefore(uint position, FileSystemNode item)
1552 Insert(position, 1);
1554 return &_[position];
1560 public class ExplorerFileItem : struct
1571 void OnDisplay(Surface surface, int x, int y, int width, FileSystemBox control, Alignment alignment, DataDisplayFlags displayFlags)
1573 int indentSize = (displayFlags.dropBox) ? 0 : 10;
1576 char label[MAX_FILENAME];
1578 //float scale = Min((float)clientSize.w / (float)bitmap.width, (float)clientSize.h / (float)bitmap.height);
1579 int w = 16; //(int)(bitmap.width * scale);
1580 int h = 16; //(int)(bitmap.height * scale);
1584 icon = control.fileIcons[type].bitmap;
1587 if(type == folder || type == folderOpen)
1588 surface.SetForeground(red); //Color { 170, 170, 0 } // REDJ What is that color?
1591 textOffset = indent * indentSize + (icon ? (icon.width + 6) : 0);
1594 sprintf(label, "%s [%s]", name, info);
1596 strcpy(label, name);
1597 len = strlen(label);
1599 surface.WriteTextDots
1600 (alignment, x + textOffset, y + 2, width - textOffset, label, len);
1601 if(type == pictureFile && control.previewPictures && bitmap)
1604 //surface.Filter(bitmap, (clientSize.w - w) / 2,(clientSize.h - h) / 2, 0,0, w, h, bitmap.width, bitmap.height);
1605 surface.Filter(bitmap, x + indent * indentSize + 2, y, 0, 0, w, h, bitmap.width, bitmap.height);
1607 // Until Filter / Stretch works with X
1608 //surface.Blit(bitmap, (clientSize.w - bitmap.width) / 2,(clientSize.h - bitmap.height) / 2, 0,0, bitmap.width, bitmap.height);
1609 surface.blend = true;
1610 surface.Blit(bitmap, x + indent * indentSize + 2, y,0,0, w, h);
1616 surface.Blit(icon, x + indent * indentSize + 2, y,0,0, icon.width, icon.height);
1619 int OnCompare(ExplorerFileItem b)
1622 if(type == b.type || (type < folder && b.type < folder) || (type >= drive))
1623 result = strcmpi(name, b.name);
1626 if(type == folder && b.type < folder) result = -1;
1627 else if(type < folder && b.type == folder) result = 1;
1632 void OnCopy(ExplorerFileItem newData)
1634 type = newData.type;
1635 indent = newData.indent;
1638 int len = strlen(newData.name) + 1;
1639 name = new char[len];
1640 CopyBytes(name, newData.name, len);
1644 bool OnGetDataFromString(char * string)
1646 int len = strlen(string) + 1;
1647 name = new char[len];
1648 CopyBytes(name, string, len);
1662 char * OnGetString(char * string, void * fieldData, bool * needClass)
1668 public class ExplorerFileItemArray : RedjArray
1670 type = class(ExplorerFileItem);
1672 ExplorerFileItem * const _;
1673 ExplorerFileItem * Add(ExplorerFileItem item)
1680 ExplorerFileItem * AddBefore(uint position, ExplorerFileItem item)
1682 Insert(position, 1);
1684 return &_[position];
1689 for(c = 0; c < _count; c++)
1699 ExplorerFileItem MakeFileItem(const FileAttribs attribs, const char * fileName, const char * filePath, const bool previewPicture, const DisplaySystem displaySystem)
1701 int len = strlen(fileName);
1702 char info[MAX_LOCATION];
1703 char name[MAX_LOCATION];
1704 char extension[MAX_EXTENSION];
1706 ExplorerFileItem item { };
1708 //if(stats.attribs.isFile) // -- should work now
1709 if(attribs.isDirectory)
1713 item.type = (attribs.isDrive) ? drive : folder;
1714 if(attribs.isServer)
1720 if(attribs.isRemote)
1721 item.type = netDrive;
1722 if(attribs.isRemovable)
1724 if(fileName[0] == 'A' || fileName[0] == 'B')
1727 item.type = removable;
1732 GetExtension(fileName, extension);
1733 //strupr(extension);
1736 item.type = _FileType::SelectByExtension(extension);
1739 if(attribs.isDrive &&
1740 len > 3 && !strncmp(&fileName[1], ": [", 3))
1742 strncpy(name, fileName, 2);
1744 strncpy(info, &fileName[4], len - 5);
1749 strcpy(name, fileName);
1753 item.path = CopyString(filePath);
1754 item.name = CopyString(name);
1756 item.info = CopyString(info);
1757 item.extension = CopyString(extension);
1759 if(item.type == pictureFile && previewPicture)
1761 item.bitmap = Bitmap { };
1762 item.bitmap.Load(filePath, null, displaySystem);
1770 public class FileSystemNode : struct
1773 /*//LinkElement<FileSystemNode> link;
1774 FileSystemNode parent;
1776 FileSystemNodeType type;
1780 FileSystemNode prev, next;
1782 bool loaded, childrenLoaded;
1791 FileSystemNode parent;
1797 void GetPath(String outputPath)
1802 strcpy(outputPath, name);
1803 for(up = parent; up; up = up.parent)
1805 char temp[MAX_LOCATION];
1806 strcpy(temp, up.name);
1807 PathCat(temp, outputPath);
1808 strcpy(outputPath, temp);
1813 strcpy(outputPath, "/");
1815 strcpy(outputPath, name);
1820 bool IsChildOf(FileSystemNode node)
1822 FileSystemNode test;
1823 for(test = parent; test; test = test.parent)
1829 void DuplicateChildren(bool recursive, bool forceExpanded, FileSystemNode addTo, FileSystemBox fsb)
1833 FileSystemNode child;
1835 for(child = children.first; child; child = child.next)
1837 FileSystemNode copy { };
1838 copy.name = CopyString(child.name);
1839 copy.type = child.type;
1840 fsb.AddTreeNode(copy, child.loaded, false, addTo);
1842 copy.row.collapsed = false;
1844 child.DuplicateChildren(recursive, forceExpanded, copy, fsb);
1849 void EnsureVisible(bool expand)
1852 parent.EnsureVisible(true);
1854 row.collapsed = false;
1855 // TODO: row.EnsureVisible(); // making the row visible by scrolling
1865 FileSystemNode child;
1866 for(; (child = children.first); )
1869 children.Delete(child);
1880 parent.children.Delete(this);
1883 void OnDisplay(Surface surface, int x, int y, int width, FileSystemBox fsb, Alignment alignment, DataDisplayFlags displayFlags)
1885 //int indentSize = (displayFlags.dropBox) ? 0 : 10;
1891 char label[MAX_FILENAME];
1898 icon = fsb.fileIcons[type].bitmap;
1899 //xStart = indent * indent + x + (icon ? (icon.width + 5) : 0);
1900 xStart = x + (icon ? (icon.width + 5) : 0);
1906 sprintf(label, "%s [%s]", name, info);
1908 strcpy(label, name);
1909 len = strlen(label);
1913 if(type == folder || type == folderOpen)
1914 surface.SetForeground(yellow);
1918 //textOffset = indent * indentSize + (icon ? (icon.width + 4) : 0);
1920 surface.TextOpacity(false);
1921 surface.TextExtent(label, len, &w, &h);
1924 // Draw the current row stipple
1925 if(displayFlags.selected)
1926 //surface.Area(xStart - 1, y, xStart - 1, y + h - 1);
1927 //surface.Area(xStart + w - 1, y, xStart + w + 1, y + h - 1);
1928 surface.Area(xStart - 3, y, xStart + w + 1, y + h - 1);
1930 //surface.WriteTextDots(alignment, x + textOffset, y + 2, width - textOffset, name, strlen(name));
1931 surface.WriteTextDots(alignment, xStart, y + 2, width, label, len);
1933 //if(!guiApp.textMode) -- how to do this in a dll?
1935 if(displayFlags.current)
1937 if(displayFlags.active)
1939 surface.LineStipple(0x5555);
1940 if(displayFlags.selected)
1941 surface.SetForeground(0xFFFFFF80);
1943 surface.SetForeground(black);
1947 surface.SetForeground(selectionColor);
1949 surface.Rectangle(xStart - 3, y, xStart + w + 1, y + h - 1);
1950 surface.LineStipple(0);
1958 if(type == pictureFile && fsb.previewPictures && bitmap)
1960 surface.SetForeground(white);
1961 surface.blend = true;
1963 //surface.Filter(bitmap, (clientSize.w - w) / 2,(clientSize.h - h) / 2, 0,0, w, h, bitmap.width, bitmap.height);
1964 //surface.Filter(bitmap, x + indent/* * indentSize*/ + 2, y, 0, 0, w, h, bitmap.width, bitmap.height);
1965 surface.Filter(bitmap, x,y,0,0, w, h, bitmap.width, bitmap.height);
1967 // Until Filter / Stretch works with X
1968 //surface.Blit(bitmap, (clientSize.w - bitmap.width) / 2,(clientSize.h - bitmap.height) / 2, 0,0, bitmap.width, bitmap.height);
1969 // surface.blend = true;
1970 //surface.Blit(bitmap, x + indent/* * indentSize*/ + 2, y,0,0, w, h);
1971 //surface.Blit(bitmap, x,y,0,0, bitmap.width, bitmap.height);
1978 //surface.blend = true;
1979 //surface.alphaWrite = blend;
1980 surface.SetForeground(white);
1981 //surface.Blit(icon, x + indent * indentSize, y,0,0, icon.width, icon.height);
1982 surface.Blit(icon, x,y,0,0, icon.width, icon.height);
1987 int OnCompare(FileSystemNode b)
1990 FileSystemNode a = this;
1991 if(a.type == b.type || (a.type < folder && b.type < folder) || (a.type >= drive))
1992 result = strcmpi(a.name, b.name);
1995 if(a.type == folder && b.type < folder) result = -1;
1996 else if(a.type < folder && b.type == folder) result = 1;
2002 /*int OnCompare(FileSystemNode b)
2005 FileSystemNode a = this;
2006 if(a.parent < b.parent) result = -1;
2007 else if(a.parent > b.parent) result = 1;
2009 result = fstrcmp(a.name, b.name);
2013 char * OnGetString(char * tempString, FileSystemToolWindow fileSysToolWnd, bool * needClass)
2015 return name ? name : "";
2019 /*FileSystemNode MakeFileSystemNode(const FileStats stats, const char * name)
2021 FileSystemNode node { stats = stats };
2022 node.name = CopyString(name);
2025 if(stats.attribs.isDirectory)
2027 node.type = (stats.attribs.isDrive) ? drive : folder;
2028 if(stats.attribs.isServer) node.type = server;
2029 if(stats.attribs.isShare) node.type = share;
2030 if(stats.attribs.isCDROM) node.type = cdrom;
2031 if(stats.attribs.isRemote) node.type = netDrive;
2032 if(stats.attribs.isRemovable)
2034 if(name[0] == 'A' || name[0] == 'B')
2037 node.type = removable;
2042 char extension[MAX_EXTENSION];
2043 GetExtension(node.name, extension);
2044 node.type = _FileType::SelectByExtension(extension);
2048 static FileSystemNode MakeFileSystemNode(const FileStats stats,
2049 const char * fileName, const char * filePath,
2050 const bool previewPicture, const DisplaySystem displaySystem)
2052 int len = strlen(fileName);
2053 char info[MAX_LOCATION];
2054 char name[MAX_LOCATION];
2055 char extension[MAX_EXTENSION];
2057 FileSystemNode node { stats = stats };
2059 //if(stats.attribs.isFile) // TODO fix this in ecere
2060 if(stats.attribs.isDirectory)
2062 extension[0] = '\0';
2064 node.type = (stats.attribs.isDrive) ? drive : folder;
2065 if(stats.attribs.isServer) node.type = server;
2066 if(stats.attribs.isShare) node.type = share;
2067 if(stats.attribs.isCDROM) node.type = cdrom;
2068 if(stats.attribs.isRemote) node.type = netDrive;
2069 if(stats.attribs.isRemovable)
2071 if(fileName[0] == 'A' || fileName[0] == 'B')
2074 node.type = removable;
2079 GetExtension(fileName, extension);
2082 node.type = _FileType::SelectByExtension(extension);
2085 if(stats.attribs.isDrive &&
2086 len > 3 && !strncmp(&fileName[1], ": [", 3))
2088 strncpy(name, fileName, 2);
2090 strncpy(info, &fileName[4], len - 5);
2095 strcpy(name, fileName);
2099 node.path = CopyString(filePath);
2100 node.name = CopyString(name);
2102 node.info = CopyString(info);
2103 node.extension = CopyString(extension);
2105 if(node.type == pictureFile && previewPicture)
2107 node.bitmap = Bitmap { alphaBlend = true };
2108 node.bitmap.Load(filePath, null, displaySystem);