public void PopulateDropdown() { DropDownEvent dde = GetComponent <DropDownEvent>(); if (dde == null) { dde = gameObject.AddComponent <DropDownEvent>(); } dde.options = new System.Collections.Generic.List <ModalConfirmation.Entry> { new ModalConfirmation.Entry("No Sort", this, nameof(ColumnNoSort)), new ModalConfirmation.Entry("Sort Ascending", this, nameof(ColumnSortAscend)), new ModalConfirmation.Entry("Sort Descending", this, nameof(ColumnSortDescend)), new ModalConfirmation.Entry("Edit Column", this, nameof(ColumnEdit), false), //new ModalConfirmation.Entry("Remove Column", this, nameof(ColumnRemove), false), }; dde.PopulateDropdown(); }
public void SetExpectedEditType(object sampleValue) { Type sampleValueType = GetEditType(); if (sampleValueType == null) { // set to read only expectedValueType = null; DropDownEvent.PopulateDropdown(valueType, new string[] { "read only" }, this, null, 0, false); } else { if (sampleValueType != expectedValueType) { // set to specific type if (sampleValueType == typeof(object)) { sampleValueType = sampleValue.GetType(); int defaultChoice = -1; if (defaultChoice < 0 && CodeConvert.IsIntegral(sampleValueType)) { defaultChoice = defaultValueTypes.FindIndex(kvp => kvp.Key == typeof(long)); } if (defaultChoice < 0 && CodeConvert.IsNumeric(sampleValueType)) { defaultChoice = defaultValueTypes.FindIndex(kvp => kvp.Key == typeof(double)); } if (defaultChoice < 0) // && sampleValueType == typeof(string)) { { defaultChoice = defaultValueTypes.FindIndex(kvp => kvp.Key == typeof(string)); } List <string> options = defaultValueTypes.ConvertAll(kvp => kvp.Value); DropDownEvent.PopulateDropdown(valueType, options, this, SetEditType, defaultChoice, true); cHeader.columnSetting.type = defaultValueTypes[defaultChoice].Key; } else { DropDownEvent.PopulateDropdown(valueType, new string[] { sampleValueType.ToString() }, this, null, 0, false); cHeader.columnSetting.type = sampleValueType; } expectedValueType = sampleValueType; } } }
public void SetColumnHeader(ColumnHeader columnHeader, UnityDataSheet uds, int column) { // unregister listeners before values change, since values are about to change. ClearInputTextBoxListeners(); this.uds = uds; this.column = column; cHeader = columnHeader; TokenErrorLog errLog = new TokenErrorLog(); // setup script value Token t = cHeader.columnSetting.fieldToken; //string textA = t.GetAsSmallText(); //string textB = t.Stringify(); //string textC = t.StringifySmall(); //string textD = t.ToString(); string text = t.GetAsBasicToken(); //Show.Log("A: "+textA+"\nB:" + textB + "\nC:" + textC + "\nD:" + textD + "\nE:" + text); scriptValue.text = text; EventBind.On(scriptValue.onValueChanged, this, OnScriptValueEdit); // implicitly setup value types dropdown OnScriptValueEdit(text); // setup column label object labelText = cHeader.columnSetting.data.label.Resolve(errLog, uds.data); if (errLog.HasError()) { popup.Set("err", defaultValue.gameObject, errLog.GetErrorString() + Proc.Now); return; } columnLabel.text = labelText.StringifySmall(); EventBind.On(columnLabel.onValueChanged, this, OnLabelEdit); // setup column width columnWidth.text = cHeader.columnSetting.data.widthOfColumn.ToString(); EventBind.On(columnWidth.onValueChanged, this, OnColumnWidthEdit); // setup column index columnIndex.text = column.ToString(); EventBind.On(columnIndex.onValueChanged, this, OnIndexEdit); // setup column type List <ModalConfirmation.Entry> entries = columnTypes.ConvertAll(c => { string dropdownLabel; if (c.uiField != null && !string.IsNullOrEmpty(c.name)) { dropdownLabel = "/*" + c.name + "*/ " + c.uiField.name; } else { dropdownLabel = c.name; } return(new ModalConfirmation.Entry(dropdownLabel, null)); }); t = cHeader.columnSetting.data.columnUi; string fieldTypeText = t.ToString(); //cHeader.columnSetting.data.columnUi.GetAsBasicToken();//ResolveString(errLog, null); int currentIndex = columnTypes.FindIndex(c => fieldTypeText.StartsWith(c.uiField.name)) + 1; //Show.Log(currentIndex+" field " + fieldTypeText); DropDownEvent.PopulateDropdown(fieldType, entries, this, SetFieldType, currentIndex, true); if (currentIndex == 0) { DropDownEvent.SetCustomValue(fieldType.gameObject, fieldTypeText); } TMP_InputField elementUiInputField = fieldType.GetComponentInChildren <TMP_InputField>(); if (elementUiInputField != null) { elementUiInputField.onValueChanged.RemoveAllListeners(); //Show.Log("bind to "+elementUiInputField.name); EventBind.On(elementUiInputField.onValueChanged, this, OnSetFieldTypeText); } // setup default value object defVal = cHeader.columnSetting.defaultValue; if (defVal != null) { defaultValue.text = defVal.ToString(); } else { defaultValue.text = ""; } EventBind.On(defaultValue.onValueChanged, this, OnSetDefaultValue); // setup column destroy option EventBind.On(trashColumn.onClick, this, ColumnRemove); popup.Hide(); }