"""Offline Eclipse Shortcuts catalog, Keys preferences & conflict detector verifier for Ch33 (shortcuts)."""
import json
VERSION = "CPython 3.12.14 offline Eclipse Keys binding & conflict detector verifier (desktop SWT IDE absent)"
def check(name, summary, expected, actual):
return {
"name": name,
"summary": summary,
"expected": expected,
"actual": actual,
"passed": actual == expected,
}
def main():
cases = []
# Case 1: 8-category Eclipse shortcut catalog (62 bindings total) + Ctrl+Shift+L overview
catalog = {
"编辑": [
"Ctrl+1", "Ctrl+Shift+F", "Ctrl+Shift+M", "Ctrl+Shift+O", "Ctrl+Y",
"Alt+/", "Ctrl+D", "Alt+↓", "Alt+↑", "Ctrl+Alt+↓", "Ctrl+Alt+↑",
"Shift+Enter", "Ctrl+/",
],
"选择": [
"Alt+Shift+↑", "Alt+Shift+←", "Alt+Shift+→", "Shift+←", "Shift+→",
"Ctrl+Shift+←", "Ctrl+Shift+→",
],
"移动": ["Ctrl+←", "Ctrl+→"],
"搜索": [
"Ctrl+K", "Ctrl+Shift+K", "Ctrl+J", "Ctrl+Shift+J",
"Ctrl+Shift+U", "Ctrl+H", "Ctrl+G", "Ctrl+Shift+G",
],
"导航": [
"Ctrl+Shift+T", "Ctrl+Shift+R", "Ctrl+E", "F4", "F3",
"Alt+←", "Alt+→", "Ctrl+PageUp/PageDown",
],
"调试": ["F5", "F6", "F7", "F8", "Ctrl+Shift+D", "Ctrl+Shift+B", "Ctrl+R"],
"重构": [
"Alt+Shift+R", "Alt+Shift+M", "Alt+Shift+C", "Alt+Shift+L",
"Alt+Shift+F", "Alt+Shift+I", "Alt+Shift+V", "Alt+Shift+Z",
],
"其他": [
"Alt+Enter", "Ctrl+↑", "Ctrl+↓", "Ctrl+M", "Ctrl+O",
"Ctrl+T", "Ctrl+W", "Ctrl+L", "F2",
],
}
total_bindings = sum(len(v) for v in catalog.values())
all_refactor_use_alt_shift = all(k.startswith("Alt+Shift+") for k in catalog["重构"])
cases.append(
check(
"shortcuts_category_catalog",
"Verify 8 Eclipse shortcut categories, 62 documented bindings, Ctrl+Shift+L cheat-sheet, and Alt+Shift refactor prefix",
{
"category_count": 8,
"total_bindings": 62,
"cheat_sheet_key": "Ctrl+Shift+L",
"all_refactor_alt_shift": True,
},
{
"category_count": len(catalog),
"total_bindings": total_bindings,
"cheat_sheet_key": "Ctrl+Shift+L",
"all_refactor_alt_shift": all_refactor_use_alt_shift,
},
)
)
# Case 2: Window > Preferences > General > Keys custom binding and When context
key_bindings = [
{"command": "Quick Fix", "binding": "Ctrl+1", "when": "In Windows"},
{"command": "Organize Imports", "binding": "Ctrl+Shift+O", "when": "Editing Java Source"},
{"command": "Run To Line", "binding": "Ctrl+R", "when": "Debugging"},
]
# Customize a command without default binding under "In Windows"
key_bindings.append({"command": "Toggle Word Wrap", "binding": "Alt+Shift+W", "when": "In Windows"})
found = next(b for b in key_bindings if b["command"] == "Toggle Word Wrap")
cases.append(
check(
"keys_preference_binding_and_when",
"Verify General > Keys allows adding custom command bindings scoped by When context (e.g. In Windows)",
{
"pref_path": "Window > Preferences > General > Keys",
"custom_binding": "Alt+Shift+W",
"custom_when": "In Windows",
},
{
"pref_path": "Window > Preferences > General > Keys",
"custom_binding": found["binding"],
"custom_when": found["when"],
},
)
)
# Case 3: Conflict detection across overlapping vs disjoint When scopes
test_bindings = [
{"command": "Format", "binding": "Ctrl+Shift+F", "when": "Editing Java Source"},
{"command": "Custom Action", "binding": "Ctrl+Shift+F", "when": "In Windows"},
{"command": "Step Over", "binding": "F6", "when": "Debugging"},
{"command": "Custom Editor F6", "binding": "F6", "when": "Editing XML"},
]
def scopes_overlap(w1, w2):
return w1 == w2 or "In Windows" in (w1, w2)
conflicts = []
for i in range(len(test_bindings)):
for j in range(i + 1, len(test_bindings)):
a, b = test_bindings[i], test_bindings[j]
if a["binding"] == b["binding"] and scopes_overlap(a["when"], b["when"]):
conflicts.append((a["binding"], a["command"], b["command"]))
cases.append(
check(
"shortcut_conflict_detection",
"Verify Keys conflict detector flags same-key overlaps with 'In Windows' while permitting disjoint scopes",
[["Ctrl+Shift+F", "Format", "Custom Action"]],
[list(c) for c in conflicts],
)
)
# Case 4: Core editing, navigation, debugging, and refactoring dispatch map
dispatch = {
"Ctrl+1": "quick_fix",
"Ctrl+Shift+O": "organize_imports",
"Ctrl+Shift+T": "open_type",
"Ctrl+Shift+R": "open_resource",
"F3": "open_declaration",
"F4": "open_type_hierarchy",
"F5": "step_into",
"F6": "step_over",
"F7": "step_return",
"F8": "resume",
"Alt+Shift+R": "rename",
"Alt+Shift+M": "extract_method",
"Ctrl+O": "quick_outline",
}
cases.append(
check(
"shortcut_quick_assist_and_refactor_map",
"Verify deterministic command dispatch for high-frequency editing, navigation, debug, and refactor keys",
{
"quick_fix": "Ctrl+1",
"open_type": "Ctrl+Shift+T",
"step_over": "F6",
"rename": "Alt+Shift+R",
"quick_outline": "Ctrl+O",
},
{
"quick_fix": next(k for k, v in dispatch.items() if v == "quick_fix"),
"open_type": next(k for k, v in dispatch.items() if v == "open_type"),
"step_over": next(k for k, v in dispatch.items() if v == "step_over"),
"rename": next(k for k, v in dispatch.items() if v == "rename"),
"quick_outline": next(k for k, v in dispatch.items() if v == "quick_outline"),
},
)
)
print(json.dumps({"version": VERSION, "cases": cases}, ensure_ascii=False, indent=2))
if __name__ == "__main__":
main()
本例需在 Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。 中运行,请复制源码、保存文件或下载工程包后在本地执行验证。
运行说明与环境独立工程
运行环境:Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。
入口文件:projects/eclipse-shortcuts-lab/explore-shortcuts.py
本地运行步骤快速上手
- 点击上方“保存源码”保存为
explore-shortcuts.py,或下载右侧课程工程包。 - 确认本地已准备 Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。。
- 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载
课程关联工程包(登记关联35章) · 含当前章节或实例 · mbskycom202612a2259.zip
课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a2289.zip