Skip to content

Commit 5598eef

Browse files
committed
Add preference options for refreshing the view + controller automatically on windowDidBecomeMain.
Add preference for showing exact or relative dates. Make the showWhitespaceDifferences preference work. Make the context slider in the diff views work. This is done with a minimal version of jQuery 1.3.2 being responsible for the animation and a small cookie storing the last value between page refreshes so that it can be incremented by the HTML sliders default value. TODO: Maybe we can also make the default context value into a preference?
1 parent 45e8aab commit 5598eef

File tree

9 files changed

+281
-151
lines changed

9 files changed

+281
-151
lines changed

English.lproj/Preferences.xib

Lines changed: 161 additions & 40 deletions
Large diffs are not rendered by default.

PBGitCommit.m

Lines changed: 58 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -38,72 +38,68 @@ - (NSDate *)date
3838
return [NSDate dateWithTimeIntervalSince1970:timestamp];
3939
}
4040

41-
#ifdef NormalDate
42-
- (NSString *) dateString
43-
{
44-
NSDateFormatter* formatter = [[NSDateFormatter alloc] initWithDateFormat:@"%Y-%m-%d %H:%M:%S" allowNaturalLanguage:NO];
45-
return [formatter stringFromDate: self.date];
46-
}
47-
#else
48-
49-
// Code modified from Gilean ( http://stackoverflow.com/users/6305/gilean ).
50-
// Copied from stackoverflow's accepted answer for Objective C relative dates.
51-
// http://stackoverflow.com/questions/902950/iphone-convert-date-string-to-a-relative-time-stamp
52-
// Modified the seconds constants with compile time math to aid in ease of adjustment of "Majic" numbers.
53-
//
5441
-(NSString *)dateString {
55-
NSDate *todayDate = [NSDate date];
56-
double ti = [self.date timeIntervalSinceDate:todayDate];
57-
ti = ti * -1;
58-
if(ti < 1) {
59-
return @"In the future!";
60-
} else if ( ti < 60 ) {
61-
return @"less than a minute ago";
62-
} else if ( ti < (60 * 60) ) {
63-
int diff = round(ti / 60);
64-
if ( diff < 2 ) {
65-
return @"1 minute ago";
66-
} else {
67-
return [NSString stringWithFormat:@"%d minutes ago", diff];
68-
}
69-
} else if ( ti < ( 60 * 60 * 24 ) ) {
70-
int diff = round(ti / 60 / 60);
71-
if ( diff < 2 ) {
72-
return @"1 hour ago";
73-
} else {
74-
return[NSString stringWithFormat:@"%d hours ago", diff];
75-
}
76-
} else if ( ti < ( 60 * 60 * 24 * 7 ) ) {
77-
int diff = round(ti / 60 / 60 / 24);
78-
if ( diff < 2 ) {
79-
return @"1 day ago";
80-
} else {
81-
return[NSString stringWithFormat:@"%d days ago", diff];
82-
}
83-
} else if ( ti < ( 60 * 60 * 24 * 31.5 ) ) {
84-
int diff = round(ti / 60 / 60 / 24 / 7);
85-
if ( diff < 2 ) {
86-
return @"1 week ago";
87-
} else {
88-
return[NSString stringWithFormat:@"%d weeks ago", diff];
89-
}
90-
} else if ( ti < ( 60 * 60 * 24 * 365 ) ) {
91-
int diff = round(ti / 60 / 60 / 24 / 30);
92-
if ( diff < 2 ) {
93-
return @"1 month ago";
94-
} else {
95-
return[NSString stringWithFormat:@"%d months ago", diff];
96-
}
42+
if ([PBGitDefaults showRelativeDates]) {
43+
// Code modified from Gilean ( http://stackoverflow.com/users/6305/gilean ).
44+
// Copied from stackoverflow's accepted answer for Objective C relative dates.
45+
// http://stackoverflow.com/questions/902950/iphone-convert-date-string-to-a-relative-time-stamp
46+
// Modified the seconds constants with compile time math to aid in ease of adjustment of "Majic" numbers.
47+
//
48+
NSDate *todayDate = [NSDate date];
49+
double ti = [self.date timeIntervalSinceDate:todayDate];
50+
ti = ti * -1;
51+
if(ti < 1) {
52+
return @"In the future!";
53+
} else if ( ti < 60 ) {
54+
return @"less than a minute ago";
55+
} else if ( ti < (60 * 60) ) {
56+
int diff = round(ti / 60);
57+
if ( diff < 2 ) {
58+
return @"1 minute ago";
59+
} else {
60+
return [NSString stringWithFormat:@"%d minutes ago", diff];
61+
}
62+
} else if ( ti < ( 60 * 60 * 24 ) ) {
63+
int diff = round(ti / 60 / 60);
64+
if ( diff < 2 ) {
65+
return @"1 hour ago";
66+
} else {
67+
return[NSString stringWithFormat:@"%d hours ago", diff];
68+
}
69+
} else if ( ti < ( 60 * 60 * 24 * 7 ) ) {
70+
int diff = round(ti / 60 / 60 / 24);
71+
if ( diff < 2 ) {
72+
return @"1 day ago";
73+
} else {
74+
return[NSString stringWithFormat:@"%d days ago", diff];
75+
}
76+
} else if ( ti < ( 60 * 60 * 24 * 31.5 ) ) {
77+
int diff = round(ti / 60 / 60 / 24 / 7);
78+
if ( diff < 2 ) {
79+
return @"1 week ago";
80+
} else {
81+
return[NSString stringWithFormat:@"%d weeks ago", diff];
82+
}
83+
} else if ( ti < ( 60 * 60 * 24 * 365 ) ) {
84+
int diff = round(ti / 60 / 60 / 24 / 30);
85+
if ( diff < 2 ) {
86+
return @"1 month ago";
87+
} else {
88+
return[NSString stringWithFormat:@"%d months ago", diff];
89+
}
90+
} else {
91+
float diff = round(ti / 60 / 60 / 24 / 365 * 4) / 4.0;
92+
if ( diff < 1.25 ) {
93+
return @"1 year ago";
94+
} else {
95+
return[NSString stringWithFormat:@"%g years ago", diff];
96+
}
97+
}
9798
} else {
98-
float diff = round(ti / 60 / 60 / 24 / 365 * 4) / 4.0;
99-
if ( diff < 1.25 ) {
100-
return @"1 year ago";
101-
} else {
102-
return[NSString stringWithFormat:@"%g years ago", diff];
103-
}
99+
NSDateFormatter* formatter = [[NSDateFormatter alloc] initWithDateFormat:@"%Y-%m-%d %H:%M:%S" allowNaturalLanguage:NO];
100+
return [formatter stringFromDate: self.date];
104101
}
105102
}
106-
#endif
107103

108104
- (NSArray*) treeContents
109105
{

PBGitDefaults.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
+ (BOOL) confirmPublicGists;
1919
+ (BOOL) isGistPublic;
2020
+ (BOOL) showWhitespaceDifferences;
21+
+ (BOOL) showRelativeDates;
2122
+ (BOOL) refreshAutomatically;
2223
+ (BOOL)openCurDirOnLaunch;
2324
+ (BOOL)showOpenPanelOnLaunch;

PBGitDefaults.m

Lines changed: 49 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -8,53 +8,58 @@
88

99
#import "PBGitDefaults.h"
1010

11-
#define kDefaultVerticalLineLength 50
11+
#define kDefaultVerticalLineLength 50
1212
#define kCommitMessageViewVerticalLineLength @"PBCommitMessageViewVerticalLineLength"
13-
#define kCommitMessageViewHasVerticalLine @"PBCommitMessageViewHasVerticalLine"
14-
#define kEnableGist @"PBEnableGist"
15-
#define kEnableGravatar @"PBEnableGravatar"
16-
#define kConfirmPublicGists @"PBConfirmPublicGists"
17-
#define kPublicGist @"PBGistPublic"
18-
#define kShowWhitespaceDifferences @"PBShowWhitespaceDifferences"
19-
#define kRefreshAutomatically @"PBRefreshAutomatically"
20-
#define kOpenCurDirOnLaunch @"PBOpenCurDirOnLaunch"
21-
#define kShowOpenPanelOnLaunch @"PBShowOpenPanelOnLaunch"
22-
#define kShouldCheckoutBranch @"PBShouldCheckoutBranch"
23-
#define kRecentCloneDestination @"PBRecentCloneDestination"
24-
#define kSuppressAcceptDropRef @"PBSuppressAcceptDropRef"
25-
#define kShowStageView @"PBShowStageView"
26-
#define kOpenPreviousDocumentsOnLaunch @"PBOpenPreviousDocumentsOnLaunch"
27-
#define kPreviousDocumentPaths @"PBPreviousDocumentPaths"
28-
#define kBranchFilterState @"PBBranchFilter"
13+
#define kCommitMessageViewHasVerticalLine @"PBCommitMessageViewHasVerticalLine"
14+
#define kEnableGist @"PBEnableGist"
15+
#define kEnableGravatar @"PBEnableGravatar"
16+
#define kConfirmPublicGists @"PBConfirmPublicGists"
17+
#define kPublicGist @"PBGistPublic"
18+
#define kShowWhitespaceDifferences @"PBShowWhitespaceDifferences"
19+
#define kRefreshAutomatically @"PBRefreshAutomatically"
20+
#define kOpenCurDirOnLaunch @"PBOpenCurDirOnLaunch"
21+
#define kShowOpenPanelOnLaunch @"PBShowOpenPanelOnLaunch"
22+
#define kShouldCheckoutBranch @"PBShouldCheckoutBranch"
23+
#define kRecentCloneDestination @"PBRecentCloneDestination"
24+
#define kSuppressAcceptDropRef @"PBSuppressAcceptDropRef"
25+
#define kShowStageView @"PBShowStageView"
26+
#define kOpenPreviousDocumentsOnLaunch @"PBOpenPreviousDocumentsOnLaunch"
27+
#define kPreviousDocumentPaths @"PBPreviousDocumentPaths"
28+
#define kBranchFilterState @"PBBranchFilter"
29+
#define kShowRelativeDates @"PBShowRelativeDates"
2930

3031
@implementation PBGitDefaults
3132

32-
+ (void)initialize
33-
{
34-
NSMutableDictionary *defaultValues = [NSMutableDictionary dictionary];
35-
[defaultValues setObject:[NSNumber numberWithInt:kDefaultVerticalLineLength]
33+
+ (void) initialize {
34+
NSMutableDictionary * defaultValues = [NSMutableDictionary dictionary];
35+
36+
[defaultValues setObject:[NSNumber numberWithInt:kDefaultVerticalLineLength]
3637
forKey:kCommitMessageViewVerticalLineLength];
3738
[defaultValues setObject:[NSNumber numberWithBool:YES]
3839
forKey:kCommitMessageViewHasVerticalLine];
39-
[defaultValues setObject:[NSNumber numberWithBool:YES]
40-
forKey:kEnableGist];
41-
[defaultValues setObject:[NSNumber numberWithBool:YES]
42-
forKey:kEnableGravatar];
43-
[defaultValues setObject:[NSNumber numberWithBool:YES]
44-
forKey:kConfirmPublicGists];
45-
[defaultValues setObject:[NSNumber numberWithBool:NO]
46-
forKey:kPublicGist];
47-
[defaultValues setObject:[NSNumber numberWithBool:YES]
48-
forKey:kShowWhitespaceDifferences];
49-
[defaultValues setObject:[NSNumber numberWithBool:YES]
50-
forKey:kOpenCurDirOnLaunch];
51-
[defaultValues setObject:[NSNumber numberWithBool:YES]
52-
forKey:kShowOpenPanelOnLaunch];
53-
[defaultValues setObject:[NSNumber numberWithBool:YES]
54-
forKey:kShouldCheckoutBranch];
55-
[defaultValues setObject:[NSNumber numberWithBool:NO]
40+
[defaultValues setObject:[NSNumber numberWithBool:YES]
41+
forKey:kEnableGist];
42+
[defaultValues setObject:[NSNumber numberWithBool:YES]
43+
forKey:kEnableGravatar];
44+
[defaultValues setObject:[NSNumber numberWithBool:YES]
45+
forKey:kConfirmPublicGists];
46+
[defaultValues setObject:[NSNumber numberWithBool:NO]
47+
forKey:kPublicGist];
48+
[defaultValues setObject:[NSNumber numberWithBool:YES]
49+
forKey:kShowWhitespaceDifferences];
50+
[defaultValues setObject:[NSNumber numberWithBool:YES]
51+
forKey:kOpenCurDirOnLaunch];
52+
[defaultValues setObject:[NSNumber numberWithBool:YES]
53+
forKey:kShowOpenPanelOnLaunch];
54+
[defaultValues setObject:[NSNumber numberWithBool:YES]
55+
forKey:kRefreshAutomatically];
56+
[defaultValues setObject:[NSNumber numberWithBool:YES]
57+
forKey:kShouldCheckoutBranch];
58+
[defaultValues setObject:[NSNumber numberWithBool:NO]
5659
forKey:kOpenPreviousDocumentsOnLaunch];
57-
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultValues];
60+
[defaultValues setObject:[NSNumber numberWithBool:YES]
61+
forKey:kShowRelativeDates];
62+
[[NSUserDefaults standardUserDefaults] registerDefaults:defaultValues];
5863
}
5964

6065
+ (int) commitMessageViewVerticalLineLength
@@ -97,6 +102,11 @@ + (BOOL)showWhitespaceDifferences
97102
return [[NSUserDefaults standardUserDefaults] boolForKey:kShowWhitespaceDifferences];
98103
}
99104

105+
+ (BOOL)showRelativeDates
106+
{
107+
return [[NSUserDefaults standardUserDefaults] boolForKey:kShowRelativeDates];
108+
}
109+
100110
+ (BOOL)openCurDirOnLaunch
101111
{
102112
return [[NSUserDefaults standardUserDefaults] boolForKey:kOpenCurDirOnLaunch];

PBGitWindowController.m

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
@implementation PBGitWindowController
1818

1919

20-
@synthesize repository;
20+
@synthesize repository, viewController, contentController;
2121

2222
- (id)initWithRepository:(PBGitRepository*)theRepository displayDefault:(BOOL)displayDefault
2323
{
@@ -124,8 +124,8 @@ - (void)windowDidBecomeMain:(NSNotification *)notification {
124124
/* Using ...didBecomeMain is better than ...didBecomeKey here because the QuickLook panel will count as key state change
125125
and the outline view window will trigger a refresh in the middle of the QuickLook panel's closing animation which
126126
causes a half second freeze with left over artifacts. */
127-
if (self.viewController && [PBGitDefaults refreshAutomatically]) {
128-
[(PBViewController *)self.viewController refresh:nil];
127+
if (self.contentController && [PBGitDefaults refreshAutomatically]) {
128+
[self.contentController refresh:nil];
129129
}
130130
}
131131

PBWebController.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,8 @@ - (BOOL) isFeatureEnabled:(NSString *)feature
131131
return [PBGitDefaults confirmPublicGists];
132132
else if([feature isEqualToString:@"publicGist"])
133133
return [PBGitDefaults isGistPublic];
134+
else if ([feature isEqualToString:@"showWhitespaceDifferences"])
135+
return [PBGitDefaults showWhitespaceDifferences];
134136
else
135137
return YES;
136138
}

html/css/diff.css

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,7 @@
4949
}
5050

5151
.diff .file .diffcontent .lines .whitespace {
52-
/* background-color: rgba(255,0,0,0.5); */
53-
background-color: transparent;
52+
background-color: rgba(255,0,0,0.5);
5453
}
5554

5655
#CurrentHunk {

html/lib/diffHighlighter.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,11 @@ var highlightDiff = function(diff, element, callbacks) {
188188

189189
sindex = "index=" + lindex.toString() + " ";
190190
if (firstChar == "+") {
191-
// Highlight trailing whitespace
192-
if (m = l.match(/\s+$/))
193-
l = l.replace(/\s+$/, "<span class='whitespace'>" + m + "</span>");
194-
191+
if (Controller.isFeatureEnabled_("showWhitespaceDifferences")) {
192+
// Highlight trailing whitespace
193+
if (m = l.match(/\s+$/))
194+
l = l.replace(/\s+$/, "<span class='whitespace'>" + m + "</span>");
195+
}
195196
line1 += "\n";
196197
line2 += ++hunk_start_line_2 + "\n";
197198
diffContent += "<div " + sindex + "class='addline'>" + l + "</div>";

html/views/commit/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
<link rel="stylesheet" href="commit.css" type="text/css" media="screen" title="no title" charset="utf-8">
1111

12-
<script type="text/javascript" src="../../js/jquery-1.3.2.min.js"></script>
12+
<script type="text/javascript" src="../../lib/jquery-1.3.2.min.js"></script>
1313
<script src="multipleSelection.js" type="text/javascript" charset="utf-8"></script>
1414
<script src="commit.js" type="text/javascript" charset="utf-8"></script>
1515
<script type="text/javascript" charset="utf-8">

0 commit comments

Comments
 (0)