Skip to content

Commit ef0d6bb

Browse files
committed
Align the commit details ref labels with the history list (issue gitx#635)
One palette written down twice had drifted apart, and one label never reached its color at all. The history list and the commit details pane each carry their own copy of the ref label colors, which no longer agree, and in that pane the current branch is drawn green rather than orange. Issue gitx#635 has both, and how the second one hid for so long. * Write the colors down once and hand them to the page as CSS variables when it loads, leaving the same values in the stylesheet as fallbacks * Keep the history list's shades, the paler set, for both panes * Call the ref through, so the current branch is told apart again
1 parent 6d01d1c commit ef0d6bb

7 files changed

Lines changed: 92 additions & 18 deletions

File tree

‎Classes/Controllers/PBWebHistoryController.m‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
#import "PBWebHistoryController.h"
10+
#import "PBGitRefLabelColors.h"
1011
#import "PBGitDefaults.h"
1112
#import <ObjectiveGit/GTConfiguration.h>
1213
#import "PBGitRef.h"
@@ -44,6 +45,7 @@ - (void)closeView
4445
- (void)didLoad
4546
{
4647
currentOID = nil;
48+
[[self script] callWebScriptMethod:@"setRefColors" withArguments:@[ [PBGitRefLabelColors CSSColors] ]];
4749
[self changeContentTo:historyController.webCommits];
4850
}
4951

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// PBGitRefLabelColors.h
3+
// GitX
4+
//
5+
6+
#import <Cocoa/Cocoa.h>
7+
8+
NS_ASSUME_NONNULL_BEGIN
9+
10+
// The one place the ref label colors are written down. The history list draws
11+
// with the NSColors; the commit details pane is handed the same values as CSS.
12+
@interface PBGitRefLabelColors : NSObject
13+
14+
+ (NSColor *)colorForRefType:(nullable NSString *)type;
15+
+ (NSColor *)currentBranchColor;
16+
17+
+ (NSDictionary<NSString *, NSString *> *)CSSColors;
18+
19+
@end
20+
21+
NS_ASSUME_NONNULL_END
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
//
2+
// PBGitRefLabelColors.m
3+
// GitX
4+
//
5+
6+
#import "PBGitRefLabelColors.h"
7+
8+
NS_ASSUME_NONNULL_BEGIN
9+
10+
@implementation PBGitRefLabelColors
11+
12+
+ (NSDictionary<NSString *, NSString *> *)CSSColors
13+
{
14+
return @{
15+
@"head" : @"#9ae284",
16+
@"remote" : @"#a2cfef",
17+
@"tag" : @"#fced6f",
18+
@"currentBranch" : @"#fca64f",
19+
};
20+
}
21+
22+
+ (NSColor *)colorNamed:(NSString *)name
23+
{
24+
NSString *hex = [self CSSColors][name];
25+
if (!hex)
26+
return [NSColor yellowColor];
27+
28+
unsigned int value = 0;
29+
[[NSScanner scannerWithString:[hex substringFromIndex:1]] scanHexInt:&value];
30+
31+
return [NSColor colorWithCalibratedRed:((value >> 16) & 0xff) / 255.0
32+
green:((value >> 8) & 0xff) / 255.0
33+
blue:(value & 0xff) / 255.0
34+
alpha:1.0];
35+
}
36+
37+
+ (NSColor *)colorForRefType:(nullable NSString *)type
38+
{
39+
return [self colorNamed:type ?: @""];
40+
}
41+
42+
+ (NSColor *)currentBranchColor
43+
{
44+
return [self colorNamed:@"currentBranch"];
45+
}
46+
47+
@end
48+
49+
NS_ASSUME_NONNULL_END

‎Classes/Views/PBGitRevisionCell.m‎

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
//
88

99
#import "PBGitRevisionCell.h"
10+
#import "PBGitRefLabelColors.h"
1011
#import "PBGitRef.h"
1112
#import "PBGitCommit.h"
1213
#import "PBGitRevSpecifier.h"
@@ -215,20 +216,10 @@ - (NSColor *)colorForRef:(PBGitRef *)ref
215216
{
216217
BOOL isHEAD = [ref.ref isEqualToString:[[[controller repository] headRef] simpleRef]];
217218

218-
if (isHEAD) {
219-
return [NSColor colorWithCalibratedRed:0Xfc / 256.0 green:0Xa6 / 256.0 blue:0X4f / 256.0 alpha:1.0];
220-
}
221-
222-
NSString *type = [ref type];
223-
if ([type isEqualToString:@"head"]) {
224-
return [NSColor colorWithCalibratedRed:0X9a / 256.0 green:0Xe2 / 256.0 blue:0X84 / 256.0 alpha:1.0];
225-
} else if ([type isEqualToString:@"remote"]) {
226-
return [NSColor colorWithCalibratedRed:0xa2 / 256.0 green:0Xcf / 256.0 blue:0Xef / 256.0 alpha:1.0];
227-
} else if ([type isEqualToString:@"tag"]) {
228-
return [NSColor colorWithCalibratedRed:0Xfc / 256.0 green:0Xed / 256.0 blue:0X6f / 256.0 alpha:1.0];
229-
}
219+
if (isHEAD)
220+
return [PBGitRefLabelColors currentBranchColor];
230221

231-
return [NSColor yellowColor];
222+
return [PBGitRefLabelColors colorForRefType:[ref type]];
232223
}
233224

234225
- (NSArray<NSValue *> *)rectsForRefsinRect:(NSRect)rect;

‎GitX.xcodeproj/project.pbxproj‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@
130130
4A5D773A14A9A9F600DF6C68 /* gitx.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A5D768614A9A9CC00DF6C68 /* gitx.m */; };
131131
4A5D773B14A9A9F900DF6C68 /* gitx_askpasswd_main.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A5D768714A9A9CC00DF6C68 /* gitx_askpasswd_main.m */; };
132132
4A5D777414A9AEB000DF6C68 /* PBSourceViewBadge.m in Sources */ = {isa = PBXBuildFile; fileRef = 4A5D776F14A9AEB000DF6C68 /* PBSourceViewBadge.m */; };
133+
73BBA7CB2CFA4A539E50DC2D /* PBGitRefLabelColors.m in Sources */ = {isa = PBXBuildFile; fileRef = E9EC58BF6EAA4E6CB0E56CC2 /* PBGitRefLabelColors.m */; };
133134
4A68AD7414A00541006DE321 /* Sparkle.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4A68AD6714A0050F006DE321 /* Sparkle.framework */; };
134135
4A774CC9142F482900E158CC /* ObjectiveGit.framework in CopyFiles */ = {isa = PBXBuildFile; fileRef = 4A4EF0AF142CBAD5001B8CDF /* ObjectiveGit.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, ); }; };
135136
4A8F6B4B14A9B6C20002F4D7 /* MGScopeBar.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 4A8F6B4714A9B6110002F4D7 /* MGScopeBar.framework */; };
@@ -652,6 +653,8 @@
652653
4A5D76DF14A9A9CC00DF6C68 /* PBSourceViewItem.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBSourceViewItem.m; sourceTree = "<group>"; };
653654
4A5D776E14A9AEB000DF6C68 /* PBSourceViewBadge.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBSourceViewBadge.h; sourceTree = "<group>"; };
654655
4A5D776F14A9AEB000DF6C68 /* PBSourceViewBadge.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBSourceViewBadge.m; sourceTree = "<group>"; };
656+
E9EC58BF6EAA4E6CB0E56CC2 /* PBGitRefLabelColors.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitRefLabelColors.m; sourceTree = "<group>"; };
657+
94915ED480AD4D678289B5AD /* PBGitRefLabelColors.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitRefLabelColors.h; sourceTree = "<group>"; };
655658
4A5D777014A9AEB000DF6C68 /* PBSourceViewItems.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBSourceViewItems.h; sourceTree = "<group>"; };
656659
4A68AD5814A0050E006DE321 /* Sparkle.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = Sparkle.xcodeproj; path = Sparkle/Sparkle.xcodeproj; sourceTree = "<group>"; };
657660
4A8F6B3B14A9B6100002F4D7 /* MGScopeBar.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = MGScopeBar.xcodeproj; path = MGScopeBar/MGScopeBar.xcodeproj; sourceTree = "<group>"; };
@@ -1274,6 +1277,8 @@
12741277
4A5D76DB14A9A9CC00DF6C68 /* PBRemoteProgressSheet.m */,
12751278
4A5D776E14A9AEB000DF6C68 /* PBSourceViewBadge.h */,
12761279
4A5D776F14A9AEB000DF6C68 /* PBSourceViewBadge.m */,
1280+
94915ED480AD4D678289B5AD /* PBGitRefLabelColors.h */,
1281+
E9EC58BF6EAA4E6CB0E56CC2 /* PBGitRefLabelColors.m */,
12771282
4A5D76DE14A9A9CC00DF6C68 /* PBSourceViewItem.h */,
12781283
4A5D76DF14A9A9CC00DF6C68 /* PBSourceViewItem.m */,
12791284
4A5D777014A9AEB000DF6C68 /* PBSourceViewItems.h */,
@@ -1924,6 +1929,7 @@
19241929
373F9A201EAF97A200A77B4C /* NSSplitView+GitX.m in Sources */,
19251930
4A5D773914A9A9CC00DF6C68 /* PBSourceViewItem.m in Sources */,
19261931
4A5D777414A9AEB000DF6C68 /* PBSourceViewBadge.m in Sources */,
1932+
73BBA7CB2CFA4A539E50DC2D /* PBGitRefLabelColors.m in Sources */,
19271933
BF42F1331E025403004769FF /* GitXTextView.m in Sources */,
19281934
4AB71FF814B7EDD400F1DFFC /* RJModalRepoSheet.m in Sources */,
19291935
643952771603EF9B00BB7AFF /* PBSourceViewGitSubmoduleItem.m in Sources */,

‎Resources/html/views/history/history.css‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,19 +153,19 @@ a {
153153
}
154154

155155
.refs.head {
156-
background-color: #7ad254;
156+
background-color: var(--ref-head, #9ae284);
157157
}
158158

159159
.refs.remote {
160-
background-color: #82afef;
160+
background-color: var(--ref-remote, #a2cfef);
161161
}
162162

163163
.refs.tag {
164-
background-color: #fced4f;
164+
background-color: var(--ref-tag, #fced6f);
165165
}
166166

167167
.refs.currentBranch {
168-
background-color: #fca64f;
168+
background-color: var(--ref-currentBranch, #fca64f);
169169
}
170170
#message_files {
171171
margin: 0;

‎Resources/html/views/history/history.js‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,11 @@ var reload = function() {
136136
showRefs();
137137
}
138138

139+
var setRefColors = function(colors) {
140+
for (var name in colors)
141+
document.documentElement.style.setProperty("--ref-" + name, colors[name]);
142+
}
143+
139144
var showRefs = function() {
140145
var refs = $("refs");
141146
if (commit.refs) {
@@ -145,7 +150,7 @@ var showRefs = function() {
145150
var ref = commit.refs[i];
146151
var span = document.createElement("span");
147152
span.classList.add("refs", ref.type());
148-
if (commit.currentRef == ref.ref) {
153+
if (commit.currentRef == ref.ref()) {
149154
span.classList.add("currentBranch");
150155
}
151156
span.textContent = ref.shortName();

0 commit comments

Comments
 (0)