[PATCH 1/2] Make the history view scale according to font size

2 views
Skip to first unread message

Jonathan del Strother

unread,
Nov 10, 2009, 9:34:50 AM11/10/09
to gi...@googlegroups.com
---
PBGitHistoryController.h | 3 +++
PBGitHistoryController.m | 16 +++++++++++++++-
PBGitRevisionCell.h | 1 +
PBGitRevisionCell.m | 12 +++++++++---
4 files changed, 28 insertions(+), 4 deletions(-)

diff --git a/PBGitHistoryController.h b/PBGitHistoryController.h
index fadb6cd..5808b31 100644
--- a/PBGitHistoryController.h
+++ b/PBGitHistoryController.h
@@ -27,12 +27,15 @@
PBGitCommit* webCommit;
PBGitCommit* rawCommit;
PBGitCommit* realCommit;
+
+ CGFloat fontSize;
}

@property (assign) int selectedTab;
@property (retain) PBGitCommit *webCommit, *rawCommit;
@property (retain) PBGitTree* gitTree;
@property (readonly) NSArrayController *commitController;
+@property (assign) CGFloat fontSize;

- (IBAction) setDetailedView: sender;
- (IBAction) setRawView: sender;
diff --git a/PBGitHistoryController.m b/PBGitHistoryController.m
index a9fde36..397e14b 100644
--- a/PBGitHistoryController.m
+++ b/PBGitHistoryController.m
@@ -13,12 +13,21 @@
#import "PBCommitList.h"
#define QLPreviewPanel NSClassFromString(@"QLPreviewPanel")

+static NSString* HistoryFontSize=@"History Font Size";

@implementation PBGitHistoryController
-@synthesize selectedTab, webCommit, rawCommit, gitTree, commitController;
+@synthesize selectedTab, webCommit, rawCommit, gitTree,
commitController, fontSize;
+
++(void)initialize {
+ if (self == [PBGitHistoryController class]) {
+ NSDictionary* defaults = [NSDictionary
dictionaryWithObject:[NSNumber numberWithFloat:[NSFont
systemFontSize]] forKey:HistoryFontSize];
+ [[NSUserDefaults standardUserDefaults] registerDefaults:defaults];
+ }
+}

- (void)awakeFromNib
{
+ self.fontSize = [[NSUserDefaults standardUserDefaults]
floatForKey:HistoryFontSize];
self.selectedTab = [[NSUserDefaults standardUserDefaults]
integerForKey:@"Repository Window Selected Tab Index"];;
[commitController addObserver:self forKeyPath:@"selection"
options:(NSKeyValueObservingOptionNew,NSKeyValueObservingOptionOld)
context:@"commitChange"];
[treeController addObserver:self forKeyPath:@"selection" options:0
context:@"treeChange"];
@@ -78,6 +87,11 @@ - (void) setSelectedTab: (int) number
[self updateKeys];
}

+-(void)setFontSize:(CGFloat)newSize {
+ fontSize = newSize;
+ [commitList setRowHeight:ceil(fontSize*1.3)];
+}
+
- (void) observeValueForKeyPath:(NSString *)keyPath
ofObject:(id)object change:(NSDictionary *)change context:(void
*)context
{
if ([(NSString *)context isEqualToString: @"commitChange"]) {
diff --git a/PBGitRevisionCell.h b/PBGitRevisionCell.h
index d6aa4ed..f0072ab 100644
--- a/PBGitRevisionCell.h
+++ b/PBGitRevisionCell.h
@@ -16,6 +16,7 @@
PBGitCommit *objectValue;
PBGraphCellInfo *cellInfo;
NSTextFieldCell *textCell;
+ CGFloat fontSize;
IBOutlet PBGitHistoryController *controller;
IBOutlet id<PBRefContextDelegate> contextMenuDelegate;
}
diff --git a/PBGitRevisionCell.m b/PBGitRevisionCell.m
index 98f978b..87c187a 100644
--- a/PBGitRevisionCell.m
+++ b/PBGitRevisionCell.m
@@ -62,7 +62,8 @@ - (void) drawCircleInRect: (NSRect) r
NSPoint origin = r.origin;
NSPoint columnOrigin = { origin.x + columnWidth * c, origin.y};

- NSRect oval = { columnOrigin.x - 5, columnOrigin.y + r.size.height *
0.5 - 5, 10, 10};
+ CGFloat radius = fontSize*0.4;
+ NSRect oval = { columnOrigin.x - radius, columnOrigin.y +
r.size.height * 0.5 - radius, radius*2, radius*2};


NSBezierPath * path = [NSBezierPath bezierPathWithOvalInRect:oval];
@@ -70,7 +71,8 @@ - (void) drawCircleInRect: (NSRect) r
[[NSColor blackColor] set];
[path fill];

- NSRect smallOval = { columnOrigin.x - 3, columnOrigin.y +
r.size.height * 0.5 - 3, 6, 6};
+ CGFloat smallRadius = radius*0.6;
+ NSRect smallOval = { columnOrigin.x - smallRadius, columnOrigin.y +
r.size.height * 0.5 - smallRadius, smallRadius*2, smallRadius*2};
[[NSColor whiteColor] set];
path = [NSBezierPath bezierPathWithOvalInRect:smallOval];
[path fill];
@@ -115,7 +117,7 @@ - (NSMutableDictionary*)
attributesForRefLabelSelected: (BOOL) selected

[style setAlignment:NSCenterTextAlignment];
[attributes setObject:style forKey:NSParagraphStyleAttributeName];
- [attributes setObject:[NSFont fontWithName:@"Helvetica" size:9]
forKey:NSFontAttributeName];
+ [attributes setObject:[NSFont fontWithName:@"Helvetica"
size:ceil(fontSize*0.75)] forKey:NSFontAttributeName];

//if (selected)
// [attributes setObject:[NSColor alternateSelectedControlTextColor]
forKey:NSForegroundColorAttributeName];
@@ -236,6 +238,10 @@ - (void) drawWithFrame: (NSRect) rect inView:(NSView *)view
[textCell setHighlighted: [self isHighlighted]];
[textCell drawWithFrame:rect inView: view];
}
+-(void)setFont:(NSFont*)font {
+ fontSize = font.pointSize;
+ [textCell setFont:font];
+}

- (void) setObjectValue: (PBGitCommit*)object {
[super setObjectValue:[NSValue valueWithNonretainedObject:object]];
--
1.6.5.rc1.44.ga1675.dirty

Pieter de Bie

unread,
Nov 10, 2009, 9:37:29 AM11/10/09
to gi...@googlegroups.com
Thanks for sending this to the list too. I'm a little swamped these
last weeks, but hopefully I'll have more time to look at it in the
next weeks. One thing I noticed is that you put the default in
PBGitHistoryController. We generally put all defaults in
PBGitDefaults, perhaps you can move it to there? The feature itself is
really useful and has been requested a few times too.

- Pieter

Jonathan del Strother

unread,
Nov 10, 2009, 9:42:31 AM11/10/09
to GitX
On Nov 10, 2:37 pm, Pieter de Bie <frimmirf+g...@gmail.com> wrote:
> One thing I noticed is that you put the default in
> PBGitHistoryController. We generally put all defaults in
> PBGitDefaults, perhaps you can move it to there?

Ohh - I noticed PBGitDefaults, but was confused because there didn't
appear to be any way of writing to the userdefaults from there.
However, now I look into it properly I see it's bound through the nib.

Will tweak & resubmit after any other comments...
Reply all
Reply to author
Forward
0 new messages