1 namespace gui::controls;
5 default extern int __ecereVMethodID_class_OnGetDataFromString;
6 default static void _workAround()
9 a.OnGetDataFromString(0);
12 public class FilePath : String
14 Window OnEdit(DataBox dataBox, DataBox obsolete, int x, int y, int w, int h, void * userData)
18 dataBox, borderStyle = 0, anchor = { 0, 0, 0, 0 },
20 browseDialog = userData ? (FileDialog)userData : { type = open, text = $"Select a file..." };
27 bool OnSaveEdit(PathBox pathBox, void * object)
30 if(pathBox.modifiedDocument)
33 changed = _class._vTbl[__ecereVMethodID_class_OnGetDataFromString](_class, &this, pathBox.systemPath);
38 int OnCompare(DirPath b)
40 return fstrcmp(this, b);
44 public class DirPath : FilePath
46 Window OnEdit(DataBox dataBox, DataBox obsolete, int x, int y, int w, int h, void * userData)
50 dataBox, borderStyle = 0, anchor = { 0, 0, 0, 0 },
51 typeExpected = directory;
52 browseDialog = userData ? (FileDialog)userData : { type = selectDir, text = $"Select a folder..." };
60 public enum PathTypeExpected { none, any, directory, file };
62 public class PathBox : CommonControl
65 clientSize = { 64, 18 };
67 watch(background) { editBox.background = background; };
68 watch(foreground) { editBox.foreground = foreground; };
69 watch(opacity) { editBox.opacity = opacity; };
71 #if defined(__WIN32__)
78 PathTypeExpected typeExpected;
79 FileDialog browseDialog;
80 #if defined(__WIN32__)
81 char path[MAX_LOCATION];
84 BitmapResource file { "<:ecere>mimeTypes/file.png", transparent = true, alphaBlend = true };
85 BitmapResource brokenFile { "<:ecere>mimeTypes/brokenFile.png", transparent = true, alphaBlend = true };
86 BitmapResource folder { "<:ecere>places/folder.png", transparent = true, alphaBlend = true };
87 BitmapResource brokenFolder { "<:ecere>places/brokenFolder.png", transparent = true, alphaBlend = true };
91 this/*, size = { 318, 94 }*/, anchor = { left = 1, vert = 0 };
98 public property EditBox editBox { get { return editBox; } }
101 this/*, size = { 290, 22 }*/, position = { 1, 1 }, anchor = { left = 1, top = 1, right = 1 };
104 void NotifyUpdate(EditBox editBox)
107 modifiedDocument = true;
109 bool NotifyModified(EditBox editBox)
111 return NotifyModified(master, this);
114 /* F4? F4 is properties, f2 works already for this
115 bool OnKeyDown(Key key, unichar ch)
118 ((PathBox)parent).browse.NotifyClicked(parent, ((PathBox)parent).browse, 0, 0, (Modifiers)null);
119 return EditBox::OnKeyDown(key, ch);
124 // For chaining popup-key event
125 bool OnKeyHit(Key key, unichar ch)
127 return editBox.OnKeyHit(key, ch);
132 this, size = { w = 26 }, anchor = { top = 0, right = 0, bottom = 0 };
138 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
142 /* We need a reinterpret cast :) Easy eC compiler introduction contribution! :)
143 DataBox dataBox = reinterpret(master);
144 ListBox lb = dataBox ? reinterpret(dataBox.parent) : null;
145 DirectoriesBox dirBox = lb ? reinterpret(lb.parent) : null;
147 DataBox dataBox = eClass_IsDerived(master._class, class(DataBox)) ? (DataBox)master : null;
148 ListBox lb = ((dataBox && eClass_IsDerived(dataBox.parent._class, class(ListBox))) ? (ListBox)dataBox.parent : null;
149 DirectoriesBox dirBox = ((lb && eClass_IsDerived(lb.parent._class, class(DirectoriesBox))) ? (DirectoriesBox)lb.parent : null;
150 char * browsePath = CopyString(editBox.contents);
151 char fileName[MAX_LOCATION];
155 GetLastDirectory(browsePath, fileName);
156 StripLastDirectory(browsePath, browsePath);
160 char filePath[MAX_LOCATION];
162 LocateModule(null, filePath);
163 StripLastDirectory(filePath, filePath);
164 browsePath = CopyString(filePath);
167 while(browsePath[0] && !FileExists(browsePath).isDirectory)
169 char temp[MAX_LOCATION];
170 GetLastDirectory(browsePath, temp);
171 PathCat(temp, fileName);
172 strcpy(fileName, temp);
173 StripLastDirectory(browsePath, browsePath);
175 browseDialog.filePath = fileName;
176 browseDialog.currentDirectory = browsePath;
178 browseDialog.master = rootWindow;
180 // THIS PART WAS MISSING IN THE PathBox/DirectoriesBox INTEGRATION AND WAS CRUCIAL
181 if(dirBox) dirBox.browsing = true;
182 if(browseDialog.Modal())
184 PathBox pathBox = dataBox ? (PathBox)dataBox.editor : this;
185 pathBox.modifiedDocument = true;
186 pathBox.property::path = browseDialog.filePath;
190 pathBox.editBox.SelectAll();
191 if(lb) lb.StopEditing(true);
192 pathBox.NotifyModified(pathBox.master, this);
194 if(dirBox) dirBox.browsing = false;
202 void CheckFileExists()
204 if(typeExpected != none)
206 BitmapResource icon = null;
207 FileAttribs exists = FileExists(editBox.contents);
212 // TODO: improvements, add drive, etc, also find a better solution/icon for expect any and file doesn't exist
213 icon = exists ? exists.isFile ? file : exists.isDirectory ? folder : null : null;
216 icon = exists && exists.isDirectory ? folder : brokenFolder;
219 icon = exists && exists.isFile ? file : brokenFile;
223 picture.image = icon;
227 void OnRedraw(Surface surface)
231 surface.SetBackground(formColor);
232 surface.Area(0, 0, clientSize.w, clientSize.h);
235 Window::OnRedraw(surface);
244 property PathTypeExpected typeExpected
248 if(value != typeExpected)
250 if(value == none || typeExpected == none)
252 bool withIcon = value != none;
253 picture.visible = withIcon;
254 editBox.anchor.left = withIcon ? 18 : 1;
257 typeExpected = value;
258 if(browseDialog && browseDialog.type == open && typeExpected == directory)
259 browseDialog.type = selectDir;
264 property FileDialog browseDialog
269 browseDialog = value;
273 if(browseDialog.type == open && typeExpected == directory)
274 browseDialog.type = selectDir;
275 if(!strcmp(browseDialog.text, "Select a file...") && text)
277 char temp[1024] = "Select ";
280 browseDialog.text = temp;
283 browse.visible = browseDialog ? true : false;
284 editBox.anchor.right = browseDialog ? 26 : 1;
288 void Home() { editBox.Home(); }
289 void End() { editBox.End(); }
291 void SelectAll() { editBox.SelectAll(); }
292 void Deselect() { editBox.Deselect(); }
298 char path[MAX_LOCATION];
299 GetSystemPathBuffer(path, value);
300 editBox.contents = path;
305 get { return editBox.contents; }
307 property String slashPath { get { return GetSlashPathBuffer (path, editBox.contents); } };
308 property String systemPath { get { return GetSystemPathBuffer(path, editBox.contents); } };
310 property Color selectionColor { set { editBox.selectionColor = value; } get { return editBox.selectionColor; }/* isset { return selectionColor ? true : false; }*/ };
311 property Color selectionText { set { editBox.selectionText = value; } get { return editBox.selectionText; }/* isset { return selectionText ? true : false; }*/ };
313 virtual bool Window::NotifyModified(PathBox pathBox);
317 FileDialog browseFileDialog { type = selectDir, text = $"Select directory" };
319 public class DirectoriesBox : CommonControl
327 virtual bool OnChangedDir(char ** directory);
328 virtual bool OnPrepareBrowseDir(char ** directory);
329 virtual bool OnBrowsedDir(char ** directory);
331 watch(foreground) { list.foreground = foreground; };
332 watch(background) { list.background = background; };
334 property Array<String> strings
343 char temp[MAX_LOCATION];
344 list.AddString(GetSystemPathBuffer(temp, s));
348 list.currentRow = list.firstRow;
349 list.modifiedDocument = false;
353 Array<String> array { };
355 for(row = list.firstRow; row; row = row.next)
357 String string = row.string;
358 if(string && string[0])
359 array.Add(CopyUnixPath(string));
365 virtual bool Window::NotifyModified(DirectoriesBox dirsBox);
367 bool OnActivate(bool active, Window previous, bool * goOnWithActivation, bool direct)
369 // Browsing was not being set, fixed by introducing dependency to this class to PathBox
370 if(!active && !browsing)
372 list.StopEditing(true);
373 if(list.modifiedDocument)
375 NotifyModified(master, this);
376 list.modifiedDocument = false;
377 modifiedDocument = true;
385 parent = this, bevelOver = true, inactive = true;
386 position = { 265, 0 }, size = { 22, 22 };
387 anchor = { top = 0, right = 77 };
388 hotKey = plus, bitmap = BitmapResource { fileName = "<:ecere>actions/listAdd.png", alphaBlend = true };
389 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
391 list.StopEditing(true);
392 list.lastRow.Edit(null);
393 list.modifiedDocument = true;
399 parent = this, bevelOver = true, inactive = true;
400 position = { 290, 0 }, size = { 22, 22 };
401 anchor = { top = 0, right = 54 };
402 hotKey = del, bitmap = BitmapResource { fileName = "<:ecere>actions/listRemove.png", alphaBlend = true };
403 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
405 list.StopEditing(true);
406 if(list.currentRow != list.lastRow)
408 list.DeleteRow(null);
409 list.modifiedDocument = true;
416 parent = this, bevelOver = true, inactive = true;
417 position = { 315, 0 }, size = { 22, 22 };
418 anchor = { top = 0, right = 31 };
419 hotKey = ctrlUp, bitmap = BitmapResource { fileName = "<:ecere>actions/goUp.png", alphaBlend = true };
420 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
422 if(list.currentRow != list.lastRow)
424 DataRow current = list.currentRow, row;
427 row = current.previous;
432 list.modifiedDocument = true;
441 parent = this, bevelOver = true, inactive = true;
442 position = { 340, 0 }, size = { 22, 22 };
443 anchor = { top = 0, right = 8 };
444 hotKey = ctrlDown, bitmap = BitmapResource { fileName = "<:ecere>actions/goDown.png", alphaBlend = true };
445 bool NotifyClicked(Button button, int x, int y, Modifiers mods)
447 DataRow current = list.currentRow, row;
451 if(row && row != list.lastRow)
454 list.modifiedDocument = true;
462 this, moveRows = true, hasVertScroll = true, dontHideScroll = true;
463 borderStyle = deep, position = { 0, 22 }, size = { 300, 60 };
464 anchor = { left = 0, top = 22, right = 0, bottom = 0 };
466 bool OnRightButtonDown(int x, int y, Modifiers mods)
468 return parent.OnRightButtonDown(x + position.x + parent.clientStart.x, y + position.y + parent.clientStart.y, mods);
471 bool NotifyChanged(ListBox listBox, DataRow row)
473 char * directory = listBox.GetData(null);
474 if(directory && directory[0])
476 char * dir = CopyString(directory);
477 if(OnChangedDir(&dir))
479 // Put this back to enable making Paths relative by overriding
480 // these DirectoriesBox virtual methods (from FileDialog only)
483 OnPrepareBrowseDir(&dir);
486 listBox.SetData(null, dir);
487 listBox.modifiedDocument = true;
488 if(listBox.currentRow == listBox.lastRow && listBox.lastRow.string)
490 DataRow r = listBox.lastRow;
492 listBox.currentRow = listBox.AddString("");
497 else if(listBox.currentRow != listBox.lastRow)
499 listBox.DeleteRow(null);
500 listBox.modifiedDocument = true;
505 bool NotifyEditDone(ListBox listBox, DataRow row)
510 bool NotifyKeyDown(ListBox listBox, DataRow row, Key key, unichar ch)
514 listBox.StopEditing(true);
515 if(listBox.currentRow != listBox.lastRow)
516 listBox.DeleteRow(null);
522 bool NotifyMove(ListBox listBox, DataRow row, Modifiers mods)
524 if(listBox.currentRow == listBox.lastRow)
526 else if(row == listBox.lastRow)
528 if(listBox.currentRow == row.previous)
530 listBox.currentRow.Move(row.previous);
536 bool NotifyReclick(ListBox listBox, DataRow row, Modifiers mods)
542 DataField dirField { dataType = class(DirPath), editable = true, userData = browseFileDialog };
546 list.AddField(dirField);
548 list.modifiedDocument = false;