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