libede/FileSystemBox: Set path to CWD upon creation; Ensure outputPath is initialized...
[ede] / libede / src / FileSystemBox.ec
index 36e6b7b..82a7abd 100644 (file)
@@ -53,7 +53,7 @@ static char * fileIconNames[] =
 
    "<:ecere>mimeTypes/package.png",      /* treeLoader */
    "<:ecere>places/startHere.png",                /* lineNumbers */
-   
+
    ""
 };
 
@@ -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,7 +212,7 @@ 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
    {
       set
@@ -282,7 +282,7 @@ public:
    };
    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
@@ -467,7 +467,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
@@ -584,7 +587,7 @@ private:
          }
          return true;
       }
-      
+
       bool NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods)
       {
          DataRow row = listBox.currentRow;
@@ -626,8 +629,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();
@@ -860,7 +863,7 @@ private:
    MenuItem itemEditPaste
    {
       editMenu, "Paste\tCtrl+V", p;
-   
+
       bool NotifySelect(MenuItem selection, Modifiers mods)
       {
          //EditPaste();
@@ -878,7 +881,7 @@ private:
       }
    };
 
-   // WHY is this crashing ? 
+   // WHY is this crashing ?
    /*void OnResize(int width, int height)
    {
       if(this && nameField)
@@ -972,14 +975,15 @@ private:
          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)
@@ -1669,7 +1673,7 @@ public:
       location.GetPath(path);
       {
          FileListing listing { path };
-         
+
          ExplorerFileItem item;
          DataRow row;
 
@@ -1724,7 +1728,7 @@ public:
       location.GetPath(path);
       {
          FileListing listing { path };
-         
+
          ExplorerFileItem item;
          DataRow row;
 
@@ -1773,7 +1777,7 @@ public:
       location.GetPath(path);
       {
          FileListing listing { path };
-         
+
          ExplorerFileItem item;
          DataRow row;
 
@@ -1820,7 +1824,7 @@ public:
       location.GetPath(path);
       {
          FileListing listing { path };
-         
+
          ExplorerFileItem item;
          DataRow row;
 
@@ -1866,7 +1870,7 @@ public:
       {
          _[c].Free();
          delete _[c];
-      }  
+      }
       count = 0;
       size = 0;
    }
@@ -1905,9 +1909,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 +1962,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 +1988,7 @@ public:
       location.GetPath(path);
       {
          FileListing listing { path };
-         
+
          ExplorerFileItem item;
          DataRow row;
 
@@ -2020,7 +2024,7 @@ public:
    FileSystemNode selection;
 
    virtual bool Window::NotifyNodeSelect(ExplorerTree tree, FileSystemNode node);
-   
+
    property FileSystemNode node
    {
       get
@@ -2108,7 +2112,7 @@ public:
          }
          return true;
       }
-      
+
       bool NotifyRightClick(ListBox listBox, int x, int y, Modifiers mods)
       {
          DataRow row = listBox.currentRow;
@@ -2129,8 +2133,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 +2207,7 @@ public:
    MenuItem itemEditPaste
    {
       editMenu, "Paste\tCtrl+V", p;
-   
+
       bool NotifySelect(MenuItem selection, Modifiers mods)
       {
          //EditPaste();
@@ -2221,7 +2225,7 @@ public:
       }
    };
 
-   // WHY is this crashing ? 
+   // WHY is this crashing ?
    /-*void OnResize(int width, int height)
    {
       if(this && nameField)
@@ -2249,14 +2253,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 +2313,7 @@ public:
             ClipBoard clipBoard { };
             if(clipBoard.Allocate(size+1))
             {
-               GetSel(clipBoard.memory, true);   
+               GetSel(clipBoard.memory, true);
                // Save clipboard
                clipBoard.Save();
             }
@@ -2358,11 +2362,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 +2393,7 @@ public:
    }
    BSloc Remove(FileSystemNode item)
    {
-      
+
    }
 }
 #endif
@@ -2438,7 +2442,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 +2453,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 +2554,7 @@ public:
       {
          //_[c].Free()
          delete _[c];
-      }  
+      }
       count = 0;
       size = 0;
    }
@@ -2562,7 +2566,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 +2583,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 +2596,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);
@@ -2726,7 +2730,7 @@ public:
    Array<int> 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 +2745,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 +2764,7 @@ public:
       if(children.first)
       {
          FileSystemNode child;
-         
+
          for(child = children.first; child; child = child.next)
          {
             FileSystemNode copy { };
@@ -2782,7 +2778,7 @@ public:
          }
       }
    }
-   
+
    void EnsureVisible(bool expand)
    {
       if(parent)
@@ -2838,8 +2834,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 +2865,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 +2874,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);
 
@@ -3134,7 +3130,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;
@@ -3164,7 +3160,7 @@ FileSystemNode MakeFileSystemNode(
    char info[MAX_LOCATION];
    char name2[MAX_LOCATION];
    char extension[MAX_EXTENSION];
-   
+
    FileSystemNode node { stats = stats };
 
    /*if(!pathAddName)
@@ -3187,7 +3183,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 +3195,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);