455ef9d31fbdafa9d31ad4207278f4a90eb4c6ea
[ede] / newexplorer / src / Explorer.ec
1 import "ecere"
2 import "EDE"
3 import "ExplorerWindow"
4
5 class Explorer : GuiApplication
6 {
7    bool Init()
8    {
9       QuickPathTool goPath { };
10       QuickPathTool searchPath { };
11       char * findWhat = null;
12
13       SetLoggingMode(debug, null);
14
15       if(argc > 1)
16       {
17          if(!strcmpi(argv[1], "go") && argc > 2)
18             goPath = argv[2];
19          else if(!strcmpi(argv[1], "find") && argc > 2)
20          {
21             char * unquoted;
22             if(argv[2][0] == '\"')
23                StripQuotes(argv[2], unquoted);
24             else
25                unquoted = argv[2];
26             findWhat = CopyString(unquoted);
27             if(argc > 3)
28             {
29                if(!strcmpi(argv[3], "in") && argc > 4)
30                   searchPath = argv[4];
31                else
32                   searchPath = ""; // this should make it current dir
33             }
34             else
35                searchPath = ""; // same
36          } 
37          else if(!strcmpi(argv[1], "search") && argc > 2)
38             searchPath = argv[2];
39          else if(!strcmpi(argv[1], "image") && argc > 2)
40             ;
41          else if(!strcmpi(argv[1], "slides") && argc > 2)
42             ;
43          else
44             goPath = argv[1];
45       }
46       else
47          goPath = "";
48       if(goPath)
49       {
50          ExplorerWindow explorerWnd { };
51          explorerWnd.Create();
52          //explorerWnd.GoToLocation(goPath);
53       }
54       else if(searchPath)
55       {
56          ExplorerWindow explorerWnd { };
57          explorerWnd.Create();
58          //explorerWnd.SearchLocation(searchPath);
59       }
60       return true;
61    }
62 }
63
64 struct QuickPathTool
65 {
66    char path[MAX_LOCATION];
67
68    property char * 
69    {
70       set
71       {
72          char * unquoted;
73          GetWorkingDir(path, MAX_LOCATION);
74          if(value[0] == '\"')
75             StripQuotes(value, unquoted);
76          else
77             unquoted = value;
78          PathCat(path, unquoted);
79          if(!FileExists(path))
80          {
81             // this incomplete functionality is not quite at it's place in this class
82             int len;
83             char * original = CopyString(path);
84             while((len = strlen(path)))
85             {
86                StripLastDirectory(path, path);
87                if(FileExists(path))
88                {
89                   // TODO: message location does not exist, 
90                   //       this higher location exists though
91                   //       go there?
92                   break;
93                }
94             }
95             if(!len)
96             {
97                // TODO: message location does not exist, 
98                //       unable to select alternate location
99             }
100             path[0] = '\0';
101             delete original;
102          }
103       }
104       get { return path[0] ? path : null; }
105    }
106    property bool { get { return (bool)path[0]; } }
107 };
108
109 define app = ((Explorer)__thisModule);