mirror of https://github.com/buggins/dlangui.git
FileDlg improvements; fix ComboBox
This commit is contained in:
parent
15226e85a4
commit
50a5232053
|
@ -297,11 +297,12 @@ extern (C) int UIAppMain(string[] args) {
|
|||
dlg.addFilter(FileFilterEntry(UIString("FILTER_ALL_FILES", "All files (*.*)"d), "*.*"));
|
||||
dlg.addFilter(FileFilterEntry(UIString("FILTER_TEXT_FILES", "Text files (*.txt)"d), "*.txt"));
|
||||
dlg.addFilter(FileFilterEntry(UIString("FILTER_SOURCE_FILES", "Source files"d), "*.d;*.dd;*.c;*.cc;*.cpp;*.h;*.hpp"));
|
||||
dlg.filterIndex = 2;
|
||||
//dlg.filterIndex = 2;
|
||||
dlg.onDialogResult = delegate(Dialog dlg, const Action result) {
|
||||
Log.d("FileDialog.onDialogResult: ", result, " param=", result.stringParam);
|
||||
window.showMessageBox(UIString("FileOpen result"d), UIString(toUTF32(result.stringParam)));
|
||||
import dlangui.core.stdaction;
|
||||
if (result.id == ACTION_OPEN.id) {
|
||||
Log.d("FileDialog.onDialogResult: ", result, " param=", result.stringParam);
|
||||
window.showMessageBox(UIString("FileOpen result"d), UIString(toUTF32(result.stringParam)));
|
||||
}
|
||||
|
||||
};
|
||||
dlg.show();
|
||||
|
|
|
@ -143,6 +143,23 @@
|
|||
fontFamily="SansSerif"
|
||||
fontSize="16"
|
||||
/>
|
||||
<style id="COMBO_BOX"
|
||||
backgroundImageId="editbox_background"
|
||||
padding="2,2,2,2"
|
||||
margins="2,2,2,2"
|
||||
minWidth="40"
|
||||
fontFace="Arial"
|
||||
fontFamily="SansSerif"
|
||||
fontSize="16"
|
||||
/>
|
||||
<style id="COMBO_BOX_BODY"
|
||||
padding="2,2,2,2"
|
||||
minWidth="40"
|
||||
fontFace="Arial"
|
||||
fontFamily="SansSerif"
|
||||
fontSize="16"
|
||||
align="Left|VCenter"
|
||||
/>
|
||||
<style id="EDIT_BOX"
|
||||
backgroundImageId="editbox_background"
|
||||
padding="5,6,5,6"
|
||||
|
|
|
@ -50,6 +50,7 @@ public import dlangui.core.logger;
|
|||
public import dlangui.core.types;
|
||||
public import dlangui.core.i18n;
|
||||
public import dlangui.core.files;
|
||||
public import dlangui.core.stdaction;
|
||||
public import dlangui.graphics.images;
|
||||
public import dlangui.widgets.widget;
|
||||
public import dlangui.widgets.controls;
|
||||
|
|
|
@ -69,15 +69,6 @@ struct FileFilterEntry {
|
|||
}
|
||||
}
|
||||
|
||||
class HorizontalLayoutTest : HorizontalLayout {
|
||||
this() {
|
||||
}
|
||||
/// Set widget rectangle to specified value and layout widget contents. (Step 2 of two phase layout).
|
||||
override void layout(Rect rc) {
|
||||
super.layout(rc);
|
||||
}
|
||||
}
|
||||
|
||||
/// File open / save dialog
|
||||
class FileDialog : Dialog, CustomGridCellAdapter {
|
||||
protected FilePathPanel _edPath;
|
||||
|
@ -341,7 +332,7 @@ class FileDialog : Dialog, CustomGridCellAdapter {
|
|||
_edPath.layoutWeight = 0;
|
||||
_edPath.onPathSelectionListener = &onPathSelected;
|
||||
|
||||
HorizontalLayout fnlayout = new HorizontalLayoutTest();
|
||||
HorizontalLayout fnlayout = new HorizontalLayout();
|
||||
fnlayout.layoutWidth(FILL_PARENT);
|
||||
_edFilename = new EditLine("filename");
|
||||
_edFilename.layoutWidth(FILL_PARENT);
|
||||
|
|
|
@ -57,14 +57,6 @@ class ComboBoxBase : HorizontalLayout, OnClickHandler {
|
|||
}
|
||||
res.layoutWidth = WRAP_CONTENT;
|
||||
res.layoutHeight = WRAP_CONTENT;
|
||||
int maxItemWidth = 0;
|
||||
for(int i = 0; i < _adapter.itemCount; i++) {
|
||||
Widget item = _adapter.itemWidget(i);
|
||||
item.measure(SIZE_UNSPECIFIED, SIZE_UNSPECIFIED);
|
||||
if (maxItemWidth < item.measuredWidth)
|
||||
maxItemWidth = item.measuredWidth;
|
||||
}
|
||||
res.minWidth = maxItemWidth;
|
||||
return res;
|
||||
}
|
||||
|
||||
|
@ -129,16 +121,20 @@ class ComboBoxBase : HorizontalLayout, OnClickHandler {
|
|||
super(ID);
|
||||
_adapter = adapter;
|
||||
_ownAdapter = ownAdapter;
|
||||
init();
|
||||
}
|
||||
|
||||
protected void init() {
|
||||
_body = createSelectedItemWidget();
|
||||
_body.onClickListener = this;
|
||||
_button = createButton();
|
||||
//_body.state = State.Parent;
|
||||
//focusable = true;
|
||||
_button.focusable = false;
|
||||
_body.focusable = true;
|
||||
//_body.focusable = true;
|
||||
addChild(_body);
|
||||
addChild(_button);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -146,7 +142,6 @@ class ComboBoxBase : HorizontalLayout, OnClickHandler {
|
|||
class ComboBox : ComboBoxBase {
|
||||
|
||||
protected StringListAdapter _adapter;
|
||||
protected EditLine _edit;
|
||||
|
||||
/// empty parameter list constructor - for usage by factory
|
||||
this() {
|
||||
|
@ -165,17 +160,8 @@ class ComboBox : ComboBoxBase {
|
|||
super(ID, (_adapter = new StringListAdapter(items)), true);
|
||||
}
|
||||
|
||||
@property bool readOnly() {
|
||||
return _edit.readOnly;
|
||||
}
|
||||
|
||||
@property ComboBox readOnly(bool ro) {
|
||||
_edit.readOnly = ro;
|
||||
return this;
|
||||
}
|
||||
|
||||
@property override dstring text() {
|
||||
return _edit.text;
|
||||
return _body.text;
|
||||
}
|
||||
|
||||
@property override Widget text(dstring txt) {
|
||||
|
@ -183,11 +169,9 @@ class ComboBox : ComboBoxBase {
|
|||
if (idx >= 0) {
|
||||
selectedItemIndex = idx;
|
||||
} else {
|
||||
if (!readOnly) {
|
||||
// not found
|
||||
_selectedItemIndex = -1;
|
||||
_edit.text = txt;
|
||||
}
|
||||
// not found
|
||||
_selectedItemIndex = -1;
|
||||
_body.text = txt;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
@ -197,18 +181,76 @@ class ComboBox : ComboBoxBase {
|
|||
if (idx >= 0) {
|
||||
selectedItemIndex = idx;
|
||||
} else {
|
||||
if (!readOnly) {
|
||||
// not found
|
||||
_selectedItemIndex = -1;
|
||||
_edit.text = txt;
|
||||
}
|
||||
// not found
|
||||
_selectedItemIndex = -1;
|
||||
_body.text = txt;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
override @property void selectedItemIndex(int index) {
|
||||
_selectedItemIndex = index;
|
||||
_edit.text = _adapter.items[index];
|
||||
_body.text = _adapter.items[index];
|
||||
super.selectedItemIndex(index);
|
||||
}
|
||||
|
||||
override void init() {
|
||||
super.init();
|
||||
_body.focusable = false;
|
||||
_body.clickable = true;
|
||||
focusable = true;
|
||||
//styleId = "COMBO_BOX";
|
||||
clickable = true;
|
||||
onClickListener = this;
|
||||
}
|
||||
|
||||
override protected Widget createSelectedItemWidget() {
|
||||
TextWidget res = new TextWidget("COMBOBOX_BODY");
|
||||
res.styleId = "COMBO_BOX";
|
||||
res.clickable = true;
|
||||
res.layoutWidth = FILL_PARENT;
|
||||
res.layoutHeight = WRAP_CONTENT;
|
||||
int maxItemWidth = 0;
|
||||
for(int i = 0; i < _adapter.itemCount; i++) {
|
||||
Widget item = _adapter.itemWidget(i);
|
||||
item.measure(SIZE_UNSPECIFIED, SIZE_UNSPECIFIED);
|
||||
if (maxItemWidth < item.measuredWidth)
|
||||
maxItemWidth = item.measuredWidth;
|
||||
}
|
||||
res.minWidth = maxItemWidth;
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** Editable ComboBox with list of strings. */
|
||||
class ComboEdit : ComboBox {
|
||||
|
||||
protected EditLine _edit;
|
||||
|
||||
/// empty parameter list constructor - for usage by factory
|
||||
this() {
|
||||
this(null);
|
||||
}
|
||||
/// create with ID parameter
|
||||
this(string ID) {
|
||||
super(ID);
|
||||
}
|
||||
|
||||
this(string ID, string[] items) {
|
||||
super(ID, items);
|
||||
}
|
||||
|
||||
this(string ID, dstring[] items) {
|
||||
super(ID, items);
|
||||
}
|
||||
|
||||
@property bool readOnly() {
|
||||
return _edit.readOnly;
|
||||
}
|
||||
|
||||
@property ComboBox readOnly(bool ro) {
|
||||
_edit.readOnly = ro;
|
||||
return this;
|
||||
}
|
||||
|
||||
override protected Widget createSelectedItemWidget() {
|
||||
|
@ -220,4 +262,11 @@ class ComboBox : ComboBoxBase {
|
|||
return res;
|
||||
}
|
||||
|
||||
override void init() {
|
||||
super.init();
|
||||
focusable = false;
|
||||
_body.focusable = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue