5e41a21b7ef785273880e1a8d0432a681e1534e2
[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       bool NotifyNodeOpen(FileSystemBox box, FileSystemNode node)
287       {
288          if(node.type.isFile)
289          {
290             char command[MAX_LOCATION];
291             char * t = node.path;
292             sprintf(command, "ide %s", node.path);
293             ShellOpen(command);
294          }
295          return true;
296       }
297    };
298
299    /*ExplorerSearch search
300    {
301       deep, this;
302       visible = false;
303       tabCycle = true;
304       size = Size { 624, 268 };
305       anchor = Anchor { left = 0, top = 0, bottom = 0 };
306    };
307
308    ExplorerViewSearch results;*/
309
310    /*Window viewHolder
311    {
312       parent = deep, master = this;
313       tabCycle = true;
314       anchor = Anchor { top = 0, bottom = 0, right = 0 };
315    };
316
317    SplitWindow split
318    {
319       deep, this;
320       leftPane = tree, rightPane = viewHolder;
321       split = 300;
322    };*/
323
324    // Preview / Showcase
325    /*PreviewArea previewArea
326    {
327       panels, this;
328    };*/
329
330    //FlipStacker flipPanels { panels, spring = previous };
331
332    /*bool TreeNotifyBranchSelect(ExplorerTree tree, ExplorerFileBranch branch)
333    {
334       if(branch)
335       {
336          char path[MAX_LOCATION];
337          branch.GetPath(path);
338          toolBar.addressBar.contents = path;
339          view.Load(branch);
340       }
341       return true;
342    }*/
343    
344    /*bool ViewNotifyItemOpen(ExplorerView view, ExplorerFileItem item)
345    {
346       ExplorerFileBranch branch = tree.branch;
347       if(item && branch)
348       {
349          if(item.type.isFolderType)
350          {
351             ExplorerFileBranch child;
352             
353             if(!branch.loaded || !branch.childrenLoaded)
354                BranchLoad(branch, tree.tree);
355
356             for(child = branch.children.first; child; child = child.next)
357                if(!strcmp(child.name, item.name))
358                   break;
359             
360             if(child)
361             {
362                if(branch.row.collapsed)
363                   child.row.collapsed = true;
364                child.EnsureVisible(false);
365                tree.Select(child);
366             }
367          }
368          else
369          {
370             char path[MAX_LOCATION];
371             branch.GetPath(path);
372             PathCat(path, item.name);
373             ShellOpen(path);
374          }
375       }
376    }*/
377
378    /*void SwitchViews(ExplorerToolId viewId)
379    {
380       ExplorerFileBranch branch = tree.branch;
381       view.Destroy(0);
382       switch(viewId)
383       {
384          case viewList:     view = ExplorerViewList     { parent = viewHolder, master = this }; break;
385          case viewDetails:  view = ExplorerViewDetails  { parent = viewHolder, master = this }; break;
386          case viewIcons:    view = ExplorerViewIcons    { parent = viewHolder, master = this }; break;
387          case viewCards:    view = ExplorerViewCards    { parent = viewHolder, master = this }; break;
388          case viewShowcase: view = ExplorerViewShowcase { parent = viewHolder, master = this }; break;
389       }
390       view.tabCycle = true;
391       view.previewPictures = toolBar.previewPictures.checked;
392       view.anchor = Anchor { left = 0, top = 0, bottom = 0, right = 0 };
393       view.NotifyItemOpen = ViewNotifyItemOpen;
394       view.Create();
395       view.Load(branch);
396       lastViewId = viewId;
397    }*/
398
399    /*void GoToLocation(char * location)
400    {
401       int c;
402       char * temp;
403       char step[MAX_LOCATION];
404       
405       StringArray steps { growingFactor = 4 };
406       ExplorerFileBranch last = null;
407       
408       temp = CopyString(location);
409       while(strlen(temp))
410       {
411          GetLastDirectory(temp, step);
412          StripLastDirectory(temp, temp);
413          steps.Add(CopyString(step));
414       }
415       
416       for(c = steps._count - 1; c >= 0; c--)
417       {
418          last = tree.Find(steps._[c], last);
419          if(!last)
420             break;
421          tree.Select(last);
422       }
423       
424       delete temp;
425       delete steps;
426    }*/
427
428    /*void SearchLocation(char * location)
429    {
430       GoToLocation(location);
431       search.location.editBox.contents = location;
432    }*/
433
434    bool OnPostCreate()
435    {
436       //userMode = true;
437       addressBar.path = view.path;
438       return true;
439    }
440
441    /*ExplorerWindow()
442    {
443       userMode = false;
444
445       treeSplit = 300;
446       searchSplit = 200;
447
448       view = ExplorerViewList
449       {
450          parent = viewHolder, master = this;
451          tabCycle = true;
452          previewPictures = toolBar.previewPictures.checked;
453          anchor = Anchor { left = 0, top = 0, bottom = 0, right = 0 };
454          NotifyItemOpen = ViewNotifyItemOpen;
455       };
456       lastViewId = viewList;
457       
458       tree.Load();
459       view.Load(tree.root);
460    }*/
461
462    /*void InitTree()
463    {
464    }*/
465
466    /*void InitSearch()
467    {
468    }*/
469 }
470
471 //class TreeFileSystemBox : FileSystemBox { }