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::NotifyNodeNavigate(FileSystemBox box, FileSystemNode node);
170 virtual bool Window::NotifyNodeOpen(FileSystemBox box, FileSystemNode node);
177 if(value && value[0])
178 path = CopyString(value);
180 locationBox.path = value;
186 //isset { return path && path[0]; }
189 property bool foldersOnly { set { bits.foldersOnly = value; bits.filesOnly = !value; } get { return bits.foldersOnly; } };
190 property bool filesOnly { set { bits.filesOnly = value; bits.foldersOnly = !value; } get { return bits.filesOnly; } };
191 property bool previewPictures { set { bits.previewPictures = value; } get { return bits.previewPictures; } };
192 property char * extensions { set { delete extensions; if(value && value[0]) extensions = CopyString(value); } get { return extensions; } }
193 property bool details { set { bits.details = value; } get { return bits.details; } };
194 property bool treeBranches
198 bits.treeBranches = value;
199 list.treeBranches = value;
200 list.collapseControl = value;
201 list.rootCollapseButton = value;
203 get { return bits.treeBranches; }
205 property bool navigateFolders { set { bits.navigateFolders = value; bits.filesOnly = !value; } get { return bits.navigateFolders; } };
206 property bool multiSelect { set { list.multiSelect = value; } get { return list.multiSelect; } };
207 property bool autoLoad { set { bits.autoLoad = value; } get { return bits.autoLoad; } };
209 property FileSystemNode node
217 if(!list.currentRow.tag)
219 return (FileSystemNode)list.currentRow.tag;
225 void Select(FileSystemNode node)
229 node.EnsureVisible(false);
230 list.SelectRow(node.row);
234 FileSystemNode SelectLocation(char * location)
238 char step[MAX_LOCATION];
240 //StringArray steps { growingFactor = 4 };
241 Array<String> steps { };
242 FileSystemNode result = null;
243 FileSystemNode node = null;
245 temp = CopyString(location);
248 GetLastDirectory(temp, step);
249 StripLastDirectory(temp, temp);
250 steps.Add(CopyString(step));
253 for(c = steps.count - 1; c >= 0; c--)
256 node = Find(steps[c], node);
274 FileSystemNode Find(const char * name, FileSystemNode parent)
276 FileSystemNode node = null;
277 FileSystemNode result = null;
278 if(!parent/* && !strcmp(name, "/")*/)
281 for(row = list.firstRow; row; row = row.next)
283 node = (FileSystemNode)row.tag;
284 if(node.name && !fstrcmp(node.name, name))
293 FileSystemNode start = parent ? parent : root;
294 if(!start.loaded || !start.childrenLoaded)
296 for(node = start.children.first; node; node = node.next)
297 if(node.name && !fstrcmp(node.name, name))
311 FileSystemBoxBits bits;
316 BitmapResource fileIcons[_FileType];
320 char wd[MAX_LOCATION];
321 GetWorkingDir(wd, sizeof(wd));
325 list.AddField(nameField);
326 bits.autoLoad = true;
336 for(c = 0; c < _FileType::enumSize; c++)
338 fileIcons[c] = BitmapResource { fileIconNames[c], alphaBlend = true };
339 AddResource(fileIcons[c]);
343 DataField nameField { dataType = "FileSystemNode", width = 240, userData = this, freeData = false };
344 DataField pathField { header = "Location", dataType = /*"String"*/ "char *", width = 100, freeData = false };
345 DataField typeField { header = "Type", dataType = /*"String"*/ "char *", width = 40, freeData = false };
346 DataField sizeField { header = "Size", dataType = "FileSize", width = 96, alignment = right, freeData = false };
360 hasHorzScroll = true;
361 hasVertScroll = true;
362 fullRowSelect = false;
365 anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
367 // WHY is this not working ?
368 /*void OnResize(int width, int height)
370 if(vertScroll.visible)
371 nameField.width = width - vertScroll.size.w;
373 nameField.width = width;
376 bool NotifyCollapse(ListBox listBox, DataRow row, bool collapsed)
380 FileSystemNode node = (FileSystemNode)row.tag;
381 FileSystemNode child;
385 for(child = node.children.last; child; child = node.children.last)
387 listBox.DeleteRow(child.row);
391 node.childrenLoaded = false;
396 if(!node.loaded || !node.childrenLoaded)
399 //list.Sort(nameField, 1);
402 for(child = node.children.first; child && child.next; child = child.next);
404 child.EnsureVisible(false);
410 bool NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods)
412 DataRow row = listBox.currentRow;
415 FileSystemNode node = (FileSystemNode)row.tag;
421 MenuItem { menu, "Cut\tCtrl+X", t, NotifySelect = null, disabled = false };
422 MenuItem { menu, "Copy\tCtrl+C", c, NotifySelect = null, disabled = false };
423 MenuItem { menu, "Paste\tCtrl+V", p, NotifySelect = null, disabled = false /*!clipboard*/ };
424 MenuItem { menu, "Delete\tDel", d, NotifySelect = null, disabled = false };
425 //MenuDivider { menu };
429 master = this, menu = menu,
431 x + clientStart.x + absPosition.x - guiApp.desktop.position.x,
432 y + clientStart.y + absPosition.y - guiApp.desktop.position.y }
440 bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
444 FileSystemNode node = (FileSystemNode)row.tag;
445 NotifyNodeSelect(listBox.parent.master, this, node);
451 bool NotifyEditing(ListBox listBox, DataRow row)
455 FileSystemNode node = (FileSystemNode)row.tag;
460 bool NotifyEdited(ListBox listBox, DataRow row)
464 FileSystemNode node = (FileSystemNode)row.tag;
469 bool NotifyEditDone(ListBox listBox, DataRow row)
473 FileSystemNode node = (FileSystemNode)row.tag;
478 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
480 bool result = !(selection && selection.type.isFolder && bits.navigateFolders);
485 bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
488 if((SmartKey)key == enter)
499 if(selection && selection.type.isFolder && bits.navigateFolders)
500 property::path = selection.path;
501 result = NotifyNodeOpen(this.master, this, selection);
506 Menu editMenu { menu, "Edit", e };
509 editMenu, "Cut\tCtrl+X", t, disabled = true;
511 bool NotifySelect(MenuItem selection, Modifiers mods)
517 MenuItem itemEditCopy
519 editMenu, "Copy\tCtrl+C", c, disabled = true;
521 bool NotifySelect(MenuItem selection, Modifiers mods)
527 MenuItem itemEditPaste
529 editMenu, "Paste\tCtrl+V", p;
531 bool NotifySelect(MenuItem selection, Modifiers mods)
537 MenuItem itemEditDelete
539 editMenu, "Delete\tDel", d, disabled = true;
541 bool NotifySelect(MenuItem selection, Modifiers mods)
548 // WHY is this crashing ?
549 /*void OnResize(int width, int height)
551 if(this && nameField)
552 nameField.width = width - 80;
558 // this is crashing in for designer when details = true // can't save the file, always yields a crash
559 /*if(list && created)
562 list.AddField(nameField);
565 list.AddField(typeField);
566 list.AddField(sizeField);
569 if(bits.treeBranches)
577 FileListing listing { path, extensions = extensions };
580 while(listing.Find())
582 if((!bits.foldersOnly && !bits.filesOnly) ||
583 (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
584 (bits.filesOnly && listing.stats.attribs.isFile))
586 FileSystemNode node = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
590 list.Sort(nameField, 1);
595 bool isRoot = !strcmp(path, "/");
596 //char startPath[MAX_LOCATION];
597 FileSystemNode parent;
599 FileListing listing { path, extensions = extensions };
602 GetWorkingDir(startPath, sizeof(startPath));
604 strcpy(path, startPath);*/
612 root = FileSystemNode { loaded = true, childrenLoaded = true };
613 AddTreeNode(root, true, false, null);
614 while(listing.Find())
616 int len = strlen(listing.name);
617 char info[MAX_LOCATION];
618 char name[MAX_LOCATION];
619 if(listing.stats.attribs.isDrive &&
620 len > 3 && !strncmp(&listing.name[1], ": [", 3))
622 strncpy(name, listing.name, 2);
624 strncpy(info, &listing.name[4], len - 5);
629 strcpy(name, listing.name);
633 parent = MakeFileSystemNode(listing.stats, name, listing.path, bits.previewPictures, displaySystem);
635 parent.info = CopyString(info);
636 parent.loaded = true;
637 AddTreeNode(parent, !listing.stats.attribs.isDirectory, listing.stats.attribs.isDirectory, root);
638 if(!listing.stats.attribs.isDirectory)
639 parent.childrenLoaded = true;
642 node = FileSystemNode { name = msNetwork, type = network };
643 AddTreeNode(node, false, true, null);
644 node.row.collapsed = true;
649 root = MakeFileSystemNode(FileStats { attribs = FileExists(path)}, path, path, bits.previewPictures, displaySystem);
650 AddTreeNode(root, false, true, null);
656 root.type = computer;
657 root.label = rootName;
660 list.Sort(nameField, 1);
661 list.SelectRow(root.row);
664 void LoadTreeNode(FileSystemNode node)
668 char path[MAX_LOCATION];
671 FileListing listing { path, extensions = extensions };
672 if(node.children.count == 1)
673 DeleteNode(node.children.first);
675 while(listing.Find())
677 if(!listing.stats.attribs.isRemovable && ((!bits.foldersOnly && !bits.filesOnly) ||
678 (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
679 (bits.filesOnly && listing.stats.attribs.isFile)))
681 FileSystemNode child = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
682 AddTreeNode(child, true, false, node);
683 NodeChildLoad(child, node);
687 node.childrenLoaded = true;
689 node.row.SortSubRows(false);
691 else if(!node.childrenLoaded)
693 FileSystemNode child;
694 if(node.children.first)
696 for(child = node.children.first; child; child = child.next)
700 else if(!child.childrenLoaded)
701 NodeChildLoad(child, node);
703 node.childrenLoaded = true;
704 node.row.SortSubRows(false);
709 void NodeChildLoad(FileSystemNode parent, FileSystemNode node)
711 char path[MAX_LOCATION];
712 parent.GetPath(path);
715 FileListing listing { path, extensions = extensions };
716 while(listing.Find())
718 if((!bits.foldersOnly && !bits.filesOnly) ||
719 (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
720 (bits.filesOnly && listing.stats.attribs.isFile))
722 FileSystemNode child = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
723 AddTreeNode(child, listing.stats.attribs.isFile, !listing.stats.attribs.isFile, parent);
730 parent.childrenLoaded = true;
733 void AddNode(FileSystemNode node)
735 DataRow row = list.AddRow();
737 row.SetData(nameField, node);
740 row.SetData(typeField, node.extension);
741 row.SetData(sizeField, (void *)node.stats.size);
745 void AddTreeNode(FileSystemNode node, bool loaded, bool addLoader, FileSystemNode addTo)
747 DataRow row = (addTo && addTo.row) ? addTo.row.AddRow() : list.AddRow();
751 node.indent = addTo.indent + 1;
752 addTo.children.Add(node);
756 row.SetData(null, node);
759 row.SetData(typeField, node.extension);
760 row.SetData(sizeField, (void *)node.stats.size);
763 node.loaded = loaded;
765 //AddTreeNode(FileSystemNode { }, false, false, node); // why would this create a compile error?
766 AddTreeNode(FileSystemNode { type = none }, false, false, node);
769 row.collapsed = true;
770 else if(node.type == folder)
771 node.type = folderOpen;
774 void DeleteNode(FileSystemNode node)
776 FileSystemNode child;
777 for(; (child = node.children.first); )
779 list.DeleteRow(node.row);
786 class ExplorerView : FileSystemBox
789 hasHorzScroll = false;
790 hasVertScroll = false;
792 virtual void Load(FileSystemNode parent);
793 virtual void Refresh();
795 virtual void LaunchNotifyItemSelect(Window master, ExplorerView view, ExplorerFileItem item, ExplorerFileItemArray selectedItems)
797 view.NotifyItemSelect(master, view, item, selectedItems);
800 virtual bool Window::NotifyItemSelect(ExplorerView view, ExplorerFileItem item, ExplorerFileItemArray selectedItems);
801 virtual bool Window::NotifyItemOpen(ExplorerView view, ExplorerFileItem item);
805 master = master, parent = this;
808 hasHorzScroll = true;
809 hasVertScroll = true;
812 fullRowSelect = false;
815 anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
817 bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
819 ExplorerView view = (ExplorerView)listBox.parent;
820 if(listBox.currentRow)
823 ExplorerFileItemArray selectedItems { growingFactor = 16 };
824 for(listRow = listBox.firstRow; listRow; listRow = listRow.next)
826 selectedItems.Add((ExplorerFileItem)listRow.tag);
827 //view.NotifyItemSelect(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
828 view.LaunchNotifyItemSelect(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag, selectedItems);
833 bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
835 ExplorerView view = (ExplorerView)listBox.parent;
836 view.NotifyItemOpen(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
840 bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
842 if((SmartKey)key == enter)
844 ExplorerView view = (ExplorerView)listBox.parent;
845 view.NotifyItemOpen(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
858 class ExplorerViewList : ExplorerView
861 FileSystemNode location;
865 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
867 ExplorerViewDetails()
869 list.AddField(nameField);
877 void Load(FileSystemNode location)
879 char path[MAX_LOCATION];
880 this.location = location;
881 location.GetPath(path);
883 FileListing listing { path };
885 ExplorerFileItem item;
890 while(listing.Find())
892 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
896 row.SetData(nameField, item);
898 list.Sort(nameField, 1);
905 class ExplorerViewDetails : ExplorerView
907 list.hasHeader = true;
908 list.moveFields = true;
909 list.resizable = true;
910 list.sortable = true;
912 FileSystemNode location;
916 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
917 DataField typeField { header = "Type", dataType = /-*"String"*-/ "char *", width = 40 };
918 DataField sizeField { header = "Size", dataType = "FileSize", width = 96, alignment = right };
920 ExplorerViewDetails()
922 list.AddField(nameField);
923 list.AddField(typeField);
924 list.AddField(sizeField);
932 void Load(FileSystemNode location)
934 char path[MAX_LOCATION];
935 this.location = location;
936 location.GetPath(path);
938 FileListing listing { path };
940 ExplorerFileItem item;
945 while(listing.Find())
947 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
951 row.SetData(nameField, item);
952 row.SetData(typeField, CopyString(item.extension));
953 row.SetData(sizeField, (uint)listing.stats.size);
955 list.Sort(nameField, 1);
962 class ExplorerViewIcons : ExplorerView
965 FileSystemNode location;
969 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
971 ExplorerViewDetails()
973 list.AddField(nameField);
981 void Load(FileSystemNode location)
983 char path[MAX_LOCATION];
984 this.location = location;
985 location.GetPath(path);
987 FileListing listing { path };
989 ExplorerFileItem item;
994 while(listing.Find())
996 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
1000 row.SetData(nameField, item);
1002 list.Sort(nameField, 1);
1009 class ExplorerViewCards : ExplorerView
1012 FileSystemNode location;
1016 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
1018 ExplorerViewDetails()
1020 list.AddField(nameField);
1028 void Load(FileSystemNode location)
1030 char path[MAX_LOCATION];
1031 this.location = location;
1032 location.GetPath(path);
1034 FileListing listing { path };
1036 ExplorerFileItem item;
1041 while(listing.Find())
1043 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
1045 row = list.AddRow();
1046 row.tag = (int)item;
1047 row.SetData(nameField, item);
1049 list.Sort(nameField, 1);
1056 public class BitmapArray : RedjArray
1058 type = class(Bitmap);
1061 Bitmap * Add(Bitmap bitmap)
1068 Bitmap * AddBefore(uint position, Bitmap bitmap)
1070 Insert(position, 1);
1071 _[position] = bitmap;
1072 return &_[position];
1077 for(c = 0; c < _count; c++)
1089 class ExplorerViewShowcase : ExplorerView
1091 list.anchor = Anchor { left = 0, top = 0, bottom = 0 };
1092 list.size = Size { w = 200 };
1094 FileSystemNode location;
1098 DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 180, editable = true, userData = this };
1101 BitmapArray bitmaps { growingFactor = 16 };
1107 anchor = Anchor { top = 0, right = 0, bottom = 0 };
1109 void OnRedraw(Surface surface)
1111 ExplorerViewShowcase view = (ExplorerViewShowcase)parent;
1114 int wBmp = view.bitmap.width;
1115 int hBmp = view.bitmap.height;
1116 int wWnd = clientSize.w;
1117 int hWnd = clientSize.h;
1119 int wList = view.list.size.w + view.split.size.w;
1121 float scale = Min((float)(wWnd - 10) / wBmp, (float)(hWnd - 10) / hBmp);
1123 int wDraw = (int)(wBmp * scale);
1124 int hDraw = (int)(hBmp * scale);
1127 surface.Filter(view.bitmap, (wWnd - wDraw) / 2, (hWnd - hDraw) / 2, 0, 0, wDraw, hDraw, wBmp, hBmp);
1129 // Until Filter / Stretch works with X
1130 surface.Blit(view.bitmap, (wWnd - wDraw) / 2, (hWnd - hDraw) / 2, 0, 0, wDraw, hDraw);
1135 surface.SetForeground(white);
1136 surface.Area(0, 0, view.clientSize.w - 1, view.clientSize.h - 1);
1150 ExplorerViewDetails()
1152 list.AddField(nameField);
1155 void LaunchNotifyItemSelect(Window master, ExplorerViewShowcase view, ExplorerFileItem item, ExplorerFileItemArray selectedItems)
1158 ExplorerFileItem selItem;
1162 if(item && item.type == pictureFile)
1164 view.bitmap = Bitmap { };
1165 view.bitmap.Load(item.path, null, displaySystem);
1168 view.bitmaps.Clear();
1169 view.bitmaps = BitmapArray { };
1170 for(pos = 0; pos < selectedItems.count; pos++)
1173 selItem = (ExplorerFileItem)selectedItems._[pos];
1174 bitmap.Load(selItem.path, null, displaySystem);
1175 //view.bitmaps.Add(bitmap);
1177 if(item && item.type == pictureFile)
1179 view.bitmap = Bitmap { };
1180 view.bitmap.Load(item.path, null, displaySystem);
1183 view.show.Update(null);
1184 view.NotifyItemSelect(master, view, item, selectedItems);
1192 void Load(FileSystemNode location)
1194 char path[MAX_LOCATION];
1195 this.location = location;
1196 location.GetPath(path);
1198 FileListing listing { path };
1200 ExplorerFileItem item;
1205 while(listing.Find())
1207 item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
1209 row = list.AddRow();
1210 row.tag = (int)item;
1211 row.SetData(nameField, item);
1213 list.Sort(nameField, 1);
1220 class ExplorerTree : FileSystemBox
1222 hasHorzScroll = false;
1223 hasVertScroll = false;
1229 DataField nameField { dataType = "FileSystemNode", width = 240, userData = this };
1231 FileSystemNode root;
1232 FileSystemNode selection;
1234 virtual bool Window::NotifyNodeSelect(ExplorerTree tree, FileSystemNode node);
1236 property FileSystemNode node
1242 if(!tree.currentRow)
1244 if(!tree.currentRow.tag)
1246 return (FileSystemNode)tree.currentRow.tag;
1250 void Select(FileSystemNode node)
1254 node.EnsureVisible(false);
1255 tree.SelectRow(node.row);
1259 FileSystemNode Find(const char * name, FileSystemNode parent)
1261 FileSystemNode node;
1262 FileSystemNode start = parent ? parent : root;
1263 if(!start.loaded || !start.childrenLoaded)
1264 LoadTreeNode(start, tree);
1265 for(node = start.children.first; node; node = node.next)
1266 if(node.name && !strcmpi(node.name, name))
1273 master = master, parent = this;
1276 hasHorzScroll = true;
1277 hasVertScroll = true;
1278 fullRowSelect = false;
1280 collapseControl = true;
1281 rootCollapseButton = true;
1283 anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
1285 // WHY is this not working ?
1286 /-*void OnResize(int width, int height)
1288 if(vertScroll.visible)
1289 nameField.width = width - vertScroll.size.w;
1291 nameField.width = width;
1294 bool NotifyCollapse(ListBox listBox, DataRow row, bool collapsed)
1298 FileSystemNode node = (FileSystemNode)row.tag;
1299 FileSystemNode child;
1303 for(child = node.children.last; child; child = node.children.last)
1305 listBox.DeleteRow(child.row);
1309 node.childrenLoaded = false;
1314 if(!node.loaded || !node.childrenLoaded)
1315 LoadTreeNode(node, tree);
1316 for(child = node.children.first; child && child.next; child = child.next);
1318 child.EnsureVisible(false);
1324 bool NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods)
1326 DataRow row = listBox.currentRow;
1329 FileSystemNode node = (FileSystemNode)row.tag;
1335 MenuItem { menu, "Cut\tCtrl+X", t, NotifySelect = null, disabled = false };
1336 MenuItem { menu, "Copy\tCtrl+C", c, NotifySelect = null, disabled = false };
1337 MenuItem { menu, "Paste\tCtrl+V", p, NotifySelect = null, disabled = false /-*!clipboard*-/ };
1338 MenuItem { menu, "Delete\tDel", d, NotifySelect = null, disabled = false };
1339 //MenuDivider { menu };
1343 master = this, menu = menu,
1345 x + clientStart.x + absPosition.x - guiApp.desktop.position.x,
1346 y + clientStart.y + absPosition.y - guiApp.desktop.position.y }
1354 bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
1358 FileSystemNode node = (FileSystemNode)row.tag;
1359 NotifyNodeSelect(listBox.parent.master, this, node);
1365 bool NotifyEditing(ListBox listBox, DataRow row)
1369 FileSystemNode node = (FileSystemNode)row.tag;
1374 bool NotifyEdited(ListBox listBox, DataRow row)
1378 FileSystemNode node = (FileSystemNode)row.tag;
1383 bool NotifyEditDone(ListBox listBox, DataRow row)
1387 FileSystemNode node = (FileSystemNode)row.tag;
1394 Menu editMenu { menu, "Edit", e };
1395 MenuItem itemEditCut
1397 editMenu, "Cut\tCtrl+X", t, disabled = true;
1399 bool NotifySelect(MenuItem selection, Modifiers mods)
1405 MenuItem itemEditCopy
1407 editMenu, "Copy\tCtrl+C", c, disabled = true;
1409 bool NotifySelect(MenuItem selection, Modifiers mods)
1415 MenuItem itemEditPaste
1417 editMenu, "Paste\tCtrl+V", p;
1419 bool NotifySelect(MenuItem selection, Modifiers mods)
1425 MenuItem itemEditDelete
1427 editMenu, "Delete\tDel", d, disabled = true;
1429 bool NotifySelect(MenuItem selection, Modifiers mods)
1436 // WHY is this crashing ?
1437 /-*void OnResize(int width, int height)
1439 if(this && nameField)
1440 nameField.width = width - 80;
1445 tree.AddField(nameField);
1450 FileSystemNode parent;
1451 FileSystemNode node;
1452 FileListing listing { "/" };
1456 root = FileSystemNode { type = computer, loaded = true, childrenLoaded = true };
1458 root.name = rootName;
1462 AddTreeNode(root, true, false, null, tree);
1464 // How can this make sense for linux?
1466 while(listing.Find())
1468 int len = strlen(listing.name);
1469 char info[MAX_LOCATION];
1470 char name[MAX_LOCATION];
1471 if(listing.stats.attribs.isDrive &&
1472 len > 3 && !strncmp(&listing.name[1], ": [", 3))
1474 strncpy(name, listing.name, 2);
1476 strncpy(info, &listing.name[4], len - 5);
1481 strcpy(name, listing.name);
1485 parent = MakeFileSystemNode(listing.stats, name);
1487 parent.info = CopyString(info);
1488 parent.loaded = true;
1489 AddTreeNode(parent, !listing.stats.attribs.isDirectory, listing.stats.attribs.isDirectory, root, tree);
1490 if(!listing.stats.attribs.isDirectory)
1491 parent.childrenLoaded = true;
1494 node = FileSystemNode { name = msNetwork, type = network };
1495 AddTreeNode(node, false, true, null, tree);
1496 node.row.collapsed = true;
1497 tree.Sort(nameField, 1);
1498 tree.SelectRow(root.row);
1503 public class ClipBoardFiles
1517 int size = SelSize();
1520 // Try to allocate memory
1521 ClipBoard clipBoard { };
1522 if(clipBoard.Allocate(size+1))
1524 GetSel(clipBoard.memory, true);
1537 ClipBoard clipBoard { };
1538 if(clipBoard.Load())
1539 PutS(clipBoard.memory);
1550 SetViewToCursor(true);
1556 Private Type DROPFILES
1562 For iCounter = 0 To filelist.ListCount - 1
1563 If filelist.Selected(iCounter) = True Then
1564 strFiles = strFiles & FixPath(filelist.Path) & filelist.List(iCounter) & vbNullChar
1567 'all selected items are now put in strFiles
1569 hGlobal = GlobalAlloc(GHND, Len(DF) + Len(strFiles)) 'put all files to a exclusive number
1570 If hGlobal Then 'if the globalalloc worked
1571 lpGlobal = GlobalLock(hGlobal) 'lock the hGlobal
1572 DF.pFiles = Len(DF) 'set the size of the files
1574 Call CopyMem(ByVal lpGlobal, DF, Len(DF)) 'copy df to the lpglobal
1575 Call CopyMem(ByVal (lpGlobal + Len(DF)), ByVal strFiles, Len(strFiles)) 'copy strfiles to lpglobal
1576 Call GlobalUnlock(hGlobal) 'unlock hglobal again
1578 SetClipboardData CF_HDROP, hGlobal 'put files to the clipboard
1581 bool SaveFile(const char * filePath)
1587 public class FileTreeNodeBSArray : ArrayBinarySorted
1589 type = class(FileSystemNode);
1591 FileSystemNode * const _;
1592 BSloc Add(FileSystemNode item)
1594 BSloc result = Find(item);
1597 Insert(result.pos, 1);
1598 _[result.pos] = item;
1602 BSloc Remove(FileSystemNode item)
1610 public class FileTreeNodeArray : RedjArray
1612 type = class(FileSystemNode);
1614 FileSystemNode * const _;
1615 FileSystemNode * Add(FileSystemNode item)
1622 FileSystemNode * AddBefore(uint position, FileSystemNode item)
1624 Insert(position, 1);
1626 return &_[position];
1632 public class ExplorerFileItem : struct
1643 void OnDisplay(Surface surface, int x, int y, int width, FileSystemBox control, Alignment alignment, DataDisplayFlags displayFlags)
1645 int indentSize = (displayFlags.dropBox) ? 0 : 10;
1648 char label[MAX_FILENAME];
1650 //float scale = Min((float)clientSize.w / (float)bitmap.width, (float)clientSize.h / (float)bitmap.height);
1651 int w = 16; //(int)(bitmap.width * scale);
1652 int h = 16; //(int)(bitmap.height * scale);
1656 icon = control.fileIcons[type].bitmap;
1659 if(type == folder || type == folderOpen)
1660 surface.SetForeground(red); //Color { 170, 170, 0 } // REDJ What is that color?
1663 textOffset = indent * indentSize + (icon ? (icon.width + 6) : 0);
1666 sprintf(label, "%s [%s]", name, info);
1668 strcpy(label, name);
1669 len = strlen(label);
1671 surface.WriteTextDots
1672 (alignment, x + textOffset, y + 2, width - textOffset, label, len);
1673 if(type == pictureFile && control.previewPictures && bitmap)
1676 //surface.Filter(bitmap, (clientSize.w - w) / 2,(clientSize.h - h) / 2, 0,0, w, h, bitmap.width, bitmap.height);
1677 surface.Filter(bitmap, x + indent * indentSize + 2, y, 0, 0, w, h, bitmap.width, bitmap.height);
1679 // Until Filter / Stretch works with X
1680 //surface.Blit(bitmap, (clientSize.w - bitmap.width) / 2,(clientSize.h - bitmap.height) / 2, 0,0, bitmap.width, bitmap.height);
1681 surface.blend = true;
1682 surface.Blit(bitmap, x + indent * indentSize + 2, y,0,0, w, h);
1688 surface.Blit(icon, x + indent * indentSize + 2, y,0,0, icon.width, icon.height);
1691 int OnCompare(ExplorerFileItem b)
1694 if(type == b.type || (type < folder && b.type < folder) || (type >= drive))
1695 result = strcmpi(name, b.name);
1698 if(type == folder && b.type < folder) result = -1;
1699 else if(type < folder && b.type == folder) result = 1;
1704 void OnCopy(ExplorerFileItem newData)
1706 type = newData.type;
1707 indent = newData.indent;
1710 int len = strlen(newData.name) + 1;
1711 name = new char[len];
1712 CopyBytes(name, newData.name, len);
1716 bool OnGetDataFromString(char * string)
1718 int len = strlen(string) + 1;
1719 name = new char[len];
1720 CopyBytes(name, string, len);
1734 char * OnGetString(char * string, void * fieldData, bool * needClass)
1740 public class ExplorerFileItemArray : RedjArray
1742 type = class(ExplorerFileItem);
1744 ExplorerFileItem * const _;
1745 ExplorerFileItem * Add(ExplorerFileItem item)
1752 ExplorerFileItem * AddBefore(uint position, ExplorerFileItem item)
1754 Insert(position, 1);
1756 return &_[position];
1761 for(c = 0; c < _count; c++)
1771 ExplorerFileItem MakeFileItem(const FileAttribs attribs, const char * fileName, const char * filePath, const bool previewPicture, const DisplaySystem displaySystem)
1773 int len = strlen(fileName);
1774 char info[MAX_LOCATION];
1775 char name[MAX_LOCATION];
1776 char extension[MAX_EXTENSION];
1778 ExplorerFileItem item { };
1780 //if(stats.attribs.isFile) // -- should work now
1781 if(attribs.isDirectory)
1785 item.type = (attribs.isDrive) ? drive : folder;
1786 if(attribs.isServer)
1792 if(attribs.isRemote)
1793 item.type = netDrive;
1794 if(attribs.isRemovable)
1796 if(fileName[0] == 'A' || fileName[0] == 'B')
1799 item.type = removable;
1804 GetExtension(fileName, extension);
1805 //strupr(extension);
1808 item.type = _FileType::SelectByExtension(extension);
1811 if(attribs.isDrive &&
1812 len > 3 && !strncmp(&fileName[1], ": [", 3))
1814 strncpy(name, fileName, 2);
1816 strncpy(info, &fileName[4], len - 5);
1821 strcpy(name, fileName);
1825 item.path = CopyString(filePath);
1826 item.name = CopyString(name);
1828 item.info = CopyString(info);
1829 item.extension = CopyString(extension);
1831 if(item.type == pictureFile && previewPicture)
1833 item.bitmap = Bitmap { };
1834 item.bitmap.Load(filePath, null, displaySystem);
1842 public class FileSystemNode : struct
1845 /*//LinkElement<FileSystemNode> link;
1846 FileSystemNode parent;
1848 FileSystemNodeType type;
1852 FileSystemNode prev, next;
1854 bool loaded, childrenLoaded;
1864 FileSystemNode parent;
1870 void GetPath(String outputPath)
1876 strcpy(outputPath, name);
1877 for(up = parent; up; up = up.parent)
1879 char temp[MAX_LOCATION];
1880 strcpy(temp, up.name);
1881 PathCat(temp, outputPath);
1882 strcpy(outputPath, temp);
1888 strcpy(outputPath, "/");
1890 //strcpy(outputPath, name);
1891 strcpy(outputPath, path);
1892 PathCat(outputPath, name);
1897 bool IsChildOf(FileSystemNode node)
1899 FileSystemNode test;
1900 for(test = parent; test; test = test.parent)
1906 void DuplicateChildren(bool recursive, bool forceExpanded, FileSystemNode addTo, FileSystemBox fsb)
1910 FileSystemNode child;
1912 for(child = children.first; child; child = child.next)
1914 FileSystemNode copy { };
1915 copy.name = CopyString(child.name);
1916 copy.type = child.type;
1917 fsb.AddTreeNode(copy, child.loaded, false, addTo);
1919 copy.row.collapsed = false;
1921 child.DuplicateChildren(recursive, forceExpanded, copy, fsb);
1926 void EnsureVisible(bool expand)
1929 parent.EnsureVisible(true);
1931 row.collapsed = false;
1932 // TODO: row.EnsureVisible(); // making the row visible by scrolling
1942 FileSystemNode child;
1943 for(; (child = children.first); )
1946 children.Delete(child);
1958 parent.children.Delete(this);
1961 void OnDisplay(Surface surface, int x, int y, int width, FileSystemBox fsb, Alignment alignment, DataDisplayFlags displayFlags)
1963 //int indentSize = (displayFlags.dropBox) ? 0 : 10;
1969 char string[MAX_FILENAME];
1976 icon = fsb.fileIcons[type].bitmap;
1977 //xStart = indent * indent + x + (icon ? (icon.width + 5) : 0);
1978 xStart = x + (icon ? (icon.width + 5) : 0);
1984 sprintf(string, "%s [%s]", label ? label : name, info);
1986 strcpy(string, label ? label : name);
1987 len = strlen(string);
1991 if(type == folder || type == folderOpen)
1992 surface.SetForeground(yellow);
1996 //textOffset = indent * indentSize + (icon ? (icon.width + 4) : 0);
1998 surface.TextOpacity(false);
1999 surface.TextExtent(string, len, &w, &h);
2002 // Draw the current row stipple
2003 if(displayFlags.selected)
2004 //surface.Area(xStart - 1, y, xStart - 1, y + h - 1);
2005 //surface.Area(xStart + w - 1, y, xStart + w + 1, y + h - 1);
2006 surface.Area(xStart - 3, y, xStart + w + 1, y + h - 1);
2008 //surface.WriteTextDots(alignment, x + textOffset, y + 2, width - textOffset, name, strlen(name));
2009 surface.WriteTextDots(alignment, xStart, y + 2, width, string, len);
2011 if(!guiApp.textMode)
2013 if(displayFlags.current)
2015 if(displayFlags.active)
2017 surface.LineStipple(0x5555);
2018 if(displayFlags.selected)
2019 surface.SetForeground(0xFFFFFF80);
2021 surface.SetForeground(black);
2025 surface.SetForeground(selectionColor);
2027 surface.Rectangle(xStart - 3, y, xStart + w + 1, y + h - 1);
2028 surface.LineStipple(0);
2036 if(type == pictureFile && fsb.previewPictures && bitmap)
2038 surface.SetForeground(white);
2039 surface.blend = true;
2041 //surface.Filter(bitmap, (clientSize.w - w) / 2,(clientSize.h - h) / 2, 0,0, w, h, bitmap.width, bitmap.height);
2042 //surface.Filter(bitmap, x + indent/* * indentSize*/ + 2, y, 0, 0, w, h, bitmap.width, bitmap.height);
2043 surface.Filter(bitmap, x,y,0,0, w, h, bitmap.width, bitmap.height);
2045 // Until Filter / Stretch works with X
2046 //surface.Blit(bitmap, (clientSize.w - bitmap.width) / 2,(clientSize.h - bitmap.height) / 2, 0,0, bitmap.width, bitmap.height);
2047 // surface.blend = true;
2048 //surface.Blit(bitmap, x + indent/* * indentSize*/ + 2, y,0,0, w, h);
2049 //surface.Blit(bitmap, x,y,0,0, bitmap.width, bitmap.height);
2056 //surface.blend = true;
2057 //surface.alphaWrite = blend;
2058 surface.SetForeground(white);
2059 //surface.Blit(icon, x + indent * indentSize, y,0,0, icon.width, icon.height);
2060 surface.Blit(icon, x,y,0,0, icon.width, icon.height);
2065 int OnCompare(FileSystemNode b)
2068 FileSystemNode a = this;
2069 if(a.type == b.type || (a.type < folder && b.type < folder) || (a.type >= drive))
2070 result = strcmpi(a.name, b.name);
2073 if(a.type == folder && b.type < folder) result = -1;
2074 else if(a.type < folder && b.type == folder) result = 1;
2080 /*int OnCompare(FileSystemNode b)
2083 FileSystemNode a = this;
2084 if(a.parent < b.parent) result = -1;
2085 else if(a.parent > b.parent) result = 1;
2087 result = fstrcmp(a.name, b.name);
2091 char * OnGetString(char * tempString, FileSystemToolWindow fileSysToolWnd, bool * needClass)
2093 return name ? name : "";
2097 /*FileSystemNode MakeFileSystemNode(const FileStats stats, const char * name)
2099 FileSystemNode node { stats = stats };
2100 node.name = CopyString(name);
2103 if(stats.attribs.isDirectory)
2105 node.type = (stats.attribs.isDrive) ? drive : folder;
2106 if(stats.attribs.isServer) node.type = server;
2107 if(stats.attribs.isShare) node.type = share;
2108 if(stats.attribs.isCDROM) node.type = cdrom;
2109 if(stats.attribs.isRemote) node.type = netDrive;
2110 if(stats.attribs.isRemovable)
2112 if(name[0] == 'A' || name[0] == 'B')
2115 node.type = removable;
2120 char extension[MAX_EXTENSION];
2121 GetExtension(node.name, extension);
2122 node.type = _FileType::SelectByExtension(extension);
2127 FileSystemNode MakeFileSystemNode(const FileStats stats,
2128 const char * fileName, const char * filePath,
2129 const bool previewPicture, const DisplaySystem displaySystem)
2131 int len = strlen(fileName);
2132 char info[MAX_LOCATION];
2133 char name[MAX_LOCATION];
2134 char extension[MAX_EXTENSION];
2136 FileSystemNode node { stats = stats };
2138 //if(stats.attribs.isFile) // TODO fix this in ecere
2139 if(stats.attribs.isDirectory)
2141 extension[0] = '\0';
2143 node.type = (stats.attribs.isDrive) ? drive : folder;
2144 if(stats.attribs.isServer) node.type = server;
2145 if(stats.attribs.isShare) node.type = share;
2146 if(stats.attribs.isCDROM) node.type = cdrom;
2147 if(stats.attribs.isRemote) node.type = netDrive;
2148 if(stats.attribs.isRemovable)
2150 if(fileName[0] == 'A' || fileName[0] == 'B')
2153 node.type = removable;
2158 GetExtension(fileName, extension);
2161 node.type = _FileType::SelectByExtension(extension);
2164 if(stats.attribs.isDrive &&
2165 len > 3 && !strncmp(&fileName[1], ": [", 3))
2167 strncpy(name, fileName, 2);
2169 strncpy(info, &fileName[4], len - 5);
2174 strcpy(name, fileName);
2178 node.path = CopyString(filePath);
2179 node.name = CopyString(name);
2181 node.info = CopyString(info);
2182 node.extension = CopyString(extension);
2184 if(node.type == pictureFile && previewPicture)
2186 node.bitmap = Bitmap { alphaBlend = true };
2187 node.bitmap.Load(filePath, null, displaySystem);