Fixed major issues
[ede] / libede / src / FileSystemSearch.ec
index cb003f4..d198f1b 100644 (file)
@@ -12,7 +12,7 @@ struct SearchStackFrame
    int tag;
    char path[MAX_LOCATION];
    FileListing listing;
-   
+
    bool branched;
    //DataRow result;
    //DataRow browse;
@@ -37,6 +37,9 @@ public:
 
    Window owner;
    FileSystemBox fsb;
+   FileSystemBox tree;
+
+   FileSystemNode messageNode;
 
    FileSystemSearch()
    {
@@ -44,12 +47,21 @@ public:
       terminate = false;
    }
 
-   virtual bool Window::NotifyUpdateSearchLocation(FileSystemSearch search, char * location);
+   virtual bool Window::NotifyUpdateSearchLocation(FileSystemSearch search, const char * location);
    virtual bool Window::NotifySearchSortResults(FileSystemSearch search);
    virtual bool Window::NotifySearchSortBrowser(FileSystemSearch search);
    virtual bool Window::NotifySearchTerminated(FileSystemSearch search);
 
-   bool SearchFileContent(String path)
+   void InitResults()
+   {
+      fsb.Clear();
+      //CreateMessageNode();
+      //messageNode.label = "No results yet!";
+   }
+
+
+
+   bool SearchFileContent(const String path)
    {
       bool match = false;
       File file = FileOpen(path, read);
@@ -84,8 +96,8 @@ public:
                      find = SearchString(buffer, start, contentSearch, optionContentMatchCase, optionContentMatchWord);
 
                      // todo add a maximum line length possibility as param
-                     for(bstart = start; 
-                           bstart < readCount && newLine && (!find || newLine < find); 
+                     for(bstart = start;
+                           bstart < readCount && newLine && (!find || newLine < find);
                               bstart += (newLine - &buffer[bstart]) / sizeof(char))
                      {
                         newLine = strstr(&buffer[bstart], "\n");
@@ -119,14 +131,14 @@ public:
                      find = SearchString(buffer, start, contentSearch, optionContentMatchCase, optionContentMatchWord);
                file.Seek(seekBack, current);
             }
-            match = (bool)find;
+            match = find != null;
          }
          delete file;
       }
       return match;
    }
-   
-   // I wonder if this is optimized at the c level to be compiled inline 
+
+   // I wonder if this is optimized at the c level to be compiled inline
    // and to use in-place in-stack memory for both the return value and the parameters
    // if not, c should be more optimized...
    // would the const have any impact on optimization?
@@ -143,59 +155,80 @@ public:
       // \\Nateus\data\ is not remote, etc...
       // How to?
       FileStats stats;
-      
+
       terminate = false;
       count = 0;
       matchCount = 0;
-      
+
       hasNameSearch = (strlen(nameSearch) != 0);
       hasSizeSearch = false;  // this is temporary
       hasContentSearch = (strlen(contentSearch) != 0);
 
       listLines = true;
       lines = OldList { };
-      
+
       //SearchDir(location);
 
       FileGetStats(location, stats);
 
       strcpy(stack[0].path, location);
-      stack[0].listing = FileListing { stack[0].path };  // there should be a sorted = true/false 
+      stack[0].listing = FileListing { stack[0].path };  // there should be a sorted = true/false
 
-      fsb.list.Clear();
+      //fsb.list.Clear();
                                                          // Binary Search sorting...
       if(optionTree)
          stack[0].branched = false;
