Skip to content

Commit

Permalink
Making FetchXML formats to any type (now LayoutXML also)
Browse files Browse the repository at this point in the history
  • Loading branch information
rappen committed Aug 6, 2022
1 parent b7820d9 commit b172167
Showing 1 changed file with 35 additions and 25 deletions.
60 changes: 35 additions & 25 deletions FetchXmlBuilder/DockControls/XmlContentControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ internal void SetContentType(ContentType contentType)
Text = contenttype.ToString().Replace("_", " ").Replace("CSharp", "C#");
TabText = Text;
var windowSettings = fxb.settings.ContentWindows.GetContentWindow(contenttype);
var allowedit = contenttype == ContentType.FetchXML;
var allowedit = contenttype == ContentType.FetchXML || contenttype == ContentType.LayoutXML;
var allowparse = contenttype == ContentType.QueryExpression;
var allowsql = contenttype == ContentType.SQL_Query;
chkLiveUpdate.Checked = allowedit && windowSettings.LiveUpdate;
Expand All @@ -70,7 +70,7 @@ internal void SetContentType(ContentType contentType)
panLiveUpdate.Visible = allowedit;
panOk.Visible = allowedit;
panFormatting.Visible = allowedit;
panExecute.Visible = allowedit;
panExecute.Visible = allowedit && contenttype == ContentType.FetchXML;
panParseQE.Visible = allowparse;
panSQL4CDS.Visible = allowsql;
panSQL4CDSInfo.Visible = allowsql;
Expand Down Expand Up @@ -202,13 +202,13 @@ private void FormatAsXML()
{
return;
}
if (!FetchIsPlain() && !FetchIsMini())
if (!XMLIsPlain() && !XMLIsMini())
{
if (FetchIsHtml())
if (XMLIsHtml())
{
txtXML.Text = HttpUtility.HtmlDecode(txtXML.Text.Trim());
}
else if (FetchIsEscaped())
else if (XMLIsEscaped())
{
txtXML.Text = Uri.UnescapeDataString(txtXML.Text.Trim());
}
Expand All @@ -217,7 +217,7 @@ private void FormatAsXML()
if (MessageBox.Show("Unrecognized encoding, unsure what to do with it.\n" +
"Currently FXB can handle htmlencoded and urlescaped strings.\n\n" +
"Would you like to submit an issue to FetchXML Builder to be able to handle this?",
"Decode FetchXML", MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
"Decode " + Text, MessageBoxButtons.YesNo, MessageBoxIcon.Exclamation) == DialogResult.Yes)
{
FetchXmlBuilder.OpenURL("https://github.com/rappen/FetchXMLBuilder/issues/new");
}
Expand All @@ -235,7 +235,7 @@ private void FormatAsHtml()
UpdateButtons();
return;
}
if (!FetchIsPlain())
if (!XMLIsPlain())
{
FormatAsXML();
}
Expand All @@ -245,7 +245,7 @@ private void FormatAsHtml()

private void FormatAsEsc()
{
if (!FetchIsPlain())
if (!XMLIsPlain())
{
FormatAsXML();
}
Expand All @@ -254,7 +254,7 @@ private void FormatAsEsc()

private void FormatAsMini()
{
if (!FetchIsPlain() && !FetchIsMini())
if (!XMLIsPlain() && !XMLIsMini())
{
FormatAsXML();
}
Expand Down Expand Up @@ -284,7 +284,7 @@ private void FormatAsMini()

private string GetCompactXml()
{
if (!FetchIsPlain())
if (!XMLIsPlain())
{
FormatAsXML();
}
Expand All @@ -301,15 +301,15 @@ private static string StripSpaces(string xml)

private XmlStyle GetStyle()
{
if (FetchIsMini())
if (XMLIsMini())
{
return XmlStyle.Mini;
}
if (FetchIsHtml())
if (XMLIsHtml())
{
return XmlStyle.Html;
}
if (FetchIsEscaped())
if (XMLIsEscaped())
{
return XmlStyle.Esc;
}
Expand Down Expand Up @@ -338,26 +338,36 @@ private void SetStyle(XmlStyle style)
}
}

private bool FetchIsPlain()
private bool XMLIsPlain()
{
var lines = txtXML.Text.Trim().Split('\n').Select(l => l.Trim()).ToList();
return lines.Count > 1 && lines[0].StartsWith("<fetch");
return lines.Count > 1 && lines[0].StartsWith("<" + ContentTypeStart(contenttype));
}

private bool FetchIsMini()
private bool XMLIsMini()
{
var lines = txtXML.Text.Trim().Split('\n').Select(l => l.Trim()).ToList();
return lines.Count == 1 && lines[0].StartsWith("<fetch");
return lines.Count == 1 && lines[0].StartsWith("<" + ContentTypeStart(contenttype));
}

private bool FetchIsHtml()
private bool XMLIsHtml()
{
return txtXML.Text.Trim().ToLowerInvariant().StartsWith("&lt;fetch");
return txtXML.Text.Trim().ToLowerInvariant().StartsWith("&lt;" + ContentTypeStart(contenttype));
}

private bool FetchIsEscaped()
private bool XMLIsEscaped()
{
return txtXML.Text.Trim().ToLowerInvariant().StartsWith("%3cfetch");
return txtXML.Text.Trim().ToLowerInvariant().StartsWith("%3c" + ContentTypeStart(contenttype));
}

private string ContentTypeStart(ContentType type)
{
switch (type)
{
case ContentType.FetchXML: return "fetch";
case ContentType.LayoutXML: return "grid";
default: return "dscxdsfdcvgfgwesdxdzsfdcbgf454";
}
}

private void txtXML_TextChanged(object sender, EventArgs e)
Expand All @@ -367,10 +377,10 @@ private void txtXML_TextChanged(object sender, EventArgs e)

private void UpdateButtons()
{
var plain = FetchIsPlain();
rbFormatEsc.Checked = FetchIsEscaped();
rbFormatHTML.Checked = FetchIsHtml();
rbFormatMini.Checked = FetchIsMini();
var plain = XMLIsPlain();
rbFormatEsc.Checked = XMLIsEscaped();
rbFormatHTML.Checked = XMLIsHtml();
rbFormatMini.Checked = XMLIsMini();
rbFormatXML.Checked = plain;
btnFormat.Enabled = plain;
btnExecute.Enabled = plain && !chkLiveUpdate.Checked;
Expand Down

0 comments on commit b172167

Please sign in to comment.