mirror of https://github.com/buggins/dlangui.git
file dialog enhancements
This commit is contained in:
parent
0a50a27974
commit
7e98f9a717
|
@ -164,11 +164,14 @@ bool filterFilename(string filename, string[] filters) {
|
||||||
|
|
||||||
Returns true if directory exists and listed successfully, false otherwise.
|
Returns true if directory exists and listed successfully, false otherwise.
|
||||||
*/
|
*/
|
||||||
bool listDirectory(string dir, bool includeDirs, bool includeFiles, string[] filters, ref DirEntry[] entries) {
|
bool listDirectory(string dir, bool includeDirs, bool includeFiles, bool showHiddenFiles, string[] filters, ref DirEntry[] entries) {
|
||||||
|
|
||||||
entries.length = 0;
|
entries.length = 0;
|
||||||
|
|
||||||
if (!isDir(dir)) {
|
if (!isDir(dir)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isRoot(dir) && includeDirs) {
|
if (!isRoot(dir) && includeDirs) {
|
||||||
entries ~= DirEntry(appendPath(dir, ".."));
|
entries ~= DirEntry(appendPath(dir, ".."));
|
||||||
}
|
}
|
||||||
|
@ -177,6 +180,9 @@ bool listDirectory(string dir, bool includeDirs, bool includeFiles, string[] fil
|
||||||
DirEntry[] dirs;
|
DirEntry[] dirs;
|
||||||
DirEntry[] files;
|
DirEntry[] files;
|
||||||
foreach (DirEntry e; dirEntries(dir, SpanMode.shallow)) {
|
foreach (DirEntry e; dirEntries(dir, SpanMode.shallow)) {
|
||||||
|
string fn = baseName(e.name);
|
||||||
|
if (!showHiddenFiles && fn.startsWith("."))
|
||||||
|
continue;
|
||||||
if (e.isDir) {
|
if (e.isDir) {
|
||||||
dirs ~= e;
|
dirs ~= e;
|
||||||
} else if (e.isFile) {
|
} else if (e.isFile) {
|
||||||
|
|
|
@ -56,9 +56,9 @@ enum FileDialogFlag : uint {
|
||||||
|
|
||||||
/// File open / save dialog
|
/// File open / save dialog
|
||||||
class FileDialog : Dialog, CustomGridCellAdapter {
|
class FileDialog : Dialog, CustomGridCellAdapter {
|
||||||
protected EditLine path;
|
protected EditLine _edPath;
|
||||||
protected EditLine filename;
|
protected EditLine _edFilename;
|
||||||
protected StringGridWidget list;
|
protected StringGridWidget _fileList;
|
||||||
//protected StringGridWidget places;
|
//protected StringGridWidget places;
|
||||||
protected VerticalLayout leftPanel;
|
protected VerticalLayout leftPanel;
|
||||||
protected VerticalLayout rightPanel;
|
protected VerticalLayout rightPanel;
|
||||||
|
@ -73,34 +73,42 @@ class FileDialog : Dialog, CustomGridCellAdapter {
|
||||||
super(caption, parent, fileDialogFlags);
|
super(caption, parent, fileDialogFlags);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Set widget rectangle to specified value and layout widget contents. (Step 2 of two phase layout).
|
||||||
|
override void layout(Rect rc) {
|
||||||
|
super.layout(rc);
|
||||||
|
_fileList.autoFitColumnWidths();
|
||||||
|
_fileList.fillColumnWidth(1);
|
||||||
|
}
|
||||||
|
|
||||||
protected bool openDirectory(string dir) {
|
protected bool openDirectory(string dir) {
|
||||||
dir = buildNormalizedPath(dir);
|
dir = buildNormalizedPath(dir);
|
||||||
Log.d("FileDialog.openDirectory(", dir, ")");
|
Log.d("FileDialog.openDirectory(", dir, ")");
|
||||||
list.rows = 0;
|
_fileList.rows = 0;
|
||||||
string[] filters;
|
string[] filters;
|
||||||
if (!listDirectory(dir, true, true, filters, _entries))
|
if (!listDirectory(dir, true, true, false, filters, _entries))
|
||||||
return false;
|
return false;
|
||||||
_path = dir;
|
_path = dir;
|
||||||
_isRoot = isRoot(dir);
|
_isRoot = isRoot(dir);
|
||||||
path.text = toUTF32(_path);
|
_edPath.text = toUTF32(_path);
|
||||||
list.rows = cast(int)_entries.length;
|
_fileList.rows = cast(int)_entries.length;
|
||||||
for (int i = 0; i < _entries.length; i++) {
|
for (int i = 0; i < _entries.length; i++) {
|
||||||
string fname = baseName(_entries[i].name);
|
string fname = baseName(_entries[i].name);
|
||||||
string sz;
|
string sz;
|
||||||
string date;
|
string date;
|
||||||
bool d = _entries[i].isDir;
|
bool d = _entries[i].isDir;
|
||||||
list.setCellText(1, i, toUTF32(fname));
|
_fileList.setCellText(1, i, toUTF32(fname));
|
||||||
if (d) {
|
if (d) {
|
||||||
list.setCellText(0, i, "folder");
|
_fileList.setCellText(0, i, "folder");
|
||||||
} else {
|
} else {
|
||||||
list.setCellText(0, i, "text-plain"d);
|
_fileList.setCellText(0, i, "text-plain"d);
|
||||||
sz = to!string(_entries[i].size);
|
sz = to!string(_entries[i].size);
|
||||||
date = "2014-01-01 00:00:00";
|
date = "2014-01-01 00:00:00";
|
||||||
}
|
}
|
||||||
list.setCellText(2, i, toUTF32(sz));
|
_fileList.setCellText(2, i, toUTF32(sz));
|
||||||
list.setCellText(3, i, toUTF32(date));
|
_fileList.setCellText(3, i, toUTF32(date));
|
||||||
}
|
}
|
||||||
list.autoFitColumnWidths();
|
_fileList.autoFitColumnWidths();
|
||||||
|
_fileList.fillColumnWidth(1);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -112,7 +120,7 @@ class FileDialog : Dialog, CustomGridCellAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected DrawableRef rowIcon(int row) {
|
protected DrawableRef rowIcon(int row) {
|
||||||
string iconId = toUTF8(list.cellText(0, row));
|
string iconId = toUTF8(_fileList.cellText(0, row));
|
||||||
DrawableRef res;
|
DrawableRef res;
|
||||||
if (iconId.length)
|
if (iconId.length)
|
||||||
res = drawableCache.get(iconId);
|
res = drawableCache.get(iconId);
|
||||||
|
@ -141,7 +149,7 @@ class FileDialog : Dialog, CustomGridCellAdapter {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Widget createRootsList() {
|
protected Widget createRootsList() {
|
||||||
ListWidget list = new ListWidget("ROOTS_LIST");
|
ListWidget res = new ListWidget("ROOTS_LIST");
|
||||||
WidgetListAdapter adapter = new WidgetListAdapter();
|
WidgetListAdapter adapter = new WidgetListAdapter();
|
||||||
foreach(ref RootEntry root; _roots) {
|
foreach(ref RootEntry root; _roots) {
|
||||||
ImageTextButton btn = new ImageTextButton(null, root.icon, root.label);
|
ImageTextButton btn = new ImageTextButton(null, root.icon, root.label);
|
||||||
|
@ -150,14 +158,14 @@ class FileDialog : Dialog, CustomGridCellAdapter {
|
||||||
btn.focusable = false;
|
btn.focusable = false;
|
||||||
adapter.widgets.add(btn);
|
adapter.widgets.add(btn);
|
||||||
}
|
}
|
||||||
list.ownAdapter = adapter;
|
res.ownAdapter = adapter;
|
||||||
list.layoutWidth = WRAP_CONTENT;
|
res.layoutWidth = WRAP_CONTENT;
|
||||||
list.layoutHeight = FILL_PARENT;
|
res.layoutHeight = FILL_PARENT;
|
||||||
list.onItemClickListener = delegate(Widget source, int itemIndex) {
|
res.onItemClickListener = delegate(Widget source, int itemIndex) {
|
||||||
openDirectory(_roots[itemIndex].path);
|
openDirectory(_roots[itemIndex].path);
|
||||||
return true;
|
return true;
|
||||||
};
|
};
|
||||||
return list;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void onItemActivated(int index) {
|
protected void onItemActivated(int index) {
|
||||||
|
@ -172,58 +180,58 @@ class FileDialog : Dialog, CustomGridCellAdapter {
|
||||||
/// override to implement creation of dialog controls
|
/// override to implement creation of dialog controls
|
||||||
override void init() {
|
override void init() {
|
||||||
_roots = getRootPaths;
|
_roots = getRootPaths;
|
||||||
|
|
||||||
layoutWidth(FILL_PARENT);
|
layoutWidth(FILL_PARENT);
|
||||||
layoutWidth(FILL_PARENT);
|
layoutWidth(FILL_PARENT);
|
||||||
|
minWidth = 600;
|
||||||
|
minHeight = 400;
|
||||||
|
|
||||||
LinearLayout content = new HorizontalLayout("dlgcontent");
|
LinearLayout content = new HorizontalLayout("dlgcontent");
|
||||||
|
|
||||||
content.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT).minWidth(400).minHeight(300);
|
content.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT).minWidth(400).minHeight(300);
|
||||||
|
|
||||||
leftPanel = new VerticalLayout("places");
|
leftPanel = new VerticalLayout("places");
|
||||||
leftPanel.addChild(createRootsList());
|
leftPanel.addChild(createRootsList());
|
||||||
rightPanel = new VerticalLayout("main");
|
|
||||||
leftPanel.layoutHeight(FILL_PARENT).minWidth(40);
|
leftPanel.layoutHeight(FILL_PARENT).minWidth(40);
|
||||||
|
|
||||||
|
rightPanel = new VerticalLayout("main");
|
||||||
rightPanel.layoutHeight(FILL_PARENT).layoutWidth(FILL_PARENT);
|
rightPanel.layoutHeight(FILL_PARENT).layoutWidth(FILL_PARENT);
|
||||||
rightPanel.addChild(new TextWidget(null, "Path:"d));
|
rightPanel.addChild(new TextWidget(null, "Path:"d));
|
||||||
|
|
||||||
content.addChild(leftPanel);
|
content.addChild(leftPanel);
|
||||||
content.addChild(rightPanel);
|
content.addChild(rightPanel);
|
||||||
path = new EditLine("path");
|
|
||||||
path.layoutWidth(FILL_PARENT);
|
|
||||||
filename = new EditLine("path");
|
|
||||||
filename.layoutWidth(FILL_PARENT);
|
|
||||||
|
|
||||||
rightPanel.addChild(path);
|
_edPath = new EditLine("path");
|
||||||
list = new StringGridWidget("files");
|
_edPath.layoutWidth(FILL_PARENT);
|
||||||
list.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
|
_edPath.layoutWeight = 0;
|
||||||
list.resize(4, 3);
|
|
||||||
list.setColTitle(0, " "d);
|
_edFilename = new EditLine("path");
|
||||||
list.setColTitle(1, "Name"d);
|
_edFilename.layoutWidth(FILL_PARENT);
|
||||||
list.setColTitle(2, "Size"d);
|
_edFilename.layoutWeight = 0;
|
||||||
list.setColTitle(3, "Modified"d);
|
|
||||||
list.showRowHeaders = false;
|
rightPanel.addChild(_edPath);
|
||||||
list.rowSelect = true;
|
_fileList = new StringGridWidget("files");
|
||||||
rightPanel.addChild(list);
|
_fileList.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT);
|
||||||
rightPanel.addChild(filename);
|
_fileList.resize(4, 3);
|
||||||
|
_fileList.setColTitle(0, " "d);
|
||||||
|
_fileList.setColTitle(1, "Name"d);
|
||||||
|
_fileList.setColTitle(2, "Size"d);
|
||||||
|
_fileList.setColTitle(3, "Modified"d);
|
||||||
|
_fileList.showRowHeaders = false;
|
||||||
|
_fileList.rowSelect = true;
|
||||||
|
rightPanel.addChild(_fileList);
|
||||||
|
rightPanel.addChild(_edFilename);
|
||||||
|
|
||||||
//places = new StringGridWidget("placesList");
|
|
||||||
//places.resize(1, 10);
|
|
||||||
//places.showRowHeaders(false).showColHeaders(true);
|
|
||||||
//places.setColTitle(0, "Places"d);
|
|
||||||
//leftPanel.addChild(places);
|
|
||||||
|
|
||||||
addChild(content);
|
addChild(content);
|
||||||
addChild(createButtonsPanel([ACTION_OPEN, ACTION_CANCEL], 0, 0));
|
addChild(createButtonsPanel([ACTION_OPEN, ACTION_CANCEL], 0, 0));
|
||||||
|
|
||||||
//string[] path = splitPath("/home/lve/src");
|
_fileList.customCellAdapter = this;
|
||||||
//Log.d("path: ", path);
|
_fileList.onCellActivated = delegate(GridWidgetBase source, int col, int row) {
|
||||||
|
|
||||||
list.customCellAdapter = this;
|
|
||||||
list.onCellActivated = delegate(GridWidgetBase source, int col, int row) {
|
|
||||||
onItemActivated(row);
|
onItemActivated(row);
|
||||||
};
|
};
|
||||||
|
|
||||||
openDirectory(currentDir);
|
openDirectory(currentDir);
|
||||||
minWidth = 600;
|
_fileList.layoutHeight = FILL_PARENT;
|
||||||
minHeight = 400;
|
|
||||||
layoutWidth = FILL_PARENT;
|
|
||||||
list.layoutHeight = FILL_PARENT;
|
|
||||||
layoutHeight = FILL_PARENT;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1045,9 +1045,21 @@ class GridWidgetBase : ScrollWidgetBase {
|
||||||
_colWidths[i] = (i < _headerCols && !_showRowHeaders) ? 0 : measureColWidth(i) + 5;
|
_colWidths[i] = (i < _headerCols && !_showRowHeaders) ? 0 : measureColWidth(i) + 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// extend specified column width to fit client area if grid width
|
||||||
|
void fillColumnWidth(int colIndex) {
|
||||||
|
int w = _clientRect.width;
|
||||||
|
int totalw = 0;
|
||||||
|
for (int i = 0; i < _cols; i++)
|
||||||
|
totalw += _colWidths[i];
|
||||||
|
if (w > totalw)
|
||||||
|
_colWidths[colIndex + _headerCols] += w - totalw;
|
||||||
|
invalidate();
|
||||||
|
}
|
||||||
|
|
||||||
void autoFitColumnWidths() {
|
void autoFitColumnWidths() {
|
||||||
for (int i = 0; i < _cols; i++)
|
for (int i = 0; i < _cols; i++)
|
||||||
autoFitColumnWidth(i);
|
autoFitColumnWidth(i);
|
||||||
|
invalidate();
|
||||||
}
|
}
|
||||||
|
|
||||||
void autoFitRowHeight(int i) {
|
void autoFitRowHeight(int i) {
|
||||||
|
|
Loading…
Reference in New Issue