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