fix(cfe-borrow,form-edit,cfe-patch-method): fix borrowed form structure to match Configurator

- cfe-borrow: keep AutoCommandBar ChildItems (buttons) with CommandName=0
  instead of stripping them — Configurator expects buttons to be present
- form-edit: insert Events section after AutoCommandBar, not before —
  matches Configurator's element ordering
- cfe-patch-method(py): fix \r\r\n double line endings by using
  newline="" in open() calls

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Nick Shirokov
2026-03-10 21:40:16 +03:00
parent 8584021446
commit 84d078bd05
5 changed files with 28 additions and 13 deletions
@@ -500,12 +500,12 @@ function Borrow-Form {
# Get OuterXml and strip redundant namespace redeclarations (they're on root <Form>)
$nsStripPattern = '\s+xmlns(?::\w+)?="[^"]*"'
# AutoCommandBar: strip ChildItems (buttons), replace CommandName→0, Autofill→false
# AutoCommandBar: keep ChildItems (buttons with CommandName→0), Autofill→false
$autoCmdXml = ""
if ($srcAutoCmd) {
$autoCmdXml = $srcAutoCmd.OuterXml
$autoCmdXml = [regex]::Replace($autoCmdXml, $nsStripPattern, '')
$autoCmdXml = [regex]::Replace($autoCmdXml, '(?s)\s*<ChildItems>.*?</ChildItems>', '')
$autoCmdXml = [regex]::Replace($autoCmdXml, '<CommandName>[^<]*</CommandName>', '<CommandName>0</CommandName>')
$autoCmdXml = $autoCmdXml -replace '<Autofill>true</Autofill>', '<Autofill>false</Autofill>'
}
@@ -671,12 +671,12 @@ def main():
ns_strip_pattern = re.compile(r'\s+xmlns(?::\w+)?="[^"]*"')
# AutoCommandBar: strip ChildItems (buttons), replace CommandName→0, Autofill→false
# AutoCommandBar: keep ChildItems (buttons with CommandName→0), Autofill→false
auto_cmd_xml = ""
if src_auto_cmd is not None:
auto_cmd_xml = etree.tostring(src_auto_cmd, encoding="unicode")
auto_cmd_xml = ns_strip_pattern.sub("", auto_cmd_xml)
auto_cmd_xml = re.sub(r'\s*<ChildItems>.*?</ChildItems>', '', auto_cmd_xml, flags=re.DOTALL)
auto_cmd_xml = re.sub(r'<CommandName>[^<]*</CommandName>', '<CommandName>0</CommandName>', auto_cmd_xml)
auto_cmd_xml = auto_cmd_xml.replace('<Autofill>true</Autofill>', '<Autofill>false</Autofill>')
# ChildItems: copy full tree, clean up base-config references
@@ -205,7 +205,7 @@ def main():
if os.path.isfile(bsl_file):
# Append to existing file
with open(bsl_file, "r", encoding="utf-8-sig") as f:
with open(bsl_file, "r", encoding="utf-8-sig", newline="") as f:
existing = f.read()
separator = "\r\n"
@@ -213,11 +213,11 @@ def main():
separator = "\r\n\r\n"
new_content = existing + separator + bsl_text
with open(bsl_file, "w", encoding="utf-8-sig") as f:
with open(bsl_file, "w", encoding="utf-8-sig", newline="") as f:
f.write(new_content)
print("[OK] \u0414\u043e\u0431\u0430\u0432\u043b\u0435\u043d \u043f\u0435\u0440\u0435\u0445\u0432\u0430\u0442\u0447\u0438\u043a \u0432 \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u0444\u0430\u0439\u043b") # Добавлен перехватчик в существующий файл
else:
with open(bsl_file, "w", encoding="utf-8-sig") as f:
with open(bsl_file, "w", encoding="utf-8-sig", newline="") as f:
f.write(bsl_text)
print("[OK] \u0421\u043e\u0437\u0434\u0430\u043d \u0444\u0430\u0439\u043b \u043c\u043e\u0434\u0443\u043b\u044f") # Создан файл модуля
+12 -5
View File
@@ -1078,11 +1078,18 @@ if ($def.formEvents -and $def.formEvents.Count -gt 0) {
$eventsSection = $xmlDoc.CreateElement("Events", $formNs)
$insertAfter = $root.SelectSingleNode("f:AutoCommandBar", $nsMgr)
if ($insertAfter) {
$refNode = $insertAfter
$ws = $xmlDoc.CreateWhitespace("`r`n`t")
# Insert before the AutoCommandBar (Events come before AutoCommandBar in 1C)
$root.InsertBefore($ws, $refNode) | Out-Null
$root.InsertBefore($eventsSection, $refNode) | Out-Null
# Insert after AutoCommandBar (Events come after AutoCommandBar in 1C)
$ws1 = $xmlDoc.CreateWhitespace("`r`n`t")
$ws2 = $xmlDoc.CreateWhitespace("`r`n`t")
if ($insertAfter.NextSibling) {
$root.InsertBefore($ws1, $insertAfter.NextSibling) | Out-Null
$root.InsertBefore($eventsSection, $ws1) | Out-Null
$root.InsertBefore($ws2, $eventsSection) | Out-Null
} else {
$root.AppendChild($xmlDoc.CreateWhitespace("`r`n`t")) | Out-Null
$root.AppendChild($eventsSection) | Out-Null
$root.AppendChild($xmlDoc.CreateWhitespace("`r`n")) | Out-Null
}
} else {
$firstChild = $root.FirstChild
if ($firstChild) {
@@ -1162,7 +1162,15 @@ form_events_list = defn.get("formEvents") or []
if form_events_list:
events_section = root.find("f:Events", NS)
if events_section is None:
events_section = etree.SubElement(root, f"{{{FORM_NS}}}Events")
events_section = etree.Element(f"{{{FORM_NS}}}Events")
# Insert after AutoCommandBar (Events come after AutoCommandBar in 1C)
acb_node = root.find("f:AutoCommandBar", NS)
if acb_node is not None:
acb_idx = list(root).index(acb_node)
acb_node.tail = (acb_node.tail or "") + "\r\n\t"
root.insert(acb_idx + 1, events_section)
else:
root.append(events_section)
evt_child_indent = get_child_indent(events_section)
if not evt_child_indent: