Skip to content

Commit 5d413e6

Browse files
committed
Condition property node is a lot better now :)
1 parent d391750 commit 5d413e6

File tree

4 files changed

+141
-74
lines changed

4 files changed

+141
-74
lines changed

FXBEditorUtils/ControlUtils.cs

Lines changed: 31 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -218,36 +218,41 @@ public static void FillControl(Dictionary<string, string> collection, Control co
218218
}
219219
else if (control is ComboBox cmb)
220220
{
221-
object selitem = null;
222-
foreach (var item in cmb.Items)
223-
{
224-
if (item is IComboBoxItem)
225-
{
226-
if (((IComboBoxItem)item).GetValue() == value)
227-
{
228-
selitem = item;
229-
break;
230-
}
231-
}
232-
}
233-
if (selitem != null)
234-
{
235-
cmb.SelectedItem = selitem;
236-
}
237-
else if (value != null && cmb.Items.IndexOf(value) >= 0)
238-
{
239-
cmb.SelectedItem = value;
240-
}
241-
else
242-
{
243-
cmb.Text = value;
244-
}
245-
if (saveable != null)
221+
SetComboBoxValue(cmb, value, saveable);
222+
}
223+
}
224+
}
225+
226+
public static void SetComboBoxValue(ComboBox cmb, string value, IDefinitionSavable saveable = null)
227+
{
228+
object selitem = null;
229+
foreach (var item in cmb.Items)
230+
{
231+
if (item is IComboBoxItem)
232+
{
233+
if (((IComboBoxItem)item).GetValue() == value)
246234
{
247-
new ComboBoxEventHandler(cmb, saveable).Attach();
235+
selitem = item;
236+
break;
248237
}
249238
}
250239
}
240+
if (selitem != null)
241+
{
242+
cmb.SelectedItem = selitem;
243+
}
244+
else if (value != null && cmb.Items.IndexOf(value) >= 0)
245+
{
246+
cmb.SelectedItem = value;
247+
}
248+
else
249+
{
250+
cmb.Text = value;
251+
}
252+
if (saveable != null)
253+
{
254+
new ComboBoxEventHandler(cmb, saveable).Attach();
255+
}
251256
}
252257
}
253258
}

FetchXmlBuilder/Controls/conditionControl.Designer.cs

Lines changed: 30 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

FetchXmlBuilder/Controls/conditionControl.cs

Lines changed: 71 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
using System.Diagnostics;
1313
using System.Globalization;
1414
using System.Linq;
15+
using System.Runtime.InteropServices;
1516
using System.ServiceModel;
1617
using System.Windows.Forms;
1718

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

2425
private bool valueOfSupported = false;
26+
private bool valueOfEdited = false;
2527

2628
#endregion Private Properties
2729

