Skip to content

Commit

Permalink
Condition property node is a lot better now :)
Browse files Browse the repository at this point in the history
  • Loading branch information
rappen committed Apr 11, 2024
1 parent d391750 commit 5d413e6
Show file tree
Hide file tree
Showing 4 changed files with 141 additions and 74 deletions.
57 changes: 31 additions & 26 deletions FXBEditorUtils/ControlUtils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,36 +218,41 @@ public static void FillControl(Dictionary<string, string> collection, Control co
}
else if (control is ComboBox cmb)
{
object selitem = null;
foreach (var item in cmb.Items)
{
if (item is IComboBoxItem)
{
if (((IComboBoxItem)item).GetValue() == value)
{
selitem = item;
break;
}
}
}
if (selitem != null)
{
cmb.SelectedItem = selitem;
}
else if (value != null && cmb.Items.IndexOf(value) >= 0)
{
cmb.SelectedItem = value;
}
else
{
cmb.Text = value;
}
if (saveable != null)
SetComboBoxValue(cmb, value, saveable);
}
}
}

public static void SetComboBoxValue(ComboBox cmb, string value, IDefinitionSavable saveable = null)
{
object selitem = null;
foreach (var item in cmb.Items)
{
if (item is IComboBoxItem)
{
if (((IComboBoxItem)item).GetValue() == value)
{
new ComboBoxEventHandler(cmb, saveable).Attach();
selitem = item;
break;
}
}
}
if (selitem != null)
{
cmb.SelectedItem = selitem;
}
else if (value != null && cmb.Items.IndexOf(value) >= 0)
{
cmb.SelectedItem = value;
}
else
{
cmb.Text = value;
}
if (saveable != null)
{
new ComboBoxEventHandler(cmb, saveable).Attach();
}
}
}
}
40 changes: 30 additions & 10 deletions FetchXmlBuilder/Controls/conditionControl.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

103 changes: 71 additions & 32 deletions FetchXmlBuilder/Controls/conditionControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Runtime.InteropServices;
using System.ServiceModel;
using System.Windows.Forms;

Expand All @@ -22,6 +23,7 @@ public partial class conditionControl : FetchXmlElementControlBase
#region Private Properties

private bool valueOfSupported = false;
private bool valueOfEdited = false;

#endregion Private Properties

