基线:全量源码首提(D1 版本控制落地,含第一轮优化 B1-B4/A1/A4/缩放修复)
This commit is contained in:
@@ -0,0 +1,213 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
"""
|
||||
精简 Designer.cs:只保留设计器需要的最小属性集,
|
||||
去掉旧工具写入的全量属性垃圾(几十行默认值/无效值),
|
||||
解决 SharpDevelop 设计时 ArgumentOutOfRangeException。
|
||||
"""
|
||||
import io
|
||||
import re
|
||||
import os
|
||||
import glob
|
||||
|
||||
BASE = r"C:\Users\099978\Documents\SharpDevelop Projects\成套报价软件\成套报价软件"
|
||||
|
||||
# 允许保留的属性行前缀模式
|
||||
KEEP_PROPS = [
|
||||
# ★ 控件创建语句(new) — 绝对不能删
|
||||
r"this\.\w+\s*=\s*new",
|
||||
r"\w+\s*=\s*new",
|
||||
r"new\s+System\.Windows\.Forms\.",
|
||||
r"new\s+Smart\.CustomComponents\.",
|
||||
r"new\s+Zuby\.ADGV\.",
|
||||
r"new\s+CJZZ\.Controls\.",
|
||||
r"new\s+System\.Drawing\.",
|
||||
r"new\s+System\.ComponentModel\.",
|
||||
# 列字段创建
|
||||
r"dataGridViewTextBoxColumn\d+\s*=",
|
||||
r"dataGridViewCheckBoxColumn\d+\s*=",
|
||||
r"dataGridViewComboBoxColumn\d+\s*=",
|
||||
r"System\.Windows\.Forms\.DataGridView\w+Column",
|
||||
r"this\.\w+\.Name\s*=",
|
||||
r"this\.\w+\.Size\s*=",
|
||||
r"this\.\w+\.Location\s*=",
|
||||
r"this\.\w+\.Text\s*=",
|
||||
r"this\.\w+\.TabIndex\s*=",
|
||||
r"this\.\w+\.Dock\s*=",
|
||||
r"this\.\w+\.Anchor\s*=",
|
||||
r"this\.\w+\.Font\s*=",
|
||||
r"this\.\w+\.BackColor\s*=",
|
||||
r"this\.\w+\.ForeColor\s*=",
|
||||
r"this\.\w+\.Enabled\s*=",
|
||||
r"this\.\w+\.Visible\s*=",
|
||||
r"this\.\w+\.ReadOnly\s*=",
|
||||
r"this\.\w+\.Multiline\s*=",
|
||||
r"this\.\w+\.WordWrap\s*=",
|
||||
r"this\.\w+\.ScrollBars\s*=",
|
||||
r"this\.\w+\.SelectedIndex\s*=\s*[0-9]", # 只保留>=0的
|
||||
r"this\.\w+\.Items\.Add",
|
||||
r"this\.\w+\.Items\.AddRange",
|
||||
r"this\.\w+\.Items\.Clear",
|
||||
r"this\.\w+\.Columns\.Add",
|
||||
r"this\.\w+\.Columns\.AddRange",
|
||||
r"this\.\w+\.Rows\.Add",
|
||||
r"this\.\w+\.Controls\.Add",
|
||||
r"this\.\w+\.Controls\.AddRange",
|
||||
r"this\.\w+\.Controls\.Clear",
|
||||
r"this\.\w+\.HeaderText\s*=",
|
||||
r"this\.\w+\.Width\s*=",
|
||||
r"this\.\w+\.DataPropertyName\s*=",
|
||||
r"this\.\w+\.SortMode\s*=",
|
||||
r"this\.\w+\.ReadOnly\s*=",
|
||||
r"this\.\w+\.Frozen\s*=",
|
||||
r"this\.\w+\.AutoSizeMode\s*=\s*System\.Windows\.Forms\.DataGridViewAutoSizeMode",
|
||||
r"this\.\w+\.Visible\s*=",
|
||||
r"this\.\w+\.DefaultCellStyle\.",
|
||||
r"this\.\w+\.UseVisualStyleBackColor\s*=",
|
||||
r"this\.\w+\.Checked\s*=",
|
||||
r"this\.\w+\.CheckState\s*=",
|
||||
r"this\.\w+\.CheckOnClick\s*=",
|
||||
r"this\.\w+\.Style\s*=\s*Smart\.CustomComponents", # Smart 控件样式枚举
|
||||
r"this\.\w+\.Radius\s*=",
|
||||
r"this\.\w+\.PlaceholderText\s*=",
|
||||
r"this\.\w+\.MultiSelect\s*=",
|
||||
r"this\.\w+\.Searchable\s*=",
|
||||
r"this\.\w+\.AllowCustomInput\s*=",
|
||||
r"this\.\w+\.Flat\s*=",
|
||||
r"this\.\w+\.AllowUserToAddRows\s*=",
|
||||
r"this\.\w+\.AllowUserToDeleteRows\s*=",
|
||||
r"this\.\w+\.AllowUserToOrderColumns\s*=",
|
||||
r"this\.\w+\.AllowUserToResizeColumns\s*=",
|
||||
r"this\.\w+\.AllowUserToResizeRows\s*=",
|
||||
r"this\.\w+\.AutoSize\b",
|
||||
r"this\.\w+\.AutoScroll\s*=",
|
||||
r"this\.\w+\.RowHeadersVisible\s*=",
|
||||
r"this\.\w+\.ColumnHeadersVisible\s*=",
|
||||
r"this\.\w+\.SelectionMode\s*=",
|
||||
r"this\.\w+\.EditMode\s*=",
|
||||
r"this\.\w+\.BackgroundColor\s*=",
|
||||
r"this\.\w+\.EnableHeadersVisualStyles\s*=",
|
||||
r"this\.\w+\.EnableExcelStyleSelection\s*=",
|
||||
r"this\.\w+\.RowHeadersWidth\s*=",
|
||||
r"this\.\w+\.ColumnHeadersHeight\s*=",
|
||||
r"this\.\w+\.RowHeadersWidthSizeMode\s*=",
|
||||
r"this\.\w+\.ColumnHeadersHeightSizeMode\s*=",
|
||||
r"this\.\w+\.BorderStyle\s*=",
|
||||
r"this\.\w+\.CellBorderStyle\s*=",
|
||||
r"this\.\w+\.GridColor\s*=",
|
||||
r"this\.\w+\.ClipboardCopyMode\s*=",
|
||||
r"this\.\w+\.MultiSelect\s*=",
|
||||
r"this\.\w+\.StandardTab\s*=",
|
||||
r"this\.\w+\.VirtualMode\s*=",
|
||||
r"this\.\w+\.ImageKey\s*=",
|
||||
r"this\.\w+\.ImageScaling\s*=",
|
||||
r"this\.\w+\.DisplayStyle\s*=",
|
||||
r"this\.\w+\.TextAlign\s*=\s*System\.Drawing", # 只留 ContentAlignment
|
||||
r"this\.\w+\.TextDirection\s*=",
|
||||
r"this\.\w+\.ToolTipText\s*=",
|
||||
r"this\.\w+\.AutoSize\b.*=\s*true",
|
||||
# 窗体自身属性
|
||||
r"this\.AutoScaleDimensions\s*=",
|
||||
r"this\.AutoScaleMode\s*=",
|
||||
r"this\.ClientSize\s*=",
|
||||
r"this\.Name\s*=",
|
||||
r"this\.Text\s*=",
|
||||
r"this\.FormBorderStyle\s*=",
|
||||
r"this\.StartPosition\s*=",
|
||||
r"this\.WindowState\s*=",
|
||||
r"this\.MaximizeBox\s*=",
|
||||
r"this\.MinimizeBox\s*=",
|
||||
r"this\.ControlBox\s*=",
|
||||
r"this\.ShowInTaskbar\s*=",
|
||||
r"this\.TopMost\s*=",
|
||||
r"this\.Opacity\s*=",
|
||||
r"this\.ShowIcon\s*=",
|
||||
r"this\.Icon\s*=",
|
||||
r"this\.KeyPreview\s*=",
|
||||
r"this\.AutoValidate\s*=",
|
||||
r"this\.Padding\s*=\s*new\s+System\.Windows\.Forms\.Padding\([1-9]", # 只留非零Padding
|
||||
r"this\.MainMenuStrip\s*=",
|
||||
# 控件本身(非 this)的属性
|
||||
r"\w+\.Name\s*=",
|
||||
r"\w+\.HeaderText\s*=",
|
||||
r"\w+\.Width\s*=",
|
||||
r"\w+\.DataPropertyName\s*=",
|
||||
r"\w+\.SortMode\s*=",
|
||||
r"\w+\.ReadOnly\s*=",
|
||||
r"\w+\.Frozen\s*=",
|
||||
r"\w+\.Visible\s*=",
|
||||
r"\w+\.AutoSizeMode\s*=",
|
||||
r"\w+\.DefaultCellStyle\.",
|
||||
]
|
||||
|
||||
# 编译为正则列表
|
||||
KEEP_RE = [re.compile(p) for p in KEEP_PROPS]
|
||||
|
||||
# 绝对排除的(即使匹配 KEEP 也要删掉——已知导致设计器崩溃的)
|
||||
HARD_KILL = [
|
||||
r"this\.\w+\.Padding\s*=\s*new\s+System\.Windows\.Forms\.Padding\(0,\s*0,\s*0,\s*0\)",
|
||||
r"this\.\w+\.SelectedIndex\s*=\s*-1",
|
||||
r"this\.\w+\.DropDownWidth\s*=\s*0",
|
||||
r"this\.\w+\.DropDownHeight\s*=\s*0",
|
||||
r"this\.\w+\.MaximumSize\s*=\s*new\s+System\.Drawing\.Size\(0,\s*0\)",
|
||||
r"this\.\w+\.MinimumSize\s*=\s*new\s+System\.Drawing\.Size\(0,\s*0\)",
|
||||
r"this\.\w+\.Margin\s*=", # Margin 对设计器布局影响大,删掉
|
||||
]
|
||||
HARD_KILL_RE = [re.compile(p) for p in HARD_KILL]
|
||||
|
||||
|
||||
def should_keep(line):
|
||||
st = line.strip()
|
||||
if not st or st.startswith("//") or st.startswith("#"):
|
||||
return True # 注释空行保留
|
||||
# 不是赋值语句的直接保留(如 new, SuspendLayout, Controls.Add 等)
|
||||
if "=" not in st and ".Add" not in st and ".Clear" not in st:
|
||||
return True
|
||||
# 硬排除
|
||||
for kr in HARD_KILL_RE:
|
||||
if kr.search(st):
|
||||
return False
|
||||
# 白名单
|
||||
for kr in KEEP_RE:
|
||||
if kr.search(st):
|
||||
return True
|
||||
# 其他赋值语句 → 删掉
|
||||
if re.match(r"this\.\w+\.\w+\s*=", st) or re.match(r"\w+\.\w+\s*=", st):
|
||||
return False
|
||||
return True # 非赋值行保留
|
||||
|
||||
|
||||
def clean_file(path):
|
||||
s = io.open(path, encoding="utf-8-sig").read()
|
||||
lines = s.split("\n")
|
||||
out = []
|
||||
removed = 0
|
||||
for line in lines:
|
||||
if should_keep(line):
|
||||
out.append(line)
|
||||
else:
|
||||
removed += 1
|
||||
# 去掉连续空行
|
||||
result = []
|
||||
prev_blank = False
|
||||
for l in out:
|
||||
blank = l.strip() == ""
|
||||
if blank and prev_blank:
|
||||
continue
|
||||
result.append(l)
|
||||
prev_blank = blank
|
||||
s2 = "\n".join(result)
|
||||
if s2 != s:
|
||||
io.open(path, "w", encoding="utf-8-sig", newline="\r\n").write(s2)
|
||||
return removed
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
total = 0
|
||||
for pattern in ["xiangmu/*.Designer.cs", "shezhi/*.Designer.cs",
|
||||
"ku/*.Designer.cs", "GCS母排计算/*.Designer.cs"]:
|
||||
for f in glob.glob(os.path.join(BASE, pattern)):
|
||||
n = clean_file(f)
|
||||
total += n
|
||||
if n > 0:
|
||||
print("%s: 删除 %d 行冗余属性" % (os.path.basename(f), n))
|
||||
print("\n共删除 %d 行" % total)
|
||||
Reference in New Issue
Block a user