Skip to content

Commit

Permalink
Add a preference for showing/hiding and setting the location of the c…
Browse files Browse the repository at this point in the history
…olumn guide in the commit message text view.
  • Loading branch information
brotherbard committed Nov 16, 2009
1 parent 6611c70 commit cde1ba3
Show file tree
Hide file tree
Showing 4 changed files with 304 additions and 52 deletions.
26 changes: 14 additions & 12 deletions PBCommitMessageView.m
Expand Up @@ -19,18 +19,20 @@ - (void)drawRect:(NSRect)aRect

// draw a vertical line after the given size (used as an indicator
// for the first line of the commit message)
float characterWidth = [@" " sizeWithAttributes:[self typingAttributes]].width;
float lineWidth = characterWidth * [PBGitDefaults commitMessageViewVerticalLineLength];

[[NSColor lightGrayColor] set];
// This depends upon the fact that NSTextView always redraws complete lines.
float padding = [[self textContainer] lineFragmentPadding];
NSRect line;
line.origin.x = padding + aRect.origin.x + lineWidth;
line.origin.y = aRect.origin.y;
line.size.width = 1;
line.size.height = aRect.size.height;
NSRectFill(line);
if ([PBGitDefaults commitMessageViewHasVerticalLine]) {
float characterWidth = [@" " sizeWithAttributes:[self typingAttributes]].width;
float lineWidth = characterWidth * [PBGitDefaults commitMessageViewVerticalLineLength];

[[NSColor lightGrayColor] set];
// This depends upon the fact that NSTextView always redraws complete lines.
float padding = [[self textContainer] lineFragmentPadding];
NSRect line;
line.origin.x = padding + aRect.origin.x + lineWidth;
line.origin.y = aRect.origin.y;
line.size.width = 1;
line.size.height = aRect.size.height;
NSRectFill(line);
}

[self setBackgroundColor:nil];
[super drawRect:aRect];
Expand Down
1 change: 1 addition & 0 deletions PBGitDefaults.h
Expand Up @@ -12,6 +12,7 @@
}

+ (int) commitMessageViewVerticalLineLength;
+ (BOOL) commitMessageViewHasVerticalLine;
+ (BOOL) isGistEnabled;
+ (BOOL) isGravatarEnabled;
+ (BOOL) confirmPublicGists;
Expand Down
8 changes: 8 additions & 0 deletions PBGitDefaults.m
Expand Up @@ -10,6 +10,7 @@

#define kDefaultVerticalLineLength 50
#define kCommitMessageViewVerticalLineLength @"PBCommitMessageViewVerticalLineLength"
#define kCommitMessageViewHasVerticalLine @"PBCommitMessageViewHasVerticalLine"
#define kEnableGist @"PBEnableGist"
#define kEnableGravatar @"PBEnableGravatar"
#define kConfirmPublicGists @"PBConfirmPublicGists"
Expand All @@ -28,6 +29,8 @@ + (void)initialize
NSMutableDictionary *defaultValues = [NSMutableDictionary dictionary];
[defaultValues setObject:[NSNumber numberWithInt:kDefaultVerticalLineLength]
forKey:kCommitMessageViewVerticalLineLength];
[defaultValues setObject:[NSNumber numberWithBool:YES]
forKey:kCommitMessageViewHasVerticalLine];
[defaultValues setObject:[NSNumber numberWithBool:YES]
forKey:kEnableGist];
[defaultValues setObject:[NSNumber numberWithBool:YES]
Expand All @@ -52,6 +55,11 @@ + (int) commitMessageViewVerticalLineLength
return [[NSUserDefaults standardUserDefaults] integerForKey:kCommitMessageViewVerticalLineLength];
}

+ (BOOL) commitMessageViewHasVerticalLine
{
return [[NSUserDefaults standardUserDefaults] boolForKey:kCommitMessageViewHasVerticalLine];
}

+ (BOOL) isGistEnabled
{
return [[NSUserDefaults standardUserDefaults] boolForKey:kEnableGist];
Expand Down

0 comments on commit cde1ba3

Please sign in to comment.