Implement a DetailsController

This controller makes sure that only the current view
receives its notifications. Therefore we won't do any work that we don't
see, like parsing diffs or asking for trees. This makes everything quicker.
This commit is contained in:
Pieter de Bie
2008-06-16 03:13:08 +02:00
parent d6a0b1bb4c
commit 6ba944b2ac
7 changed files with 1331 additions and 1265 deletions
+1275 -1237
View File
File diff suppressed because it is too large Load Diff
+17 -3
View File
@@ -24,6 +24,7 @@
F57ABE0B0E0442DD00A088B8 /* commit.js in Resources */ = {isa = PBXBuildFile; fileRef = F57ABDDE0E0441DE00A088B8 /* commit.js */; };
F57ABE2B0E04435100A088B8 /* prototype.js in Resources */ = {isa = PBXBuildFile; fileRef = F57ABE180E04431D00A088B8 /* prototype.js */; };
F57CC3910E05DDF2000472E2 /* PBEasyPipe.m in Sources */ = {isa = PBXBuildFile; fileRef = F57CC3900E05DDF2000472E2 /* PBEasyPipe.m */; };
F57CC4410E05E496000472E2 /* PBDetailController.m in Sources */ = {isa = PBXBuildFile; fileRef = F57CC4400E05E496000472E2 /* PBDetailController.m */; };
F58A8F280E043698007E3FC0 /* commits.css in Resources */ = {isa = PBXBuildFile; fileRef = F58A8F270E043698007E3FC0 /* commits.css */; };
F5945E170E02B0C200706420 /* PBGitRepository.m in Sources */ = {isa = PBXBuildFile; fileRef = F5945E160E02B0C200706420 /* PBGitRepository.m */; };
F5B721C40E05CF7E00AF29DC /* MainMenu.xib in Resources */ = {isa = PBXBuildFile; fileRef = F5B721C20E05CF7E00AF29DC /* MainMenu.xib */; };
@@ -59,6 +60,8 @@
F57ABE180E04431D00A088B8 /* prototype.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; name = prototype.js; path = html/prototype.js; sourceTree = "<group>"; };
F57CC38F0E05DDF2000472E2 /* PBEasyPipe.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBEasyPipe.h; sourceTree = "<group>"; };
F57CC3900E05DDF2000472E2 /* PBEasyPipe.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBEasyPipe.m; sourceTree = "<group>"; };
F57CC43F0E05E496000472E2 /* PBDetailController.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBDetailController.h; sourceTree = "<group>"; };
F57CC4400E05E496000472E2 /* PBDetailController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBDetailController.m; sourceTree = "<group>"; };
F58A8F270E043698007E3FC0 /* commits.css */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.css; name = commits.css; path = html/commits.css; sourceTree = "<group>"; };
F5945E150E02B0C200706420 /* PBGitRepository.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PBGitRepository.h; sourceTree = "<group>"; };
F5945E160E02B0C200706420 /* PBGitRepository.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = PBGitRepository.m; sourceTree = "<group>"; };
@@ -81,8 +84,6 @@
080E96DDFE201D6D7F000001 /* Classes */ = {
isa = PBXGroup;
children = (
F56524B90E02D22D00F03B52 /* NSFileHandleExt.m */,
F56524BA0E02D22D00F03B52 /* NSFileHandleExt.h */,
);
name = Classes;
sourceTree = "<group>";
@@ -117,6 +118,7 @@
29B97314FDCFA39411CA2CEA /* GitTest */ = {
isa = PBXGroup;
children = (
F57CC43E0E05E472000472E2 /* Aux */,
F57CC3850E05DDC1000472E2 /* Controllers */,
F561777C0E05C88E001DCD79 /* DetailView.png */,
F56174540E05887E001DCD79 /* Git */,
@@ -187,10 +189,21 @@
F565262A0E03D89B00F03B52 /* PBWebGitController.m */,
77C8280B06725ACE000B614F /* ApplicationController.h */,
77C8280C06725ACE000B614F /* ApplicationController.m */,
F57CC43F0E05E496000472E2 /* PBDetailController.h */,
F57CC4400E05E496000472E2 /* PBDetailController.m */,
);
name = Controllers;
sourceTree = "<group>";
};
F57CC43E0E05E472000472E2 /* Aux */ = {
isa = PBXGroup;
children = (
F56524B90E02D22D00F03B52 /* NSFileHandleExt.m */,
F56524BA0E02D22D00F03B52 /* NSFileHandleExt.h */,
F57CC38F0E05DDF2000472E2 /* PBEasyPipe.h */,
F57CC3900E05DDF2000472E2 /* PBEasyPipe.m */,
);
name = Controllers;
name = Aux;
sourceTree = "<group>";
};
F58A8F250E04368A007E3FC0 /* HTML */ = {
@@ -277,6 +290,7 @@
F565262B0E03D89B00F03B52 /* PBWebGitController.m in Sources */,
F56174570E058893001DCD79 /* PBGitTree.m in Sources */,
F57CC3910E05DDF2000472E2 /* PBEasyPipe.m in Sources */,
F57CC4410E05E496000472E2 /* PBDetailController.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
-1
View File
@@ -23,7 +23,6 @@
@property (copy) NSNumber* selectedTab;
@property (retain) PBGitCommit* webCommit;
@property (retain) PBGitCommit* rawCommit;
@property (retain) PBGitCommit* realCommit;
@property (retain) PBGitTree* gitTree;
@end
+27 -13
View File
@@ -11,17 +11,24 @@
@implementation PBDetailController
@synthesize selectedTab, webCommit, rawCommit, realCommit, gitTree;
@synthesize selectedTab, webCommit, rawCommit, gitTree;
- init
- awakeFromNib
{
self.selectedTab = [NSNumber numberWithInt:0];
[commitController bind:@"realCommit" toObject:self withKeyPath:@"selection" options:nil];
[commitController addObserver:self forKeyPath:@"selection" options:(NSKeyValueObservingOptionNew,NSKeyValueObservingOptionOld) context:@"commitChange"];
return self;
}
- (void) updateKeys
{
NSArray* selection = [commitController selectedObjects];
if ([selection count] > 0)
realCommit = [selection objectAtIndex:0];
else
realCommit = nil;
self.webCommit = nil;
self.rawCommit = nil;
self.gitTree = nil;
@@ -29,22 +36,29 @@
int num = [self.selectedTab intValue];
if (num == 0) // Detailed view
self.webCommit = self.realCommit;
if (num == 1)
self.rawCommit = self.realCommit;
if (num == 2)
self.gitTree = self.realCommit.tree;
self.webCommit = realCommit;
else if (num == 1)
self.rawCommit = realCommit;
else if (num == 2)
self.gitTree = realCommit.tree;
}
- (void) setRealCommit: (PBGitCommit*) commit
{
realCommit = commit;
[self updateKeys];
}
- (void) setSelectedTab: (NSNumber*) number
{
selectedTab = number;
[self updateKeys];
}
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if ([(NSString *)context isEqualToString: @"commitChange"]) {
[self updateKeys];
return;
}
else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
}
}
@end
+2 -1
View File
@@ -9,12 +9,13 @@
#import <Cocoa/Cocoa.h>
#import "ApplicationController.h"
#import "PBGitCommit.h"
#import "PBDetailController.h"
#import <WebKit/WebKit.h>
@interface PBWebGitController : NSObject {
IBOutlet ApplicationController* controller;
IBOutlet WebView* view;
IBOutlet NSArrayController* commitsController;
IBOutlet PBDetailController* detailController;
NSString* currentSha;
NSString* diff;
}
+8 -8
View File
@@ -15,7 +15,7 @@
- (void) awakeFromNib
{
[commitsController addObserver:self forKeyPath:@"selection" options:0 context:@"ChangedCommit"];
[detailController addObserver:self forKeyPath:@"webCommit" options:0 context:@"ChangedCommit"];
NSLog([[NSBundle mainBundle] resourcePath]);
NSString* file = [[NSBundle mainBundle] pathForResource:@"commit" ofType:@"html"];
@@ -29,17 +29,14 @@
id script = [view windowScriptObject];
[script setValue: self forKey:@"Controller"];
currentSha = @"";
if ([[commitsController selectedObjects] count] == 0)
return;
[self changeContentTo: [[commitsController selectedObjects] objectAtIndex:0]];
[self changeContentTo: detailController.webCommit];
}
- (void) observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{
if (context == @"ChangedCommit") {
if ([[commitsController selectedObjects] count] != 0)
[self changeContentTo: [[commitsController selectedObjects] objectAtIndex:0]];
[self changeContentTo: detailController.webCommit];
}
else {
[super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
@@ -48,6 +45,9 @@
- (void) changeContentTo: (PBGitCommit *) content
{
if (content == nil)
return;
if ([currentSha isEqualToString: content.sha] || [currentSha isEqualToString:@"Not Loaded"])
return;
@@ -65,8 +65,8 @@
- (void) selectCommit: (NSString*) sha
{
NSPredicate* selection = [NSPredicate predicateWithFormat:@"sha == %@", sha];
NSArray* selectedCommits = [[commitsController arrangedObjects] filteredArrayUsingPredicate:selection];
[commitsController setSelectedObjects:selectedCommits];
NSArray* selectedCommits = [controller.repository.commits filteredArrayUsingPredicate:selection];
// TODO: reimplement this. How can we set the new commit? Our detailscontroller is read-only
}
+ (BOOL)isSelectorExcludedFromWebScript:(SEL)aSelector
+2 -2
View File
@@ -1,9 +1,9 @@
var Commit = Class.create({
initialize: function(obj) {
this.raw = obj.details();
this.raw = obj.details;
var messageStart = this.raw.indexOf("\n\n") + 2;
var diffStart = this.raw.indexOf("\ndiff ");
this.header = this.raw.substring(0, messageStart);
this.sha = this.header.match(/^commit ([0-9a-f]{40,40})/)[1];