mirror of https://github.com/buggins/dlangui.git
add inputbox dialog; add New Folder button to file dialog
This commit is contained in:
parent
167cc17d22
commit
9e878d2c16
|
@ -260,6 +260,7 @@
|
||||||
<Compile Include="src\dlangui\core\types.d" />
|
<Compile Include="src\dlangui\core\types.d" />
|
||||||
<Compile Include="src\dlangui\dialogs\dialog.d" />
|
<Compile Include="src\dlangui\dialogs\dialog.d" />
|
||||||
<Compile Include="src\dlangui\dialogs\filedlg.d" />
|
<Compile Include="src\dlangui\dialogs\filedlg.d" />
|
||||||
|
<Compile Include="src\dlangui\dialogs\inputbox.d" />
|
||||||
<Compile Include="src\dlangui\dialogs\msgbox.d" />
|
<Compile Include="src\dlangui\dialogs\msgbox.d" />
|
||||||
<Compile Include="src\dlangui\dialogs\settingsdialog.d" />
|
<Compile Include="src\dlangui\dialogs\settingsdialog.d" />
|
||||||
<Compile Include="src\dlangui\dml\annotations.d" />
|
<Compile Include="src\dlangui\dml\annotations.d" />
|
||||||
|
|
|
@ -120,6 +120,7 @@
|
||||||
<Compile Include="src\dlangui\dialogs\dialog.d" />
|
<Compile Include="src\dlangui\dialogs\dialog.d" />
|
||||||
<Compile Include="src\dlangui\dialogs\filedlg.d" />
|
<Compile Include="src\dlangui\dialogs\filedlg.d" />
|
||||||
<Compile Include="src\dlangui\dialogs\msgbox.d" />
|
<Compile Include="src\dlangui\dialogs\msgbox.d" />
|
||||||
|
<Compile Include="src\dlangui\dialogs\inputbox.d" />
|
||||||
<Compile Include="src\dlangui\dialogs\settingsdialog.d" />
|
<Compile Include="src\dlangui\dialogs\settingsdialog.d" />
|
||||||
<Compile Include="src\dlangui\dml\annotations.d" />
|
<Compile Include="src\dlangui\dml\annotations.d" />
|
||||||
<Compile Include="src\dlangui\dml\dmlhighlight.d" />
|
<Compile Include="src\dlangui\dml\dmlhighlight.d" />
|
||||||
|
|
|
@ -578,6 +578,7 @@
|
||||||
<Folder name="dialogs">
|
<Folder name="dialogs">
|
||||||
<File path="src\dlangui\dialogs\dialog.d" />
|
<File path="src\dlangui\dialogs\dialog.d" />
|
||||||
<File path="src\dlangui\dialogs\filedlg.d" />
|
<File path="src\dlangui\dialogs\filedlg.d" />
|
||||||
|
<File path="src\dlangui\dialogs\inputbox.d" />
|
||||||
<File path="src\dlangui\dialogs\msgbox.d" />
|
<File path="src\dlangui\dialogs\msgbox.d" />
|
||||||
<File path="src\dlangui\dialogs\settingsdialog.d" />
|
<File path="src\dlangui\dialogs\settingsdialog.d" />
|
||||||
</Folder>
|
</Folder>
|
||||||
|
|
|
@ -36,6 +36,7 @@ enum StandardAction : int {
|
||||||
OpenUrl,
|
OpenUrl,
|
||||||
Apply,
|
Apply,
|
||||||
OpenDirectory,
|
OpenDirectory,
|
||||||
|
CreateDirectory,
|
||||||
}
|
}
|
||||||
|
|
||||||
const Action ACTION_OK = new Action(StandardAction.Ok, "ACTION_OK"c, "dialog-ok");
|
const Action ACTION_OK = new Action(StandardAction.Ok, "ACTION_OK"c, "dialog-ok");
|
||||||
|
@ -49,6 +50,7 @@ const Action ACTION_RETRY = new Action(StandardAction.Retry, "ACTION_RETRY"c);
|
||||||
const Action ACTION_IGNORE = new Action(StandardAction.Ignore, "ACTION_IGNORE"c);
|
const Action ACTION_IGNORE = new Action(StandardAction.Ignore, "ACTION_IGNORE"c);
|
||||||
const Action ACTION_OPEN = new Action(StandardAction.Open, "ACTION_OPEN"c);
|
const Action ACTION_OPEN = new Action(StandardAction.Open, "ACTION_OPEN"c);
|
||||||
const Action ACTION_OPEN_DIRECTORY = new Action(StandardAction.OpenDirectory, "ACTION_OPEN_DIRECTORY"c);
|
const Action ACTION_OPEN_DIRECTORY = new Action(StandardAction.OpenDirectory, "ACTION_OPEN_DIRECTORY"c);
|
||||||
|
const Action ACTION_CREATE_DIRECTORY = new Action(StandardAction.CreateDirectory, "ACTION_CREATE_DIRECTORY"c);
|
||||||
const Action ACTION_SAVE = new Action(StandardAction.Save, "ACTION_SAVE"c);
|
const Action ACTION_SAVE = new Action(StandardAction.Save, "ACTION_SAVE"c);
|
||||||
const Action ACTION_SAVE_ALL = new Action(StandardAction.SaveAll, "ACTION_SAVE_ALL"c);
|
const Action ACTION_SAVE_ALL = new Action(StandardAction.SaveAll, "ACTION_SAVE_ALL"c);
|
||||||
const Action ACTION_DISCARD_CHANGES = new Action(StandardAction.DiscardChanges, "ACTION_DISCARD_CHANGES"c);
|
const Action ACTION_DISCARD_CHANGES = new Action(StandardAction.DiscardChanges, "ACTION_DISCARD_CHANGES"c);
|
||||||
|
|
|
@ -315,12 +315,30 @@ class FileDialog : Dialog, CustomGridCellAdapter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void createAndEnterDirectory(string name) {
|
||||||
|
string newdir = buildNormalizedPath(_path, name);
|
||||||
|
try {
|
||||||
|
mkdirRecurse(newdir);
|
||||||
|
openDirectory(newdir, null);
|
||||||
|
} catch (Exception e) {
|
||||||
|
window.showMessageBox(UIString("CREATE_FOLDER_ERROR_TITLE"c), UIString("CREATE_FOLDER_ERROR_MESSAGE"c));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// Custom handling of actions
|
/// Custom handling of actions
|
||||||
override bool handleAction(const Action action) {
|
override bool handleAction(const Action action) {
|
||||||
if (action.id == StandardAction.Cancel) {
|
if (action.id == StandardAction.Cancel) {
|
||||||
super.handleAction(action);
|
super.handleAction(action);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
if (action.id == StandardAction.CreateDirectory) {
|
||||||
|
// show editor popup
|
||||||
|
window.showInputBox(UIString("CREATE_NEW_FOLDER"c), UIString("INPUT_NAME_FOR_FOLDER"c), ""d, delegate(dstring s) {
|
||||||
|
if (!s.empty)
|
||||||
|
createAndEnterDirectory(toUTF8(s));
|
||||||
|
});
|
||||||
|
return true;
|
||||||
|
}
|
||||||
if (action.id == StandardAction.Open || action.id == StandardAction.OpenDirectory || action.id == StandardAction.Save) {
|
if (action.id == StandardAction.Open || action.id == StandardAction.OpenDirectory || action.id == StandardAction.Save) {
|
||||||
if (_filename.length > 0 || action.id == StandardAction.OpenDirectory) {
|
if (_filename.length > 0 || action.id == StandardAction.OpenDirectory) {
|
||||||
Action result = _action;
|
Action result = _action;
|
||||||
|
@ -411,7 +429,11 @@ class FileDialog : Dialog, CustomGridCellAdapter {
|
||||||
|
|
||||||
|
|
||||||
addChild(content);
|
addChild(content);
|
||||||
|
if (_flags & FileDialogFlag.EnableCreateDirectory) {
|
||||||
|
addChild(createButtonsPanel([ACTION_CREATE_DIRECTORY, cast(immutable)_action, ACTION_CANCEL], 1, 1));
|
||||||
|
} else {
|
||||||
addChild(createButtonsPanel([cast(immutable)_action, ACTION_CANCEL], 0, 0));
|
addChild(createButtonsPanel([cast(immutable)_action, ACTION_CANCEL], 0, 0));
|
||||||
|
}
|
||||||
|
|
||||||
_fileList.customCellAdapter = this;
|
_fileList.customCellAdapter = this;
|
||||||
_fileList.onCellActivated = delegate(GridWidgetBase source, int col, int row) {
|
_fileList.onCellActivated = delegate(GridWidgetBase source, int col, int row) {
|
||||||
|
|
|
@ -0,0 +1,48 @@
|
||||||
|
module dlangui.dialogs.inputbox;
|
||||||
|
|
||||||
|
import dlangui.core.i18n;
|
||||||
|
import dlangui.core.signals;
|
||||||
|
import dlangui.core.stdaction;
|
||||||
|
import dlangui.widgets.layouts;
|
||||||
|
import dlangui.widgets.controls;
|
||||||
|
import dlangui.widgets.editors;
|
||||||
|
import dlangui.platforms.common.platform;
|
||||||
|
import dlangui.dialogs.dialog;
|
||||||
|
|
||||||
|
/// Message box
|
||||||
|
class InputBox : Dialog {
|
||||||
|
protected UIString _message;
|
||||||
|
protected const(Action)[] _actions;
|
||||||
|
protected int _defaultButtonIndex;
|
||||||
|
protected dstring _text;
|
||||||
|
this(UIString caption, UIString message, Window parentWindow, dstring initialText, void delegate(dstring result) handler) {
|
||||||
|
super(caption, parentWindow, DialogFlag.Modal | DialogFlag.Popup);
|
||||||
|
_message = message;
|
||||||
|
_actions = [ACTION_OK, ACTION_CANCEL];
|
||||||
|
_defaultButtonIndex = 0;
|
||||||
|
_text = initialText;
|
||||||
|
if (handler) {
|
||||||
|
dialogResult = delegate (Dialog dlg, const Action action) {
|
||||||
|
if (action.id == ACTION_OK.id) {
|
||||||
|
handler(_text);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
/// override to implement creation of dialog controls
|
||||||
|
override void init() {
|
||||||
|
TextWidget msg = new MultilineTextWidget("msg", _message);
|
||||||
|
padding(Rect(10, 10, 10, 10));
|
||||||
|
msg.padding(Rect(10, 10, 10, 10));
|
||||||
|
EditLine editor = new EditLine("inputbox_editor");
|
||||||
|
editor.layoutWidth = FILL_PARENT;
|
||||||
|
editor.text = _text;
|
||||||
|
editor.contentChange = delegate(EditableContent content) {
|
||||||
|
_text = content.text;
|
||||||
|
};
|
||||||
|
addChild(msg);
|
||||||
|
addChild(editor);
|
||||||
|
addChild(createButtonsPanel(_actions, _defaultButtonIndex, 0));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -26,7 +26,6 @@ import dlangui.widgets.widget;
|
||||||
import dlangui.widgets.popup;
|
import dlangui.widgets.popup;
|
||||||
import dlangui.graphics.drawbuf;
|
import dlangui.graphics.drawbuf;
|
||||||
import dlangui.core.stdaction;
|
import dlangui.core.stdaction;
|
||||||
import dlangui.dialogs.msgbox;
|
|
||||||
|
|
||||||
private import dlangui.graphics.gldrawbuf;
|
private import dlangui.graphics.gldrawbuf;
|
||||||
private import std.algorithm;
|
private import std.algorithm;
|
||||||
|
@ -1065,6 +1064,7 @@ class Window {
|
||||||
|
|
||||||
/// Show message box with specified title and message (title and message as UIString)
|
/// Show message box with specified title and message (title and message as UIString)
|
||||||
void showMessageBox(UIString title, UIString message, const (Action)[] actions = [ACTION_OK], int defaultActionIndex = 0, bool delegate(const Action result) handler = null) {
|
void showMessageBox(UIString title, UIString message, const (Action)[] actions = [ACTION_OK], int defaultActionIndex = 0, bool delegate(const Action result) handler = null) {
|
||||||
|
import dlangui.dialogs.msgbox;
|
||||||
MessageBox dlg = new MessageBox(title, message, this, actions, defaultActionIndex, handler);
|
MessageBox dlg = new MessageBox(title, message, this, actions, defaultActionIndex, handler);
|
||||||
dlg.show();
|
dlg.show();
|
||||||
}
|
}
|
||||||
|
@ -1074,6 +1074,16 @@ class Window {
|
||||||
showMessageBox(UIString(title), UIString(message), actions, defaultActionIndex, handler);
|
showMessageBox(UIString(title), UIString(message), actions, defaultActionIndex, handler);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void showInputBox(UIString title, UIString message, dstring initialText, void delegate(dstring result) handler) {
|
||||||
|
import dlangui.dialogs.inputbox;
|
||||||
|
InputBox dlg = new InputBox(title, message, this, initialText, handler);
|
||||||
|
dlg.show();
|
||||||
|
}
|
||||||
|
|
||||||
|
void showInputBox(dstring title, dstring message, dstring initialText, void delegate(dstring result) handler) {
|
||||||
|
showInputBox(UIString(title), UIString(message), initialText, handler);
|
||||||
|
}
|
||||||
|
|
||||||
protected TimerQueue _timerQueue;
|
protected TimerQueue _timerQueue;
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -15,3 +15,8 @@ ACTION_SAVE=Save
|
||||||
ACTION_SAVE_ALL=Save All
|
ACTION_SAVE_ALL=Save All
|
||||||
ACTION_DISCARD_CHANGES=Discard
|
ACTION_DISCARD_CHANGES=Discard
|
||||||
ACTION_DISCARD_ALL=Discard all
|
ACTION_DISCARD_ALL=Discard all
|
||||||
|
ACTION_CREATE_DIRECTORY=New folder
|
||||||
|
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
|
||||||
|
|
|
@ -11,3 +11,8 @@ ACTION_IGNORE=Игнорировать
|
||||||
ACTION_OPEN=Открыть
|
ACTION_OPEN=Открыть
|
||||||
ACTION_OPEN_DIRECTORY=Выбрать папку
|
ACTION_OPEN_DIRECTORY=Выбрать папку
|
||||||
ACTION_SAVE=Сохранить
|
ACTION_SAVE=Сохранить
|
||||||
|
ACTION_CREATE_DIRECTORY=Новая папка
|
||||||
|
CREATE_NEW_FOLDER=Создать папку
|
||||||
|
INPUT_NAME_FOR_FOLDER=Введите имя для папки
|
||||||
|
CREATE_FOLDER_ERROR_TITLE=Ошибка сосдания папки
|
||||||
|
CREATE_FOLDER_ERROR_MESSAGE=Не удалось создать папку
|
||||||
|
|
Loading…
Reference in New Issue