From 83e8917d600247319d0cbe9dc79991d7bef99638 Mon Sep 17 00:00:00 2001 From: Rejean Loyer Date: Wed, 14 Sep 2011 01:28:05 -0400 Subject: [PATCH 1/1] libide: ExplorerControl becomes FileSystemBox. (bulk commit) --- libede/src/FileSystemBox.ec | 845 ++++++++++++++++++++++++++++++++++++-------- 1 file changed, 704 insertions(+), 141 deletions(-) diff --git a/libede/src/FileSystemBox.ec b/libede/src/FileSystemBox.ec index cdd7aa2..201b508 100644 --- a/libede/src/FileSystemBox.ec +++ b/libede/src/FileSystemBox.ec @@ -8,7 +8,7 @@ static char * rootName = "File System"; #endif private: -define guiApp = ((GuiApplication)__thisModule); +define guiApp = ((GuiApplication)__thisModule); // how to do this in a dll? define selectionColor = guiApp.currentSkin.selectionColor; //Color { 10, 36, 106 }; static char * fileIconNames[] = @@ -137,13 +137,137 @@ public enum _FileType } }; -class ExplorerControl : Window +class FileSystemBoxBits { - bool previewPictures; + bool foldersOnly:1, filesOnly:1, details:1, treeBranches:1, previewPictures:1, navigateFolders:1; + //bool header:1, freeSelect:1, fullRowSelect:1, multiSelect:1, autoScroll:1, alwaysHL : 1, moveRows:1, resizable:1; + //bool moveFields:1, clearHeader:1, alwaysEdit:1, collapse:1, treeBranch:1, rootCollapse:1, heightSet:1; + //bool sortable:1, noDragging:1, fillLastField:1, expandOnAdd:1; +}; + +public class FileSystemBox : Window // should we not derive from ListBox instead? +/* + this stuff from the listbox would be nicely exposed... + fullRowSelect = false; + treeBranches = true; + collapseControl = true; + rootCollapseButton = true; + sortable = true; +*/ +{ + borderStyle = deep; + hasHorzScroll = false; + hasVertScroll = false; + + menu = Menu { }; + +public: + FileSystemNode root; + FileSystemNode selection; + + virtual bool Window::NotifyNodeSelect(FileSystemBox box, FileSystemNode node); + virtual bool Window::NotifyNodeOpen(FileSystemBox box, FileSystemNode node); + + property char * path + { + set + { + delete path; + if(value && value[0]) + path = CopyString(value); + if(locationBox) + locationBox.path = value; + if(created) + Load(); + } + + get { return path; } + //isset { return path && path[0]; } + } + + property bool foldersOnly { set { bits.foldersOnly = value; bits.filesOnly = !value; } get { return bits.foldersOnly; } }; + property bool filesOnly { set { bits.filesOnly = value; bits.foldersOnly = !value; } get { return bits.filesOnly; } }; + property bool previewPictures { set { bits.previewPictures = value; } get { return bits.previewPictures; } }; + property char * extensions { set { delete extensions; if(value && value[0]) extensions = CopyString(value); } get { return extensions; } } + property bool details { set { bits.details = value; } get { return bits.details; } }; + property bool treeBranches + { + set + { + bits.treeBranches = value; + list.treeBranches = value; + list.collapseControl = value; + list.rootCollapseButton = value; + } + get { return bits.treeBranches; } + }; + property bool navigateFolders { set { bits.navigateFolders = value; bits.foldersOnly = !value; } get { return bits.navigateFolders; } }; + + property FileSystemNode node + { + get + { + if(!list) + return null; + if(!list.currentRow) + return null; + if(!list.currentRow.tag) + return null; + return (FileSystemNode)list.currentRow.tag; + } + } + + PathBox locationBox; + + void Select(FileSystemNode node) + { + if(node.row) + { + node.EnsureVisible(false); + list.SelectRow(node.row); + } + } + + FileSystemNode Find(const char * name, FileSystemNode parent) + { + FileSystemNode node; + FileSystemNode start = parent ? parent : root; + if(!start.loaded || !start.childrenLoaded) + LoadTreeNode(start); + for(node = start.children.first; node; node = node.next) + if(node.name && !strcmpi(node.name, name)) + return node; + return null; + } + + void Refresh() + { + Load(); + } + +private: + FileSystemBoxBits bits; + + char * path; + char * extensions; BitmapResource fileIcons[_FileType]; - ExplorerControl() + FileSystemBox() + { + char wd[MAX_LOCATION]; + GetWorkingDir(wd, sizeof(wd)); + property::path = wd; + + InitFileIcons(); + list.AddField(nameField); + } + ~FileSystemBox() + { + delete extensions; + delete path; + } + void InitFileIcons() { _FileType c; for(c = 0; c < _FileType::enumSize; c++) @@ -152,10 +276,435 @@ class ExplorerControl : Window AddResource(fileIcons[c]); } } + + DataField nameField { dataType = "FileSystemNode", width = 240, userData = this, freeData = false }; + DataField typeField { header = "Type", dataType = /*"String"*/ "char *", width = 40, freeData = false }; + DataField sizeField { header = "Size", dataType = "FileSize", width = 96, alignment = right, freeData = false }; + + bool OnPostCreate() + { + Load(); + return true; + } + + ListBox list + { + this; + + borderStyle = none; + hasHorzScroll = true; + hasVertScroll = true; + fullRowSelect = false; + sortable = true; + + anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 }; + + // WHY is this not working ? + /*void OnResize(int width, int height) + { + if(vertScroll.visible) + nameField.width = width - vertScroll.size.w; + else + nameField.width = width; + }*/ + + bool NotifyCollapse(ListBox listBox, DataRow row, bool collapsed) + { + if(row) + { + FileSystemNode node = (FileSystemNode)row.tag; + FileSystemNode child; + if(collapsed) + { + /* + for(child = node.children.last; child; child = node.children.last) + { + listBox.DeleteRow(child.row); + child.Free(); + delete child; + } + node.childrenLoaded = false; + */ + } + else + { + if(!node.loaded || !node.childrenLoaded) + { + LoadTreeNode(node); + //list.Sort(nameField, 1); + //node. + } + for(child = node.children.first; child && child.next; child = child.next); + if(child) + child.EnsureVisible(false); + } + } + return true; + } + + bool NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods) + { + DataRow row = listBox.currentRow; + if(row) + { + FileSystemNode node = (FileSystemNode)row.tag; + if(node) + { + PopupMenu popup; + Menu menu { }; + + MenuItem { menu, "Cut\tCtrl+X", t, NotifySelect = null, disabled = false }; + MenuItem { menu, "Copy\tCtrl+C", c, NotifySelect = null, disabled = false }; + MenuItem { menu, "Paste\tCtrl+V", p, NotifySelect = null, disabled = false /*!clipboard*/ }; + MenuItem { menu, "Delete\tDel", d, NotifySelect = null, disabled = false }; + //MenuDivider { menu }; + + popup = PopupMenu + { + master = this, menu = menu, + position = { + x + clientStart.x + absPosition.x - guiApp.desktop.position.x, + y + clientStart.y + absPosition.y - guiApp.desktop.position.y } + }; + popup.Create(); + } + } + return true; + } + + bool NotifySelect(ListBox listBox, DataRow row, Modifiers mods) + { + if(row) + { + FileSystemNode node = (FileSystemNode)row.tag; + NotifyNodeSelect(listBox.parent.master, this, node); + selection = node; + } + return true; + } + + bool NotifyEditing(ListBox listBox, DataRow row) + { + if(row) + { + FileSystemNode node = (FileSystemNode)row.tag; + } + return true; + } + + bool NotifyEdited(ListBox listBox, DataRow row) + { + if(row) + { + FileSystemNode node = (FileSystemNode)row.tag; + } + return true; + } + + bool NotifyEditDone(ListBox listBox, DataRow row) + { + if(row) + { + FileSystemNode node = (FileSystemNode)row.tag; + } + return true; + } + + bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods) + { + return OpenNode(); + } + + bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch) + { + bool result; + if((SmartKey)key == enter) + result = OpenNode(); + else + result = true; + return true; + } + }; + + bool OpenNode() + { + bool result; + if(selection && selection.type.isFolder && bits.navigateFolders) + { + property::path = selection.path; + result = true; + } + else + result = NotifyNodeOpen(this.master, this, selection); + return result; + } + + // Edit Menu + Menu editMenu { menu, "Edit", e }; + MenuItem itemEditCut + { + editMenu, "Cut\tCtrl+X", t, disabled = true; + + bool NotifySelect(MenuItem selection, Modifiers mods) + { + //EditCut(); + return true; + } + }; + MenuItem itemEditCopy + { + editMenu, "Copy\tCtrl+C", c, disabled = true; + + bool NotifySelect(MenuItem selection, Modifiers mods) + { + //EditCopy(); + return true; + } + }; + MenuItem itemEditPaste + { + editMenu, "Paste\tCtrl+V", p; + + bool NotifySelect(MenuItem selection, Modifiers mods) + { + //EditPaste(); + return true; + } + }; + MenuItem itemEditDelete + { + editMenu, "Delete\tDel", d, disabled = true; + + 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 : ExplorerControl +class ExplorerView : FileSystemBox { borderStyle = none; hasHorzScroll = false; @@ -286,7 +835,7 @@ class ExplorerViewDetails : ExplorerView public: DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this }; - DataField typeField { header = "Type", dataType = /*"String"*/ "char *", width = 40 }; + DataField typeField { header = "Type", dataType = /-*"String"*-/ "char *", width = 40 }; DataField sizeField { header = "Size", dataType = "FileSize", width = 96, alignment = right }; ExplorerViewDetails() @@ -589,7 +1138,7 @@ public: #endif #if 0 -class ExplorerTree : ExplorerControl +class ExplorerTree : FileSystemBox { hasHorzScroll = false; hasVertScroll = false; @@ -633,7 +1182,7 @@ public: FileSystemNode node; FileSystemNode start = parent ? parent : root; if(!start.loaded || !start.childrenLoaded) - NodeLoad(start, tree); + LoadTreeNode(start, tree); for(node = start.children.first; node; node = node.next) if(node.name && !strcmpi(node.name, name)) return node; @@ -655,13 +1204,13 @@ public: anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 }; // WHY is this not working ? - /*void OnResize(int width, int height) + /-*void OnResize(int width, int height) { if(vertScroll.visible) nameField.width = width - vertScroll.size.w; else nameField.width = width; - }*/ + }*-/ bool NotifyCollapse(ListBox listBox, DataRow row, bool collapsed) { @@ -671,7 +1220,7 @@ public: FileSystemNode child; if(collapsed) { - /* + /-* for(child = node.children.last; child; child = node.children.last) { listBox.DeleteRow(child.row); @@ -679,12 +1228,12 @@ public: delete child; } node.childrenLoaded = false; - */ + *-/ } else { if(!node.loaded || !node.childrenLoaded) - NodeLoad(node, tree); + LoadTreeNode(node, tree); for(child = node.children.first; child && child.next; child = child.next); if(child) child.EnsureVisible(false); @@ -706,7 +1255,7 @@ public: MenuItem { menu, "Cut\tCtrl+X", t, NotifySelect = null, disabled = false }; MenuItem { menu, "Copy\tCtrl+C", c, NotifySelect = null, disabled = false }; - MenuItem { menu, "Paste\tCtrl+V", p, NotifySelect = null, disabled = false /*!clipboard*/ }; + MenuItem { menu, "Paste\tCtrl+V", p, NotifySelect = null, disabled = false /-*!clipboard*-/ }; MenuItem { menu, "Delete\tDel", d, NotifySelect = null, disabled = false }; //MenuDivider { menu }; @@ -806,11 +1355,11 @@ public: }; // WHY is this crashing ? - /*void OnResize(int width, int height) + /-*void OnResize(int width, int height) { if(this && nameField) nameField.width = width - 80; - }*/ + }*-/ ExplorerTree() { @@ -831,7 +1380,7 @@ public: #else root.name = "/"; #endif - AddNode(root, true, false, null, tree); + AddTreeNode(root, true, false, null, tree); // How can this make sense for linux? #ifdef __WIN32__ @@ -854,24 +1403,24 @@ public: info[0] = 0; } - parent = MakeFileNode(listing.stats, name); + parent = MakeFileSystemNode(listing.stats, name); if(info[0]) parent.info = CopyString(info); parent.loaded = true; - AddNode(parent, !listing.stats.attribs.isDirectory, listing.stats.attribs.isDirectory, root, tree); + AddTreeNode(parent, !listing.stats.attribs.isDirectory, listing.stats.attribs.isDirectory, root, tree); if(!listing.stats.attribs.isDirectory) parent.childrenLoaded = true; } - + #endif node = FileSystemNode { name = msNetwork, type = network }; - AddNode(node, false, true, null, tree); + AddTreeNode(node, false, true, null, tree); node.row.collapsed = true; tree.Sort(nameField, 1); tree.SelectRow(root.row); - #endif } +} -/* +#if 0 public class ClipBoardFiles { @@ -924,6 +1473,7 @@ public: } } +/-* Private Type DROPFILES pFiles As Long pt As POINTAPI @@ -948,13 +1498,10 @@ If hGlobal Then 'if the globalalloc worked SetClipboardData CF_HDROP, hGlobal 'put files to the clipboard End If - +*-/ bool SaveFile(const char * filePath) { } -*/ - -} #endif #if 0 @@ -1014,7 +1561,7 @@ public class ExplorerFileItem : struct Bitmap bitmap; - void OnDisplay(Surface surface, int x, int y, int width, ExplorerControl control, Alignment alignment, DataDisplayFlags displayFlags) + void OnDisplay(Surface surface, int x, int y, int width, FileSystemBox control, Alignment alignment, DataDisplayFlags displayFlags) { int indentSize = (displayFlags.dropBox) ? 0 : 10; int textOffset; @@ -1211,14 +1758,25 @@ ExplorerFileItem MakeFileItem(const FileAttribs attribs, const char * fileName, return item; } #endif +*/ public class FileSystemNode : struct { +public: + /*//LinkElement link; + FileSystemNode parent; + + FileSystemNodeType type; + + char * name;*/ + FileSystemNode prev, next; bool loaded, childrenLoaded; int indent; + char * path; char * name; + char * extension; char * info; DataRow row; OldList children; @@ -1227,6 +1785,8 @@ public class FileSystemNode : struct FileStats stats; + Bitmap bitmap; + void GetPath(String outputPath) { FileSystemNode up; @@ -1259,7 +1819,7 @@ public class FileSystemNode : struct return false; } - void DuplicateChildren(bool recursive, bool forceExpanded, FileSystemNode addTo, ListBox tree) + void DuplicateChildren(bool recursive, bool forceExpanded, FileSystemNode addTo, FileSystemBox fsb) { if(children.first) { @@ -1270,11 +1830,11 @@ public class FileSystemNode : struct FileSystemNode copy { }; copy.name = CopyString(child.name); copy.type = child.type; - AddNode(copy, child.loaded, false, addTo, tree); + fsb.AddTreeNode(copy, child.loaded, false, addTo); if(forceExpanded) copy.row.collapsed = false; if(recursive) - child.DuplicateChildren(recursive, forceExpanded, copy, tree); + child.DuplicateChildren(recursive, forceExpanded, copy, fsb); } } } @@ -1313,7 +1873,7 @@ public class FileSystemNode : struct parent.children.Delete(this); } - void OnDisplay(Surface surface, int x, int y, int width, ExplorerControl control, Alignment alignment, DataDisplayFlags displayFlags) + void OnDisplay(Surface surface, int x, int y, int width, FileSystemBox fsb, Alignment alignment, DataDisplayFlags displayFlags) { //int indentSize = (displayFlags.dropBox) ? 0 : 10; int indent = 16; @@ -1328,7 +1888,7 @@ public class FileSystemNode : struct if(!this) return; - icon = control.fileIcons[type].bitmap; + icon = fsb.fileIcons[type].bitmap; //xStart = indent * indent + x + (icon ? (icon.width + 5) : 0); xStart = x + (icon ? (icon.width + 5) : 0); @@ -1363,7 +1923,7 @@ public class FileSystemNode : struct //surface.WriteTextDots(alignment, x + textOffset, y + 2, width - textOffset, name, strlen(name)); surface.WriteTextDots(alignment, xStart, y + 2, width, label, len); - if(!guiApp.textMode) + //if(!guiApp.textMode) -- how to do this in a dll? { if(displayFlags.current) { @@ -1385,6 +1945,29 @@ public class FileSystemNode : struct if(icon) { + w = icon.width; + h = icon.height; + } + if(type == pictureFile && fsb.previewPictures && bitmap) + { + surface.SetForeground(white); + surface.blend = true; + //#ifndef __linux__ + //surface.Filter(bitmap, (clientSize.w - w) / 2,(clientSize.h - h) / 2, 0,0, w, h, bitmap.width, bitmap.height); + //surface.Filter(bitmap, x + indent/* * indentSize*/ + 2, y, 0, 0, w, h, bitmap.width, bitmap.height); + surface.Filter(bitmap, x,y,0,0, w, h, bitmap.width, bitmap.height); + //#else + // Until Filter / Stretch works with X + //surface.Blit(bitmap, (clientSize.w - bitmap.width) / 2,(clientSize.h - bitmap.height) / 2, 0,0, bitmap.width, bitmap.height); + // surface.blend = true; + //surface.Blit(bitmap, x + indent/* * indentSize*/ + 2, y,0,0, w, h); + //surface.Blit(bitmap, x,y,0,0, bitmap.width, bitmap.height); + //#endif + //bitmap.Free(); + //delete bitmap; + } + else if(icon) + { //surface.blend = true; //surface.alphaWrite = blend; surface.SetForeground(white); @@ -1397,146 +1980,126 @@ public class FileSystemNode : struct int OnCompare(FileSystemNode b) { int result; - if(type == b.type || (type < folder && b.type < folder) || (type >= drive)) - result = strcmpi(name, b.name); + FileSystemNode a = this; + if(a.type == b.type || (a.type < folder && b.type < folder) || (a.type >= drive)) + result = strcmpi(a.name, b.name); else { - if(type == folder && b.type < folder) result = -1; - else if(type < folder && b.type == folder) result = 1; + if(a.type == folder && b.type < folder) result = -1; + else if(a.type < folder && b.type == folder) result = 1; + else result = 0; } return result; } + /*int OnCompare(FileSystemNode b) + { + int result; + FileSystemNode a = this; + if(a.parent < b.parent) result = -1; + else if(a.parent > b.parent) result = 1; + else + result = fstrcmp(a.name, b.name); + return result; + }*/ + char * OnGetString(char * tempString, FileSystemToolWindow fileSysToolWnd, bool * needClass) { return name ? name : ""; } -}; +} -FileSystemNode MakeFileNode(const FileStats stats, const char * name) +/*FileSystemNode MakeFileSystemNode(const FileStats stats, const char * name) { - FileSystemNode fileTreeNode { stats = stats }; - fileTreeNode.name = CopyString(name); - if(!fileTreeNode.name) - fileTreeNode.name = null; + FileSystemNode node { stats = stats }; + node.name = CopyString(name); + if(!node.name) + node.name = null; if(stats.attribs.isDirectory) { - fileTreeNode.type = (stats.attribs.isDrive) ? drive : folder; - if(stats.attribs.isServer) fileTreeNode.type = server; - if(stats.attribs.isShare) fileTreeNode.type = share; - if(stats.attribs.isCDROM) fileTreeNode.type = cdrom; - if(stats.attribs.isRemote) fileTreeNode.type = netDrive; + node.type = (stats.attribs.isDrive) ? drive : folder; + if(stats.attribs.isServer) node.type = server; + if(stats.attribs.isShare) node.type = share; + if(stats.attribs.isCDROM) node.type = cdrom; + if(stats.attribs.isRemote) node.type = netDrive; if(stats.attribs.isRemovable) { if(name[0] == 'A' || name[0] == 'B') - fileTreeNode.type = floppy; + node.type = floppy; else - fileTreeNode.type = removable; + node.type = removable; } } else { char extension[MAX_EXTENSION]; - GetExtension(fileTreeNode.name, extension); - fileTreeNode.type = _FileType::SelectByExtension(extension); - } - return fileTreeNode; -} - -void AddNode(FileSystemNode node, bool loaded, bool addLoader, FileSystemNode addTo, ListBox tree) + GetExtension(node.name, extension); + node.type = _FileType::SelectByExtension(extension); + } + return node; +}*/ +static FileSystemNode MakeFileSystemNode(const FileStats stats, + const char * fileName, const char * filePath, + const bool previewPicture, const DisplaySystem displaySystem) { - DataRow row = (addTo && addTo.row) ? addTo.row.AddRow() : tree.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) - //AddNode(FileSystemNode { }, false, false, node, tree); // why would this create a compile error? - AddNode(FileSystemNode { type = none }, false, false, node, tree); - - if(node.indent > 0) - row.collapsed = true; - else if(node.type == folder) - node.type = folderOpen; -} + int len = strlen(fileName); + char info[MAX_LOCATION]; + char name[MAX_LOCATION]; + char extension[MAX_EXTENSION]; + + FileSystemNode node { stats = stats }; -void NodeLoad(FileSystemNode node, ListBox tree) -{ - if(!node.loaded) + //if(stats.attribs.isFile) // TODO fix this in ecere + if(stats.attribs.isDirectory) { - char path[MAX_LOCATION]; - node.GetPath(path); - { - FileListing listing { path }; - if(node.children.count == 1) - DeleteNode(node.children.first, tree); + extension[0] = '\0'; - while(listing.Find()) - { - if(listing.stats.attribs.isDirectory) - { - FileSystemNode child = MakeFileNode(listing.stats, listing.name); - AddNode(child, true, false, node, tree); - NodeChildLoad(child, node, tree); - } - } + node.type = (stats.attribs.isDrive) ? drive : folder; + if(stats.attribs.isServer) node.type = server; + if(stats.attribs.isShare) node.type = share; + if(stats.attribs.isCDROM) node.type = cdrom; + if(stats.attribs.isRemote) node.type = netDrive; + if(stats.attribs.isRemovable) + { + if(fileName[0] == 'A' || fileName[0] == 'B') + node.type = floppy; + else + node.type = removable; } - node.childrenLoaded = true; - node.loaded = true; - node.row.SortSubRows(false); } - else if(!node.childrenLoaded) + else { - FileSystemNode child; - if(node.children.first) - { - for(child = node.children.first; child; child = child.next) - { - if(!child.loaded) - NodeLoad(child, tree); - else if(!child.childrenLoaded) - NodeChildLoad(child, node, tree); - } - node.childrenLoaded = true; - node.row.SortSubRows(false); - } + GetExtension(fileName, extension); + strlwr(extension); + + node.type = _FileType::SelectByExtension(extension); } -} -static void NodeChildLoad(FileSystemNode parent, FileSystemNode node, ListBox tree) -{ - char path[MAX_LOCATION]; - parent.GetPath(path); + if(stats.attribs.isDrive && + len > 3 && !strncmp(&fileName[1], ": [", 3)) { - bool added = false; - FileListing listing { path }; - while(listing.Find()) - { - if(listing.stats.attribs.isDirectory) - { - FileSystemNode child = MakeFileNode(listing.stats, listing.name); - AddNode(child, true, false, parent, tree); - added = true; - } - } - if(!added) - added = true; + strncpy(name, fileName, 2); + name[2] = 0; + strncpy(info, &fileName[4], len - 5); + info[len - 5] = 0; + } + else + { + strcpy(name, fileName); + info[0] = 0; } - //parent.childrenLoaded = true; -} -void DeleteNode(FileSystemNode node, ListBox tree) -{ - FileSystemNode child; - for(; (child = node.children.first); ) - DeleteNode(child, tree); - tree.DeleteRow(node.row); - node.Delete(); + node.path = CopyString(filePath); + node.name = CopyString(name); + if(info[0]) + node.info = CopyString(info); + node.extension = CopyString(extension); + + if(node.type == pictureFile && previewPicture) + { + node.bitmap = Bitmap { alphaBlend = true }; + node.bitmap.Load(filePath, null, displaySystem); + } + + return node; } -- 1.8.3.1