From fb53e6f55cf1b3491f8d8d6773b09352c5f96b32 Mon Sep 17 00:00:00 2001 From: and3md Date: Fri, 21 Jul 2017 13:42:07 +0200 Subject: [PATCH 1/3] FileDialogFlag.ConfirmOverwrite flag support. --- src/dlangui/dialogs/filedlg.d | 51 +++++++++++++++++++++++++++-------- 1 file changed, 40 insertions(+), 11 deletions(-) diff --git a/src/dlangui/dialogs/filedlg.d b/src/dlangui/dialogs/filedlg.d index 8c90abc1..1abf117c 100644 --- a/src/dlangui/dialogs/filedlg.d +++ b/src/dlangui/dialogs/filedlg.d @@ -364,11 +364,8 @@ class FileDialog : Dialog, CustomGridCellAdapter { return sz; } if (BACKEND_CONSOLE) - { return Point(0, 0); - } - else - { + else { DrawableRef icon = rowIcon(row); if (icon.isNull) return Point(0, 0); @@ -439,11 +436,16 @@ class FileDialog : Dialog, CustomGridCellAdapter { openDirectory(e.name, _path); } else if (e.isFile) { string fname = e.name; - Action result = _action; - result.stringParam = fname; - close(result); + if ((_flags & FileDialogFlag.ConfirmOverwrite) && exists(fname) && isFile(fname)) { + showConfirmOverwriteQuestion(fname); + return; + } + else { + Action result = _action; + result.stringParam = fname; + close(result); + } } - } /// file list item selected @@ -487,6 +489,7 @@ class FileDialog : Dialog, CustomGridCellAdapter { _filename = _path ~ dirSeparator ~ baseFilename; if (action.id != StandardAction.OpenDirectory && exists(_filename) && isDir(_filename)) { + // directory selected but we need file so open directory auto row = _fileList.row(); onItemActivated(row); return true; @@ -494,9 +497,23 @@ class FileDialog : Dialog, CustomGridCellAdapter { Action result = _action; result.stringParam = _filename; // success if either selected dir & has to open dir or if selected file - if (action.id == StandardAction.OpenDirectory && exists(_filename) && isDir(_filename) || - action.id == StandardAction.Save && !(_flags & FileDialogFlag.FileMustExist) || - exists(_filename) && isFile(_filename)) { + if (action.id == StandardAction.OpenDirectory && exists(_filename) && isDir(_filename)) { + close(result); + 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); return true; } @@ -505,6 +522,18 @@ class FileDialog : Dialog, CustomGridCellAdapter { 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) { // return openDirectory(path, null); From 3af97996ca2c8f16705c23ff01485961269a6f4b Mon Sep 17 00:00:00 2001 From: and3md Date: Fri, 21 Jul 2017 13:43:09 +0200 Subject: [PATCH 2/3] showMessageBox() example fix. --- src/dlangui/dialogs/msgbox.d | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dlangui/dialogs/msgbox.d b/src/dlangui/dialogs/msgbox.d index 295266fe..985d54d0 100644 --- a/src/dlangui/dialogs/msgbox.d +++ b/src/dlangui/dialogs/msgbox.d @@ -13,7 +13,7 @@ import dlangui.dialogs.msgbox; 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 -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) Log.d("OK pressed"); else if (a.id == StandardAction.Cancel) From 3f6e4d03a49fafefe895623f5d4fd4663f4c0e6c Mon Sep 17 00:00:00 2001 From: and3md Date: Fri, 21 Jul 2017 13:47:31 +0200 Subject: [PATCH 3/3] English and Polish translation for confirm overwrite. --- views/res/i18n/std_en.ini | 2 ++ views/res/i18n/std_pl.ini | 2 ++ 2 files changed, 4 insertions(+) diff --git a/views/res/i18n/std_en.ini b/views/res/i18n/std_en.ini index af1f777b..59081eb3 100644 --- a/views/res/i18n/std_en.ini +++ b/views/res/i18n/std_en.ini @@ -20,6 +20,8 @@ CREATE_NEW_FOLDER=Create new folder INPUT_NAME_FOR_FOLDER=Input folder name CREATE_FOLDER_ERROR_TITLE=Cannot create folder 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_GOTO_NEXT_BOOKMARK=Go to next bookmark diff --git a/views/res/i18n/std_pl.ini b/views/res/i18n/std_pl.ini index e91ef92f..31951303 100644 --- a/views/res/i18n/std_pl.ini +++ b/views/res/i18n/std_pl.ini @@ -20,6 +20,8 @@ CREATE_NEW_FOLDER=Utwórz nowy folder INPUT_NAME_FOR_FOLDER=Wprowadź nazwę folderu CREATE_FOLDER_ERROR_TITLE=Nie można utworzyć 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_GOTO_NEXT_BOOKMARK=Następna zakładka