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