2 // PBWebChangesController.m
5 // Created by Pieter de Bie on 22-09-08.
6 // Copyright 2008 __MyCompanyName__. All rights reserved.
9 #import "PBWebChangesController.h"
10 #import "PBGitIndexController.h"
12 @implementation PBWebChangesController
17 selectedFileIsCached = NO;
19 startFile = @"commit";
22 [unstagedFilesController addObserver:self forKeyPath:@"selection" options:0 context:@"UnstagedFileSelected"];
23 [cachedFilesController addObserver:self forKeyPath:@"selection" options:0 context:@"cachedFileSelected"];
28 [[self script] setValue:indexController forKey:@"IndexController"];
34 return controller.amend;
37 - (void)observeValueForKeyPath:(NSString *)keyPath
39 change:(NSDictionary *)change
40 context:(void *)context
42 NSArrayController *otherController;
43 otherController = object == unstagedFilesController ? cachedFilesController : unstagedFilesController;
44 int count = [[object selectedObjects] count];
46 if([[otherController selectedObjects] count] == 0 && selectedFile) {
48 selectedFileIsCached = NO;
54 // TODO: Move this to commitcontroller
55 [otherController setSelectionIndexes:[NSIndexSet indexSet]];
58 [self showMultiple: [object selectedObjects]];
62 selectedFile = [[object selectedObjects] objectAtIndex:0];
63 selectedFileIsCached = object == cachedFilesController;
68 - (void) showMultiple: (NSArray *)objects
70 [[self script] callWebScriptMethod:@"showMultipleFilesSelection" withArguments:[NSArray arrayWithObject:objects]];
78 id script = [view windowScriptObject];
79 [script callWebScriptMethod:@"showFileChanges"
80 withArguments:[NSArray arrayWithObjects:selectedFile ?: (id)[NSNull null],
81 [NSNumber numberWithBool:selectedFileIsCached], nil]];
84 - (void) stageHunk:(NSString *)hunk reverse:(BOOL)reverse
86 [controller stageHunk: hunk reverse:reverse];
90 - (void)discardHunk:(NSString *)hunk altKey:(BOOL)altKey
92 int ret = NSAlertDefaultReturn;
94 ret = [[NSAlert alertWithMessageText:@"Discard hunk"
96 alternateButton:@"Cancel"
98 informativeTextWithFormat:@"Are you sure you wish to discard the changes in this hunk?\n\nYou cannot undo this operation."] runModal];
101 if (ret == NSAlertDefaultReturn) {
102 [controller discardHunk:hunk];
107 - (void) setStateMessage:(NSString *)state
109 id script = [view windowScriptObject];
110 [script callWebScriptMethod:@"setState" withArguments: [NSArray arrayWithObject:state]];
113 - (void) setContextSize:(int)size
115 if (size == indexController.contextSize)
118 indexController.contextSize = size;