explorer: started using the new FileSystemSearch class. this will search for .txt...
[ede] / explorer / src / ExplorerWindow.ec
index 2a61c01..b8cb03d 100644 (file)
@@ -125,30 +125,67 @@ class ExplorerWindow : Window
             case goBack:
             case goForward:
                break;
+            case goHome:
+            {
+               char * home = getenv("HOME");
+               if(home && home[0] && FileExists(home).isDirectory)
+                  GoToLocation(home, false, false);
+               break;
+            }
             case goUp:
             {
                char * path = view.path;
-               char * newPath = new char[strlen(path)];
+               char * newPath = new char[strlen(path)+1];
                StripLastDirectory(path, newPath);
                if(!newPath[0])
                {
                   newPath[0] = '/';
                   newPath[1] = 0;
                }
-               view.path = newPath;
+               GoToLocation(newPath, false, false);
                delete newPath;
                break;
             }
             case panelTree:
                // TODO TOFIX : need to fix Stacker for this to work
                tree.visible = button.checked;
+               split.visible = button.checked;
+               if(button.checked)
+               {
+                  split.rightPane = view;
+                  view.anchor = { top = 0, bottom = 0, right = 0 };
+                  tree.SelectLocation(view.path);
+               }
+               else
+               {
+                  split.rightPane = null;
+                  view.anchor = { left = 0, top = 0, bottom = 0, right = 0 };
+               }
                //search.visible = !button.checked;
                panels.size = { panels.size.w, panels.size.h }; // TOFIX : another Stacker fix needed
                break;
             case panelSearch:
                // TODO TOFIX : need to fix Stacker for this to work
                //search.visible = button.checked;
-               tree.visible = !button.checked;
+               tree.visible = false; //!button.checked;
+               split.visible = false; //!button.checked;
+               if(button.checked)
+               {
+                  /*split.rightPane = view;
+                  view.anchor = { top = 0, bottom = 0, right = 0 };*/
+                  split.rightPane = null;
+                  view.anchor = { left = 0, top = 0, bottom = 0, right = 0 };
+
+                  SearchStart();
+               }
+               else
+               {
+                  split.rightPane = null;
+                  view.anchor = { left = 0, top = 0, bottom = 0, right = 0 };
+
+                  SearchStop();
+                  view.path = addressBar.path;
+               }
                panels.size = { panels.size.w, panels.size.h }; // TOFIX : another Stacker fix needed
                break;
             case refresh:
@@ -204,7 +241,7 @@ class ExplorerWindow : Window
 
       bool NotifyModified(PathBox pathBox)
       {
-         view.path = pathBox.path;
+         GoToLocation(pathBox.path, false, false);
          return true;
       }
    };
@@ -269,44 +306,149 @@ class ExplorerWindow : Window
       panels, this;
    };*/
 
-   /*Tree*/FileSystemBox tree;
-   /*{
+   Window hack
+   {
       panels, this;
-      size = { w = 240 };
       anchor.top = 0;
       anchor.bottom = 0;
-      navigateFolders = true;
+      anchor.right = 0;
+      borderStyle = deep;
+   };
+
+   /*Tree*/FileSystemBox tree//;
+   {
+      hack, this;
+      size = { w = 240 };
+      borderStyle = none;
+      visible = false;
+      /*anchor.top = 0;
+      anchor.bottom = 0;*/
+      anchor = { left = 0, top = 0, bottom = 0 };
+
       treeBranches = true;
       foldersOnly = true;
-      borderStyle = none;
+      autoLoad = false;
+
+      bool NotifyNodeSelect(FileSystemBox box, FileSystemNode node)
+      {
+         char p[MAX_LOCATION];
+         node.GetPath(p);
+         GoToLocation(node.path, false, true);
+         return true;
+      }
+   };
+
+   PaneSplitter split
+   {
+      hack, this;
       visible = false;
-   };*/
+      leftPane = tree;//, rightPane = view;
+      split = 300;
+   };
 
    FileSystemBox view
    {
-      panels, this;
-      anchor.top = 0;
+      hack, this;
+      borderStyle = none;
+      /*anchor.top = 0;
       anchor.bottom = 0;
-      anchor.right = 0;
+      anchor.right = 0;*/
+      anchor = { left = 0, top = 0, bottom = 0, right = 0 };
+
       locationBox = addressBar;
       navigateFolders = true;
-      borderStyle = none;
-
       multiSelect = true;
+      autoLoad = false;
 
       bool NotifyNodeOpen(FileSystemBox box, FileSystemNode node)
       {
          if(node.type.isFile)
          {
+            char path[MAX_LOCATION];
+         #ifndef __WIN32__
             char command[MAX_LOCATION];
-            char * t = node.path;
-            sprintf(command, "ide %s", node.path);
-            ShellOpen(command);
+            node.GetPath(path);
+            /*_FileType t = node.type;
+            if(t == ewsFile || t == epjFile ||
+                  t == ecFile || t == ehFile ||
+                  t == cppFile || t == hppFile ||
+                  t == cFile || t == hFile ||
+                  t == textFile || t == webFile)*/
+               sprintf(command, "ide %s", path);
+            /*else
+               sprintf(command, "%s", path);*/
+            Execute(command);
+         #else
+            node.GetPath(path);
+            ShellOpen(path);
+         #endif
          }
+         else if(node.type.isFolder && tree.visible)
+            tree.SelectLocation(node.path);
          return true;
       }
    };
 
