Revision: 13985
http://sourceforge.net/p/skim-app/code/13985
Author: hofman
Date: 2023-12-25 10:41:24 +0000 (Mon, 25 Dec 2023)
Log Message:
-----------
Include UI updating in array KVC methods for downloads. Make array KVC methods
private.
Modified Paths:
--------------
trunk/SKDownloadController.h
trunk/SKDownloadController.m
Modified: trunk/SKDownloadController.h
===================================================================
--- trunk/SKDownloadController.h 2023-12-24 22:52:50 UTC (rev 13984)
+++ trunk/SKDownloadController.h 2023-12-25 10:41:24 UTC (rev 13985)
@@ -72,15 +72,10 @@
- (IBAction)moveToTrash:(nullable id)sender;
@property (nonatomic, readonly) NSArray<SKDownload *> *downloads;
-@property (nonatomic, readonly) NSUInteger countOfDownloads;
-- (SKDownload *)objectInDownloadsAtIndex:(NSUInteger)anIndex;
-- (void)insertObject:(SKDownload *)download
inDownloadsAtIndex:(NSUInteger)anIndex;
-- (void)removeDownloadsAtIndexes:(NSIndexSet *)indexes;
// these notify and animate, so should be used to add/remove downloads
- (void)addObjectToDownloads:(SKDownload *)download;
- (void)removeObjectFromDownloads:(SKDownload *)download;
-- (void)removeObjectsFromDownloadsAtIndexes:(NSIndexSet *)indexes;
- (void)setupToolbar;
Modified: trunk/SKDownloadController.m
===================================================================
--- trunk/SKDownloadController.m 2023-12-24 22:52:50 UTC (rev 13984)
+++ trunk/SKDownloadController.m 2023-12-25 10:41:24 UTC (rev 13985)
@@ -80,13 +80,17 @@
static NSString *SKDownloadsIdentifier = nil;
@interface SKDownloadController () <NSURLSessionDelegate>
-@end
-@interface SKDownloadController (SKPrivate)
+@property (nonatomic, readonly) NSUInteger countOfDownloads;
+- (SKDownload *)objectInDownloadsAtIndex:(NSUInteger)anIndex;
+- (void)insertObject:(SKDownload *)download
inDownloadsAtIndex:(NSUInteger)anIndex;
+- (void)removeDownloadsAtIndexes:(NSIndexSet *)indexes;
+
- (void)handleApplicationWillTerminateNotification:(NSNotification
*)notification;
- (void)startObservingDownloads:(NSArray *)newDownloads;
- (void)endObservingDownloads:(NSArray *)oldDownloads;
- (void)updateClearButton;
+
@end
@implementation SKDownloadController
@@ -223,9 +227,15 @@
}
- (void)insertObject:(SKDownload *)download
inDownloadsAtIndex:(NSUInteger)anIndex {
+ NSTableViewAnimationOptions options = NSTableViewAnimationEffectGap |
NSTableViewAnimationSlideDown;
+ if ([self isWindowLoaded] == NO || [[self window] isVisible] == NO ||
[NSView shouldShowSlideAnimation] == NO)
+ options = NSTableViewAnimationEffectNone;
+ [tableView beginUpdates];
+ [tableView insertRowsAtIndexes:[NSIndexSet indexSetWithIndex:anIndex]
withAnimation:options];
[downloads insertObject:download atIndex:anIndex];
[self startObservingDownloads:@[download]];
[download start];
+ [tableView endUpdates];
[self updateClearButton];
}
@@ -232,8 +242,14 @@
- (void)removeDownloadsAtIndexes:(NSIndexSet *)indexes {
NSArray *oldDownloads = [downloads objectsAtIndexes:indexes];
[self endObservingDownloads:oldDownloads];
- [downloads makeObjectsPerformSelector:@selector(cancel)];
+ [oldDownloads makeObjectsPerformSelector:@selector(cancel)];
+ NSTableViewAnimationOptions options = NSTableViewAnimationEffectGap |
NSTableViewAnimationSlideUp;
+ if ([self isWindowLoaded] == NO || [[self window] isVisible] == NO ||
[NSView shouldShowSlideAnimation] == NO)
+ options = NSTableViewAnimationEffectNone;
+ [tableView beginUpdates];
+ [tableView removeRowsAtIndexes:indexes withAnimation:options];
[downloads removeObjectsAtIndexes:indexes];
+ [tableView endUpdates];
[self updateClearButton];
}
@@ -240,30 +256,13 @@
#pragma mark Adding/Removing Downloads
- (void)addObjectToDownloads:(SKDownload *)download {
- NSInteger row = [self countOfDownloads];
- NSTableViewAnimationOptions options = NSTableViewAnimationEffectGap |
NSTableViewAnimationSlideDown;
- if ([self isWindowLoaded] == NO || [[self window] isVisible] == NO ||
[NSView shouldShowSlideAnimation] == NO)
- options = NSTableViewAnimationEffectNone;
- [tableView beginUpdates];
- [tableView insertRowsAtIndexes:[NSIndexSet indexSetWithIndex:row]
withAnimation:options];
- [self insertObject:download inDownloadsAtIndex:row];
- [tableView endUpdates];
+ [self insertObject:download inDownloadsAtIndex:[self countOfDownloads]];
}
-- (void)removeObjectsFromDownloadsAtIndexes:(NSIndexSet *)indexes {
- NSTableViewAnimationOptions options = NSTableViewAnimationEffectGap |
NSTableViewAnimationSlideUp;
- if ([self isWindowLoaded] == NO || [[self window] isVisible] == NO ||
[NSView shouldShowSlideAnimation] == NO)
- options = NSTableViewAnimationEffectNone;
- [tableView beginUpdates];
- [tableView removeRowsAtIndexes:indexes withAnimation:options];
- [self removeDownloadsAtIndexes:indexes];
- [tableView endUpdates];
-}
-
- (void)removeObjectFromDownloads:(SKDownload *)download {
NSUInteger idx = [downloads indexOfObject:download];
if (idx != NSNotFound)
- [self removeObjectsFromDownloadsAtIndexes:[NSIndexSet
indexSetWithIndex:idx]];
+ [self removeDownloadsAtIndexes:[NSIndexSet indexSetWithIndex:idx]];
}
#pragma mark Actions
@@ -283,7 +282,7 @@
[indexes addIndex:i];
}
if ([indexes count])
- [self removeObjectsFromDownloadsAtIndexes:indexes];
+ [self removeDownloadsAtIndexes:indexes];
}
- (IBAction)moveToTrash:(id)sender {
@@ -464,7 +463,7 @@
else if ([download canRemove])
[removeIndexes addIndex:row];
if ([removeIndexes count])
- [self removeObjectsFromDownloadsAtIndexes:removeIndexes];
+ [self removeDownloadsAtIndexes:removeIndexes];
}
- (BOOL)tableView:(NSTableView *)aTableView
canDeleteRowsWithIndexes:(NSIndexSet *)rowIndexes {
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit