Skip to content

Commit fc63af0

Browse files
jmesnilpieter
authored andcommitted
CommitView: Add a vertical line to the commit message
Since Git recommends to use 50 characters in the first line of a commit message, this adds a vertical line to the commit message view to show where the 50 char limit is. [PB: This preference can be changed using a user default -- for now we don't have a preference pane yet, so this is hidden.]
1 parent a8d2982 commit fc63af0

File tree

6 files changed

+130
-9
lines changed

6 files changed

+130
-9
lines changed

GitX.xcodeproj/project.pbxproj

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
913D5E500E55645900CECEA2 /* gitx in Resources */ = {isa = PBXBuildFile; fileRef = 913D5E490E55644600CECEA2 /* gitx */; };
2121
913D5E5F0E556A9300CECEA2 /* PBCLIProxy.mm in Sources */ = {isa = PBXBuildFile; fileRef = 913D5E5E0E556A9300CECEA2 /* PBCLIProxy.mm */; };
2222
91B103CC0E898EC300C84364 /* PBIconAndTextCell.mm in Sources */ = {isa = PBXBuildFile; fileRef = 91B103CB0E898EC300C84364 /* PBIconAndTextCell.mm */; };
23+
93CB42C20EAB7B2200530609 /* PBGitDefaults.m in Sources */ = {isa = PBXBuildFile; fileRef = 93CB42C10EAB7B2200530609 /* PBGitDefaults.m */; };
24+
93F7857F0EA3ABF100C1F443 /* PBCommitMessageView.m in Sources */ = {isa = PBXBuildFile; fileRef = 93F7857E0EA3ABF100C1F443 /* PBCommitMessageView.m */; };
25+
93FCCBA90EA8AF450061B02B /* PBGitConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = 93FCCBA80EA8AF450061B02B /* PBGitConfig.m */; };
2326
D26DC6450E782C9000C777B2 /* gitx.icns in Resources */ = {isa = PBXBuildFile; fileRef = D26DC6440E782C9000C777B2 /* gitx.icns */; };
2427
F50FE0E30E07BE9600854FCD /* PBGitRevisionCell.m in Sources */ = {isa = PBXBuildFile; fileRef = F50FE0E20E07BE9600854FCD /* PBGitRevisionCell.m */; };
2528
F513085B0E0740F2000C8BCD /* PBQLOutlineView.m in Sources */ = {isa = PBXBuildFile; fileRef = F513085A0E0740F2000C8BCD /* PBQLOutlineView.m */; };
@@ -59,7 +62,6 @@
5962
F5B721C40E05CF7E00AF29DC /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = F5B721C20E05CF7E00AF29DC /* MainMenu.xib */; };
6063
F5C007750E731B48007B84B2 /* PBGitRef.m in Sources */ = {isa = PBXBuildFile; fileRef = F5C007740E731B48007B84B2 /* PBGitRef.m */; };
6164
F5C6F68D0E65FF9300478D97 /* PBGitLane.m in Sources */ = {isa = PBXBuildFile; fileRef = F5C6F68C0E65FF9300478D97 /* PBGitLane.m */; };
62-
F5D2DC870EA401A80034AD24 /* PBGitConfig.m in Sources */ = {isa = PBXBuildFile; fileRef = F5D2DC860EA401A80034AD24 /* PBGitConfig.m */; };
6365
F5DFFA6C0E075D8800617813 /* PBEasyFS.m in Sources */ = {isa = PBXBuildFile; fileRef = F5DFFA6B0E075D8800617813 /* PBEasyFS.m */; };
6466
F5E4DBFB0EAB58D90013FAFC /* SystemConfiguration.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = F5E4DBFA0EAB58D90013FAFC /* SystemConfiguration.framework */; };
6567
F5E926060E8827D300056E75 /* PBViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = F5E926050E8827D300056E75 /* PBViewController.m */; };
@@ -122,6 +124,11 @@
122124
913D5E5E0E556A9300CECEA2 /* PBCLIProxy.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PBCLIProxy.mm; sourceTree = "<group>"; };
123125
91B103CA0E898EC300C84364 /* PBIconAndTextCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBIconAndTextCell.h; sourceTree = "<group>"; };
124126
91B103CB0E898EC300C84364 /* PBIconAndTextCell.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = PBIconAndTextCell.mm; sourceTree = "<group>"; };
127+
93CB42C00EAB7B2200530609 /* PBGitDefaults.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitDefaults.h; sourceTree = "<group>"; };
128+
93CB42C10EAB7B2200530609 /* PBGitDefaults.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitDefaults.m; sourceTree = "<group>"; };
129+
93F7857D0EA3ABF100C1F443 /* PBCommitMessageView.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBCommitMessageView.h; sourceTree = "<group>"; };
130+
93F7857E0EA3ABF100C1F443 /* PBCommitMessageView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBCommitMessageView.m; sourceTree = "<group>"; };
131+
93FCCBA80EA8AF450061B02B /* PBGitConfig.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitConfig.m; sourceTree = "<group>"; };
125132
D26DC6440E782C9000C777B2 /* gitx.icns */ = {isa = PBXFileReference; lastKnownFileType = image.icns; path = gitx.icns; sourceTree = "<group>"; };
126133
F50FE0E10E07BE9600854FCD /* PBGitRevisionCell.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitRevisionCell.h; sourceTree = "<group>"; };
127134
F50FE0E20E07BE9600854FCD /* PBGitRevisionCell.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitRevisionCell.m; sourceTree = "<group>"; };
@@ -181,7 +188,6 @@
181188
F5C6F68B0E65FF9300478D97 /* PBGitLane.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitLane.h; sourceTree = "<group>"; };
182189
F5C6F68C0E65FF9300478D97 /* PBGitLane.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitLane.m; sourceTree = "<group>"; };
183190
F5D2DC850EA401A80034AD24 /* PBGitConfig.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitConfig.h; sourceTree = "<group>"; };
184-
F5D2DC860EA401A80034AD24 /* PBGitConfig.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitConfig.m; sourceTree = "<group>"; };
185191
F5DFFA6A0E075D8800617813 /* PBEasyFS.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBEasyFS.h; sourceTree = "<group>"; };
186192
F5DFFA6B0E075D8800617813 /* PBEasyFS.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBEasyFS.m; sourceTree = "<group>"; };
187193
F5E4DBFA0EAB58D90013FAFC /* SystemConfiguration.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = SystemConfiguration.framework; path = /System/Library/Frameworks/SystemConfiguration.framework; sourceTree = "<absolute>"; };
@@ -348,7 +354,7 @@
348354
F53C4DF50E97FC630022AD59 /* PBGitBinary.h */,
349355
F53C4DF60E97FC630022AD59 /* PBGitBinary.m */,
350356
F5D2DC850EA401A80034AD24 /* PBGitConfig.h */,
351-
F5D2DC860EA401A80034AD24 /* PBGitConfig.m */,
357+
93FCCBA80EA8AF450061B02B /* PBGitConfig.m */,
352358
);
353359
name = Git;
354360
sourceTree = "<group>";
@@ -360,6 +366,8 @@
360366
F5E927F90E883EF600056E75 /* Commit */,
361367
77C8280B06725ACE000B614F /* ApplicationController.h */,
362368
77C8280C06725ACE000B614F /* ApplicationController.m */,
369+
93CB42C00EAB7B2200530609 /* PBGitDefaults.h */,
370+
93CB42C10EAB7B2200530609 /* PBGitDefaults.m */,
363371
F57CC43F0E05E496000472E2 /* PBGitWindowController.h */,
364372
F57CC4400E05E496000472E2 /* PBGitWindowController.m */,
365373
911111F60E594F3F00BF76B4 /* PBRepositoryDocumentController.h */,
@@ -466,6 +474,8 @@
466474
F59116E80E843BCB0072CCB1 /* PBGitCommitController.m */,
467475
F5E927FA0E883F0700056E75 /* PBWebChangesController.h */,
468476
F5E927FB0E883F0700056E75 /* PBWebChangesController.m */,
477+
93F7857D0EA3ABF100C1F443 /* PBCommitMessageView.h */,
478+
93F7857E0EA3ABF100C1F443 /* PBCommitMessageView.m */,
469479
);
470480
name = Commit;
471481
sourceTree = "<group>";
@@ -609,7 +619,9 @@
609619
F56244090E9684B0002B6C44 /* PBUnsortableTableHeader.m in Sources */,
610620
F53C4DF70E97FC630022AD59 /* PBGitBinary.m in Sources */,
611621
F593DF780E9E636C003A8559 /* PBFileChangesTableView.m in Sources */,
612-
F5D2DC870EA401A80034AD24 /* PBGitConfig.m in Sources */,
622+
93F7857F0EA3ABF100C1F443 /* PBCommitMessageView.m in Sources */,
623+
93FCCBA90EA8AF450061B02B /* PBGitConfig.m in Sources */,
624+
93CB42C20EAB7B2200530609 /* PBGitDefaults.m in Sources */,
613625
);
614626
runOnlyForDeploymentPostprocessing = 0;
615627
};

