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