X-Git-Url: https://ecere.com/cgi-bin/gitweb.cgi?a=blobdiff_plain;ds=sidebyside;f=libede%2Fsrc%2FFileSystemBox.ec;h=8842cf1b965abf9a75025b71589d19e5445b0ccd;hb=9e16f30612eb73393d7fde121037b1546c98c22b;hp=36e6b7b696414422b8942ebdc2c739bcd5bc2e7d;hpb=0a9a2099baaa56c453eb0903258f329c9d4bc25d;p=ede diff --git a/libede/src/FileSystemBox.ec b/libede/src/FileSystemBox.ec index 36e6b7b..8842cf1 100644 --- a/libede/src/FileSystemBox.ec +++ b/libede/src/FileSystemBox.ec @@ -3,22 +3,22 @@ import "FileSystemCache" #ifdef __WIN32__ static char * rootName = "Entire Computer"; -static char * msNetwork = "Microsoft Windows Network"; +static const char * msNetwork = "Microsoft Windows Network"; #else -static char * rootName = "File System"; +static const char * rootName = "File System"; #endif private: define guiApp = (GuiApplication)((__thisModule).application); define selectionColor = guiApp.currentSkin.selectionColor; //Color { 10, 36, 106 }; -void MessageBoxTodo(char * message) +void MessageBoxTodo(const char * message) { PrintLn("MessageBoxTodo(char * message) -- ", message); MessageBox { type = ok, text = "MessageBoxTodo(char * message)", contents = message }.Modal(); } -static char * fileIconNames[] = +static const char * fileIconNames[] = { "<:ecere>mimeTypes/file.png", /* none */ @@ -53,12 +53,12 @@ static char * fileIconNames[] = "<:ecere>mimeTypes/package.png", /* treeLoader */ "<:ecere>places/startHere.png", /* lineNumbers */ - + "" }; define countOfCompIconNames = 6; -static char * compIconNames[] = +static const char * compIconNames[] = { /* "<:ede>a.png", @@ -79,19 +79,19 @@ static char * compIconNames[] = public enum _FileType { none, - + normalFile, ewsFile, epjFile, ecFile, ehFile, cFile, hFile, cppFile, hppFile, textFile, webFile, pictureFile, soundFile, archiveFile, packageFile, opticalMediaImageFile, /* these (all previous) are sort equal */ - + folder, folderOpen, computer, drive, netDrive, cdrom, removable, floppy, network, server, share, // these are sort equal - + // utilities treeLoader, lineNumbers; - /*property char * + /*property char * { set { @@ -212,8 +212,8 @@ public: virtual bool Window::NotifyNodeOpen(FileSystemBox box, FileSystemBoxSelection selection); virtual bool Window::NotifyNodeMenu(FileSystemBox box, Menu menu, FileSystemBoxSelection selection); virtual bool Window::NotifyIteratorInit(FileSystemBox box, FileSystemIterator fileSystemIterator); - - property char * path + + property const char * path { set { @@ -233,7 +233,11 @@ public: { set { - delete comparedPaths; + if(comparedPaths) + { + comparedPaths.Free(); + delete comparedPaths; + } if(value && value.count) comparedPaths = value; if(locationBox) @@ -277,12 +281,17 @@ public: split.leftPane = value ? list : null; split.visible = value; show.visible = value; + if(!value) + { + list.parent = this; + list.anchor = Anchor { left = 0, top = 0, right = 0, bottom = 0 }; + } } get { return bits.preview; } }; property bool columnsCompareStyle { set { bits.columnsCompareStyle = value; } get { return bits.columnsCompareStyle; } }; property bool textFileLinesStyle { set { bits.textFileLinesStyle = value; } get { return bits.textFileLinesStyle; } }; - + property FileSystemNode node { get @@ -334,7 +343,7 @@ public: delete map; } - FileSystemNode SelectLocation(char * location) + FileSystemNode SelectLocation(const char * location) { int c; char * temp; @@ -355,7 +364,7 @@ public: for(c = steps.count - 1; c >= 0; c--) { - char * t = steps[c]; + //char * t = steps[c]; node = Find(steps[c], node); if(!node) break; @@ -418,6 +427,7 @@ public: bool MenuOpen(MenuItem selection, Modifiers mods) { OpenNode(); + return true; } bool MenuReplaceListItemByContainingDir(MenuItem selection, Modifiers mods) @@ -467,7 +477,10 @@ private: FileSystemBox() { - path = CopyString(""); + char wd[MAX_LOCATION]; + GetWorkingDir(wd, sizeof(wd)); + property::path = wd; + InitFileIcons(); InitCompIcons(); // todo: these icons should not be initialize, they should be set // or at least initalized when the comparison listing is requested @@ -479,6 +492,11 @@ private: ~FileSystemBox() { + if(comparedPaths) + { + comparedPaths.Free(); + delete comparedPaths; + } delete extensions; delete path; } @@ -584,7 +602,7 @@ private: } return true; } - + bool NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods) { DataRow row = listBox.currentRow; @@ -626,8 +644,8 @@ private: popup = PopupMenu { master = this, menu = menu, - position = { - x + clientStart.x + absPosition.x - guiApp.desktop.position.x, + position = { + x + clientStart.x + absPosition.x - guiApp.desktop.position.x, y + clientStart.y + absPosition.y - guiApp.desktop.position.y } }; popup.Create(); @@ -696,7 +714,7 @@ private: { if(row) { - FileSystemNode node = (FileSystemNode)row.tag; + //FileSystemNode node = (FileSystemNode)row.tag; } return true; } @@ -705,7 +723,7 @@ private: { if(row) { - FileSystemNode node = (FileSystemNode)row.tag; + //FileSystemNode node = (FileSystemNode)row.tag; } return true; } @@ -714,7 +732,7 @@ private: { if(row) { - FileSystemNode node = (FileSystemNode)row.tag; + //FileSystemNode node = (FileSystemNode)row.tag; } return true; } @@ -728,20 +746,20 @@ private: bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch) { - bool result; + //bool result = false; if((SmartKey)key == enter) - result = OpenNode(); + /*result = */OpenNode(); #if 0 else if((SmartKey)key == f2) - result = RenameNode(); + /*result = */RenameNode(); #endif else if((SmartKey)key == f2) { FileSystemNode node = selection.node; node.row.Edit(nameField); } - else - result = true; + //else + //result = true; return true; } }; @@ -774,12 +792,12 @@ private: int wWnd = fsb.show.clientSize.w; int hWnd = fsb.show.clientSize.h; - int wList = 0;//fsb.list.size.w + fsb.split.size.w; + //int wList = 0;//fsb.list.size.w + fsb.split.size.w; - float scale = Min((float)(wWnd - 10) / wBmp, (float)(hWnd - 10) / hBmp); + //float scale = Min((float)(wWnd - 10) / wBmp, (float)(hWnd - 10) / hBmp); - int wDraw = (int)(wBmp * scale); - int hDraw = (int)(hBmp * scale); + //int wDraw = (int)(wBmp * scale); + //int hDraw = (int)(hBmp * scale); #ifndef __linux__ surface.Filter(fsb.bitmap, (wWnd - wDraw) / 2, (hWnd - hDraw) / 2, 0, 0, wDraw, hDraw, wBmp, hBmp); @@ -794,7 +812,7 @@ private: surface.Area(0, 0, fsb.clientSize.w - 1, fsb.clientSize.h - 1); } } - } + }; bool OpenNode() { @@ -860,7 +878,7 @@ private: MenuItem itemEditPaste { editMenu, "Paste\tCtrl+V", p; - + bool NotifySelect(MenuItem selection, Modifiers mods) { //EditPaste(); @@ -878,7 +896,7 @@ private: } }; - // WHY is this crashing ? + // WHY is this crashing ? /*void OnResize(int width, int height) { if(this && nameField) @@ -964,22 +982,23 @@ private: { bool isRoot = !strcmp(path, "/"); char name[MAX_LOCATION]; - FileSystemNode parent; - FileSystemNode node; - FileListing listing { path, extensions = extensions }; + //FileSystemNode parent; + //FileSystemNode node; + //FileListing listing { path, extensions = extensions }; if(!isRoot) GetLastDirectory(path, name); else name[0] = '\0'; - + /*if(!path) GetWorkingDir(startPath, sizeof(startPath)); else strcpy(path, startPath);*/ - bits.mode = directory; + list.Clear(); + delete root; #ifdef __WIN32__ if(isRoot) @@ -1101,7 +1120,7 @@ private: } } - bool ListIterator_OnObject(char * name, char * path, FileStats stats, bool isRootObject) + bool ListIterator_OnObject(const char * name, const char * path, FileStats stats, bool isRootObject) { ProcessListItem(name, path, stats, false); return false; @@ -1109,7 +1128,7 @@ private: //void ListIterator_OnLeavingDirectory(char * path) { } - void ProcessListItem(char * name, char * path, FileStats stats, bool isListItem) + void ProcessListItem(const char * name, const char * path, FileStats stats, bool isListItem) { if((!bits.foldersOnly && !bits.filesOnly) || (bits.foldersOnly && stats.attribs.isDirectory) || (bits.filesOnly && stats.attribs.isFile)) { @@ -1188,17 +1207,21 @@ private: FileListing listing { path, extensions = extensions }; while(listing.Find()) { - char * test; + //char * test; FileSystemNode child = null; if((!bits.foldersOnly && !bits.filesOnly) || (bits.foldersOnly && listing.stats.attribs.isDirectory) || (bits.filesOnly && listing.stats.attribs.isFile)) child = MakeAndAddToTreeFileSystemNodeFromFileListing(listing, parent); if(child) + { added = true; - test = child.name; - if(!test) - PrintLn("error"); + /* + test = child.name; + if(!test) + PrintLn("error"); + */ + } } if(!added) added = true; @@ -1208,7 +1231,7 @@ private: void LoadComparedList() { - int c, cmp/*, smallest*/, icon;//, equalCount; + int c/*, cmp*/ /*, smallest*/, icon;//, equalCount; int count = comparedPaths ? comparedPaths.count : 0; //bool allDone = false; bool not; @@ -1452,7 +1475,7 @@ private: void AddNode(FileSystemNode node) { DataRow row = list.AddRow(); - row.tag = (int)node; + row.tag = (intptr)node; node.row = row; incref node; row.SetData(nameField, node); @@ -1484,7 +1507,7 @@ private: (bits.filesOnly && listing.stats.attribs.isFile)))*/ { bool textFileLinesStyle = false; - char * test = listing.name; + const char * test = listing.name; if(!test) PrintLn("error"); result = MakeFileSystemNode(listing.stats, listing.name, listing.path, false, bits.previewPictures, false, displaySystem); @@ -1521,7 +1544,7 @@ private: node.indent = addTo.indent + 1; addTo.children.Add(node); } - row.tag = (int)node; + row.tag = (intptr)node; node.row = row; row.SetData(null, node); if(bits.pathColumn) @@ -1669,7 +1692,7 @@ public: location.GetPath(path); { FileListing listing { path }; - + ExplorerFileItem item; DataRow row; @@ -1724,7 +1747,7 @@ public: location.GetPath(path); { FileListing listing { path }; - + ExplorerFileItem item; DataRow row; @@ -1773,7 +1796,7 @@ public: location.GetPath(path); { FileListing listing { path }; - + ExplorerFileItem item; DataRow row; @@ -1820,7 +1843,7 @@ public: location.GetPath(path); { FileListing listing { path }; - + ExplorerFileItem item; DataRow row; @@ -1866,7 +1889,7 @@ public: { _[c].Free(); delete _[c]; - } + } count = 0; size = 0; } @@ -1905,9 +1928,9 @@ public: 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); @@ -1958,10 +1981,10 @@ public: for(pos = 0; pos < selectedItems.count; pos++) { Bitmap bitmap { }; - selItem = (ExplorerFileItem)selectedItems._[pos]; + selItem = (ExplorerFileItem)selectedItems._[pos]; bitmap.Load(selItem.path, null, displaySystem); //view.bitmaps.Add(bitmap); - } + } if(item && item.type == pictureFile) { view.bitmap = Bitmap { }; @@ -1984,7 +2007,7 @@ public: location.GetPath(path); { FileListing listing { path }; - + ExplorerFileItem item; DataRow row; @@ -2020,7 +2043,7 @@ public: FileSystemNode selection; virtual bool Window::NotifyNodeSelect(ExplorerTree tree, FileSystemNode node); - + property FileSystemNode node { get @@ -2108,7 +2131,7 @@ public: } return true; } - + bool NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods) { DataRow row = listBox.currentRow; @@ -2129,8 +2152,8 @@ public: popup = PopupMenu { master = this, menu = menu, - position = { - x + clientStart.x + absPosition.x - guiApp.desktop.position.x, + position = { + x + clientStart.x + absPosition.x - guiApp.desktop.position.x, y + clientStart.y + absPosition.y - guiApp.desktop.position.y } }; popup.Create(); @@ -2203,7 +2226,7 @@ public: MenuItem itemEditPaste { editMenu, "Paste\tCtrl+V", p; - + bool NotifySelect(MenuItem selection, Modifiers mods) { //EditPaste(); @@ -2221,7 +2244,7 @@ public: } }; - // WHY is this crashing ? + // WHY is this crashing ? /-*void OnResize(int width, int height) { if(this && nameField) @@ -2249,14 +2272,14 @@ public: #endif AddTreeNode(root, true, false, false, null, tree); - // How can this make sense for linux? + // How can this make sense for linux? #ifdef __WIN32__ while(listing.Find()) { int len = strlen(listing.name); char info[MAX_LOCATION]; char name[MAX_LOCATION]; - if(listing.stats.attribs.isDrive && + if(listing.stats.attribs.isDrive && len > 3 && !strncmp(&listing.name[1], ": [", 3)) { strncpy(name, listing.name, 2); @@ -2309,7 +2332,7 @@ public: ClipBoard clipBoard { }; if(clipBoard.Allocate(size+1)) { - GetSel(clipBoard.memory, true); + GetSel(clipBoard.memory, true); // Save clipboard clipBoard.Save(); } @@ -2358,11 +2381,11 @@ hGlobal = GlobalAlloc(GHND, Len(DF) + Len(strFiles)) 'put all files to a exclusi If hGlobal Then 'if the globalalloc worked lpGlobal = GlobalLock(hGlobal) 'lock the hGlobal DF.pFiles = Len(DF) 'set the size of the files - + Call CopyMem(ByVal lpGlobal, DF, Len(DF)) 'copy df to the lpglobal Call CopyMem(ByVal (lpGlobal + Len(DF)), ByVal strFiles, Len(strFiles)) 'copy strfiles to lpglobal Call GlobalUnlock(hGlobal) 'unlock hglobal again - + SetClipboardData CF_HDROP, hGlobal 'put files to the clipboard End If *-/ @@ -2389,7 +2412,7 @@ public: } BSloc Remove(FileSystemNode item) { - + } } #endif @@ -2438,7 +2461,7 @@ public class ExplorerFileItem : struct //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; @@ -2449,7 +2472,7 @@ public class ExplorerFileItem : struct indentSize = 8; } textOffset = indent * indentSize + (icon ? (icon.width + 6) : 0); - + if(info) sprintf(label, "%s [%s]", name, info); else @@ -2550,7 +2573,7 @@ public: { //_[c].Free() delete _[c]; - } + } count = 0; size = 0; } @@ -2562,7 +2585,7 @@ ExplorerFileItem MakeFileItem(const FileAttribs attribs, const char * fileName, char info[MAX_LOCATION]; char name[MAX_LOCATION]; char extension[MAX_EXTENSION]; - + ExplorerFileItem item { }; //if(stats.attribs.isFile) // -- should work now @@ -2579,7 +2602,7 @@ ExplorerFileItem MakeFileItem(const FileAttribs attribs, const char * fileName, item.type = cdrom; if(attribs.isRemote) item.type = netDrive; - if(attribs.isRemovable) + if(attribs.isRemovable) { if(fileName[0] == 'A' || fileName[0] == 'B') item.type = floppy; @@ -2592,11 +2615,11 @@ ExplorerFileItem MakeFileItem(const FileAttribs attribs, const char * fileName, GetExtension(fileName, extension); //strupr(extension); strlwr(extension); - + item.type = _FileType::SelectByExtension(extension); } - if(attribs.isDrive && + if(attribs.isDrive && len > 3 && !strncmp(&fileName[1], ": [", 3)) { strncpy(name, fileName, 2); @@ -2673,7 +2696,7 @@ private: } public: - /*//LinkElement link; + /* LinkElement link; FileSystemNode parent; FileSystemNodeType type; @@ -2686,12 +2709,12 @@ public: property bool isListItem { set { bits.isListItem = value; } get { return bits.isListItem; } }; - property char * path + property const char * path { set { delete path; if(value && value[0]) path = CopyString(value); } get { return path; } isset { return path && path[0]; } } - property char * name + property const char * name { set { delete name; if(value && value[0]) name = CopyString(value); } get { return name; } isset { return name && name[0]; } @@ -2701,12 +2724,12 @@ public: set { delete extension; if(value && value[0]) extension = CopyString(value); } get { return extension; } isset { return extension && extension[0]; } } - property char * label + property const char * label { set { delete label; if(value && value[0]) label = CopyString(value); } get { return label; } isset { return label && label[0]; } } - property char * info + property const char * info { set { delete info; if(value && value[0]) info = CopyString(value); } get { return info; } isset { return info && info[0]; } @@ -2726,7 +2749,7 @@ public: Array exists; // would use (see) BoolArrayInt to pack this into an int if could be accessed as an array void GetPath(String outputPath) - { + { if(path) strcpy(outputPath, path); else if(parent) @@ -2741,17 +2764,9 @@ public: PathCat(temp, outputPath); strcpy(outputPath, temp); } - /*else - { - /-*#ifdef __WIN32__ - strcpy(outputPath, "/"); - #else*-/ - //strcpy(outputPath, name); - strcpy(outputPath, path); - PathCat(outputPath, name); - //#endif - }*/ } + else + strcpy(outputPath, name ? name : ""); } bool IsChildOf(FileSystemNode node) @@ -2768,7 +2783,7 @@ public: if(children.first) { FileSystemNode child; - + for(child = children.first; child; child = child.next) { FileSystemNode copy { }; @@ -2782,7 +2797,7 @@ public: } } } - + void EnsureVisible(bool expand) { if(parent) @@ -2823,7 +2838,7 @@ public: 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 indent = 16; int xStart; int len; int w, h; @@ -2838,8 +2853,9 @@ public: if(!this) return; - + comp = fsb.comparedPaths && fsb.comparedPaths.count > 1; + icon = fsb.fileIcons[type].bitmap; alt = bits.isListItem ? path : name; if(comp && !fsb.bits.columnsCompareStyle && cmpIcon) @@ -2868,7 +2884,7 @@ public: strcpy(text, label ? label : alt); //"%d-%d/%s", stats.inode, stats.nlink //sprintf(text, "%d-%d/%s", stats.inode, stats.nlink, label ? label : alt); len = strlen(text); - + if(!icon) { if(type == folder || type == folderOpen) @@ -2877,18 +2893,17 @@ public: indent = 8; } //textOffset = indent * indentSize + (icon ? (icon.width + 4) : 0); - + surface.SetForeground(displayFlags.selected ? fsb.selectionText : fsb.foreground); surface.TextOpacity(false); surface.TextExtent(text, 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, alt, strlen(alt)); surface.WriteTextDots(alignment, xStart, y + 2, width, text, len); @@ -3101,7 +3116,7 @@ public: //} #endif - bool OnGetDataFromString(char * string) + bool OnGetDataFromString(const char * string) { #if 0 if(string && *string) @@ -3115,7 +3130,7 @@ public: return false; } - char * OnGetString(char * tempString, FileSystemToolWindow fileSysToolWnd, bool * needClass) + const char * OnGetString(char * tempString, void * unused /*FileSystemToolWindow fileSysToolWnd*/, bool * needClass) { return name ? name : ""; } @@ -3134,7 +3149,7 @@ public: 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(stats.attribs.isRemovable) { if(name[0] == 'A' || name[0] == 'B') node.type = floppy; @@ -3158,13 +3173,13 @@ FileSystemNode MakeFileSystemNode( const bool pathAddName, const bool previewPicture, const bool isListItem, - const DisplaySystem displaySystem) + /*const */DisplaySystem displaySystem) { int len = strlen(name); char info[MAX_LOCATION]; char name2[MAX_LOCATION]; char extension[MAX_EXTENSION]; - + FileSystemNode node { stats = stats }; /*if(!pathAddName) @@ -3187,7 +3202,7 @@ FileSystemNode MakeFileSystemNode( 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(stats.attribs.isRemovable) { if(name[0] == 'A' || name[0] == 'B') node.type = floppy; @@ -3199,11 +3214,11 @@ FileSystemNode MakeFileSystemNode( { GetExtension(name, extension); strlwr(extension); - + node.type = _FileType::SelectByExtension(extension); } - if(stats.attribs.isDrive && + if(stats.attribs.isDrive && len > 3 && !strncmp(&name[1], ": [", 3)) { strncpy(name2, name, 2); @@ -3219,8 +3234,8 @@ FileSystemNode MakeFileSystemNode( if(pathAddName) { - bool isFile = stats.attribs.isFile; - bool isFolder = stats.attribs.isDirectory; + //bool isFile = stats.attribs.isFile; + //bool isFolder = stats.attribs.isDirectory; char full[MAX_LOCATION]; strcpy(full, path); PathCat(full, name); @@ -3253,8 +3268,8 @@ FileSystemNode MakeComparedFileSystemNode( const bool previewPicture, const int cmpIcon, const bool cmpNot, - const Array exists, - const DisplaySystem displaySystem) + /*const */Array exists, + /*const */DisplaySystem displaySystem) { FileSystemNode node = MakeFileSystemNode(stats, name, path, pathAddName, previewPicture, false, displaySystem); if(node)