Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Library improvements and few bug fixes #50

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions DCIntrospect/DCIntrospect.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,29 @@

@interface DCIntrospect : NSObject <DCFrameViewDelegate, UITextViewDelegate, UIWebViewDelegate>
{
BOOL keyboardBindingsOn;
BOOL showStatusBarOverlay;
UIGestureRecognizer* invokeGestureRecognizer;

BOOL on;
BOOL handleArrowKeys;
BOOL viewOutlines;
BOOL highlightNonOpaqueViews;
BOOL flashOnRedraw;
DCFrameView *frameView;
UITextView *inputTextView;
DCStatusBarOverlay *statusBarOverlay;

NSMutableDictionary *objectNames;

UIView *currentView;
CGRect originalFrame;
CGFloat originalAlpha;

NSMutableArray *currentViewHistory;
NSMutableArray *currentViewStack;

BOOL showingHelp;
}

@property (nonatomic) BOOL keyboardBindingsOn; // default: YES
Expand All @@ -48,6 +71,7 @@
@property (nonatomic) CGRect originalFrame;
@property (nonatomic) CGFloat originalAlpha;
@property (nonatomic, retain) NSMutableArray *currentViewHistory;
@property (nonatomic, retain) NSMutableArray *currentViewStack;

@property (nonatomic) BOOL showingHelp;

Expand Down
94 changes: 83 additions & 11 deletions DCIntrospect/DCIntrospect.m
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ @interface DCIntrospect ()

- (void)takeFirstResponder;

- (void)moveDownInViewStack;
- (void)moveUpInViewStack;

@end


Expand All @@ -77,6 +80,7 @@ @implementation DCIntrospect
@synthesize currentView, originalFrame, originalAlpha;
@synthesize currentViewHistory;
@synthesize showingHelp;
@synthesize currentViewStack;

#pragma mark Setup

Expand Down Expand Up @@ -322,14 +326,24 @@ - (void)touchAtPoint:(CGPoint)point
CGPoint convertedTouchPoint = [[self mainWindow] convertPoint:point fromView:self.frameView];

// find all the views under that point – will be added in order on screen, ie mainWindow will be index 0, main view controller at index 1 etc.
NSMutableArray *views = [self viewsAtPoint:convertedTouchPoint inView:[self mainWindow]];
if (views.count == 0)
self.currentViewStack = [self viewsAtPoint:convertedTouchPoint inView:[self mainWindow]];
if (self.currentViewStack.count == 0)
return;

// get the topmost view and setup the UI
// setup the UI and get the topmost view which has a non nil superview
[self.currentViewHistory removeAllObjects];
UIView *newView = [views lastObject];
[self selectView:newView];

BOOL isViewFound = NO;
for( UIView* view in [self.currentViewStack reverseObjectEnumerator] )
if(view.superview)
{
isViewFound = YES;
[self selectView:view];
break;
}

if(!isViewFound && [self.currentViewStack count])
[self selectView:[self.currentViewStack lastObject]];
}

- (void)selectView:(UIView *)view
Expand Down Expand Up @@ -582,6 +596,24 @@ - (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range r
[self logCodeForCurrentViewChanges];
return NO;
}
else if([string isEqualToString:kDCIntrospectKeysMoveDownInViewStack])
{
[self moveDownInViewStack];
return NO;
}
else if([string isEqualToString:kDCIntrospectKeysMoveUpInViewStack])
{
[self moveUpInViewStack];
return NO;
}
else if( [string isEqualToString:kDCIntrospectKeysGenerateBackgroundColor] )
{
self.currentView.backgroundColor = [UIColor colorWithRed:(arc4random() % 256) / 256.0f
green:(arc4random() % 256) / 256.0f
blue:(arc4random() % 256) / 256.0f
alpha:1.0f];
return NO;
}

CGRect frame = self.currentView.frame;
if ([string isEqualToString:kDCIntrospectKeysNudgeViewLeft])
Expand Down Expand Up @@ -730,10 +762,12 @@ - (void)updateFrameView
if (!self.frameView)
{
self.frameView = [[[DCFrameView alloc] initWithFrame:(CGRect){ CGPointZero, mainWindow.frame.size } delegate:self] autorelease];
[mainWindow addSubview:self.frameView];
self.frameView.alpha = 0.0f;
[self updateViews];
}

//window can be changed
[mainWindow addSubview:self.frameView];

[mainWindow bringSubviewToFront:self.frameView];

Expand Down Expand Up @@ -786,7 +820,10 @@ - (void)updateStatusBar
}

