+ bool NotifySelect(MenuItem selection, Modifiers mods)
+ {
+ //EditDelete();
+ return true;
+ }
+ };
+
+ // WHY is this crashing ?
+ /*void OnResize(int width, int height)
+ {
+ if(this && nameField)
+ nameField.width = width - 80;
+ }*/
+
+ void Load()
+ {
+ // TODO: fix this!
+ // this is crashing in for designer when details = true // can't save the file, always yields a crash
+ /*if(list && created)
+ {
+ list.ClearFields();
+ list.AddField(nameField);
+ if(bits.details)
+ {
+ list.AddField(typeField);
+ list.AddField(sizeField);
+ }
+ }*/
+ if(bits.treeBranches)
+ LoadTree();
+ else
+ LoadList();
+ }
+
+ void LoadList()
+ {
+ FileListing listing { path, extensions = extensions };
+
+ list.Clear();
+ while(listing.Find())
+ {
+ if((!bits.foldersOnly && !bits.filesOnly) ||
+ (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
+ (bits.filesOnly && !listing.stats.attribs.isDirectory/*listing.stats.attribs.isFile*/)) // TOCHECK: isFile broken?
+ {
+ FileSystemNode node = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
+ DataRow row = list.AddRow();
+ row.tag = (int)node;
+ row.SetData(nameField, node);
+ if(bits.details)
+ {
+ row.SetData(typeField, node.extension);
+ row.SetData(sizeField, (void *)node.stats.size);
+ }
+ }
+ }
+ list.Sort(nameField, 1);
+ }
+
+ void LoadTree()
+ {
+ //char startPath[MAX_LOCATION];
+ FileSystemNode parent;
+ FileSystemNode node;
+ FileListing listing { path, extensions = extensions };
+
+ /*if(!path)
+ GetWorkingDir(startPath, sizeof(startPath));
+ else
+ strcpy(path, startPath);*/
+
+ list.Clear();
+
+ delete root;
+ #ifdef __WIN32__
+ root = FileSystemNode { type = computer, loaded = true, childrenLoaded = true };
+ root.name = rootName;
+ AddTreeNode(root, true, false, null);
+ #else
+ root = MakeFileSystemNode(FileStats { attribs = FileExists(path)}, path, path, bits.previewPictures, displaySystem);
+ //root.name = "/";
+ root.type = computer;
+ AddTreeNode(root, false, true, null);
+ #endif
+
+ #ifdef __WIN32__
+ while(listing.Find())
+ {
+ int len = strlen(listing.name);
+ char info[MAX_LOCATION];
+ char name[MAX_LOCATION];
+ if(listing.stats.attribs.isDrive &&
+ len > 3 && !strncmp(&listing.name[1], ": [", 3))
+ {
+ strncpy(name, listing.name, 2);
+ name[2] = 0;
+ strncpy(info, &listing.name[4], len - 5);
+ info[len - 5] = 0;
+ }
+ else
+ {
+ strcpy(name, listing.name);
+ info[0] = 0;
+ }
+
+ parent = MakeFileSystemNode(listing.stats, name);
+ if(info[0])
+ parent.info = CopyString(info);
+ parent.loaded = true;
+ AddTreeNode(parent, !listing.stats.attribs.isDirectory, listing.stats.attribs.isDirectory, root, this);
+ if(!listing.stats.attribs.isDirectory)
+ parent.childrenLoaded = true;
+ }
+
+ node = FileSystemNode { name = msNetwork, type = network };
+ AddTreeNode(node, false, true, null, this);
+ node.row.collapsed = true;
+ Sort(nameField, 1);
+ SelectRow(root.row);
+ #endif
+ LoadTreeNode(root);
+ list.Sort(nameField, 1);
+ }
+
+ void LoadTreeNode(FileSystemNode node)
+ {
+ if(!node.loaded)
+ {
+ char path[MAX_LOCATION];
+ node.GetPath(path);
+ {
+ FileListing listing { path, extensions = extensions };
+ if(node.children.count == 1)
+ DeleteNode(node.children.first);
+
+ while(listing.Find())
+ {
+ if((!bits.foldersOnly && !bits.filesOnly) ||
+ (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
+ (bits.filesOnly && !listing.stats.attribs.isDirectory/*listing.stats.attribs.isFile*/)) // TOCHECK: isFile broken?
+ {
+ FileSystemNode child = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
+ AddTreeNode(child, true, false, node);
+ NodeChildLoad(child, node);
+ }
+ }
+ }
+ node.childrenLoaded = true;
+ node.loaded = true;
+ node.row.SortSubRows(false);
+ }
+ else if(!node.childrenLoaded)
+ {
+ FileSystemNode child;
+ if(node.children.first)
+ {
+ for(child = node.children.first; child; child = child.next)
+ {
+ if(!child.loaded)
+ LoadTreeNode(child);
+ else if(!child.childrenLoaded)
+ NodeChildLoad(child, node);
+ }
+ node.childrenLoaded = true;
+ node.row.SortSubRows(false);
+ }
+ }
+ }
+
+ void NodeChildLoad(FileSystemNode parent, FileSystemNode node)
+ {
+ char path[MAX_LOCATION];
+ parent.GetPath(path);
+ {
+ bool added = false;
+ FileListing listing { path, extensions = extensions };
+ while(listing.Find())
+ {
+ if((!bits.foldersOnly && !bits.filesOnly) ||
+ (bits.foldersOnly && listing.stats.attribs.isDirectory) ||
+ (bits.filesOnly && !listing.stats.attribs.isDirectory/*listing.stats.attribs.isFile*/)) // TOCHECK: isFile broken?
+ {
+ FileSystemNode child = MakeFileSystemNode(listing.stats, listing.name, listing.path, bits.previewPictures, displaySystem);
+ AddTreeNode(child, true, false, parent);
+ added = true;
+ }
+ }
+ if(!added)
+ added = true;
+ }
+ //parent.childrenLoaded = true;
+ }
+
+ void AddTreeNode(FileSystemNode node, bool loaded, bool addLoader, FileSystemNode addTo)
+ {
+ DataRow row = (addTo && addTo.row) ? addTo.row.AddRow() : list.AddRow();
+ if(addTo)
+ {
+ node.parent = addTo;
+ node.indent = addTo.indent + 1;
+ addTo.children.Add(node);
+ }
+ row.tag = (int)node;
+ node.row = row;
+ row.SetData(null, node);
+
+ node.loaded = loaded;
+ if(addLoader)
+ //AddTreeNode(FileSystemNode { }, false, false, node); // why would this create a compile error?
+ AddTreeNode(FileSystemNode { type = none }, false, false, node);
+
+ if(node.indent > 0)
+ row.collapsed = true;
+ else if(node.type == folder)
+ node.type = folderOpen;
+ }
+
+ void DeleteNode(FileSystemNode node)
+ {
+ FileSystemNode child;
+ for(; (child = node.children.first); )
+ DeleteNode(child);
+ list.DeleteRow(node.row);
+ node.Delete();
+ }
+}
+
+/*
+#if 0
+class ExplorerView : FileSystemBox
+{
+ borderStyle = none;
+ hasHorzScroll = false;
+ hasVertScroll = false;
+
+ virtual void Load(FileSystemNode parent);
+ virtual void Refresh();
+
+ virtual void LaunchNotifyItemSelect(Window master, ExplorerView view, ExplorerFileItem item, ExplorerFileItemArray selectedItems)
+ {
+ view.NotifyItemSelect(master, view, item, selectedItems);
+ }
+
+ virtual bool Window::NotifyItemSelect(ExplorerView view, ExplorerFileItem item, ExplorerFileItemArray selectedItems);
+ virtual bool Window::NotifyItemOpen(ExplorerView view, ExplorerFileItem item);
+
+ ListBox list
+ {
+ master = master, parent = this;
+ //this, master;
+ borderStyle = none;
+ hasHorzScroll = true;
+ hasVertScroll = true;
+ resizable = true;
+ sortable = true;
+ fullRowSelect = false;
+ multiSelect = true;
+
+ anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
+
+ bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods)
+ {
+ ExplorerView view = (ExplorerView)listBox.parent;
+ if(listBox.currentRow)
+ {
+ DataRow listRow;
+ ExplorerFileItemArray selectedItems { growingFactor = 16 };
+ for(listRow = listBox.firstRow; listRow; listRow = listRow.next)
+ if(listRow.selected)
+ selectedItems.Add((ExplorerFileItem)listRow.tag);
+ //view.NotifyItemSelect(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
+ view.LaunchNotifyItemSelect(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag, selectedItems);
+ }
+ return true;
+ }
+
+ bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
+ {
+ ExplorerView view = (ExplorerView)listBox.parent;
+ view.NotifyItemOpen(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
+ return false;
+ }
+
+ bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
+ {
+ if((SmartKey)key == enter)
+ {
+ ExplorerView view = (ExplorerView)listBox.parent;
+ view.NotifyItemOpen(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
+ }
+ return true;
+ }
+ };
+
+ ExplorerView()
+ {
+ }
+}
+#endif
+
+#if 0
+class ExplorerViewList : ExplorerView
+{
+
+ FileSystemNode location;
+
+public:
+
+ DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
+
+ ExplorerViewDetails()
+ {
+ list.AddField(nameField);
+ }
+
+ void Refresh()
+ {
+ Load(location);
+ }
+
+ void Load(FileSystemNode location)
+ {
+ char path[MAX_LOCATION];
+ this.location = location;
+ location.GetPath(path);
+ {
+ FileListing listing { path };
+
+ ExplorerFileItem item;
+ DataRow row;
+
+ list.Clear();
+
+ while(listing.Find())
+ {
+ item = MakeFileItem(listing.stats.attribs, listing.name, listing.path, previewPictures, displaySystem);
+
+ row = list.AddRow();
+ row.tag = (int)item;
+ row.SetData(nameField, item);
+ }
+ list.Sort(nameField, 1);
+ }
+ }
+}
+#endif
+
+#if 0
+class ExplorerViewDetails : ExplorerView
+{
+ list.hasHeader = true;
+ list.moveFields = true;
+ list.resizable = true;
+ list.sortable = true;
+
+ FileSystemNode location;
+
+public:
+
+ DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
+ DataField typeField { header = "Type", dataType = /-*"String"*-/ "char *", width = 40 };
+ DataField sizeField { header = "Size", dataType = "FileSize", width = 96, alignment = right };
+
+ ExplorerViewDetails()
+ {
+ list.AddField(nameField);
+ list.AddField(typeField);
+ list.AddField(sizeField);
+ }
+
+ void Refresh()
+ {
+ Load(location);
+ }
+
+ void Load(FileSystemNode location)
+ {
+ char path[MAX_LOCATION];
+ this.location = location;
+ location.GetPath(path);
+ {
+ FileListing listing { path };
+
+ ExplorerFileItem item;
+ DataRow row;
+
+ list.Clear();