Skip to content

Commit eca0f1a

Browse files
committed
Highlight colors are now fully configurable through the preferences window. Added a reset button.
1 parent fed1b54 commit eca0f1a

7 files changed

Lines changed: 105 additions & 57 deletions

XcodeBoost/MFHighlighter.m

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ - (id)init
2424
self = [super init];
2525
if (self)
2626
{
27-
[self setupHighlightColors];
27+
[self updateHighlightColors];
2828
}
2929
return self;
3030
}
3131

32-
- (void)setupHighlightColors
32+
- (void)updateHighlightColors
3333
{
3434
NSColor *color1 = [[NSUserDefaults standardUserDefaults] xb_colorForKey:XBHighlightColor1Key];
3535
NSColor *color2 = [[NSUserDefaults standardUserDefaults] xb_colorForKey:XBHighlightColor2Key];
@@ -47,6 +47,8 @@ - (NSColor *)pushHighlightColor
4747

4848
if (_highlightCount < [_highlightColors count])
4949
{
50+
[self updateHighlightColors];
51+
5052
color = _highlightColors[_highlightCount];
5153
}
5254
else

XcodeBoost/MFPreferencesWindowController.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#pragma mark Action Methods
2323

24-
- (IBAction)colorChanged:(id)sender;
24+
- (IBAction)well_colorChanged:(id)sender;
25+
- (IBAction)resetColors_clicked:(id)sender;
2526

2627
@end

XcodeBoost/MFPreferencesWindowController.m

Lines changed: 31 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77
//
88

99
#import "XcodeBoostConstants.h"
10+
#import "NSColor+XcodeBoost.h"
1011
#import "NSUserDefaults+XcodeBoost.h"
1112
#import "MFPreferencesWindowController.h"
1213

1314
@implementation MFPreferencesWindowController
1415
{
15-
NSUserDefaults *_defaults;
16+
NSDictionary *_defaults;
17+
NSUserDefaults *_userDefaults;
1618
}
1719

1820
#pragma mark Lifetime
@@ -23,41 +25,56 @@ - (id)initWithBundle:(NSBundle *)bundle
2325
self = [super initWithWindowNibPath:nibPath owner:self];
2426
if (self)
2527
{
26-
_defaults = [NSUserDefaults standardUserDefaults];
28+
NSString *defaultsFilePath = [bundle pathForResource:@"Defaults" ofType:@"plist"];
29+
_defaults = [NSDictionary dictionaryWithContentsOfFile:defaultsFilePath];
30+
_userDefaults = [NSUserDefaults standardUserDefaults];
2731
}
2832
return self;
2933
}
3034

31-
- (void)windowDidLoad
35+
- (void)awakeFromNib
3236
{
33-
[super windowDidLoad];
34-
3537
[self loadHighlightColors];
3638
}
3739

3840
#pragma mark Highlighting
3941

42+
- (void)resetHighlightColors
43+
{
44+
[self.colorWell1 setColor:[NSColor xb_colorWithStringRepresentation:[_defaults objectForKey:XBHighlightColor1Key]]];
45+
[self.colorWell2 setColor:[NSColor xb_colorWithStringRepresentation:[_defaults objectForKey:XBHighlightColor2Key]]];
46+
[self.colorWell3 setColor:[NSColor xb_colorWithStringRepresentation:[_defaults objectForKey:XBHighlightColor3Key]]];
47+
[self.colorWell4 setColor:[NSColor xb_colorWithStringRepresentation:[_defaults objectForKey:XBHighlightColor4Key]]];
48+
49+
[self saveHighlightColors];
50+
}
51+
4052
- (void)loadHighlightColors
4153
{
42-
[self.colorWell1 setColor:[_defaults xb_colorForKey:XBHighlightColor1Key]];
43-
[self.colorWell2 setColor:[_defaults xb_colorForKey:XBHighlightColor2Key]];
44-
[self.colorWell3 setColor:[_defaults xb_colorForKey:XBHighlightColor3Key]];
45-
[self.colorWell4 setColor:[_defaults xb_colorForKey:XBHighlightColor4Key]];
54+
[self.colorWell1 setColor:[_userDefaults xb_colorForKey:XBHighlightColor1Key]];
55+
[self.colorWell2 setColor:[_userDefaults xb_colorForKey:XBHighlightColor2Key]];
56+
[self.colorWell3 setColor:[_userDefaults xb_colorForKey:XBHighlightColor3Key]];
57+
[self.colorWell4 setColor:[_userDefaults xb_colorForKey:XBHighlightColor4Key]];
4658
}
4759

