4 static char * rootName = "Entire Computer";
5 static char * msNetwork = "Microsoft Windows Network";
7 static char * rootName = "File System";
11 define guiApp = (GuiApplication)((__thisModule).application);
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, autoLoad: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; } };
206 property bool autoLoad { set { bits.autoLoad = value; } get { return bits.autoLoad; } };
208 property FileSystemNode node
216 if(!list.currentRow.tag)
218 return (FileSystemNode)list.currentRow.tag;
224 void Select(FileSystemNode node)
228 node.EnsureVisible(false);
229 list.SelectRow(node.row);
233 FileSystemNode SelectLocation(char * location)
237 char step[MAX_LOCATION];
239 //StringArray steps { growingFactor = 4 };
240 Array<String> steps { };
241 FileSystemNode result = null;
242 FileSystemNode node = null;
244 temp = CopyString(location);
247 GetLastDirectory(temp, step);
248 StripLastDirectory(temp, temp);
249 steps.Add(CopyString(step));
252 for(c = steps.count - 1; c >= 0; c--)
255 node = Find(steps[c], node);
273 FileSystemNode Find(const char * name, FileSystemNode parent)
275 FileSystemNode node = null;
276 FileSystemNode result = null;
277 if(!parent/* && !strcmp(name, "/")*/)
280 for(row = list.firstRow; row; row = row.next)
282 node = (FileSystemNode)row.tag;
283 if(node.name && !fstrcmp(node.name, name))
292 FileSystemNode start = parent ? parent : root;
293 if(!start.loaded || !start.childrenLoaded)
295 for(node = start.children.first; node; node = node.next)
296 if(node.name && !fstrcmp(node.name, name))
310 FileSystemBoxBits bits;
315 BitmapResource fileIcons[_FileType];
319 char wd[MAX_LOCATION];
320 GetWorkingDir(wd, sizeof(wd));
324 list.AddField(nameField);
325 bits.autoLoad = true;
335 for(c = 0; c < _FileType::enumSize; c++)
337 fileIcons[c] = BitmapResource { fileIconNames[c], alphaBlend = true };
338 AddResource(fileIcons[c]);
342 DataField nameField { dataType = "FileSystemNode", width = 240, userData = this, freeData = false };
343 DataField typeField { header = "Type", dataType = /*"String"*/ "char *", width = 40, freeData = false };
344 DataField sizeField { header = "Size", dataType = "FileSize", width = 96, alignment = right, freeData = false };
358 hasHorzScroll = true;
359 hasVertScroll = true;
360 fullRowSelect = false;
363 anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
365 // WHY is this not working ?
366 /*void OnResize(int width, int height)
368 if(vertScroll.visible)
369 nameField.width = width - vertScroll.size.w;
371 nameField.width = width;
374 bool NotifyCollapse(ListBox listBox, DataRow row, bool collapsed)
378 FileSystemNode node = (FileSystemNode)row.tag;
379 FileSystemNode child;
383 for(child = node.children.last; child; child = node.children.last)
385 listBox.DeleteRow(child.row);
389 node.childrenLoaded = false;
394 if(!node.loaded || !node.childrenLoaded)
397 //list.Sort(nameField, 1);
400 for(child = node.children.first; child && child.next; child = child.next);
402 child.EnsureVisible(false);
408 bool NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods)
410 DataRow row = listBox.currentRow;
413 FileSystemNode node = (FileSystemNode)row.tag;
419 MenuItem { menu, "Cut\tCtrl+X", t, NotifySelect = null, disabled = false };
420 MenuItem { menu, "Copy\tCtrl+C", c, NotifySelect = null, disabled = false };
421 MenuItem { menu, "Paste\tCtrl+V", p, NotifySelect = null, disabled = false /*!clipboard*/ };
422 MenuItem { menu, "Delete\tDel", d, NotifySelect = null, disabled = false };
423 //MenuDivider { menu };
427 master = this, menu = menu,
429 x + clientStart.x + absPosition.x - guiApp.desktop.position.x,
430 y + clientStart.y + absPosition.y - guiApp.desktop.position.y }
438 bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
442 FileSystemNode node = (FileSystemNode)row.tag;
443 NotifyNodeSelect(listBox.parent.master, this, node);
449 bool NotifyEditing(ListBox listBox, DataRow row)
453 FileSystemNode node = (FileSystemNode)row.tag;
458 bool NotifyEdited(ListBox listBox, DataRow row)
462 FileSystemNode node = (FileSystemNode)row.tag;
467 bool NotifyEditDone(ListBox listBox, DataRow row)
471 FileSystemNode node = (FileSystemNode)row.tag;
476 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
478 bool result = !(selection && selection.type.isFolder && bits.navigateFolders);
483 bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
486 if((SmartKey)key == enter)
497 if(selection && selection.type.isFolder && bits.navigateFolders)
498 property::path = selection.path;
499 result = NotifyNodeOpen(this.master, this, selection);
504 Menu editMenu { menu, "Edit", e };
507 editMenu, "Cut\tCtrl+X", t, disabled = true;
509 bool NotifySelect(MenuItem selection, Modifiers mods)
515 MenuItem itemEditCopy
517 editMenu, "Copy\tCtrl+C", c, disabled = true;
519 bool NotifySelect(MenuItem selection, Modifiers mods)
525 MenuItem itemEditPaste
527 editMenu, "Paste\tCtrl+V", p;
529 bool NotifySelect(MenuItem selection, Modifiers mods)
535 MenuItem itemEditDelete
537 editMenu, "Delete\tDel", d, disabled = true;
539 bool NotifySelect(MenuItem selection, Modifiers mods)
546 // WHY is this crashing ?
547 /*void OnResize(int width, int height)
549 if(this && nameField)
550 nameField.width = width - 80;
556 // this is crashing in for designer when details = true // can't save the file, always yields a crash
557 /*if(list && created)
560 list.AddField(nameField);
563 list.AddField(typeField);
564 list.AddField(sizeField);
567 if(bits.treeBranches)
575 FileListing listing { path, extensions = extensions };
578 while(listing.Find())
580 if((!bits.foldersOnly && !bits.filesOnly) ||
581 (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
582 (bits.filesOnly && listing.stats.attribs.isFile))
584 FileSystemNode node = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
585 DataRow row = list.AddRow();
587 row.SetData(nameField, node);
590 row.SetData(typeField, node.extension);
591 row.SetData(sizeField, (void *)node.stats.size);
595 list.Sort(nameField, 1);
600 bool isRoot = !strcmp(path, "/");
601 //char startPath[MAX_LOCATION];
602 FileSystemNode parent;
604 FileListing listing { path, extensions = extensions };
607 GetWorkingDir(startPath, sizeof(startPath));
609 strcpy(path, startPath);*/
617 root = FileSystemNode { loaded = true, childrenLoaded = true };
618 AddTreeNode(root, true, false, null);
619 while(listing.Find())
621 int len = strlen(listing.name);
622 char info[MAX_LOCATION];
623 char name[MAX_LOCATION];
624 if(listing.stats.attribs.isDrive &&
625 len > 3 && !strncmp(&listing.name[1], ": [", 3))
627 strncpy(name, listing.name, 2);
629 strncpy(info, &listing.name[4], len - 5);
634 strcpy(name, listing.name);
638 parent = MakeFileSystemNode(listing.stats, name, listing.path, bits.previewPictures, displaySystem);
640 parent.info = CopyString(info);
641 parent.loaded = true;
642 AddTreeNode(parent, !listing.stats.attribs.isDirectory, listing.stats.attribs.isDirectory, root);
643 if(!listing.stats.attribs.isDirectory)
644 parent.childrenLoaded = true;
647 node = FileSystemNode { name = msNetwork, type = network };
648 AddTreeNode(node, false, true, null);
649 node.row.collapsed = true;
654 root = MakeFileSystemNode(FileStats { attribs = FileExists(path)}, path, path, bits.previewPictures, displaySystem);
655 AddTreeNode(root, false, true, null);
661 root.type = computer;
662 root.label = rootName;
665 list.Sort(nameField, 1);
666 list.SelectRow(root.row);
669 void LoadTreeNode(FileSystemNode node)
673 char path[MAX_LOCATION];
676 FileListing listing { path, extensions = extensions };
677 if(node.children.count == 1)
678 DeleteNode(node.children.first);
680 while(listing.Find())
682 if(!listing.stats.attribs.isRemovable && ((!bits.foldersOnly && !bits.filesOnly) ||
683 (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
684 (bits.filesOnly && listing.stats.attribs.isFile)))
686 FileSystemNode child = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
687 AddTreeNode(child, true, false, node);
688 NodeChildLoad(child, node);
692 node.childrenLoaded = true;
694 node.row.SortSubRows(false);
696 else if(!node.childrenLoaded)
698 FileSystemNode child;
699 if(node.children.first)
701 for(child = node.children.first; child; child = child.next)
705 else if(!child.childrenLoaded)
706 NodeChildLoad(child, node);
708 node.childrenLoaded = true;
709 node.row.SortSubRows(false);
714 void NodeChildLoad(FileSystemNode parent, FileSystemNode node)
716 char path[MAX_LOCATION];
717 parent.GetPath(path);
720 FileListing listing { path, extensions = extensions };
721 while(listing.Find())
723 if((!bits.foldersOnly && !bits.filesOnly) ||
724 (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
725 (bits.filesOnly && listing.stats.attribs.isFile))
727 FileSystemNode child = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
728 AddTreeNode(child, listing.stats.attribs.isFile, !listing.stats.attribs.isFile, parent);
735 parent.childrenLoaded = true;
738 void AddTreeNode(FileSystemNode node, bool loaded, bool addLoader, FileSystemNode addTo)
740 DataRow row = (addTo && addTo.row) ? addTo.row.AddRow() : list.AddRow();
744 node.indent = addTo.indent + 1;
745 addTo.children.Add(node);
749 row.SetData(null, node);
751 node.loaded = loaded;
753 //AddTreeNode(FileSystemNode { }, false, false, node); // why would this create a compile error?
754 AddTreeNode(FileSystemNode { type = none }, false, false, node);
757 row.collapsed = true;
758 else if(node.type == folder)
759 node.type = folderOpen;
762 void DeleteNode(FileSystemNode node)
764 FileSystemNode child;
765 for(; (child = node.children.first); )
767 list.DeleteRow(node.row);
774 class ExplorerView : FileSystemBox
777 hasHorzScroll = false;
778 hasVertScroll = false;
780 virtual void Load(FileSystemNode parent);
781 virtual void Refresh();
783 virtual void LaunchNotifyItemSelect(Window master, ExplorerView view, ExplorerFileItem item, ExplorerFileItemArray selectedItems)
785 view.NotifyItemSelect(master, view, item, selectedItems);
788 virtual bool Window::NotifyItemSelect(ExplorerView view, ExplorerFileItem item, ExplorerFileItemArray selectedItems);
789 virtual bool Window::NotifyItemOpen(ExplorerView view, ExplorerFileItem item);
793 master = master, parent = this;
796 hasHorzScroll = true;
797 hasVertScroll = true;
800 fullRowSelect = false;
803 anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
805 bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
807 ExplorerView view = (ExplorerView)listBox.parent;
808 if(listBox.currentRow)
811 ExplorerFileItemArray selectedItems { growingFactor = 16 };
812 for(listRow = listBox.firstRow; listRow; listRow = listRow.next)
814 selectedItems.Add((ExplorerFileItem)listRow.tag);
815 //view.NotifyItemSelect(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
816 view.LaunchNotifyItemSelect(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag, selectedItems);
821 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
823 ExplorerView view = (ExplorerView)listBox.parent;
824 view.NotifyItemOpen(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
828 bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
830 if((SmartKey)key == enter)
832 ExplorerView view = (ExplorerView)listBox.parent;
833 view.NotifyItemOpen(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
846 class ExplorerViewList : ExplorerView
849 FileSystemNode location;
853 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
855 ExplorerViewDetails()
857 list.AddField(nameField);
865 void Load(FileSystemNode location)
867 char path[MAX_LOCATION];
868 this.location = location;
869 location.GetPath(path);
871 FileListing listing { path };
873 ExplorerFileItem item;
878 while(listing.Find())
880 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
884 row.SetData(nameField, item);
886 list.Sort(nameField, 1);
893 class ExplorerViewDetails : ExplorerView
895 list.hasHeader = true;
896 list.moveFields = true;
897 list.resizable = true;
898 list.sortable = true;
900 FileSystemNode location;
904 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
905 DataField typeField { header = "Type", dataType = /-*"String"*-/ "char *", width = 40 };
906 DataField sizeField { header = "Size", dataType = "FileSize", width = 96, alignment = right };
908 ExplorerViewDetails()
910 list.AddField(nameField);
911 list.AddField(typeField);
912 list.AddField(sizeField);
920 void Load(FileSystemNode location)
922 char path[MAX_LOCATION];
923 this.location = location;
924 location.GetPath(path);
926 FileListing listing { path };
928 ExplorerFileItem item;
933 while(listing.Find())
935 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
939 row.SetData(nameField, item);
940 row.SetData(typeField, CopyString(item.extension));
941 row.SetData(sizeField, (uint)listing.stats.size);
943 list.Sort(nameField, 1);
950 class ExplorerViewIcons : ExplorerView
953 FileSystemNode location;
957 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
959 ExplorerViewDetails()
961 list.AddField(nameField);
969 void Load(FileSystemNode location)
971 char path[MAX_LOCATION];
972 this.location = location;
973 location.GetPath(path);
975 FileListing listing { path };
977 ExplorerFileItem item;
982 while(listing.Find())
984 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
988 row.SetData(nameField, item);
990 list.Sort(nameField, 1);
997 class ExplorerViewCards : ExplorerView
1000 FileSystemNode location;
1004 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
1006 ExplorerViewDetails()
1008 list.AddField(nameField);
1016 void Load(FileSystemNode location)
1018 char path[MAX_LOCATION];
1019 this.location = location;
1020 location.GetPath(path);
1022 FileListing listing { path };
1024 ExplorerFileItem item;
1029 while(listing.Find())
1031 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
1033 row = list.AddRow();
1034 row.tag = (int)item;
1035 row.SetData(nameField, item);
1037 list.Sort(nameField, 1);
1044 public class BitmapArray : RedjArray
1046 type = class(Bitmap);
1049 Bitmap * Add(Bitmap bitmap)
1056 Bitmap * AddBefore(uint position, Bitmap bitmap)
1058 Insert(position, 1);
1059 _[position] = bitmap;
1060 return &_[position];
1065 for(c = 0; c < _count; c++)
1077 class ExplorerViewShowcase : ExplorerView
1079 list.anchor = Anchor { left = 0, top = 0, bottom = 0 };
1080 list.size = Size { w = 200 };
1082 FileSystemNode location;
1086 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 180, editable = true, userData = this };
1089 BitmapArray bitmaps { growingFactor = 16 };
1095 anchor = Anchor { top = 0, right = 0, bottom = 0 };
1097 void OnRedraw(Surface surface)
1099 ExplorerViewShowcase view = (ExplorerViewShowcase)parent;
1102 int wBmp = view.bitmap.width;
1103 int hBmp = view.bitmap.height;
1104 int wWnd = clientSize.w;
1105 int hWnd = clientSize.h;
1107 int wList = view.list.size.w + view.split.size.w;
1109 float scale = Min((float)(wWnd - 10) / wBmp, (float)(hWnd - 10) / hBmp);
1111 int wDraw = (int)(wBmp * scale);
1112 int hDraw = (int)(hBmp * scale);
1115 surface.Filter(view.bitmap, (wWnd - wDraw) / 2, (hWnd - hDraw) / 2, 0, 0, wDraw, hDraw, wBmp, hBmp);
1117 // Until Filter / Stretch works with X
1118 surface.Blit(view.bitmap, (wWnd - wDraw) / 2, (hWnd - hDraw) / 2, 0, 0, wDraw, hDraw);
1123 surface.SetForeground(white);
1124 surface.Area(0, 0, view.clientSize.w - 1, view.clientSize.h - 1);
1138 ExplorerViewDetails()
1140 list.AddField(nameField);
1143 void LaunchNotifyItemSelect(Window master, ExplorerViewShowcase view, ExplorerFileItem item, ExplorerFileItemArray selectedItems)
1146 ExplorerFileItem selItem;
1150 if(item && item.type == pictureFile)
1152 view.bitmap = Bitmap { };
1153 view.bitmap.Load(item.path, null, displaySystem);
1156 view.bitmaps.Clear();
1157 view.bitmaps = BitmapArray { };
1158 for(pos = 0; pos < selectedItems.count; pos++)
1161 selItem = (ExplorerFileItem)selectedItems._[pos];
1162 bitmap.Load(selItem.path, null, displaySystem);
1163 //view.bitmaps.Add(bitmap);
1165 if(item && item.type == pictureFile)
1167 view.bitmap = Bitmap { };
1168 view.bitmap.Load(item.path, null, displaySystem);
1171 view.show.Update(null);
1172 view.NotifyItemSelect(master, view, item, selectedItems);
1180 void Load(FileSystemNode location)
1182 char path[MAX_LOCATION];
1183 this.location = location;
1184 location.GetPath(path);
1186 FileListing listing { path };
1188 ExplorerFileItem item;
1193 while(listing.Find())
1195 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
1197 row = list.AddRow();
1198 row.tag = (int)item;
1199 row.SetData(nameField, item);
1201 list.Sort(nameField, 1);
1208 class ExplorerTree : FileSystemBox
1210 hasHorzScroll = false;
1211 hasVertScroll = false;
1217 DataField nameField { dataType = "FileSystemNode", width = 240, userData = this };
1219 FileSystemNode root;
1220 FileSystemNode selection;
1222 virtual bool Window::NotifyNodeSelect(ExplorerTree tree, FileSystemNode node);
1224 property FileSystemNode node
1230 if(!tree.currentRow)
1232 if(!tree.currentRow.tag)
1234 return (FileSystemNode)tree.currentRow.tag;
1238 void Select(FileSystemNode node)
1242 node.EnsureVisible(false);
1243 tree.SelectRow(node.row);
1247 FileSystemNode Find(const char * name, FileSystemNode parent)
1249 FileSystemNode node;
1250 FileSystemNode start = parent ? parent : root;
1251 if(!start.loaded || !start.childrenLoaded)
1252 LoadTreeNode(start, tree);
1253 for(node = start.children.first; node; node = node.next)
1254 if(node.name && !strcmpi(node.name, name))
1261 master = master, parent = this;
1264 hasHorzScroll = true;
1265 hasVertScroll = true;
1266 fullRowSelect = false;
1268 collapseControl = true;
1269 rootCollapseButton = true;
1271 anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
1273 // WHY is this not working ?
1274 /-*void OnResize(int width, int height)
1276 if(vertScroll.visible)
1277 nameField.width = width - vertScroll.size.w;
1279 nameField.width = width;
1282 bool NotifyCollapse(ListBox listBox, DataRow row, bool collapsed)
1286 FileSystemNode node = (FileSystemNode)row.tag;
1287 FileSystemNode child;
1291 for(child = node.children.last; child; child = node.children.last)
1293 listBox.DeleteRow(child.row);
1297 node.childrenLoaded = false;
1302 if(!node.loaded || !node.childrenLoaded)
1303 LoadTreeNode(node, tree);
1304 for(child = node.children.first; child && child.next; child = child.next);
1306 child.EnsureVisible(false);
1312 bool NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods)
1314 DataRow row = listBox.currentRow;
1317 FileSystemNode node = (FileSystemNode)row.tag;
1323 MenuItem { menu, "Cut\tCtrl+X", t, NotifySelect = null, disabled = false };
1324 MenuItem { menu, "Copy\tCtrl+C", c, NotifySelect = null, disabled = false };
1325 MenuItem { menu, "Paste\tCtrl+V", p, NotifySelect = null, disabled = false /-*!clipboard*-/ };
1326 MenuItem { menu, "Delete\tDel", d, NotifySelect = null, disabled = false };
1327 //MenuDivider { menu };
1331 master = this, menu = menu,
1333 x + clientStart.x + absPosition.x - guiApp.desktop.position.x,
1334 y + clientStart.y + absPosition.y - guiApp.desktop.position.y }
1342 bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
1346 FileSystemNode node = (FileSystemNode)row.tag;
1347 NotifyNodeSelect(listBox.parent.master, this, node);
1353 bool NotifyEditing(ListBox listBox, DataRow row)
1357 FileSystemNode node = (FileSystemNode)row.tag;
1362 bool NotifyEdited(ListBox listBox, DataRow row)
1366 FileSystemNode node = (FileSystemNode)row.tag;
1371 bool NotifyEditDone(ListBox listBox, DataRow row)
1375 FileSystemNode node = (FileSystemNode)row.tag;
1382 Menu editMenu { menu, "Edit", e };
1383 MenuItem itemEditCut
1385 editMenu, "Cut\tCtrl+X", t, disabled = true;
1387 bool NotifySelect(MenuItem selection, Modifiers mods)
1393 MenuItem itemEditCopy
1395 editMenu, "Copy\tCtrl+C", c, disabled = true;
1397 bool NotifySelect(MenuItem selection, Modifiers mods)
1403 MenuItem itemEditPaste
1405 editMenu, "Paste\tCtrl+V", p;
1407 bool NotifySelect(MenuItem selection, Modifiers mods)
1413 MenuItem itemEditDelete
1415 editMenu, "Delete\tDel", d, disabled = true;
1417 bool NotifySelect(MenuItem selection, Modifiers mods)
1424 // WHY is this crashing ?
1425 /-*void OnResize(int width, int height)
1427 if(this && nameField)
1428 nameField.width = width - 80;
1433 tree.AddField(nameField);
1438 FileSystemNode parent;
1439 FileSystemNode node;
1440 FileListing listing { "/" };
1444 root = FileSystemNode { type = computer, loaded = true, childrenLoaded = true };
1446 root.name = rootName;
1450 AddTreeNode(root, true, false, null, tree);
1452 // How can this make sense for linux?
1454 while(listing.Find())
1456 int len = strlen(listing.name);
1457 char info[MAX_LOCATION];
1458 char name[MAX_LOCATION];
1459 if(listing.stats.attribs.isDrive &&
1460 len > 3 && !strncmp(&listing.name[1], ": [", 3))
1462 strncpy(name, listing.name, 2);
1464 strncpy(info, &listing.name[4], len - 5);
1469 strcpy(name, listing.name);
1473 parent = MakeFileSystemNode(listing.stats, name);
1475 parent.info = CopyString(info);
1476 parent.loaded = true;
1477 AddTreeNode(parent, !listing.stats.attribs.isDirectory, listing.stats.attribs.isDirectory, root, tree);
1478 if(!listing.stats.attribs.isDirectory)
1479 parent.childrenLoaded = true;
1482 node = FileSystemNode { name = msNetwork, type = network };
1483 AddTreeNode(node, false, true, null, tree);
1484 node.row.collapsed = true;
1485 tree.Sort(nameField, 1);
1486 tree.SelectRow(root.row);
1491 public class ClipBoardFiles
1505 int size = SelSize();
1508 // Try to allocate memory
1509 ClipBoard clipBoard { };
1510 if(clipBoard.Allocate(size+1))
1512 GetSel(clipBoard.memory, true);
1525 ClipBoard clipBoard { };
1526 if(clipBoard.Load())
1527 PutS(clipBoard.memory);
1538 SetViewToCursor(true);
1544 Private Type DROPFILES
1550 For iCounter = 0 To filelist.ListCount - 1
1551 If filelist.Selected(iCounter) = True Then
1552 strFiles = strFiles & FixPath(filelist.Path) & filelist.List(iCounter) & vbNullChar
1555 'all selected items are now put in strFiles
1557 hGlobal = GlobalAlloc(GHND, Len(DF) + Len(strFiles)) 'put all files to a exclusive number
1558 If hGlobal Then 'if the globalalloc worked
1559 lpGlobal = GlobalLock(hGlobal) 'lock the hGlobal
1560 DF.pFiles = Len(DF) 'set the size of the files
1562 Call CopyMem(ByVal lpGlobal, DF, Len(DF)) 'copy df to the lpglobal
1563 Call CopyMem(ByVal (lpGlobal + Len(DF)), ByVal strFiles, Len(strFiles)) 'copy strfiles to lpglobal
1564 Call GlobalUnlock(hGlobal) 'unlock hglobal again
1566 SetClipboardData CF_HDROP, hGlobal 'put files to the clipboard
1569 bool SaveFile(const char * filePath)
1575 public class FileTreeNodeBSArray : ArrayBinarySorted
1577 type = class(FileSystemNode);
1579 FileSystemNode * const _;
1580 BSloc Add(FileSystemNode item)
1582 BSloc result = Find(item);
1585 Insert(result.pos, 1);
1586 _[result.pos] = item;
1590 BSloc Remove(FileSystemNode item)
1598 public class FileTreeNodeArray : RedjArray
1600 type = class(FileSystemNode);
1602 FileSystemNode * const _;
1603 FileSystemNode * Add(FileSystemNode item)
1610 FileSystemNode * AddBefore(uint position, FileSystemNode item)
1612 Insert(position, 1);
1614 return &_[position];
1620 public class ExplorerFileItem : struct
1631 void OnDisplay(Surface surface, int x, int y, int width, FileSystemBox control, Alignment alignment, DataDisplayFlags displayFlags)
1633 int indentSize = (displayFlags.dropBox) ? 0 : 10;
1636 char label[MAX_FILENAME];
1638 //float scale = Min((float)clientSize.w / (float)bitmap.width, (float)clientSize.h / (float)bitmap.height);
1639 int w = 16; //(int)(bitmap.width * scale);
1640 int h = 16; //(int)(bitmap.height * scale);
1644 icon = control.fileIcons[type].bitmap;
1647 if(type == folder || type == folderOpen)
1648 surface.SetForeground(red); //Color { 170, 170, 0 } // REDJ What is that color?
1651 textOffset = indent * indentSize + (icon ? (icon.width + 6) : 0);
1654 sprintf(label, "%s [%s]", name, info);
1656 strcpy(label, name);
1657 len = strlen(label);
1659 surface.WriteTextDots
1660 (alignment, x + textOffset, y + 2, width - textOffset, label, len);
1661 if(type == pictureFile && control.previewPictures && bitmap)
1664 //surface.Filter(bitmap, (clientSize.w - w) / 2,(clientSize.h - h) / 2, 0,0, w, h, bitmap.width, bitmap.height);
1665 surface.Filter(bitmap, x + indent * indentSize + 2, y, 0, 0, w, h, bitmap.width, bitmap.height);
1667 // Until Filter / Stretch works with X
1668 //surface.Blit(bitmap, (clientSize.w - bitmap.width) / 2,(clientSize.h - bitmap.height) / 2, 0,0, bitmap.width, bitmap.height);
1669 surface.blend = true;
1670 surface.Blit(bitmap, x + indent * indentSize + 2, y,0,0, w, h);
1676 surface.Blit(icon, x + indent * indentSize + 2, y,0,0, icon.width, icon.height);
1679 int OnCompare(ExplorerFileItem b)
1682 if(type == b.type || (type < folder && b.type < folder) || (type >= drive))
1683 result = strcmpi(name, b.name);
1686 if(type == folder && b.type < folder) result = -1;
1687 else if(type < folder && b.type == folder) result = 1;
1692 void OnCopy(ExplorerFileItem newData)
1694 type = newData.type;
1695 indent = newData.indent;
1698 int len = strlen(newData.name) + 1;
1699 name = new char[len];
1700 CopyBytes(name, newData.name, len);
1704 bool OnGetDataFromString(char * string)
1706 int len = strlen(string) + 1;
1707 name = new char[len];
1708 CopyBytes(name, string, len);
1722 char * OnGetString(char * string, void * fieldData, bool * needClass)
1728 public class ExplorerFileItemArray : RedjArray
1730 type = class(ExplorerFileItem);
1732 ExplorerFileItem * const _;
1733 ExplorerFileItem * Add(ExplorerFileItem item)
1740 ExplorerFileItem * AddBefore(uint position, ExplorerFileItem item)
1742 Insert(position, 1);
1744 return &_[position];
1749 for(c = 0; c < _count; c++)
1759 ExplorerFileItem MakeFileItem(const FileAttribs attribs, const char * fileName, const char * filePath, const bool previewPicture, const DisplaySystem displaySystem)
1761 int len = strlen(fileName);
1762 char info[MAX_LOCATION];
1763 char name[MAX_LOCATION];
1764 char extension[MAX_EXTENSION];
1766 ExplorerFileItem item { };
1768 //if(stats.attribs.isFile) // -- should work now
1769 if(attribs.isDirectory)
1773 item.type = (attribs.isDrive) ? drive : folder;
1774 if(attribs.isServer)
1780 if(attribs.isRemote)
1781 item.type = netDrive;
1782 if(attribs.isRemovable)
1784 if(fileName[0] == 'A' || fileName[0] == 'B')
1787 item.type = removable;
1792 GetExtension(fileName, extension);
1793 //strupr(extension);
1796 item.type = _FileType::SelectByExtension(extension);
1799 if(attribs.isDrive &&
1800 len > 3 && !strncmp(&fileName[1], ": [", 3))
1802 strncpy(name, fileName, 2);
1804 strncpy(info, &fileName[4], len - 5);
1809 strcpy(name, fileName);
1813 item.path = CopyString(filePath);
1814 item.name = CopyString(name);
1816 item.info = CopyString(info);
1817 item.extension = CopyString(extension);
1819 if(item.type == pictureFile && previewPicture)
1821 item.bitmap = Bitmap { };
1822 item.bitmap.Load(filePath, null, displaySystem);
1830 public class FileSystemNode : struct
1833 /*//LinkElement<FileSystemNode> link;
1834 FileSystemNode parent;
1836 FileSystemNodeType type;
1840 FileSystemNode prev, next;
1842 bool loaded, childrenLoaded;
1852 FileSystemNode parent;
1858 void GetPath(String outputPath)
1864 strcpy(outputPath, name);
1865 for(up = parent; up; up = up.parent)
1867 char temp[MAX_LOCATION];
1868 strcpy(temp, up.name);
1869 PathCat(temp, outputPath);
1870 strcpy(outputPath, temp);
1875 strcpy(outputPath, "/");
1877 strcpy(outputPath, name);
1882 bool IsChildOf(FileSystemNode node)
1884 FileSystemNode test;
1885 for(test = parent; test; test = test.parent)
1891 void DuplicateChildren(bool recursive, bool forceExpanded, FileSystemNode addTo, FileSystemBox fsb)
1895 FileSystemNode child;
1897 for(child = children.first; child; child = child.next)
1899 FileSystemNode copy { };
1900 copy.name = CopyString(child.name);
1901 copy.type = child.type;
1902 fsb.AddTreeNode(copy, child.loaded, false, addTo);
1904 copy.row.collapsed = false;
1906 child.DuplicateChildren(recursive, forceExpanded, copy, fsb);
1911 void EnsureVisible(bool expand)
1914 parent.EnsureVisible(true);
1916 row.collapsed = false;
1917 // TODO: row.EnsureVisible(); // making the row visible by scrolling
1927 FileSystemNode child;
1928 for(; (child = children.first); )
1931 children.Delete(child);
1943 parent.children.Delete(this);
1946 void OnDisplay(Surface surface, int x, int y, int width, FileSystemBox fsb, Alignment alignment, DataDisplayFlags displayFlags)
1948 //int indentSize = (displayFlags.dropBox) ? 0 : 10;
1954 char string[MAX_FILENAME];
1961 icon = fsb.fileIcons[type].bitmap;
1962 //xStart = indent * indent + x + (icon ? (icon.width + 5) : 0);
1963 xStart = x + (icon ? (icon.width + 5) : 0);
1969 sprintf(string, "%s [%s]", label ? label : name, info);
1971 strcpy(string, label ? label : name);
1972 len = strlen(string);
1976 if(type == folder || type == folderOpen)
1977 surface.SetForeground(yellow);
1981 //textOffset = indent * indentSize + (icon ? (icon.width + 4) : 0);
1983 surface.TextOpacity(false);
1984 surface.TextExtent(string, len, &w, &h);
1987 // Draw the current row stipple
1988 if(displayFlags.selected)
1989 //surface.Area(xStart - 1, y, xStart - 1, y + h - 1);
1990 //surface.Area(xStart + w - 1, y, xStart + w + 1, y + h - 1);
1991 surface.Area(xStart - 3, y, xStart + w + 1, y + h - 1);
1993 //surface.WriteTextDots(alignment, x + textOffset, y + 2, width - textOffset, name, strlen(name));
1994 surface.WriteTextDots(alignment, xStart, y + 2, width, string, len);
1996 if(!guiApp.textMode)
1998 if(displayFlags.current)
2000 if(displayFlags.active)
2002 surface.LineStipple(0x5555);
2003 if(displayFlags.selected)
2004 surface.SetForeground(0xFFFFFF80);
2006 surface.SetForeground(black);
2010 surface.SetForeground(selectionColor);
2012 surface.Rectangle(xStart - 3, y, xStart + w + 1, y + h - 1);
2013 surface.LineStipple(0);
2021 if(type == pictureFile && fsb.previewPictures && bitmap)
2023 surface.SetForeground(white);
2024 surface.blend = true;
2026 //surface.Filter(bitmap, (clientSize.w - w) / 2,(clientSize.h - h) / 2, 0,0, w, h, bitmap.width, bitmap.height);
2027 //surface.Filter(bitmap, x + indent/* * indentSize*/ + 2, y, 0, 0, w, h, bitmap.width, bitmap.height);
2028 surface.Filter(bitmap, x,y,0,0, w, h, bitmap.width, bitmap.height);
2030 // Until Filter / Stretch works with X
2031 //surface.Blit(bitmap, (clientSize.w - bitmap.width) / 2,(clientSize.h - bitmap.height) / 2, 0,0, bitmap.width, bitmap.height);
2032 // surface.blend = true;
2033 //surface.Blit(bitmap, x + indent/* * indentSize*/ + 2, y,0,0, w, h);
2034 //surface.Blit(bitmap, x,y,0,0, bitmap.width, bitmap.height);
2041 //surface.blend = true;
2042 //surface.alphaWrite = blend;
2043 surface.SetForeground(white);
2044 //surface.Blit(icon, x + indent * indentSize, y,0,0, icon.width, icon.height);
2045 surface.Blit(icon, x,y,0,0, icon.width, icon.height);
2050 int OnCompare(FileSystemNode b)
2053 FileSystemNode a = this;
2054 if(a.type == b.type || (a.type < folder && b.type < folder) || (a.type >= drive))
2055 result = strcmpi(a.name, b.name);
2058 if(a.type == folder && b.type < folder) result = -1;
2059 else if(a.type < folder && b.type == folder) result = 1;
2065 /*int OnCompare(FileSystemNode b)
2068 FileSystemNode a = this;
2069 if(a.parent < b.parent) result = -1;
2070 else if(a.parent > b.parent) result = 1;
2072 result = fstrcmp(a.name, b.name);
2076 char * OnGetString(char * tempString, FileSystemToolWindow fileSysToolWnd, bool * needClass)
2078 return name ? name : "";
2082 /*FileSystemNode MakeFileSystemNode(const FileStats stats, const char * name)
2084 FileSystemNode node { stats = stats };
2085 node.name = CopyString(name);
2088 if(stats.attribs.isDirectory)
2090 node.type = (stats.attribs.isDrive) ? drive : folder;
2091 if(stats.attribs.isServer) node.type = server;
2092 if(stats.attribs.isShare) node.type = share;
2093 if(stats.attribs.isCDROM) node.type = cdrom;
2094 if(stats.attribs.isRemote) node.type = netDrive;
2095 if(stats.attribs.isRemovable)
2097 if(name[0] == 'A' || name[0] == 'B')
2100 node.type = removable;
2105 char extension[MAX_EXTENSION];
2106 GetExtension(node.name, extension);
2107 node.type = _FileType::SelectByExtension(extension);
2111 static FileSystemNode MakeFileSystemNode(const FileStats stats,
2112 const char * fileName, const char * filePath,
2113 const bool previewPicture, const DisplaySystem displaySystem)
2115 int len = strlen(fileName);
2116 char info[MAX_LOCATION];
2117 char name[MAX_LOCATION];
2118 char extension[MAX_EXTENSION];
2120 FileSystemNode node { stats = stats };
2122 //if(stats.attribs.isFile) // TODO fix this in ecere
2123 if(stats.attribs.isDirectory)
2125 extension[0] = '\0';
2127 node.type = (stats.attribs.isDrive) ? drive : folder;
2128 if(stats.attribs.isServer) node.type = server;
2129 if(stats.attribs.isShare) node.type = share;
2130 if(stats.attribs.isCDROM) node.type = cdrom;
2131 if(stats.attribs.isRemote) node.type = netDrive;
2132 if(stats.attribs.isRemovable)
2134 if(fileName[0] == 'A' || fileName[0] == 'B')
2137 node.type = removable;
2142 GetExtension(fileName, extension);
2145 node.type = _FileType::SelectByExtension(extension);
2148 if(stats.attribs.isDrive &&
2149 len > 3 && !strncmp(&fileName[1], ": [", 3))
2151 strncpy(name, fileName, 2);
2153 strncpy(info, &fileName[4], len - 5);
2158 strcpy(name, fileName);
2162 node.path = CopyString(filePath);
2163 node.name = CopyString(name);
2165 node.info = CopyString(info);
2166 node.extension = CopyString(extension);
2168 if(node.type == pictureFile && previewPicture)
2170 node.bitmap = Bitmap { alphaBlend = true };
2171 node.bitmap.Load(filePath, null, displaySystem);