Skip to content

Commit

Permalink
dynamic cell height in plugin list
Browse files Browse the repository at this point in the history
  • Loading branch information
nate-parrott committed Nov 10, 2014
1 parent aa5d3ab commit 61d347a
Show file tree
Hide file tree
Showing 9 changed files with 194 additions and 52 deletions.
2 changes: 2 additions & 0 deletions FlashlightApp/EasySIMBL/PluginListController.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@

@property (nonatomic,weak) IBOutlet NSArrayController *arrayController;

@property (nonatomic) IBOutlet NSTableView *tableView;

- (IBAction)reloadPluginsFromWeb:(id)sender;

- (void)installPlugin:(PluginModel *)plugin;
Expand Down
18 changes: 17 additions & 1 deletion FlashlightApp/EasySIMBL/PluginListController.m
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,32 @@ - (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
- (void)tableView:(NSTableView *)tableView didAddRowView:(NSTableRowView *)rowView forRow:(NSInteger)row {
((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;
Expand Down
2 changes: 2 additions & 0 deletions FlashlightApp/EasySIMBL/PluginModel.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,6 @@

+ (NSArray *)mergeDuplicates:(NSArray *)models;

@property (nonatomic,readonly) NSAttributedString *attributedString;

@end
7 changes: 7 additions & 0 deletions FlashlightApp/EasySIMBL/PluginModel.m
Original file line number Diff line number Diff line change
Expand Up @@ -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
116 changes: 68 additions & 48 deletions FlashlightApp/EasySIMBL/en.lproj/MainMenu.xib

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -251,6 +252,8 @@
5F97AD3F1A0AC51B00838C7C /* _SS_PluginRunner.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = _SS_PluginRunner.m; sourceTree = "<group>"; };
5F97AD441A0B0A2E00838C7C /* NSTask+_FlashlightExtensions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSTask+_FlashlightExtensions.h"; sourceTree = "<group>"; };
5F97AD451A0B0A2E00838C7C /* NSTask+_FlashlightExtensions.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "NSTask+_FlashlightExtensions.m"; sourceTree = "<group>"; };
5FB199011A105BD10048DC46 /* _SS_InlineWebViewContainer.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = _SS_InlineWebViewContainer.h; sourceTree = "<group>"; };
5FB199021A105BD10048DC46 /* _SS_InlineWebViewContainer.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = _SS_InlineWebViewContainer.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6250" systemVersion="14A361c" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="6250" systemVersion="14B17" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none" useAutolayout="YES" customObjectInstantitationMethod="direct">
<dependencies>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="6250"/>
<plugIn identifier="com.apple.WebKitIBPlugin" version="6250"/>
Expand All @@ -12,23 +12,37 @@
</customObject>
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
<customObject id="-3" userLabel="Application" customClass="NSObject"/>
<customView id="c22-O7-iKe">
<customView id="c22-O7-iKe" customClass="_SS_InlineWebViewContainer">
<rect key="frame" x="0.0" y="0.0" width="480" height="272"/>
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
<subviews>
<webView translatesAutoresizingMaskIntoConstraints="NO" id="HDd-zA-9Ah">
<rect key="frame" x="0.0" y="0.0" width="480" height="272"/>
<webPreferences key="preferences" defaultFontSize="12" defaultFixedFontSize="12">
<webPreferences key="preferences" defaultFontSize="12" defaultFixedFontSize="12" plugInsEnabled="NO" javaEnabled="NO">
<nil key="identifier"/>
</webPreferences>
<connections>
<outlet property="frameLoadDelegate" destination="c22-O7-iKe" id="9DR-0q-C2C"/>
<outlet property="policyDelegate" destination="c22-O7-iKe" id="MUe-90-c4f"/>
</connections>
</webView>
<progressIndicator horizontalHuggingPriority="750" verticalHuggingPriority="750" maxValue="100" displayedWhenStopped="NO" bezeled="NO" indeterminate="YES" controlSize="small" style="spinning" translatesAutoresizingMaskIntoConstraints="NO" id="4Wr-Z3-AVi">
<rect key="frame" x="444" y="20" width="16" height="16"/>
</progressIndicator>
</subviews>
<constraints>
<constraint firstAttribute="trailing" secondItem="HDd-zA-9Ah" secondAttribute="trailing" id="AKE-A3-HIB"/>
<constraint firstAttribute="trailing" secondItem="4Wr-Z3-AVi" secondAttribute="trailing" constant="20" id="euj-QZ-QgC"/>
<constraint firstItem="HDd-zA-9Ah" firstAttribute="leading" secondItem="c22-O7-iKe" secondAttribute="leading" id="ltS-69-uGQ"/>
<constraint firstAttribute="bottom" secondItem="HDd-zA-9Ah" secondAttribute="bottom" id="oHv-bK-AJC"/>
<constraint firstItem="HDd-zA-9Ah" firstAttribute="top" secondItem="c22-O7-iKe" secondAttribute="top" id="tmk-OL-jcm"/>
<constraint firstAttribute="bottom" secondItem="4Wr-Z3-AVi" secondAttribute="bottom" constant="20" id="tvN-q2-YbJ"/>
</constraints>
<connections>
<outlet property="loader" destination="4Wr-Z3-AVi" id="xwL-z2-Fp4"/>
<outlet property="webView" destination="HDd-zA-9Ah" id="IKi-gO-fHb"/>
</connections>
</customView>
<userDefaultsController representsSharedInstance="YES" id="xiP-DD-W1h"/>
</objects>
</document>
Original file line number Diff line number Diff line change
@@ -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 <WebKit/WebKit.h>

@interface _SS_InlineWebViewContainer : NSView

@property (nonatomic) IBOutlet NSProgressIndicator *loader;
@property (nonatomic) IBOutlet WebView *webView;

@end
Original file line number Diff line number Diff line change
@@ -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<WebPolicyDecisionListener>)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<WebPolicyDecisionListener>)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<WebPolicyDecisionListener>)listener {
[listener use];
}

- (void)dealloc {
self.webView.policyDelegate = nil;
self.webView.frameLoadDelegate = nil;
[self.webView stopLoading:nil];
}

@end

0 comments on commit 61d347a

Please sign in to comment.