Rollback code related to commands_by_key
This commit is contained in:
parent
71f9544a3b
commit
f9ad4d030d
1 changed files with 11 additions and 26 deletions
|
|
@ -211,7 +211,6 @@ class CmdSet(object, metaclass=_CmdSetMeta):
|
||||||
if key:
|
if key:
|
||||||
self.key = key
|
self.key = key
|
||||||
self.commands = []
|
self.commands = []
|
||||||
self.commands_by_key = {}
|
|
||||||
self.system_commands = []
|
self.system_commands = []
|
||||||
self.actual_mergetype = self.mergetype
|
self.actual_mergetype = self.mergetype
|
||||||
self.cmdsetobj = cmdsetobj
|
self.cmdsetobj = cmdsetobj
|
||||||
|
|
@ -244,13 +243,9 @@ class CmdSet(object, metaclass=_CmdSetMeta):
|
||||||
# we make copies, not refs by use of [:]
|
# we make copies, not refs by use of [:]
|
||||||
cmdset_c.commands = cmdset_a.commands[:]
|
cmdset_c.commands = cmdset_a.commands[:]
|
||||||
if cmdset_a.duplicates and cmdset_a.priority == cmdset_b.priority:
|
if cmdset_a.duplicates and cmdset_a.priority == cmdset_b.priority:
|
||||||
new_cmds = cmdset_b.commands
|
cmdset_c.commands.extend(cmdset_b.commands)
|
||||||
else:
|
else:
|
||||||
new_cmds = [cmd for cmd in cmdset_b if cmd not in cmdset_a]
|
cmdset_c.commands.extend([cmd for cmd in cmdset_b if cmd not in cmdset_a])
|
||||||
|
|
||||||
cmdset_c.commands.extend(new_cmds)
|
|
||||||
cmdset_c.commands_by_key.update({cmd.key: cmd for cmd in new_cmds})
|
|
||||||
|
|
||||||
return cmdset_c
|
return cmdset_c
|
||||||
|
|
||||||
def _intersect(self, cmdset_a, cmdset_b):
|
def _intersect(self, cmdset_a, cmdset_b):
|
||||||
|
|
@ -277,10 +272,7 @@ class CmdSet(object, metaclass=_CmdSetMeta):
|
||||||
cmdset_c.add(cmd)
|
cmdset_c.add(cmd)
|
||||||
cmdset_c.add(cmdset_b.get(cmd))
|
cmdset_c.add(cmdset_b.get(cmd))
|
||||||
else:
|
else:
|
||||||
new_cmds = [cmd for cmd in cmdset_a if cmd in cmdset_b]
|
cmdset_c.commands = [cmd for cmd in cmdset_a if cmd in cmdset_b]
|
||||||
cmdset_c.commands = new_cmds
|
|
||||||
cmdset_c.commands_by_key = {cmd.key: cmd for cmd in new_cmds}
|
|
||||||
|
|
||||||
return cmdset_c
|
return cmdset_c
|
||||||
|
|
||||||
def _replace(self, cmdset_a, cmdset_b):
|
def _replace(self, cmdset_a, cmdset_b):
|
||||||
|
|
@ -299,10 +291,7 @@ class CmdSet(object, metaclass=_CmdSetMeta):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
cmdset_c = cmdset_a._duplicate()
|
cmdset_c = cmdset_a._duplicate()
|
||||||
commands = cmdset_a.commands[:]
|
cmdset_c.commands = cmdset_a.commands[:]
|
||||||
cmdset_c.commands = commands
|
|
||||||
cmdset_c.commands_by_key = {cmd.key: cmd for cmd in commands}
|
|
||||||
|
|
||||||
return cmdset_c
|
return cmdset_c
|
||||||
|
|
||||||
def _remove(self, cmdset_a, cmdset_b):
|
def _remove(self, cmdset_a, cmdset_b):
|
||||||
|
|
@ -322,10 +311,7 @@ class CmdSet(object, metaclass=_CmdSetMeta):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
cmdset_c = cmdset_a._duplicate()
|
cmdset_c = cmdset_a._duplicate()
|
||||||
new_cmds = [cmd for cmd in cmdset_b if cmd not in cmdset_a]
|
cmdset_c.commands = [cmd for cmd in cmdset_b if cmd not in cmdset_a]
|
||||||
cmdset_c.commands = new_cmds
|
|
||||||
cmdset_c.commands_by_key = {cmd.key: cmd for cmd in new_cmds}
|
|
||||||
|
|
||||||
return cmdset_c
|
return cmdset_c
|
||||||
|
|
||||||
def _instantiate(self, cmd):
|
def _instantiate(self, cmd):
|
||||||
|
|
@ -575,8 +561,6 @@ class CmdSet(object, metaclass=_CmdSetMeta):
|
||||||
# extra run to make sure to avoid doublets
|
# extra run to make sure to avoid doublets
|
||||||
self.commands = list(set(self.commands))
|
self.commands = list(set(self.commands))
|
||||||
|
|
||||||
self.commands_by_key = {cmd.key: cmd for cmd in self.commands}
|
|
||||||
|
|
||||||
def remove(self, cmd):
|
def remove(self, cmd):
|
||||||
"""
|
"""
|
||||||
Remove a command instance from the cmdset.
|
Remove a command instance from the cmdset.
|
||||||
|
|
@ -587,7 +571,9 @@ class CmdSet(object, metaclass=_CmdSetMeta):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if isinstance(cmd, str):
|
if isinstance(cmd, str):
|
||||||
cmd = self.commands_by_key.get(cmd)
|
cmd = next((cmd for cmd in self.commands if cmd.key == cmd), None)
|
||||||
|
if cmd is None:
|
||||||
|
return None
|
||||||
|
|
||||||
cmd = self._instantiate(cmd)
|
cmd = self._instantiate(cmd)
|
||||||
if cmd.key.startswith("__"):
|
if cmd.key.startswith("__"):
|
||||||
|
|
@ -599,7 +585,6 @@ class CmdSet(object, metaclass=_CmdSetMeta):
|
||||||
pass
|
pass
|
||||||
else:
|
else:
|
||||||
self.commands = [oldcmd for oldcmd in self.commands if oldcmd != cmd]
|
self.commands = [oldcmd for oldcmd in self.commands if oldcmd != cmd]
|
||||||
self.commands_by_key = {cmd.key: cmd for cmd in self.commands}
|
|
||||||
|
|
||||||
def get(self, cmd):
|
def get(self, cmd):
|
||||||
"""
|
"""
|
||||||
|
|
@ -614,7 +599,9 @@ class CmdSet(object, metaclass=_CmdSetMeta):
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if isinstance(cmd, str):
|
if isinstance(cmd, str):
|
||||||
cmd = self.commands_by_key.get(cmd)
|
cmd = next((cmd for cmd in self.commands if cmd.key == cmd), None)
|
||||||
|
if cmd is None:
|
||||||
|
return None
|
||||||
|
|
||||||
cmd = self._instantiate(cmd)
|
cmd = self._instantiate(cmd)
|
||||||
for thiscmd in self.commands:
|
for thiscmd in self.commands:
|
||||||
|
|
@ -674,9 +661,7 @@ class CmdSet(object, metaclass=_CmdSetMeta):
|
||||||
unique[cmd.key] = cmd
|
unique[cmd.key] = cmd
|
||||||
else:
|
else:
|
||||||
unique[cmd.key] = cmd
|
unique[cmd.key] = cmd
|
||||||
|
|
||||||
self.commands = list(unique.values())
|
self.commands = list(unique.values())
|
||||||
self.commands_by_key = {cmd.key: cmd for cmd in self.commands}
|
|
||||||
|
|
||||||
def get_all_cmd_keys_and_aliases(self, caller=None):
|
def get_all_cmd_keys_and_aliases(self, caller=None):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue