mirror of
https://github.com/MacPass/MacPass.git
synced 2025-12-13 22:52:26 +00:00
Group view has rudimentary drag'n'drop support
This commit is contained in:
@@ -17,10 +17,11 @@ APPKIT_EXTERN NSString *const MPGroupNameUndoableKey;
|
|||||||
- (NSString *)nameUndoable;
|
- (NSString *)nameUndoable;
|
||||||
- (void)setNameUndoable:(NSString *)newName;
|
- (void)setNameUndoable:(NSString *)newName;
|
||||||
|
|
||||||
|
|
||||||
- (void)addEntryUndoable:(KdbEntry *)entry;
|
- (void)addEntryUndoable:(KdbEntry *)entry;
|
||||||
- (void)addGroupUndoable:(KdbGroup *)group;
|
- (void)addGroupUndoable:(KdbGroup *)group;
|
||||||
- (void)removeGroupUndoable:(KdbGroup *)group;
|
- (void)removeGroupUndoable:(KdbGroup *)group;
|
||||||
- (void)removeEntryUndoable:(KdbEntry *)entry;
|
- (void)removeEntryUndoable:(KdbEntry *)entry;
|
||||||
|
|
||||||
|
- (void)moveToGroupUndoable:(KdbGroup *)group;
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -58,4 +58,17 @@ NSString *const MPGroupNameUndoableKey = @"nameUndoable";
|
|||||||
[[self undoManager] setActionName:NSLocalizedString(@"UNDO_DELETE_GROUP", @"Create Group Undo")];
|
[[self undoManager] setActionName:NSLocalizedString(@"UNDO_DELETE_GROUP", @"Create Group Undo")];
|
||||||
[group.parent removeObjectFromGroupsAtIndex:index];
|
[group.parent removeObjectFromGroupsAtIndex:index];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (void)moveToGroupUndoable:(KdbGroup *)group {
|
||||||
|
NSInteger index = [self.parent.groups indexOfObject:self];
|
||||||
|
if(NSNotFound == index) {
|
||||||
|
return; // No object found
|
||||||
|
}
|
||||||
|
[[self undoManager] registerUndoWithTarget:self selector:@selector(moveToGroupUndoable:) object:self.parent];
|
||||||
|
[[self undoManager] setActionName:NSLocalizedString(@"UNDO_MOVE_GROUP", @"Move Group Undo")];
|
||||||
|
[self.parent removeObjectFromGroupsAtIndex:index];
|
||||||
|
[group insertObject:self inGroupsAtIndex:[group.groups count]];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -8,7 +8,11 @@
|
|||||||
|
|
||||||
#import <Foundation/Foundation.h>
|
#import <Foundation/Foundation.h>
|
||||||
|
|
||||||
@interface MPOutlineDataSource : NSObject <NSOutlineViewDataSource>
|
APPKIT_EXTERN NSString *const MPPasteBoardType;
|
||||||
|
|
||||||
|
@class KdbGroup;
|
||||||
|
|
||||||
|
@interface MPOutlineDataSource : NSObject <NSOutlineViewDataSource> {
|
||||||
|
KdbGroup *_draggedItem;
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -9,43 +9,45 @@
|
|||||||
#import "MPOutlineDataSource.h"
|
#import "MPOutlineDataSource.h"
|
||||||
#import "MPDocument.h"
|
#import "MPDocument.h"
|
||||||
#import "KdbLib.h"
|
#import "KdbLib.h"
|
||||||
|
#import "KdbGroup+Undo.h"
|
||||||
|
|
||||||
|
NSString *const MPPasteBoardType = @"com.hicknhack.macpass.pasteboard";
|
||||||
|
|
||||||
@implementation MPOutlineDataSource
|
@implementation MPOutlineDataSource
|
||||||
|
|
||||||
- (NSInteger)outlineView:(NSOutlineView *)outlineView numberOfChildrenOfItem:(id)item {
|
|
||||||
if(!item) {
|
- (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray *)items toPasteboard:(NSPasteboard *)pasteboard {
|
||||||
return 1;
|
[_draggedItem release];
|
||||||
|
_draggedItem = nil;
|
||||||
|
[pasteboard setString:@"Weee" forType:MPPasteBoardType];
|
||||||
|
if([items count] == 1) {
|
||||||
|
_draggedItem = [[[items lastObject] representedObject] retain];
|
||||||
|
return (nil != _draggedItem.parent);
|
||||||
}
|
}
|
||||||
if( [item isKindOfClass:[KdbGroup class]]) {
|
return YES;
|
||||||
KdbGroup *group = item;
|
|
||||||
return [[group groups] count];
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
- (id)outlineView:(NSOutlineView *)outlineView child:(NSInteger)index ofItem:(id)item {
|
|
||||||
if(!item) {
|
|
||||||
MPDocument *document = [[[outlineView window] windowController] document];
|
|
||||||
return document.root;
|
|
||||||
}
|
|
||||||
if( [item isKindOfClass:[KdbGroup class]]) {
|
|
||||||
KdbGroup *group = item;
|
|
||||||
if( [[group groups] count] > index ) {
|
|
||||||
return [group groups][index];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nil;
|
|
||||||
}
|
|
||||||
- (BOOL)outlineView:(NSOutlineView *)outlineView isItemExpandable:(id)item {
|
|
||||||
if(!item) {
|
|
||||||
MPDocument *document = [[[outlineView window] windowController] document];
|
|
||||||
return ([[document.root groups] count] > 0);
|
|
||||||
}
|
|
||||||
if([item isKindOfClass:[KdbGroup class]])
|
|
||||||
{
|
|
||||||
KdbGroup *group = item;
|
|
||||||
return ([[group groups] count] > 0);
|
|
||||||
}
|
|
||||||
return NO;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
- (NSDragOperation)outlineView:(NSOutlineView *)outlineView validateDrop:(id<NSDraggingInfo>)info proposedItem:(id)item proposedChildIndex:(NSInteger)index {
|
||||||
|
if(_draggedItem) {
|
||||||
|
KdbGroup *target = [item representedObject];
|
||||||
|
if( target == nil) {
|
||||||
|
return NSDragOperationNone; // Draggin over root
|
||||||
|
}
|
||||||
|
BOOL validParent = ( _draggedItem.parent == target && index != NSOutlineViewDropOnItemIndex);
|
||||||
|
if(validParent || _draggedItem.parent != target) {
|
||||||
|
return NSDragOperationMove;
|
||||||
|
info.animatesToDestination = YES;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return NSDragOperationNone;
|
||||||
|
}
|
||||||
|
|
||||||
|
- (BOOL)outlineView:(NSOutlineView *)outlineView acceptDrop:(id<NSDraggingInfo>)info item:(id)item childIndex:(NSInteger)index {
|
||||||
|
NSLog(@"Drag %@ to: %@ index: %ld", _draggedItem, [item representedObject], index);
|
||||||
|
KdbGroup *target = [item representedObject];
|
||||||
|
BOOL accepted = (target != _draggedItem.parent);
|
||||||
|
info.animatesToDestination = YES;
|
||||||
|
[_draggedItem moveToGroupUndoable:target];
|
||||||
|
return accepted;
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
|||||||
@@ -13,6 +13,7 @@
|
|||||||
#import "MPAppDelegate.h"
|
#import "MPAppDelegate.h"
|
||||||
#import "KdbLib.h"
|
#import "KdbLib.h"
|
||||||
|
|
||||||
|
|
||||||
@interface MPOutlineViewController () {
|
@interface MPOutlineViewController () {
|
||||||
BOOL _bindingEstablished;
|
BOOL _bindingEstablished;
|
||||||
}
|
}
|
||||||
@@ -42,8 +43,8 @@
|
|||||||
if (self) {
|
if (self) {
|
||||||
_treeController = [[NSTreeController alloc] init];
|
_treeController = [[NSTreeController alloc] init];
|
||||||
_bindingEstablished = NO;
|
_bindingEstablished = NO;
|
||||||
self.outlineDelegate = [[[MPOutlineViewDelegate alloc] init] autorelease];
|
_outlineDelegate = [[MPOutlineViewDelegate alloc] init];
|
||||||
self.datasource = [[[MPOutlineDataSource alloc] init] autorelease];
|
_datasource = [[MPOutlineDataSource alloc] init];
|
||||||
|
|
||||||
[[NSNotificationCenter defaultCenter] addObserver:self
|
[[NSNotificationCenter defaultCenter] addObserver:self
|
||||||
selector:@selector(_didUpdateData:)
|
selector:@selector(_didUpdateData:)
|
||||||
@@ -71,11 +72,11 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
- (void)didLoadView {
|
- (void)didLoadView {
|
||||||
//[self.outlineView setDataSource:self.datasource];
|
|
||||||
[self.outlineView setDelegate:self.outlineDelegate];
|
[self.outlineView setDelegate:self.outlineDelegate];
|
||||||
[self.outlineView setMenu:[self _contextMenu]];
|
[self.outlineView setMenu:[self _contextMenu]];
|
||||||
[self.outlineView setAllowsEmptySelection:YES];
|
[self.outlineView setAllowsEmptySelection:YES];
|
||||||
[self.outlineView setFloatsGroupRows:NO];
|
[self.outlineView setFloatsGroupRows:NO];
|
||||||
|
[_outlineView registerForDraggedTypes:@[ MPPasteBoardType ]];
|
||||||
[self.outlineView setDraggingSourceOperationMask:NSDragOperationEvery forLocal:YES];
|
[self.outlineView setDraggingSourceOperationMask:NSDragOperationEvery forLocal:YES];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,6 +86,7 @@
|
|||||||
[_treeController setChildrenKeyPath:@"groups"];
|
[_treeController setChildrenKeyPath:@"groups"];
|
||||||
[_treeController bind:NSContentBinding toObject:document withKeyPath:@"root" options:nil];
|
[_treeController bind:NSContentBinding toObject:document withKeyPath:@"root" options:nil];
|
||||||
[_outlineView bind:NSContentBinding toObject:_treeController withKeyPath:@"arrangedObjects" options:nil];
|
[_outlineView bind:NSContentBinding toObject:_treeController withKeyPath:@"arrangedObjects" options:nil];
|
||||||
|
[_outlineView setDataSource:self.datasource];
|
||||||
_bindingEstablished = YES;
|
_bindingEstablished = YES;
|
||||||
}
|
}
|
||||||
NSTreeNode *node = [_outlineView itemAtRow:0];
|
NSTreeNode *node = [_outlineView itemAtRow:0];
|
||||||
|
|||||||
@@ -48,7 +48,7 @@
|
|||||||
<key>CFBundleSignature</key>
|
<key>CFBundleSignature</key>
|
||||||
<string>????</string>
|
<string>????</string>
|
||||||
<key>CFBundleVersion</key>
|
<key>CFBundleVersion</key>
|
||||||
<string>A2F</string>
|
<string>A6E</string>
|
||||||
<key>LSMinimumSystemVersion</key>
|
<key>LSMinimumSystemVersion</key>
|
||||||
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
|
<string>${MACOSX_DEPLOYMENT_TARGET}</string>
|
||||||
<key>NSHumanReadableCopyright</key>
|
<key>NSHumanReadableCopyright</key>
|
||||||
|
|||||||
Reference in New Issue
Block a user