Skip to content
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
Add hidden preference to use a split column guide in commit messages
The conventional git commit message styling says to limit your first line
to roughly 50 characters, and subsequent lines to 76 characters. The column
guide in GitX doesn't support this.

Implement 2 new hidden preferences, one to determine whether it uses a split
column guide and the other to set the length of this guide. Default these
preferences to NO and 76, respectively. When the split column guide is
turned on, the drawing code will draw the normal column guide only for the
first line and it will use the split column guide length for every other
line.
  • Loading branch information
lilyball committed Dec 9, 2010
commit 6a81b7bbd1f8dde0f2987bf1d02fa41ea384b6ce
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