-      /*if(optionBrowser)
+      if(optionBrowser)
       {
          guiApp.Lock();
          {
             //stack[0].browse = searchPanel.AddBrowserRow();
-            //node = MakeFileSystemNode(attribs, stack[0].path,
+            //DeleteMessageNode();
+            //node = MakeFileSystemNode(attribs, stack[0].path, true,
             //      stack[0].path, fsb.bits.previewPictures, fsb.displaySystem);
             //stack[0].browse.SetData(browserNameField, node);
             //stack[0].browse.SetData(typeField, null);
             //stack[0].browse.SetData(sizeField, null);
 
-            stack[0].browse = MakeFileSystemNode(stats, stack[0].path, stack[0].path,
-                  fsb.bits.previewPictures, fsb.displaySystem);
-            fsb.AddTreeNode(stack[0].browse, true, false, null); // TEMPORARY // searchPanel.AddBrowse(stack[0].browse, null);
+            //DeleteMessageNode();
+            tree.Clear();
+            stack[0].browse = MakeFileSystemNode(stats, stack[0].path, stack[0].path, false,
+                  tree.bits.previewPictures, false, tree.displaySystem);
+            tree.AddTreeNode(stack[0].browse, false, true, true, null); // TEMPORARY // searchPanel.AddBrowse(stack[0].browse, null);
          }
          guiApp.Unlock();
-      }*/
-      
+      }
+
       for(frame = 0; frame >= 0 && !terminate; )
       {
+         guiApp.Lock();
+         {
+            double thisTime = GetTime();
+            if(thisTime - lastTime > 0.25)
+            {
+               NotifyUpdateSearchLocation(owner, this, stack[frame].listing.path); // TEMPORARY // searchPanel.SearchUpdateLabel(stack[frame].listing.path);
+               //if(!messageNode)
+               //   CreateMessageNode();
+               //delete messageNode.label;
+               //messageNode.label = PrintString("Searching '", stack[frame].listing.path, "'...");
+               //messageNode.EnsureVisible(false);
+               //fsb.Select(messageNode);
+               //fsb.Update(null);
+               //guiApp.UpdateDisplay();
+               lastTime = thisTime;
+            }
+         }
+         guiApp.Unlock();
          if(stack[frame].listing.Find())
          {
             count++;
-            
+
             //match = (strcmp(stack[frame].listing.name, nameSearch) == 0);
             //match = (stack[frame].listing.name[0] == nameSearch[0]);
             //match = (bool)strstr(stack[frame].listing.name, nameSearch);
-               
+
             if(hasNameSearch)
-               match = (bool)SearchString(stack[frame].listing.name, 0, nameSearch, optionNameMatchCase, optionNameMatchWord);
+               match = SearchString(stack[frame].listing.name, 0, nameSearch, optionNameMatchCase, optionNameMatchWord) != null;
             else
                match = true;
 
@@ -215,17 +248,19 @@ public:
                         guiApp.Lock();
                            if(frame)
                            {
+                              DeleteMessageNode();
                               stack[frame].result = MakeFileSystemNode(stack[frame - 1].listing.stats,
-                                    stack[frame - 1].listing.name, stack[frame - 1].path,
-                                    fsb.bits.previewPictures, fsb.displaySystem);
-                              fsb.AddTreeNode(stack[frame].result, true, false, stack[frame - 1].result); // TEMPORARY // searchPanel.AddResult(stack[frame].result, stack[frame - 1].result);
+                                    stack[frame - 1].listing.name, stack[frame - 1].path, true,
+                                    fsb.bits.previewPictures, false, fsb.displaySystem);
+                              fsb.AddTreeNode(stack[frame].result, true, true, false, stack[frame - 1].result); // TEMPORARY // searchPanel.AddResult(stack[frame].result, stack[frame - 1].result);
                               stack[frame].result.row.collapsed = false;
                            }
                            else
                            {
-                              stack[0].result = MakeFileSystemNode(stats, stack[0].path, stack[0].path,
-                                    fsb.bits.previewPictures, fsb.displaySystem);
-                              fsb.AddTreeNode(stack[0].result, true, false, null); // TEMPORARY // searchPanel.AddResult(stack[0].result, null);
+                              DeleteMessageNode();
+                              stack[0].result = MakeFileSystemNode(stats, stack[0].path, stack[0].path, true,
+                                    fsb.bits.previewPictures, false, fsb.displaySystem);
+                              fsb.AddTreeNode(stack[0].result, true, true, false, null); // TEMPORARY // searchPanel.AddResult(stack[0].result, null);
                               stack[0].result.row.collapsed = false;
                            }
                            stack[frame].branched = true;
@@ -238,23 +273,31 @@ public:
             }
             if(optionSubdirs && stack[frame].listing.stats.attribs.isDirectory)
             {
-               guiApp.Lock();
+               /*guiApp.Lock();
                   {
                      double thisTime = GetTime();
                      if(thisTime - lastTime > 0.25)
                      {
                         NotifyUpdateSearchLocation(owner, this, stack[stackTop].listing.path); // TEMPORARY // searchPanel.SearchUpdateLabel(stack[stackTop].listing.path);
+                        if(!messageNode)
+                           CreateMessageNode();
+                        //delete messageNode.label;
+                        messageNode.label = PrintString("Searching '", stack[stackTop].listing.path, "'...");
+                        messageNode.EnsureVisible(false);
+                        fsb.Update(null);
+                        guiApp.UpdateDisplay();
                         lastTime = thisTime;
                      }
                   }
-                  //searchPanel.SearchUpdateLabel(stack[stackTop].listing.path);
+                  //searchPanel.SearchUpdateLabel(stack[stackTop].listing.path);*/
                   frame++;
-                  /*if(optionBrowser)
+               /*   /-*if(optionBrowser)
                   {
+                     DeleteMessageNode();
                      stack[frame].browse = MakeFileSystemNode(stack[stackTop].listing.stats,
-                           stack[stackTop].listing.name, stack[stackTop].path,
+                           stack[stackTop].listing.name, stack[stackTop].path, true,
                            fsb.bits.previewPictures, fsb.displaySystem);
-                     fsb.AddTreeNode(stack[frame].browse, true, false, stack[stackTop].browse); // TEMPORARY // searchPanel.AddBrowse(stack[frame].browse, stack[stackTop].browse);
+                     fsb.AddTreeNode(stack[frame].browse, true, true, false, stack[stackTop].browse); // TEMPORARY // searchPanel.AddBrowse(stack[frame].browse, stack[stackTop].browse);
 
                      if(frame)
                         stack[frame].browse.row.collapsed = true;
@@ -262,8 +305,8 @@ public:
                         //searchPanel.SortBrowser();  // this can be very bad for performance in some situations
                                                 // there should be a way to sort the nodes as they are added
                                                 // BinarySearch sorting implementation in listBox's Sort?
-                  }*/
-               guiApp.Unlock();
+                  }*-/
+               guiApp.Unlock();*/
                strcpy(stack[frame].path, stack[stackTop].listing.path);
                stack[frame].listing = FileListing { stack[frame].path };
                if(optionTree)