4860
- (void)saveHighlightColors
4961
{
50-
[_defaults xb_setColor:self.colorWell1.color forKey:XBHighlightColor1Key];
51-
[_defaults xb_setColor:self.colorWell2.color forKey:XBHighlightColor2Key];
52-
[_defaults xb_setColor:self.colorWell3.color forKey:XBHighlightColor3Key];
53-
[_defaults xb_setColor:self.colorWell4.color forKey:XBHighlightColor4Key];
62+
[_userDefaults xb_setColor:self.colorWell1.color forKey:XBHighlightColor1Key];
63+
[_userDefaults xb_setColor:self.colorWell2.color forKey:XBHighlightColor2Key];
64+
[_userDefaults xb_setColor:self.colorWell3.color forKey:XBHighlightColor3Key];
65+
[_userDefaults xb_setColor:self.colorWell4.color forKey:XBHighlightColor4Key];
5466
}
5567

5668
#pragma mark Action Methods
5769

58-
- (IBAction)colorChanged:(id)sender
70+
- (IBAction)well_colorChanged:(id)sender
5971
{
6072
[self saveHighlightColors];
6173
}
6274

75+
- (IBAction)resetColors_clicked:(id)sender
76+
{
77+
[self resetHighlightColors];
78+
}
79+
6380
@end

XcodeBoost/NSColor+XcodeBoost.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,9 @@
2323
- (NSColor *)interpolateFrom:(NSColor *)fromColor percentage:(float)percentage;
2424
- (NSColor *)interpolateTo:(NSColor *)toColor percentage:(float)percentage;
2525

26+
#pragma mark String Representation
27+
28+
+ (NSColor *)xb_colorWithStringRepresentation:(NSString *)stringRepresentation;
29+
- (NSString *)xb_stringRepresentation;
30+
2631
@end

XcodeBoost/NSColor+XcodeBoost.m

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// Copyright (c) 2014 Michaël Fortin. All rights reserved.
77
//
88

9+
#import "Collector.h"
910
#import "NSColor+XcodeBoost.h"
1011

1112
@implementation NSColor (XcodeBoost)
@@ -56,6 +57,38 @@ - (NSColor *)interpolateTo:(NSColor *)toColor percentage:(float)percentage
5657
return [NSColor interpolateFrom:self to:toColor percentage:percentage];
5758
}
5859

