explorer: introducing new explorer based on ede::FileSystemBox
[ede] / newexplorer / src / Explorer.ec
diff --git a/newexplorer/src/Explorer.ec b/newexplorer/src/Explorer.ec
new file mode 100644 (file)
index 0000000..cb9fa3d
--- /dev/null
@@ -0,0 +1,107 @@
+import "ecere"
+import "EDE"
+import "ExplorerWindow"
+
+class Explorer : GuiApplication
+{
+   bool Init()
+   {
+      QuickPathTool goPath { };
+      QuickPathTool searchPath { };
+      char * findWhat = null;
+      SetLoggingMode(debug, null);
+      if(argc > 1)
+      {
+         if(!strcmpi(argv[1], "go") && argc > 2)
+            goPath = argv[2];
+         else if(!strcmpi(argv[1], "find") && argc > 2)
+         {
+            char * unquoted;
+            if(argv[2][0] == '\"')
+               StripQuotes(argv[2], unquoted);
+            else
+               unquoted = argv[2];
+            findWhat = CopyString(unquoted);
+            if(argc > 3)
+            {
+               if(!strcmpi(argv[3], "in") && argc > 4)
+                  searchPath = argv[4];
+               else
+                  searchPath = ""; // this should make it current dir
+            }
+            else
+               searchPath = ""; // same
+         } 
+         else if(!strcmpi(argv[1], "search") && argc > 2)
+            searchPath = argv[2];
+         else if(!strcmpi(argv[1], "image") && argc > 2)
+            ;
+         else if(!strcmpi(argv[1], "slides") && argc > 2)
+            ;
+         else
+            goPath = argv[1];
+      }
+      else
+         goPath = "";
+      if(goPath)
+      {
+         ExplorerWindow explorerWnd { };
+         explorerWnd.Create();
+         //explorerWnd.GoToLocation(goPath);
+      }
+      else if(searchPath)
+      {
+         ExplorerWindow explorerWnd { };
+         explorerWnd.Create();
+         //explorerWnd.SearchLocation(searchPath);
+      }
+      return true;
+   }
+}
+
+struct QuickPathTool
+{
+   char path[MAX_LOCATION];
+
+   property char * 
+   {
+      set
+      {
+         char * unquoted;
+         GetWorkingDir(path, MAX_LOCATION);
+         if(value[0] == '\"')
+            StripQuotes(value, unquoted);
+         else
+            unquoted = value;
+         PathCat(path, unquoted);
+         if(!FileExists(path))
+         {
+            // this incomplete functionality is not quite at it's place in this class
+            int len;
+            char * original = CopyString(path);
+            while((len = strlen(path)))
+            {
+               StripLastDirectory(path, path);
+               if(FileExists(path))
+               {
+                  // TODO: message location does not exist, 
+                  //       this higher location exists though
+                  //       go there?
+                  break;
+               }
+            }
+            if(!len)
+            {
+               // TODO: message location does not exist, 
+               //       unable to select alternate location
+            }
+            path[0] = '\0';
+            delete original;
+         }
+      }
+      get { return path[0] ? path : null; }
+   }
+   property bool { get { return (bool)path[0]; } }
+};
+
+define app = ((Explorer)__thisModule);