+   FileSystemSearch searchThread
+   {
+      owner = this, fsb = view/*, searchPanel = this*/;
+
+      bool Window::NotifyUpdateSearchLocation(FileSystemSearch search, char * location)
+      {
+         char text[2048];
+         sprintf(text, "Search Results (Searching %s)", location);
+         PrintLn(text); //view.results.text = text;
+         return true;
+      }
+   };
+
+   void SearchStart()
+   {
+      char text[2048];
+
+      searchThread.active = true;
+
+      searchThread.optionSubdirs = true; //options.subdirs.checked;
+      searchThread.optionTree = view.treeBranches; //(options.subdirs.checked && options.tree.checked);
+      searchThread.optionBrowser = false; //(options.subdirs.checked && options.browser.checked);
+      searchThread.optionNameMatchCase = false; //findName.optionMatchCase.checked;
+      searchThread.optionNameMatchWord = false; //findName.optionMatchWord.checked;
+      searchThread.optionContentMatchCase = false; //findTextContent.optionMatchCase.checked;
+      searchThread.optionContentMatchWord = false; //findTextContent.optionMatchWord.checked;
+
+      strcpy(searchThread.location, view.path/*location.GetText()*/);
+      strcpy(searchThread.nameSearch, ".txt"/*findName.GetText()*/);
+      strcpy(searchThread.contentSearch, ""/*findTextContent.GetText()*/);
+
+      //actions.startStop.text = "Stop Search";
+      //actions.clear.disabled = false;
+      //view.results.Clear();
+      //view.results.hasHeader = !searchThread.optionTree;
+      //view.results.treeBranches = searchThread.optionTree;
+      //view.browser.Clear();
+      //ToggleBrowserDisplay(searchThread.optionBrowser);
+
+      //view.browser.text = "Browser";
+      //sprintf(text, "Search Results (Searching %s)", location.GetText());
+      PrintLn("Search Results (Searching ", view.path, ")");
+      //view.results.text = text;
+
+      searchThread.Create();
+   }
+
+   bool SearchStop()
+   {
+      if(searchThread.active)
+      {
+         searchThread.terminate = true;
+         app.Unlock();
+            searchThread.Wait();
+         app.Lock();
+         return true;
+      }
+      return false;
+   }
+
    /*ExplorerSearch search
    {
       deep, this;
@@ -323,13 +465,6 @@ class ExplorerWindow : Window
       parent = deep, master = this;
       tabCycle = true;
       anchor = Anchor { top = 0, bottom = 0, right = 0 };
-   };
-
-   SplitWindow split
-   {
-      deep, this;
-      leftPane = tree, rightPane = viewHolder;
-      split = 300;
    };*/
 
    // Preview / Showcase
@@ -407,34 +542,13 @@ class ExplorerWindow : Window
       lastViewId = viewId;
    }*/
 
-   /*void GoToLocation(char * location)
+   void GoToLocation(char * location, bool viewIsAtLocation, bool treeIsAtLocation)
    {
-      int c;
-      char * temp;
-      char step[MAX_LOCATION];
-      
-      StringArray steps { growingFactor = 4 };
-      ExplorerFileBranch last = null;
-      
-      temp = CopyString(location);
-      while(strlen(temp))
-      {
-         GetLastDirectory(temp, step);
-         StripLastDirectory(temp, temp);
-         steps.Add(CopyString(step));
-      }
-      
-      for(c = steps._count - 1; c >= 0; c--)
-      {
-         last = tree.Find(steps._[c], last);
-         if(!last)
-            break;
-         tree.Select(last);
-      }
-      
-      delete temp;
-      delete steps;
-   }*/
+      if(!viewIsAtLocation)
+         view.path = location;
+      if(tree.visible && !treeIsAtLocation)
+         tree.SelectLocation(location);
+   }
 
    /*void SearchLocation(char * location)
    {
@@ -446,6 +560,7 @@ class ExplorerWindow : Window
    {
       //userMode = true;
       addressBar.path = view.path;
+      tree.path = "/"; // this should be available as a parameter
       return true;
    }