Skip to content

Commit

Permalink
Filter when Enter-Key pressed
Browse files Browse the repository at this point in the history
  • Loading branch information
tinymind committed Dec 21, 2015
1 parent b3f0c84 commit b8ee48b
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 55 deletions.
44 changes: 26 additions & 18 deletions LSLog-XCode.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@
B15C7B631C197A8300C92958 /* AppKit.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B15C7B621C197A8300C92958 /* AppKit.framework */; settings = {ASSET_TAGS = (); }; };
B15C7B651C197A8300C92958 /* Foundation.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = B15C7B641C197A8300C92958 /* Foundation.framework */; settings = {ASSET_TAGS = (); }; };
B15C7B691C197A8300C92958 /* LSLog-XCode.xcscheme in Resources */ = {isa = PBXBuildFile; fileRef = B15C7B681C197A8300C92958 /* LSLog-XCode.xcscheme */; };
B15C7B6C1C197A8300C92958 /* LSLog.m in Sources */ = {isa = PBXBuildFile; fileRef = B15C7B6B1C197A8300C92958 /* LSLog.m */; };
B15C7B7D1C19873500C92958 /* NSObject+LSLog.m in Sources */ = {isa = PBXBuildFile; fileRef = B15C7B7C1C19873500C92958 /* NSObject+LSLog.m */; settings = {ASSET_TAGS = (); }; };
B15C7B801C19878C00C92958 /* NSTextStorage+LSLog.m in Sources */ = {isa = PBXBuildFile; fileRef = B15C7B7F1C19878C00C92958 /* NSTextStorage+LSLog.m */; settings = {ASSET_TAGS = (); }; };
B15C7B831C1A665C00C92958 /* NSObject+LSSwizzle.m in Sources */ = {isa = PBXBuildFile; fileRef = B15C7B821C1A665B00C92958 /* NSObject+LSSwizzle.m */; settings = {ASSET_TAGS = (); }; };
B15C7B891C1A6F7200C92958 /* LSIDEConsoleArea.m in Sources */ = {isa = PBXBuildFile; fileRef = B15C7B881C1A6F7200C92958 /* LSIDEConsoleArea.m */; settings = {ASSET_TAGS = (); }; };
B15C7B8C1C1A726A00C92958 /* LSIDEConsoleItem.m in Sources */ = {isa = PBXBuildFile; fileRef = B15C7B8B1C1A726A00C92958 /* LSIDEConsoleItem.m */; settings = {ASSET_TAGS = (); }; };
B1944C581C27BB4C006071E7 /* LSIDEConsoleArea.m in Sources */ = {isa = PBXBuildFile; fileRef = B1944C531C27BB4C006071E7 /* LSIDEConsoleArea.m */; settings = {ASSET_TAGS = (); }; };
B1944C591C27BB4C006071E7 /* LSIDEConsoleItem.m in Sources */ = {isa = PBXBuildFile; fileRef = B1944C551C27BB4C006071E7 /* LSIDEConsoleItem.m */; settings = {ASSET_TAGS = (); }; };
B1944C5A1C27BB4C006071E7 /* LSLog.m in Sources */ = {isa = PBXBuildFile; fileRef = B1944C571C27BB4C006071E7 /* LSLog.m */; settings = {ASSET_TAGS = (); }; };
/* End PBXBuildFile section */

