Skip to content
Snippets Groups Projects
Commit 837560d7 authored by George Nachman's avatar George Nachman
Browse files

Load patron names at runtime

parent 23b9c351
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="10117" systemVersion="15G31" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<?xml version="1.0" encoding="UTF-8"?>
<document type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="3.0" toolsVersion="11201" systemVersion="16A320" targetRuntime="MacOSX.Cocoa" propertyAccessControl="none">
<dependencies>
<deployment identifier="macosx"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="10117"/>
<plugIn identifier="com.apple.InterfaceBuilder.CocoaPlugin" version="11201"/>
</dependencies>
<objects>
<customObject id="-2" userLabel="File's Owner" customClass="iTermAboutWindowController">
Loading
Loading
@@ -40,15 +40,13 @@
<rect key="frame" x="0.0" y="0.0" width="165" height="92"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textView editable="NO" importsGraphics="NO" usesRuler="YES" usesFontPanel="YES" verticallyResizable="YES" spellingCorrection="YES" smartInsertDelete="YES" id="syc-QG-1mF">
<textView editable="NO" importsGraphics="NO" usesFontPanel="YES" usesRuler="YES" spellingCorrection="YES" smartInsertDelete="YES" id="syc-QG-1mF">
<rect key="frame" x="0.0" y="0.0" width="165" height="92"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
<size key="minSize" width="165" height="92"/>
<size key="maxSize" width="364" height="10000000"/>
<color key="insertionPointColor" white="0.0" alpha="1" colorSpace="calibratedWhite"/>
<size key="minSize" width="165" height="92"/>
<size key="maxSize" width="364" height="10000000"/>
</textView>
</subviews>
</clipView>
Loading
Loading
@@ -73,15 +71,13 @@
<rect key="frame" x="0.0" y="0.0" width="314" height="83"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<subviews>
<textView editable="NO" importsGraphics="NO" usesRuler="YES" usesFontPanel="YES" verticallyResizable="YES" spellingCorrection="YES" smartInsertDelete="YES" id="cP7-fE-CE6">
<textView editable="NO" importsGraphics="NO" usesFontPanel="YES" usesRuler="YES" spellingCorrection="YES" smartInsertDelete="YES" id="cP7-fE-CE6">
<rect key="frame" x="0.0" y="0.0" width="314" height="83"/>
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
<size key="minSize" width="314" height="83"/>
<size key="minSize" width="314" height="0.0"/>
<size key="maxSize" width="364" height="10000000"/>
<color key="insertionPointColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
<size key="minSize" width="314" height="83"/>
<size key="maxSize" width="364" height="10000000"/>
</textView>
</subviews>
</clipView>
Loading
Loading
Loading
Loading
@@ -35,19 +35,15 @@
title:@"Home Page\n"];
NSAttributedString *bugsAString =
[self attributedStringWithLinkToURL:@"https://iterm2.com/bugs"
title:@"Report a bug\n\n"];
title:@"Report a bug\n"];
NSAttributedString *creditsAString =
[self attributedStringWithLinkToURL:@"https://iterm2.com/credits"
title:@"Credits\n\n"];
NSDictionary *linkTextViewAttributes = @{ NSUnderlineStyleAttributeName: @(NSSingleUnderlineStyle),
NSForegroundColorAttributeName: [NSColor blueColor],
NSCursorAttributeName: [NSCursor pointingHandCursor] };
title:@"Credits"];
 
// Force IBOutlets to be bound by creating window.
[self window];
[_dynamicText setLinkTextAttributes:linkTextViewAttributes];
[_dynamicText setLinkTextAttributes:self.linkTextViewAttributes];
[[_dynamicText textStorage] deleteCharactersInRange:NSMakeRange(0, [[_dynamicText textStorage] length])];
[[_dynamicText textStorage] appendAttributedString:[[[NSAttributedString alloc] initWithString:versionString] autorelease]];
[[_dynamicText textStorage] appendAttributedString:webAString];
Loading
Loading
@@ -56,53 +52,66 @@
[_dynamicText setAlignment:NSCenterTextAlignment
range:NSMakeRange(0, [[_dynamicText textStorage] length])];
 
