explorer: fixed go up on root crash (jerome's fix)
[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                if(!newPath[0])
130                {
131                   newPath[0] = '/';
132                   newPath[1] = 0;
133                }
134                view.path = newPath;
135                delete newPath;
136                break;
137             }
138             case panelTree:
139                // TODO TOFIX : need to fix Stacker for this to work
140                tree.visible = button.checked;
141                //search.visible = !button.checked;
142                panels.size = { panels.size.w, panels.size.h }; // TOFIX : another Stacker fix needed
143                break;
144             case panelSearch:
145                // TODO TOFIX : need to fix Stacker for this to work
146                //search.visible = button.checked;
147                tree.visible = !button.checked;
148                panels.size = { panels.size.w, panels.size.h }; // TOFIX : another Stacker fix needed
149                break;
150             case refresh:
151                if(tree.visible)
152                   tree.Refresh();
153                view.Refresh();
154                break;
155             case previewPictures:
156                view.previewPictures = button.checked;
157                view.Refresh();
158                break;
159             case viewList:
160             case viewDetails:
161             case viewIcons:
162             case viewCards:
163             case viewShowcase:
164                //SwitchViews(toolId);
165                view.treeBranches = false;
166                view.Refresh();
167                break;
168             case viewTree:
169                view.treeBranches = button.checked;
170                view.Refresh();
171                break;
172          }
173       }
174    };
175
176    Window s1 { toolBar, size = { w = 8 } };
177    ToolButton goBack { toolBar, this, id = ExplorerToolId::goBack };
178    Window s2 { toolBar, size = { w = 2 } };
179    ToolButton goForward { toolBar, this, id = ExplorerToolId::goForward };
180    Window s3 { toolBar, size = { w = 2 } };
181    ToolButton refresh { toolBar, this, id = ExplorerToolId::refresh };
182    Window s4 { toolBar, size = { w = 2 } };
183    ToolButton goHome { toolBar, this, id = ExplorerToolId::goHome };
184    Window s5 { toolBar, size = { w = 8 } };
185    PathBox addressBar
186    {
187       toolBar, this;
188       size = { 300, 23 }, id = ExplorerToolId::addressBar;
189       typeExpected = directory;
190
191       bool OnKeyDown(Key key, unichar ch)
192       {
193          if((SmartKey)key == enter)
194          {
195             // how to make enter effect a modification
196             // how to implement in PathBox
197          }
198          return true;
199       }
200
201       bool NotifyModified(PathBox pathBox)
202       {
203          view.path = pathBox.path;
204          return true;
205       }
206    };
207    FlipStacker { toolBar, spring = previous };
208    Window s6 { toolBar, size = { w = 8 } };
209    ToolButton goUp { toolBar, this, id = ExplorerToolId::goUp };
210    Window s7 { toolBar, size = { w = 8 } };
211    GroupToggleToolButton selectedPanel;
212    GroupToggleToolButton panelTree   { toolBar, this, id = ExplorerToolId::panelTree, selected = &selectedPanel, checked = true };
213    GroupToggleToolButton panelSearch { toolBar, this, id = ExplorerToolId::panelSearch, selected = &selectedPanel };
214    selectedPanel = panelTree;
215    Window s8 { toolBar, size = { w = 8 } };
216    OptionToolButton selectedView;
217    OptionToolButton viewList     { toolBar, this, id = ExplorerToolId::viewList, selected = &selectedView, checked = true };
218    OptionToolButton viewDetails  { toolBar, this, id = ExplorerToolId::viewDetails, selected = &selectedView };
219    OptionToolButton viewIcons    { toolBar, this, id = ExplorerToolId::viewIcons, selected = &selectedView };
220    OptionToolButton viewTiles    { toolBar, this, id = ExplorerToolId::viewCards, selected = &selectedView };
221    OptionToolButton viewShowcase { toolBar, this, id = ExplorerToolId::viewShowcase, selected = &selectedView };
222    OptionToolButton viewTree     { toolBar, this, id = ExplorerToolId::viewTree, selected = &selectedView };
223    selectedView = viewList;
224    Window s9 { toolBar, size = { w = 8 } };
225    ToggleToolButton previewPictures { toolBar, this, id = ExplorerToolId::previewPictures };
226
227    Window s10 { toolBar, size = { w = 8 } };
228    ToolButton newWindow { toolBar, this, id = ExplorerToolId::newWindow };
229    Window s11 { toolBar, size = { w = 8 } };
230
231    /*void OnDestroy()
232    {
233       iconBag.window = null;
234       delete iconBag;
235    }*/
236
237    bool OnLoadGraphics()
238    {
239       iconBag.Load();
240       return true;
241    }
242
243    void OnUnloadGraphics()
244    {
245       iconBag.Unload();
246    }
247
248    Stacker panels
249    {
250       stack, this;
251       gap = 0;
252       direction = horizontal;
253       background = yellow;//activeBorder;
254       //opacity = 1.0f;
255
256       anchor.left = 0;
257       anchor.bottom = 0;
258       anchor.right = 0;
259    };
260
261    //FlipStacker flipStack { stack, spring = previous };
262
263    /*SearchPanel searchPanel
264    {
265       panels, this;
266    };*/
267
268    /*Tree*/FileSystemBox tree;
269    /*{
270       panels, this;
271       size = { w = 240 };
272       anchor.top = 0;
273       anchor.bottom = 0;
274       navigateFolders = true;
275       treeBranches = true;
276       foldersOnly = true;
277       borderStyle = none;
278       visible = false;
279    };*/
280
281    FileSystemBox view
282    {
283       panels, this;
284       anchor.top = 0;
285       anchor.bottom = 0;
286       anchor.right = 0;
287       locationBox = addressBar;
288       navigateFolders = true;
289       borderStyle = none;
290
291       bool NotifyNodeOpen(FileSystemBox box, FileSystemNode node)
292       {
293          if(node.type.isFile)
294          {
295             char command[MAX_LOCATION];
296             char * t = node.path;
297             sprintf(command, "ide %s", node.path);
298             ShellOpen(command);
299          }
300          return true;
301       }
302    };
303
304    /*ExplorerSearch search
305    {
306       deep, this;
307       visible = false;
308       tabCycle = true;
309       size = Size { 624, 268 };
310       anchor = Anchor { left = 0, top = 0, bottom = 0 };
311    };
312
313    ExplorerViewSearch results;*/
314
315    /*Window viewHolder
316    {
317       parent = deep, master = this;
318       tabCycle = true;
319       anchor = Anchor { top = 0, bottom = 0, right = 0 };
320    };
321
322    SplitWindow split
323    {
324       deep, this;
325       leftPane = tree, rightPane = viewHolder;
326       split = 300;
327    };*/
328
329    // Preview / Showcase
330    /*PreviewArea previewArea
331    {
332       panels, this;
333    };*/
334
335    //FlipStacker flipPanels { panels, spring = previous };
336
337    /*bool TreeNotifyBranchSelect(ExplorerTree tree, ExplorerFileBranch branch)
338    {
339       if(branch)
340       {
341          char path[MAX_LOCATION];
342          branch.GetPath(path);
343          toolBar.addressBar.contents = path;
344          view.Load(branch);
345       }
346       return true;
347    }*/
348    
349    /*bool ViewNotifyItemOpen(ExplorerView view, ExplorerFileItem item)
350    {
351       ExplorerFileBranch branch = tree.branch;
352       if(item && branch)
353       {
354          if(item.type.isFolderType)
355          {
356             ExplorerFileBranch child;
357             
358             if(!branch.loaded || !branch.childrenLoaded)
359                BranchLoad(branch, tree.tree);
360
361             for(child = branch.children.first; child; child = child.next)
362                if(!strcmp(child.name, item.name))
363                   break;
364             
365             if(child)
366             {
367                if(branch.row.collapsed)
368                   child.row.collapsed = true;
369                child.EnsureVisible(false);
370                tree.Select(child);
371             }
372          }
373          else
374          {
375             char path[MAX_LOCATION];
376             branch.GetPath(path);
377             PathCat(path, item.name);
378             ShellOpen(path);
379          }
380       }
381    }*/
382
383    /*void SwitchViews(ExplorerToolId viewId)
384    {
385       ExplorerFileBranch branch = tree.branch;
386       view.Destroy(0);
387       switch(viewId)
388       {
389          case viewList:     view = ExplorerViewList     { parent = viewHolder, master = this }; break;
390          case viewDetails:  view = ExplorerViewDetails  { parent = viewHolder, master = this }; break;
391          case viewIcons:    view = ExplorerViewIcons    { parent = viewHolder, master = this }; break;
392          case viewCards:    view = ExplorerViewCards    { parent = viewHolder, master = this }; break;
393          case viewShowcase: view = ExplorerViewShowcase { parent = viewHolder, master = this }; break;
394       }
395       view.tabCycle = true;
396       view.previewPictures = toolBar.previewPictures.checked;
397       view.anchor = Anchor { left = 0, top = 0, bottom = 0, right = 0 };
398       view.NotifyItemOpen = ViewNotifyItemOpen;
399       view.Create();
400       view.Load(branch);
401       lastViewId = viewId;
402    }*/
403
404    /*void GoToLocation(char * location)
405    {
406       int c;
407       char * temp;
408       char step[MAX_LOCATION];
409       
410       StringArray steps { growingFactor = 4 };
411       ExplorerFileBranch last = null;
412       
413       temp = CopyString(location);
414       while(strlen(temp))
415       {
416          GetLastDirectory(temp, step);
417          StripLastDirectory(temp, temp);
418          steps.Add(CopyString(step));
419       }
420       
421       for(c = steps._count - 1; c >= 0; c--)
422       {
423          last = tree.Find(steps._[c], last);
424          if(!last)
425             break;
426          tree.Select(last);
427       }
428       
429       delete temp;
430       delete steps;
431    }*/
432
433    /*void SearchLocation(char * location)
434    {
435       GoToLocation(location);
436       search.location.editBox.contents = location;
437    }*/
438
439    bool OnPostCreate()
440    {
441       //userMode = true;
442       addressBar.path = view.path;
443       return true;
444    }
445
446    /*ExplorerWindow()
447    {
448       userMode = false;
449
450       treeSplit = 300;
451       searchSplit = 200;
452
453       view = ExplorerViewList
454       {
455          parent = viewHolder, master = this;
456          tabCycle = true;
457          previewPictures = toolBar.previewPictures.checked;
458          anchor = Anchor { left = 0, top = 0, bottom = 0, right = 0 };
459          NotifyItemOpen = ViewNotifyItemOpen;
460       };
461       lastViewId = viewList;
462       
463       tree.Load();
464       view.Load(tree.root);
465    }*/
466
467    /*void InitTree()
468    {
469    }*/
470
471    /*void InitSearch()
472    {
473    }*/
474 }
475
476 //class TreeFileSystemBox : FileSystemBox { }