예제 #1
0
 def test(c):
     m = Mocker()
     menu = m.mock(ak.NSMenu)
     ctl = CommandManager("<history>")
     for command in c.commands:
         ctl.add_command(command, None, menu)
     eq_(ctl.lookup(c.lookup), c.result)
예제 #2
0
def test_CommandManager_load_shortcuts():
    from editxt.config import config_schema

    @command
    def doc(editor, opts):
        pass

    shorts = config_schema()["shortcuts"]
    menu = const.Constant("menu")
    expect = []
    tags = {doc: doc.name}
    key = lambda kv: kv[1]["rank"].default
    for i, (hotkey, value) in enumerate(sorted(shorts.items(), key=key)):
        hkey = mod.parse_hotkey(hotkey)
        title = value["name"].default
        expect.append((menu, title) + hkey)
        tags[title] = i
    items = []

    def add_menu_item(menu, title, hotkey, modifiers):
        items.append((menu, title, hotkey, modifiers))
        return tags[title]

    with test_app() as app:
        ctl = CommandManager("<history>", app=app)
        ctl.add_command(doc, None, menu)
        ctl.add_menu_item = add_menu_item
        ctl.load_shortcuts(menu)
        eq_(items, expect)
        eq_(set(ctl.commands), set(tags.values()))
예제 #3
0
def test_CommandBar_history_reset_on_execute():
    from editxt.editor import Editor
    from editxt.textcommand import CommandHistory, CommandManager
    with tempdir() as tmp:
        m = Mocker()
        window = m.mock()
        history = CommandHistory(tmp)
        commander = CommandManager(history)
        bar = mod.CommandBar(window, commander)
        args = ["cmd"]
        editor = m.mock(Editor)
        (window.current_editor << editor).count(2)
        @command
        def cmd(editor, args):
            pass
        commander.add_command(cmd, None, None)
        with m:
            bar.get_history("cmd")
            bar.execute("cmd")
            eq_(bar.history_view, None)
            eq_(list(history), ["cmd"])
예제 #4
0
 def test(c):
     m = Mocker()
     menu = m.mock(ak.NSMenu)
     mi_class = m.replace(ak, "NSMenuItem")
     ctl = CommandManager("<history>")
     handlers = m.replace(ctl, "input_handlers")
     validate = m.method(ctl.validate_hotkey)
     cmd = m.mock()
     cmd.names >> []
     cmd.lookup_with_arg_parser >> False
     cmd.config >> None
     tag = cmd._CommandManager__tag = next(ctl.tagger) + 1
     validate(cmd.hotkey >> "<hotkey>") >> ("<hotkey>", "<keymask>")
     mi = mi_class.alloc() >> m.mock(ak.NSMenuItem)
     (cmd.title << "<title>").count(2)
     mi.initWithTitle_action_keyEquivalent_("<title>", "doMenuCommand:", "<hotkey>") >> mi
     mi.setKeyEquivalentModifierMask_("<keymask>")
     mi.setTag_(tag)
     menu.addItem_(mi)
     with m:
         ctl.add_command(cmd, None, menu)
         assert ctl.commands[tag] is cmd, (ctl.commands[tag], cmd)