/* Begin PBXFileReference section */
Expand All @@ -31,19 +31,19 @@
B15C7B621C197A8300C92958 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = /System/Library/Frameworks/AppKit.framework; sourceTree = "<absolute>"; };
B15C7B641C197A8300C92958 /* Foundation.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = Foundation.framework; path = /System/Library/Frameworks/Foundation.framework; sourceTree = "<absolute>"; };
B15C7B681C197A8300C92958 /* LSLog-XCode.xcscheme */ = {isa = PBXFileReference; lastKnownFileType = text.xml; name = "LSLog-XCode.xcscheme"; path = "LSLog-XCode.xcodeproj/xcshareddata/xcschemes/LSLog-XCode.xcscheme"; sourceTree = SOURCE_ROOT; };
B15C7B6A1C197A8300C92958 /* LSLog.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = LSLog.h; sourceTree = "<group>"; };
B15C7B6B1C197A8300C92958 /* LSLog.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LSLog.m; sourceTree = "<group>"; };
B15C7B701C197A8300C92958 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
B15C7B7B1C19873500C92958 /* NSObject+LSLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+LSLog.h"; sourceTree = "<group>"; };
B15C7B7C1C19873500C92958 /* NSObject+LSLog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+LSLog.m"; sourceTree = "<group>"; };
B15C7B7E1C19878C00C92958 /* NSTextStorage+LSLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSTextStorage+LSLog.h"; sourceTree = "<group>"; };
B15C7B7F1C19878C00C92958 /* NSTextStorage+LSLog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSTextStorage+LSLog.m"; sourceTree = "<group>"; };
B15C7B811C1A665B00C92958 /* NSObject+LSSwizzle.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSObject+LSSwizzle.h"; sourceTree = "<group>"; };
B15C7B821C1A665B00C92958 /* NSObject+LSSwizzle.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSObject+LSSwizzle.m"; sourceTree = "<group>"; };
B15C7B871C1A6F7200C92958 /* LSIDEConsoleArea.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSIDEConsoleArea.h; sourceTree = "<group>"; };
B15C7B881C1A6F7200C92958 /* LSIDEConsoleArea.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LSIDEConsoleArea.m; sourceTree = "<group>"; };
B15C7B8A1C1A726A00C92958 /* LSIDEConsoleItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSIDEConsoleItem.h; sourceTree = "<group>"; };
B15C7B8B1C1A726A00C92958 /* LSIDEConsoleItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LSIDEConsoleItem.m; sourceTree = "<group>"; };
B1944C521C27BB4C006071E7 /* LSIDEConsoleArea.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSIDEConsoleArea.h; sourceTree = "<group>"; };
B1944C531C27BB4C006071E7 /* LSIDEConsoleArea.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LSIDEConsoleArea.m; sourceTree = "<group>"; };
B1944C541C27BB4C006071E7 /* LSIDEConsoleItem.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSIDEConsoleItem.h; sourceTree = "<group>"; };
B1944C551C27BB4C006071E7 /* LSIDEConsoleItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LSIDEConsoleItem.m; sourceTree = "<group>"; };
B1944C561C27BB4C006071E7 /* LSLog.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = LSLog.h; sourceTree = "<group>"; };
B1944C571C27BB4C006071E7 /* LSLog.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = LSLog.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -102,12 +102,7 @@
children = (
B136427F1C1AC81F00D82640 /* Settings */,
B15C7B7A1C19873500C92958 /* Category */,
B15C7B6A1C197A8300C92958 /* LSLog.h */,
B15C7B6B1C197A8300C92958 /* LSLog.m */,
B15C7B871C1A6F7200C92958 /* LSIDEConsoleArea.h */,
B15C7B881C1A6F7200C92958 /* LSIDEConsoleArea.m */,
B15C7B8A1C1A726A00C92958 /* LSIDEConsoleItem.h */,
B15C7B8B1C1A726A00C92958 /* LSIDEConsoleItem.m */,
B1944C511C27BB4C006071E7 /* LSLog */,
B15C7B671C197A8300C92958 /* Supporting Files */,
);
path = "LSLog-XCode";
Expand Down Expand Up @@ -135,6 +130,19 @@
path = Category;
sourceTree = "<group>";
};
B1944C511C27BB4C006071E7 /* LSLog */ = {
isa = PBXGroup;
children = (
B1944C521C27BB4C006071E7 /* LSIDEConsoleArea.h */,
B1944C531C27BB4C006071E7 /* LSIDEConsoleArea.m */,
B1944C541C27BB4C006071E7 /* LSIDEConsoleItem.h */,
B1944C551C27BB4C006071E7 /* LSIDEConsoleItem.m */,
B1944C561C27BB4C006071E7 /* LSLog.h */,
B1944C571C27BB4C006071E7 /* LSLog.m */,
);
path = LSLog;
sourceTree = "<group>";
};
/* End PBXGroup section */

/* Begin PBXNativeTarget section */
Expand Down Expand Up @@ -203,10 +211,10 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
B15C7B8C1C1A726A00C92958 /* LSIDEConsoleItem.m in Sources */,
B15C7B891C1A6F7200C92958 /* LSIDEConsoleArea.m in Sources */,
B1944C591C27BB4C006071E7 /* LSIDEConsoleItem.m in Sources */,
B1944C581C27BB4C006071E7 /* LSIDEConsoleArea.m in Sources */,
B15C7B7D1C19873500C92958 /* NSObject+LSLog.m in Sources */,
B15C7B6C1C197A8300C92958 /* LSLog.m in Sources */,
B1944C5A1C27BB4C006071E7 /* LSLog.m in Sources */,
B13642821C1AC83700D82640 /* LSLogSettings.m in Sources */,
B136428B1C1D83E600D82640 /* LSLogSettingsWindowController.m in Sources */,
B15C7B801C19878C00C92958 /* NSTextStorage+LSLog.m in Sources */,
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,20 @@ - (BOOL)_shouldAppendItem:(id)obj {
[cachedItems setObject:obj forKey:@([obj timestamp])];
}

NSInteger filterMode = [[self valueForKey:@"filterMode"] intValue];
BOOL shouldShowLogLevel = YES;
BOOL isForcedShow = [[obj valueForKey:@"input"] boolValue]
|| [[obj valueForKey:@"prompt"] boolValue]
|| [[obj valueForKey:@"outputRequestedByUser"] boolValue]
|| [[obj valueForKey:@"adaptorType"] hasSuffix:@".Debugger"];
|| [[obj valueForKey:@"prompt"] boolValue]
|| [[obj valueForKey:@"outputRequestedByUser"] boolValue]
|| [[obj valueForKey:@"adaptorType"] hasSuffix:@".Debugger"];
if (isForcedShow) {
return YES;
}

NSInteger filterMode = [[self valueForKey:@"filterMode"] intValue];
BOOL shouldShowLogLevel = NO;
if (filterMode >= LSLogLevelVerbose) {
shouldShowLogLevel = [obj logLevel] >= filterMode || isForcedShow;
shouldShowLogLevel = [obj logLevel] >= filterMode;
} else {
shouldShowLogLevel = [LSLog.originalShouldAppendItemIMP(self, _cmd, obj) boolValue];
shouldShowLogLevel = [[LSLog originalShouldAppendItemIMP](self, _cmd, obj) boolValue];
}

if (!shouldShowLogLevel) {
Expand All @@ -54,19 +58,19 @@ - (BOOL)_shouldAppendItem:(id)obj {
// Match with regex
NSError *error;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:filterString
options:(NSRegularExpressionCaseInsensitive|NSRegularExpressionDotMatchesLineSeparators)
error:&error];
options:(NSRegularExpressionCaseInsensitive|NSRegularExpressionDotMatchesLineSeparators)
error:&error];
NSString *content = [obj content];
NSArray *matches = [regex matchesInString:content options:0 range:NSMakeRange(0, content.length)];
if ([matches count] > 0 || isForcedShow) {
if ([matches count] > 0) {
return YES;
}

return NO;
}

- (void)_clearText {
LSLog.originalClearTextIMP(self, _cmd);
[LSLog originalClearTextIMP](self, _cmd);
[[LSLog originalConsoleAreaItemsDict] removeObjectForKey:[self ls_hash]];
}

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@

#import "LSIDEConsoleItem.h"
#import "LSLog.h"
#import "LSLogSettings.h"
#import "NSObject+LSLog.h"

@implementation LSIDEConsoleItem

- (id)initWithAdaptorType:(id)arg1 content:(id)arg2 kind:(int)arg3 {
id item = LSLog.originalConsoleItemInitIMP(self, _cmd, arg1, arg2, arg3);
id item = [LSLog originalConsoleItemInitIMP](self, _cmd, arg1, arg2, arg3);
if (![LSLog hasXcodeColorsInstalled]) {
[self ls_updateItemAttribute:item];
}
Expand Down
4 changes: 2 additions & 2 deletions LSLog-XCode/LSLog.h → LSLog-XCode/LSLog/LSLog.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ extern NSMutableArray *originalConsoleItems;
+ (instancetype)sharedPlugin;

/**
* NSMutableDictionary<Obj : NSMutableDictionary<@timestamp, item>>
* NSMutableDictionary<Obj : NSMutableDictionary<@timestamp, IDEConsoleItem>>
*
* @return Cached console items
*/
+ (NSMutableDictionary *)originalConsoleAreaItemsDict;
+ (BOOL)hasXcodeColorsInstalled;
+ (IMP)originalShouldAppendItemIMP;
+ (IMP)originalClearTextIMP;
+ (IMP)originalConsoleItemInitIMP;
+ (BOOL)hasXcodeColorsInstalled;

@end
35 changes: 13 additions & 22 deletions LSLog-XCode/LSLog.m → LSLog-XCode/LSLog/LSLog.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
static BOOL _hasXcodeColorsInstalled = NO;


@interface LSLog() <NSSearchFieldDelegate>
@interface LSLog()

@property (nonatomic, strong, readwrite) LSLogSettingsWindowController *settingsPanel;

Expand Down Expand Up @@ -111,12 +111,14 @@ - (void)onIDEControlGroupDidChange:(NSNotification*)notification {
});
}

- (void)onFilterFieldDidChange:(NSNotification*)notification {
if (![[notification object] isMemberOfClass:[NSSearchField class]]) {
return;
}

NSSearchField *searchField = [notification object];
#pragma mark - Action

- (void)onSettingsButtonClicked:(NSButton *)sender {
self.settingsPanel = [[LSLogSettingsWindowController alloc] initWithWindowNibName:@"LSLogSettingsWindowController"];
[self.settingsPanel showWindow:self.settingsPanel];
}

- (void)onFilterFieldDidEnter:(NSSearchField *)searchField {
if (![searchField respondsToSelector:@selector(consoleTextView)]) {
return;
}
Expand All @@ -135,26 +137,15 @@ - (void)onFilterFieldDidChange:(NSNotification*)notification {
}

if ([consoleArea respondsToSelector:@selector(_appendItems:)]) {

NSMutableDictionary *cacheItems = [[LSLog originalConsoleAreaItemsDict] objectForKey:[consoleArea ls_hash]];
NSArray *sortedKeys = [[cacheItems allKeys] sortedArrayUsingSelector:@selector(compare:)];
NSMutableArray *sortedItems = [NSMutableArray array];
for (NSNumber *key in sortedKeys) {
[sortedItems addObject:cacheItems[key]];
}
NSArray *sortedItems = [cacheItems objectsForKeys:sortedKeys notFoundMarker:[NSClassFromString(@"IDEConsoleItem") new]];

[consoleArea performSelector:@selector(_appendItems:) withObject:sortedItems];
}
#pragma clang diagnostic pop
}

#pragma mark - Action

- (void)onSettingsButtonClicked:(NSButton *)sender {
self.settingsPanel = [[LSLogSettingsWindowController alloc] initWithWindowNibName:@"LSLogSettingsWindowController"];
[self.settingsPanel showWindow:self.settingsPanel];
}

#pragma mark - Private

- (void)addFilterViews {
Expand Down Expand Up @@ -236,12 +227,12 @@ - (void)addFilterViews {
filterField.tag = LSLogViewTagFilterField;
filterField.autoresizingMask = NSViewMinXMargin | NSViewMinYMargin;
filterField.font = [NSFont systemFontOfSize:11.0];
filterField.delegate = self;
filterField.sendsWholeSearchString = YES;
[filterField setTarget:self];
[filterField setAction:@selector(onFilterFieldDidEnter:)];
filterField.consoleTextView = (NSTextView *)consoleTextView;
[filterField.cell setPlaceholderString:@"Regular Expression"];
[scopeBarView addSubview:filterField];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(onFilterFieldDidChange:) name:NSControlTextDidChangeNotification object:nil];
}

- (NSView *)getViewByClassName:(NSString *)className inContainerView:(NSView *)container {
Expand Down

0 comments on commit b8ee48b

Please sign in to comment.