60+
#pragma mark String Representation
61+
62+
+ (NSColor *)xb_colorWithStringRepresentation:(NSString *)stringRepresentation
63+
{
64+
NSString *componentsString = [stringRepresentation substringFromIndex:6];
65+
NSArray *components = [[componentsString componentsSeparatedByString:@","] ct_map:^id(NSString *string)
66+
{
67+
return [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
68+
}];
69+
70+
if ([components count] != 4)
71+
{
72+
NSString *reason = [NSString stringWithFormat:@"Couldn't parse color from string %@", stringRepresentation];
73+
@throw [NSException exceptionWithName:@"XcodeBoost Exception" reason:reason userInfo:nil];
74+
}
75+
76+
CGFloat red = [components[0] floatValue];
77+
CGFloat green = [components[1] floatValue];
78+
CGFloat blue = [components[2] floatValue];
79+
CGFloat alpha = [components[3] floatValue];
80+
81+
return [NSColor colorWithCalibratedRed:red green:green blue:blue alpha:alpha];
82+
}
83+
84+
- (NSString *)xb_stringRepresentation
85+
{
86+
CGFloat red, green, blue, alpha;
87+
[self getRed:&red green:&green blue:&blue alpha:&alpha];
88+
89+
return [NSString stringWithFormat:@"color(%f, %f, %f, %f)", red, green, blue, alpha];
90+
}
91+
5992
#pragma mark Helper Functions
6093

6194
CGFloat XBInterpolate(CGFloat value, CGFloat start, CGFloat end)

XcodeBoost/NSUserDefaults+XcodeBoost.m

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,18 @@
88

99
#import "Collector.h"
1010
#import "NSUserDefaults+XcodeBoost.h"
11+
#import "NSColor+XcodeBoost.h"
1112

1213
@implementation NSUserDefaults (XcodeBoost)
1314

1415
- (NSColor *)xb_colorForKey:(NSString *)key
1516
{
16-
NSString *stringRepresentation = [self stringForKey:key];
17-
NSString *componentsString = [stringRepresentation substringFromIndex:6];
18-
NSArray *components = [[componentsString componentsSeparatedByString:@","] ct_map:^id(NSString *string)
19-
{
20-
return [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
21-
}];
22-
23-
if ([components count] != 4)
24-
{
25-
NSString *reason = [NSString stringWithFormat:@"Couldn't parse color from string %@", stringRepresentation];
26-
@throw [NSException exceptionWithName:@"XcodeBoost Exception" reason:reason userInfo:nil];
27-
}
28-
29-
CGFloat red = [components[0] floatValue];
30-
CGFloat green = [components[1] floatValue];
31-
CGFloat blue = [components[2] floatValue];
32-
CGFloat alpha = [components[3] floatValue];
33-
34-
return [NSColor colorWithCalibratedRed:red green:green blue:blue alpha:alpha];
17+
return [NSColor xb_colorWithStringRepresentation:[self stringForKey:key]];
3518
}
3619

3720
- (void)xb_setColor:(NSColor *)color forKey:(NSString *)key
3821
{
39-
CGFloat red, green, blue, alpha;
40-
[color getRed:&red green:&green blue:&blue alpha:&alpha];
41-
42-
NSString *stringRepresentation = [NSString stringWithFormat:@"color(%f, %f, %f, %f)", red, green, blue, alpha];
43-
44-
[self setObject:stringRepresentation forKey:key];
22+
[self setObject:[color xb_stringRepresentation] forKey:key];
4523
}
4624

4725
@end

XcodeBoost/PreferencesWindow.xib

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -10,75 +10,87 @@
1010
<outlet property="colorWell2" destination="TJd-vg-OPF" id="TMG-o4-6ih"/>
1111
<outlet property="colorWell3" destination="5A6-sq-JXe" id="Gxr-QI-5h6"/>
1212
<outlet property="colorWell4" destination="Nb7-V2-BBi" id="azg-RO-Kh7"/>
13+
<outlet property="resetColors_clicked" destination="KHB-0c-d9B" id="Yzp-JB-FOe"/>
1314
<outlet property="window" destination="QvC-M9-y7g" id="aYl-ru-0zi"/>
1415
</connections>
1516
</customObject>
1617
<customObject id="-1" userLabel="First Responder" customClass="FirstResponder"/>
1718
<customObject id="-3" userLabel="Application"/>
1819
<window title="XcodeBoost Preferences" allowsToolTipsWhenApplicationIsInactive="NO" autorecalculatesKeyViewLoop="NO" oneShot="NO" releasedWhenClosed="NO" animationBehavior="default" id="QvC-M9-y7g">
19-
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES" resizable="YES"/>
20+
<windowStyleMask key="styleMask" titled="YES" closable="YES" miniaturizable="YES"/>
2021
<windowPositionMask key="initialPositionMask" leftStrut="YES" rightStrut="YES" topStrut="YES" bottomStrut="YES"/>
21-
<rect key="contentRect" x="196" y="240" width="272" height="172"/>
22+
<rect key="contentRect" x="196" y="240" width="272" height="195"/>
2223
<rect key="screenRect" x="0.0" y="0.0" width="1440" height="878"/>
2324
<view key="contentView" id="EiT-Mj-1SZ">
24-
<rect key="frame" x="0.0" y="0.0" width="272" height="172"/>
25+
<rect key="frame" x="0.0" y="0.0" width="272" height="195"/>
2526
<autoresizingMask key="autoresizingMask"/>
2627
<subviews>
2728
<box autoresizesSubviews="NO" fixedFrame="YES" borderType="line" titlePosition="noTitle" translatesAutoresizingMaskIntoConstraints="NO" id="doK-rA-mI9">
28-
<rect key="frame" x="17" y="17" width="238" height="112"/>
29+
<rect key="frame" x="17" y="16" width="238" height="136"/>
2930
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
3031
<view key="contentView">
31-
<rect key="frame" x="1" y="1" width="236" height="110"/>
32+
<rect key="frame" x="1" y="1" width="236" height="134"/>
3233
<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>
3334
<subviews>
3435
<colorWell fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="1XK-6M-lIt">
35-
<rect key="frame" x="18" y="65" width="44" height="23"/>
36+
<rect key="frame" x="18" y="89" width="44" height="23"/>
3637
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
3738
<color key="color" red="0.05813049898" green="0.055541899059999997" blue="1" alpha="1" colorSpace="calibratedRGB"/>
3839
<connections>
39-
<action selector="colorChanged:" target="-2" id="sTg-Jh-gch"/>
40+
<action selector="well_colorChanged:" target="-2" id="0Fk-T3-RSR"/>
4041
</connections>
4142
</colorWell>
4243
<colorWell fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="TJd-vg-OPF">
43-
<rect key="frame" x="70" y="65" width="44" height="23"/>
44+
<rect key="frame" x="70" y="89" width="44" height="23"/>
4445
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
4546
<color key="color" red="0.05813049898" green="0.055541899059999997" blue="1" alpha="1" colorSpace="calibratedRGB"/>
4647
<connections>
47-
<action selector="colorChanged:" target="-2" id="olY-LI-buO"/>
48+
<action selector="well_colorChanged:" target="-2" id="YCV-Ys-eSZ"/>
4849
</connections>
4950
</colorWell>
5051
<colorWell fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="5A6-sq-JXe">
51-
<rect key="frame" x="122" y="65" width="44" height="23"/>
52+
<rect key="frame" x="122" y="89" width="44" height="23"/>
5253
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
5354
<color key="color" red="0.05813049898" green="0.055541899059999997" blue="1" alpha="1" colorSpace="calibratedRGB"/>
5455
<connections>
55-
<action selector="colorChanged:" target="-2" id="0gF-hQ-tiO"/>
56+
<action selector="well_colorChanged:" target="-2" id="SVw-rQ-8IE"/>
5657
</connections>
5758
</colorWell>
5859
<colorWell fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="Nb7-V2-BBi">
59-
<rect key="frame" x="174" y="65" width="44" height="23"/>
60+
<rect key="frame" x="174" y="89" width="44" height="23"/>
6061
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
6162
<color key="color" red="0.05813049898" green="0.055541899059999997" blue="1" alpha="1" colorSpace="calibratedRGB"/>
6263
<connections>
63-
<action selector="colorChanged:" target="-2" id="byF-EU-Pl2"/>
64+
<action selector="well_colorChanged:" target="-2" id="o9I-hC-lvw"/>
6465
</connections>
6566
</colorWell>
6667
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" setsMaxLayoutWidthAtFirstLayout="YES" translatesAutoresizingMaskIntoConstraints="NO" id="EGl-ZQ-yIS">
67-
<rect key="frame" x="21" y="24" width="194" height="28"/>
68+
<rect key="frame" x="21" y="48" width="194" height="28"/>
6869
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
6970
<textFieldCell key="cell" sendsActionOnEndEditing="YES" alignment="center" title="Beyond 4 highlights, colors will be chosen randomly by XcodeBoost." id="EK5-tP-Edo">
7071
<font key="font" metaFont="smallSystem"/>
7172
<color key="textColor" name="controlTextColor" catalog="System" colorSpace="catalog"/>
7273
<color key="backgroundColor" name="controlColor" catalog="System" colorSpace="catalog"/>
7374
</textFieldCell>
7475
</textField>
76+
<button verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="KHB-0c-d9B">
77+
<rect key="frame" x="81" y="7" width="74" height="32"/>
78+
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
79+
<buttonCell key="cell" type="push" title="Reset" bezelStyle="rounded" alignment="center" borderStyle="border" imageScaling="proportionallyDown" inset="2" id="jJ6-3v-jD7">
80+
<behavior key="behavior" pushIn="YES" lightByBackground="YES" lightByGray="YES"/>
81+
<font key="font" metaFont="system"/>
82+
</buttonCell>
83+
<connections>
84+
<action selector="resetColors_clicked:" target="-2" id="ECu-TB-GMM"/>
85+
</connections>
86+
</button>
7587
</subviews>
7688
</view>
7789
<color key="borderColor" white="0.0" alpha="0.41999999999999998" colorSpace="calibratedWhite"/>
7890
<color key="fillColor" white="0.0" alpha="0.0" colorSpace="calibratedWhite"/>
7991
</box>
8092
<textField horizontalHuggingPriority="251" verticalHuggingPriority="750" fixedFrame="YES" translatesAutoresizingMaskIntoConstraints="NO" id="lN7-Uo-NAO">
81-
<rect key="frame" x="95" y="135" width="82" height="17"/>
93+
<rect key="frame" x="95" y="158" width="82" height="17"/>
8294
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
8395
<textFieldCell key="cell" scrollable="YES" lineBreakMode="clipping" sendsActionOnEndEditing="YES" title="Highlighting" id="3di-kC-amW">
8496
<font key="font" metaFont="smallSystemBold"/>

0 commit comments

Comments
 (0)