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