FileDlg improvements; fix ComboBox

This commit is contained in:
Vadim Lopatin 2015-01-07 18:08:11 +03:00
parent 15226e85a4
commit 50a5232053
5 changed files with 106 additions and 47 deletions

View File

@ -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_ALL_FILES", "All files (*.*)"d), "*.*"));
dlg.addFilter(FileFilterEntry(UIString("FILTER_TEXT_FILES", "Text files (*.txt)"d), "*.txt")); 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.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) { dlg.onDialogResult = delegate(Dialog dlg, const Action result) {
if (result.id == ACTION_OPEN.id) {
Log.d("FileDialog.onDialogResult: ", result, " param=", result.stringParam); Log.d("FileDialog.onDialogResult: ", result, " param=", result.stringParam);
window.showMessageBox(UIString("FileOpen result"d), UIString(toUTF32(result.stringParam))); window.showMessageBox(UIString("FileOpen result"d), UIString(toUTF32(result.stringParam)));
import dlangui.core.stdaction; }
}; };
dlg.show(); dlg.show();

View File

@ -143,6 +143,23 @@
fontFamily="SansSerif" fontFamily="SansSerif"
fontSize="16" 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" <style id="EDIT_BOX"
backgroundImageId="editbox_background" backgroundImageId="editbox_background"
padding="5,6,5,6" padding="5,6,5,6"

View File

@ -50,6 +50,7 @@ public import dlangui.core.logger;
public import dlangui.core.types; public import dlangui.core.types;
public import dlangui.core.i18n; public import dlangui.core.i18n;
public import dlangui.core.files; public import dlangui.core.files;
public import dlangui.core.stdaction;
public import dlangui.graphics.images; public import dlangui.graphics.images;
public import dlangui.widgets.widget; public import dlangui.widgets.widget;
public import dlangui.widgets.controls; public import dlangui.widgets.controls;

View File

@ -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 /// File open / save dialog
class FileDialog : Dialog, CustomGridCellAdapter { class FileDialog : Dialog, CustomGridCellAdapter {
protected FilePathPanel _edPath; protected FilePathPanel _edPath;
@ -341,7 +332,7 @@ class FileDialog : Dialog, CustomGridCellAdapter {
_edPath.layoutWeight = 0; _edPath.layoutWeight = 0;
_edPath.onPathSelectionListener = &onPathSelected; _edPath.onPathSelectionListener = &onPathSelected;
HorizontalLayout fnlayout = new HorizontalLayoutTest(); HorizontalLayout fnlayout = new HorizontalLayout();
fnlayout.layoutWidth(FILL_PARENT); fnlayout.layoutWidth(FILL_PARENT);
_edFilename = new EditLine("filename"); _edFilename = new EditLine("filename");
_edFilename.layoutWidth(FILL_PARENT); _edFilename.layoutWidth(FILL_PARENT);

View File

@ -57,14 +57,6 @@ class ComboBoxBase : HorizontalLayout, OnClickHandler {
} }
res.layoutWidth = WRAP_CONTENT; res.layoutWidth = WRAP_CONTENT;
res.layoutHeight = 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; return res;
} }
@ -129,13 +121,17 @@ class ComboBoxBase : HorizontalLayout, OnClickHandler {
super(ID); super(ID);
_adapter = adapter; _adapter = adapter;
_ownAdapter = ownAdapter; _ownAdapter = ownAdapter;
init();
}
protected void init() {
_body = createSelectedItemWidget(); _body = createSelectedItemWidget();
_body.onClickListener = this; _body.onClickListener = this;
_button = createButton(); _button = createButton();
//_body.state = State.Parent; //_body.state = State.Parent;
//focusable = true; //focusable = true;
_button.focusable = false; _button.focusable = false;
_body.focusable = true; //_body.focusable = true;
addChild(_body); addChild(_body);
addChild(_button); addChild(_button);
} }
@ -146,7 +142,6 @@ class ComboBoxBase : HorizontalLayout, OnClickHandler {
class ComboBox : ComboBoxBase { class ComboBox : ComboBoxBase {
protected StringListAdapter _adapter; protected StringListAdapter _adapter;
protected EditLine _edit;
/// empty parameter list constructor - for usage by factory /// empty parameter list constructor - for usage by factory
this() { this() {
@ -165,17 +160,8 @@ class ComboBox : ComboBoxBase {
super(ID, (_adapter = new StringListAdapter(items)), true); 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() { @property override dstring text() {
return _edit.text; return _body.text;
} }
@property override Widget text(dstring txt) { @property override Widget text(dstring txt) {
@ -183,11 +169,9 @@ class ComboBox : ComboBoxBase {
if (idx >= 0) { if (idx >= 0) {
selectedItemIndex = idx; selectedItemIndex = idx;
} else { } else {
if (!readOnly) {
// not found // not found
_selectedItemIndex = -1; _selectedItemIndex = -1;
_edit.text = txt; _body.text = txt;
}
} }
return this; return this;
} }
@ -197,18 +181,76 @@ class ComboBox : ComboBoxBase {
if (idx >= 0) { if (idx >= 0) {
selectedItemIndex = idx; selectedItemIndex = idx;
} else { } else {
if (!readOnly) {
// not found // not found
_selectedItemIndex = -1; _selectedItemIndex = -1;
_edit.text = txt; _body.text = txt;
}
} }
return this; return this;
} }
override @property void selectedItemIndex(int index) { override @property void selectedItemIndex(int index) {
_selectedItemIndex = index; _body.text = _adapter.items[index];
_edit.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() { override protected Widget createSelectedItemWidget() {
@ -220,4 +262,11 @@ class ComboBox : ComboBoxBase {
return res; return res;
} }
override void init() {
super.init();
focusable = false;
_body.focusable = true;
}
} }