explorer: fixed opening nodes that specify a path
[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                   GoToLocation(home, false, false);
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                GoToLocation(newPath, false, false);
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          GoToLocation(pathBox.path, false, false);
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       autoLoad = false;
324
325       bool NotifyNodeSelect(FileSystemBox box, FileSystemNode node)
326       {
327          char p[MAX_LOCATION];
328          node.GetPath(p);
329          GoToLocation(node.path, false, true);
330          return true;
331       }
332    };
333
334    PaneSplitter split
335    {
336       hack, this;
337       visible = false;
338       leftPane = tree;//, rightPane = view;
339       split = 300;
340    };
341
342    FileSystemBox view
343    {
344       hack, this;
345       borderStyle = none;
346       /*anchor.top = 0;
347       anchor.bottom = 0;
348       anchor.right = 0;*/
349       anchor = { left = 0, top = 0, bottom = 0, right = 0 };
350
351       locationBox = addressBar;
352       navigateFolders = true;
353       multiSelect = true;
354       autoLoad = false;
355
356       bool NotifyNodeOpen(FileSystemBox box, FileSystemNode node)
357       {
358          if(node.type.isFile)
359          {
360             char path[MAX_LOCATION];
361          #ifndef __WIN32__
362             char command[MAX_LOCATION];
363             node.GetPath(path);
364             /*_FileType t = node.type;
365             if(t == ewsFile || t == epjFile ||
366                   t == ecFile || t == ehFile ||
367                   t == cppFile || t == hppFile ||
368                   t == cFile || t == hFile ||
369                   t == textFile || t == webFile)*/
370                sprintf(command, "ide %s", path);
371             /*else
372                sprintf(command, "%s", path);*/
373             Execute(command);
374          #else
375             node.GetPath(path);
376             ShellOpen(path);
377          #endif
378          }
379          else if(node.type.isFolder && tree.visible)
380             tree.SelectLocation(node.path);
381          return true;
382       }
383    };
384
385    /*ExplorerSearch search
386    {
387       deep, this;
388       visible = false;
389       tabCycle = true;
390       size = Size { 624, 268 };
391       anchor = Anchor { left = 0, top = 0, bottom = 0 };
392    };
393
394    ExplorerViewSearch results;*/
395
396    /*Window viewHolder
397    {
398       parent = deep, master = this;
399       tabCycle = true;
400       anchor = Anchor { top = 0, bottom = 0, right = 0 };
401    };*/
402
403    // Preview / Showcase
404    /*PreviewArea previewArea
405    {
406       panels, this;
407    };*/
408
409    //FlipStacker flipPanels { panels, spring = previous };
410
411    /*bool TreeNotifyBranchSelect(ExplorerTree tree, ExplorerFileBranch branch)
412    {
413       if(branch)
414       {
415          char path[MAX_LOCATION];
416          branch.GetPath(path);
417          toolBar.addressBar.contents = path;
418          view.Load(branch);
419       }
420       return true;
421    }*/
422    
423    /*bool ViewNotifyItemOpen(ExplorerView view, ExplorerFileItem item)
424    {
425       ExplorerFileBranch branch = tree.branch;
426       if(item && branch)
427       {
428          if(item.type.isFolderType)
429          {
430             ExplorerFileBranch child;
431             
432             if(!branch.loaded || !branch.childrenLoaded)
433                BranchLoad(branch, tree.tree);
434
435             for(child = branch.children.first; child; child = child.next)
436                if(!strcmp(child.name, item.name))
437                   break;
438             
439             if(child)
440             {
441                if(branch.row.collapsed)
442                   child.row.collapsed = true;
443                child.EnsureVisible(false);
444                tree.Select(child);
445             }
446          }
447          else
448          {
449             char path[MAX_LOCATION];
450             branch.GetPath(path);
451             PathCat(path, item.name);
452             ShellOpen(path);
453          }
454       }
455    }*/
456
457    /*void SwitchViews(ExplorerToolId viewId)
458    {
459       ExplorerFileBranch branch = tree.branch;
460       view.Destroy(0);
461       switch(viewId)
462       {
463          case viewList:     view = ExplorerViewList     { parent = viewHolder, master = this }; break;
464          case viewDetails:  view = ExplorerViewDetails  { parent = viewHolder, master = this }; break;
465          case viewIcons:    view = ExplorerViewIcons    { parent = viewHolder, master = this }; break;
466          case viewCards:    view = ExplorerViewCards    { parent = viewHolder, master = this }; break;
467          case viewShowcase: view = ExplorerViewShowcase { parent = viewHolder, master = this }; break;
468       }
469       view.tabCycle = true;
470       view.previewPictures = toolBar.previewPictures.checked;
471       view.anchor = Anchor { left = 0, top = 0, bottom = 0, right = 0 };
472       view.NotifyItemOpen = ViewNotifyItemOpen;
473       view.Create();
474       view.Load(branch);
475       lastViewId = viewId;
476    }*/
477
478    void GoToLocation(char * location, bool viewIsAtLocation, bool treeIsAtLocation)
479    {
480       if(!viewIsAtLocation)
481          view.path = location;
482       if(tree.visible && !treeIsAtLocation)
483          tree.SelectLocation(location);
484    }
485
486    /*void SearchLocation(char * location)
487    {
488       GoToLocation(location);
489       search.location.editBox.contents = location;
490    }*/
491
492    bool OnPostCreate()
493    {
494       //userMode = true;
495       addressBar.path = view.path;
496       tree.path = "/"; // this should be available as a parameter
497       return true;
498    }
499
500    /*ExplorerWindow()
501    {
502       userMode = false;
503
504       treeSplit = 300;
505       searchSplit = 200;
506
507       view = ExplorerViewList
508       {
509          parent = viewHolder, master = this;
510          tabCycle = true;
511          previewPictures = toolBar.previewPictures.checked;
512          anchor = Anchor { left = 0, top = 0, bottom = 0, right = 0 };
513          NotifyItemOpen = ViewNotifyItemOpen;
514       };
515       lastViewId = viewList;
516       
517       tree.Load();
518       view.Load(tree.root);
519    }*/
520
521    /*void InitTree()
522    {
523    }*/
524
525    /*void InitSearch()
526    {
527    }*/
528 }
529
530 //class TreeFileSystemBox : FileSystemBox { }