mirror of https://github.com/buggins/dlangui.git
FileDialogFlag.ConfirmOverwrite flag support.
This commit is contained in:
parent
018a3c9857
commit
fb53e6f55c
|
@ -364,11 +364,8 @@ class FileDialog : Dialog, CustomGridCellAdapter {
|
||||||
return sz;
|
return sz;
|
||||||
}
|
}
|
||||||
if (BACKEND_CONSOLE)
|
if (BACKEND_CONSOLE)
|
||||||
{
|
|
||||||
return Point(0, 0);
|
return Point(0, 0);
|
||||||
}
|
else {
|
||||||
else
|
|
||||||
{
|
|
||||||
DrawableRef icon = rowIcon(row);
|
DrawableRef icon = rowIcon(row);
|
||||||
if (icon.isNull)
|
if (icon.isNull)
|
||||||
return Point(0, 0);
|
return Point(0, 0);
|
||||||
|
@ -439,11 +436,16 @@ class FileDialog : Dialog, CustomGridCellAdapter {
|
||||||
openDirectory(e.name, _path);
|
openDirectory(e.name, _path);
|
||||||
} else if (e.isFile) {
|
} else if (e.isFile) {
|
||||||
string fname = e.name;
|
string fname = e.name;
|
||||||
|
if ((_flags & FileDialogFlag.ConfirmOverwrite) && exists(fname) && isFile(fname)) {
|
||||||
|
showConfirmOverwriteQuestion(fname);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
Action result = _action;
|
Action result = _action;
|
||||||
result.stringParam = fname;
|
result.stringParam = fname;
|
||||||
close(result);
|
close(result);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// file list item selected
|
/// file list item selected
|
||||||
|
@ -487,6 +489,7 @@ class FileDialog : Dialog, CustomGridCellAdapter {
|
||||||
_filename = _path ~ dirSeparator ~ baseFilename;
|
_filename = _path ~ dirSeparator ~ baseFilename;
|
||||||
|
|
||||||
if (action.id != StandardAction.OpenDirectory && exists(_filename) && isDir(_filename)) {
|
if (action.id != StandardAction.OpenDirectory && exists(_filename) && isDir(_filename)) {
|
||||||
|
// directory selected but we need file so open directory
|
||||||
auto row = _fileList.row();
|
auto row = _fileList.row();
|
||||||
onItemActivated(row);
|
onItemActivated(row);
|
||||||
return true;
|
return true;
|
||||||
|
@ -494,9 +497,23 @@ class FileDialog : Dialog, CustomGridCellAdapter {
|
||||||
Action result = _action;
|
Action result = _action;
|
||||||
result.stringParam = _filename;
|
result.stringParam = _filename;
|
||||||
// success if either selected dir & has to open dir or if selected file
|
// success if either selected dir & has to open dir or if selected file
|
||||||
if (action.id == StandardAction.OpenDirectory && exists(_filename) && isDir(_filename) ||
|
if (action.id == StandardAction.OpenDirectory && exists(_filename) && isDir(_filename)) {
|
||||||
action.id == StandardAction.Save && !(_flags & FileDialogFlag.FileMustExist) ||
|
close(result);
|
||||||
exists(_filename) && isFile(_filename)) {
|
return true;
|
||||||
|
}
|
||||||
|
else if (action.id == StandardAction.Save && !(_flags & FileDialogFlag.FileMustExist)) {
|
||||||
|
// save dialog
|
||||||
|
if ((_flags & FileDialogFlag.ConfirmOverwrite) && exists(_filename) && isFile(_filename)) {
|
||||||
|
showConfirmOverwriteQuestion(_filename);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
close(result);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (exists(_filename) && isFile(_filename)) {
|
||||||
|
// open dialog
|
||||||
close(result);
|
close(result);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -505,6 +522,18 @@ class FileDialog : Dialog, CustomGridCellAdapter {
|
||||||
return super.handleAction(action);
|
return super.handleAction(action);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// shows question "override file?"
|
||||||
|
protected void showConfirmOverwriteQuestion(string fileName) {
|
||||||
|
window.showMessageBox(UIString.fromId("CONFIRM_OVERWRITE_TITLE"c).value, format(UIString.fromId("CONFIRM_OVERWRITE_FILE_NAMED_%s_QUESTION"c).value, baseName(fileName)), [ACTION_YES, ACTION_NO], 1, delegate bool(const Action a) {
|
||||||
|
if (a.id == StandardAction.Yes) {
|
||||||
|
Action result = _action;
|
||||||
|
result.stringParam = fileName;
|
||||||
|
close(result);
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
bool onPathSelected(string path) {
|
bool onPathSelected(string path) {
|
||||||
//
|
//
|
||||||
return openDirectory(path, null);
|
return openDirectory(path, null);
|
||||||
|
|
Loading…
Reference in New Issue