-
Notifications
You must be signed in to change notification settings - Fork 804
/
fbchisellldbviewcontrollerhelpers.py
executable file
·122 lines (97 loc) · 4.22 KB
/
fbchisellldbviewcontrollerhelpers.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
#!/usr/bin/python
# Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved
#
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
import fbchisellldbbase as fb
import fbchisellldbobjcruntimehelpers as runtimeHelpers
def presentViewController(viewController):
vc = "(%s)" % (viewController)
if fb.evaluateBooleanExpression(
"%s != nil && ((BOOL)[(id)%s isKindOfClass:(Class)[UIViewController class]])"
% (vc, vc)
):
notPresented = fb.evaluateBooleanExpression(
"[%s presentingViewController] == nil" % vc
)
if notPresented:
fb.evaluateEffect(
"[[[[UIApplication sharedApplication] keyWindow] rootViewController] presentViewController:%s animated:YES completion:nil]"
% vc
)
else:
raise Exception("Argument is already presented")
else:
raise Exception("Argument must be a UIViewController")
def dismissViewController(viewController):
vc = "(%s)" % (viewController)
if fb.evaluateBooleanExpression(
"%s != nil && ((BOOL)[(id)%s isKindOfClass:(Class)[UIViewController class]])"
% (vc, vc)
):
isPresented = fb.evaluateBooleanExpression(
"[%s presentingViewController] != nil" % vc
)
if isPresented:
fb.evaluateEffect(
"[(UIViewController *)%s dismissViewControllerAnimated:YES completion:nil]"
% vc
)
else:
raise Exception("Argument must be presented")
else:
raise Exception("Argument must be a UIViewController")
def viewControllerRecursiveDescription(vc):
return _recursiveViewControllerDescriptionWithPrefixAndChildPrefix(
fb.evaluateObjectExpression(vc), "", "", ""
)
def _viewControllerDescription(viewController):
vc = "(%s)" % (viewController)
if fb.evaluateBooleanExpression("[(id)%s isViewLoaded]" % (vc)):
result = fb.evaluateExpressionValue(
'(id)[[NSString alloc] initWithFormat:@"<%%@: %%p; view = <%%@; %%p>; frame = (%%g, %%g; %%g, %%g)>", (id)NSStringFromClass((id)[(id)%s class]), %s, (id)[(id)[(id)%s view] class], (id)[(id)%s view], ((CGRect)[(id)[(id)%s view] frame]).origin.x, ((CGRect)[(id)[(id)%s view] frame]).origin.y, ((CGRect)[(id)[(id)%s view] frame]).size.width, ((CGRect)[(id)[(id)%s view] frame]).size.height]'
% (vc, vc, vc, vc, vc, vc, vc, vc)
)
else:
result = fb.evaluateExpressionValue(
'(id)[[NSString alloc] initWithFormat:@"<%%@: %%p; view not loaded>", (id)NSStringFromClass((id)[(id)%s class]), %s]'
% (vc, vc)
)
if result.GetError() is not None and str(result.GetError()) != "success":
return "[Error getting description.]"
else:
return result.GetObjectDescription()
def _recursiveViewControllerDescriptionWithPrefixAndChildPrefix(
vc, string, prefix, childPrefix
):
isMac = runtimeHelpers.isMacintoshArch()
s = "%s%s%s\n" % (
prefix,
"" if prefix == "" else " ",
_viewControllerDescription(vc),
)
nextPrefix = childPrefix + " |"
numChildViewControllers = fb.evaluateIntegerExpression(
"(int)[(id)[%s childViewControllers] count]" % (vc)
)
for i in range(0, numChildViewControllers):
viewController = fb.evaluateExpression(
"(id)[(id)[%s childViewControllers] objectAtIndex:%d]" % (vc, i)
)
s += _recursiveViewControllerDescriptionWithPrefixAndChildPrefix(
viewController, string, nextPrefix, nextPrefix
)
if not isMac:
isModal = fb.evaluateBooleanExpression(
"%s != nil && ((id)[(id)[(id)%s presentedViewController] presentingViewController]) == %s"
% (vc, vc, vc)
)
if isModal:
modalVC = fb.evaluateObjectExpression(
"(id)[(id)%s presentedViewController]" % (vc)
)
s += _recursiveViewControllerDescriptionWithPrefixAndChildPrefix(
modalVC, string, childPrefix + " *M", nextPrefix
)
s += "\n// '*M' means the view controller is presented modally."
return string + s