Skip to content

Commit

Permalink
Reset Layout better now. #960
Browse files Browse the repository at this point in the history
  • Loading branch information
rappen committed Aug 17, 2023
1 parent 0d107f4 commit 04abf5e
Show file tree
Hide file tree
Showing 8 changed files with 33 additions and 16 deletions.
1 change: 1 addition & 0 deletions FetchXmlBuilder/DockControls/ResultGrid.Designer.cs

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

9 changes: 9 additions & 0 deletions FetchXmlBuilder/DockControls/ResultGrid.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ private void RefreshData()
crmGridView1.Refresh();
if (form.dockControlBuilder.LayoutXML == null)
{
ShowHiddenColumns();
crmGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.DisplayedCells);
}
else
Expand All @@ -157,6 +158,14 @@ private void RefreshData()
reloaded = false;
}

private void ShowHiddenColumns()
{
crmGridView1.Columns.Cast<DataGridViewColumn>()
.Where(c => !c.Name.StartsWith("#") && !c.Visible)
.ToList()
.ForEach(c => c.Visible = true);
}

internal void SetQueryIfChangesDesign()
{
var changed = queryinfo?.QuerySignature != form.dockControlBuilder?.GetTreeChecksum(null);
Expand Down
16 changes: 10 additions & 6 deletions FetchXmlBuilder/DockControls/TreeBuilderControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,11 +295,11 @@ internal QueryExpression GetQueryExpression(bool validate = true)
return query;
}

internal void Init(string fetchStr, string layoutStr, string action, bool validate)
internal void Init(string fetchStr, string layoutStr, bool layoutisfromview, string action, bool validate)
{
ParseXML(fetchStr, validate);
layoutxmloriginal = layoutStr;
ResetLayout();
layoutxmloriginal = layoutisfromview ? layoutStr : string.Empty;
ResetLayout(layoutStr);
fxb.UpdateLiveXML();
ClearChanged();
fxb.EnableControls(true);
Expand Down Expand Up @@ -342,10 +342,14 @@ internal void ParseXML(string xml, bool validate)
}
}

internal void ResetLayout()
internal void ResetLayout(string layoutxml = null)
{
LayoutXML = fxb.settings.Results.WorkWithLayout && !string.IsNullOrWhiteSpace(layoutxmloriginal)
? new LayoutXML(layoutxmloriginal, fxb) : null;
if (string.IsNullOrWhiteSpace(layoutxml))
{
layoutxml = layoutxmloriginal;
}
LayoutXML = fxb.settings.Results.WorkWithLayout && !string.IsNullOrWhiteSpace(layoutxml)
? new LayoutXML(layoutxml, fxb) : null;
}

