code dump. unfortunate lack of commits. rick click menu on files/folders. comparative...
[ede] / explorer / src / Explorer.ec
1 import "ecere"
2 import "EDE"
3 import "ExplorerWindow"
4
5 //import "Finder"
6 //import "Search"
7 //import "Panels"
8
9 /*
10 #ifdef __WIN32__
11 #include <direct.h>
12 #else
13 #include <unistd.h>
14 #endif
15 */
16
17 DummyFileSystemCacheWindow dw;// { size = { 200, 200 } };
18
19
20 class Explorer : GuiApplication
21 {
22    //skin = "Acovel";
23
24    bool Init()
25    {
26       int c, argc = this.argc;
27       int openArgsStartAt = 0;
28       QuickPathTool searchPath { };
29       char * findWhat = null;
30       Array<String> comparedPaths = null;
31
32       SetLoggingMode(debug, null);
33
34       for(c = 1; c < argc; c++)
35       {
36          if(!strcmp(argv[c], "#"))
37          {
38             argc = c;
39             break;
40          }
41       }
42
43       if(argc > 1)
44       {
45          if(!strcmpi(argv[1], "go") && argc > 2)
46             openArgsStartAt = 2;
47          else if(!strcmpi(argv[1], "find") && argc > 2)
48          {
49             char * unquoted;
50             if(argv[2][0] == '\"')
51                StripQuotes(argv[2], unquoted);
52             else
53                unquoted = argv[2];
54             findWhat = CopyString(unquoted);
55             if(argc > 3)
56             {
57                if(!strcmpi(argv[3], "in") && argc > 4)
58                   searchPath = argv[4];
59                else
60                   searchPath = ""; // this should make it current dir
61             }
62             else
63                searchPath = ""; // same
64          } 
65          else if(!strcmpi(argv[1], "search") && argc > 2)
66             searchPath = argv[2];
67          else if(!strcmpi(argv[1], "compare") && argc > 2)
68          {
69             QuickPathTool goPath { };
70             comparedPaths = { };
71             if(argc == 3)
72             {
73                goPath = ""; // current dir
74                comparedPaths.Add(goPath);
75             }
76             for(c = 2; c < argc; c++)
77             {
78                char * s;
79                goPath = argv[c];
80                s = goPath;
81                if(s)
82                   comparedPaths.Add(CopyString(s));
83             }
84             if(comparedPaths.count < 2)
85                PrintLn("compare requires at least 2 existing directories to work.");
86          }
87          else if(!strcmpi(argv[1], "image") && argc > 2)
88             ;
89          else if(!strcmpi(argv[1], "slides") && argc > 2)
90             ;
91          else
92             openArgsStartAt = 1;
93       }
94       else
95          openArgsStartAt = -1;
96
97       if(openArgsStartAt)
98       {
99          QuickPathTool goPath { };
100          for(c = openArgsStartAt; c < argc; c++)
101          {
102             goPath = openArgsStartAt == -1 ? "" : argv[c];
103             if(goPath)
104             {
105                ExplorerWindow explorerWnd { };
106                explorerWnd.Create();
107                explorerWnd.location = goPath;//explorerWnd.GoTo(goPath, false, false);
108             }
109          }
110       }
111       else if(searchPath)
112       {
113          ExplorerWindow explorerWnd { };
114          explorerWnd.Create();
115          //explorerWnd.SearchLocation(searchPath);
116       }
117       else if(comparedPaths && comparedPaths.count > 1)
118       {
119          // compare /s1/library/dummies /s1/library/movies /s1/oldlib/movies "/home/redj/.gvfs/d02-2tb on kimji/library/movies"
120          ExplorerWindow explorerWnd { };
121          explorerWnd.Create();
122          explorerWnd.view.columnsCompareStyle = true;
123          explorerWnd.comparedLocations = comparedPaths;
124          // delete comparedPaths;
125       }
126       return true;
127    }
128 }
129
130 struct QuickPathTool
131 {
132    char path[MAX_LOCATION];
133
134    property char * 
135    {
136       set
137       {
138          char * unquoted;
139          GetWorkingDir(path, MAX_LOCATION);
140          if(value[0] == '\"')
141             StripQuotes(value, unquoted);
142          else
143             unquoted = value;
144          PathCat(path, unquoted);
145          if(!FileExists(path))
146          {
147             // this incomplete functionality is not quite at it's place in this class
148             int len;
149             char * original = CopyString(path);
150             while((len = strlen(path)))
151             {
152                StripLastDirectory(path, path);
153                if(FileExists(path))
154                {
155                   // TODO: message location does not exist, 
156                   //       this higher location exists though
157                   //       go there?
158                   break;
159                }
160             }
161             if(!len)
162             {
163                // TODO: message location does not exist, 
164                //       unable to select alternate location
165             }
166             path[0] = '\0';
167             delete original;
168          }
169       }
170       get { return path[0] ? (char*)path : null; }
171    }
172    property bool { get { return path[0] != '\0'; } }
173 };
174
175 define app = ((Explorer)__thisModule);