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"
11 #import "PBGitIndex.h"
13 @implementation PBWebChangesController
18 selectedFileIsCached = NO;
20 startFile = @"commit";
23 [unstagedFilesController addObserver:self forKeyPath:@"selection" options:0 context:@"UnstagedFileSelected"];
24 [cachedFilesController addObserver:self forKeyPath:@"selection" options:0 context:@"cachedFileSelected"];
29 [[self script] setValue:controller.index forKey:@"Index"];
33 - (void)observeValueForKeyPath:(NSString *)keyPath
35 change:(NSDictionary *)change
36 context:(void *)context
38 NSArrayController *otherController;
39 otherController = object == unstagedFilesController ? cachedFilesController : unstagedFilesController;
40 int count = [[object selectedObjects] count];
42 if([[otherController selectedObjects] count] == 0 && selectedFile) {
44 selectedFileIsCached = NO;
50 // TODO: Move this to commitcontroller
51 [otherController setSelectionIndexes:[NSIndexSet indexSet]];
54 [self showMultiple: [object selectedObjects]];
58 selectedFile = [[object selectedObjects] objectAtIndex:0];
59 selectedFileIsCached = object == cachedFilesController;
64 - (void) showMultiple: (NSArray *)objects
66 [[self script] callWebScriptMethod:@"showMultipleFilesSelection" withArguments:[NSArray arrayWithObject:objects]];
74 id script = [view windowScriptObject];
75 [script callWebScriptMethod:@"showFileChanges"
76 withArguments:[NSArray arrayWithObjects:selectedFile ?: (id)[NSNull null],
77 [NSNumber numberWithBool:selectedFileIsCached], nil]];
80 - (void)stageHunk:(NSString *)hunk reverse:(BOOL)reverse
82 [controller.index applyPatch:hunk stage:YES reverse:reverse];
83 // FIXME: Don't need a hard refresh
88 - (void)discardHunk:(NSString *)hunk altKey:(BOOL)altKey
90 int ret = NSAlertDefaultReturn;
92 ret = [[NSAlert alertWithMessageText:@"Discard hunk"
94 alternateButton:@"Cancel"
96 informativeTextWithFormat:@"Are you sure you wish to discard the changes in this hunk?\n\nYou cannot undo this operation."] runModal];
99 if (ret == NSAlertDefaultReturn) {
100 [controller.index applyPatch:hunk stage:NO reverse:YES];
105 - (void) setStateMessage:(NSString *)state
107 id script = [view windowScriptObject];
108 [script callWebScriptMethod:@"setState" withArguments: [NSArray arrayWithObject:state]];