internal void SetLayoutFromXML(string layoutxml)
Expand Down
8 changes: 4 additions & 4 deletions FetchXmlBuilder/FXBGui.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ private void OpenCWPFeed()
if (feed.Contains("cint_fetchxml"))
{
CWPFeed = feed.Contains("cint_id") ? feed["cint_id"].ToString() : feedid;
dockControlBuilder.Init(feed["cint_fetchxml"].ToString(), null, "open CWP feed", false);
dockControlBuilder.Init(feed["cint_fetchxml"].ToString(), null, false, "open CWP feed", false);
LogUse("OpenCWP");
}
EnableControls(true);
Expand All @@ -350,7 +350,7 @@ private void OpenFile()
FileName = ofd.FileName;
var fetchDoc = new XmlDocument();
fetchDoc.Load(ofd.FileName);
dockControlBuilder.Init(fetchDoc.OuterXml, null, "open file", true);
dockControlBuilder.Init(fetchDoc.OuterXml, null, false, "open file", true);
LogUse("OpenFile");
}
EnableControls(true);
Expand All @@ -369,7 +369,7 @@ private void OpenML()
if (mlselector.View.Contains("query") && !string.IsNullOrEmpty(mlselector.View["query"].ToString()))
{
DynML = mlselector.View;
dockControlBuilder.Init(DynML["query"].ToString(), null, "open marketing list", false);
dockControlBuilder.Init(DynML["query"].ToString(), null, false, "open marketing list", false);
LogUse("OpenML");
}
else
Expand Down Expand Up @@ -403,7 +403,7 @@ private void OpenView()
if (viewselector.View.Contains("fetchxml") && !string.IsNullOrEmpty(viewselector.View["fetchxml"].ToString()))
{
View = viewselector.View;
dockControlBuilder.Init(View["fetchxml"].ToString(), View["layoutxml"].ToString(), "open view", false);
dockControlBuilder.Init(View["fetchxml"].ToString(), View["layoutxml"].ToString(), true, "open view", false);
attributesChecksum = dockControlBuilder.GetAttributesSignature();
LogUse($"OpenView-{(View.LogicalName == "savedquery" ? "S" : "P")}");
}
Expand Down
4 changes: 3 additions & 1 deletion FetchXmlBuilder/FXBInterfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public void OnIncomingMessage(MessageBusEventArgs message)
callerArgs = message;
var fetchXml = string.Empty;
var layoutxml = string.Empty;
var fromview = false;
var requestedType = "FetchXML";
if (message.TargetArgument != null)
{
Expand All @@ -72,14 +73,15 @@ public void OnIncomingMessage(MessageBusEventArgs message)
View = GetViewById(id);
fetchXml = View?.GetAttributeValue<string>("fetchxml");
layoutxml = View?.GetAttributeValue<string>("layoutxml");
fromview = true;
}
else
{
fetchXml = strArgument;
}
}
}
dockControlBuilder.Init(fetchXml, layoutxml, $"called from {message.SourcePlugin}", false);
dockControlBuilder.Init(fetchXml, layoutxml, fromview, $"called from {message.SourcePlugin}", false);
attributesChecksum = dockControlBuilder.GetAttributesSignature();
tsbReturnToCaller.Text = callerArgs.SourcePlugin == URLcaller ? "FetchXML from an URL" : "Return FetchXML";
tsbReturnToCaller.Image =
Expand Down
2 changes: 1 addition & 1 deletion FetchXmlBuilder/FXBQueries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ internal void StringQueryExpressionToFetchXml(string query, QExStyleEnum style)
}
else if (completedargs.Result is string)
{
dockControlBuilder.Init(completedargs.Result.ToString().ToXml().OuterXml, null, $"parse {style}", true);
dockControlBuilder.Init(completedargs.Result.ToString().ToXml().OuterXml, null, false, $"parse {style}", true);
}
working = false;
}
Expand Down
8 changes: 4 additions & 4 deletions FetchXmlBuilder/FetchXmlBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ public void ApplyState(object state)
{
if (state is string fetch && fetch.ToLowerInvariant().StartsWith("<fetch"))
{
dockControlBuilder.Init(fetch, null, null, false);
dockControlBuilder.Init(fetch, null, false, null, false);
}
}

Expand Down Expand Up @@ -376,7 +376,7 @@ private void ApplySettings(bool reloadquery)
tsmiShowOData.Visible = settings.ShowOData2;
if (reloadquery && connectionsettings != null && !string.IsNullOrWhiteSpace(connectionsettings.FetchXML))
{
dockControlBuilder.Init(connectionsettings.FetchXML, connectionsettings.LayoutXML, "loaded from last session", false);
dockControlBuilder.Init(connectionsettings.FetchXML, connectionsettings.LayoutXML, false, "loaded from last session", false);
}
dockControlBuilder.lblQAExpander.GroupBoxSetState(null, settings.QueryOptions.ShowQuickActions);
var ass = Assembly.GetExecutingAssembly().GetName();
Expand Down Expand Up @@ -595,7 +595,7 @@ private void tsbNew_Click(object sender, EventArgs e)
return;
}
LogUse("New");
dockControlBuilder.Init(null, null, "new", false);
dockControlBuilder.Init(null, null, false, "new", false);
return;
}
var newconnection = sender == tsmiNewNewConnection;
Expand Down Expand Up @@ -752,7 +752,7 @@ private void tsmiRepoOpen_Click(object sender, EventArgs e)
{
if (sender is ToolStripMenuItem menu && menu.Tag is QueryDefinition query)
{
dockControlBuilder.Init(query.Fetch, null, $"open repo {query.Name}", false);
dockControlBuilder.Init(query.Fetch, null, false, $"open repo {query.Name}", false);
tsbRepo.Tag = query;
dockControlBuilder.SetFetchName($"Repo: {query.Name}");
}
Expand Down
1 change: 1 addition & 0 deletions FetchXmlBuilder/Views/LayoutXML.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ internal void MakeSureAllCellsExistForColumns(Dictionary<string, int> namewidths
{
Name = nw.Key,
Width = nw.Value,
IsHidden = nw.Value < 5,
Attribute = fxb.dockControlBuilder.GetAttributeNodeFromLayoutName(nw.Key)
}));
Cells.ToList().ForEach(c => c.Width = namewidths.ContainsKey(c.Name) ? namewidths[c.Name] : 0);
Expand Down

0 comments on commit 04abf5e

Please sign in to comment.