public import "ecere"
+#ifdef __WIN32__
+static char * rootName = "Entire Computer";
+static char * msNetwork = "Microsoft Windows Network";
+#else
+static char * rootName = "File System";
+#endif
+
+private:
+define guiApp = ((GuiApplication)__thisModule);
+define selectionColor = guiApp.currentSkin.selectionColor; //Color { 10, 36, 106 };
+
static char * fileIconNames[] =
{
"<:ecere>mimeTypes/file.png", /* none */
""
};
-//define guiApp = ((GuiApplication)__thisModule);
-//define selectionColor = guiApp.currentSkin.selectionColor; //Color { 10, 36, 106 };
-
-public enum __FileType
+public enum _FileType
{
none,
get { return this >= normalFile && this <= opticalMediaImageFile; }
}
- __FileType ::SelectByExtension(char * extension)
+ _FileType ::SelectByExtension(char * extension)
{
if(!strcmpi(extension, "ews"))
return ewsFile;
}
};
-//public enum FileSystemNodeType { file, folder, system };
+class ExplorerControl : Window
+{
+ bool previewPictures;
-define guiApp = ((GuiApplication)__thisModule); // how to do this in a dll?
-define selectionColor = guiApp.currentSkin.selectionColor; //Color { 10, 36, 106 };
+ BitmapResource fileIcons[_FileType];
+
+ ExplorerControl()
+ {
+ _FileType c;
+ for(c = 0; c < _FileType::enumSize; c++)
+ {
+ fileIcons[c] = BitmapResource { fileIconNames[c], alphaBlend = true };
+ AddResource(fileIcons[c]);
+ }
+ }
+}
-public class FileSystemNode : struct // : struct
+#if 0
+class ExplorerView : ExplorerControl
{
-public:
- /*//LinkElement<FileSystemNode> link;
- FileSystemNode parent;
+ borderStyle = none;
+ hasHorzScroll = false;
+ hasVertScroll = false;
- FileSystemNodeType type;
+ virtual void Load(FileSystemNode parent);
+ virtual void Refresh();
- char * name;*/
+ virtual void LaunchNotifyItemSelect(Window master, ExplorerView view, ExplorerFileItem item, ExplorerFileItemArray selectedItems)
+ {
+ view.NotifyItemSelect(master, view, item, selectedItems);
+ }
- FileSystemNode prev, next;
+ virtual bool Window::NotifyItemSelect(ExplorerView view, ExplorerFileItem item, ExplorerFileItemArray selectedItems);
+ virtual bool Window::NotifyItemOpen(ExplorerView view, ExplorerFileItem item);
- bool loaded, childrenLoaded;
- int indent;
- char * path;
- char * name;
- char * extension;
- char * info;
- DataRow row;
- OldList children;
- __FileType type;
- FileSystemNode parent;
+ ListBox list
+ {
+ master = master, parent = this;
+ //this, master;
+ borderStyle = none;
+ hasHorzScroll = true;
+ hasVertScroll = true;
+ resizable = true;
+ sortable = true;
+ fullRowSelect = false;
+ multiSelect = true;
- FileStats stats;
+ anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
- Bitmap bitmap;
+ 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;
+ }
- void GetPath(String outputPath)
- {
- FileSystemNode up;
- if(parent)
+ bool NotifyDoubleClick(ListBox listBox, int x, int y, Modifiers mods)
{
- strcpy(outputPath, name);
- for(up = parent; up; up = up.parent)
+ 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)
{
- char temp[MAX_LOCATION];
- strcpy(temp, up.name);
- PathCat(temp, outputPath);
- strcpy(outputPath, temp);
+ ExplorerView view = (ExplorerView)listBox.parent;
+ view.NotifyItemOpen(listBox.parent.master, view, (ExplorerFileItem)listBox.currentRow.tag);
}
+ return true;
}
- else
-#ifdef __WIN32__
- strcpy(outputPath, "/");
-#else
- strcpy(outputPath, name);
+ };
+
+ 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);
}
- bool IsChildOf(FileSystemNode node)
+ void Refresh()
{
- FileSystemNode test;
- for(test = parent; test; test = test.parent)
- if(test == node)
- return true;
- return false;
+ Load(location);
}
- void DuplicateChildren(bool recursive, bool forceExpanded, FileSystemNode addTo, FileSystemBox fsb)
+ void Load(FileSystemNode location)
{
- if(children.first)
+ char path[MAX_LOCATION];
+ this.location = location;
+ location.GetPath(path);
{
- FileSystemNode child;
+ FileListing listing { path };
- for(child = children.first; child; child = child.next)
+ ExplorerFileItem item;
+ DataRow row;
+
+ list.Clear();
+
+ while(listing.Find())
{
- FileSystemNode copy { };
- copy.name = CopyString(child.name);
- copy.type = child.type;
- fsb.AddTreeNode(copy, child.loaded, false, addTo);
- if(forceExpanded)
- copy.row.collapsed = false;
- if(recursive)
- child.DuplicateChildren(recursive, forceExpanded, copy, fsb);
+ 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);
}
}
-
- void EnsureVisible(bool expand)
+}
+#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()
{
- if(parent)
- parent.EnsureVisible(true);
- if(expand)
- row.collapsed = false;
- // TODO: row.EnsureVisible(); // making the row visible by scrolling
+ list.AddField(nameField);
+ list.AddField(typeField);
+ list.AddField(sizeField);
}
- void OnFree()
+ void Refresh()
{
- //delete name;
+ Load(location);
}
- void Free()
+ void Load(FileSystemNode location)
{
- FileSystemNode child;
- for(; (child = children.first); )
+ char path[MAX_LOCATION];
+ this.location = location;
+ location.GetPath(path);
{
- child.Free();
- children.Delete(child);
+ 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);
+ row.SetData(typeField, CopyString(item.extension));
+ row.SetData(sizeField, (uint)listing.stats.size);
+ }
+ list.Sort(nameField, 1);
}
- //if(name)
- delete name;
- delete info;
}
+}
+#endif
- void Delete()
- {
- Free();
- if(parent)
- parent.children.Delete(this);
- }
+#if 0
+class ExplorerViewIcons : ExplorerView
+{
- 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;
- int xStart;
- int len;
- int w, h;
- //int textOffset;
- char label[MAX_FILENAME];
+ FileSystemNode location;
- Bitmap icon;
+public:
- if(!this)
- return;
-
- icon = fsb.fileIcons[type].bitmap;
- /*if(type == normalFile)
- PrintLn("dd");*/
- //xStart = indent * indent + x + (icon ? (icon.width + 5) : 0);
- xStart = x + (icon ? (icon.width + 5) : 0);
+ DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
- if(!name)
- return;
+ ExplorerViewDetails()
+ {
+ list.AddField(nameField);
+ }
- if(info)
- sprintf(label, "%s [%s]", name, info);
- else
- strcpy(label, name);
- len = strlen(label);
-
- if(!icon)
- {
- if(type == folder || type == folderOpen)
- surface.SetForeground(yellow);
- //indentSize = 8;
- indent = 8;
- }
- //textOffset = indent * indentSize + (icon ? (icon.width + 4) : 0);
-
- surface.TextOpacity(false);
- surface.TextExtent(label, len, &w, &h);
- h = Max(h, 16);
-
- // Draw the current row stipple
- if(displayFlags.selected)
- //surface.Area(xStart - 1, y, xStart - 1, y + h - 1);
- //surface.Area(xStart + w - 1, y, xStart + w + 1, y + h - 1);
- surface.Area(xStart - 3, y, xStart + w + 1, y + h - 1);
-
- //surface.WriteTextDots(alignment, x + textOffset, y + 2, width - textOffset, name, strlen(name));
- surface.WriteTextDots(alignment, xStart, y + 2, width, label, len);
+ void Refresh()
+ {
+ Load(location);
+ }
- //if(!guiApp.textMode) -- how to do this in a dll?
+ void Load(FileSystemNode location)
+ {
+ char path[MAX_LOCATION];
+ this.location = location;
+ location.GetPath(path);
{
- if(displayFlags.current)
- {
- if(displayFlags.active)
- {
- surface.LineStipple(0x5555);
- if(displayFlags.selected)
- surface.SetForeground(0xFFFFFF80);
- else
- surface.SetForeground(black);
- }
- else
- {
- surface.SetForeground(selectionColor);
- }
- surface.Rectangle(xStart - 3, y, xStart + w + 1, y + h - 1);
- surface.LineStipple(0);
- }
+ FileListing listing { path };
+
+ ExplorerFileItem item;
+ DataRow row;
- if(icon)
+ list.Clear();
+
+ while(listing.Find())
{
- //surface.blend = true;
- //surface.alphaWrite = blend;
- surface.SetForeground(white);
- //surface.Blit(icon, x + indent * indentSize, y,0,0, icon.width, icon.height);
- surface.Blit(icon, x,y,0,0, icon.width, icon.height);
+ 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
- int OnCompare(FileSystemNode b)
- {
- int result;
- 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(a.type == folder && b.type < folder) result = -1;
- else if(a.type < folder && b.type == folder) result = 1;
- else result = 0;
- }
- return result;
- }
+#if 0
+class ExplorerViewCards : ExplorerView
+{
+
+ FileSystemNode location;
+
+public:
+
+ DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 304, editable = true, userData = this };
- /*int OnCompare(FileSystemNode b)
+ ExplorerViewDetails()
{
- 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;
- }*/
+ list.AddField(nameField);
+ }
- char * OnGetString(char * tempString, FileSystemToolWindow fileSysToolWnd, bool * needClass)
+ void Refresh()
{
- return name ? name : "";
+ Load(location);
}
-}
-/*FileSystemNode MakeFileSystemNode(const FileStats stats, const char * name)
-{
- FileSystemNode node { stats = stats };
- node.name = CopyString(name);
- if(!node.name)
- node.name = null;
- if(stats.attribs.isDirectory)
+ void Load(FileSystemNode location)
{
- 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)
+ char path[MAX_LOCATION];
+ this.location = location;
+ location.GetPath(path);
{
- if(name[0] == 'A' || name[0] == 'B')
- node.type = floppy;
- else
- node.type = removable;
- }
+ 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);
+ }
}
- else
+}
+#endif
+
+#if 0
+public class BitmapArray : RedjArray
+{
+ type = class(Bitmap);
+public:
+ Bitmap * const _;
+ Bitmap * Add(Bitmap bitmap)
{
- char extension[MAX_EXTENSION];
- GetExtension(node.name, extension);
- node.type = __FileType::SelectByExtension(extension);
+ uint pos = _count;
+ Append(1);
+ _[pos] = bitmap;
+ return &_[pos];
+ }
+ Bitmap * AddBefore(uint position, Bitmap bitmap)
+ {
+ Insert(position, 1);
+ _[position] = bitmap;
+ return &_[position];
+ }
+ void Clear()
+ {
+ int c;
+ for(c = 0; c < _count; c++)
+ {
+ _[c].Free();
+ delete _[c];
+ }
+ count = 0;
+ size = 0;
}
- return node;
-}*/
-static FileSystemNode MakeFileSystemNode(const FileStats stats, const char * fileName, const char * filePath, const bool previewPicture, const DisplaySystem displaySystem)
+}
+#endif
+
+#if 0
+class ExplorerViewShowcase : ExplorerView
{
- int len = strlen(fileName);
- char info[MAX_LOCATION];
- char name[MAX_LOCATION];
- char extension[MAX_EXTENSION];
-
- FileSystemNode node { stats = stats };
+ list.anchor = Anchor { left = 0, top = 0, bottom = 0 };
+ list.size = Size { w = 200 };
- //if(stats.attribs.isFile) // TODO fix this in ecere
- if(stats.attribs.isDirectory)
+ FileSystemNode location;
+
+public:
+
+ DataField nameField { header = "Name", dataType = "ExplorerFileItem", width = 180, editable = true, userData = this };
+
+ Bitmap bitmap;
+ BitmapArray bitmaps { growingFactor = 16 };
+
+ Window show
{
- extension[0] = '\0';
+ this;
+ borderStyle = none;
+ anchor = Anchor { top = 0, right = 0, bottom = 0 };
- 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)
+ void OnRedraw(Surface surface)
{
- if(fileName[0] == 'A' || fileName[0] == 'B')
- node.type = floppy;
+ ExplorerViewShowcase view = (ExplorerViewShowcase)parent;
+ if(view.bitmap)
+ {
+ int wBmp = view.bitmap.width;
+ int hBmp = view.bitmap.height;
+ int wWnd = clientSize.w;
+ int hWnd = clientSize.h;
+
+ int wList = view.list.size.w + view.split.size.w;
+
+ float scale = Min((float)(wWnd - 10) / wBmp, (float)(hWnd - 10) / hBmp);
+
+ int wDraw = (int)(wBmp * scale);
+ int hDraw = (int)(hBmp * scale);
+
+ #ifndef __linux__
+ surface.Filter(view.bitmap, (wWnd - wDraw) / 2, (hWnd - hDraw) / 2, 0, 0, wDraw, hDraw, wBmp, hBmp);
+ #else
+ // Until Filter / Stretch works with X
+ surface.Blit(view.bitmap, (wWnd - wDraw) / 2, (hWnd - hDraw) / 2, 0, 0, wDraw, hDraw);
+ #endif
+ }
else
- node.type = removable;
+ {
+ surface.SetForeground(white);
+ surface.Area(0, 0, view.clientSize.w - 1, view.clientSize.h - 1);
+ }
}
}
- else
+
+ SplitWindow split
{
- GetExtension(fileName, extension);
- strlwr(extension);
-
- node.type = __FileType::SelectByExtension(extension);
- }
+ this;
+ leftPane = list;
+ rightPane = show;
+ split = 200;
+ tabCycle = true;
+ };
- if(stats.attribs.isDrive &&
- len > 3 && !strncmp(&fileName[1], ": [", 3))
+ ExplorerViewDetails()
{
- strncpy(name, fileName, 2);
- name[2] = 0;
- strncpy(info, &fileName[4], len - 5);
- info[len - 5] = 0;
+ list.AddField(nameField);
}
- else
+
+ void LaunchNotifyItemSelect(Window master, ExplorerViewShowcase view, ExplorerFileItem item, ExplorerFileItemArray selectedItems)
{
- strcpy(name, fileName);
- info[0] = 0;
- }
+ int pos;
+ ExplorerFileItem selItem;
+ if(view.bitmap)
+ view.bitmap.Free();
+ delete view.bitmap;
+ if(item && item.type == pictureFile)
+ {
+ view.bitmap = Bitmap { };
+ view.bitmap.Load(item.path, null, displaySystem);
+ }
- node.path = CopyString(filePath);
- node.name = CopyString(name);
- if(info[0])
- node.info = CopyString(info);
- node.extension = CopyString(extension);
+ view.bitmaps.Clear();
+ view.bitmaps = BitmapArray { };
+ for(pos = 0; pos < selectedItems.count; pos++)
+ {
+ Bitmap bitmap { };
+ selItem = (ExplorerFileItem)selectedItems._[pos];
+ bitmap.Load(selItem.path, null, displaySystem);
+ //view.bitmaps.Add(bitmap);
+ }
+ if(item && item.type == pictureFile)
+ {
+ view.bitmap = Bitmap { };
+ view.bitmap.Load(item.path, null, displaySystem);
+ }
+
+ view.show.Update(null);
+ view.NotifyItemSelect(master, view, item, selectedItems);
+ }
- if(node.type == pictureFile && previewPicture)
+ void Refresh()
{
- node.bitmap = Bitmap { };
- node.bitmap.Load(filePath, null, displaySystem);
+ Load(location);
}
- return node;
-}
+ void Load(FileSystemNode location)
+ {
+ char path[MAX_LOCATION];
+ this.location = location;
+ location.GetPath(path);
+ {
+ FileListing listing { path };
+
+ ExplorerFileItem item;
+ DataRow row;
-class FileSystemBoxBits
-{
- bool foldersOnly:1, filesOnly:1, details:1, treeBranches:1, previewPictures: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;
-};
+ list.Clear();
-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;
-*/
+ 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 ExplorerTree : ExplorerControl
{
- borderStyle = deep;
hasHorzScroll = false;
hasVertScroll = false;
menu = Menu { };
public:
- FileSystemNode root;
- FileSystemNode selection;
- virtual bool Window::NotifyNodeSelect(FileSystemBox box, FileSystemNode node);
-
- property char * path
- {
- set
- {
- delete path;
- if(value && value[0])
- path = CopyString(value);
- if(created)
- Load();
- }
+ DataField nameField { dataType = "FileSystemNode", width = 240, userData = this };
- get { return path; }
- //isset { return path && path[0]; }
- }
+ FileSystemNode root;
+ FileSystemNode selection;
- 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; }
- };
+ virtual bool Window::NotifyNodeSelect(ExplorerTree tree, FileSystemNode node);
property FileSystemNode node
{
get
{
- if(!list)
+ if(!tree)
return null;
- if(!list.currentRow)
+ if(!tree.currentRow)
return null;
- if(!list.currentRow.tag)
+ if(!tree.currentRow.tag)
return null;
- return (FileSystemNode)list.currentRow.tag;
+ return (FileSystemNode)tree.currentRow.tag;
}
}
if(node.row)
{
node.EnsureVisible(false);
- list.SelectRow(node.row);
+ tree.SelectRow(node.row);
}
}
FileSystemNode node;
FileSystemNode start = parent ? parent : root;
if(!start.loaded || !start.childrenLoaded)
- LoadTreeNode(start);
+ NodeLoad(start, tree);
for(node = start.children.first; node; node = node.next)
if(node.name && !strcmpi(node.name, name))
return node;
return null;
}
-private:
- FileSystemBoxBits bits;
-
- char * path;
- char * extensions;
-
- BitmapResource fileIcons[__FileType];
-
- 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++)
- {
- fileIcons[c] = BitmapResource { fileIconNames[c], alphaBlend = true };
- AddResource(fileIcons[c]);
- }
- }
-
- DataField nameField { dataType = "FileSystemNode", width = 240, userData = this };
- DataField typeField { header = "Type", dataType = /*"String"*/ "char *", width = 40, freeData = false };
- DataField sizeField { header = "Size", dataType = "FileSize", width = 96, alignment = right };
-
- bool OnPostCreate()
- {
- Load();
- return true;
- }
-
- ListBox list
+ ListBox tree
{
- this;
-
+ master = master, parent = this;
+ //this, master;
borderStyle = none;
hasHorzScroll = true;
hasVertScroll = true;
fullRowSelect = false;
- sortable = true;
+ treeNodees = true;
+ collapseControl = true;
+ rootCollapseButton = true;
anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 };
else
{
if(!node.loaded || !node.childrenLoaded)
- {
- LoadTreeNode(node);
- //list.Sort(nameField, 1);
- //node.
- }
+ NodeLoad(node, tree);
for(child = node.children.first; child && child.next; child = child.next);
if(child)
child.EnsureVisible(false);
}
return true;
}
-
};
// Edit Menu
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()
+ ExplorerTree()
{
- 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);
+ tree.AddField(nameField);
}
- void LoadTree()
+ void Load()
{
- //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();
+ FileListing listing { "/" };
+
+ tree.Clear();
- delete root;
- //root = FileSystemNode { type = computer, loaded = true, childrenLoaded = true };
- root = MakeFileSystemNode(FileStats { attribs = FileExists(path)}, path, path, bits.previewPictures, displaySystem);
+ root = FileSystemNode { type = computer, loaded = true, childrenLoaded = true };
#ifdef __WIN32__
- //root.name = rootName;
- AddTreeNode(root, true, false, null, list);
+ root.name = rootName;
#else
- //root.name = "/";
+ root.name = "/";
#endif
- AddTreeNode(root, false, true, null);
+ AddNode(root, true, false, null, tree);
// How can this make sense for linux?
#ifdef __WIN32__
info[0] = 0;
}
- parent = MakeFileSystemNode(listing.stats, name);
+ parent = MakeFileNode(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);
+ AddNode(parent, !listing.stats.attribs.isDirectory, listing.stats.attribs.isDirectory, root, tree);
if(!listing.stats.attribs.isDirectory)
parent.childrenLoaded = true;
}
node = FileSystemNode { name = msNetwork, type = network };
- AddTreeNode(node, false, true, null, this);
+ AddNode(node, false, true, null, tree);
node.row.collapsed = true;
- Sort(nameField, 1);
- SelectRow(root.row);
+ tree.Sort(nameField, 1);
+ tree.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();
- }
/*
public class ClipBoardFiles
{
*/
}
+#endif
+
+#if 0
+public class FileTreeNodeBSArray : ArrayBinarySorted
+{
+ type = class(FileSystemNode);
+public:
+ FileSystemNode * const _;
+ BSloc Add(FileSystemNode item)
+ {
+ BSloc result = Find(item);
+ if(!result.valid)
+ {
+ Insert(result.pos, 1);
+ _[result.pos] = item;
+ }
+ return result;
+ }
+ BSloc Remove(FileSystemNode item)
+ {
+
+ }
+}
+#endif
+
+#if 0
+public class FileTreeNodeArray : RedjArray
+{
+ type = class(FileSystemNode);
+public:
+ FileSystemNode * const _;
+ FileSystemNode * Add(FileSystemNode item)
+ {
+ uint pos = _count;
+ Append(1);
+ _[pos] = item;
+ return &_[pos];
+ }
+ FileSystemNode * AddBefore(uint position, FileSystemNode item)
+ {
+ Insert(position, 1);
+ _[position] = item;
+ return &_[position];
+ }
+}
+#endif
+
+#if 0
+public class ExplorerFileItem : struct
+{
+ char * path;
+ char * name;
+ char * info;
+ char * extension;
+ _FileType type;
+ int indent;
+
+ Bitmap bitmap;
+
+ void OnDisplay(Surface surface, int x, int y, int width, ExplorerControl control, Alignment alignment, DataDisplayFlags displayFlags)
+ {
+ int indentSize = (displayFlags.dropBox) ? 0 : 10;
+ int textOffset;
+ int len;
+ char label[MAX_FILENAME];
+
+ //float scale = Min((float)clientSize.w / (float)bitmap.width, (float)clientSize.h / (float)bitmap.height);
+ int w = 16; //(int)(bitmap.width * scale);
+ int h = 16; //(int)(bitmap.height * scale);
+
+ Bitmap icon;
+
+ icon = control.fileIcons[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 + 6) : 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(type == pictureFile && control.previewPictures && bitmap)
+ {
+#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);
+#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);
+#endif
+ //bitmap.Free();
+ //delete bitmap;
+ }
+ else if(icon)
+ surface.Blit(icon, x + indent * indentSize + 2, y,0,0, icon.width, icon.height);
+ }
+
+ int OnCompare(ExplorerFileItem 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(ExplorerFileItem 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 path;
+ delete name;
+ delete info;
+ delete extension;
+ if(bitmap)
+ bitmap.Free();
+ }
+
+ char * OnGetString(char * string, void * fieldData, bool * needClass)
+ {
+ return name;
+ }
+};
+
+public class ExplorerFileItemArray : RedjArray
+{
+ type = class(ExplorerFileItem);
+public:
+ ExplorerFileItem * const _;
+ ExplorerFileItem * Add(ExplorerFileItem item)
+ {
+ uint pos = _count;
+ Append(1);
+ _[pos] = item;
+ return &_[pos];
+ }
+ ExplorerFileItem * AddBefore(uint position, ExplorerFileItem item)
+ {
+ Insert(position, 1);
+ _[position] = item;
+ return &_[position];
+ }
+ void Clear()
+ {
+ int c;
+ for(c = 0; c < _count; c++)
+ {
+ //_[c].Free()
+ delete _[c];
+ }
+ count = 0;
+ size = 0;
+ }
+}
+
+ExplorerFileItem MakeFileItem(const FileAttribs attribs, const char * fileName, const char * filePath, const bool previewPicture, const DisplaySystem displaySystem)
+{
+ int len = strlen(fileName);
+ char info[MAX_LOCATION];
+ char name[MAX_LOCATION];
+ char extension[MAX_EXTENSION];
+
+ ExplorerFileItem item { };
+
+ //if(attribs.isFile) // TODO fix this in ecere
+ if(attribs.isDirectory)
+ {
+ extension[0] = 0;
+
+ item.type = (attribs.isDrive) ? drive : folder;
+ if(attribs.isServer)
+ item.type = server;
+ if(attribs.isShare)
+ item.type = share;
+ if(attribs.isCDROM)
+ item.type = cdrom;
+ if(attribs.isRemote)
+ item.type = netDrive;
+ if(attribs.isRemovable)
+ {
+ if(fileName[0] == 'A' || fileName[0] == 'B')
+ item.type = floppy;
+ else
+ item.type = removable;
+ }
+ }
+ else
+ {
+ GetExtension(fileName, extension);
+ //strupr(extension);
+ strlwr(extension);
+
+ item.type = _FileType::SelectByExtension(extension);
+ }
+
+ if(attribs.isDrive &&
+ len > 3 && !strncmp(&fileName[1], ": [", 3))
+ {
+ strncpy(name, fileName, 2);
+ name[2] = 0;
+ strncpy(info, &fileName[4], len - 5);
+ info[len - 5] = 0;
+ }
+ else
+ {
+ strcpy(name, fileName);
+ info[0] = 0;
+ }
+
+ item.path = CopyString(filePath);
+ item.name = CopyString(name);
+ if(info[0])
+ item.info = CopyString(info);
+ item.extension = CopyString(extension);
+
+ if(item.type == pictureFile && previewPicture)
+ {
+ item.bitmap = Bitmap { };
+ item.bitmap.Load(filePath, null, displaySystem);
+ }
+
+ return item;
+}
+#endif
+
+public class FileSystemNode : struct
+{
+ FileSystemNode prev, next;
+
+ bool loaded, childrenLoaded;
+ int indent;
+ char * name;
+ char * info;
+ DataRow row;
+ OldList children;
+ _FileType type;
+ FileSystemNode parent;
+
+ FileStats stats;
+
+ void GetPath(String outputPath)
+ {
+ FileSystemNode up;
+ if(parent)
+ {
+ strcpy(outputPath, name);
+ for(up = parent; up; up = up.parent)
+ {
+ char temp[MAX_LOCATION];
+ strcpy(temp, up.name);
+ PathCat(temp, outputPath);
+ strcpy(outputPath, temp);
+ }
+ }
+ else
+#ifdef __WIN32__
+ strcpy(outputPath, "/");
+#else
+ strcpy(outputPath, name);
+#endif
+
+ }
+
+ bool IsChildOf(FileSystemNode node)
+ {
+ FileSystemNode test;
+ for(test = parent; test; test = test.parent)
+ if(test == node)
+ return true;
+ return false;
+ }
+
+ void DuplicateChildren(bool recursive, bool forceExpanded, FileSystemNode addTo, ListBox tree)
+ {
+ if(children.first)
+ {
+ FileSystemNode child;
+
+ for(child = children.first; child; child = child.next)
+ {
+ FileSystemNode copy { };
+ copy.name = CopyString(child.name);
+ copy.type = child.type;
+ AddNode(copy, child.loaded, false, addTo, tree);
+ if(forceExpanded)
+ copy.row.collapsed = false;
+ if(recursive)
+ child.DuplicateChildren(recursive, forceExpanded, copy, tree);
+ }
+ }
+ }
+
+ void EnsureVisible(bool expand)
+ {
+ if(parent)
+ parent.EnsureVisible(true);
+ if(expand)
+ row.collapsed = false;
+ // TODO: row.EnsureVisible(); // making the row visible by scrolling
+ }
+
+ void OnFree()
+ {
+ //delete name;
+ }
+
+ void Free()
+ {
+ FileSystemNode child;
+ for(; (child = children.first); )
+ {
+ child.Free();
+ children.Delete(child);
+ }
+ //if(name)
+ delete name;
+ delete info;
+ }
+
+ void Delete()
+ {
+ Free();
+ if(parent)
+ parent.children.Delete(this);
+ }
+
+ void OnDisplay(Surface surface, int x, int y, int width, ExplorerControl control, Alignment alignment, DataDisplayFlags displayFlags)
+ {
+ //int indentSize = (displayFlags.dropBox) ? 0 : 10;
+ int indent = 16;
+ int xStart;
+ int len;
+ int w, h;
+ //int textOffset;
+ char label[MAX_FILENAME];
+
+ Bitmap icon;
+
+ if(!this)
+ return;
+
+ icon = control.fileIcons[type].bitmap;
+ //xStart = indent * indent + x + (icon ? (icon.width + 5) : 0);
+ xStart = x + (icon ? (icon.width + 5) : 0);
+
+ if(!name)
+ return;
+
+ if(info)
+ sprintf(label, "%s [%s]", name, info);
+ else
+ strcpy(label, name);
+ len = strlen(label);
+
+ if(!icon)
+ {
+ if(type == folder || type == folderOpen)
+ surface.SetForeground(yellow);
+ //indentSize = 8;
+ indent = 8;
+ }
+ //textOffset = indent * indentSize + (icon ? (icon.width + 4) : 0);
+
+ surface.TextOpacity(false);
+ surface.TextExtent(label, len, &w, &h);
+ h = Max(h, 16);
+
+ // Draw the current row stipple
+ if(displayFlags.selected)
+ //surface.Area(xStart - 1, y, xStart - 1, y + h - 1);
+ //surface.Area(xStart + w - 1, y, xStart + w + 1, y + h - 1);
+ surface.Area(xStart - 3, y, xStart + w + 1, y + h - 1);
+
+ //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(displayFlags.current)
+ {
+ if(displayFlags.active)
+ {
+ surface.LineStipple(0x5555);
+ if(displayFlags.selected)
+ surface.SetForeground(0xFFFFFF80);
+ else
+ surface.SetForeground(black);
+ }
+ else
+ {
+ surface.SetForeground(selectionColor);
+ }
+ surface.Rectangle(xStart - 3, y, xStart + w + 1, y + h - 1);
+ surface.LineStipple(0);
+ }
+
+ if(icon)
+ {
+ //surface.blend = true;
+ //surface.alphaWrite = blend;
+ surface.SetForeground(white);
+ //surface.Blit(icon, x + indent * indentSize, y,0,0, icon.width, icon.height);
+ surface.Blit(icon, x,y,0,0, icon.width, icon.height);
+ }
+ }
+ }
+
+ int OnCompare(FileSystemNode 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;
+ }
+
+ char * OnGetString(char * tempString, FileSystemToolWindow fileSysToolWnd, bool * needClass)
+ {
+ return name ? name : "";
+ }
+};
+
+FileSystemNode MakeFileNode(const FileStats stats, const char * name)
+{
+ FileSystemNode fileTreeNode { stats = stats };
+ fileTreeNode.name = CopyString(name);
+ if(!fileTreeNode.name)
+ fileTreeNode.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;
+ if(stats.attribs.isRemovable)
+ {
+ if(name[0] == 'A' || name[0] == 'B')
+ fileTreeNode.type = floppy;
+ else
+ fileTreeNode.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)
+{
+ 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;
+}
+
+void NodeLoad(FileSystemNode node, ListBox tree)
+{
+ if(!node.loaded)
+ {
+ char path[MAX_LOCATION];
+ node.GetPath(path);
+ {
+ FileListing listing { path };
+ if(node.children.count == 1)
+ DeleteNode(node.children.first, tree);
+
+ 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.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)
+ NodeLoad(child, tree);
+ else if(!child.childrenLoaded)
+ NodeChildLoad(child, node, tree);
+ }
+ node.childrenLoaded = true;
+ node.row.SortSubRows(false);
+ }
+ }
+}
+
+static void NodeChildLoad(FileSystemNode parent, FileSystemNode node, ListBox tree)
+{
+ char path[MAX_LOCATION];
+ parent.GetPath(path);
+ {
+ 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;
+ }
+ //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();
+}