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