@@ -40,13 +42,7 @@ public conditionControl(TreeNode node, FetchXmlBuilder fetchXmlBuilder, TreeBuil
4042
dlgLookup.Service = fetchXmlBuilder.Service;
4143
rbUseLookup.Checked = fetchXmlBuilder.settings.UseLookup;
4244
rbEnterGuid.Checked = !rbUseLookup.Checked;
43-
var collect = (Dictionary<string, string>)node.Tag;
44-
if (collect != null && collect.TryGetValue("valueof", out var valueof) && valueof.Split('.') is string[] valueofsplits && valueofsplits.Length == 2)
45-
{
46-
collect.Add("valueofalias", valueofsplits[0]);
47-
collect["valueof"] = valueofsplits[1];
48-
}
49-
InitializeFXB(collect, fetchXmlBuilder, tree, node);
45+
InitializeFXB(null, fetchXmlBuilder, tree, node);
5046
EndInit();
5147
RefreshAttributes();
5248
EnableValueFields();
@@ -309,7 +305,11 @@ protected override Dictionary<string, string> GetAttributesCollection()
309305
{
310306
result.Remove("valueof");
311307
}
312-
if (panValueOf.Visible == true && result.ContainsKey("valueof") && !string.IsNullOrWhiteSpace(result["valueof"]))
308+
if (result.TryGetValue("valueof", out var valueof) && string.IsNullOrWhiteSpace(valueof))
309+
{
310+
result.Remove("valueof");
311+
}
312+
if (result.ContainsKey("valueof"))
313313
{
314314
if (result.ContainsKey("value"))
315315
{
@@ -325,16 +325,6 @@ protected override Dictionary<string, string> GetAttributesCollection()
325325
result.Remove("value");
326326
result.Remove("valueof");
327327
}
328-
if (result.TryGetValue("valueofalias", out var alias))
329-
{
330-
if (!string.IsNullOrWhiteSpace(alias) &&
331-
result.TryGetValue("valueof", out var valueof) &&
332-
!string.IsNullOrWhiteSpace(valueof))
333-
{
334-
result["valueof"] = alias + "." + valueof;
335-
}
336-
result.Remove("valueofalias");
337-
}
338328
return result;
339329
}
340330

@@ -369,10 +359,9 @@ private void EnableValueFields()
369359
panValueOf.Enabled = string.IsNullOrEmpty(cmbValue.Text) || cmbValue.Text == Guid.Empty.ToString();
370360
if (!panValueOf.Enabled)
371361
{
372-
cmbValueOf.Text = null;
373-
cmbValueOfAlias.Text = null;
362+
txtValueOf.Text = "";
374363
}
375-
cmbValue.Enabled = string.IsNullOrEmpty(cmbValueOf.Text);
364+
cmbValue.Enabled = string.IsNullOrWhiteSpace(txtValueOf.Text);
376365
if (!cmbValue.Enabled)
377366
{
378367
cmbValue.Text = null;
@@ -488,16 +477,12 @@ private void RefreshValueOf()
488477
panValueOf.Visible = true;
489478
cmbValueOf.Items.Clear();
490479

491-
var aliasyNode = cmbValueOfAlias.SelectedItem is EntityNode ? (EntityNode)cmbValueOfAlias.SelectedItem : null;
492-
if (aliasyNode == null)
480+
var aliasNode = cmbValueOfAlias.SelectedItem is EntityNode ? (EntityNode)cmbValueOfAlias.SelectedItem : null;
481+
if (aliasNode == null)
493482
{
494-
aliasyNode = new EntityNode(Node.LocalEntityNode());
483+
aliasNode = new EntityNode(Node.LocalEntityNode());
495484
}
496-
if (aliasyNode == null)
497-
{
498-
return;
499-
}
500-
var entityName = aliasyNode.EntityName;
485+
var entityName = aliasNode.EntityName;
501486
if (fxb.NeedToLoadEntity(entityName))
502487
{
503488
if (!fxb.working)
@@ -507,20 +492,19 @@ private void RefreshValueOf()
507492
return;
508493
}
509494
BeginInit();
495+
cmbValueOf.Items.Add("");
510496
var attributes = fxb.GetDisplayAttributes(entityName);
511497
cmbValueOf.Items.AddRange(attributes?
512498
.Select(a => new AttributeItem(a, fxb.settings.ShowAttributeTypes))
513499
.Where(a => TypeIsCloseEnough(a.Metadata, attribute.Metadata))
514500
.ToArray());
515-
// RefreshFill now that attributes are loaded
516-
ReFillControl(cmbValueOf);
517501
EndInit();
518502
}
519503
else
520504
{
521505
cmbValueOf.Text = "";
522506
}
523-
//ReFillControl(cmbValueOf);
507+
ControlUtils.SetComboBoxValue(cmbValueOf, GetValueOf(txtValueOf.Text));
524508
}
525509

526510
private bool TypeIsCloseEnough(AttributeMetadata comparer, AttributeMetadata target)
@@ -735,6 +719,50 @@ enummeta.OptionSet is OptionSetMetadata options &&
735719
}
736720
}
737721

722+
private void SetValueOfFromUI()
723+
{
724+
if (!IsInitialized)
725+
{
726+
return;
727+
}
728+
valueOfEdited = true;
729+
var valueof = ControlUtils.GetValueFromControl(cmbValueOf);
730+
var valueofalias = string.IsNullOrWhiteSpace(valueof) ? string.Empty : ControlUtils.GetValueFromControl(cmbValueOfAlias);
731+
txtValueOf.Text = (string.IsNullOrWhiteSpace(valueofalias) ? "" : valueofalias + ".") + valueof;
732+
valueOfEdited = false;
733+
}
734+
735+
private void SetValueOfControlsFromFetchXml()
736+
{
737+
if (valueOfEdited)
738+
{
739+
return;
740+
}
741+
var valueof = txtValueOf.Text;
742+
ControlUtils.SetComboBoxValue(cmbValueOfAlias, GetValueOfAlias(valueof));
743+
ControlUtils.SetComboBoxValue(cmbValueOf, GetValueOf(valueof));
744+
}
745+
746+
private string GetValueOfAlias(string valueof)
747+
{
748+
if (valueof.Contains("."))
749+
{
750+
var splits = valueof.Split('.');
751+
return splits[0];
752+
}
753+
return string.Empty;
754+
}
755+
756+
private string GetValueOf(string valueof)
757+
{
758+
if (valueof.Contains("."))
759+
{
760+
var splits = valueof.Split('.');
761+
return splits[1];
762+
}
763+
return valueof;
764+
}
765+
738766
#endregion Private Methods
739767

740768
#region Private Event Handlers
@@ -822,9 +850,20 @@ private void cmbValue_KeyPress(object sender, KeyPressEventArgs e)
822850
}
823851
}
824852

853+
private void txtValueOf_TextChanged(object sender, EventArgs e)
854+
{
855+
SetValueOfControlsFromFetchXml();
856+
}
857+
825858
private void cmbValueOfAlias_SelectedIndexChanged(object sender, EventArgs e)
826859
{
827860
RefreshValueOf();
861+
SetValueOfFromUI();
862+
}
863+
864+
private void cmbValueOf_Changed(object sender, EventArgs e)
865+
{
866+
SetValueOfFromUI();
828867
}
829868

830869
#endregion Private Event Handlers

0 commit comments

Comments
 (0)