def test(c): m = Mocker() menu = m.mock(ak.NSMenu) ctl = TextCommandController("<history>") for command in c.commands: ctl.add_command(command, None, menu) eq_(ctl.lookup(c.lookup), c.result)
def test(c): m = Mocker() menu = m.mock(ak.NSMenu) ctl = TextCommandController("<history>") for command in c.commands: ctl.add_command(command, None, menu) menu.insertItem_atIndex_(ANY, ANY) eq_(ctl.lookup_full_command(c.lookup), c.result)
def test(c): m = Mocker() menu = m.mock(NSMenu) mi_class = m.replace(NSMenuItem, passthrough=False) ctl = TextCommandController(menu) cmds = m.replace(ctl.commands) handlers = m.replace(ctl.input_handlers, passthrough=False) validate = m.method(ctl.validate_hotkey) cmd = m.mock(TextCommand) tag = cmd._TextCommandController__tag = ctl.tagger.next() + 1 validate(cmd.preferred_hotkey() >> "<hotkey>") >> ("<hotkey>", "<keymask>") mi = mi_class.alloc() >> m.mock(NSMenuItem) mi.initWithTitle_action_keyEquivalent_( cmd.title() >> "<title>", "performTextCommand:" ,"<hotkey>") >> mi mi.setKeyEquivalentModifierMask_("<keymask>") mi.setTag_(tag) menu.insertItem_atIndex_(mi, tag) ctl.commands[tag] = cmd with m: ctl.add_command(cmd, None)
def test_CommandBar_history_reset_on_execute(): from editxt.document import TextDocumentView from editxt.textcommand import CommandHistory, TextCommandController with tempdir() as tmp: m = Mocker() editor = m.mock() history = CommandHistory(tmp) commander = TextCommandController(history) bar = mod.CommandBar(editor, commander) args = ["cmd"] view = editor.current_view >> m.mock(TextDocumentView) view.text_view >> '<view>' @command def cmd(textview, sender, 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"])
def test(c): m = Mocker() menu = m.mock(ak.NSMenu) mi_class = m.replace(ak, 'NSMenuItem') ctl = TextCommandController("<history>") handlers = m.replace(ctl, 'input_handlers') validate = m.method(ctl.validate_hotkey) cmd = m.mock() cmd.names >> [] cmd.lookup_with_arg_parser >> False tag = cmd._TextCommandController__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>', "performTextCommand:" ,"<hotkey>") >> mi mi.setKeyEquivalentModifierMask_("<keymask>") mi.setTag_(tag) menu.insertItem_atIndex_(mi, tag) with m: ctl.add_command(cmd, None, menu) assert ctl.commands[tag] is cmd, (ctl.commands[tag], cmd)
def test(c): m = Mocker() menu = m.mock(ak.NSMenu) mi_class = m.replace(ak, 'NSMenuItem') ctl = TextCommandController("<history>") handlers = m.replace(ctl, 'input_handlers') validate = m.method(ctl.validate_hotkey) cmd = m.mock() cmd.names >> [] cmd.lookup_with_arg_parser >> False tag = cmd._TextCommandController__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>', "performTextCommand:", "<hotkey>") >> mi mi.setKeyEquivalentModifierMask_("<keymask>") mi.setTag_(tag) menu.insertItem_atIndex_(mi, tag) with m: ctl.add_command(cmd, None, menu) assert ctl.commands[tag] is cmd, (ctl.commands[tag], cmd)