PBCommitMessageView.h

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// PBCommitMessageView.h
3+
// GitX
4+
//
5+
// Created by Jeff Mesnil on 13/10/08.
6+
// Copyright 2008 Jeff Mesnil (http://jmesnil.net/). All rights reserved.
7+
//
8+
9+
#import <Cocoa/Cocoa.h>
10+
11+
@interface PBCommitMessageView : NSTextView {
12+
13+
}
14+
15+
@end

PBCommitMessageView.m

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// PBCommitMessageView.m
3+
// GitX
4+
//
5+
// Created by Jeff Mesnil on 13/10/08.
6+
// Copyright 2008 Jeff Mesnil (http://jmesnil.net/). All rights reserved.
7+
//
8+
9+
#import "PBCommitMessageView.h"
10+
#import "PBGitDefaults.h"
11+
12+
@implementation PBCommitMessageView
13+
14+
- (void)drawRect:(NSRect)aRect
15+
{
16+
NSColor *originalColor = [self backgroundColor];
17+
[originalColor set];
18+
NSRectFill(aRect);
19+
20+
// draw a vertical line after the given size (used as an indicator
21+
// for the first line of the commit message)
22+
float characterWidth = [@" " sizeWithAttributes:[self typingAttributes]].width;
23+
float lineWidth = characterWidth * [PBGitDefaults commitMessageViewVerticalLineLength];
24+
25+
[[NSColor lightGrayColor] set];
26+
// This depends upon the fact that NSTextView always redraws complete lines.
27+
float padding = [[self textContainer] lineFragmentPadding];
28+
NSRect line;
29+
line.origin.x = padding + aRect.origin.x + lineWidth;
30+
line.origin.y = aRect.origin.y;
31+
line.size.width = 1;
32+
line.size.height = aRect.size.height;
33+
NSRectFill(line);
34+
35+
[self setBackgroundColor:nil];
36+
[super drawRect:aRect];
37+
[self setBackgroundColor:originalColor];
38+
}
39+
40+
@end

PBGitCommitView.xib

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
<data>
44
<int key="IBDocument.SystemTarget">1050</int>
55
<string key="IBDocument.SystemVersion">9F33</string>
6-
<string key="IBDocument.InterfaceBuilderVersion">670</string>
6+
<string key="IBDocument.InterfaceBuilderVersion">672</string>
77
<string key="IBDocument.AppKitVersion">949.34</string>
88
<string key="IBDocument.HIToolboxVersion">352.00</string>
99
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
1010
<bool key="EncodedWithXMLCoder">YES</bool>
11-
<integer value="45"/>
11+
<integer value="130"/>
1212
</object>
1313
<object class="NSArray" key="IBDocument.PluginDependencies">
1414
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -1421,6 +1421,7 @@
14211421
<string>130.IBPluginDependency</string>
14221422
<string>131.IBPluginDependency</string>
14231423
<string>132.IBPluginDependency</string>
1424+
<string>133.CustomClassName</string>
14241425
<string>133.IBPluginDependency</string>
14251426
<string>163.IBPluginDependency</string>
14261427
<string>164.IBPluginDependency</string>
@@ -1453,7 +1454,7 @@
14531454
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
14541455
<string>com.apple.InterfaceBuilderKit</string>
14551456
<string>com.apple.InterfaceBuilderKit</string>
1456-
<string>{{358, 206}, {852, 432}}</string>
1457+
<string>{{37, 206}, {852, 432}}</string>
14571458
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
14581459
<integer value="0" id="8"/>
14591460
<reference ref="8"/>
@@ -1463,6 +1464,7 @@
14631464
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
14641465
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
14651466
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
1467+
<string>PBCommitMessageView</string>
14661468
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
14671469
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
14681470
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -1516,6 +1518,14 @@
15161518
<object class="IBClassDescriber" key="IBDocument.Classes">
15171519
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
15181520
<bool key="EncodedWithXMLCoder">YES</bool>
1521+
<object class="IBPartialClassDescription">
1522+
<string key="className">PBCommitMessageView</string>
1523+
<string key="superclassName">NSTextView</string>
1524+
<object class="IBClassDescriptionSource" key="sourceIdentifier">
1525+
<string key="majorKey">IBProjectSource</string>
1526+
<string key="minorKey">PBCommitMessageView.h</string>
1527+
</object>
1528+
</object>
15191529
<object class="IBPartialClassDescription">
15201530
<string key="className">PBFileChangesTableView</string>
15211531
<string key="superclassName">NSTableView</string>
@@ -1601,14 +1611,12 @@
16011611
<bool key="EncodedWithXMLCoder">YES</bool>
16021612
<string>cachedFilesController</string>
16031613
<string>controller</string>
1604-
<string>previousFile</string>
16051614
<string>unstagedFilesController</string>
16061615
</object>
16071616
<object class="NSMutableArray" key="dict.values">
16081617
<bool key="EncodedWithXMLCoder">YES</bool>
16091618
<string>NSArrayController</string>
16101619
<string>PBGitCommitController</string>
1611-
<string>id</string>
16121620
<string>NSArrayController</string>
16131621
</object>
16141622
</object>

PBGitDefaults.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//
2+
// PBGitDefaults.h
3+
// GitX
4+
//
5+
// Created by Jeff Mesnil on 19/10/08.
6+
// Copyright 2008 Jeff Mesnil (http://jmesnil.net/). All rights reserved.
7+
//
8+
9+
@interface PBGitDefaults : NSObject
10+
{
11+
12+
}
13+
14+
+ (int) commitMessageViewVerticalLineLength;
15+
16+
@end

PBGitDefaults.m

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// PBGitDefaults.m
3+
// GitX
4+
//
5+
// Created by Jeff Mesnil on 19/10/08.
6+
// Copyright 2008 Jeff Mesnil (http://jmesnil.net/). All rights reserved.
7+
//
8+
9+
#import "PBGitDefaults.h"
10+
11+
#define kDefaultVerticalLineLength 50
12+
#define kCommitMessageViewVerticalLineLength @"PBCommitMessageViewVerticalLineLength"
13+
14+
@implementation PBGitDefaults
15+
16+
+ (void)initialize
17+
{
18+
NSMutableDictionary *defaultValues = [NSMutableDictionary dictionary];
19+
[defaultValues setObject:[NSNumber numberWithInt:kDefaultVerticalLineLength]
20+
forKey:kCommitMessageViewVerticalLineLength];
21+
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultValues];
22+
NSLog(@"registered defaults: %@", defaultValues);
23+
}
24+
25+
+ (int) commitMessageViewVerticalLineLength
26+
{
27+
return [[NSUserDefaults standardUserDefaults] integerForKey:kCommitMessageViewVerticalLineLength];
28+
}
29+
30+
@end

0 commit comments

Comments
 (0)