@@ -271,12 +314,13 @@ public:
                if(match)
                {
                   guiApp.Lock();
+                     DeleteMessageNode();
                      stack[frame].result = MakeFileSystemNode(stack[stackTop].listing.stats,
-                           stack[stackTop].listing.name, stack[stackTop].path,
-                           fsb.bits.previewPictures, fsb.displaySystem);
+                           stack[stackTop].listing.name, stack[stackTop].path, true,
+                           fsb.bits.previewPictures, false, fsb.displaySystem);
                      if(optionTree)
                      {
-                        fsb.AddTreeNode(stack[frame].result, true, false, stack[stackTop].result); // TEMPORARY // searchPanel.AddResult(stack[frame].result, stack[stackTop].result);
+                        fsb.AddTreeNode(stack[frame].result, true, true, false, stack[stackTop].result); // TEMPORARY // searchPanel.AddResult(stack[frame].result, stack[stackTop].result);
                         stack[frame].result.row.collapsed = false;
                         //searchPanel.SortResults();  // this can be very bad for performance in some situations
                                                 // there should be a way to sort the nodes as they are added
@@ -297,10 +341,11 @@ public:
                   /*if(optionBrowser)
                   {
                      FileSystemNode item;
+                     DeleteMessageNode();
                      item = MakeFileSystemNode(stack[frame].listing.stats,
-                           stack[frame].listing.name, stack[frame].path,
+                           stack[frame].listing.name, stack[frame].path, true,
                            fsb.bits.previewPictures, fsb.displaySystem);
-                     fsb.AddTreeNode(item, true, false, stack[frame].browse); // TEMPORARY // searchPanel.AddBrowse(item, stack[frame].browse);
+                     fsb.AddTreeNode(item, true, true, false, stack[frame].browse); // TEMPORARY // searchPanel.AddBrowse(item, stack[frame].browse);
                      //if(frame == 1)
                         //searchPanel.SortBrowser();  // this can be very bad for performance in some situations
                                                 // there should be a way to sort the nodes as they are added
@@ -309,12 +354,13 @@ public:
                   if(match)
                   {
                      FileSystemNode item;
+                     DeleteMessageNode();
                      item = MakeFileSystemNode(stack[frame].listing.stats,
-                           stack[frame].listing.name, stack[frame].path,
-                           fsb.bits.previewPictures, fsb.displaySystem);
+                           stack[frame].listing.name, stack[frame].path, true,
+                           fsb.bits.previewPictures, false, fsb.displaySystem);
                      if(optionTree)
                      {
-                        fsb.AddTreeNode(item, true, false, stack[frame].result); // TEMPORARY // searchPanel.AddResult(item, stack[frame].result);
+                        fsb.AddTreeNode(item, true, true, false, stack[frame].result); // TEMPORARY // searchPanel.AddResult(item, stack[frame].result);
                         item.row.collapsed = false;
                         //searchPanel.SortResults();  // this can be very bad for performance in some situations
                                                 // there should be a way to sort the nodes as they are added
@@ -327,8 +373,8 @@ public:
                            sprintf(temp, "lines %d", lin.num);
                            for(lin = lin.next; lin && strlen(temp) < MAX_F_STRING; lin = lin.next)
                               strcatf(temp, ", %d", lin.num);
-                           node = FileSystemNode { name = CopyString(temp), type = lineNumbers };
-                           fsb.AddTreeNode(node, true, false, item); // TEMPORARY // searchPanel.AddResult(node, item);
+                           node = FileSystemNode { name = temp/*CopyString(temp)*/, type = lineNumbers };
+                           fsb.AddTreeNode(node, true, true, false, item); // TEMPORARY // searchPanel.AddResult(node, item);
                            //row.AddRow().SetData(resultsNameField, node);
                            lines.Free(null);
                         }
@@ -365,7 +411,25 @@ public:
 
       guiApp.Lock();
       NotifySearchTerminated(owner, this); // TEMPORARY // searchPanel.SearchTerminate();
+      //delete messageNode.label;
+      //messageNode.label = PrintString("Searching '", stack[stackTop].listing.path, "'...");
+      //delete the messageNode;
+      //fsb.Update(null);
       guiApp.Unlock();
       return 0;
    }
+
+private:
+   void CreateMessageNode()
+   {
+      //messageNode = MakeFileSystemNode({ }, " ", " ", false, false, fsb.displaySystem);
+      //messageNode.type = normalFile;
+      //fsb.AddNode(messageNode);
+   }
+   void DeleteMessageNode()
+   {
+      //if(messageNode)
+      //   fsb.DeleteNode(messageNode);
+      //messageNode = null;
+   }
 }