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