mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-14 23:52:21 +00:00
MPOutlineViewController refactored to use MPTargetItemResolving
This commit is contained in:
@@ -533,6 +533,9 @@ NSString *const MPDocumentGroupKey = @"MPDocumentGroupKey
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)deleteGroup:(KPKGroup *)group {
|
- (void)deleteGroup:(KPKGroup *)group {
|
||||||
|
if(!group) {
|
||||||
|
return; // Nothing to do;
|
||||||
|
}
|
||||||
if(self.useTrash) {
|
if(self.useTrash) {
|
||||||
if(!self.trash) {
|
if(!self.trash) {
|
||||||
[self _createTrashGroup];
|
[self _createTrashGroup];
|
||||||
|
|||||||
@@ -7,13 +7,14 @@
|
|||||||
//
|
//
|
||||||
|
|
||||||
#import "MPViewController.h"
|
#import "MPViewController.h"
|
||||||
|
#import "MPTargetItemResolving.h"
|
||||||
|
|
||||||
APPKIT_EXTERN NSString *const MPOutlineViewDidChangeGroupSelection;
|
APPKIT_EXTERN NSString *const MPOutlineViewDidChangeGroupSelection;
|
||||||
|
|
||||||
@class HNHGradientView;
|
@class HNHGradientView;
|
||||||
@class MPDocument;
|
@class MPDocument;
|
||||||
|
|
||||||
@interface MPOutlineViewController : MPViewController <NSOutlineViewDelegate, NSMenuDelegate>
|
@interface MPOutlineViewController : MPViewController <MPTargetItemResolving, NSOutlineViewDelegate, NSMenuDelegate>
|
||||||
|
|
||||||
|
|
||||||
@property (weak) IBOutlet HNHGradientView *bottomBar;
|
@property (weak) IBOutlet HNHGradientView *bottomBar;
|
||||||
|
|||||||
@@ -145,6 +145,15 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell";
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#pragma mark MPTargetItemResolving
|
||||||
|
- (KPKNode *)targetItemForAction {
|
||||||
|
NSInteger row = [self.outlineView clickedRow];
|
||||||
|
if( row < 0 ) {
|
||||||
|
row = [self.outlineView selectedRow];
|
||||||
|
}
|
||||||
|
return [[self.outlineView itemAtRow:row] representedObject];
|
||||||
|
}
|
||||||
|
|
||||||
#pragma mark Notifications
|
#pragma mark Notifications
|
||||||
- (void)regsiterNotificationsForDocument:(MPDocument *)document {
|
- (void)regsiterNotificationsForDocument:(MPDocument *)document {
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didAddGroup:) name:MPDocumentDidAddGroupNotification object:document];
|
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(_didAddGroup:) name:MPDocumentDidAddGroupNotification object:document];
|
||||||
@@ -189,7 +198,7 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell";
|
|||||||
#pragma mark Actions
|
#pragma mark Actions
|
||||||
|
|
||||||
- (void)createGroup:(id)sender {
|
- (void)createGroup:(id)sender {
|
||||||
KPKGroup *group = [self _clickedOrSelectedGroup];
|
KPKGroup *group = [[self targetItemForAction] asGroup];
|
||||||
MPDocument *document = [[self windowController] document];
|
MPDocument *document = [[self windowController] document];
|
||||||
if(!group) {
|
if(!group) {
|
||||||
group = document.root;
|
group = document.root;
|
||||||
@@ -199,11 +208,11 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell";
|
|||||||
|
|
||||||
- (void)createEntry:(id)sender {
|
- (void)createEntry:(id)sender {
|
||||||
MPDocument *document = [[self windowController] document];
|
MPDocument *document = [[self windowController] document];
|
||||||
[document createEntry:[self _clickedOrSelectedGroup]];
|
[document createEntry:[[self targetItemForAction] asGroup]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)delete:(id)sender {
|
- (void)delete:(id)sender {
|
||||||
[[[self windowController] document] deleteGroup:[self _clickedOrSelectedGroup]];
|
[[[self windowController] document] deleteGroup:[[self targetItemForAction] asGroup]];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (void)_doubleClickedGroup:(id)sender {
|
- (void)_doubleClickedGroup:(id)sender {
|
||||||
@@ -281,21 +290,14 @@ NSString *const _MPOutlinveViewHeaderViewIdentifier = @"HeaderCell";
|
|||||||
if(![document validateUserInterfaceItem:menuItem]) {
|
if(![document validateUserInterfaceItem:menuItem]) {
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
id selected = [self _clickedOrSelectedGroup];
|
id selected = [[self targetItemForAction] asGroup];
|
||||||
if(!selected) { return NO; }
|
if(!selected) {
|
||||||
if(selected == document.trash) { return NO; }
|
return NO;
|
||||||
return ![document isItemTrashed:selected];
|
|
||||||
}
|
|
||||||
|
|
||||||
#pragma mark -
|
|
||||||
#pragma mark Private
|
|
||||||
|
|
||||||
- (KPKGroup *)_clickedOrSelectedGroup {
|
|
||||||
NSInteger row = [self.outlineView clickedRow];
|
|
||||||
if( row < 0 ) {
|
|
||||||
row = [self.outlineView selectedRow];
|
|
||||||
}
|
}
|
||||||
return [[self.outlineView itemAtRow:row] representedObject];
|
if(selected == document.trash) {
|
||||||
|
return NO;
|
||||||
|
}
|
||||||
|
return ![document isItemTrashed:selected];
|
||||||
}
|
}
|
||||||
|
|
||||||
- (NSMenu *)_contextMenu {
|
- (NSMenu *)_contextMenu {
|
||||||
|
|||||||
Reference in New Issue
Block a user