蓝色天空.知识 · 实践 · 创造
我的收藏
在线代码实验室

运行 Eclipse 首选项多插件分类树、过滤检索与作用域 OK/Cancel 事务离线核验

PYTHONWindows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。explore-preferences.py
explore-preferences.py110 行
"""Offline Eclipse Preferences tree, filter search & scope inheritance verifier for Ch22 (preferences)."""
import json

VERSION = "CPython 3.12.14 offline Eclipse Preferences hierarchy & scope 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: Framework & plugin-contributed preference tree
    pref_pages = [
        {"path": "General > Appearance > Colors and Fonts", "provider": "platform"},
        {"path": "General > Editors > Text Editors", "provider": "platform"},
        {"path": "General > Keys", "provider": "platform"},
        {"path": "General > Workspace", "provider": "platform"},
        {"path": "Java > Compiler", "provider": "jdt-plugin"},
        {"path": "Java > Editor > Content Assist", "provider": "jdt-plugin"},
        {"path": "Maven > User Settings", "provider": "m2e-plugin"},
    ]
    top_categories = sorted({p["path"].split(" > ")[0] for p in pref_pages})
    plugin_pages = [p["path"] for p in pref_pages if p["provider"] != "platform"]

    cases.append(
        check(
            "preference_tree_and_plugin_pages",
            "Verify Window > Preferences combines core platform pages and plugin-contributed pages",
            {
                "top_categories": ["General", "Java", "Maven"],
                "plugin_page_count": 3,
            },
            {
                "top_categories": top_categories,
                "plugin_page_count": len(plugin_pages),
            },
        )
    )

    # Case 2: Top-left quick filter box matches page names case-insensitively (e.g., "font")
    query = "font"
    matched_font = [p["path"] for p in pref_pages if query.lower() in p["path"].lower()]
    query_keys = "keys"
    matched_keys = [p["path"] for p in pref_pages if query_keys.lower() in p["path"].lower()]

    cases.append(
        check(
            "preference_filter_search",
            "Verify top-left filter input narrows preference tree for queries such as 'font' and 'keys'",
            {
                "font_matches": ["General > Appearance > Colors and Fonts"],
                "keys_matches": ["General > Keys"],
            },
            {
                "font_matches": matched_font,
                "keys_matches": matched_keys,
            },
        )
    )

    # Case 3: Preference scope inheritance (default -> instance -> project) and OK vs Cancel transaction
    default_scope = {"encoding": "ISO-8859-1", "tabWidth": 4, "fontSize": 10}
    instance_scope = {"encoding": "UTF-8"}
    project_scope = {"tabWidth": 2}

    def effective(inst):
        merged = dict(default_scope)
        merged.update(inst)
        merged.update(project_scope)
        return merged

    # Edit in dialog then Cancel -> discards draft
    draft_cancel = dict(instance_scope, fontSize=14)
    # Cancel does not write back to instance_scope
    after_cancel = effective(instance_scope)

    # Edit in dialog then OK -> persists draft
    draft_ok = dict(instance_scope, fontSize=12)
    instance_scope = draft_ok
    after_ok = effective(instance_scope)

    cases.append(
        check(
            "preference_scope_and_ok_cancel",
            "Verify preference scope override order and OK commit vs Cancel discard semantics",
            {
                "after_cancel": {"encoding": "UTF-8", "tabWidth": 2, "fontSize": 10},
                "after_ok": {"encoding": "UTF-8", "tabWidth": 2, "fontSize": 12},
            },
            {
                "after_cancel": after_cancel,
                "after_ok": after_ok,
            },
        )
    )

    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-preferences-lab/explore-preferences.py

本地运行步骤快速上手
  1. 点击上方“保存源码”保存为 explore-preferences.py,或下载右侧课程工程包。
  2. 确认本地已准备 Windows x64、CPython 3.12.14、Playwright 与本地浏览器/标准库。。
  3. 按对应章节命令执行,结合正文核对实际输出。
附件与关联工程包下载

下载课程关联工程包:Eclipse

课程关联工程包(登记关联35章) · 含当前章节或实例 · mbskycom202612a2259.zip

下载课程关联工程包:Eclipse

课程关联工程包(登记关联1章) · 含当前章节或实例 · mbskycom202612a2282.zip
SITE SEARCH

搜索教程、工具与资讯

热门搜索

JavaScriptJSON格式化正则表达式AI 编程AI 翻译AI导航专题标签
Esc 关闭

欢迎登录蓝色天空网

使用会员账号,继续你的学习