From 61d347a047081ff517592ec118f8f8cc930a9325 Mon Sep 17 00:00:00 2001 From: nate-parrott Date: Mon, 10 Nov 2014 00:27:39 -0500 Subject: [PATCH] dynamic cell height in plugin list --- .../EasySIMBL/PluginListController.h | 2 + .../EasySIMBL/PluginListController.m | 18 ++- FlashlightApp/EasySIMBL/PluginModel.h | 2 + FlashlightApp/EasySIMBL/PluginModel.m | 7 ++ FlashlightApp/EasySIMBL/en.lproj/MainMenu.xib | 116 ++++++++++-------- .../SpotlightSIMBL.xcodeproj/project.pbxproj | 6 + .../SPOpenAPIPreviewViewController.xib | 20 ++- .../_SS_InlineWebViewContainer.h | 16 +++ .../_SS_InlineWebViewContainer.m | 59 +++++++++ 9 files changed, 194 insertions(+), 52 deletions(-) create mode 100644 FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/_SS_InlineWebViewContainer.h create mode 100644 FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/_SS_InlineWebViewContainer.m diff --git a/FlashlightApp/EasySIMBL/PluginListController.h b/FlashlightApp/EasySIMBL/PluginListController.h index 64b45a09..ad37d39c 100644 --- a/FlashlightApp/EasySIMBL/PluginListController.h +++ b/FlashlightApp/EasySIMBL/PluginListController.h @@ -14,6 +14,8 @@ @property (nonatomic,weak) IBOutlet NSArrayController *arrayController; +@property (nonatomic) IBOutlet NSTableView *tableView; + - (IBAction)reloadPluginsFromWeb:(id)sender; - (void)installPlugin:(PluginModel *)plugin; diff --git a/FlashlightApp/EasySIMBL/PluginListController.m b/FlashlightApp/EasySIMBL/PluginListController.m index 80be5c59..f0ad2dd9 100644 --- a/FlashlightApp/EasySIMBL/PluginListController.m +++ b/FlashlightApp/EasySIMBL/PluginListController.m @@ -35,9 +35,13 @@ - (void)awakeFromNib { [self startWatchingPluginsDir]; [self reloadFromDisk]; [self reloadPluginsFromWeb:nil]; + + [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resized) name:NSViewFrameDidChangeNotification object:self.tableView]; + [self.tableView setPostsFrameChangedNotifications:YES]; } - (void)dealloc { - [self startWatchingPluginsDir]; + [[NSNotificationCenter defaultCenter] removeObserver:self]; + [self stopWatchingPluginsDir]; } #pragma mark UI @@ -45,6 +49,18 @@ - (void)tableView:(NSTableView *)tableView didAddRowView:(NSTableRowView *)rowVi ((PluginCellView *)[rowView viewAtColumn:0]).listController = self; } +- (void)resized { + [self.tableView noteHeightOfRowsWithIndexesChanged:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(0, [self.arrayController.arrangedObjects count])]]; +} + +- (CGFloat)tableView:(NSTableView *)tableView heightOfRow:(NSInteger)row { + CGFloat leftInset = 7; + CGFloat topInset = 7; + CGFloat bottomInset = 7; + CGFloat rightInset = 65; + return [[[self.arrayController.arrangedObjects objectAtIndex:row] attributedString] boundingRectWithSize:CGSizeMake(tableView.bounds.size.width-leftInset-rightInset, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin].size.height + topInset + bottomInset; +} + - (NSIndexSet *)tableView:(NSTableView *)tableView selectionIndexesForProposedSelection:(NSIndexSet *)proposedSelectionIndexes { return nil; diff --git a/FlashlightApp/EasySIMBL/PluginModel.h b/FlashlightApp/EasySIMBL/PluginModel.h index 0c652ed1..a395d2db 100644 --- a/FlashlightApp/EasySIMBL/PluginModel.h +++ b/FlashlightApp/EasySIMBL/PluginModel.h @@ -20,4 +20,6 @@ + (NSArray *)mergeDuplicates:(NSArray *)models; +@property (nonatomic,readonly) NSAttributedString *attributedString; + @end diff --git a/FlashlightApp/EasySIMBL/PluginModel.m b/FlashlightApp/EasySIMBL/PluginModel.m index e6d97dc2..d8c532b5 100644 --- a/FlashlightApp/EasySIMBL/PluginModel.m +++ b/FlashlightApp/EasySIMBL/PluginModel.m @@ -60,4 +60,11 @@ - (PluginModel *)mergeWith:(PluginModel *)other { } } +- (NSAttributedString *)attributedString { + NSMutableAttributedString* s = [NSMutableAttributedString new]; + [s appendAttributedString:[[NSAttributedString alloc] initWithString:[self.displayName stringByAppendingString:@"\n"] attributes:@{NSFontAttributeName: [NSFont boldSystemFontOfSize:[NSFont systemFontSize]]}]]; + [s appendAttributedString:[[NSAttributedString alloc] initWithString:self.pluginDescription attributes:@{NSFontAttributeName: [NSFont systemFontOfSize:[NSFont systemFontSize]]}]]; + return s; +} + @end diff --git a/FlashlightApp/EasySIMBL/en.lproj/MainMenu.xib b/FlashlightApp/EasySIMBL/en.lproj/MainMenu.xib index 34406991..6d6bb0a4 100755 --- a/FlashlightApp/EasySIMBL/en.lproj/MainMenu.xib +++ b/FlashlightApp/EasySIMBL/en.lproj/MainMenu.xib @@ -1,5 +1,5 @@ - + @@ -660,16 +660,15 @@ - + - + - @@ -680,7 +679,7 @@ - + @@ -697,48 +696,46 @@ - - - - - - - - - - - - - - - + + - + - + - + + + + - - - + + + + + + + + + + + + - @@ -763,47 +760,48 @@ - + - + + + + - + - - + + + + + + + + + + + + + @@ -822,9 +845,8 @@ - - - + - Are you sure you want to uninstall @@ -855,9 +875,8 @@ Gw - + - @@ -871,6 +890,7 @@ Gw + diff --git a/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL.xcodeproj/project.pbxproj b/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL.xcodeproj/project.pbxproj index 21d02f83..23f48b58 100644 --- a/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL.xcodeproj/project.pbxproj +++ b/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL.xcodeproj/project.pbxproj @@ -24,6 +24,7 @@ 5F5B18441A07197500809207 /* SPOpenAPIPreviewViewController.xib in Resources */ = {isa = PBXBuildFile; fileRef = 5F5B18431A07197500809207 /* SPOpenAPIPreviewViewController.xib */; }; 5F97AD401A0AC51B00838C7C /* _SS_PluginRunner.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F97AD3F1A0AC51B00838C7C /* _SS_PluginRunner.m */; }; 5F97AD461A0B0A2E00838C7C /* NSTask+_FlashlightExtensions.m in Sources */ = {isa = PBXBuildFile; fileRef = 5F97AD451A0B0A2E00838C7C /* NSTask+_FlashlightExtensions.m */; }; + 5FB199031A105BD10048DC46 /* _SS_InlineWebViewContainer.m in Sources */ = {isa = PBXBuildFile; fileRef = 5FB199021A105BD10048DC46 /* _SS_InlineWebViewContainer.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -251,6 +252,8 @@ 5F97AD3F1A0AC51B00838C7C /* _SS_PluginRunner.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = _SS_PluginRunner.m; sourceTree = ""; }; 5F97AD441A0B0A2E00838C7C /* NSTask+_FlashlightExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSTask+_FlashlightExtensions.h"; sourceTree = ""; }; 5F97AD451A0B0A2E00838C7C /* NSTask+_FlashlightExtensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSTask+_FlashlightExtensions.m"; sourceTree = ""; }; + 5FB199011A105BD10048DC46 /* _SS_InlineWebViewContainer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _SS_InlineWebViewContainer.h; sourceTree = ""; }; + 5FB199021A105BD10048DC46 /* _SS_InlineWebViewContainer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = _SS_InlineWebViewContainer.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -292,6 +295,8 @@ 5F5B18211A059DB100809207 /* SPOpenAPIQuery.m */, 5F5B183D1A06CB0000809207 /* SPOpenAPIResult.h */, 5F5B183E1A06CB0000809207 /* SPOpenAPIResult.m */, + 5FB199011A105BD10048DC46 /* _SS_InlineWebViewContainer.h */, + 5FB199021A105BD10048DC46 /* _SS_InlineWebViewContainer.m */, 5F97AD3E1A0AC51B00838C7C /* _SS_PluginRunner.h */, 5F97AD3F1A0AC51B00838C7C /* _SS_PluginRunner.m */, 5F97AD441A0B0A2E00838C7C /* NSTask+_FlashlightExtensions.h */, @@ -621,6 +626,7 @@ 5F5B183C1A06C6EE00809207 /* NSObject+LogProperties.m in Sources */, 5F5B18351A05A1A000809207 /* RTProtocol.m in Sources */, 5F5B18221A059DB100809207 /* SPOpenAPIQuery.m in Sources */, + 5FB199031A105BD10048DC46 /* _SS_InlineWebViewContainer.m in Sources */, 5F5B18361A05A1A000809207 /* RTUnregisteredClass.m in Sources */, 5F5B174D1A05758800809207 /* _Flashlight_Bootstrap.m in Sources */, 5F5B18321A05A1A000809207 /* RTIvar.m in Sources */, diff --git a/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/SPOpenAPIPreviewViewController.xib b/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/SPOpenAPIPreviewViewController.xib index acf3b4c9..9396f161 100644 --- a/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/SPOpenAPIPreviewViewController.xib +++ b/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/SPOpenAPIPreviewViewController.xib @@ -1,5 +1,5 @@ - + @@ -12,23 +12,37 @@ - + - + + + + + + + + + + + + + + + diff --git a/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/_SS_InlineWebViewContainer.h b/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/_SS_InlineWebViewContainer.h new file mode 100644 index 00000000..5403483a --- /dev/null +++ b/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/_SS_InlineWebViewContainer.h @@ -0,0 +1,16 @@ +// +// _SS_InlineWebView.h +// SpotlightSIMBL +// +// Created by Nate Parrott on 11/9/14. +// Copyright (c) 2014 Nate Parrott. All rights reserved. +// + +#import + +@interface _SS_InlineWebViewContainer : NSView + +@property (nonatomic) IBOutlet NSProgressIndicator *loader; +@property (nonatomic) IBOutlet WebView *webView; + +@end diff --git a/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/_SS_InlineWebViewContainer.m b/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/_SS_InlineWebViewContainer.m new file mode 100644 index 00000000..89a8f264 --- /dev/null +++ b/FlashlightApp/SpotlightSIMBL/SpotlightSIMBL/_SS_InlineWebViewContainer.m @@ -0,0 +1,59 @@ +// +// _SS_InlineWebView.m +// SpotlightSIMBL +// +// Created by Nate Parrott on 11/9/14. +// Copyright (c) 2014 Nate Parrott. All rights reserved. +// + +#import "_SS_InlineWebViewContainer.h" + +@implementation _SS_InlineWebViewContainer + +- (void)webView:(WebView *)sender didStartProvisionalLoadForFrame:(WebFrame *)frame { + dispatch_async(dispatch_get_main_queue(), ^{ + if (frame == sender.mainFrame) { + [self.loader startAnimation:nil]; + } + }); +} + +- (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame { + dispatch_async(dispatch_get_main_queue(), ^{ + if (frame == sender.mainFrame) { + [self.loader stopAnimation:nil]; + } + }); +} + +- (void)webView:(WebView *)webView decidePolicyForNewWindowAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request newFrameName:(NSString *)frameName decisionListener:(id)listener { + NSLog(@"Decide window policy: %@", actionInformation); + dispatch_async(dispatch_get_main_queue(), ^{ + [[NSWorkspace sharedWorkspace] openURL:request.URL]; + }); + [listener ignore]; +} + +- (void)webView:(WebView *)webView decidePolicyForNavigationAction:(NSDictionary *)actionInformation request:(NSURLRequest *)request newFrameName:(NSString *)frameName decisionListener:(id)listener { + NSLog(@"Decide policy: %@", actionInformation); + if ([actionInformation[WebActionNavigationTypeKey] isEqualToString:WebNavigationTypeLinkClicked]) { + dispatch_async(dispatch_get_main_queue(), ^{ + [[NSWorkspace sharedWorkspace] openURL:request.URL]; + }); + [listener ignore]; + } else { + [listener use]; + } +} + +- (void)webView:(WebView *)webView decidePolicyForMIMEType:(NSString *)type request:(NSURLRequest *)request frame:(WebFrame *)frame decisionListener:(id)listener { + [listener use]; +} + +- (void)dealloc { + self.webView.policyDelegate = nil; + self.webView.frameLoadDelegate = nil; + [self.webView stopLoading:nil]; +} + +@end