From 15226e85a4135296822751621eee1df8512fd66c Mon Sep 17 00:00:00 2001 From: Vadim Lopatin Date: Wed, 7 Jan 2015 12:50:58 +0300 Subject: [PATCH] i18n: fix fallback value; FileDialog: filetype combobox --- src/dlangui/core/i18n.d | 4 ++-- src/dlangui/dialogs/filedlg.d | 40 ++++++++++++++++++++++++++++++---- src/dlangui/widgets/combobox.d | 11 +++++++++- 3 files changed, 48 insertions(+), 7 deletions(-) diff --git a/src/dlangui/core/i18n.d b/src/dlangui/core/i18n.d index 42797219..239bbf0e 100644 --- a/src/dlangui/core/i18n.d +++ b/src/dlangui/core/i18n.d @@ -90,7 +90,7 @@ struct UIString { /** create string with resource id and raw value as fallback for missing translations */ this(string id, dstring fallbackValue) { _id = id; - _value = value; + _value = fallbackValue; } @@ -326,7 +326,7 @@ synchronized class UIStringTranslator { s = _fallback.get(id); if (s !is null) return s; - if (fallbackValue !is null) + if (fallbackValue.length > 0) return fallbackValue; return "UNTRANSLATED: "d ~ toUTF32(id); } diff --git a/src/dlangui/dialogs/filedlg.d b/src/dlangui/dialogs/filedlg.d index 08f30682..fe110644 100644 --- a/src/dlangui/dialogs/filedlg.d +++ b/src/dlangui/dialogs/filedlg.d @@ -34,6 +34,7 @@ import dlangui.widgets.layouts; import dlangui.widgets.grid; import dlangui.widgets.editors; import dlangui.widgets.menu; +import dlangui.widgets.combobox; import dlangui.platforms.common.platform; import dlangui.dialogs.dialog; @@ -68,10 +69,20 @@ 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; protected EditLine _edFilename; + protected ComboBox _cbFilters; protected StringGridWidget _fileList; protected VerticalLayout leftPanel; protected VerticalLayout rightPanel; @@ -143,7 +154,7 @@ class FileDialog : Dialog, CustomGridCellAdapter { } protected bool reopenDirectory() { - return true; + return openDirectory(_path, null); } protected bool openDirectory(string dir, string selectedItemPath) { @@ -330,11 +341,30 @@ class FileDialog : Dialog, CustomGridCellAdapter { _edPath.layoutWeight = 0; _edPath.onPathSelectionListener = &onPathSelected; + HorizontalLayout fnlayout = new HorizontalLayoutTest(); + fnlayout.layoutWidth(FILL_PARENT); _edFilename = new EditLine("filename"); _edFilename.layoutWidth(FILL_PARENT); - _edFilename.layoutWeight = 0; + //_edFilename.layoutWeight = 0; + fnlayout.addChild(_edFilename); + if (_filters.length) { + dstring[] filterLabels; + foreach(f; _filters) + filterLabels ~= f.label.value; + _cbFilters = new ComboBox("filter", filterLabels); + _cbFilters.selectedItemIndex = _filterIndex; + _cbFilters.onItemClickListener = delegate(Widget source, int itemIndex) { + _filterIndex = itemIndex; + reopenDirectory(); + return true; + }; + _cbFilters.layoutWidth(WRAP_CONTENT); + _cbFilters.layoutWeight(0); + //_cbFilters.backgroundColor = 0xFFC0FF; + fnlayout.addChild(_cbFilters); + //fnlayout.backgroundColor = 0xFFFFC0; + } - rightPanel.addChild(_edPath); _fileList = new StringGridWidget("files"); _fileList.layoutWidth(FILL_PARENT).layoutHeight(FILL_PARENT); _fileList.resize(4, 3); @@ -344,8 +374,10 @@ class FileDialog : Dialog, CustomGridCellAdapter { _fileList.setColTitle(3, "Modified"d); _fileList.showRowHeaders = false; _fileList.rowSelect = true; + + rightPanel.addChild(_edPath); rightPanel.addChild(_fileList); - rightPanel.addChild(_edFilename); + rightPanel.addChild(fnlayout); addChild(content); diff --git a/src/dlangui/widgets/combobox.d b/src/dlangui/widgets/combobox.d index ad8944ca..10416cd5 100644 --- a/src/dlangui/widgets/combobox.d +++ b/src/dlangui/widgets/combobox.d @@ -55,8 +55,16 @@ class ComboBoxBase : HorizontalLayout, OnClickHandler { } else { res = new Widget("COMBOBOX_BODY"); } - res.layoutWidth = FILL_PARENT; + 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; } @@ -80,6 +88,7 @@ class ComboBoxBase : HorizontalLayout, OnClickHandler { protected ImageButton createButton() { ImageButton res = new ImageButton("COMBOBOX_BUTTON", "scrollbar_btn_down"); + res.layoutWeight = 0; res.onClickListener = this; return res; }