Expand All @@ -40,13 +42,7 @@ public conditionControl(TreeNode node, FetchXmlBuilder fetchXmlBuilder, TreeBuil
dlgLookup.Service = fetchXmlBuilder.Service;
rbUseLookup.Checked = fetchXmlBuilder.settings.UseLookup;
rbEnterGuid.Checked = !rbUseLookup.Checked;
var collect = (Dictionary<string, string>)node.Tag;
if (collect != null && collect.TryGetValue("valueof", out var valueof) && valueof.Split('.') is string[] valueofsplits && valueofsplits.Length == 2)
{
collect.Add("valueofalias", valueofsplits[0]);
collect["valueof"] = valueofsplits[1];
}
InitializeFXB(collect, fetchXmlBuilder, tree, node);
InitializeFXB(null, fetchXmlBuilder, tree, node);
EndInit();
RefreshAttributes();
EnableValueFields();
Expand Down Expand Up @@ -309,7 +305,11 @@ protected override Dictionary<string, string> GetAttributesCollection()
{
result.Remove("valueof");
}
if (panValueOf.Visible == true && result.ContainsKey("valueof") && !string.IsNullOrWhiteSpace(result["valueof"]))
if (result.TryGetValue("valueof", out var valueof) && string.IsNullOrWhiteSpace(valueof))
{
result.Remove("valueof");
}
if (result.ContainsKey("valueof"))
{
if (result.ContainsKey("value"))
{
Expand All @@ -325,16 +325,6 @@ protected override Dictionary<string, string> GetAttributesCollection()
result.Remove("value");
result.Remove("valueof");
}
if (result.TryGetValue("valueofalias", out var alias))
{
if (!string.IsNullOrWhiteSpace(alias) &&
result.TryGetValue("valueof", out var valueof) &&
!string.IsNullOrWhiteSpace(valueof))
{
result["valueof"] = alias + "." + valueof;
}
result.Remove("valueofalias");
}
return result;
}

Expand Down Expand Up @@ -369,10 +359,9 @@ private void EnableValueFields()
panValueOf.Enabled = string.IsNullOrEmpty(cmbValue.Text) || cmbValue.Text == Guid.Empty.ToString();
if (!panValueOf.Enabled)
{
cmbValueOf.Text = null;
cmbValueOfAlias.Text = null;
txtValueOf.Text = "";
}
cmbValue.Enabled = string.IsNullOrEmpty(cmbValueOf.Text);
cmbValue.Enabled = string.IsNullOrWhiteSpace(txtValueOf.Text);
if (!cmbValue.Enabled)
{
cmbValue.Text = null;
Expand Down Expand Up @@ -488,16 +477,12 @@ private void RefreshValueOf()
panValueOf.Visible = true;
cmbValueOf.Items.Clear();

var aliasyNode = cmbValueOfAlias.SelectedItem is EntityNode ? (EntityNode)cmbValueOfAlias.SelectedItem : null;
if (aliasyNode == null)
var aliasNode = cmbValueOfAlias.SelectedItem is EntityNode ? (EntityNode)cmbValueOfAlias.SelectedItem : null;
if (aliasNode == null)
{
aliasyNode = new EntityNode(Node.LocalEntityNode());
aliasNode = new EntityNode(Node.LocalEntityNode());
}
if (aliasyNode == null)
{
return;
}
var entityName = aliasyNode.EntityName;
var entityName = aliasNode.EntityName;
if (fxb.NeedToLoadEntity(entityName))
{
if (!fxb.working)
Expand All @@ -507,20 +492,19 @@ private void RefreshValueOf()
return;
}
BeginInit();
cmbValueOf.Items.Add("");
var attributes = fxb.GetDisplayAttributes(entityName);
cmbValueOf.Items.AddRange(attributes?
.Select(a => new AttributeItem(a, fxb.settings.ShowAttributeTypes))
.Where(a => TypeIsCloseEnough(a.Metadata, attribute.Metadata))
.ToArray());
// RefreshFill now that attributes are loaded
ReFillControl(cmbValueOf);
EndInit();
}
else
{
cmbValueOf.Text = "";
}
//ReFillControl(cmbValueOf);
ControlUtils.SetComboBoxValue(cmbValueOf, GetValueOf(txtValueOf.Text));
}

private bool TypeIsCloseEnough(AttributeMetadata comparer, AttributeMetadata target)
Expand Down Expand Up @@ -735,6 +719,50 @@ enummeta.OptionSet is OptionSetMetadata options &&
}
}

private void SetValueOfFromUI()
{
if (!IsInitialized)
{
return;
}
valueOfEdited = true;
var valueof = ControlUtils.GetValueFromControl(cmbValueOf);
var valueofalias = string.IsNullOrWhiteSpace(valueof) ? string.Empty : ControlUtils.GetValueFromControl(cmbValueOfAlias);
txtValueOf.Text = (string.IsNullOrWhiteSpace(valueofalias) ? "" : valueofalias + ".") + valueof;
valueOfEdited = false;
}

private void SetValueOfControlsFromFetchXml()
{
if (valueOfEdited)
{
return;
}
var valueof = txtValueOf.Text;
ControlUtils.SetComboBoxValue(cmbValueOfAlias, GetValueOfAlias(valueof));
ControlUtils.SetComboBoxValue(cmbValueOf, GetValueOf(valueof));
}

private string GetValueOfAlias(string valueof)
{
if (valueof.Contains("."))
{
var splits = valueof.Split('.');
return splits[0];
}
return string.Empty;
}

private string GetValueOf(string valueof)
{
if (valueof.Contains("."))
{
var splits = valueof.Split('.');
return splits[1];
}
return valueof;
}

#endregion Private Methods

#region Private Event Handlers
Expand Down Expand Up @@ -822,9 +850,20 @@ private void cmbValue_KeyPress(object sender, KeyPressEventArgs e)
}
}

private void txtValueOf_TextChanged(object sender, EventArgs e)
{
SetValueOfControlsFromFetchXml();
}

private void cmbValueOfAlias_SelectedIndexChanged(object sender, EventArgs e)
{
RefreshValueOf();
SetValueOfFromUI();
}

private void cmbValueOf_Changed(object sender, EventArgs e)
{
SetValueOfFromUI();
}

#endregion Private Event Handlers
Expand Down
Loading

0 comments on commit 5d413e6

Please sign in to comment.