bunch of changes, unfortunate lack of commits
[ede] / libede / src / FileSystemSearch.ec
index df805b0..53b6da8 100644 (file)
@@ -1,5 +1,5 @@
-import "ExplorerTree"
-import "Finder"
+public import "ecere"
+import "FileSystemBox"
 
 class NumberLink : struct
 {
 
 class NumberLink : struct
 {
@@ -16,12 +16,13 @@ struct SearchStackFrame
    bool branched;
    //DataRow result;
    //DataRow browse;
    bool branched;
    //DataRow result;
    //DataRow browse;
-   ExplorerFileBranch result;
-   ExplorerFileBranch browse;
+   FileSystemNode result;
+   FileSystemNode browse;
 };
 
 };
 
-class SearchThread : Thread
+public class FileSystemSearch : Thread
 {
 {
+public:
    bool active, terminate, hasNameSearch, hasSizeSearch, hasContentSearch, listLines;
    int count, matchCount;
    char location[MAX_LOCATION], nameSearch[1024], contentSearch[1024];
    bool active, terminate, hasNameSearch, hasSizeSearch, hasContentSearch, listLines;
    int count, matchCount;
    char location[MAX_LOCATION], nameSearch[1024], contentSearch[1024];
@@ -32,14 +33,34 @@ class SearchThread : Thread
    //DataField resultsNameField;
    //DataField browserNameField;
 
    //DataField resultsNameField;
    //DataField browserNameField;
 
-   ExplorerSearch searchPanel;
+   // TEMPORARY // ExplorerSearch searchPanel;
 
 
-   SearchThread()
+   Window owner;
+   FileSystemBox fsb;
+   FileSystemBox tree;
+
+   FileSystemNode messageNode;
+
+   FileSystemSearch()
    {
       active = false;
       terminate = false;
    }
 
    {
       active = false;
       terminate = false;
    }
 
+   virtual bool Window::NotifyUpdateSearchLocation(FileSystemSearch search, char * location);
+   virtual bool Window::NotifySearchSortResults(FileSystemSearch search);
+   virtual bool Window::NotifySearchSortBrowser(FileSystemSearch search);
+   virtual bool Window::NotifySearchTerminated(FileSystemSearch search);
+
+   void InitResults()
+   {
+      fsb.Clear();
+      //CreateMessageNode();
+      //messageNode.label = "No results yet!";
+   }
+
+
+
    bool SearchFileContent(String path)
    {
       bool match = false;
    bool SearchFileContent(String path)
    {
       bool match = false;
@@ -129,7 +150,7 @@ class SearchThread : Thread
       SearchStackFrame stack[1024];
       //to be used for content replace... EditBox edit { multiLine = true, textHorzScroll = true, textVertScroll = true, maxLineSize = 65536 };
 
       SearchStackFrame stack[1024];
       //to be used for content replace... EditBox edit { multiLine = true, textHorzScroll = true, textVertScroll = true, maxLineSize = 65536 };
 
-      ExplorerFileBranch fileTreeBranch;
+      FileSystemNode node;
       // This won't give drive attribs for c: or c:\ and other drives as well
       // \\Nateus\data\ is not remote, etc...
       // How to?
       // This won't give drive attribs for c: or c:\ and other drives as well
       // \\Nateus\data\ is not remote, etc...
       // How to?
@@ -152,27 +173,52 @@ class SearchThread : Thread
 
       strcpy(stack[0].path, location);
       stack[0].listing = FileListing { stack[0].path };  // there should be a sorted = true/false 
 
       strcpy(stack[0].path, location);
       stack[0].listing = FileListing { stack[0].path };  // there should be a sorted = true/false 
+
+      //fsb.list.Clear();
                                                          // Binary Search sorting...
       if(optionTree)
          stack[0].branched = false;
       if(optionBrowser)
       {
                                                          // Binary Search sorting...
       if(optionTree)
          stack[0].branched = false;
       if(optionBrowser)
       {
-         app.Lock();
+         guiApp.Lock();
          {
             //stack[0].browse = searchPanel.AddBrowserRow();
          {
             //stack[0].browse = searchPanel.AddBrowserRow();
-            //fileTreeBranch = MakeFileBranch(attribs, stack[0].path);
-            //stack[0].browse.SetData(browserNameField, fileTreeBranch);
+            //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.SetData(typeField, null);
             //stack[0].browse.SetData(sizeField, null);
 
-            stack[0].browse = MakeFileBranch(stats, stack[0].path);
-            searchPanel.AddBrowse(stack[0].browse, null);
+            //DeleteMessageNode();
+            tree.Clear();
+            stack[0].browse = MakeFileSystemNode(stats, stack[0].path, stack[0].path, false,
+                  tree.bits.previewPictures, tree.displaySystem);
+            tree.AddTreeNode(stack[0].browse, false, true, null); // TEMPORARY // searchPanel.AddBrowse(stack[0].browse, null);
          }
          }
-         app.Unlock();
+         guiApp.Unlock();
       }
       
       for(frame = 0; frame >= 0 && !terminate; )
       {
       }
       
       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++;
          if(stack[frame].listing.Find())
          {
             count++;
@@ -199,21 +245,26 @@ class SearchThread : Thread
                   {
                      if(!stack[frame].branched)
                      {
                   {
                      if(!stack[frame].branched)
                      {
-                        app.Lock();
+                        guiApp.Lock();
                            if(frame)
                            {
                            if(frame)
                            {
-                              stack[frame].result = MakeFileBranch(stack[frame - 1].listing.stats, stack[frame - 1].listing.name);
-                              searchPanel.AddResult(stack[frame].result, stack[frame - 1].result);
+                              DeleteMessageNode();
+                              stack[frame].result = MakeFileSystemNode(stack[frame - 1].listing.stats,
+                                    stack[frame - 1].listing.name, stack[frame - 1].path, true,
+                                    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].result.row.collapsed = false;
                            }
                            else
                            {
                               stack[frame].result.row.collapsed = false;
                            }
                            else
                            {
-                              stack[0].result = MakeFileBranch(stats, stack[0].path);
-                              searchPanel.AddResult(stack[0].result, null);
+                              DeleteMessageNode();
+                              stack[0].result = MakeFileSystemNode(stats, stack[0].path, stack[0].path, true,
+                                    fsb.bits.previewPictures, fsb.displaySystem);
+                              fsb.AddTreeNode(stack[0].result, true, false, null); // TEMPORARY // searchPanel.AddResult(stack[0].result, null);
                               stack[0].result.row.collapsed = false;
                            }
                            stack[frame].branched = true;
                               stack[0].result.row.collapsed = false;
                            }
                            stack[frame].branched = true;
-                        app.Unlock();
+                        guiApp.Unlock();
                      }
                   }
                   treeTop = stackTop;
                      }
                   }
                   treeTop = stackTop;
@@ -222,21 +273,31 @@ class SearchThread : Thread
             }
             if(optionSubdirs && stack[frame].listing.stats.attribs.isDirectory)
             {
             }
             if(optionSubdirs && stack[frame].listing.stats.attribs.isDirectory)
             {
-               app.Lock();
+               /*guiApp.Lock();
                   {
                      double thisTime = GetTime();
                      if(thisTime - lastTime > 0.25)
                      {
                   {
                      double thisTime = GetTime();
                      if(thisTime - lastTime > 0.25)
                      {
-                        searchPanel.SearchUpdateLabel(stack[stackTop].listing.path);
+                        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;
                      }
                   }
                         lastTime = thisTime;
                      }
                   }
-                  //searchPanel.SearchUpdateLabel(stack[stackTop].listing.path);
+                  //searchPanel.SearchUpdateLabel(stack[stackTop].listing.path);*/
                   frame++;
                   frame++;
-                  if(optionBrowser)
+               /*   /-*if(optionBrowser)
                   {
                   {
-                     stack[frame].browse = MakeFileBranch(stack[stackTop].listing.stats, stack[stackTop].listing.name);
-                     searchPanel.AddBrowse(stack[frame].browse, stack[stackTop].browse);
+                     DeleteMessageNode();
+                     stack[frame].browse = MakeFileSystemNode(stack[stackTop].listing.stats,
+                           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);
 
                      if(frame)
                         stack[frame].browse.row.collapsed = true;
 
                      if(frame)
                         stack[frame].browse.row.collapsed = true;
@@ -244,19 +305,22 @@ class SearchThread : Thread
                         //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?
                         //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?
-                  }
-               app.Unlock();
+                  }*-/
+               guiApp.Unlock();*/
                strcpy(stack[frame].path, stack[stackTop].listing.path);
                stack[frame].listing = FileListing { stack[frame].path };
                if(optionTree)
                   stack[frame].branched = false;
                if(match)
                {
                strcpy(stack[frame].path, stack[stackTop].listing.path);
                stack[frame].listing = FileListing { stack[frame].path };
                if(optionTree)
                   stack[frame].branched = false;
                if(match)
                {
-                  app.Lock();
+                  guiApp.Lock();
+                     DeleteMessageNode();
+                     stack[frame].result = MakeFileSystemNode(stack[stackTop].listing.stats,
+                           stack[stackTop].listing.name, stack[stackTop].path, true,
+                           fsb.bits.previewPictures, fsb.displaySystem);
                      if(optionTree)
                      {
                      if(optionTree)
                      {
-                        stack[frame].result = MakeFileBranch(stack[stackTop].listing.stats, stack[stackTop].listing.name);
-                        searchPanel.AddResult(stack[frame].result, stack[stackTop].result);
+                        fsb.AddTreeNode(stack[frame].result, 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
                         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
@@ -265,32 +329,38 @@ class SearchThread : Thread
                      }
                      else
                      {
                      }
                      else
                      {
-                        //searchPanel.SearchAddResultsItem(stack[stackTop].listing.name, stack[stackTop].listing.path);
+                        fsb.AddNode(stack[frame].result); //searchPanel.SearchAddResultsItem(stack[stackTop].listing.name, stack[stackTop].listing.path);
                      }
                      }
-                  app.Unlock();
+                  guiApp.Unlock();
                }
                stackTop++;
             }
             else
             {
                }
                stackTop++;
             }
             else
             {
-               app.Lock();
-                  if(optionBrowser)
+               guiApp.Lock();
+                  /*if(optionBrowser)
                   {
                   {
-                     ExplorerFileBranch item;
-                     item = MakeFileBranch(stack[frame].listing.stats, stack[frame].listing.name);
-                     searchPanel.AddBrowse(item, stack[frame].browse);
+                     FileSystemNode item;
+                     DeleteMessageNode();
+                     item = MakeFileSystemNode(stack[frame].listing.stats,
+                           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);
                      //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
                                                 // BinarySearch sorting implementation in listBox's Sort?
                      //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
                                                 // BinarySearch sorting implementation in listBox's Sort?
-                  }
+                  }*/
                   if(match)
                   {
                   if(match)
                   {
+                     FileSystemNode item;
+                     DeleteMessageNode();
+                     item = MakeFileSystemNode(stack[frame].listing.stats,
+                           stack[frame].listing.name, stack[frame].path, true,
+                           fsb.bits.previewPictures, fsb.displaySystem);
                      if(optionTree)
                      {
                      if(optionTree)
                      {
-                        ExplorerFileBranch item;
-                        item = MakeFileBranch(stack[frame].listing.stats, stack[frame].listing.name);
-                        searchPanel.AddResult(item, stack[frame].result);
+                        fsb.AddTreeNode(item, 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
                         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
@@ -303,16 +373,16 @@ class SearchThread : Thread
                            sprintf(temp, "lines %d", lin.num);
                            for(lin = lin.next; lin && strlen(temp) < MAX_F_STRING; lin = lin.next)
                               strcatf(temp, ", %d", lin.num);
                            sprintf(temp, "lines %d", lin.num);
                            for(lin = lin.next; lin && strlen(temp) < MAX_F_STRING; lin = lin.next)
                               strcatf(temp, ", %d", lin.num);
-                           fileTreeBranch = ExplorerFileBranch { name = CopyString(temp), type = lineNumbers };
-                           searchPanel.AddResult(fileTreeBranch, item);
-                           //row.AddRow().SetData(resultsNameField, fileTreeBranch);
+                           node = FileSystemNode { name = temp/*CopyString(temp)*/, type = lineNumbers };
+                           fsb.AddTreeNode(node, true, false, item); // TEMPORARY // searchPanel.AddResult(node, item);
+                           //row.AddRow().SetData(resultsNameField, node);
                            lines.Free(null);
                         }
                      }
                      else
                            lines.Free(null);
                         }
                      }
                      else
-                        ;//searchPanel.SearchAddResultsItem(stack[frame].listing.name, stack[frame].listing.path);
+                        fsb.AddNode(item); //searchPanel.SearchAddResultsItem(stack[frame].listing.name, stack[frame].listing.path);
                   }
                   }
-               app.Unlock();
+               guiApp.Unlock();
             }
          }
          else
             }
          }
          else
@@ -330,18 +400,36 @@ class SearchThread : Thread
          for( ; frame >= 0 ; frame--)
             stack[frame].listing.Stop();
 
          for( ; frame >= 0 ; frame--)
             stack[frame].listing.Stop();
 
-      app.Lock();
+      guiApp.Lock();
          if(optionTree)
          if(optionTree)
-            searchPanel.SortResults();
+            NotifySearchSortResults(owner, this); // TEMPORARY // searchPanel.SortResults();
          if(optionBrowser)
          if(optionBrowser)
-            searchPanel.SortBrowser();
-      app.Unlock();
+            NotifySearchSortBrowser(owner, this); // TEMPORARY // searchPanel.SortBrowser();
+      guiApp.Unlock();
 
       active = false;
 
 
       active = false;
 
-      searchPanel.SearchTerminate();
+      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;
    }
       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;
+   }
+}