NSAttributedString *patronsAttributedString = [self patronsString];
[_patronsTextView setLinkTextAttributes:linkTextViewAttributes];
[[_patronsTextView textStorage] deleteCharactersInRange:NSMakeRange(0, [[_patronsTextView textStorage] length])];
[[_patronsTextView textStorage] appendAttributedString:patronsAttributedString];
[_patronsTextView setAlignment:NSLeftTextAlignment
range:NSMakeRange(0, [[_patronsTextView textStorage] length])];
_patronsTextView.horizontallyResizable = NO;
NSRect rect = _patronsTextView.enclosingScrollView.frame;
[_patronsTextView sizeToFit];
CGFloat diff = _patronsTextView.frame.size.height - rect.size.height;
rect.size.height = _patronsTextView.frame.size.height;
_patronsTextView.enclosingScrollView.frame = rect;
rect = self.window.frame;
rect.size.height += diff;
[self.window setFrame:rect display:YES];
[self setPatronsString:[self defaultPatronsString] animate:NO];
 
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
NSURL *url = [NSURL URLWithString:@"https://iterm2.com/patrons.txt"];
NSData *data = [NSData dataWithContentsOfURL:url];
NSString *string = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] autorelease];
NSArray<NSString *> *patronNames = string.length > 0 ? [string componentsSeparatedByString:@"\n"] : nil;
patronNames = [patronNames filteredArrayUsingBlock:^BOOL(NSString *name) {
return name.length > 0;
}];
dispatch_async(dispatch_get_main_queue(), ^{
[self setPatrons:patronNames];
});
});
}
return self;
}
 
- (NSAttributedString *)patronsString {
NSArray *patronNames = @[@"Aaron Kulbe",
@"Alex Howells",
@"Brian Gupta",
@"Brod",
@"Colin",
@"Colton Myers",
@"Daniel Collin",
@"Filip",
@"Han Zhang",
@"haoformayor",
@"James Dorn",
@"Karl Bunch",
@"Mark H Berger",
@"Matt Svoboda",
@"Ozzy Johnson",
@"Rob McGuire-Dale",
@"Roger Tokarek",
@"Ryan Sorensen",
@"Shunwen Hsiao",
@"Simo Kinnunen",
@"Stephan Telling",
@"Wayne Robinson"];
- (NSDictionary *)linkTextViewAttributes {
return @{ NSUnderlineStyleAttributeName: @(NSSingleUnderlineStyle),
NSForegroundColorAttributeName: [NSColor blueColor],
NSCursorAttributeName: [NSCursor pointingHandCursor] };
}
- (void)setPatronsString:(NSAttributedString *)patronsAttributedString animate:(BOOL)animate {
NSSize minSize = _patronsTextView.minSize;
minSize.height = 1;
_patronsTextView.minSize = minSize;
[_patronsTextView setLinkTextAttributes:self.linkTextViewAttributes];
[[_patronsTextView textStorage] deleteCharactersInRange:NSMakeRange(0, [[_patronsTextView textStorage] length])];
[[_patronsTextView textStorage] appendAttributedString:patronsAttributedString];
[_patronsTextView setAlignment:NSLeftTextAlignment
range:NSMakeRange(0, [[_patronsTextView textStorage] length])];
_patronsTextView.horizontallyResizable = NO;
NSRect rect = _patronsTextView.enclosingScrollView.frame;
[_patronsTextView sizeToFit];
CGFloat diff = _patronsTextView.frame.size.height - rect.size.height;
rect.size.height = _patronsTextView.frame.size.height;
_patronsTextView.enclosingScrollView.frame = rect;
rect = self.window.frame;
rect.size.height += diff;
[self.window setFrame:rect display:YES animate:animate];
}
- (NSAttributedString *)defaultPatronsString {
NSString *string = [NSString stringWithFormat:@"Loading supporters…"];
NSMutableAttributedString *attributedString =
[[[NSMutableAttributedString alloc] initWithString:string] autorelease];
return attributedString;
}
- (void)setPatrons:(NSArray *)patronNames {
if (!patronNames.count) {
[self setPatronsString:[[[NSAttributedString alloc] initWithString:@"Error loading patrons :("] autorelease] animate:NO];
return;
}
NSArray *sortedNames = [patronNames sortedArrayUsingComparator:^NSComparisonResult(id _Nonnull obj1, id _Nonnull obj2) {
return [[obj1 surname] compare:[obj2 surname]];
}];
Loading
Loading
@@ -116,7 +125,7 @@
NSAttributedString *period = [[[NSAttributedString alloc] initWithString:@"."] autorelease];
[attributedString appendAttributedString:period];
 
return attributedString;
[self setPatronsString:attributedString animate:YES];
}
 
- (NSAttributedString *)attributedStringWithLinkToURL:(NSString *)urlString title:(NSString *)title {
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment