From 6a81b7bbd1f8dde0f2987bf1d02fa41ea384b6ce Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Tue, 9 Nov 2010 16:05:53 -0800 Subject: [PATCH] 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. --- PBCommitMessageView.m | 23 ++++++++++++++++++++--- PBGitDefaults.h | 2 ++ PBGitDefaults.m | 17 +++++++++++++++++ 3 files changed, 39 insertions(+), 3 deletions(-) diff --git a/PBCommitMessageView.m b/PBCommitMessageView.m index da24242c2..a01d2e0c5 100644 --- a/PBCommitMessageView.m +++ b/PBCommitMessageView.m @@ -18,8 +18,8 @@ - (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]; @@ -27,7 +27,24 @@ - (void)drawRect:(NSRect)aRect 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); } } diff --git a/PBGitDefaults.h b/PBGitDefaults.h index a95b5242e..4e265050c 100644 --- a/PBGitDefaults.h +++ b/PBGitDefaults.h @@ -13,6 +13,8 @@ + (int) commitMessageViewVerticalLineLength; + (BOOL) commitMessageViewHasVerticalLine; ++ (int) commitMessageViewSplitVerticalLineLength; ++ (BOOL) commitMessageViewHasSplitVerticalLine; + (BOOL) isGistEnabled; + (BOOL) isGravatarEnabled; + (BOOL) confirmPublicGists; diff --git a/PBGitDefaults.m b/PBGitDefaults.m index 565646924..d2c726142 100644 --- a/PBGitDefaults.m +++ b/PBGitDefaults.m @@ -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" @@ -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] @@ -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];