file dialog, continue

This commit is contained in:
Vadim Lopatin 2014-07-07 11:19:25 +04:00
parent 60b5f084d4
commit def5580108
2 changed files with 55 additions and 4 deletions

View File

@ -399,3 +399,17 @@ char[] appendPath(char[] buf, string[] pathItems ...) {
return convertPathDelimiters(buf);
}
/// split path into elements (e.g. /home/user/dir1 -> ["home", "user", "dir1"], "c:\dir1\dir2" -> ["c:", "dir1", "dir2"]
string[] splitPath(string path) {
string[] res;
int start = 0;
for (int i = 0; i <= path.length; i++) {
char ch = i < path.length ? path[i] : 0;
if (ch == '\\' || ch == '/' || ch == 0) {
if (start < i)
res ~= path[start .. i].dup;
start = i + 1;
}
}
return res;
}

View File

@ -30,6 +30,8 @@ import dlangui.widgets.controls;
import dlangui.widgets.lists;
import dlangui.widgets.popup;
import dlangui.widgets.layouts;
import dlangui.widgets.grid;
import dlangui.widgets.editors;
import dlangui.platforms.common.platform;
import dlangui.dialogs.dialog;
@ -46,17 +48,52 @@ enum FileDialogFlag : uint {
}
/// file open / save dialog
class FileDialog : Dialog {
this(UIString caption, Window parent, uint fileDialogFlags = DialogFlag.Modal | FileDialogFlag.FileMustExist) {
class FileDialog : Dialog {
EditLine path;
StringGridWidget list;
StringGridWidget places;
VerticalLayout leftPanel;
VerticalLayout rightPanel;
this(UIString caption, Window parent, uint fileDialogFlags = DialogFlag.Modal | FileDialogFlag.FileMustExist) {
super(caption, parent, fileDialogFlags);
}
/// override to implement creation of dialog controls
override void init() {
layoutWidth(FILL_PARENT);
layoutWidth(FILL_PARENT);
LinearLayout content = new LinearLayout("dlgcontent");
LinearLayout content = new HorizontalLayout("dlgcontent");
content.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT).minWidth(400).minHeight(300);
leftPanel = new VerticalLayout("places");
rightPanel = new VerticalLayout("main");
leftPanel.layoutHeight(FILL_PARENT).minWidth(40);
rightPanel.layoutHeight(FILL_PARENT).layoutWidth(FILL_PARENT);
rightPanel.addChild(new TextWidget(null, "Path:"d));
content.addChild(leftPanel);
content.addChild(rightPanel);
path = new EditLine("path");
path.layoutWidth(FILL_PARENT);
rightPanel.addChild(path);
list = new StringGridWidget("files");
list.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
list.resize(3, 3);
list.setColTitle(0, "Name"d);
list.setColTitle(1, "Size"d);
list.setColTitle(2, "Modified"d);
list.showRowHeaders = false;
list.rowSelect = true;
rightPanel.addChild(list);
places = new StringGridWidget("placesList");
places.resize(1, 10);
places.showRowHeaders(false).showColHeaders(true);
places.setColTitle(0, "Places"d);
leftPanel.addChild(places);
addChild(content);
addChild(createButtonsPanel([ACTION_OK, ACTION_CANCEL], 0, 1));
addChild(createButtonsPanel([ACTION_OPEN, ACTION_CANCEL], 0, 0));
string[] path = splitPath("/home/lve/src");
Log.d("path: ", path);
}
}