explorer: fixed going to location via command line. e.g.: explorer /home
[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 class Explorer : GuiApplication
18 {
19    //skin = "Acovel";
20
21    bool Init()
22    {
23       QuickPathTool goPath { };
24       QuickPathTool searchPath { };
25       char * findWhat = null;
26
27       SetLoggingMode(debug, null);
28
29       if(argc > 1)
30       {
31          if(!strcmpi(argv[1], "go") && argc > 2)
32             goPath = argv[2];
33          else if(!strcmpi(argv[1], "find") && argc > 2)
34          {
35             char * unquoted;
36             if(argv[2][0] == '\"')
37                StripQuotes(argv[2], unquoted);
38             else
39                unquoted = argv[2];
40             findWhat = CopyString(unquoted);
41             if(argc > 3)
42             {
43                if(!strcmpi(argv[3], "in") && argc > 4)
44                   searchPath = argv[4];
45                else
46                   searchPath = ""; // this should make it current dir
47             }
48             else
49                searchPath = ""; // same
50          } 
51          else if(!strcmpi(argv[1], "search") && argc > 2)
52             searchPath = argv[2];
53          else if(!strcmpi(argv[1], "image") && argc > 2)
54             ;
55          else if(!strcmpi(argv[1], "slides") && argc > 2)
56             ;
57          else
58             goPath = argv[1];
59       }
60       else
61          goPath = "";
62       if(goPath)
63       {
64          ExplorerWindow explorerWnd { };
65          explorerWnd.Create();
66          explorerWnd.view.path = goPath;
67       }
68       else if(searchPath)
69       {
70          ExplorerWindow explorerWnd { };
71          explorerWnd.Create();
72          //explorerWnd.SearchLocation(searchPath);
73       }
74       return true;
75    }
76 }
77
78 struct QuickPathTool
79 {
80    char path[MAX_LOCATION];
81
82    property char * 
83    {
84       set
85       {
86          char * unquoted;
87          GetWorkingDir(path, MAX_LOCATION);
88          if(value[0] == '\"')
89             StripQuotes(value, unquoted);
90          else
91             unquoted = value;
92          PathCat(path, unquoted);
93          if(!FileExists(path))
94          {
95             // this incomplete functionality is not quite at it's place in this class
96             int len;
97             char * original = CopyString(path);
98             while((len = strlen(path)))
99             {
100                StripLastDirectory(path, path);
101                if(FileExists(path))
102                {
103                   // TODO: message location does not exist, 
104                   //       this higher location exists though
105                   //       go there?
106                   break;
107                }
108             }
109             if(!len)
110             {
111                // TODO: message location does not exist, 
112                //       unable to select alternate location
113             }
114             path[0] = '\0';
115             delete original;
116          }
117       }
118       get { return path[0] ? path : null; }
119    }
120    property bool { get { return (bool)path[0]; } }
121 };
122
123 define app = ((Explorer)__thisModule);