wip II
[sdk] / ide / src / dialogs / FindInFilesDialog.ec
index 1c95975..c0f8e0f 100644 (file)
@@ -14,7 +14,6 @@ class FindInFilesDialog : Window
    tabCycle = true;
    size = { 440, 208 };
    autoCreate = false;
-   stayOnTop = true;
    
 public:
    property char * searchString { set { findContent.contents = value; } get { return findContent.contents; } };
@@ -143,7 +142,7 @@ public:
          DataRow row;
          sprintf(label, $"%s Project", project.name);
          row = findIn.AddString(label);
-         row.tag = (uint)project;
+         row.tag = (int64)project;
       }
    }
 
@@ -166,7 +165,7 @@ public:
    void Show()
    {
       if(!created)
-         Create();
+         Modal();
       else
          Activate();
    }
@@ -287,7 +286,7 @@ private:
          row = findWherePrjNode/*parentRow*/.AddRow();
       else
          row = findWherePrjNode.AddRow();
-      row.tag = (int)node;
+      row.tag = (int64)node;
       row.SetData(null, node);
       if(node.files)
       {
@@ -339,7 +338,7 @@ private:
 
       bool NotifySelect(DropBox control, DataRow row, Modifiers mods)
       {
-         fileFilter = row ? row.tag : 0;
+         fileFilter = (int)(row ? row.tag : 0);
          //ListFiles();
          return true;
       }
@@ -595,7 +594,7 @@ private:
 
    bool OnKeyHit(Key key, unichar ch)
    {
-      if(ch)
+      if(ch && !key.alt && !key.ctrl && !key.shift && (contentMatchCase.active || contentWholeWord.active))
       {
          findContent.Activate();
          return findContent.OnKeyHit(key, ch);
@@ -648,10 +647,11 @@ private:
 
    unsigned int Main()
    {
+      const int stackSize = 1024;
       int frame, treeTop = 0;
       int globalFindCount = 0, filesSearchedCount = 0, filesMatchedCount = 0, dirsMatchedCount = 0;
       //double lastTime = GetTime();
-      SearchStackFrame stack[1024];
+      SearchStackFrame stack[stackSize];
       FindInFilesMode mode = this.mode;
       
       EditBox replaceEdit = null;
@@ -662,27 +662,42 @@ private:
       app.Lock();
          {
             char substring[512];
+            char containing[512];
+            char * and;
+            char * filterName;
+            if(!strcmp(filter.name, "All files"))
+               filterName = "files";
+            else
+               filterName = filter.name;
             if(nameCriteria[0])
                sprintf(substring, $" with file name matching \"%s\"", nameCriteria);
             else
                substring[0] = '\0';
+            if(contentCriteria && contentCriteria[0])
+               sprintf(containing, $" containing \"%s\"", contentCriteria);
+            else
+               containing[0] = '\0';
+            if(substring[0] && containing[0])
+               and = " and";
+            else
+               and = "";
             if(mode == directory)
             {
                char * s;
                ide.outputView.findBox.Logf(
-                     $"Searching \"%s\"%s for %s%s%s containing \"%s\"\n\n",
+                     $"Searching \"%s\"%s for %s%s%s%s\n\n",
                      (s = CopySystemPath(dir)), subDirs ? $" and its sub directories" : "",
-                     filter.name, substring, substring[0] ? $" and" : "", contentCriteria);
+                     filterName, substring, and, containing);
                delete s;
             }
             else if(mode == workspace)
                ide.outputView.findBox.Logf(
-                     $"Searching workspace files for files%s%s containing \"%s\"\n\n",
-                     substring, substring[0] ? $" and" : "", contentCriteria);
+                     $"Searching workspace files for %s%s%s%s\n\n",
+                     filterName, substring, and, containing);
             else if(mode == project)
                ide.outputView.findBox.Logf(
-                     $"Searching project %s files for files%s%s containing \"%s\"\n\n",
-                     project.name, substring, substring[0] ? $" and" : "", contentCriteria);
+                     $"Searching project %s files for %s%s%s%s\n\n",
+                     project.name, filterName, substring, and, containing);
          }
       app.Unlock();
       
@@ -691,7 +706,7 @@ private:
          replaceEdit = EditBox
          {
             multiLine = true,textHorzScroll = true,textVertScroll = true, 
-            text = $"Replacing Editbox", size = Size { 640,480 },maxLineSize = 65536
+            text = $"Replacing Editbox", size = Size { 640,480 }/*,maxLineSize = 65536*/
          };
       }
 
@@ -700,7 +715,7 @@ private:
          strcpy(stack[0].path, dir);
          stack[0].fileList = FileListing { dir, extensions = filter.extensions };  // there should be a sorted = true/false 
 
-         for(frame = 0; frame >= 0 && !abort; )
+         for(frame = 0; frame >= 0 && frame < stackSize && !abort; )
          {
             if(stack[frame].fileList.Find())
             {
@@ -771,7 +786,7 @@ private:
                   app.Unlock();
                }
 
-               if(subDirs && stack[frame].fileList.stats.attribs.isDirectory)
+               if(subDirs && stack[frame].fileList.stats.attribs.isDirectory && strcmp(stack[frame].fileList.name, ".git"))
                {
                   int lastFrame = frame;
                   /*double thisTime = GetTime();
@@ -1021,6 +1036,14 @@ private:
                f.Seek(-strlen(contentCriteria), current);*/
          }
          delete f;
+         if(findCount)
+         {
+            app.Lock();
+               ide.outputView.findBox.Logf(
+                     $"Found %d match%s in \"%s\"%s\n\n", findCount, (findCount > 1) ? "es" : "",
+                     relative ? fileRelative : filePath, abortNow ? $" before search was aborted" : "");
+            app.Unlock();
+         }
       }
       else
       {
@@ -1028,14 +1051,6 @@ private:
             ide.outputView.findBox.Logf($"Unable to open file %s\n\n", filePath);
          app.Unlock();
       }
-      if(findCount)
-      {
-         app.Lock();
-            ide.outputView.findBox.Logf(
-                  $"Found %d match%s in \"%s\"%s\n\n", findCount, (findCount > 1) ? "es" : "",
-                  relative ? fileRelative : filePath, abortNow ? $" before search was aborted" : "");
-         app.Unlock();
-      }
       return findCount;
    }
 
@@ -1107,6 +1122,14 @@ private:
                
          }
          delete f;
+         if(replaceCount)
+         {
+            app.Lock();
+               ide.outputView.findBox.Logf(
+                     $"Replaced %d match%s in \"%s\"%s\n\n", replaceCount, (replaceCount > 1) ? $"es" : "",
+                     relative ? fileRelative : filePath, abortNow ? $" before search was aborted" : "");
+            app.Unlock();
+         }
       }
       else
       {
@@ -1114,14 +1137,6 @@ private:
             ide.outputView.findBox.Logf($"Unable to open file %s\n\n", filePath);
          app.Unlock();
       }
-      if(replaceCount)
-      {
-         app.Lock();
-            ide.outputView.findBox.Logf(
-                  $"Replaced %d match%s in \"%s\"%s\n\n", replaceCount, (replaceCount > 1) ? $"es" : "",
-                  relative ? fileRelative : filePath, abortNow ? $" before search was aborted" : "");
-         app.Unlock();
-      }
       return replaceCount;
    }
 }