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);
588 list.Sort(nameField, 1);
593 bool isRoot = !strcmp(path, "/");
594 //char startPath[MAX_LOCATION];
595 FileSystemNode parent;
597 FileListing listing { path, extensions = extensions };
600 GetWorkingDir(startPath, sizeof(startPath));
602 strcpy(path, startPath);*/
610 root = FileSystemNode { loaded = true, childrenLoaded = true };
611 AddTreeNode(root, true, false, null);
612 while(listing.Find())
614 int len = strlen(listing.name);
615 char info[MAX_LOCATION];
616 char name[MAX_LOCATION];
617 if(listing.stats.attribs.isDrive &&
618 len > 3 && !strncmp(&listing.name[1], ": [", 3))
620 strncpy(name, listing.name, 2);
622 strncpy(info, &listing.name[4], len - 5);
627 strcpy(name, listing.name);
631 parent = MakeFileSystemNode(listing.stats, name, listing.path, bits.previewPictures, displaySystem);
633 parent.info = CopyString(info);
634 parent.loaded = true;
635 AddTreeNode(parent, !listing.stats.attribs.isDirectory, listing.stats.attribs.isDirectory, root);
636 if(!listing.stats.attribs.isDirectory)
637 parent.childrenLoaded = true;
640 node = FileSystemNode { name = msNetwork, type = network };
641 AddTreeNode(node, false, true, null);
642 node.row.collapsed = true;
647 root = MakeFileSystemNode(FileStats { attribs = FileExists(path)}, path, path, bits.previewPictures, displaySystem);
648 AddTreeNode(root, false, true, null);
654 root.type = computer;
655 root.label = rootName;
658 list.Sort(nameField, 1);
659 list.SelectRow(root.row);
662 void LoadTreeNode(FileSystemNode node)
666 char path[MAX_LOCATION];
669 FileListing listing { path, extensions = extensions };
670 if(node.children.count == 1)
671 DeleteNode(node.children.first);
673 while(listing.Find())
675 if(!listing.stats.attribs.isRemovable && ((!bits.foldersOnly && !bits.filesOnly) ||
676 (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
677 (bits.filesOnly && listing.stats.attribs.isFile)))
679 FileSystemNode child = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
680 AddTreeNode(child, true, false, node);
681 NodeChildLoad(child, node);
685 node.childrenLoaded = true;
687 node.row.SortSubRows(false);
689 else if(!node.childrenLoaded)
691 FileSystemNode child;
692 if(node.children.first)
694 for(child = node.children.first; child; child = child.next)
698 else if(!child.childrenLoaded)
699 NodeChildLoad(child, node);
701 node.childrenLoaded = true;
702 node.row.SortSubRows(false);
707 void NodeChildLoad(FileSystemNode parent, FileSystemNode node)
709 char path[MAX_LOCATION];
710 parent.GetPath(path);
713 FileListing listing { path, extensions = extensions };
714 while(listing.Find())
716 if((!bits.foldersOnly && !bits.filesOnly) ||
717 (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
718 (bits.filesOnly && listing.stats.attribs.isFile))
720 FileSystemNode child = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
721 AddTreeNode(child, listing.stats.attribs.isFile, !listing.stats.attribs.isFile, parent);
728 parent.childrenLoaded = true;
731 void AddNode(FileSystemNode node)
733 DataRow row = list.AddRow();
735 row.SetData(nameField, node);
738 row.SetData(typeField, node.extension);
739 row.SetData(sizeField, (void *)node.stats.size);
743 void AddTreeNode(FileSystemNode node, bool loaded, bool addLoader, FileSystemNode addTo)
745 DataRow row = (addTo && addTo.row) ? addTo.row.AddRow() : list.AddRow();
749 node.indent = addTo.indent + 1;
750 addTo.children.Add(node);
754 row.SetData(null, node);
757 row.SetData(typeField, node.extension);
758 row.SetData(sizeField, (void *)node.stats.size);
761 node.loaded = loaded;
763 //AddTreeNode(FileSystemNode { }, false, false, node); // why would this create a compile error?
764 AddTreeNode(FileSystemNode { type = none }, false, false, node);
767 row.collapsed = true;
768 else if(node.type == folder)
769 node.type = folderOpen;
772 void DeleteNode(FileSystemNode node)
774 FileSystemNode child;
775 for(; (child = node.children.first); )
777 list.DeleteRow(node.row);
784 class ExplorerView : FileSystemBox
787 hasHorzScroll = false;
788 hasVertScroll = false;
790 virtual void Load(FileSystemNode parent);
791 virtual void Refresh();
793 virtual void LaunchNotifyItemSelect(Window master, ExplorerView view, ExplorerFileItem item, ExplorerFileItemArray selectedItems)
795 view.NotifyItemSelect(master, view, item, selectedItems);
798 virtual bool Window::NotifyItemSelect(ExplorerView view, ExplorerFileItem item, ExplorerFileItemArray selectedItems);
799 virtual bool Window::NotifyItemOpen(ExplorerView view, ExplorerFileItem item);
803 master = master, parent = this;
806 hasHorzScroll = true;
807 hasVertScroll = true;
810 fullRowSelect = false;
813 anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
815 bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
817 ExplorerView view = (ExplorerView)listBox.parent;
818 if(listBox.currentRow)
821 ExplorerFileItemArray selectedItems { growingFactor = 16 };
822 for(listRow = listBox.firstRow; listRow; listRow = listRow.next)
824 selectedItems.Add((ExplorerFileItem)listRow.tag);
825 //view.NotifyItemSelect(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
826 view.LaunchNotifyItemSelect(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag, selectedItems);
831 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
833 ExplorerView view = (ExplorerView)listBox.parent;
834 view.NotifyItemOpen(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
838 bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
840 if((SmartKey)key == enter)
842 ExplorerView view = (ExplorerView)listBox.parent;
843 view.NotifyItemOpen(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
856 class ExplorerViewList : ExplorerView
859 FileSystemNode location;
863 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
865 ExplorerViewDetails()
867 list.AddField(nameField);
875 void Load(FileSystemNode location)
877 char path[MAX_LOCATION];
878 this.location = location;
879 location.GetPath(path);
881 FileListing listing { path };
883 ExplorerFileItem item;
888 while(listing.Find())
890 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
894 row.SetData(nameField, item);
896 list.Sort(nameField, 1);
903 class ExplorerViewDetails : ExplorerView
905 list.hasHeader = true;
906 list.moveFields = true;
907 list.resizable = true;
908 list.sortable = true;
910 FileSystemNode location;
914 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
915 DataField typeField { header = "Type", dataType = /-*"String"*-/ "char *", width = 40 };
916 DataField sizeField { header = "Size", dataType = "FileSize", width = 96, alignment = right };
918 ExplorerViewDetails()
920 list.AddField(nameField);
921 list.AddField(typeField);
922 list.AddField(sizeField);
930 void Load(FileSystemNode location)
932 char path[MAX_LOCATION];
933 this.location = location;
934 location.GetPath(path);
936 FileListing listing { path };
938 ExplorerFileItem item;
943 while(listing.Find())
945 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
949 row.SetData(nameField, item);
950 row.SetData(typeField, CopyString(item.extension));
951 row.SetData(sizeField, (uint)listing.stats.size);
953 list.Sort(nameField, 1);
960 class ExplorerViewIcons : ExplorerView
963 FileSystemNode location;
967 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
969 ExplorerViewDetails()
971 list.AddField(nameField);
979 void Load(FileSystemNode location)
981 char path[MAX_LOCATION];
982 this.location = location;
983 location.GetPath(path);
985 FileListing listing { path };
987 ExplorerFileItem item;
992 while(listing.Find())
994 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
998 row.SetData(nameField, item);
1000 list.Sort(nameField, 1);
1007 class ExplorerViewCards : ExplorerView
1010 FileSystemNode location;
1014 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
1016 ExplorerViewDetails()
1018 list.AddField(nameField);
1026 void Load(FileSystemNode location)
1028 char path[MAX_LOCATION];
1029 this.location = location;
1030 location.GetPath(path);
1032 FileListing listing { path };
1034 ExplorerFileItem item;
1039 while(listing.Find())
1041 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
1043 row = list.AddRow();
1044 row.tag = (int)item;
1045 row.SetData(nameField, item);
1047 list.Sort(nameField, 1);
1054 public class BitmapArray : RedjArray
1056 type = class(Bitmap);
1059 Bitmap * Add(Bitmap bitmap)
1066 Bitmap * AddBefore(uint position, Bitmap bitmap)
1068 Insert(position, 1);
1069 _[position] = bitmap;
1070 return &_[position];
1075 for(c = 0; c < _count; c++)
1087 class ExplorerViewShowcase : ExplorerView
1089 list.anchor = Anchor { left = 0, top = 0, bottom = 0 };
1090 list.size = Size { w = 200 };
1092 FileSystemNode location;
1096 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 180, editable = true, userData = this };
1099 BitmapArray bitmaps { growingFactor = 16 };
1105 anchor = Anchor { top = 0, right = 0, bottom = 0 };
1107 void OnRedraw(Surface surface)
1109 ExplorerViewShowcase view = (ExplorerViewShowcase)parent;
1112 int wBmp = view.bitmap.width;
1113 int hBmp = view.bitmap.height;
1114 int wWnd = clientSize.w;
1115 int hWnd = clientSize.h;
1117 int wList = view.list.size.w + view.split.size.w;
1119 float scale = Min((float)(wWnd - 10) / wBmp, (float)(hWnd - 10) / hBmp);
1121 int wDraw = (int)(wBmp * scale);
1122 int hDraw = (int)(hBmp * scale);
1125 surface.Filter(view.bitmap, (wWnd - wDraw) / 2, (hWnd - hDraw) / 2, 0, 0, wDraw, hDraw, wBmp, hBmp);
1127 // Until Filter / Stretch works with X
1128 surface.Blit(view.bitmap, (wWnd - wDraw) / 2, (hWnd - hDraw) / 2, 0, 0, wDraw, hDraw);
1133 surface.SetForeground(white);
1134 surface.Area(0, 0, view.clientSize.w - 1, view.clientSize.h - 1);
1148 ExplorerViewDetails()
1150 list.AddField(nameField);
1153 void LaunchNotifyItemSelect(Window master, ExplorerViewShowcase view, ExplorerFileItem item, ExplorerFileItemArray selectedItems)
1156 ExplorerFileItem selItem;
1160 if(item && item.type == pictureFile)
1162 view.bitmap = Bitmap { };
1163 view.bitmap.Load(item.path, null, displaySystem);
1166 view.bitmaps.Clear();
1167 view.bitmaps = BitmapArray { };
1168 for(pos = 0; pos < selectedItems.count; pos++)
1171 selItem = (ExplorerFileItem)selectedItems._[pos];
1172 bitmap.Load(selItem.path, null, displaySystem);
1173 //view.bitmaps.Add(bitmap);
1175 if(item && item.type == pictureFile)
1177 view.bitmap = Bitmap { };
1178 view.bitmap.Load(item.path, null, displaySystem);
1181 view.show.Update(null);
1182 view.NotifyItemSelect(master, view, item, selectedItems);
1190 void Load(FileSystemNode location)
1192 char path[MAX_LOCATION];
1193 this.location = location;
1194 location.GetPath(path);
1196 FileListing listing { path };
1198 ExplorerFileItem item;
1203 while(listing.Find())
1205 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
1207 row = list.AddRow();
1208 row.tag = (int)item;
1209 row.SetData(nameField, item);
1211 list.Sort(nameField, 1);
1218 class ExplorerTree : FileSystemBox
1220 hasHorzScroll = false;
1221 hasVertScroll = false;
1227 DataField nameField { dataType = "FileSystemNode", width = 240, userData = this };
1229 FileSystemNode root;
1230 FileSystemNode selection;
1232 virtual bool Window::NotifyNodeSelect(ExplorerTree tree, FileSystemNode node);
1234 property FileSystemNode node
1240 if(!tree.currentRow)
1242 if(!tree.currentRow.tag)
1244 return (FileSystemNode)tree.currentRow.tag;
1248 void Select(FileSystemNode node)
1252 node.EnsureVisible(false);
1253 tree.SelectRow(node.row);
1257 FileSystemNode Find(const char * name, FileSystemNode parent)
1259 FileSystemNode node;
1260 FileSystemNode start = parent ? parent : root;
1261 if(!start.loaded || !start.childrenLoaded)
1262 LoadTreeNode(start, tree);
1263 for(node = start.children.first; node; node = node.next)
1264 if(node.name && !strcmpi(node.name, name))
1271 master = master, parent = this;
1274 hasHorzScroll = true;
1275 hasVertScroll = true;
1276 fullRowSelect = false;
1278 collapseControl = true;
1279 rootCollapseButton = true;
1281 anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
1283 // WHY is this not working ?
1284 /-*void OnResize(int width, int height)
1286 if(vertScroll.visible)
1287 nameField.width = width - vertScroll.size.w;
1289 nameField.width = width;
1292 bool NotifyCollapse(ListBox listBox, DataRow row, bool collapsed)
1296 FileSystemNode node = (FileSystemNode)row.tag;
1297 FileSystemNode child;
1301 for(child = node.children.last; child; child = node.children.last)
1303 listBox.DeleteRow(child.row);
1307 node.childrenLoaded = false;
1312 if(!node.loaded || !node.childrenLoaded)
1313 LoadTreeNode(node, tree);
1314 for(child = node.children.first; child && child.next; child = child.next);
1316 child.EnsureVisible(false);
1322 bool NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods)
1324 DataRow row = listBox.currentRow;
1327 FileSystemNode node = (FileSystemNode)row.tag;
1333 MenuItem { menu, "Cut\tCtrl+X", t, NotifySelect = null, disabled = false };
1334 MenuItem { menu, "Copy\tCtrl+C", c, NotifySelect = null, disabled = false };
1335 MenuItem { menu, "Paste\tCtrl+V", p, NotifySelect = null, disabled = false /-*!clipboard*-/ };
1336 MenuItem { menu, "Delete\tDel", d, NotifySelect = null, disabled = false };
1337 //MenuDivider { menu };
1341 master = this, menu = menu,
1343 x + clientStart.x + absPosition.x - guiApp.desktop.position.x,
1344 y + clientStart.y + absPosition.y - guiApp.desktop.position.y }
1352 bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
1356 FileSystemNode node = (FileSystemNode)row.tag;
1357 NotifyNodeSelect(listBox.parent.master, this, node);
1363 bool NotifyEditing(ListBox listBox, DataRow row)
1367 FileSystemNode node = (FileSystemNode)row.tag;
1372 bool NotifyEdited(ListBox listBox, DataRow row)
1376 FileSystemNode node = (FileSystemNode)row.tag;
1381 bool NotifyEditDone(ListBox listBox, DataRow row)
1385 FileSystemNode node = (FileSystemNode)row.tag;
1392 Menu editMenu { menu, "Edit", e };
1393 MenuItem itemEditCut
1395 editMenu, "Cut\tCtrl+X", t, disabled = true;
1397 bool NotifySelect(MenuItem selection, Modifiers mods)
1403 MenuItem itemEditCopy
1405 editMenu, "Copy\tCtrl+C", c, disabled = true;
1407 bool NotifySelect(MenuItem selection, Modifiers mods)
1413 MenuItem itemEditPaste
1415 editMenu, "Paste\tCtrl+V", p;
1417 bool NotifySelect(MenuItem selection, Modifiers mods)
1423 MenuItem itemEditDelete
1425 editMenu, "Delete\tDel", d, disabled = true;
1427 bool NotifySelect(MenuItem selection, Modifiers mods)
1434 // WHY is this crashing ?
1435 /-*void OnResize(int width, int height)
1437 if(this && nameField)
1438 nameField.width = width - 80;
1443 tree.AddField(nameField);
1448 FileSystemNode parent;
1449 FileSystemNode node;
1450 FileListing listing { "/" };
1454 root = FileSystemNode { type = computer, loaded = true, childrenLoaded = true };
1456 root.name = rootName;
1460 AddTreeNode(root, true, false, null, tree);
1462 // How can this make sense for linux?
1464 while(listing.Find())
1466 int len = strlen(listing.name);
1467 char info[MAX_LOCATION];
1468 char name[MAX_LOCATION];
1469 if(listing.stats.attribs.isDrive &&
1470 len > 3 && !strncmp(&listing.name[1], ": [", 3))
1472 strncpy(name, listing.name, 2);
1474 strncpy(info, &listing.name[4], len - 5);
1479 strcpy(name, listing.name);
1483 parent = MakeFileSystemNode(listing.stats, name);
1485 parent.info = CopyString(info);
1486 parent.loaded = true;
1487 AddTreeNode(parent, !listing.stats.attribs.isDirectory, listing.stats.attribs.isDirectory, root, tree);
1488 if(!listing.stats.attribs.isDirectory)
1489 parent.childrenLoaded = true;
1492 node = FileSystemNode { name = msNetwork, type = network };
1493 AddTreeNode(node, false, true, null, tree);
1494 node.row.collapsed = true;
1495 tree.Sort(nameField, 1);
1496 tree.SelectRow(root.row);
1501 public class ClipBoardFiles
1515 int size = SelSize();
1518 // Try to allocate memory
1519 ClipBoard clipBoard { };
1520 if(clipBoard.Allocate(size+1))
1522 GetSel(clipBoard.memory, true);
1535 ClipBoard clipBoard { };
1536 if(clipBoard.Load())
1537 PutS(clipBoard.memory);
1548 SetViewToCursor(true);
1554 Private Type DROPFILES
1560 For iCounter = 0 To filelist.ListCount - 1
1561 If filelist.Selected(iCounter) = True Then
1562 strFiles = strFiles & FixPath(filelist.Path) & filelist.List(iCounter) & vbNullChar
1565 'all selected items are now put in strFiles
1567 hGlobal = GlobalAlloc(GHND, Len(DF) + Len(strFiles)) 'put all files to a exclusive number
1568 If hGlobal Then 'if the globalalloc worked
1569 lpGlobal = GlobalLock(hGlobal) 'lock the hGlobal
1570 DF.pFiles = Len(DF) 'set the size of the files
1572 Call CopyMem(ByVal lpGlobal, DF, Len(DF)) 'copy df to the lpglobal
1573 Call CopyMem(ByVal (lpGlobal + Len(DF)), ByVal strFiles, Len(strFiles)) 'copy strfiles to lpglobal
1574 Call GlobalUnlock(hGlobal) 'unlock hglobal again
1576 SetClipboardData CF_HDROP, hGlobal 'put files to the clipboard
1579 bool SaveFile(const char * filePath)
1585 public class FileTreeNodeBSArray : ArrayBinarySorted
1587 type = class(FileSystemNode);
1589 FileSystemNode * const _;
1590 BSloc Add(FileSystemNode item)
1592 BSloc result = Find(item);
1595 Insert(result.pos, 1);
1596 _[result.pos] = item;
1600 BSloc Remove(FileSystemNode item)
1608 public class FileTreeNodeArray : RedjArray
1610 type = class(FileSystemNode);
1612 FileSystemNode * const _;
1613 FileSystemNode * Add(FileSystemNode item)
1620 FileSystemNode * AddBefore(uint position, FileSystemNode item)
1622 Insert(position, 1);
1624 return &_[position];
1630 public class ExplorerFileItem : struct
1641 void OnDisplay(Surface surface, int x, int y, int width, FileSystemBox control, Alignment alignment, DataDisplayFlags displayFlags)
1643 int indentSize = (displayFlags.dropBox) ? 0 : 10;
1646 char label[MAX_FILENAME];
1648 //float scale = Min((float)clientSize.w / (float)bitmap.width, (float)clientSize.h / (float)bitmap.height);
1649 int w = 16; //(int)(bitmap.width * scale);
1650 int h = 16; //(int)(bitmap.height * scale);
1654 icon = control.fileIcons[type].bitmap;
1657 if(type == folder || type == folderOpen)
1658 surface.SetForeground(red); //Color { 170, 170, 0 } // REDJ What is that color?
1661 textOffset = indent * indentSize + (icon ? (icon.width + 6) : 0);
1664 sprintf(label, "%s [%s]", name, info);
1666 strcpy(label, name);
1667 len = strlen(label);
1669 surface.WriteTextDots
1670 (alignment, x + textOffset, y + 2, width - textOffset, label, len);
1671 if(type == pictureFile && control.previewPictures && bitmap)
1674 //surface.Filter(bitmap, (clientSize.w - w) / 2,(clientSize.h - h) / 2, 0,0, w, h, bitmap.width, bitmap.height);
1675 surface.Filter(bitmap, x + indent * indentSize + 2, y, 0, 0, w, h, bitmap.width, bitmap.height);
1677 // Until Filter / Stretch works with X
1678 //surface.Blit(bitmap, (clientSize.w - bitmap.width) / 2,(clientSize.h - bitmap.height) / 2, 0,0, bitmap.width, bitmap.height);
1679 surface.blend = true;
1680 surface.Blit(bitmap, x + indent * indentSize + 2, y,0,0, w, h);
1686 surface.Blit(icon, x + indent * indentSize + 2, y,0,0, icon.width, icon.height);
1689 int OnCompare(ExplorerFileItem b)
1692 if(type == b.type || (type < folder && b.type < folder) || (type >= drive))
1693 result = strcmpi(name, b.name);
1696 if(type == folder && b.type < folder) result = -1;
1697 else if(type < folder && b.type == folder) result = 1;
1702 void OnCopy(ExplorerFileItem newData)
1704 type = newData.type;
1705 indent = newData.indent;
1708 int len = strlen(newData.name) + 1;
1709 name = new char[len];
1710 CopyBytes(name, newData.name, len);
1714 bool OnGetDataFromString(char * string)
1716 int len = strlen(string) + 1;
1717 name = new char[len];
1718 CopyBytes(name, string, len);
1732 char * OnGetString(char * string, void * fieldData, bool * needClass)
1738 public class ExplorerFileItemArray : RedjArray
1740 type = class(ExplorerFileItem);
1742 ExplorerFileItem * const _;
1743 ExplorerFileItem * Add(ExplorerFileItem item)
1750 ExplorerFileItem * AddBefore(uint position, ExplorerFileItem item)
1752 Insert(position, 1);
1754 return &_[position];
1759 for(c = 0; c < _count; c++)
1769 ExplorerFileItem MakeFileItem(const FileAttribs attribs, const char * fileName, const char * filePath, const bool previewPicture, const DisplaySystem displaySystem)
1771 int len = strlen(fileName);
1772 char info[MAX_LOCATION];
1773 char name[MAX_LOCATION];
1774 char extension[MAX_EXTENSION];
1776 ExplorerFileItem item { };
1778 //if(stats.attribs.isFile) // -- should work now
1779 if(attribs.isDirectory)
1783 item.type = (attribs.isDrive) ? drive : folder;
1784 if(attribs.isServer)
1790 if(attribs.isRemote)
1791 item.type = netDrive;
1792 if(attribs.isRemovable)
1794 if(fileName[0] == 'A' || fileName[0] == 'B')
1797 item.type = removable;
1802 GetExtension(fileName, extension);
1803 //strupr(extension);
1806 item.type = _FileType::SelectByExtension(extension);
1809 if(attribs.isDrive &&
1810 len > 3 && !strncmp(&fileName[1], ": [", 3))
1812 strncpy(name, fileName, 2);
1814 strncpy(info, &fileName[4], len - 5);
1819 strcpy(name, fileName);
1823 item.path = CopyString(filePath);
1824 item.name = CopyString(name);
1826 item.info = CopyString(info);
1827 item.extension = CopyString(extension);
1829 if(item.type == pictureFile && previewPicture)
1831 item.bitmap = Bitmap { };
1832 item.bitmap.Load(filePath, null, displaySystem);
1840 public class FileSystemNode : struct
1843 /*//LinkElement<FileSystemNode> link;
1844 FileSystemNode parent;
1846 FileSystemNodeType type;
1850 FileSystemNode prev, next;
1852 bool loaded, childrenLoaded;
1862 FileSystemNode parent;
1868 void GetPath(String outputPath)
1874 strcpy(outputPath, name);
1875 for(up = parent; up; up = up.parent)
1877 char temp[MAX_LOCATION];
1878 strcpy(temp, up.name);
1879 PathCat(temp, outputPath);
1880 strcpy(outputPath, temp);
1886 strcpy(outputPath, "/");
1888 //strcpy(outputPath, name);
1889 strcpy(outputPath, path);
1890 PathCat(outputPath, name);
1895 bool IsChildOf(FileSystemNode node)
1897 FileSystemNode test;
1898 for(test = parent; test; test = test.parent)
1904 void DuplicateChildren(bool recursive, bool forceExpanded, FileSystemNode addTo, FileSystemBox fsb)
1908 FileSystemNode child;
1910 for(child = children.first; child; child = child.next)
1912 FileSystemNode copy { };
1913 copy.name = CopyString(child.name);
1914 copy.type = child.type;
1915 fsb.AddTreeNode(copy, child.loaded, false, addTo);
1917 copy.row.collapsed = false;
1919 child.DuplicateChildren(recursive, forceExpanded, copy, fsb);
1924 void EnsureVisible(bool expand)
1927 parent.EnsureVisible(true);
1929 row.collapsed = false;
1930 // TODO: row.EnsureVisible(); // making the row visible by scrolling
1940 FileSystemNode child;
1941 for(; (child = children.first); )
1944 children.Delete(child);
1956 parent.children.Delete(this);
1959 void OnDisplay(Surface surface, int x, int y, int width, FileSystemBox fsb, Alignment alignment, DataDisplayFlags displayFlags)
1961 //int indentSize = (displayFlags.dropBox) ? 0 : 10;
1967 char string[MAX_FILENAME];
1974 icon = fsb.fileIcons[type].bitmap;
1975 //xStart = indent * indent + x + (icon ? (icon.width + 5) : 0);
1976 xStart = x + (icon ? (icon.width + 5) : 0);
1982 sprintf(string, "%s [%s]", label ? label : name, info);
1984 strcpy(string, label ? label : name);
1985 len = strlen(string);
1989 if(type == folder || type == folderOpen)
1990 surface.SetForeground(yellow);
1994 //textOffset = indent * indentSize + (icon ? (icon.width + 4) : 0);
1996 surface.TextOpacity(false);
1997 surface.TextExtent(string, len, &w, &h);
2000 // Draw the current row stipple
2001 if(displayFlags.selected)
2002 //surface.Area(xStart - 1, y, xStart - 1, y + h - 1);
2003 //surface.Area(xStart + w - 1, y, xStart + w + 1, y + h - 1);
2004 surface.Area(xStart - 3, y, xStart + w + 1, y + h - 1);
2006 //surface.WriteTextDots(alignment, x + textOffset, y + 2, width - textOffset, name, strlen(name));
2007 surface.WriteTextDots(alignment, xStart, y + 2, width, string, len);
2009 if(!guiApp.textMode)
2011 if(displayFlags.current)
2013 if(displayFlags.active)
2015 surface.LineStipple(0x5555);
2016 if(displayFlags.selected)
2017 surface.SetForeground(0xFFFFFF80);
2019 surface.SetForeground(black);
2023 surface.SetForeground(selectionColor);
2025 surface.Rectangle(xStart - 3, y, xStart + w + 1, y + h - 1);
2026 surface.LineStipple(0);
2034 if(type == pictureFile && fsb.previewPictures && bitmap)
2036 surface.SetForeground(white);
2037 surface.blend = true;
2039 //surface.Filter(bitmap, (clientSize.w - w) / 2,(clientSize.h - h) / 2, 0,0, w, h, bitmap.width, bitmap.height);
2040 //surface.Filter(bitmap, x + indent/* * indentSize*/ + 2, y, 0, 0, w, h, bitmap.width, bitmap.height);
2041 surface.Filter(bitmap, x,y,0,0, w, h, bitmap.width, bitmap.height);
2043 // Until Filter / Stretch works with X
2044 //surface.Blit(bitmap, (clientSize.w - bitmap.width) / 2,(clientSize.h - bitmap.height) / 2, 0,0, bitmap.width, bitmap.height);
2045 // surface.blend = true;
2046 //surface.Blit(bitmap, x + indent/* * indentSize*/ + 2, y,0,0, w, h);
2047 //surface.Blit(bitmap, x,y,0,0, bitmap.width, bitmap.height);
2054 //surface.blend = true;
2055 //surface.alphaWrite = blend;
2056 surface.SetForeground(white);
2057 //surface.Blit(icon, x + indent * indentSize, y,0,0, icon.width, icon.height);
2058 surface.Blit(icon, x,y,0,0, icon.width, icon.height);
2063 int OnCompare(FileSystemNode b)
2066 FileSystemNode a = this;
2067 if(a.type == b.type || (a.type < folder && b.type < folder) || (a.type >= drive))
2068 result = strcmpi(a.name, b.name);
2071 if(a.type == folder && b.type < folder) result = -1;
2072 else if(a.type < folder && b.type == folder) result = 1;
2078 /*int OnCompare(FileSystemNode b)
2081 FileSystemNode a = this;
2082 if(a.parent < b.parent) result = -1;
2083 else if(a.parent > b.parent) result = 1;
2085 result = fstrcmp(a.name, b.name);
2089 char * OnGetString(char * tempString, FileSystemToolWindow fileSysToolWnd, bool * needClass)
2091 return name ? name : "";
2095 /*FileSystemNode MakeFileSystemNode(const FileStats stats, const char * name)
2097 FileSystemNode node { stats = stats };
2098 node.name = CopyString(name);
2101 if(stats.attribs.isDirectory)
2103 node.type = (stats.attribs.isDrive) ? drive : folder;
2104 if(stats.attribs.isServer) node.type = server;
2105 if(stats.attribs.isShare) node.type = share;
2106 if(stats.attribs.isCDROM) node.type = cdrom;
2107 if(stats.attribs.isRemote) node.type = netDrive;
2108 if(stats.attribs.isRemovable)
2110 if(name[0] == 'A' || name[0] == 'B')
2113 node.type = removable;
2118 char extension[MAX_EXTENSION];
2119 GetExtension(node.name, extension);
2120 node.type = _FileType::SelectByExtension(extension);
2125 FileSystemNode MakeFileSystemNode(const FileStats stats,
2126 const char * fileName, const char * filePath,
2127 const bool previewPicture, const DisplaySystem displaySystem)
2129 int len = strlen(fileName);
2130 char info[MAX_LOCATION];
2131 char name[MAX_LOCATION];
2132 char extension[MAX_EXTENSION];
2134 FileSystemNode node { stats = stats };
2136 //if(stats.attribs.isFile) // TODO fix this in ecere
2137 if(stats.attribs.isDirectory)
2139 extension[0] = '\0';
2141 node.type = (stats.attribs.isDrive) ? drive : folder;
2142 if(stats.attribs.isServer) node.type = server;
2143 if(stats.attribs.isShare) node.type = share;
2144 if(stats.attribs.isCDROM) node.type = cdrom;
2145 if(stats.attribs.isRemote) node.type = netDrive;
2146 if(stats.attribs.isRemovable)
2148 if(fileName[0] == 'A' || fileName[0] == 'B')
2151 node.type = removable;
2156 GetExtension(fileName, extension);
2159 node.type = _FileType::SelectByExtension(extension);
2162 if(stats.attribs.isDrive &&
2163 len > 3 && !strncmp(&fileName[1], ": [", 3))
2165 strncpy(name, fileName, 2);
2167 strncpy(info, &fileName[4], len - 5);
2172 strcpy(name, fileName);
2176 node.path = CopyString(filePath);
2177 node.name = CopyString(name);
2179 node.info = CopyString(info);
2180 node.extension = CopyString(extension);
2182 if(node.type == pictureFile && previewPicture)
2184 node.bitmap = Bitmap { alphaBlend = true };
2185 node.bitmap.Load(filePath, null, displaySystem);