Fixed major issues
[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             if(argv[2][0] == '\"')
50             {
51                findWhat = new char[strlen(argv[2])+1];
52                StripQuotes(argv[2], findWhat);
53             }
54             else
55                findWhat = CopyString(argv[2]);
56             if(argc > 3)
57             {
58                if(!strcmpi(argv[3], "in") && argc > 4)
59                   searchPath = argv[4];
60                else
61                   searchPath = ""; // this should make it current dir
62             }
63             else
64                searchPath = ""; // same
65          }
66          else if(!strcmpi(argv[1], "search") && argc > 2)
67             searchPath = argv[2];
68          else if(!strcmpi(argv[1], "compare") && argc > 2)
69          {
70             QuickPathTool goPath { };
71             comparedPaths = { };
72             if(argc == 3)
73             {
74                goPath = ""; // current dir
75                comparedPaths.Add(CopyString((const char *)goPath));  // TODO: Review whether this gets freed?
76             }
77             for(c = 2; c < argc; c++)
78             {
79                const char * s;
80                goPath = argv[c];
81                s = goPath;
82                if(s)
83                   comparedPaths.Add(CopyString(s));
84             }
85             if(comparedPaths.count < 2)
86                PrintLn("compare requires at least 2 existing directories to work.");
87          }
88          else if(!strcmpi(argv[1], "image") && argc > 2)
89             ;
90          else if(!strcmpi(argv[1], "slides") && argc > 2)
91             ;
92          else
93             openArgsStartAt = 1;
94       }
95       else
96          openArgsStartAt = -1;
97
98       if(openArgsStartAt)
99       {
100          QuickPathTool goPath { };
101          for(c = openArgsStartAt; c < argc; c++)
102          {
103             goPath = openArgsStartAt == -1 ? "" : argv[c];
104             if(goPath)
105             {
106                ExplorerWindow explorerWnd { };
107                explorerWnd.Create();
108                explorerWnd.location = goPath;//explorerWnd.GoTo(goPath, false, false);
109             }
110             if(openArgsStartAt == -1)
111                break;
112          }
113       }
114       else if(searchPath)
115       {
116          ExplorerWindow explorerWnd { };
117          explorerWnd.Create();
118          //explorerWnd.SearchLocation(searchPath);
119       }
120       else if(comparedPaths && comparedPaths.count > 1)
121       {
122          // compare /s1/library/dummies /s1/library/movies /s1/oldlib/movies "/home/redj/.gvfs/d02-2tb on kimji/library/movies"
123          ExplorerWindow explorerWnd { };
124          explorerWnd.Create();
125          explorerWnd.view.columnsCompareStyle = true;
126          explorerWnd.comparedLocations = comparedPaths;
127          comparedPaths = null;
128          // delete comparedPaths;
129       }
130       if(comparedPaths)
131       {
132          comparedPaths.Free();
133          delete comparedPaths;
134       }
135       return true;
136    }
137 }
138
139 struct QuickPathTool
140 {
141    char path[MAX_LOCATION];
142
143    property const char *
144    {
145       set
146       {
147          GetWorkingDir(path, MAX_LOCATION);
148          if(value[0] == '\"')
149          {
150             char * unquoted = new char[strlen(value) + 1];
151             StripQuotes(value, unquoted);
152             PathCat(path, unquoted);
153             delete unquoted;
154          }
155          else
156             PathCat(path, value);
157          if(!FileExists(path))
158          {
159             // this incomplete functionality is not quite at it's place in this class
160             int len;
161             char * original = CopyString(path);
162             while((len = strlen(path)))
163             {
164                StripLastDirectory(path, path);
165                if(FileExists(path))
166                {
167                   // TODO: message location does not exist,
168                   //       this higher location exists though
169                   //       go there?
170                   break;
171                }
172             }
173             if(!len)
174             {
175                // TODO: message location does not exist,
176                //       unable to select alternate location
177             }
178             path[0] = '\0';
179             delete original;
180          }
181       }
182       get { return path[0] ? (char*)path : null; }
183    }
184    property bool { get { return path[0] != '\0'; } }
185 };
186
187 define app = ((Explorer)__thisModule);