Refactored the selection tracking to be in the document now

Filtering should work reliably now. No "sticking" of entries
Fixed #42. Deleted entries now result in desolation.
This commit is contained in:
michael starke
2013-07-24 01:05:49 +02:00
parent 8087085fc0
commit 4a35d0d4ff
29 changed files with 1713 additions and 1444 deletions

View File

@@ -16,6 +16,7 @@
#import "MPIconHelper.h"
#import "MPUppercaseStringValueTransformer.h"
#import "MPRootAdapter.h"
#import "MPNotifications.h"
#import "KdbLib.h"
#import "Kdb4Node.h"
@@ -33,7 +34,6 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell";
}
@property (weak) IBOutlet NSOutlineView *outlineView;
@property (weak) IBOutlet NSButton *addGroupButton;
@property (nonatomic, weak) KdbGroup *selectedGroup;
@property (strong) NSTreeController *treeController;
@property (strong) MPOutlineDataSource *datasource;
@@ -71,6 +71,11 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell";
[_outlineView setDraggingSourceOperationMask:NSDragOperationEvery forLocal:YES];
[_bottomBar setBorderType:HNHBorderTop];
[_addGroupButton setAction:[MPActionHelper actionOfType:MPActionAddGroup]];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(_didBecomeFirstResponder:)
name:MPDidBecomeFirstResonderNotification
object:_outlineView];
}
- (void)showOutline {
@@ -101,17 +106,6 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell";
}
}
//- (void)setSelectedGroup:(KdbGroup *)selectedGroup {
// if(_selectedGroup != selectedGroup) {
// _selectedGroup = selectedGroup;
// if([selectedGroup isKindOfClass:[Kdb4Group class]]) {
// MPDocument *document = [[self windowController] document];
// document.treeV4.lastSelectedGroup = ((Kdb4Group *)selectedGroup).uuid;
// }
// }
//}
#pragma mark Notifications
- (void)setupNotifications:(MPDocumentWindowController *)windowController {
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didCreateGroup:) name:MPDocumentDidAddGroupNotification object:[windowController document]];
@@ -128,7 +122,6 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell";
if( selectedRow == -1) {
MPDocument *document = [[self windowController] document];
indexSet = [NSIndexSet indexSetWithIndex:[document.root.groups count]];
//TODO: Find out why selection is not set (treeUpdate?)
}
else {
id item = [_outlineView itemAtRow:selectedRow];
@@ -137,6 +130,14 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell";
}
}
- (void)_didBecomeFirstResponder:(NSNotification *)notification {
if( [notification object] != _outlineView ) {
return; // Nothing we need to worry about
}
MPDocument *document = [[self windowController] document];
document.selectedItem = document.selectedGroup;
}
#pragma mark Validation
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
@@ -212,8 +213,8 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell";
- (void)outlineViewSelectionDidChange:(NSNotification *)notification {
NSTreeNode *treeNode = [_outlineView itemAtRow:[_outlineView selectedRow]];
KdbGroup *selectedGroup = [treeNode representedObject];
self.selectedGroup = selectedGroup;
[[NSNotificationCenter defaultCenter] postNotificationName:MPOutlineViewDidChangeGroupSelection object:self userInfo:nil];
MPDocument *document = [[self windowController] document];
document.selectedGroup = selectedGroup;
}
- (BOOL)outlineView:(NSOutlineView *)outlineView shouldShowOutlineCellForItem:(id)item {