1 #ifdef BUILDING_ECERE_COM
2 namespace gui::controls;
7 public import static "ecere"
15 FileDialog browseFileDialog { type = selectDir, text = "Select directory" };
17 public class DirectoriesBox : CommonControl
25 virtual bool OnChangedDir(char ** directory)
29 virtual bool OnPrepareBrowseDir(char ** directory)
33 virtual bool OnBrowsedDir(char ** directory)
38 watch(foreground) { list.foreground = foreground; };
39 watch(background) { list.background = background; };
41 property Array<String> strings
50 char temp[MAX_LOCATION];
51 list.AddString(GetSystemPathBuffer(temp, s));
55 list.currentRow = list.firstRow;
56 list.modifiedDocument = false;
60 Array<String> array { };
62 for(row = list.firstRow; row; row = row.next)
64 String string = row.string;
65 if(string && string[0])
66 array.Add(CopyUnixPath(string));
72 virtual bool Window::NotifyModified(DirectoriesBox dirsBox);
74 // TOCHECK: Is this not working?! :S
75 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
77 // Browsing was not being set, fixed by introducing dependency to this class to PathBox
78 if(!active && !browsing)
80 list.StopEditing(true);
81 if(list.modifiedDocument)
83 NotifyModified(master, this);
84 list.modifiedDocument = false;
85 modifiedDocument = true;
93 parent = this, bevelOver = true, inactive = true;
94 position = { 265, 0 }, size = { 22, 22 };
95 anchor = { top = 0, right = 77 };
96 hotKey = plus, bitmap = BitmapResource { fileName = "<:ecere>actions/listAdd.png", alphaBlend = true };
97 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
99 list.StopEditing(true);
100 list.lastRow.Edit(null);
101 list.modifiedDocument = true;
107 parent = this, bevelOver = true, inactive = true;
108 position = { 290, 0 }, size = { 22, 22 };
109 anchor = { top = 0, right = 54 };
110 hotKey = del, bitmap = BitmapResource { fileName = "<:ecere>actions/listRemove.png", alphaBlend = true };
111 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
113 list.StopEditing(true);
114 if(list.currentRow != list.lastRow)
116 list.DeleteRow(null);
117 list.modifiedDocument = true;
124 parent = this, bevelOver = true, inactive = true;
125 position = { 315, 0 }, size = { 22, 22 };
126 anchor = { top = 0, right = 31 };
127 hotKey = ctrlUp, bitmap = BitmapResource { fileName = "<:ecere>actions/goUp.png", alphaBlend = true };
128 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
130 if(list.currentRow != list.lastRow)
132 DataRow current = list.currentRow, row;
135 row = current.previous;
140 list.modifiedDocument = true;
149 parent = this, bevelOver = true, inactive = true;
150 position = { 340, 0 }, size = { 22, 22 };
151 anchor = { top = 0, right = 8 };
152 hotKey = ctrlDown, bitmap = BitmapResource { fileName = "<:ecere>actions/goDown.png", alphaBlend = true };
153 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
155 DataRow current = list.currentRow, row;
159 if(row && row != list.lastRow)
162 list.modifiedDocument = true;
170 this, moveRows = true, hasVertScroll = true, dontHideScroll = true;
171 borderStyle = deep, position = { 0, 22 }, size = { 300, 60 };
172 anchor = { left = 0, top = 22, right = 0, bottom = 0 };
174 bool OnRightButtonDown(int x, int y, Modifiers mods)
176 return parent.OnRightButtonDown(x + position.x + parent.clientStart.x, y + position.y + parent.clientStart.y, mods);
179 bool NotifyChanged(ListBox listBox, DataRow row)
181 char * directory = listBox.GetData(null);
182 if(directory && directory[0])
184 char * dir = CopyString(directory);
185 if(OnChangedDir(&dir))
187 listBox.SetData(null, dir);
188 listBox.modifiedDocument = true;
189 if(listBox.currentRow == listBox.lastRow && listBox.lastRow.string)
191 DataRow r = listBox.lastRow;
193 listBox.currentRow = listBox.AddString("");
198 else if(listBox.currentRow != listBox.lastRow)
200 listBox.DeleteRow(null);
201 listBox.modifiedDocument = true;
206 bool NotifyEditDone(ListBox listBox, DataRow row)
208 //browseDir.Destroy(0);
213 bool NotifyEdited(ListBox listBox, DataRow row)
215 browseDir.anchor = Anchor { right = 0, top = listBox.currentIndex * listBox.rowHeight - 2 };
216 browseDir.size = { 30, listBox.rowHeight + 3 };
222 bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
226 listBox.StopEditing(true);
227 if(listBox.currentRow != listBox.lastRow)
228 listBox.DeleteRow(null);
234 bool NotifyMove(ListBox listBox, DataRow row, Modifiers mods)
236 if(listBox.currentRow == listBox.lastRow)
238 else if(row == listBox.lastRow)
240 if(listBox.currentRow == row.previous)
242 listBox.currentRow.Move(row.previous);
248 bool NotifyReclick(ListBox listBox, DataRow row, Modifiers mods)
254 DataField dirField { dataType = class(DirPath), editable = true, userData = browseFileDialog };
258 master = this, parent = list, autoCreate = false, inactive = true, hotKey = f2, text = "...";
260 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
265 list.StopEditing(true);
267 row = list.currentRow;
268 directory = CopyString(row.string ? row.string : "");
269 if(OnPrepareBrowseDir(&directory))
271 browseFileDialog.filePath = directory;
272 StripLastDirectory(directory, directory);
273 browseFileDialog.currentDirectory = directory;
274 //browseFileDialog.master = rootWindow;
276 if(browseFileDialog.Modal())
278 char * newDir = CopyString(browseFileDialog.filePath);
279 if(OnBrowsedDir(&newDir))
282 if(list.lastRow.string && list.lastRow.string[0])
285 list.currentRow = list.lastRow;
287 list.modifiedDocument = true;
300 list.AddField(dirField);
302 list.modifiedDocument = false;