Skip to content

Commit

Permalink
Truly two-way-editing of the layouts
Browse files Browse the repository at this point in the history
  • Loading branch information
rappen committed Aug 6, 2022
1 parent b172167 commit 4a8073d
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 25 deletions.
1 change: 1 addition & 0 deletions FetchXmlBuilder/Controls/attributeControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ private void UpdateCellFromUI()
grpLayout.Visible = cell != null;
trkLayoutWidth.Enabled = chkLayoutVisible.Checked;
UpdateCellUI();
fxb.dockControlGrid?.SetLayoutToGrid();
}

private void UpdateCellUI()
Expand Down
27 changes: 17 additions & 10 deletions FetchXmlBuilder/DockControls/ResultGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,16 +95,7 @@ private void RefreshData()
}
else
{
foreach (var cell in form.dockControlBuilder.LayoutXML.Cells)
{
var col = crmGridView1.Columns[cell.Name];
if (col != null)
{
col.DisplayIndex = cell.DisplayIndex;
col.Width = cell.Width;
col.Visible = cell.Width > 0;
}
}
SetLayoutToGrid();
}
crmGridView1.Columns.Cast<DataGridViewColumn>()
.Where(c => c.Width > form.settings.Results.MaxColumnWidth)
Expand All @@ -115,6 +106,22 @@ private void RefreshData()
reloaded = false;
}

internal void SetLayoutToGrid()
{
reloaded = true;
foreach (var cell in form.dockControlBuilder.LayoutXML.Cells)
{
var col = crmGridView1.Columns[cell.Name];
if (col != null)
{
col.DisplayIndex = cell.DisplayIndex;
col.Width = cell.Width;
col.Visible = cell.Width > 0;
}
}
reloaded = false;
}

private void GetLayoutFromGrid()
{
if (!form.settings.Results.WorkWithLayout || !(form.dockControlBuilder.GetRootEntityMetadata() is EntityMetadata entity))
Expand Down
9 changes: 9 additions & 0 deletions FetchXmlBuilder/DockControls/TreeBuilderControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,15 @@ internal void ResetLayout()
? new LayoutXML(layoutxmloriginal, GetRootEntity(), fxb) : null;
}

internal void SetLayoutFromXML(string layoutxml)
{
LayoutXML = new LayoutXML(layoutxml, GetRootEntity(), fxb);
if (GetCurrentControl() is attributeControl attrcontrol)
{
attrcontrol.UpdateUIFromCell();
}
}

internal void RecordHistory(string action)
{
var fetch = GetFetchString(false, false);
Expand Down
14 changes: 12 additions & 2 deletions FetchXmlBuilder/DockControls/XmlContentControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -772,9 +772,19 @@ private void UpdateQueryBuild(string action, bool live)
doc.LoadXml(txtXML.Text);
if (doc.OuterXml != liveUpdateXml)
{
fxb.dockControlBuilder.ParseXML(txtXML.Text, false);
switch (contenttype)
{
case ContentType.FetchXML:
fxb.dockControlBuilder.ParseXML(txtXML.Text, false);
fxb.historyMgr.RecordHistory(action, txtXML.Text);
break;

case ContentType.LayoutXML:
fxb.dockControlBuilder.SetLayoutFromXML(txtXML.Text);
fxb.dockControlGrid?.SetLayoutToGrid();
break;
}
fxb.UpdateLiveXML(live);
fxb.historyMgr.RecordHistory(action, txtXML.Text);
}
liveUpdateXml = doc.OuterXml;
}
Expand Down
15 changes: 3 additions & 12 deletions FetchXmlBuilder/FXBGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ public partial class FetchXmlBuilder : PluginControlBase
internal static bool friendlyNames = false;
internal TreeBuilderControl dockControlBuilder;
internal XmlContentControl dockControlLayoutXml;
internal ResultGrid dockControlGrid;
internal HistoryManager historyMgr = new HistoryManager();
internal bool historyisavailable = true;
private string cwpfeed;
private XmlContentControl dockControlFetchResult;
private XmlContentControl dockControlFetchXml;
private XmlContentControl dockControlFetchXmlCs;
private XmlContentControl dockControlFetchXmlJs;
private ResultGrid dockControlGrid;
private ODataControl dockControlOData2;
private ODataControl dockControlOData4;
private FlowListControl dockControlFlowList;
Expand Down Expand Up @@ -115,20 +115,11 @@ internal void EnableDisableHistoryButtons()

internal void UpdateLiveXML(bool preventxmlupdate = false)
{
var fetch = string.Empty;
string GetFetch()
{
if (string.IsNullOrWhiteSpace(fetch))
{
fetch = dockControlBuilder.GetFetchString(true, false);
}
return fetch;
}
if (!preventxmlupdate && dockControlFetchXml?.Visible == true)
{
dockControlFetchXml.UpdateXML(GetFetch());
dockControlFetchXml.UpdateXML(dockControlBuilder.GetFetchString(true, false));
}
if (dockControlLayoutXml?.Visible == true)
if (!preventxmlupdate && dockControlLayoutXml?.Visible == true)
{
dockControlBuilder.LayoutXML?.MakeSureAllCellsExistForAttributes();
dockControlLayoutXml.UpdateXML(dockControlBuilder.LayoutXML?.ToXML());
Expand Down
2 changes: 1 addition & 1 deletion FetchXmlBuilder/Views/LayoutXML.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public LayoutXML(string layoutxmlstr, TreeNode entity, FetchXmlBuilder fxb)
.Select(c => new Cell(this, c)).ToList();
}
}
if (string.IsNullOrEmpty(EntityName))
if (string.IsNullOrEmpty(EntityName) && entity != null)
{
EntityName = entity.Value("name");
}
Expand Down

0 comments on commit 4a8073d

Please sign in to comment.