Add support to has_cmdset for cmdset instances as suggested in #1083.
This commit is contained in:
parent
78d422dd7a
commit
402a4c8aa0
1 changed files with 24 additions and 7 deletions
|
|
@ -537,12 +537,13 @@ class CmdSetHandler(object):
|
||||||
self.obj.cmdset_storage = storage
|
self.obj.cmdset_storage = storage
|
||||||
self.update()
|
self.update()
|
||||||
|
|
||||||
def has_cmdset(self, cmdset_key, must_be_default=False):
|
def has(self, cmdset, must_be_default=False):
|
||||||
"""
|
"""
|
||||||
checks so the cmdsethandler contains a cmdset with the given key.
|
checks so the cmdsethandler contains a given cmdset
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
cmdset_key (str): Cmdset key to check
|
cmdset (str or Cmdset): Cmdset key, pythonpath or
|
||||||
|
Cmdset to check the existence for.
|
||||||
must_be_default (bool, optional): Only return True if
|
must_be_default (bool, optional): Only return True if
|
||||||
the checked cmdset is the default one.
|
the checked cmdset is the default one.
|
||||||
|
|
||||||
|
|
@ -550,11 +551,27 @@ class CmdSetHandler(object):
|
||||||
has_cmdset (bool): Whether or not the cmdset is in the handler.
|
has_cmdset (bool): Whether or not the cmdset is in the handler.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if must_be_default:
|
if callable(cmdset) and hasattr(cmdset, 'path'):
|
||||||
return self.cmdset_stack and self.cmdset_stack[0].key == cmdset_key
|
# try it as a callable
|
||||||
|
print "Try callable", cmdset
|
||||||
|
if must_be_default:
|
||||||
|
return self.cmdset_stack and (self.cmdset_stack[0].path == cmdset.path)
|
||||||
|
else:
|
||||||
|
print [cset.path for cset in self.cmdset_stack], cmdset.path
|
||||||
|
return any([cset for cset in self.cmdset_stack
|
||||||
|
if cset.path == cmdset.path])
|
||||||
else:
|
else:
|
||||||
return any([cmdset.key == cmdset_key or cmdset.path == cmdset_key
|
# try it as a path or key
|
||||||
for cmdset in self.cmdset_stack])
|
if must_be_default:
|
||||||
|
return self.cmdset_stack and (
|
||||||
|
self.cmdset_stack[0].key == cmdset or
|
||||||
|
self.cmdset_stack[0].path == cmdset)
|
||||||
|
else:
|
||||||
|
return any([cset for cset in self.cmdset_stack
|
||||||
|
if cset.path == cmdset or cset.key == cmdset])
|
||||||
|
|
||||||
|
# backwards-compatability alias
|
||||||
|
has_cmdset = has
|
||||||
|
|
||||||
def reset(self):
|
def reset(self):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue