Merge pull request #391 from and3md/confirm_override

FileDialogFlag.ConfirmOverwrite flag support
This commit is contained in:
Vadim Lopatin 2017-07-22 10:44:12 +03:00 committed by GitHub
commit f7fa74a980
4 changed files with 45 additions and 12 deletions

View File

@ -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);

View File

@ -13,7 +13,7 @@ import dlangui.dialogs.msgbox;
window.showMessageBox(UIString("Dialog title"d), UIString("Some message"d)); window.showMessageBox(UIString("Dialog title"d), UIString("Some message"d));
// show message box with OK and CANCEL buttons, cancel by default, and handle its result // show message box with OK and CANCEL buttons, cancel by default, and handle its result
window.showMessageBox(UIString("Dialog title"d), UIString("Some message"d), [ACTION_OK, ACTION_CANCEL], 1, delegate(const Action a) { window.showMessageBox(UIString("Dialog title"d), UIString("Some message"d), [ACTION_OK, ACTION_CANCEL], 1, delegate bool(const Action a) {
if (a.id == StandardAction.Ok) if (a.id == StandardAction.Ok)
Log.d("OK pressed"); Log.d("OK pressed");
else if (a.id == StandardAction.Cancel) else if (a.id == StandardAction.Cancel)

View File

@ -20,6 +20,8 @@ CREATE_NEW_FOLDER=Create new folder
INPUT_NAME_FOR_FOLDER=Input folder name INPUT_NAME_FOR_FOLDER=Input folder name
CREATE_FOLDER_ERROR_TITLE=Cannot create folder CREATE_FOLDER_ERROR_TITLE=Cannot create folder
CREATE_FOLDER_ERROR_MESSAGE=Folder creation is failed CREATE_FOLDER_ERROR_MESSAGE=Folder creation is failed
CONFIRM_OVERWRITE_TITLE=Confirm overwrite
CONFIRM_OVERWRITE_FILE_NAMED_%s_QUESTION=A file named "%s" already exists. Do you want to replace it?
ACTION_EDITOR_TOGGLE_BOOKMARK=Toggle bookmark ACTION_EDITOR_TOGGLE_BOOKMARK=Toggle bookmark
ACTION_EDITOR_GOTO_NEXT_BOOKMARK=Go to next bookmark ACTION_EDITOR_GOTO_NEXT_BOOKMARK=Go to next bookmark

View File

@ -20,6 +20,8 @@ CREATE_NEW_FOLDER=Utwórz nowy folder
INPUT_NAME_FOR_FOLDER=Wprowadź nazwę folderu INPUT_NAME_FOR_FOLDER=Wprowadź nazwę folderu
CREATE_FOLDER_ERROR_TITLE=Nie można utworzyć folderu CREATE_FOLDER_ERROR_TITLE=Nie można utworzyć folderu
CREATE_FOLDER_ERROR_MESSAGE=Nieudane utworzenie folderu CREATE_FOLDER_ERROR_MESSAGE=Nieudane utworzenie folderu
CONFIRM_OVERWRITE_TITLE=Potwierdź nadpisanie
CONFIRM_OVERWRITE_FILE_NAMED_%s_QUESTION=Plik o nazwie "%s" już istnieje. Czy chcesz go nadpisać?
ACTION_EDITOR_TOGGLE_BOOKMARK=Wstaw/usuń zakładkę ACTION_EDITOR_TOGGLE_BOOKMARK=Wstaw/usuń zakładkę
ACTION_EDITOR_GOTO_NEXT_BOOKMARK=Następna zakładka ACTION_EDITOR_GOTO_NEXT_BOOKMARK=Następna zakładka