38b30b6efc6e98f4dc24f030597e0d68f91a555a
[ede] / explorer / src / ExplorerWindow.ec
1 import "Explorer"
2 import "IconBag"
3 import "ToolBar"
4
5 enum ExplorerToolId
6 {
7    none,
8    newWindow, goBack, goForward, goUp, goHome,
9    browse,
10    panelTree, panelSearch,
11    addressBar,
12    refresh,
13    viewList, viewDetails, viewIcons, viewCards, viewShowcase, viewTree, viewCustom,
14    previewPictures
15 };
16
17 class ExplorerWindow : Window
18 {
19 #ifdef _DEBUG
20    text = "Ecere Explorer (Debug)";
21 #else
22    text = "Ecere Explorer";
23 #endif
24    background = activeBorder;
25    borderStyle = sizable;
26    hasMaximize = true;
27    hasMinimize = true;
28    hasClose = true;
29    hasMenuBar = true;
30    //tabCycle = true;
31    size = { 840, 480 };
32    minClientSize = { 600, 300 };
33    nativeDecorations = true;
34
35    /*
36    bool userMode;
37    bool clipboard;
38
39    int treeSplit;
40    int searchSplit;
41    
42    ExplorerToolId lastViewId;
43 */
44
45    menu = Menu { };
46    
47    Menu fileMenu { menu, "File", f };
48    Menu windowMenu { menu, "Window", w };
49       MenuItem itemNewWindow
50       {
51          windowMenu, "New Window", n;
52          
53          bool NotifySelect(MenuItem selection, Modifiers mods)
54          {
55             ExplorerWindow { }.Create();
56             return true;
57          }
58       };
59
60    IconBag<ExplorerToolId> iconBag
61    {
62       //window = guiApp.desktop;
63       window = this;
64       alphaBlend = true;
65       iconNames =
66       [
67          "<:ecere>emblems/unreadable.png",     /* none */
68
69          "<:ecere>actions/windowNew.png",            /* newWindow */
70          "<:ecere>actions/goPrevious.png",           /* goBack */
71          "<:ecere>actions/goNext.png",               /* goForward */
72          "<:ecere>actions/goUp.png",                 /* goUp */
73          "<:ecere>actions/goHome.png",               /* goHome */
74
75          ":browse.png",                                           /* browse */
76
77          ":panel-tree.png",                                       /* panelTree */
78          "<:ecere>actions/editFind.png",             /* panelSearch */
79
80          "<:ecere>emblems/unreadable.png",     /* addressBar */
81
82          "<:ecere>actions/viewRefresh.png",          /* refresh */
83
84          ":view-list.png",                                        /* viewList */
85          ":view-details.png",                                     /* viewDetails */
86          ":view-icons.png",                                       /* viewIcons */
87          ":view-cards.png",                                       /* viewCards */
88          ":view-showcase-right.png",                              /* viewShowcase */
89          ":panel-tree.png",                                       /* viewTree */
90          ":view-custom.png",                                      /* viewCustom */
91          
92          "<:ecere>mimeTypes/image.png"     /* previewPictures */
93       ];
94    };
95
96    Stacker stack
97    {
98       this;
99       gap = 0;
100       direction = vertical;
101       background = activeBorder;
102       //opacity = 1.0f;
103       
104       anchor = { left = 0, top = 0, right = 0, bottom = 0 };
105       //moveable = false;
106    };
107
108    ToolBar/*<ExplorerToolId>*/ toolBar
109    {
110       stack, this;
111       iconBag = iconBag;
112       size = { h = 32 };
113       //moveable = false;
114
115       void NotifyToolClick(ToolButton button)
116       {
117          ExplorerToolId id = (ExplorerToolId)button.id;
118          switch(id)
119          {
120             case none:
121                break;
122             case newWindow:
123                ExplorerWindow { }.Create();
124                break;
125             case goBack:
126             case goForward:
127                break;
128             case goUp:
129             {
130                char * path = view.path;
131                char * newPath = new char[strlen(path)];
132                StripLastDirectory(path, newPath);
133                if(!newPath[0])
134                {
135                   newPath[0] = '/';
136                   newPath[1] = 0;
137                }
138                view.path = newPath;
139                delete newPath;
140                break;
141             }
142             case panelTree:
143                // TODO TOFIX : need to fix Stacker for this to work
144                tree.visible = button.checked;
145                //search.visible = !button.checked;
146                panels.size = { panels.size.w, panels.size.h }; // TOFIX : another Stacker fix needed
147                break;
148             case panelSearch:
149                // TODO TOFIX : need to fix Stacker for this to work
150                //search.visible = button.checked;
151                tree.visible = !button.checked;
152                panels.size = { panels.size.w, panels.size.h }; // TOFIX : another Stacker fix needed
153                break;
154             case refresh:
155                if(tree.visible)
156                   tree.Refresh();
157                view.Refresh();
158                break;
159             case previewPictures:
160                view.previewPictures = button.checked;
161                view.Refresh();
162                break;
163             case viewList:
164             case viewDetails:
165             case viewIcons:
166             case viewCards:
167             case viewShowcase:
168                //SwitchViews(toolId);
169                view.treeBranches = false;
170                view.Refresh();
171                break;
172             case viewTree:
173                view.treeBranches = button.checked;
174                view.Refresh();
175                break;
176          }
177       }
178    };
179
180    Window s1 { toolBar, size = { w = 8 } };
181    ToolButton goBack { toolBar, this, id = ExplorerToolId::goBack };
182    Window s2 { toolBar, size = { w = 2 } };
183    ToolButton goForward { toolBar, this, id = ExplorerToolId::goForward };
184    Window s3 { toolBar, size = { w = 2 } };
185    ToolButton refresh { toolBar, this, id = ExplorerToolId::refresh };
186    Window s4 { toolBar, size = { w = 2 } };
187    ToolButton goHome { toolBar, this, id = ExplorerToolId::goHome };
188    Window s5 { toolBar, size = { w = 8 } };
189    PathBox addressBar
190    {
191       toolBar, this;
192       size = { 300, 23 }, id = ExplorerToolId::addressBar;
193       typeExpected = directory;
194
195       bool OnKeyDown(Key key, unichar ch)
196       {
197          if((SmartKey)key == enter)
198          {
199             // how to make enter effect a modification
200             // how to implement in PathBox
201          }
202          return true;
203       }
204
205       bool NotifyModified(PathBox pathBox)
206       {
207          view.path = pathBox.path;
208          return true;
209       }
210    };
211    FlipStacker { toolBar, spring = previous };
212    Window s6 { toolBar, size = { w = 8 } };
213    ToolButton goUp { toolBar, this, id = ExplorerToolId::goUp };
214    Window s7 { toolBar, size = { w = 8 } };
215    GroupToggleToolButton selectedPanel;
216    GroupToggleToolButton panelTree   { toolBar, this, id = ExplorerToolId::panelTree, selected = &selectedPanel, checked = true };
217    GroupToggleToolButton panelSearch { toolBar, this, id = ExplorerToolId::panelSearch, selected = &selectedPanel };
218    selectedPanel = panelTree;
219    Window s8 { toolBar, size = { w = 8 } };
220    OptionToolButton selectedView;
221    OptionToolButton viewList     { toolBar, this, id = ExplorerToolId::viewList, selected = &selectedView, checked = true };
222    OptionToolButton viewDetails  { toolBar, this, id = ExplorerToolId::viewDetails, selected = &selectedView };
223    OptionToolButton viewIcons    { toolBar, this, id = ExplorerToolId::viewIcons, selected = &selectedView };
224    OptionToolButton viewTiles    { toolBar, this, id = ExplorerToolId::viewCards, selected = &selectedView };
225    OptionToolButton viewShowcase { toolBar, this, id = ExplorerToolId::viewShowcase, selected = &selectedView };
226    OptionToolButton viewTree     { toolBar, this, id = ExplorerToolId::viewTree, selected = &selectedView };
227    selectedView = viewList;
228    Window s9 { toolBar, size = { w = 8 } };
229    ToggleToolButton previewPictures { toolBar, this, id = ExplorerToolId::previewPictures };
230
231    Window s10 { toolBar, size = { w = 8 } };
232    ToolButton newWindow { toolBar, this, id = ExplorerToolId::newWindow };
233    Window s11 { toolBar, size = { w = 8 } };
234
235    /*void OnDestroy()
236    {
237       iconBag.window = null;
238       delete iconBag;
239    }*/
240
241    bool OnLoadGraphics()
242    {
243       iconBag.Load();
244       return true;
245    }
246
247    void OnUnloadGraphics()
248    {
249       iconBag.Unload();
250    }
251
252    Stacker panels
253    {
254       stack, this;
255       gap = 0;
256       direction = horizontal;
257       background = yellow;//activeBorder;
258       //opacity = 1.0f;
259
260       anchor.left = 0;
261       anchor.bottom = 0;
262       anchor.right = 0;
263    };
264
265    //FlipStacker flipStack { stack, spring = previous };
266
267    /*SearchPanel searchPanel
268    {
269       panels, this;
270    };*/
271
272    /*Tree*/FileSystemBox tree;
273    /*{
274       panels, this;
275       size = { w = 240 };
276       anchor.top = 0;
277       anchor.bottom = 0;
278       navigateFolders = true;
279       treeBranches = true;
280       foldersOnly = true;
281       borderStyle = none;
282       visible = false;
283    };*/
284
285    FileSystemBox view
286    {
287       panels, this;
288       anchor.top = 0;
289       anchor.bottom = 0;
290       anchor.right = 0;
291       locationBox = addressBar;
292       navigateFolders = true;
293       borderStyle = none;
294
295       multiSelect = true;
296
297       bool NotifyNodeOpen(FileSystemBox box, FileSystemNode node)
298       {
299          if(node.type.isFile)
300          {
301             char command[MAX_LOCATION];
302             /*_FileType t = node.type;
303             if(t == ewsFile || t == epjFile ||
304                   t == ecFile || t == ehFile ||
305                   t == cppFile || t == hppFile ||
306                   t == cFile || t == hFile ||
307                   t == textFile || t == webFile)*/
308                sprintf(command, "ide %s", node.path);
309             /*else
310                sprintf(command, "%s", node.path);*/
311             ShellOpen(command);
312          }
313          return true;
314       }
315    };
316
317    /*ExplorerSearch search
318    {
319       deep, this;
320       visible = false;
321       tabCycle = true;
322       size = Size { 624, 268 };
323       anchor = Anchor { left = 0, top = 0, bottom = 0 };
324    };
325
326    ExplorerViewSearch results;*/
327
328    /*Window viewHolder
329    {
330       parent = deep, master = this;
331       tabCycle = true;
332       anchor = Anchor { top = 0, bottom = 0, right = 0 };
333    };
334
335    SplitWindow split
336    {
337       deep, this;
338       leftPane = tree, rightPane = viewHolder;
339       split = 300;
340    };*/
341
342    // Preview / Showcase
343    /*PreviewArea previewArea
344    {
345       panels, this;
346    };*/
347
348    //FlipStacker flipPanels { panels, spring = previous };
349
350    /*bool TreeNotifyBranchSelect(ExplorerTree tree, ExplorerFileBranch branch)
351    {
352       if(branch)
353       {
354          char path[MAX_LOCATION];
355          branch.GetPath(path);
356          toolBar.addressBar.contents = path;
357          view.Load(branch);
358       }
359       return true;
360    }*/
361    
362    /*bool ViewNotifyItemOpen(ExplorerView view, ExplorerFileItem item)
363    {
364       ExplorerFileBranch branch = tree.branch;
365       if(item && branch)
366       {
367          if(item.type.isFolderType)
368          {
369             ExplorerFileBranch child;
370             
371             if(!branch.loaded || !branch.childrenLoaded)
372                BranchLoad(branch, tree.tree);
373
374             for(child = branch.children.first; child; child = child.next)
375                if(!strcmp(child.name, item.name))
376                   break;
377             
378             if(child)
379             {
380                if(branch.row.collapsed)
381                   child.row.collapsed = true;
382                child.EnsureVisible(false);
383                tree.Select(child);
384             }
385          }
386          else
387          {
388             char path[MAX_LOCATION];
389             branch.GetPath(path);
390             PathCat(path, item.name);
391             ShellOpen(path);
392          }
393       }
394    }*/
395
396    /*void SwitchViews(ExplorerToolId viewId)
397    {
398       ExplorerFileBranch branch = tree.branch;
399       view.Destroy(0);
400       switch(viewId)
401       {
402          case viewList:     view = ExplorerViewList     { parent = viewHolder, master = this }; break;
403          case viewDetails:  view = ExplorerViewDetails  { parent = viewHolder, master = this }; break;
404          case viewIcons:    view = ExplorerViewIcons    { parent = viewHolder, master = this }; break;
405          case viewCards:    view = ExplorerViewCards    { parent = viewHolder, master = this }; break;
406          case viewShowcase: view = ExplorerViewShowcase { parent = viewHolder, master = this }; break;
407       }
408       view.tabCycle = true;
409       view.previewPictures = toolBar.previewPictures.checked;
410       view.anchor = Anchor { left = 0, top = 0, bottom = 0, right = 0 };
411       view.NotifyItemOpen = ViewNotifyItemOpen;
412       view.Create();
413       view.Load(branch);
414       lastViewId = viewId;
415    }*/
416
417    /*void GoToLocation(char * location)
418    {
419       int c;
420       char * temp;
421       char step[MAX_LOCATION];
422       
423       StringArray steps { growingFactor = 4 };
424       ExplorerFileBranch last = null;
425       
426       temp = CopyString(location);
427       while(strlen(temp))
428       {
429          GetLastDirectory(temp, step);
430          StripLastDirectory(temp, temp);
431          steps.Add(CopyString(step));
432       }
433       
434       for(c = steps._count - 1; c >= 0; c--)
435       {
436          last = tree.Find(steps._[c], last);
437          if(!last)
438             break;
439          tree.Select(last);
440       }
441       
442       delete temp;
443       delete steps;
444    }*/
445
446    /*void SearchLocation(char * location)
447    {
448       GoToLocation(location);
449       search.location.editBox.contents = location;
450    }*/
451
452    bool OnPostCreate()
453    {
454       //userMode = true;
455       addressBar.path = view.path;
456       return true;
457    }
458
459    /*ExplorerWindow()
460    {
461       userMode = false;
462
463       treeSplit = 300;
464       searchSplit = 200;
465
466       view = ExplorerViewList
467       {
468          parent = viewHolder, master = this;
469          tabCycle = true;
470          previewPictures = toolBar.previewPictures.checked;
471          anchor = Anchor { left = 0, top = 0, bottom = 0, right = 0 };
472          NotifyItemOpen = ViewNotifyItemOpen;
473       };
474       lastViewId = viewList;
475       
476       tree.Load();
477       view.Load(tree.root);
478    }*/
479
480    /*void InitTree()
481    {
482    }*/
483
484    /*void InitSearch()
485    {
486    }*/
487 }
488
489 //class TreeFileSystemBox : FileSystemBox { }