mirror of
https://github.com/ksherlock/ample.git
synced 2025-01-10 07:29:37 +00:00
use some pretty animations when drag/dropping media.
This commit is contained in:
parent
416310fe69
commit
8362692523
@ -71,7 +71,7 @@
|
|||||||
<action selector="pathAction:" target="-2" id="4oX-bW-ANp"/>
|
<action selector="pathAction:" target="-2" id="4oX-bW-ANp"/>
|
||||||
</connections>
|
</connections>
|
||||||
</pathControl>
|
</pathControl>
|
||||||
<imageView hidden="YES" horizontalHuggingPriority="251" verticalHuggingPriority="251" id="6g1-NT-J1w">
|
<imageView horizontalHuggingPriority="251" verticalHuggingPriority="251" id="6g1-NT-J1w">
|
||||||
<rect key="frame" x="0.0" y="1" width="20" height="20"/>
|
<rect key="frame" x="0.0" y="1" width="20" height="20"/>
|
||||||
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
<autoresizingMask key="autoresizingMask" flexibleMaxX="YES" flexibleMinY="YES"/>
|
||||||
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageAlignment="left" image="drag-handle-4x10" id="x7F-qD-5y9"/>
|
<imageCell key="cell" refusesFirstResponder="YES" alignment="left" imageAlignment="left" image="drag-handle-4x10" id="x7F-qD-5y9"/>
|
||||||
|
@ -26,6 +26,7 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
-(void)viewDidMoveToSuperview {
|
-(void)viewDidMoveToSuperview {
|
||||||
|
return;
|
||||||
if (_trackingRect) {
|
if (_trackingRect) {
|
||||||
[self removeTrackingRect: _trackingRect];
|
[self removeTrackingRect: _trackingRect];
|
||||||
}
|
}
|
||||||
@ -151,25 +152,32 @@
|
|||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(BOOL)pruneChildren {
|
-(BOOL)pruneChildrenWithOutlineView: (NSOutlineView *)view {
|
||||||
NSUInteger count = [_children count];
|
NSUInteger count = [_children count];
|
||||||
BOOL delta = NO;
|
BOOL delta = NO;
|
||||||
if (_validCount == count) return NO;
|
if (_validCount == count) return NO;
|
||||||
|
NSMutableIndexSet *set = [NSMutableIndexSet new];
|
||||||
|
|
||||||
for (NSInteger i = _validCount; i < count; ++i) {
|
for (NSInteger i = _validCount; i < count; ++i) {
|
||||||
MediaItem *item = [_children lastObject];
|
MediaItem *item = [_children lastObject];
|
||||||
if ([item url]) break;
|
if ([item url]) break;
|
||||||
|
|
||||||
[_children removeLastObject];
|
[_children removeLastObject];
|
||||||
|
[set addIndex: [_children count]];
|
||||||
|
|
||||||
delta = YES;
|
delta = YES;
|
||||||
}
|
}
|
||||||
if (delta) {
|
if (delta) {
|
||||||
|
|
||||||
|
if (view)
|
||||||
|
[view removeItemsAtIndexes: set inParent: self withAnimation: NSTableViewAnimationEffectFade];
|
||||||
|
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
return NO;
|
return NO;
|
||||||
}
|
}
|
||||||
|
|
||||||
-(BOOL)moveItemFrom: (NSInteger)oldIndex to: (NSInteger)newIndex {
|
-(BOOL)moveItemFrom: (NSInteger)oldIndex to: (NSInteger)newIndex outlineView: (NSOutlineView *)view {
|
||||||
if (newIndex == oldIndex) return NO;
|
if (newIndex == oldIndex) return NO;
|
||||||
NSUInteger count = [_children count];
|
NSUInteger count = [_children count];
|
||||||
if (oldIndex >= count) return NO;
|
if (oldIndex >= count) return NO;
|
||||||
@ -182,15 +190,20 @@
|
|||||||
} else {
|
} else {
|
||||||
[_children insertObject: item atIndex: newIndex];
|
[_children insertObject: item atIndex: newIndex];
|
||||||
}
|
}
|
||||||
|
if (view) [view moveItemAtIndex: oldIndex inParent: self toIndex: newIndex inParent: self];
|
||||||
|
|
||||||
// re-index and re-validate.
|
// re-index and re-validate.
|
||||||
unsigned ix = 0;
|
unsigned ix = 0;
|
||||||
for (MediaItem *item in _children) {
|
for (MediaItem *item in _children) {
|
||||||
[item setIndex: ix];
|
[item setIndex: ix];
|
||||||
[item setValid: ix < _validCount];
|
[item setValid: ix < _validCount];
|
||||||
|
|
||||||
|
[view reloadItem: item];
|
||||||
|
|
||||||
++ix;
|
++ix;
|
||||||
}
|
}
|
||||||
[self pruneChildren];
|
[self pruneChildrenWithOutlineView: view];
|
||||||
|
//[view reloadItem: self reloadChildren: YES];
|
||||||
return YES;
|
return YES;
|
||||||
}
|
}
|
||||||
@end
|
@end
|
||||||
@ -338,6 +351,9 @@ enum {
|
|||||||
}
|
}
|
||||||
_root = tmp;
|
_root = tmp;
|
||||||
|
|
||||||
|
// todo - switch this to use removeItemsAtIndexes:inParent:withAnimation:
|
||||||
|
// and insertItemsAtIndexes:inParent:withAnimation:
|
||||||
|
|
||||||
[_outlineView reloadData];
|
[_outlineView reloadData];
|
||||||
[_outlineView expandItem: nil expandChildren: YES];
|
[_outlineView expandItem: nil expandChildren: YES];
|
||||||
}
|
}
|
||||||
@ -590,10 +606,12 @@ static NSString *kDragType = @"private.ample.media";
|
|||||||
|
|
||||||
NSInteger oldIndex = indexes[1];
|
NSInteger oldIndex = indexes[1];
|
||||||
|
|
||||||
[cat moveItemFrom: oldIndex to: index];
|
[_outlineView beginUpdates];
|
||||||
|
[cat moveItemFrom: oldIndex to: index outlineView: _outlineView];
|
||||||
|
[_outlineView endUpdates];
|
||||||
[self rebuildArgs];
|
[self rebuildArgs];
|
||||||
|
|
||||||
[_outlineView reloadItem: cat reloadChildren: YES];
|
//[_outlineView reloadItem: cat reloadChildren: YES];
|
||||||
return YES;
|
return YES;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -615,8 +633,14 @@ static NSString *kDragType = @"private.ample.media";
|
|||||||
// if item is invalid, should attempt to remove...
|
// if item is invalid, should attempt to remove...
|
||||||
if (![item valid]) {
|
if (![item valid]) {
|
||||||
MediaCategory *cat = [_outlineView parentForItem: item];
|
MediaCategory *cat = [_outlineView parentForItem: item];
|
||||||
if ([cat pruneChildren]) [self rebuildRoot];
|
[_outlineView beginUpdates];
|
||||||
|
[cat pruneChildrenWithOutlineView: _outlineView];
|
||||||
|
[_outlineView endUpdates];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// todo -- if this eliminates a category completely, it will still be included
|
||||||
|
// since we're now using animaations instead of reloading.
|
||||||
|
|
||||||
[self rebuildArgs];
|
[self rebuildArgs];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user