libede:FileSystemBox: complete migration of previewPictures support code from old...
[ede] / newexplorer / 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    refreshView,
13    viewList, viewDetails, viewIcons, viewCards, viewShowcase, viewCustom,
14    previewPictures
15 };
16
17 class ExplorerWindow : Window
18 {
19    text = "Ecere Explorer";
20    background = activeBorder;
21    borderStyle = sizable;
22    hasMaximize = true;
23    hasMinimize = true;
24    hasClose = true;
25    size = { 840, 480 };
26    nativeDecorations = true;
27
28    IconBag<ExplorerToolId> iconBag
29    {
30       //window = guiApp.desktop;
31       window = this;
32       alphaBlend = true;
33       iconNames =
34       [
35          "<:ecere>emblems/unreadable.png",     /* none */
36
37          "<:ecere>actions/windowNew.png",            /* newWindow */
38          "<:ecere>actions/goPrevious.png",           /* goBack */
39          "<:ecere>actions/goNext.png",               /* goForward */
40          "<:ecere>actions/goUp.png",                 /* goUp */
41          "<:ecere>actions/goHome.png",               /* goHome */
42
43          ":browse.png",                                           /* browse */
44
45          ":panel-tree.png",                                       /* panelTree */
46          "<:ecere>actions/editFind.png",             /* panelSearch */
47
48          "<:ecere>emblems/unreadable.png",     /* addressBar */
49
50          "<:ecere>actions/viewRefresh.png",          /* refreshView */
51
52          ":view-list.png",                                        /* viewList */
53          ":view-details.png",                                     /* viewDetails */
54          ":view-icons.png",                                       /* viewIcons */
55          ":view-cards.png",                                       /* viewCards */
56          ":view-showcase-right.png",                              /* viewShowcase */
57          ":view-custom.png",                                      /* viewCustom */
58          
59          "<:ecere>mimeTypes/image.png"     /* previewPictures */
60       ];
61    };
62
63    Stacker stack
64    {
65       this;
66       gap = 0;
67       direction = vertical;
68       background = activeBorder;
69       //opacity = 1.0f;
70       
71       anchor = { left = 0, top = 0, right = 0, bottom = 0 };
72       //moveable = false;
73    };
74
75    ToolBar<ExplorerToolId> toolBar
76    {
77       stack, this;
78       iconBag = iconBag;
79       size = { h = 32 };
80       //moveable = false;
81    };
82
83    Window s1 { toolBar, size = { w = 8 } };
84    ToolButton goBack    { toolBar, this, id = ExplorerToolId::goBack };
85    Window s2 { toolBar, size = { w = 2 } };
86    ToolButton goForward { toolBar, this, id = ExplorerToolId::goForward };
87    Window s3 { toolBar, size = { w = 2 } };
88    ToolButton refreshView
89    {
90       toolBar, this, id = ExplorerToolId::refreshView;
91
92       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
93       {
94          fsb.Refresh();
95          return true;
96       }
97    };
98    Window s4 { toolBar, size = { w = 2 } };
99    ToolButton goHome    { toolBar, this, id = ExplorerToolId::goHome };
100    Window s5 { toolBar, size = { w = 8 } };
101    PathBox addressBar
102    {
103       toolBar, this;
104       size = { 300, 23 }, id = ExplorerToolId::addressBar;
105       typeExpected = directory;
106
107       bool OnKeyDown(Key key, unichar ch)
108       {
109          if((SmartKey)key == enter)
110          {
111             // how to make enter effect a modification
112             // how to implement in PathBox
113          }
114          return true;
115       }
116
117       bool NotifyModified(PathBox pathBox)
118       {
119          fsb.path = pathBox.path;
120          return true;
121       }
122    };
123    Window s6 { toolBar, size = { w = 8 } };
124    ToolButton goUp
125    {
126       toolBar, this, id = ExplorerToolId::goUp;
127
128       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
129       {
130          char * path = fsb.path;
131          char * newPath = new char[strlen(path)];
132          StripLastDirectory(path, newPath);
133          fsb.path = newPath;
134          delete newPath;
135          return true;
136       }
137    };
138    Window s7 { toolBar, size = { w = 8 } };
139    GroupToggleToolButton selectedPanel;
140    GroupToggleToolButton panelTree   { toolBar, this, id = ExplorerToolId::panelTree, selected = &selectedPanel, checked = true };
141    GroupToggleToolButton panelSearch { toolBar, this, id = ExplorerToolId::panelSearch, selected = &selectedPanel };
142    selectedPanel = panelTree;
143    Window s8 { toolBar, size = { w = 8 } };
144    OptionToolButton selectedView;
145    OptionToolButton viewList     { toolBar, this, id = ExplorerToolId::viewList, selected = &selectedView, checked = true };
146    OptionToolButton viewDetails  { toolBar, this, id = ExplorerToolId::viewDetails, selected = &selectedView };
147    OptionToolButton viewIcons    { toolBar, this, id = ExplorerToolId::viewIcons, selected = &selectedView };
148    OptionToolButton viewTiles    { toolBar, this, id = ExplorerToolId::viewCards, selected = &selectedView };
149    OptionToolButton viewShowcase { toolBar, this, id = ExplorerToolId::viewShowcase, selected = &selectedView };
150    selectedView = viewList;
151    Window s9 { toolBar, size = { w = 8 } };
152    ToggleToolButton previewPictures
153    {
154       toolBar, this, id = ExplorerToolId::previewPictures;
155
156       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
157       {
158          fsb.previewPictures = button.checked;
159          return true;
160       }
161    };
162
163    Window s10 { toolBar, size = { w = 8 } };
164    ToolButton newWindow
165    {
166       toolBar, this, id = ExplorerToolId::newWindow;
167
168       bool NotifyClicked(Button button, int x, int y, Modifiers mods)
169       {
170          ExplorerWindow { }.Create();
171          return true;
172       }
173    };
174
175    /*void OnDestroy()
176    {
177       iconBag.window = null;
178       delete iconBag;
179    }*/
180
181    bool OnLoadGraphics()
182    {
183       iconBag.Load();
184       return true;
185    }
186
187    void OnUnloadGraphics()
188    {
189       iconBag.Unload();
190    }
191
192    FileSystemBox fsb
193    {
194       stack, this;
195       //anchor = { left = 0, top = 4, right = 0, bottom = 0 };
196       anchor.left = 0;
197       anchor.bottom = 0;
198       anchor.right = 0;
199       locationBox = addressBar;
200       navigateFolders = true;
201    };
202
203    bool OnPostCreate()
204    {
205       addressBar.path = fsb.path;
206       return true;
207    }
208 }