if (self.showStatusBarOverlay)
{
[self.statusBarOverlay updateBarFrame];
self.statusBarOverlay.hidden = NO;
}
else
self.statusBarOverlay.hidden = YES;
}
Expand Down Expand Up @@ -964,6 +1001,42 @@ - (void)flashRect:(CGRect)rect inView:(UIView *)view
}
}

- (void)moveDownInViewStack
{
int indexOfCurrentView = [self.currentViewStack indexOfObject:self.currentView];
if(indexOfCurrentView == NSNotFound)
{
NSLog(@"DCIntrospect: The current view was changed and the view stack doesn't contain it.");
return;
}

if (indexOfCurrentView == 0)
{
NSLog(@"DCIntrospect: At bottom of the view stack.");
}else
{
[self selectView:[self.currentViewStack objectAtIndex:indexOfCurrentView - 1]];
}
}

- (void)moveUpInViewStack
{
int indexOfCurrentView = [self.currentViewStack indexOfObject:self.currentView];
if(indexOfCurrentView == NSNotFound)
{
NSLog(@"DCIntrospect: The current view was changed and the view stack doesn't contain it.");
return;
}

if (indexOfCurrentView == [self.currentViewStack count]-1)
{
NSLog(@"DCIntrospect: At top of the view stack.");
}else
{
[self selectView:[self.currentViewStack objectAtIndex:indexOfCurrentView + 1]];
}
}

#pragma mark Description Methods

- (NSString *)describeProperty:(NSString *)propertyName value:(id)value
Expand Down Expand Up @@ -1338,6 +1411,9 @@ - (void)toggleHelp
[helpString appendFormat:@"<div><span class='name'>Enter GDB</span><div class='key'>%@</div></div>", kDCIntrospectKeysEnterGDB];
[helpString appendFormat:@"<div><span class='name'>Move up in view hierarchy</span><div class='key'>%@</div></div>", ([kDCIntrospectKeysMoveUpInViewHierarchy isEqualToString:@""]) ? @"page up" : kDCIntrospectKeysMoveUpInViewHierarchy];
[helpString appendFormat:@"<div><span class='name'>Move back down in view hierarchy</span><div class='key'>%@</div></div>", ([kDCIntrospectKeysMoveBackInViewHierarchy isEqualToString:@""]) ? @"page down" : kDCIntrospectKeysMoveBackInViewHierarchy];
[helpString appendFormat:@"<div><span class='name'>Move up in a view stack</span><div class='key'>%@</div></div>", kDCIntrospectKeysMoveUpInViewStack];
[helpString appendFormat:@"<div><span class='name'>Move down in a view stack</span><div class='key'>%@</div></div>", kDCIntrospectKeysMoveDownInViewStack];
[helpString appendFormat:@"<div><span class='name'>Change the background color randomly</span><div class='key'>%@</div></div>", kDCIntrospectKeysGenerateBackgroundColor];
[helpString appendString:@"<div class='spacer'></div>"];

[helpString appendFormat:@"<div><span class='name'>Nudge Left</span><div class='key'>\uE235 / %@</div></div>", kDCIntrospectKeysNudgeViewLeft];
Expand Down Expand Up @@ -1577,11 +1653,7 @@ - (NSArray *)subclassesOfClass:(Class)parentClass

- (UIWindow *)mainWindow
{
NSArray *windows = [[UIApplication sharedApplication] windows];
if (windows.count == 0)
return nil;

return [windows objectAtIndex:0];
return [UIApplication sharedApplication].keyWindow;
}

- (NSMutableArray *)viewsAtPoint:(CGPoint)touchPoint inView:(UIView *)view
Expand Down
5 changes: 5 additions & 0 deletions DCIntrospect/DCIntrospectSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,10 @@
#define kDCIntrospectKeysMoveToNextSiblingView @"j"
#define kDCIntrospectKeysMoveToPrevSiblingView @"g"

#define kDCIntrospectKeysMoveUpInViewStack @"m" // select view which is under the selected view and contains a clicked point
#define kDCIntrospectKeysMoveDownInViewStack @"n" // select view whichg is over the selected view and contains a clicked point

#define kDCIntrospectKeysGenerateBackgroundColor @"k" // change the selected view's background color randomly

#define kDCIntrospectKeysEnterGDB @"`" // enters GDB
#define kDCIntrospectKeysDisableForPeriod @"~" // disables DCIntrospect for a given period (see kDCIntrospectTemporaryDisableDuration)