@@ -88,14 +88,48 @@ - (void)loadView {
88
88
89
89
self.selectedCommitDetailsIndex = [[NSUserDefaults standardUserDefaults ] integerForKey: kHistorySelectedDetailIndexKey ];
90
90
91
- [commitController addObserver: self forKeyPath: @" selection" options: 0 context: @" commitChange" ];
92
- [commitController addObserver: self forKeyPath: @" arrangedObjects.@count" options: NSKeyValueObservingOptionInitial context: @" updateCommitCount" ];
93
- [treeController addObserver: self forKeyPath: @" selection" options: 0 context: @" treeChange" ];
91
+ [commitController addObserver: self keyPath: @" selection" options: 0 block: ^(MAKVONotification *notification) {
92
+ PBGitHistoryController *observer = notification.observer ;
93
+ [observer updateKeys ];
94
+ }];
95
+
96
+ [commitController addObserver: self keyPath: @" arrangedObjects.@count" options: NSKeyValueObservingOptionInitial block: ^(MAKVONotification *notification) {
97
+ PBGitHistoryController *observer = notification.observer ;
98
+ [observer reselectCommitAfterUpdate ];
99
+ }];
100
+
101
+ [treeController addObserver: self keyPath: @" selection" options: 0 block: ^(MAKVONotification *notification) {
102
+ PBGitHistoryController *observer = notification.observer ;
103
+ [observer updateQuicklookForce: NO ];
104
+ [observer saveFileBrowserSelection ];
105
+ }];
106
+
107
+ [repository.revisionList addObserver: self keyPath: @" isUpdating" options: 0 block: ^(MAKVONotification *notification) {
108
+ PBGitHistoryController *observer = notification.observer ;
109
+ [observer reselectCommitAfterUpdate ];
110
+ }];
111
+
112
+ [repository addObserver: self keyPath: @" currentBranch" options: 0 block: ^(MAKVONotification *notification) {
113
+ PBGitHistoryController *observer = notification.observer ;
114
+ // Reset the sorting
115
+ if ([[observer.commitController sortDescriptors ] count ]) {
116
+ [observer.commitController setSortDescriptors: [NSArray array ]];
117
+ [observer.commitController rearrangeObjects ];
118
+ }
119
+
120
+ [observer updateBranchFilterMatrix ];
121
+ }];
94
122
95
- [repository.revisionList addObserver: self forKeyPath: @" isUpdating" options: 0 context: @" revisionListUpdating" ];
96
- [repository addObserver: self forKeyPath: @" currentBranch" options: 0 context: @" branchChange" ];
97
- [repository addObserver: self forKeyPath: @" refs" options: 0 context: @" updateRefs" ];
98
- [repository addObserver: self forKeyPath: @" currentBranchFilter" options: 0 context: @" branchFilterChange" ];
123
+ [repository addObserver: self keyPath: @" refs" options: 0 block: ^(MAKVONotification *notification) {
124
+ PBGitHistoryController *observer = notification.observer ;
125
+ [observer.commitController rearrangeObjects ];
126
+ }];
127
+
128
+ [repository addObserver: self keyPath: @" currentBranchFilter" options: 0 block: ^(MAKVONotification *notification) {
129
+ PBGitHistoryController *observer = notification.observer ;
130
+ [PBGitDefaults setBranchFilter: observer.repository.currentBranchFilter];
131
+ [observer updateBranchFilterMatrix ];
132
+ }];
99
133
100
134
forceSelectionUpdate = YES ;
101
135
NSSize cellSpacing = [commitList intercellSpacing ];
@@ -131,9 +165,10 @@ - (void)loadView {
131
165
// listen for updates
132
166
[[NSNotificationCenter defaultCenter ] addObserver: self selector: @selector (_repositoryUpdatedNotification: ) name: PBGitRepositoryEventNotification object: repository];
133
167
134
- __unsafe_unretained PBGitHistoryController * weakSelf = self;
168
+ __weak typeof (self) weakSelf = self;
135
169
commitList.findPanelActionBlock = ^(id sender) {
136
- [weakSelf.view.window makeFirstResponder: weakSelf->searchField];
170
+ __strong typeof (weakSelf) strongSelf = weakSelf;
171
+ [weakSelf.view.window makeFirstResponder: strongSelf->searchField];
137
172
};
138
173
139
174
[super awakeFromNib ];
@@ -147,6 +182,15 @@ - (void) _repositoryUpdatedNotification:(NSNotification *)notification {
147
182
}
148
183
}
149
184
185
+ - (void )reselectCommitAfterUpdate {
186
+ [self updateStatus ];
187
+
188
+ if ([self .repository.currentBranch isSimpleRef ])
189
+ [self selectCommit: [self .repository OIDForRef: self .repository.currentBranch.ref]];
190
+ else
191
+ [self selectCommit: self .firstCommit.OID];
192
+ }
193
+
150
194
- (NSTableRowView *)tableView : (NSTableView *)tableView rowViewForRow : (NSInteger )row {
151
195
NSTableRowView *view = [tableView rowViewAtRow: row makeIfNecessary: NO ];
152
196
@@ -309,56 +353,6 @@ - (void) saveFileBrowserSelection
309
353
}
310
354
}
311
355
312
- - (void ) observeValueForKeyPath : (NSString *)keyPath ofObject : (id )object change : (NSDictionary *)change context : (void *)context
313
- {
314
- NSString * strContext = (__bridge NSString *)context;
315
- if ([strContext isEqualToString: @" commitChange" ]) {
316
- [self updateKeys ];
317
- [self restoreFileBrowserSelection ];
318
- return ;
319
- }
320
-
321
- if ([strContext isEqualToString: @" treeChange" ]) {
322
- [self updateQuicklookForce: NO ];
323
- [self saveFileBrowserSelection ];
324
- return ;
325
- }
326
-
327
- if ([strContext isEqualToString: @" branchChange" ]) {
328
- // Reset the sorting
329
- if ([[commitController sortDescriptors ] count ]) {
330
- [commitController setSortDescriptors: [NSArray array ]];
331
- [commitController rearrangeObjects ];
332
- }
333
-
334
- [self updateBranchFilterMatrix ];
335
- return ;
336
- }
337
-
338
- if ([strContext isEqualToString: @" updateRefs" ]) {
339
- [commitController rearrangeObjects ];
340
- return ;
341
- }
342
-
343
- if ([strContext isEqualToString: @" branchFilterChange" ]) {
344
- [PBGitDefaults setBranchFilter: repository.currentBranchFilter];
345
- [self updateBranchFilterMatrix ];
346
- return ;
347
- }
348
-
349
- if ([strContext isEqualToString: @" updateCommitCount" ] || [(__bridge NSString *)context isEqualToString: @" revisionListUpdating" ]) {
350
- [self updateStatus ];
351
-
352
- if ([repository.currentBranch isSimpleRef ])
353
- [self selectCommit: [repository OIDForRef: repository.currentBranch.ref]];
354
- else
355
- [self selectCommit: self .firstCommit.OID];
356
- return ;
357
- }
358
-
359
- [super observeValueForKeyPath: keyPath ofObject: object change: change context: context];
360
- }
361
-
362
356
- (IBAction ) openSelectedFile : (id )sender
363
357
{
364
358
NSArray * selectedFiles = [treeController selectedObjects ];
@@ -563,17 +557,7 @@ - (BOOL) hasNonlinearPath
563
557
564
558
- (void )closeView
565
559
{
566
- if (commitController) {
567
- [[NSNotificationCenter defaultCenter ] removeObserver: self ];
568
- [commitController removeObserver: self forKeyPath: @" selection" ];
569
- [commitController removeObserver: self forKeyPath: @" arrangedObjects.@count" ];
570
- [treeController removeObserver: self forKeyPath: @" selection" ];
571
-
572
- [repository.revisionList removeObserver: self forKeyPath: @" isUpdating" ];
573
- [repository removeObserver: self forKeyPath: @" currentBranch" ];
574
- [repository removeObserver: self forKeyPath: @" refs" ];
575
- [repository removeObserver: self forKeyPath: @" currentBranchFilter" ];
576
- }
560
+ [[NSNotificationCenter defaultCenter ] removeObserver: self ];
577
561
578
562
[webHistoryController closeView ];
579
563
[fileView closeView ];
0 commit comments