Skip to content

Commit

Permalink
Merge pull request #95 from facebook/pactions
Browse files Browse the repository at this point in the history
Add `pactions` command to print the target/actions of a UIControl
  • Loading branch information
arigrant committed May 27, 2015
2 parents 22d74dd + e317b2d commit bd12c6a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions commands/FBPrintCommands.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ def lldbcommands():
FBPrintKeyPath(),
FBPrintApplicationDocumentsPath(),
FBPrintData(),
FBPrintTargetActions(),
]

class FBPrintViewHierarchyCommand(fb.FBCommand):
Expand Down Expand Up @@ -398,3 +399,28 @@ def run(self, arguments, option):

print_command = 'po (NSString *)[[NSString alloc] initWithData:{} encoding:{}]'.format(arguments[0], enc)
lldb.debugger.HandleCommand(print_command)

class FBPrintTargetActions(fb.FBCommand):

def name(self):
return 'pactions'

def description(self):
return 'Print the actions and targets of a control.'

def args(self):
return [ fb.FBCommandArgument(arg='control', type='UIControl *', help='The control to inspect the actions of.') ]

def run(self, arguments, options):
control = arguments[0]
targets = fb.evaluateObjectExpression('[[{control} allTargets] allObjects]'.format(control=control))
targetCount = fb.evaluateIntegerExpression('[{targets} count]'.format(targets=targets))

for index in range(0, targetCount):
target = fb.evaluateObjectExpression('[{targets} objectAtIndex:{index}]'.format(targets=targets, index=index))
actions = fb.evaluateObjectExpression('[{control} actionsForTarget:{target} forControlEvent:0]'.format(control=control, target=target))

targetDescription = fb.evaluateExpressionValue('(id){target}'.format(target=target)).GetObjectDescription()
actionsDescription = fb.evaluateExpressionValue('(id)[{actions} componentsJoinedByString:@", "]'.format(actions=actions)).GetObjectDescription()

print '{target}: {actions}'.format(target=targetDescription, actions=actionsDescription)

0 comments on commit bd12c6a

Please sign in to comment.