Skip to content

Commit

Permalink
Possible to show both Friendly and LogicalName of Entities. Solves #1015
Browse files Browse the repository at this point in the history
  • Loading branch information
rappen committed Apr 20, 2024
1 parent 3c65edb commit 056daab
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 15 deletions.
29 changes: 23 additions & 6 deletions FetchXmlBuilder/Controls/entityControl.Designer.cs

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

36 changes: 27 additions & 9 deletions FetchXmlBuilder/Controls/entityControl.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
using Microsoft.Xrm.Sdk.Metadata;
using Rappen.XRM.Helpers.FetchXML;
using Rappen.XTB.FetchXmlBuilder.ControlsClasses;
using Rappen.XTB.FetchXmlBuilder.DockControls;
using Rappen.XTB.FetchXmlBuilder.Views;
using Rappen.XTB.Helpers.ControlItems;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
Expand All @@ -18,6 +18,7 @@ public entityControl() : this(new Dictionary<string, string>(), null, null)
public entityControl(Dictionary<string, string> collection, FetchXmlBuilder fetchXmlBuilder, TreeBuilderControl tree)
{
InitializeComponent();
chkIncludeLogicalName.Checked = fetchXmlBuilder.settings.UseFriendlyAndRawEntities;
InitializeFXB(collection, fetchXmlBuilder, tree, null);
}

Expand All @@ -27,7 +28,7 @@ protected override void PopulateControls()
var entities = fxb.GetDisplayEntities();
if (entities != null)
{
cmbEntity.Items.AddRange(entities.Select(e => new EntityItem(e)).ToArray());
cmbEntity.Items.AddRange(entities.Select(e => new EntityMetadataItem(e, fxb.settings.UseFriendlyNames, fxb.settings.UseFriendlyAndRawEntities)).ToArray());
}
}

Expand All @@ -40,7 +41,7 @@ protected override ControlValidationResult ValidateControl(Control control)
return new ControlValidationResult(ControlValidationLevel.Error, "Entity", ControlValidationMessage.IsRequired);
}

if (!(cmbEntity.SelectedItem is EntityItem) && fxb.entities != null)
if (!(cmbEntity.SelectedItem is EntityMetadataItem) && fxb.entities != null)
{
if (!fxb.entities.Any(e => e.LogicalName == cmbEntity.Text))
{
Expand All @@ -51,7 +52,7 @@ protected override ControlValidationResult ValidateControl(Control control)
return new ControlValidationResult(ControlValidationLevel.Info, "Entity", ControlValidationMessage.NotShowingNow);
}
}
if (fxb.entities != null && !cmbEntity.Items.OfType<EntityItem>().Any(i => i.ToString() == cmbEntity.Text))
if (fxb.entities != null && !cmbEntity.Items.OfType<EntityMetadataItem>().Any(i => i.ToString() == cmbEntity.Text))
{
return new ControlValidationResult(ControlValidationLevel.Warning, "Entity", ControlValidationMessage.IsRequired);
}
Expand All @@ -64,18 +65,18 @@ private void cmbEntity_SelectedIndexChanged(object sender, System.EventArgs e)
{
fxb.ShowMetadata(Metadata());
if (IsInitialized &&
cmbEntity.SelectedItem is EntityItem item &&
item.Meta?.LogicalName != fxb.dockControlBuilder.LayoutXML?.EntityMeta?.LogicalName)
cmbEntity.SelectedItem is EntityMetadataItem item &&
item.Metadata?.LogicalName != fxb.dockControlBuilder.LayoutXML?.EntityMeta?.LogicalName)
{
fxb.dockControlBuilder.LayoutXML = new LayoutXML(item.Meta, fxb);
fxb.dockControlBuilder.LayoutXML = new LayoutXML(item.Metadata, fxb);
}
}

public override MetadataBase Metadata()
{
if (cmbEntity.SelectedItem is EntityItem item)
if (cmbEntity.SelectedItem is EntityMetadataItem item)
{
return item.Meta;
return item.Metadata;
}
return fxb.GetEntity(cmbEntity.Text) ?? base.Metadata();
}
Expand All @@ -84,5 +85,22 @@ public override void Focus()
{
cmbEntity.Focus();
}

private void chkIncludeLogicalName_CheckedChanged(object sender, System.EventArgs e)
{
if (fxb == null)
{
return;
}
fxb.settings.UseFriendlyAndRawEntities = chkIncludeLogicalName.Checked;
SetIncLogName();
}

private void SetIncLogName()
{
SaveInternal(false);
PopulateControls();
ReFillControl(cmbEntity);
}
}
}

0 comments on commit 056daab

Please sign in to comment.