Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Minor tweaks to commit line drawing #74

Open
wants to merge 1 commit into
base: experimental
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions PBCommitMessageView.m
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,33 @@ - (void)drawRect:(NSRect)aRect
// draw a vertical line after the given size (used as an indicator
// for the first line of the commit message)
if ([PBGitDefaults commitMessageViewHasVerticalLine]) {
float characterWidth = [@" " sizeWithAttributes:[self typingAttributes]].width;
float lineWidth = characterWidth * [PBGitDefaults commitMessageViewVerticalLineLength];
NSSize characterSize = [@" " sizeWithAttributes:[self typingAttributes]];
float lineWidth = characterSize.width * [PBGitDefaults commitMessageViewVerticalLineLength];

[[NSColor lightGrayColor] set];
float padding = [[self textContainer] lineFragmentPadding];
NSRect line;
line.origin.x = padding + lineWidth;
line.origin.y = 0;
line.size.width = 1;
line.size.height = [self bounds].size.height;
if ([PBGitDefaults commitMessageViewHasSplitVerticalLine]) {
line.size.height = characterSize.height;
NSRectFill(line);
line.origin.y = characterSize.height;
lineWidth = characterSize.width * [PBGitDefaults commitMessageViewSplitVerticalLineLength];
line.size.width = padding + lineWidth - line.origin.x;
line.size.height = 1;
if (line.size.width < 0) {
line.origin.x = padding + lineWidth + 1;
line.size.width = -line.size.width;
}
NSRectFill(line);
line.origin.x = padding + lineWidth;
line.size.width = 1;
line.size.height = [self bounds].size.height - characterSize.height;
} else {
line.size.height = [self bounds].size.height;
}
NSRectFill(line);
}
}
Expand Down
2 changes: 2 additions & 0 deletions PBGitDefaults.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@

+ (int) commitMessageViewVerticalLineLength;
+ (BOOL) commitMessageViewHasVerticalLine;
+ (int) commitMessageViewSplitVerticalLineLength;
+ (BOOL) commitMessageViewHasSplitVerticalLine;
+ (BOOL) isGistEnabled;
+ (BOOL) isGravatarEnabled;
+ (BOOL) confirmPublicGists;
Expand Down
17 changes: 17 additions & 0 deletions PBGitDefaults.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
#import "PBHistorySearchController.h"

#define kDefaultVerticalLineLength 50
#define kDefaultSplitVerticalLineLength 76
#define kCommitMessageViewVerticalLineLength @"PBCommitMessageViewVerticalLineLength"
#define kCommitMessageViewHasVerticalLine @"PBCommitMessageViewHasVerticalLine"
#define kCommitMessageViewHasSplitVerticalLine @"PBCommitMessageViewHasSplitVerticalLine"
#define kCommitMessageViewSplitVerticalLineLength @"PBCommitMessageViewSplitVerticalLineLength"
#define kEnableGist @"PBEnableGist"
#define kEnableGravatar @"PBEnableGravatar"
#define kConfirmPublicGists @"PBConfirmPublicGists"
Expand All @@ -37,6 +40,10 @@ + (void)initialize
forKey:kCommitMessageViewVerticalLineLength];
[defaultValues setObject:[NSNumber numberWithBool:YES]
forKey:kCommitMessageViewHasVerticalLine];
[defaultValues setObject:[NSNumber numberWithInt:kDefaultSplitVerticalLineLength]
forKey:kCommitMessageViewSplitVerticalLineLength];
[defaultValues setObject:[NSNumber numberWithBool:NO]
forKey:kCommitMessageViewHasSplitVerticalLine];
[defaultValues setObject:[NSNumber numberWithBool:YES]
forKey:kEnableGist];
[defaultValues setObject:[NSNumber numberWithBool:YES]
Expand Down Expand Up @@ -70,6 +77,16 @@ + (BOOL) commitMessageViewHasVerticalLine
return [[NSUserDefaults standardUserDefaults] boolForKey:kCommitMessageViewHasVerticalLine];
}

+ (int) commitMessageViewSplitVerticalLineLength
{
return [[NSUserDefaults standardUserDefaults] integerForKey:kCommitMessageViewSplitVerticalLineLength];
}

+ (BOOL) commitMessageViewHasSplitVerticalLine
{
return [[NSUserDefaults standardUserDefaults] boolForKey:kCommitMessageViewHasSplitVerticalLine];
}

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