From 609ff510c928ed42a5f34c32bee06d0fa356f18e Mon Sep 17 00:00:00 2001 From: Mike Czepiel Date: Tue, 15 May 2012 22:00:28 -0700 Subject: [PATCH 1/2] Add second vertical line in commit message This helps enforce the "standard" git commit message format without splitting the textfield apart. --- English.lproj/Preferences.xib | 450 +++++++++++++++++++--------------- PBCommitMessageView.m | 23 +- PBGitDefaults.h | 1 + PBGitDefaults.m | 9 + 4 files changed, 287 insertions(+), 196 deletions(-) diff --git a/English.lproj/Preferences.xib b/English.lproj/Preferences.xib index 73cdd074e..6a27b3c60 100644 --- a/English.lproj/Preferences.xib +++ b/English.lproj/Preferences.xib @@ -2,13 +2,13 @@ 1050 - 11A459e - 1565 - 1121.2 - 557.00 + 11D50d + 2182 + 1138.32 + 568.00 com.apple.InterfaceBuilder.CocoaPlugin - 1565 + 2182 YES @@ -33,11 +33,8 @@ com.apple.InterfaceBuilder.CocoaPlugin - YES - - YES - - + PluginDependencyRecalculationVersion + YES @@ -58,7 +55,7 @@ 268 - {{18, 197}, {158, 18}} + {{18, 206}, {158, 18}} @@ -91,7 +88,7 @@ 268 - {{17, 34}, {166, 17}} + {{17, 22}, {166, 17}} @@ -125,7 +122,7 @@ 268 - {{182, 24}, {137, 32}} + {{182, 12}, {137, 32}} @@ -145,20 +142,20 @@ 75 - + 268 - {{248, 129}, {41, 22}} + {{275, 113}, {41, 22}} YES - + -1804468671 272630784 - + YES 6 @@ -169,7 +166,7 @@ MQA - + 6 System textColor @@ -177,10 +174,47 @@ + + + 268 + {{74, 116}, {196, 17}} + + + + YES + + 68288064 + 272630784 + Display body guide at column: + + + + + + + + + 268 + {{290, 138}, {41, 22}} + + + + YES + + -1804468671 + 272630784 + + + + YES + + + + 268 - {{121, 131}, {122, 17}} + {{74, 143}, {211, 17}} @@ -188,7 +222,7 @@ 68288064 272630784 - Display at column: + Display subject guide at column: @@ -198,7 +232,7 @@ 268 - {{18, 157}, {273, 18}} + {{18, 166}, {322, 18}} @@ -206,7 +240,7 @@ -2080244224 0 - Show column guide in commit message + Show vertical column guide in commit message 1211912703 @@ -222,7 +256,7 @@ 268 - {{17, 104}, {99, 17}} + {{17, 88}, {99, 17}} @@ -248,7 +282,7 @@ NSFilenamesPboardType - {{121, 100}, {179, 22}} + {{121, 84}, {179, 22}} @@ -272,7 +306,7 @@ 268 - {{118, 64}, {192, 28}} + {{118, 48}, {192, 28}} @@ -290,7 +324,7 @@ 268 - {{306, 104}, {54, 14}} + {{306, 88}, {54, 14}} @@ -317,7 +351,7 @@ 268 - {{18, 177}, {203, 18}} + {{18, 186}, {203, 18}} @@ -341,7 +375,7 @@ 268 - {{18, 217}, {279, 18}} + {{18, 226}, {279, 18}} @@ -365,7 +399,7 @@ 268 - {{18, 237}, {279, 18}} + {{18, 246}, {279, 18}} @@ -389,7 +423,7 @@ 268 - {{18, 257}, {207, 18}} + {{18, 266}, {207, 18}} @@ -413,7 +447,7 @@ 268 - {{18, 277}, {207, 18}} + {{18, 286}, {207, 18}} @@ -435,14 +469,14 @@ - {401, 313} + {401, 322} NSView - + 268 YES @@ -608,7 +642,7 @@ formatterBehavior timeStyle - + YES %m/%d/%y @@ -616,7 +650,7 @@ - EEEE, d MMMM, y h:mm:ss a + EEEE, MMMM d, y h:mm:ss a NO @@ -646,10 +680,11 @@ {400, 139} + NSView - + 268 YES @@ -677,6 +712,7 @@ {239, 54} + NSView @@ -686,7 +722,7 @@ YES - + 268 YES @@ -837,6 +873,7 @@ {400, 136} + NSView @@ -859,6 +896,62 @@ 8 + + + checkGitValidity: + + + + 58 + + + + gitPathController + + + + 59 + + + + gitPathOpenAccessory + + + + 65 + + + + showHideAllFiles: + + + + 66 + + + + resetGitPath: + + + + 79 + + + + integrationPrefsView + + + + 92 + + + + resetAllDialogWarnings: + + + + 140 + value: automaticallyChecksForUpdates @@ -939,14 +1032,6 @@ 41 - - - delegate - - - - 54 - checkForUpdates: @@ -955,73 +1040,13 @@ 55 - - - checkGitValidity: - - - - 58 - - - - gitPathController - - - - 59 - delegate - + - 61 - - - - gitPathOpenAccessory - - - - 65 - - - - showHideAllFiles: - - - - 66 - - - - resetGitPath: - - - - 79 - - - - hidden: values.gitExecutable - - - - - - hidden: values.gitExecutable - hidden - values.gitExecutable - - NSValueTransformerName - NSIsNil - - 2 - - - 83 + 54 @@ -1042,7 +1067,7 @@ NSNullPlaceholder NSValueTransformerName - + YES No Executable set @@ -1056,27 +1081,31 @@ - integrationPrefsView - - + delegate + + - 92 + 61 - value: values.PBEnableGist - + hidden: values.gitExecutable + - + - value: values.PBEnableGist - value - values.PBEnableGist + hidden: values.gitExecutable + hidden + values.gitExecutable + + NSValueTransformerName + NSIsNil + 2 - 94 + 83 @@ -1094,6 +1123,22 @@ 96 + + + value: values.PBEnableGist + + + + + + value: values.PBEnableGist + value + values.PBEnableGist + 2 + + + 94 + value: values.PBConfirmPublicGists @@ -1238,14 +1283,6 @@ 135 - - - resetAllDialogWarnings: - - - - 140 - value: values.PBRefreshAutomatically @@ -1326,13 +1363,31 @@ 165 + + + value: values.PBCommitMessageViewVerticalBodyLineLength + + + + + + value: values.PBCommitMessageViewVerticalBodyLineLength + value + values.PBCommitMessageViewVerticalBodyLineLength + 2 + + + 176 + YES 0 - + + YES + @@ -1365,15 +1420,17 @@ + + + - General @@ -1708,20 +1765,6 @@ - - 130 - - - YES - - - - - - 131 - - - 136 @@ -1860,18 +1903,59 @@ + + 167 + + + YES + + + + + + 168 + + + YES + + + + + + 169 + + + + + 170 + + + + + 130 + + + YES + + + + + + 131 + + + YES YES + -1.IBPluginDependency + -2.IBPluginDependency -3.IBPluginDependency - 1.IBEditorWindowLastContentRect 1.IBPluginDependency 1.IBUserGuides - 1.WindowOrigin - 1.editorWindowContentRectSynchronizationRect 10.IBPluginDependency 108.IBPluginDependency 109.IBPluginDependency @@ -1892,26 +1976,26 @@ 131.IBPluginDependency 136.IBAttributePlaceholdersKey 136.IBPluginDependency - 136.IBViewBoundsToFrameTransform 137.IBPluginDependency - 137.IBViewBoundsToFrameTransform 138.IBPluginDependency 139.IBPluginDependency 14.IBPluginDependency 141.IBPluginDependency - 141.IBViewBoundsToFrameTransform 142.IBPluginDependency - 145.IBViewBoundsToFrameTransform + 145.IBPluginDependency 146.IBPluginDependency 147.IBPluginDependency - 15.IBEditorWindowLastContentRect 15.IBPluginDependency 155.IBPluginDependency 156.IBPluginDependency 16.IBPluginDependency 162.IBPluginDependency 163.IBPluginDependency + 167.IBPluginDependency + 168.IBPluginDependency + 169.IBPluginDependency 17.IBPluginDependency + 170.IBPluginDependency 18.IBPluginDependency 19.IBPluginDependency 20.IBPluginDependency @@ -1920,8 +2004,8 @@ 23.IBPluginDependency 24.IBPluginDependency 25.IBPluginDependency + 26.IBPluginDependency 28.IBPluginDependency - 4.IBEditorWindowLastContentRect 4.IBPluginDependency 4.IBUserGuides 42.IBPluginDependency @@ -1931,16 +2015,13 @@ 46.IBPluginDependency 47.IBPluginDependency 48.IBPluginDependency - 62.IBEditorWindowLastContentRect 62.IBPluginDependency 63.IBPluginDependency 64.IBPluginDependency 77.IBPluginDependency 78.IBPluginDependency - 87.IBEditorWindowLastContentRect 87.IBPluginDependency 88.IBPluginDependency - 88.IBViewBoundsToFrameTransform 89.IBPluginDependency 9.IBPluginDependency 90.IBPluginDependency @@ -1948,21 +2029,25 @@ 97.IBPluginDependency 98.IBPluginDependency - + YES com.apple.InterfaceBuilder.CocoaPlugin - {{511, 477}, {401, 279}} com.apple.InterfaceBuilder.CocoaPlugin - + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + YES 121 0 + + + 76 + 0 + - {628, 654} - {{217, 442}, {480, 272}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -1990,27 +2075,14 @@ com.apple.InterfaceBuilder.CocoaPlugin - - P4AAAL+AAABDXwAAwggAAA - com.apple.InterfaceBuilder.CocoaPlugin - - P4AAAL+AAABCaAAAwegAAA - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - - P4AAAL+AAADBcAAAw3QAAA - com.apple.InterfaceBuilder.CocoaPlugin - - AUKaAABCvgAAA - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{443, 712}, {103, 71}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -2027,7 +2099,12 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{324, 683}, {400, 139}} + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin YES @@ -2044,18 +2121,13 @@ com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{505, 405}, {239, 54}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{329, 400}, {400, 136}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - - P4AAAL+AAABCYAAAwoIAAA - com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -2076,7 +2148,7 @@ - 165 + 176 @@ -2101,7 +2173,7 @@ resetGitPath: showHideAllFiles: - + YES id id @@ -2118,7 +2190,7 @@ resetGitPath: showHideAllFiles: - + YES checkGitValidity: @@ -2149,7 +2221,7 @@ integrationPrefsView updatesPrefsView - + YES NSImageView NSView @@ -2170,7 +2242,7 @@ integrationPrefsView updatesPrefsView - + YES badGitPathIcon @@ -2241,10 +2313,6 @@ com.apple.InterfaceBuilder.CocoaPlugin.macosx - - com.apple.InterfaceBuilder.CocoaPlugin.macosx - - com.apple.InterfaceBuilder.CocoaPlugin.InterfaceBuilder3 @@ -2260,10 +2328,10 @@ NSStopProgressFreestandingTemplate NSSwitch - + YES - {9, 8} - {7, 2} + {11, 11} + {10, 3} {83, 83} {15, 15} diff --git a/PBCommitMessageView.m b/PBCommitMessageView.m index da24242c2..2ab95e13f 100644 --- a/PBCommitMessageView.m +++ b/PBCommitMessageView.m @@ -15,19 +15,32 @@ - (void)drawRect:(NSRect)aRect { [super drawRect: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]; + NSRect line; + float padding; + float textViewHeight = [self bounds].size.height; + // draw a vertical line after the given size (used as an indicator + // for the first line of the commit message) [[NSColor lightGrayColor] set]; - float padding = [[self textContainer] lineFragmentPadding]; - NSRect line; + padding = [[self textContainer] lineFragmentPadding]; + line.origin.x = padding + lineWidth; + line.origin.y = 0; + line.size.width = 1; + line.size.height = textViewHeight; + NSRectFill(line); + + // and one for the body of the commit message + lineWidth = lineWidth = characterWidth * [PBGitDefaults commitMessageViewVerticalBodyLineLength]; + [[NSColor darkGrayColor] set]; + padding = [[self textContainer] lineFragmentPadding]; line.origin.x = padding + lineWidth; line.origin.y = 0; line.size.width = 1; - line.size.height = [self bounds].size.height; + line.size.height = textViewHeight; NSRectFill(line); } } diff --git a/PBGitDefaults.h b/PBGitDefaults.h index b23a2ee6b..86c18037b 100644 --- a/PBGitDefaults.h +++ b/PBGitDefaults.h @@ -12,6 +12,7 @@ } + (int) commitMessageViewVerticalLineLength; ++ (int) commitMessageViewVerticalBodyLineLength; + (BOOL) commitMessageViewHasVerticalLine; + (BOOL) isGistEnabled; + (BOOL) isGravatarEnabled; diff --git a/PBGitDefaults.m b/PBGitDefaults.m index 13895d79f..c0aee1460 100644 --- a/PBGitDefaults.m +++ b/PBGitDefaults.m @@ -11,6 +11,8 @@ #define kDefaultVerticalLineLength 50 #define kCommitMessageViewVerticalLineLength @"PBCommitMessageViewVerticalLineLength" +#define kDefaultVerticalBodyLineLength 72 +#define kCommitMessageViewVerticalBodyLineLength @"PBCommitMessageViewVerticalBodyLineLength" #define kCommitMessageViewHasVerticalLine @"PBCommitMessageViewHasVerticalLine" #define kEnableGist @"PBEnableGist" #define kEnableGravatar @"PBEnableGravatar" @@ -40,6 +42,8 @@ + (void)initialize NSMutableDictionary *defaultValues = [NSMutableDictionary dictionary]; [defaultValues setObject:[NSNumber numberWithInt:kDefaultVerticalLineLength] forKey:kCommitMessageViewVerticalLineLength]; + [defaultValues setObject:[NSNumber numberWithInt:kDefaultVerticalBodyLineLength] + forKey:kCommitMessageViewVerticalBodyLineLength]; [defaultValues setObject:[NSNumber numberWithBool:YES] forKey:kCommitMessageViewHasVerticalLine]; [defaultValues setObject:[NSNumber numberWithBool:YES] @@ -83,6 +87,11 @@ + (BOOL) commitMessageViewHasVerticalLine return [[NSUserDefaults standardUserDefaults] boolForKey:kCommitMessageViewHasVerticalLine]; } ++ (int) commitMessageViewVerticalBodyLineLength +{ + return [[NSUserDefaults standardUserDefaults] integerForKey:kCommitMessageViewVerticalBodyLineLength]; +} + + (BOOL) isGistEnabled { return [[NSUserDefaults standardUserDefaults] boolForKey:kEnableGist]; From e712412484751a85a3b5f46bff67206e7064e210 Mon Sep 17 00:00:00 2001 From: Mike Czepiel Date: Wed, 16 May 2012 22:58:44 -0700 Subject: [PATCH 2/2] Redraw commit message guides as preferences change It seemed like it made sense to update the commit message view live. --- English.lproj/Preferences.xib | 23 ++++++++++++++--------- PBCommitMessageView.m | 25 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 9 deletions(-) diff --git a/English.lproj/Preferences.xib b/English.lproj/Preferences.xib index 6a27b3c60..6487b92e3 100644 --- a/English.lproj/Preferences.xib +++ b/English.lproj/Preferences.xib @@ -476,7 +476,7 @@ NSView - + 268 YES @@ -680,11 +680,10 @@ {400, 139} - NSView - + 268 YES @@ -712,7 +711,6 @@ {239, 54} - NSView @@ -722,7 +720,7 @@ YES - + 268 YES @@ -873,7 +871,6 @@ {400, 136} - NSView @@ -1278,10 +1275,14 @@ value: values.PBCommitMessageViewVerticalLineLength value values.PBCommitMessageViewVerticalLineLength + + NSContinuouslyUpdatesValue + + 2 - 135 + 181 @@ -1374,10 +1375,14 @@ value: values.PBCommitMessageViewVerticalBodyLineLength value values.PBCommitMessageViewVerticalBodyLineLength + + NSContinuouslyUpdatesValue + + 2 - 176 + 182 @@ -2148,7 +2153,7 @@ - 176 + 182 diff --git a/PBCommitMessageView.m b/PBCommitMessageView.m index 2ab95e13f..ec412bb60 100644 --- a/PBCommitMessageView.m +++ b/PBCommitMessageView.m @@ -11,6 +11,31 @@ @implementation PBCommitMessageView +- (void) awakeFromNib +{ + NSUserDefaults *defaults = [NSUserDefaults standardUserDefaults]; + + [defaults addObserver:self + forKeyPath:@"PBCommitMessageViewHasVerticalLine" + options:NSKeyValueObservingOptionNew + context:NULL]; + + [defaults addObserver:self + forKeyPath:@"PBCommitMessageViewVerticalLineLength" + options:NSKeyValueObservingOptionNew + context:NULL]; + + [defaults addObserver:self + forKeyPath:@"PBCommitMessageViewVerticalBodyLineLength" + options:NSKeyValueObservingOptionNew + context:NULL]; +} + +-(void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context +{ + [self setNeedsDisplay:YES]; +} + - (void)drawRect:(NSRect)aRect { [super drawRect:aRect];