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 //char startPath[MAX_LOCATION];
540 FileSystemNode parent;
542 FileListing listing { path, extensions = extensions };
545 GetWorkingDir(startPath, sizeof(startPath));
547 strcpy(path, startPath);*/
553 root = FileSystemNode { type = computer, loaded = true, childrenLoaded = true };
554 root.name = rootName;
555 AddTreeNode(root, true, false, null);
557 root = MakeFileSystemNode(FileStats { attribs = FileExists(path)}, path, path, bits.previewPictures, displaySystem);
559 root.type = computer;
560 AddTreeNode(root, false, true, null);
564 while(listing.Find())
566 int len = strlen(listing.name);
567 char info[MAX_LOCATION];
568 char name[MAX_LOCATION];
569 if(listing.stats.attribs.isDrive &&
570 len > 3 && !strncmp(&listing.name[1], ": [", 3))
572 strncpy(name, listing.name, 2);
574 strncpy(info, &listing.name[4], len - 5);
579 strcpy(name, listing.name);
583 parent = MakeFileSystemNode(listing.stats, name);
585 parent.info = CopyString(info);
586 parent.loaded = true;
587 AddTreeNode(parent, !listing.stats.attribs.isDirectory, listing.stats.attribs.isDirectory, root, this);
588 if(!listing.stats.attribs.isDirectory)
589 parent.childrenLoaded = true;
592 node = FileSystemNode { name = msNetwork, type = network };
593 AddTreeNode(node, false, true, null, this);
594 node.row.collapsed = true;
599 list.Sort(nameField, 1);
602 void LoadTreeNode(FileSystemNode node)
606 char path[MAX_LOCATION];
609 FileListing listing { path, extensions = extensions };
610 if(node.children.count == 1)
611 DeleteNode(node.children.first);
613 while(listing.Find())
615 if((!bits.foldersOnly && !bits.filesOnly) ||
616 (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
617 (bits.filesOnly && !listing.stats.attribs.isDirectory/*listing.stats.attribs.isFile*/)) // TOCHECK: isFile broken?
619 FileSystemNode child = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
620 AddTreeNode(child, true, false, node);
621 NodeChildLoad(child, node);
625 node.childrenLoaded = true;
627 node.row.SortSubRows(false);
629 else if(!node.childrenLoaded)
631 FileSystemNode child;
632 if(node.children.first)
634 for(child = node.children.first; child; child = child.next)
638 else if(!child.childrenLoaded)
639 NodeChildLoad(child, node);
641 node.childrenLoaded = true;
642 node.row.SortSubRows(false);
647 void NodeChildLoad(FileSystemNode parent, FileSystemNode node)
649 char path[MAX_LOCATION];
650 parent.GetPath(path);
653 FileListing listing { path, extensions = extensions };
654 while(listing.Find())
656 if((!bits.foldersOnly && !bits.filesOnly) ||
657 (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
658 (bits.filesOnly && !listing.stats.attribs.isDirectory/*listing.stats.attribs.isFile*/)) // TOCHECK: isFile broken?
660 FileSystemNode child = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
661 AddTreeNode(child, true, false, parent);
668 //parent.childrenLoaded = true;
671 void AddTreeNode(FileSystemNode node, bool loaded, bool addLoader, FileSystemNode addTo)
673 DataRow row = (addTo && addTo.row) ? addTo.row.AddRow() : list.AddRow();
677 node.indent = addTo.indent + 1;
678 addTo.children.Add(node);
682 row.SetData(null, node);
684 node.loaded = loaded;
686 //AddTreeNode(FileSystemNode { }, false, false, node); // why would this create a compile error?
687 AddTreeNode(FileSystemNode { type = none }, false, false, node);
690 row.collapsed = true;
691 else if(node.type == folder)
692 node.type = folderOpen;
695 void DeleteNode(FileSystemNode node)
697 FileSystemNode child;
698 for(; (child = node.children.first); )
700 list.DeleteRow(node.row);
707 class ExplorerView : FileSystemBox
710 hasHorzScroll = false;
711 hasVertScroll = false;
713 virtual void Load(FileSystemNode parent);
714 virtual void Refresh();
716 virtual void LaunchNotifyItemSelect(Window master, ExplorerView view, ExplorerFileItem item, ExplorerFileItemArray selectedItems)
718 view.NotifyItemSelect(master, view, item, selectedItems);
721 virtual bool Window::NotifyItemSelect(ExplorerView view, ExplorerFileItem item, ExplorerFileItemArray selectedItems);
722 virtual bool Window::NotifyItemOpen(ExplorerView view, ExplorerFileItem item);
726 master = master, parent = this;
729 hasHorzScroll = true;
730 hasVertScroll = true;
733 fullRowSelect = false;
736 anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
738 bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
740 ExplorerView view = (ExplorerView)listBox.parent;
741 if(listBox.currentRow)
744 ExplorerFileItemArray selectedItems { growingFactor = 16 };
745 for(listRow = listBox.firstRow; listRow; listRow = listRow.next)
747 selectedItems.Add((ExplorerFileItem)listRow.tag);
748 //view.NotifyItemSelect(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
749 view.LaunchNotifyItemSelect(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag, selectedItems);
754 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
756 ExplorerView view = (ExplorerView)listBox.parent;
757 view.NotifyItemOpen(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
761 bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
763 if((SmartKey)key == enter)
765 ExplorerView view = (ExplorerView)listBox.parent;
766 view.NotifyItemOpen(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
779 class ExplorerViewList : ExplorerView
782 FileSystemNode location;
786 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
788 ExplorerViewDetails()
790 list.AddField(nameField);
798 void Load(FileSystemNode location)
800 char path[MAX_LOCATION];
801 this.location = location;
802 location.GetPath(path);
804 FileListing listing { path };
806 ExplorerFileItem item;
811 while(listing.Find())
813 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
817 row.SetData(nameField, item);
819 list.Sort(nameField, 1);
826 class ExplorerViewDetails : ExplorerView
828 list.hasHeader = true;
829 list.moveFields = true;
830 list.resizable = true;
831 list.sortable = true;
833 FileSystemNode location;
837 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
838 DataField typeField { header = "Type", dataType = /-*"String"*-/ "char *", width = 40 };
839 DataField sizeField { header = "Size", dataType = "FileSize", width = 96, alignment = right };
841 ExplorerViewDetails()
843 list.AddField(nameField);
844 list.AddField(typeField);
845 list.AddField(sizeField);
853 void Load(FileSystemNode location)
855 char path[MAX_LOCATION];
856 this.location = location;
857 location.GetPath(path);
859 FileListing listing { path };
861 ExplorerFileItem item;
866 while(listing.Find())
868 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
872 row.SetData(nameField, item);
873 row.SetData(typeField, CopyString(item.extension));
874 row.SetData(sizeField, (uint)listing.stats.size);
876 list.Sort(nameField, 1);
883 class ExplorerViewIcons : ExplorerView
886 FileSystemNode location;
890 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
892 ExplorerViewDetails()
894 list.AddField(nameField);
902 void Load(FileSystemNode location)
904 char path[MAX_LOCATION];
905 this.location = location;
906 location.GetPath(path);
908 FileListing listing { path };
910 ExplorerFileItem item;
915 while(listing.Find())
917 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
921 row.SetData(nameField, item);
923 list.Sort(nameField, 1);
930 class ExplorerViewCards : ExplorerView
933 FileSystemNode location;
937 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
939 ExplorerViewDetails()
941 list.AddField(nameField);
949 void Load(FileSystemNode location)
951 char path[MAX_LOCATION];
952 this.location = location;
953 location.GetPath(path);
955 FileListing listing { path };
957 ExplorerFileItem item;
962 while(listing.Find())
964 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
968 row.SetData(nameField, item);
970 list.Sort(nameField, 1);
977 public class BitmapArray : RedjArray
979 type = class(Bitmap);
982 Bitmap * Add(Bitmap bitmap)
989 Bitmap * AddBefore(uint position, Bitmap bitmap)
992 _[position] = bitmap;
998 for(c = 0; c < _count; c++)
1010 class ExplorerViewShowcase : ExplorerView
1012 list.anchor = Anchor { left = 0, top = 0, bottom = 0 };
1013 list.size = Size { w = 200 };
1015 FileSystemNode location;
1019 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 180, editable = true, userData = this };
1022 BitmapArray bitmaps { growingFactor = 16 };
1028 anchor = Anchor { top = 0, right = 0, bottom = 0 };
1030 void OnRedraw(Surface surface)
1032 ExplorerViewShowcase view = (ExplorerViewShowcase)parent;
1035 int wBmp = view.bitmap.width;
1036 int hBmp = view.bitmap.height;
1037 int wWnd = clientSize.w;
1038 int hWnd = clientSize.h;
1040 int wList = view.list.size.w + view.split.size.w;
1042 float scale = Min((float)(wWnd - 10) / wBmp, (float)(hWnd - 10) / hBmp);
1044 int wDraw = (int)(wBmp * scale);
1045 int hDraw = (int)(hBmp * scale);
1048 surface.Filter(view.bitmap, (wWnd - wDraw) / 2, (hWnd - hDraw) / 2, 0, 0, wDraw, hDraw, wBmp, hBmp);
1050 // Until Filter / Stretch works with X
1051 surface.Blit(view.bitmap, (wWnd - wDraw) / 2, (hWnd - hDraw) / 2, 0, 0, wDraw, hDraw);
1056 surface.SetForeground(white);
1057 surface.Area(0, 0, view.clientSize.w - 1, view.clientSize.h - 1);
1071 ExplorerViewDetails()
1073 list.AddField(nameField);
1076 void LaunchNotifyItemSelect(Window master, ExplorerViewShowcase view, ExplorerFileItem item, ExplorerFileItemArray selectedItems)
1079 ExplorerFileItem selItem;
1083 if(item && item.type == pictureFile)
1085 view.bitmap = Bitmap { };
1086 view.bitmap.Load(item.path, null, displaySystem);
1089 view.bitmaps.Clear();
1090 view.bitmaps = BitmapArray { };
1091 for(pos = 0; pos < selectedItems.count; pos++)
1094 selItem = (ExplorerFileItem)selectedItems._[pos];
1095 bitmap.Load(selItem.path, null, displaySystem);
1096 //view.bitmaps.Add(bitmap);
1098 if(item && item.type == pictureFile)
1100 view.bitmap = Bitmap { };
1101 view.bitmap.Load(item.path, null, displaySystem);
1104 view.show.Update(null);
1105 view.NotifyItemSelect(master, view, item, selectedItems);
1113 void Load(FileSystemNode location)
1115 char path[MAX_LOCATION];
1116 this.location = location;
1117 location.GetPath(path);
1119 FileListing listing { path };
1121 ExplorerFileItem item;
1126 while(listing.Find())
1128 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
1130 row = list.AddRow();
1131 row.tag = (int)item;
1132 row.SetData(nameField, item);
1134 list.Sort(nameField, 1);
1141 class ExplorerTree : FileSystemBox
1143 hasHorzScroll = false;
1144 hasVertScroll = false;
1150 DataField nameField { dataType = "FileSystemNode", width = 240, userData = this };
1152 FileSystemNode root;
1153 FileSystemNode selection;
1155 virtual bool Window::NotifyNodeSelect(ExplorerTree tree, FileSystemNode node);
1157 property FileSystemNode node
1163 if(!tree.currentRow)
1165 if(!tree.currentRow.tag)
1167 return (FileSystemNode)tree.currentRow.tag;
1171 void Select(FileSystemNode node)
1175 node.EnsureVisible(false);
1176 tree.SelectRow(node.row);
1180 FileSystemNode Find(const char * name, FileSystemNode parent)
1182 FileSystemNode node;
1183 FileSystemNode start = parent ? parent : root;
1184 if(!start.loaded || !start.childrenLoaded)
1185 LoadTreeNode(start, tree);
1186 for(node = start.children.first; node; node = node.next)
1187 if(node.name && !strcmpi(node.name, name))
1194 master = master, parent = this;
1197 hasHorzScroll = true;
1198 hasVertScroll = true;
1199 fullRowSelect = false;
1201 collapseControl = true;
1202 rootCollapseButton = true;
1204 anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
1206 // WHY is this not working ?
1207 /-*void OnResize(int width, int height)
1209 if(vertScroll.visible)
1210 nameField.width = width - vertScroll.size.w;
1212 nameField.width = width;
1215 bool NotifyCollapse(ListBox listBox, DataRow row, bool collapsed)
1219 FileSystemNode node = (FileSystemNode)row.tag;
1220 FileSystemNode child;
1224 for(child = node.children.last; child; child = node.children.last)
1226 listBox.DeleteRow(child.row);
1230 node.childrenLoaded = false;
1235 if(!node.loaded || !node.childrenLoaded)
1236 LoadTreeNode(node, tree);
1237 for(child = node.children.first; child && child.next; child = child.next);
1239 child.EnsureVisible(false);
1245 bool NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods)
1247 DataRow row = listBox.currentRow;
1250 FileSystemNode node = (FileSystemNode)row.tag;
1256 MenuItem { menu, "Cut\tCtrl+X", t, NotifySelect = null, disabled = false };
1257 MenuItem { menu, "Copy\tCtrl+C", c, NotifySelect = null, disabled = false };
1258 MenuItem { menu, "Paste\tCtrl+V", p, NotifySelect = null, disabled = false /-*!clipboard*-/ };
1259 MenuItem { menu, "Delete\tDel", d, NotifySelect = null, disabled = false };
1260 //MenuDivider { menu };
1264 master = this, menu = menu,
1266 x + clientStart.x + absPosition.x - guiApp.desktop.position.x,
1267 y + clientStart.y + absPosition.y - guiApp.desktop.position.y }
1275 bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
1279 FileSystemNode node = (FileSystemNode)row.tag;
1280 NotifyNodeSelect(listBox.parent.master, this, node);
1286 bool NotifyEditing(ListBox listBox, DataRow row)
1290 FileSystemNode node = (FileSystemNode)row.tag;
1295 bool NotifyEdited(ListBox listBox, DataRow row)
1299 FileSystemNode node = (FileSystemNode)row.tag;
1304 bool NotifyEditDone(ListBox listBox, DataRow row)
1308 FileSystemNode node = (FileSystemNode)row.tag;
1315 Menu editMenu { menu, "Edit", e };
1316 MenuItem itemEditCut
1318 editMenu, "Cut\tCtrl+X", t, disabled = true;
1320 bool NotifySelect(MenuItem selection, Modifiers mods)
1326 MenuItem itemEditCopy
1328 editMenu, "Copy\tCtrl+C", c, disabled = true;
1330 bool NotifySelect(MenuItem selection, Modifiers mods)
1336 MenuItem itemEditPaste
1338 editMenu, "Paste\tCtrl+V", p;
1340 bool NotifySelect(MenuItem selection, Modifiers mods)
1346 MenuItem itemEditDelete
1348 editMenu, "Delete\tDel", d, disabled = true;
1350 bool NotifySelect(MenuItem selection, Modifiers mods)
1357 // WHY is this crashing ?
1358 /-*void OnResize(int width, int height)
1360 if(this && nameField)
1361 nameField.width = width - 80;
1366 tree.AddField(nameField);
1371 FileSystemNode parent;
1372 FileSystemNode node;
1373 FileListing listing { "/" };
1377 root = FileSystemNode { type = computer, loaded = true, childrenLoaded = true };
1379 root.name = rootName;
1383 AddTreeNode(root, true, false, null, tree);
1385 // How can this make sense for linux?
1387 while(listing.Find())
1389 int len = strlen(listing.name);
1390 char info[MAX_LOCATION];
1391 char name[MAX_LOCATION];
1392 if(listing.stats.attribs.isDrive &&
1393 len > 3 && !strncmp(&listing.name[1], ": [", 3))
1395 strncpy(name, listing.name, 2);
1397 strncpy(info, &listing.name[4], len - 5);
1402 strcpy(name, listing.name);
1406 parent = MakeFileSystemNode(listing.stats, name);
1408 parent.info = CopyString(info);
1409 parent.loaded = true;
1410 AddTreeNode(parent, !listing.stats.attribs.isDirectory, listing.stats.attribs.isDirectory, root, tree);
1411 if(!listing.stats.attribs.isDirectory)
1412 parent.childrenLoaded = true;
1415 node = FileSystemNode { name = msNetwork, type = network };
1416 AddTreeNode(node, false, true, null, tree);
1417 node.row.collapsed = true;
1418 tree.Sort(nameField, 1);
1419 tree.SelectRow(root.row);
1424 public class ClipBoardFiles
1438 int size = SelSize();
1441 // Try to allocate memory
1442 ClipBoard clipBoard { };
1443 if(clipBoard.Allocate(size+1))
1445 GetSel(clipBoard.memory, true);
1458 ClipBoard clipBoard { };
1459 if(clipBoard.Load())
1460 PutS(clipBoard.memory);
1471 SetViewToCursor(true);
1477 Private Type DROPFILES
1483 For iCounter = 0 To filelist.ListCount - 1
1484 If filelist.Selected(iCounter) = True Then
1485 strFiles = strFiles & FixPath(filelist.Path) & filelist.List(iCounter) & vbNullChar
1488 'all selected items are now put in strFiles
1490 hGlobal = GlobalAlloc(GHND, Len(DF) + Len(strFiles)) 'put all files to a exclusive number
1491 If hGlobal Then 'if the globalalloc worked
1492 lpGlobal = GlobalLock(hGlobal) 'lock the hGlobal
1493 DF.pFiles = Len(DF) 'set the size of the files
1495 Call CopyMem(ByVal lpGlobal, DF, Len(DF)) 'copy df to the lpglobal
1496 Call CopyMem(ByVal (lpGlobal + Len(DF)), ByVal strFiles, Len(strFiles)) 'copy strfiles to lpglobal
1497 Call GlobalUnlock(hGlobal) 'unlock hglobal again
1499 SetClipboardData CF_HDROP, hGlobal 'put files to the clipboard
1502 bool SaveFile(const char * filePath)
1508 public class FileTreeNodeBSArray : ArrayBinarySorted
1510 type = class(FileSystemNode);
1512 FileSystemNode * const _;
1513 BSloc Add(FileSystemNode item)
1515 BSloc result = Find(item);
1518 Insert(result.pos, 1);
1519 _[result.pos] = item;
1523 BSloc Remove(FileSystemNode item)
1531 public class FileTreeNodeArray : RedjArray
1533 type = class(FileSystemNode);
1535 FileSystemNode * const _;
1536 FileSystemNode * Add(FileSystemNode item)
1543 FileSystemNode * AddBefore(uint position, FileSystemNode item)
1545 Insert(position, 1);
1547 return &_[position];
1553 public class ExplorerFileItem : struct
1564 void OnDisplay(Surface surface, int x, int y, int width, FileSystemBox control, Alignment alignment, DataDisplayFlags displayFlags)
1566 int indentSize = (displayFlags.dropBox) ? 0 : 10;
1569 char label[MAX_FILENAME];
1571 //float scale = Min((float)clientSize.w / (float)bitmap.width, (float)clientSize.h / (float)bitmap.height);
1572 int w = 16; //(int)(bitmap.width * scale);
1573 int h = 16; //(int)(bitmap.height * scale);
1577 icon = control.fileIcons[type].bitmap;
1580 if(type == folder || type == folderOpen)
1581 surface.SetForeground(red); //Color { 170, 170, 0 } // REDJ What is that color?
1584 textOffset = indent * indentSize + (icon ? (icon.width + 6) : 0);
1587 sprintf(label, "%s [%s]", name, info);
1589 strcpy(label, name);
1590 len = strlen(label);
1592 surface.WriteTextDots
1593 (alignment, x + textOffset, y + 2, width - textOffset, label, len);
1594 if(type == pictureFile && control.previewPictures && bitmap)
1597 //surface.Filter(bitmap, (clientSize.w - w) / 2,(clientSize.h - h) / 2, 0,0, w, h, bitmap.width, bitmap.height);
1598 surface.Filter(bitmap, x + indent * indentSize + 2, y, 0, 0, w, h, bitmap.width, bitmap.height);
1600 // Until Filter / Stretch works with X
1601 //surface.Blit(bitmap, (clientSize.w - bitmap.width) / 2,(clientSize.h - bitmap.height) / 2, 0,0, bitmap.width, bitmap.height);
1602 surface.blend = true;
1603 surface.Blit(bitmap, x + indent * indentSize + 2, y,0,0, w, h);
1609 surface.Blit(icon, x + indent * indentSize + 2, y,0,0, icon.width, icon.height);
1612 int OnCompare(ExplorerFileItem b)
1615 if(type == b.type || (type < folder && b.type < folder) || (type >= drive))
1616 result = strcmpi(name, b.name);
1619 if(type == folder && b.type < folder) result = -1;
1620 else if(type < folder && b.type == folder) result = 1;
1625 void OnCopy(ExplorerFileItem newData)
1627 type = newData.type;
1628 indent = newData.indent;
1631 int len = strlen(newData.name) + 1;
1632 name = new char[len];
1633 CopyBytes(name, newData.name, len);
1637 bool OnGetDataFromString(char * string)
1639 int len = strlen(string) + 1;
1640 name = new char[len];
1641 CopyBytes(name, string, len);
1655 char * OnGetString(char * string, void * fieldData, bool * needClass)
1661 public class ExplorerFileItemArray : RedjArray
1663 type = class(ExplorerFileItem);
1665 ExplorerFileItem * const _;
1666 ExplorerFileItem * Add(ExplorerFileItem item)
1673 ExplorerFileItem * AddBefore(uint position, ExplorerFileItem item)
1675 Insert(position, 1);
1677 return &_[position];
1682 for(c = 0; c < _count; c++)
1692 ExplorerFileItem MakeFileItem(const FileAttribs attribs, const char * fileName, const char * filePath, const bool previewPicture, const DisplaySystem displaySystem)
1694 int len = strlen(fileName);
1695 char info[MAX_LOCATION];
1696 char name[MAX_LOCATION];
1697 char extension[MAX_EXTENSION];
1699 ExplorerFileItem item { };
1701 //if(attribs.isFile) // TODO fix this in ecere
1702 if(attribs.isDirectory)
1706 item.type = (attribs.isDrive) ? drive : folder;
1707 if(attribs.isServer)
1713 if(attribs.isRemote)
1714 item.type = netDrive;
1715 if(attribs.isRemovable)
1717 if(fileName[0] == 'A' || fileName[0] == 'B')
1720 item.type = removable;
1725 GetExtension(fileName, extension);
1726 //strupr(extension);
1729 item.type = _FileType::SelectByExtension(extension);
1732 if(attribs.isDrive &&
1733 len > 3 && !strncmp(&fileName[1], ": [", 3))
1735 strncpy(name, fileName, 2);
1737 strncpy(info, &fileName[4], len - 5);
1742 strcpy(name, fileName);
1746 item.path = CopyString(filePath);
1747 item.name = CopyString(name);
1749 item.info = CopyString(info);
1750 item.extension = CopyString(extension);
1752 if(item.type == pictureFile && previewPicture)
1754 item.bitmap = Bitmap { };
1755 item.bitmap.Load(filePath, null, displaySystem);
1763 public class FileSystemNode : struct
1766 /*//LinkElement<FileSystemNode> link;
1767 FileSystemNode parent;
1769 FileSystemNodeType type;
1773 FileSystemNode prev, next;
1775 bool loaded, childrenLoaded;
1784 FileSystemNode parent;
1790 void GetPath(String outputPath)
1795 strcpy(outputPath, name);
1796 for(up = parent; up; up = up.parent)
1798 char temp[MAX_LOCATION];
1799 strcpy(temp, up.name);
1800 PathCat(temp, outputPath);
1801 strcpy(outputPath, temp);
1806 strcpy(outputPath, "/");
1808 strcpy(outputPath, name);
1813 bool IsChildOf(FileSystemNode node)
1815 FileSystemNode test;
1816 for(test = parent; test; test = test.parent)
1822 void DuplicateChildren(bool recursive, bool forceExpanded, FileSystemNode addTo, FileSystemBox fsb)
1826 FileSystemNode child;
1828 for(child = children.first; child; child = child.next)
1830 FileSystemNode copy { };
1831 copy.name = CopyString(child.name);
1832 copy.type = child.type;
1833 fsb.AddTreeNode(copy, child.loaded, false, addTo);
1835 copy.row.collapsed = false;
1837 child.DuplicateChildren(recursive, forceExpanded, copy, fsb);
1842 void EnsureVisible(bool expand)
1845 parent.EnsureVisible(true);
1847 row.collapsed = false;
1848 // TODO: row.EnsureVisible(); // making the row visible by scrolling
1858 FileSystemNode child;
1859 for(; (child = children.first); )
1862 children.Delete(child);
1873 parent.children.Delete(this);
1876 void OnDisplay(Surface surface, int x, int y, int width, FileSystemBox fsb, Alignment alignment, DataDisplayFlags displayFlags)
1878 //int indentSize = (displayFlags.dropBox) ? 0 : 10;
1884 char label[MAX_FILENAME];
1891 icon = fsb.fileIcons[type].bitmap;
1892 //xStart = indent * indent + x + (icon ? (icon.width + 5) : 0);
1893 xStart = x + (icon ? (icon.width + 5) : 0);
1899 sprintf(label, "%s [%s]", name, info);
1901 strcpy(label, name);
1902 len = strlen(label);
1906 if(type == folder || type == folderOpen)
1907 surface.SetForeground(yellow);
1911 //textOffset = indent * indentSize + (icon ? (icon.width + 4) : 0);
1913 surface.TextOpacity(false);
1914 surface.TextExtent(label, len, &w, &h);
1917 // Draw the current row stipple
1918 if(displayFlags.selected)
1919 //surface.Area(xStart - 1, y, xStart - 1, y + h - 1);
1920 //surface.Area(xStart + w - 1, y, xStart + w + 1, y + h - 1);
1921 surface.Area(xStart - 3, y, xStart + w + 1, y + h - 1);
1923 //surface.WriteTextDots(alignment, x + textOffset, y + 2, width - textOffset, name, strlen(name));
1924 surface.WriteTextDots(alignment, xStart, y + 2, width, label, len);
1926 //if(!guiApp.textMode) -- how to do this in a dll?
1928 if(displayFlags.current)
1930 if(displayFlags.active)
1932 surface.LineStipple(0x5555);
1933 if(displayFlags.selected)
1934 surface.SetForeground(0xFFFFFF80);
1936 surface.SetForeground(black);
1940 surface.SetForeground(selectionColor);
1942 surface.Rectangle(xStart - 3, y, xStart + w + 1, y + h - 1);
1943 surface.LineStipple(0);
1951 if(type == pictureFile && fsb.previewPictures && bitmap)
1953 surface.SetForeground(white);
1954 surface.blend = true;
1956 //surface.Filter(bitmap, (clientSize.w - w) / 2,(clientSize.h - h) / 2, 0,0, w, h, bitmap.width, bitmap.height);
1957 //surface.Filter(bitmap, x + indent/* * indentSize*/ + 2, y, 0, 0, w, h, bitmap.width, bitmap.height);
1958 surface.Filter(bitmap, x,y,0,0, w, h, bitmap.width, bitmap.height);
1960 // Until Filter / Stretch works with X
1961 //surface.Blit(bitmap, (clientSize.w - bitmap.width) / 2,(clientSize.h - bitmap.height) / 2, 0,0, bitmap.width, bitmap.height);
1962 // surface.blend = true;
1963 //surface.Blit(bitmap, x + indent/* * indentSize*/ + 2, y,0,0, w, h);
1964 //surface.Blit(bitmap, x,y,0,0, bitmap.width, bitmap.height);
1971 //surface.blend = true;
1972 //surface.alphaWrite = blend;
1973 surface.SetForeground(white);
1974 //surface.Blit(icon, x + indent * indentSize, y,0,0, icon.width, icon.height);
1975 surface.Blit(icon, x,y,0,0, icon.width, icon.height);
1980 int OnCompare(FileSystemNode b)
1983 FileSystemNode a = this;
1984 if(a.type == b.type || (a.type < folder && b.type < folder) || (a.type >= drive))
1985 result = strcmpi(a.name, b.name);
1988 if(a.type == folder && b.type < folder) result = -1;
1989 else if(a.type < folder && b.type == folder) result = 1;
1995 /*int OnCompare(FileSystemNode b)
1998 FileSystemNode a = this;
1999 if(a.parent < b.parent) result = -1;
2000 else if(a.parent > b.parent) result = 1;
2002 result = fstrcmp(a.name, b.name);
2006 char * OnGetString(char * tempString, FileSystemToolWindow fileSysToolWnd, bool * needClass)
2008 return name ? name : "";
2012 /*FileSystemNode MakeFileSystemNode(const FileStats stats, const char * name)
2014 FileSystemNode node { stats = stats };
2015 node.name = CopyString(name);
2018 if(stats.attribs.isDirectory)
2020 node.type = (stats.attribs.isDrive) ? drive : folder;
2021 if(stats.attribs.isServer) node.type = server;
2022 if(stats.attribs.isShare) node.type = share;
2023 if(stats.attribs.isCDROM) node.type = cdrom;
2024 if(stats.attribs.isRemote) node.type = netDrive;
2025 if(stats.attribs.isRemovable)
2027 if(name[0] == 'A' || name[0] == 'B')
2030 node.type = removable;
2035 char extension[MAX_EXTENSION];
2036 GetExtension(node.name, extension);
2037 node.type = _FileType::SelectByExtension(extension);
2041 static FileSystemNode MakeFileSystemNode(const FileStats stats,
2042 const char * fileName, const char * filePath,
2043 const bool previewPicture, const DisplaySystem displaySystem)
2045 int len = strlen(fileName);
2046 char info[MAX_LOCATION];
2047 char name[MAX_LOCATION];
2048 char extension[MAX_EXTENSION];
2050 FileSystemNode node { stats = stats };
2052 //if(stats.attribs.isFile) // TODO fix this in ecere
2053 if(stats.attribs.isDirectory)
2055 extension[0] = '\0';
2057 node.type = (stats.attribs.isDrive) ? drive : folder;
2058 if(stats.attribs.isServer) node.type = server;
2059 if(stats.attribs.isShare) node.type = share;
2060 if(stats.attribs.isCDROM) node.type = cdrom;
2061 if(stats.attribs.isRemote) node.type = netDrive;
2062 if(stats.attribs.isRemovable)
2064 if(fileName[0] == 'A' || fileName[0] == 'B')
2067 node.type = removable;
2072 GetExtension(fileName, extension);
2075 node.type = _FileType::SelectByExtension(extension);
2078 if(stats.attribs.isDrive &&
2079 len > 3 && !strncmp(&fileName[1], ": [", 3))
2081 strncpy(name, fileName, 2);
2083 strncpy(info, &fileName[4], len - 5);
2088 strcpy(name, fileName);
2092 node.path = CopyString(filePath);
2093 node.name = CopyString(name);
2095 node.info = CopyString(info);
2096 node.extension = CopyString(extension);
2098 if(node.type == pictureFile && previewPicture)
2100 node.bitmap = Bitmap { alphaBlend = true };
2101 node.bitmap.Load(filePath, null, displaySystem);