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)
482 bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
485 if((SmartKey)key == enter)
496 if(selection && selection.type.isFolder && bits.navigateFolders)
498 property::path = selection.path;
502 result = NotifyNodeOpen(this.master, this, selection);
507 Menu editMenu { menu, "Edit", e };
510 editMenu, "Cut\tCtrl+X", t, disabled = true;
512 bool NotifySelect(MenuItem selection, Modifiers mods)
518 MenuItem itemEditCopy
520 editMenu, "Copy\tCtrl+C", c, disabled = true;
522 bool NotifySelect(MenuItem selection, Modifiers mods)
528 MenuItem itemEditPaste
530 editMenu, "Paste\tCtrl+V", p;
532 bool NotifySelect(MenuItem selection, Modifiers mods)
538 MenuItem itemEditDelete
540 editMenu, "Delete\tDel", d, disabled = true;
542 bool NotifySelect(MenuItem selection, Modifiers mods)
549 // WHY is this crashing ?
550 /*void OnResize(int width, int height)
552 if(this && nameField)
553 nameField.width = width - 80;
559 // this is crashing in for designer when details = true // can't save the file, always yields a crash
560 /*if(list && created)
563 list.AddField(nameField);
566 list.AddField(typeField);
567 list.AddField(sizeField);
570 if(bits.treeBranches)
578 FileListing listing { path, extensions = extensions };
581 while(listing.Find())
583 if((!bits.foldersOnly && !bits.filesOnly) ||
584 (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
585 (bits.filesOnly && listing.stats.attribs.isFile))
587 FileSystemNode node = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
588 DataRow row = list.AddRow();
590 row.SetData(nameField, node);
593 row.SetData(typeField, node.extension);
594 row.SetData(sizeField, (void *)node.stats.size);
598 list.Sort(nameField, 1);
603 bool isRoot = !strcmp(path, "/");
604 //char startPath[MAX_LOCATION];
605 FileSystemNode parent;
607 FileListing listing { path, extensions = extensions };
610 GetWorkingDir(startPath, sizeof(startPath));
612 strcpy(path, startPath);*/
620 root = FileSystemNode { loaded = true, childrenLoaded = true };
621 AddTreeNode(root, true, false, null);
622 while(listing.Find())
624 int len = strlen(listing.name);
625 char info[MAX_LOCATION];
626 char name[MAX_LOCATION];
627 if(listing.stats.attribs.isDrive &&
628 len > 3 && !strncmp(&listing.name[1], ": [", 3))
630 strncpy(name, listing.name, 2);
632 strncpy(info, &listing.name[4], len - 5);
637 strcpy(name, listing.name);
641 parent = MakeFileSystemNode(listing.stats, name, listing.path, bits.previewPictures, displaySystem);
643 parent.info = CopyString(info);
644 parent.loaded = true;
645 AddTreeNode(parent, !listing.stats.attribs.isDirectory, listing.stats.attribs.isDirectory, root);
646 if(!listing.stats.attribs.isDirectory)
647 parent.childrenLoaded = true;
650 node = FileSystemNode { name = msNetwork, type = network };
651 AddTreeNode(node, false, true, null);
652 node.row.collapsed = true;
657 root = MakeFileSystemNode(FileStats { attribs = FileExists(path)}, path, path, bits.previewPictures, displaySystem);
658 AddTreeNode(root, false, true, null);
664 root.type = computer;
665 root.label = rootName;
668 list.Sort(nameField, 1);
669 list.SelectRow(root.row);
672 void LoadTreeNode(FileSystemNode node)
676 char path[MAX_LOCATION];
679 FileListing listing { path, extensions = extensions };
680 if(node.children.count == 1)
681 DeleteNode(node.children.first);
683 while(listing.Find())
685 if(!listing.stats.attribs.isRemovable && ((!bits.foldersOnly && !bits.filesOnly) ||
686 (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
687 (bits.filesOnly && listing.stats.attribs.isFile)))
689 FileSystemNode child = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
690 AddTreeNode(child, true, false, node);
691 NodeChildLoad(child, node);
695 node.childrenLoaded = true;
697 node.row.SortSubRows(false);
699 else if(!node.childrenLoaded)
701 FileSystemNode child;
702 if(node.children.first)
704 for(child = node.children.first; child; child = child.next)
708 else if(!child.childrenLoaded)
709 NodeChildLoad(child, node);
711 node.childrenLoaded = true;
712 node.row.SortSubRows(false);
717 void NodeChildLoad(FileSystemNode parent, FileSystemNode node)
719 char path[MAX_LOCATION];
720 parent.GetPath(path);
723 FileListing listing { path, extensions = extensions };
724 while(listing.Find())
726 if((!bits.foldersOnly && !bits.filesOnly) ||
727 (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
728 (bits.filesOnly && listing.stats.attribs.isFile))
730 FileSystemNode child = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
731 AddTreeNode(child, listing.stats.attribs.isFile, !listing.stats.attribs.isFile, parent);
738 parent.childrenLoaded = true;
741 void AddTreeNode(FileSystemNode node, bool loaded, bool addLoader, FileSystemNode addTo)
743 DataRow row = (addTo && addTo.row) ? addTo.row.AddRow() : list.AddRow();
747 node.indent = addTo.indent + 1;
748 addTo.children.Add(node);
752 row.SetData(null, node);
754 node.loaded = loaded;
756 //AddTreeNode(FileSystemNode { }, false, false, node); // why would this create a compile error?
757 AddTreeNode(FileSystemNode { type = none }, false, false, node);
760 row.collapsed = true;
761 else if(node.type == folder)
762 node.type = folderOpen;
765 void DeleteNode(FileSystemNode node)
767 FileSystemNode child;
768 for(; (child = node.children.first); )
770 list.DeleteRow(node.row);
777 class ExplorerView : FileSystemBox
780 hasHorzScroll = false;
781 hasVertScroll = false;
783 virtual void Load(FileSystemNode parent);
784 virtual void Refresh();
786 virtual void LaunchNotifyItemSelect(Window master, ExplorerView view, ExplorerFileItem item, ExplorerFileItemArray selectedItems)
788 view.NotifyItemSelect(master, view, item, selectedItems);
791 virtual bool Window::NotifyItemSelect(ExplorerView view, ExplorerFileItem item, ExplorerFileItemArray selectedItems);
792 virtual bool Window::NotifyItemOpen(ExplorerView view, ExplorerFileItem item);
796 master = master, parent = this;
799 hasHorzScroll = true;
800 hasVertScroll = true;
803 fullRowSelect = false;
806 anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
808 bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
810 ExplorerView view = (ExplorerView)listBox.parent;
811 if(listBox.currentRow)
814 ExplorerFileItemArray selectedItems { growingFactor = 16 };
815 for(listRow = listBox.firstRow; listRow; listRow = listRow.next)
817 selectedItems.Add((ExplorerFileItem)listRow.tag);
818 //view.NotifyItemSelect(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
819 view.LaunchNotifyItemSelect(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag, selectedItems);
824 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
826 ExplorerView view = (ExplorerView)listBox.parent;
827 view.NotifyItemOpen(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
831 bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
833 if((SmartKey)key == enter)
835 ExplorerView view = (ExplorerView)listBox.parent;
836 view.NotifyItemOpen(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
849 class ExplorerViewList : ExplorerView
852 FileSystemNode location;
856 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
858 ExplorerViewDetails()
860 list.AddField(nameField);
868 void Load(FileSystemNode location)
870 char path[MAX_LOCATION];
871 this.location = location;
872 location.GetPath(path);
874 FileListing listing { path };
876 ExplorerFileItem item;
881 while(listing.Find())
883 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
887 row.SetData(nameField, item);
889 list.Sort(nameField, 1);
896 class ExplorerViewDetails : ExplorerView
898 list.hasHeader = true;
899 list.moveFields = true;
900 list.resizable = true;
901 list.sortable = true;
903 FileSystemNode location;
907 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
908 DataField typeField { header = "Type", dataType = /-*"String"*-/ "char *", width = 40 };
909 DataField sizeField { header = "Size", dataType = "FileSize", width = 96, alignment = right };
911 ExplorerViewDetails()
913 list.AddField(nameField);
914 list.AddField(typeField);
915 list.AddField(sizeField);
923 void Load(FileSystemNode location)
925 char path[MAX_LOCATION];
926 this.location = location;
927 location.GetPath(path);
929 FileListing listing { path };
931 ExplorerFileItem item;
936 while(listing.Find())
938 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
942 row.SetData(nameField, item);
943 row.SetData(typeField, CopyString(item.extension));
944 row.SetData(sizeField, (uint)listing.stats.size);
946 list.Sort(nameField, 1);
953 class ExplorerViewIcons : ExplorerView
956 FileSystemNode location;
960 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
962 ExplorerViewDetails()
964 list.AddField(nameField);
972 void Load(FileSystemNode location)
974 char path[MAX_LOCATION];
975 this.location = location;
976 location.GetPath(path);
978 FileListing listing { path };
980 ExplorerFileItem item;
985 while(listing.Find())
987 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
991 row.SetData(nameField, item);
993 list.Sort(nameField, 1);
1000 class ExplorerViewCards : ExplorerView
1003 FileSystemNode location;
1007 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
1009 ExplorerViewDetails()
1011 list.AddField(nameField);
1019 void Load(FileSystemNode location)
1021 char path[MAX_LOCATION];
1022 this.location = location;
1023 location.GetPath(path);
1025 FileListing listing { path };
1027 ExplorerFileItem item;
1032 while(listing.Find())
1034 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
1036 row = list.AddRow();
1037 row.tag = (int)item;
1038 row.SetData(nameField, item);
1040 list.Sort(nameField, 1);
1047 public class BitmapArray : RedjArray
1049 type = class(Bitmap);
1052 Bitmap * Add(Bitmap bitmap)
1059 Bitmap * AddBefore(uint position, Bitmap bitmap)
1061 Insert(position, 1);
1062 _[position] = bitmap;
1063 return &_[position];
1068 for(c = 0; c < _count; c++)
1080 class ExplorerViewShowcase : ExplorerView
1082 list.anchor = Anchor { left = 0, top = 0, bottom = 0 };
1083 list.size = Size { w = 200 };
1085 FileSystemNode location;
1089 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 180, editable = true, userData = this };
1092 BitmapArray bitmaps { growingFactor = 16 };
1098 anchor = Anchor { top = 0, right = 0, bottom = 0 };
1100 void OnRedraw(Surface surface)
1102 ExplorerViewShowcase view = (ExplorerViewShowcase)parent;
1105 int wBmp = view.bitmap.width;
1106 int hBmp = view.bitmap.height;
1107 int wWnd = clientSize.w;
1108 int hWnd = clientSize.h;
1110 int wList = view.list.size.w + view.split.size.w;
1112 float scale = Min((float)(wWnd - 10) / wBmp, (float)(hWnd - 10) / hBmp);
1114 int wDraw = (int)(wBmp * scale);
1115 int hDraw = (int)(hBmp * scale);
1118 surface.Filter(view.bitmap, (wWnd - wDraw) / 2, (hWnd - hDraw) / 2, 0, 0, wDraw, hDraw, wBmp, hBmp);
1120 // Until Filter / Stretch works with X
1121 surface.Blit(view.bitmap, (wWnd - wDraw) / 2, (hWnd - hDraw) / 2, 0, 0, wDraw, hDraw);
1126 surface.SetForeground(white);
1127 surface.Area(0, 0, view.clientSize.w - 1, view.clientSize.h - 1);
1141 ExplorerViewDetails()
1143 list.AddField(nameField);
1146 void LaunchNotifyItemSelect(Window master, ExplorerViewShowcase view, ExplorerFileItem item, ExplorerFileItemArray selectedItems)
1149 ExplorerFileItem selItem;
1153 if(item && item.type == pictureFile)
1155 view.bitmap = Bitmap { };
1156 view.bitmap.Load(item.path, null, displaySystem);
1159 view.bitmaps.Clear();
1160 view.bitmaps = BitmapArray { };
1161 for(pos = 0; pos < selectedItems.count; pos++)
1164 selItem = (ExplorerFileItem)selectedItems._[pos];
1165 bitmap.Load(selItem.path, null, displaySystem);
1166 //view.bitmaps.Add(bitmap);
1168 if(item && item.type == pictureFile)
1170 view.bitmap = Bitmap { };
1171 view.bitmap.Load(item.path, null, displaySystem);
1174 view.show.Update(null);
1175 view.NotifyItemSelect(master, view, item, selectedItems);
1183 void Load(FileSystemNode location)
1185 char path[MAX_LOCATION];
1186 this.location = location;
1187 location.GetPath(path);
1189 FileListing listing { path };
1191 ExplorerFileItem item;
1196 while(listing.Find())
1198 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
1200 row = list.AddRow();
1201 row.tag = (int)item;
1202 row.SetData(nameField, item);
1204 list.Sort(nameField, 1);
1211 class ExplorerTree : FileSystemBox
1213 hasHorzScroll = false;
1214 hasVertScroll = false;
1220 DataField nameField { dataType = "FileSystemNode", width = 240, userData = this };
1222 FileSystemNode root;
1223 FileSystemNode selection;
1225 virtual bool Window::NotifyNodeSelect(ExplorerTree tree, FileSystemNode node);
1227 property FileSystemNode node
1233 if(!tree.currentRow)
1235 if(!tree.currentRow.tag)
1237 return (FileSystemNode)tree.currentRow.tag;
1241 void Select(FileSystemNode node)
1245 node.EnsureVisible(false);
1246 tree.SelectRow(node.row);
1250 FileSystemNode Find(const char * name, FileSystemNode parent)
1252 FileSystemNode node;
1253 FileSystemNode start = parent ? parent : root;
1254 if(!start.loaded || !start.childrenLoaded)
1255 LoadTreeNode(start, tree);
1256 for(node = start.children.first; node; node = node.next)
1257 if(node.name && !strcmpi(node.name, name))
1264 master = master, parent = this;
1267 hasHorzScroll = true;
1268 hasVertScroll = true;
1269 fullRowSelect = false;
1271 collapseControl = true;
1272 rootCollapseButton = true;
1274 anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
1276 // WHY is this not working ?
1277 /-*void OnResize(int width, int height)
1279 if(vertScroll.visible)
1280 nameField.width = width - vertScroll.size.w;
1282 nameField.width = width;
1285 bool NotifyCollapse(ListBox listBox, DataRow row, bool collapsed)
1289 FileSystemNode node = (FileSystemNode)row.tag;
1290 FileSystemNode child;
1294 for(child = node.children.last; child; child = node.children.last)
1296 listBox.DeleteRow(child.row);
1300 node.childrenLoaded = false;
1305 if(!node.loaded || !node.childrenLoaded)
1306 LoadTreeNode(node, tree);
1307 for(child = node.children.first; child && child.next; child = child.next);
1309 child.EnsureVisible(false);
1315 bool NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods)
1317 DataRow row = listBox.currentRow;
1320 FileSystemNode node = (FileSystemNode)row.tag;
1326 MenuItem { menu, "Cut\tCtrl+X", t, NotifySelect = null, disabled = false };
1327 MenuItem { menu, "Copy\tCtrl+C", c, NotifySelect = null, disabled = false };
1328 MenuItem { menu, "Paste\tCtrl+V", p, NotifySelect = null, disabled = false /-*!clipboard*-/ };
1329 MenuItem { menu, "Delete\tDel", d, NotifySelect = null, disabled = false };
1330 //MenuDivider { menu };
1334 master = this, menu = menu,
1336 x + clientStart.x + absPosition.x - guiApp.desktop.position.x,
1337 y + clientStart.y + absPosition.y - guiApp.desktop.position.y }
1345 bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
1349 FileSystemNode node = (FileSystemNode)row.tag;
1350 NotifyNodeSelect(listBox.parent.master, this, node);
1356 bool NotifyEditing(ListBox listBox, DataRow row)
1360 FileSystemNode node = (FileSystemNode)row.tag;
1365 bool NotifyEdited(ListBox listBox, DataRow row)
1369 FileSystemNode node = (FileSystemNode)row.tag;
1374 bool NotifyEditDone(ListBox listBox, DataRow row)
1378 FileSystemNode node = (FileSystemNode)row.tag;
1385 Menu editMenu { menu, "Edit", e };
1386 MenuItem itemEditCut
1388 editMenu, "Cut\tCtrl+X", t, disabled = true;
1390 bool NotifySelect(MenuItem selection, Modifiers mods)
1396 MenuItem itemEditCopy
1398 editMenu, "Copy\tCtrl+C", c, disabled = true;
1400 bool NotifySelect(MenuItem selection, Modifiers mods)
1406 MenuItem itemEditPaste
1408 editMenu, "Paste\tCtrl+V", p;
1410 bool NotifySelect(MenuItem selection, Modifiers mods)
1416 MenuItem itemEditDelete
1418 editMenu, "Delete\tDel", d, disabled = true;
1420 bool NotifySelect(MenuItem selection, Modifiers mods)
1427 // WHY is this crashing ?
1428 /-*void OnResize(int width, int height)
1430 if(this && nameField)
1431 nameField.width = width - 80;
1436 tree.AddField(nameField);
1441 FileSystemNode parent;
1442 FileSystemNode node;
1443 FileListing listing { "/" };
1447 root = FileSystemNode { type = computer, loaded = true, childrenLoaded = true };
1449 root.name = rootName;
1453 AddTreeNode(root, true, false, null, tree);
1455 // How can this make sense for linux?
1457 while(listing.Find())
1459 int len = strlen(listing.name);
1460 char info[MAX_LOCATION];
1461 char name[MAX_LOCATION];
1462 if(listing.stats.attribs.isDrive &&
1463 len > 3 && !strncmp(&listing.name[1], ": [", 3))
1465 strncpy(name, listing.name, 2);
1467 strncpy(info, &listing.name[4], len - 5);
1472 strcpy(name, listing.name);
1476 parent = MakeFileSystemNode(listing.stats, name);
1478 parent.info = CopyString(info);
1479 parent.loaded = true;
1480 AddTreeNode(parent, !listing.stats.attribs.isDirectory, listing.stats.attribs.isDirectory, root, tree);
1481 if(!listing.stats.attribs.isDirectory)
1482 parent.childrenLoaded = true;
1485 node = FileSystemNode { name = msNetwork, type = network };
1486 AddTreeNode(node, false, true, null, tree);
1487 node.row.collapsed = true;
1488 tree.Sort(nameField, 1);
1489 tree.SelectRow(root.row);
1494 public class ClipBoardFiles
1508 int size = SelSize();
1511 // Try to allocate memory
1512 ClipBoard clipBoard { };
1513 if(clipBoard.Allocate(size+1))
1515 GetSel(clipBoard.memory, true);
1528 ClipBoard clipBoard { };
1529 if(clipBoard.Load())
1530 PutS(clipBoard.memory);
1541 SetViewToCursor(true);
1547 Private Type DROPFILES
1553 For iCounter = 0 To filelist.ListCount - 1
1554 If filelist.Selected(iCounter) = True Then
1555 strFiles = strFiles & FixPath(filelist.Path) & filelist.List(iCounter) & vbNullChar
1558 'all selected items are now put in strFiles
1560 hGlobal = GlobalAlloc(GHND, Len(DF) + Len(strFiles)) 'put all files to a exclusive number
1561 If hGlobal Then 'if the globalalloc worked
1562 lpGlobal = GlobalLock(hGlobal) 'lock the hGlobal
1563 DF.pFiles = Len(DF) 'set the size of the files
1565 Call CopyMem(ByVal lpGlobal, DF, Len(DF)) 'copy df to the lpglobal
1566 Call CopyMem(ByVal (lpGlobal + Len(DF)), ByVal strFiles, Len(strFiles)) 'copy strfiles to lpglobal
1567 Call GlobalUnlock(hGlobal) 'unlock hglobal again
1569 SetClipboardData CF_HDROP, hGlobal 'put files to the clipboard
1572 bool SaveFile(const char * filePath)
1578 public class FileTreeNodeBSArray : ArrayBinarySorted
1580 type = class(FileSystemNode);
1582 FileSystemNode * const _;
1583 BSloc Add(FileSystemNode item)
1585 BSloc result = Find(item);
1588 Insert(result.pos, 1);
1589 _[result.pos] = item;
1593 BSloc Remove(FileSystemNode item)
1601 public class FileTreeNodeArray : RedjArray
1603 type = class(FileSystemNode);
1605 FileSystemNode * const _;
1606 FileSystemNode * Add(FileSystemNode item)
1613 FileSystemNode * AddBefore(uint position, FileSystemNode item)
1615 Insert(position, 1);
1617 return &_[position];
1623 public class ExplorerFileItem : struct
1634 void OnDisplay(Surface surface, int x, int y, int width, FileSystemBox control, Alignment alignment, DataDisplayFlags displayFlags)
1636 int indentSize = (displayFlags.dropBox) ? 0 : 10;
1639 char label[MAX_FILENAME];
1641 //float scale = Min((float)clientSize.w / (float)bitmap.width, (float)clientSize.h / (float)bitmap.height);
1642 int w = 16; //(int)(bitmap.width * scale);
1643 int h = 16; //(int)(bitmap.height * scale);
1647 icon = control.fileIcons[type].bitmap;
1650 if(type == folder || type == folderOpen)
1651 surface.SetForeground(red); //Color { 170, 170, 0 } // REDJ What is that color?
1654 textOffset = indent * indentSize + (icon ? (icon.width + 6) : 0);
1657 sprintf(label, "%s [%s]", name, info);
1659 strcpy(label, name);
1660 len = strlen(label);
1662 surface.WriteTextDots
1663 (alignment, x + textOffset, y + 2, width - textOffset, label, len);
1664 if(type == pictureFile && control.previewPictures && bitmap)
1667 //surface.Filter(bitmap, (clientSize.w - w) / 2,(clientSize.h - h) / 2, 0,0, w, h, bitmap.width, bitmap.height);
1668 surface.Filter(bitmap, x + indent * indentSize + 2, y, 0, 0, w, h, bitmap.width, bitmap.height);
1670 // Until Filter / Stretch works with X
1671 //surface.Blit(bitmap, (clientSize.w - bitmap.width) / 2,(clientSize.h - bitmap.height) / 2, 0,0, bitmap.width, bitmap.height);
1672 surface.blend = true;
1673 surface.Blit(bitmap, x + indent * indentSize + 2, y,0,0, w, h);
1679 surface.Blit(icon, x + indent * indentSize + 2, y,0,0, icon.width, icon.height);
1682 int OnCompare(ExplorerFileItem b)
1685 if(type == b.type || (type < folder && b.type < folder) || (type >= drive))
1686 result = strcmpi(name, b.name);
1689 if(type == folder && b.type < folder) result = -1;
1690 else if(type < folder && b.type == folder) result = 1;
1695 void OnCopy(ExplorerFileItem newData)
1697 type = newData.type;
1698 indent = newData.indent;
1701 int len = strlen(newData.name) + 1;
1702 name = new char[len];
1703 CopyBytes(name, newData.name, len);
1707 bool OnGetDataFromString(char * string)
1709 int len = strlen(string) + 1;
1710 name = new char[len];
1711 CopyBytes(name, string, len);
1725 char * OnGetString(char * string, void * fieldData, bool * needClass)
1731 public class ExplorerFileItemArray : RedjArray
1733 type = class(ExplorerFileItem);
1735 ExplorerFileItem * const _;
1736 ExplorerFileItem * Add(ExplorerFileItem item)
1743 ExplorerFileItem * AddBefore(uint position, ExplorerFileItem item)
1745 Insert(position, 1);
1747 return &_[position];
1752 for(c = 0; c < _count; c++)
1762 ExplorerFileItem MakeFileItem(const FileAttribs attribs, const char * fileName, const char * filePath, const bool previewPicture, const DisplaySystem displaySystem)
1764 int len = strlen(fileName);
1765 char info[MAX_LOCATION];
1766 char name[MAX_LOCATION];
1767 char extension[MAX_EXTENSION];
1769 ExplorerFileItem item { };
1771 //if(stats.attribs.isFile) // -- should work now
1772 if(attribs.isDirectory)
1776 item.type = (attribs.isDrive) ? drive : folder;
1777 if(attribs.isServer)
1783 if(attribs.isRemote)
1784 item.type = netDrive;
1785 if(attribs.isRemovable)
1787 if(fileName[0] == 'A' || fileName[0] == 'B')
1790 item.type = removable;
1795 GetExtension(fileName, extension);
1796 //strupr(extension);
1799 item.type = _FileType::SelectByExtension(extension);
1802 if(attribs.isDrive &&
1803 len > 3 && !strncmp(&fileName[1], ": [", 3))
1805 strncpy(name, fileName, 2);
1807 strncpy(info, &fileName[4], len - 5);
1812 strcpy(name, fileName);
1816 item.path = CopyString(filePath);
1817 item.name = CopyString(name);
1819 item.info = CopyString(info);
1820 item.extension = CopyString(extension);
1822 if(item.type == pictureFile && previewPicture)
1824 item.bitmap = Bitmap { };
1825 item.bitmap.Load(filePath, null, displaySystem);
1833 public class FileSystemNode : struct
1836 /*//LinkElement<FileSystemNode> link;
1837 FileSystemNode parent;
1839 FileSystemNodeType type;
1843 FileSystemNode prev, next;
1845 bool loaded, childrenLoaded;
1855 FileSystemNode parent;
1861 void GetPath(String outputPath)
1867 strcpy(outputPath, name);
1868 for(up = parent; up; up = up.parent)
1870 char temp[MAX_LOCATION];
1871 strcpy(temp, up.name);
1872 PathCat(temp, outputPath);
1873 strcpy(outputPath, temp);
1878 strcpy(outputPath, "/");
1880 strcpy(outputPath, name);
1885 bool IsChildOf(FileSystemNode node)
1887 FileSystemNode test;
1888 for(test = parent; test; test = test.parent)
1894 void DuplicateChildren(bool recursive, bool forceExpanded, FileSystemNode addTo, FileSystemBox fsb)
1898 FileSystemNode child;
1900 for(child = children.first; child; child = child.next)
1902 FileSystemNode copy { };
1903 copy.name = CopyString(child.name);
1904 copy.type = child.type;
1905 fsb.AddTreeNode(copy, child.loaded, false, addTo);
1907 copy.row.collapsed = false;
1909 child.DuplicateChildren(recursive, forceExpanded, copy, fsb);
1914 void EnsureVisible(bool expand)
1917 parent.EnsureVisible(true);
1919 row.collapsed = false;
1920 // TODO: row.EnsureVisible(); // making the row visible by scrolling
1930 FileSystemNode child;
1931 for(; (child = children.first); )
1934 children.Delete(child);
1946 parent.children.Delete(this);
1949 void OnDisplay(Surface surface, int x, int y, int width, FileSystemBox fsb, Alignment alignment, DataDisplayFlags displayFlags)
1951 //int indentSize = (displayFlags.dropBox) ? 0 : 10;
1957 char string[MAX_FILENAME];
1964 icon = fsb.fileIcons[type].bitmap;
1965 //xStart = indent * indent + x + (icon ? (icon.width + 5) : 0);
1966 xStart = x + (icon ? (icon.width + 5) : 0);
1972 sprintf(string, "%s [%s]", label ? label : name, info);
1974 strcpy(string, label ? label : name);
1975 len = strlen(string);
1979 if(type == folder || type == folderOpen)
1980 surface.SetForeground(yellow);
1984 //textOffset = indent * indentSize + (icon ? (icon.width + 4) : 0);
1986 surface.TextOpacity(false);
1987 surface.TextExtent(string, len, &w, &h);
1990 // Draw the current row stipple
1991 if(displayFlags.selected)
1992 //surface.Area(xStart - 1, y, xStart - 1, y + h - 1);
1993 //surface.Area(xStart + w - 1, y, xStart + w + 1, y + h - 1);
1994 surface.Area(xStart - 3, y, xStart + w + 1, y + h - 1);
1996 //surface.WriteTextDots(alignment, x + textOffset, y + 2, width - textOffset, name, strlen(name));
1997 surface.WriteTextDots(alignment, xStart, y + 2, width, string, len);
1999 if(!guiApp.textMode)
2001 if(displayFlags.current)
2003 if(displayFlags.active)
2005 surface.LineStipple(0x5555);
2006 if(displayFlags.selected)
2007 surface.SetForeground(0xFFFFFF80);
2009 surface.SetForeground(black);
2013 surface.SetForeground(selectionColor);
2015 surface.Rectangle(xStart - 3, y, xStart + w + 1, y + h - 1);
2016 surface.LineStipple(0);
2024 if(type == pictureFile && fsb.previewPictures && bitmap)
2026 surface.SetForeground(white);
2027 surface.blend = true;
2029 //surface.Filter(bitmap, (clientSize.w - w) / 2,(clientSize.h - h) / 2, 0,0, w, h, bitmap.width, bitmap.height);
2030 //surface.Filter(bitmap, x + indent/* * indentSize*/ + 2, y, 0, 0, w, h, bitmap.width, bitmap.height);
2031 surface.Filter(bitmap, x,y,0,0, w, h, bitmap.width, bitmap.height);
2033 // Until Filter / Stretch works with X
2034 //surface.Blit(bitmap, (clientSize.w - bitmap.width) / 2,(clientSize.h - bitmap.height) / 2, 0,0, bitmap.width, bitmap.height);
2035 // surface.blend = true;
2036 //surface.Blit(bitmap, x + indent/* * indentSize*/ + 2, y,0,0, w, h);
2037 //surface.Blit(bitmap, x,y,0,0, bitmap.width, bitmap.height);
2044 //surface.blend = true;
2045 //surface.alphaWrite = blend;
2046 surface.SetForeground(white);
2047 //surface.Blit(icon, x + indent * indentSize, y,0,0, icon.width, icon.height);
2048 surface.Blit(icon, x,y,0,0, icon.width, icon.height);
2053 int OnCompare(FileSystemNode b)
2056 FileSystemNode a = this;
2057 if(a.type == b.type || (a.type < folder && b.type < folder) || (a.type >= drive))
2058 result = strcmpi(a.name, b.name);
2061 if(a.type == folder && b.type < folder) result = -1;
2062 else if(a.type < folder && b.type == folder) result = 1;
2068 /*int OnCompare(FileSystemNode b)
2071 FileSystemNode a = this;
2072 if(a.parent < b.parent) result = -1;
2073 else if(a.parent > b.parent) result = 1;
2075 result = fstrcmp(a.name, b.name);
2079 char * OnGetString(char * tempString, FileSystemToolWindow fileSysToolWnd, bool * needClass)
2081 return name ? name : "";
2085 /*FileSystemNode MakeFileSystemNode(const FileStats stats, const char * name)
2087 FileSystemNode node { stats = stats };
2088 node.name = CopyString(name);
2091 if(stats.attribs.isDirectory)
2093 node.type = (stats.attribs.isDrive) ? drive : folder;
2094 if(stats.attribs.isServer) node.type = server;
2095 if(stats.attribs.isShare) node.type = share;
2096 if(stats.attribs.isCDROM) node.type = cdrom;
2097 if(stats.attribs.isRemote) node.type = netDrive;
2098 if(stats.attribs.isRemovable)
2100 if(name[0] == 'A' || name[0] == 'B')
2103 node.type = removable;
2108 char extension[MAX_EXTENSION];
2109 GetExtension(node.name, extension);
2110 node.type = _FileType::SelectByExtension(extension);
2114 static FileSystemNode MakeFileSystemNode(const FileStats stats,
2115 const char * fileName, const char * filePath,
2116 const bool previewPicture, const DisplaySystem displaySystem)
2118 int len = strlen(fileName);
2119 char info[MAX_LOCATION];
2120 char name[MAX_LOCATION];
2121 char extension[MAX_EXTENSION];
2123 FileSystemNode node { stats = stats };
2125 //if(stats.attribs.isFile) // TODO fix this in ecere
2126 if(stats.attribs.isDirectory)
2128 extension[0] = '\0';
2130 node.type = (stats.attribs.isDrive) ? drive : folder;
2131 if(stats.attribs.isServer) node.type = server;
2132 if(stats.attribs.isShare) node.type = share;
2133 if(stats.attribs.isCDROM) node.type = cdrom;
2134 if(stats.attribs.isRemote) node.type = netDrive;
2135 if(stats.attribs.isRemovable)
2137 if(fileName[0] == 'A' || fileName[0] == 'B')
2140 node.type = removable;
2145 GetExtension(fileName, extension);
2148 node.type = _FileType::SelectByExtension(extension);
2151 if(stats.attribs.isDrive &&
2152 len > 3 && !strncmp(&fileName[1], ": [", 3))
2154 strncpy(name, fileName, 2);
2156 strncpy(info, &fileName[4], len - 5);
2161 strcpy(name, fileName);
2165 node.path = CopyString(filePath);
2166 node.name = CopyString(name);
2168 node.info = CopyString(info);
2169 node.extension = CopyString(extension);
2171 if(node.type == pictureFile && previewPicture)
2173 node.bitmap = Bitmap { alphaBlend = true };
2174 node.bitmap.Load(filePath, null, displaySystem);