public import "ecere" import "ExplorerTree" public class FileListItem : struct { char * name; char * info; FileItemType type; int indent; void OnDisplay(Surface surface, int x, int y, int width, ExplorerListBox icons, Alignment alignment, DataDisplayFlags displayFlags) { int indentSize = (displayFlags.dropBox) ? 0 : 10; int textOffset; int len; char label[MAX_FILENAME]; Bitmap icon = icons.icons[type].bitmap; if(!icon) { if(type == folder || type == folderOpen) surface.SetForeground(red); //Color { 170, 170, 0 } // REDJ What is that color? indentSize = 8; } textOffset = indent * indentSize + (icon ? (icon.width + 4) : 0); if(info) sprintf(label, "%s [%s]", name, info); else strcpy(label, name); len = strlen(label); surface.WriteTextDots (alignment, x + textOffset, y + 2, width - textOffset, label, len); if(icon) surface.Blit(icon, x + indent * indentSize, y,0,0, icon.width, icon.height); } int OnCompare(FileListItem b) { int result; if(type == b.type || (type < folder && b.type < folder) || (type >= drive)) result = strcmpi(name, b.name); else { if(type == folder && b.type < folder) result = -1; else if(type < folder && b.type == folder) result = 1; } return result; } void OnCopy(FileListItem newData) { type = newData.type; indent = newData.indent; if(newData.name) { int len = strlen(newData.name) + 1; name = new char[len]; CopyBytes(name, newData.name, len); } } bool OnGetDataFromString(char * string) { int len = strlen(string) + 1; name = new char[len]; CopyBytes(name, string, len); return true; } void OnFree() { delete name; delete info; } char * OnGetString(char * string, void * fieldData, bool * needClass) { return name; } }; FileListItem MakeFileListItem(const FileAttribs attribs, const char * name, const char * extension) { FileListItem fileListRow { }; fileListRow.name = CopyString(name); if(attribs.isDirectory) { fileListRow.type = (attribs.isDrive) ? drive : folder; if(attribs.isServer) fileListRow.type = server; if(attribs.isShare) fileListRow.type = share; if(attribs.isCDROM) fileListRow.type = cdrom; if(attribs.isRemote) fileListRow.type = netDrive; if(attribs.isRemovable) { if(name[0] == 'A' || name[0] == 'B') fileListRow.type = floppy; else fileListRow.type = removable; } } else fileListRow.type = FileItemType::SelectByExtension(extension); return fileListRow; }