Add 'open' option to downloads panel

This commit is contained in:
anthony 2021-02-09 19:44:05 +00:00
parent d2c2ff6bb9
commit 7868683d3e
3 changed files with 21 additions and 4 deletions

View File

@ -49,6 +49,7 @@ struct download_context;
-(NSArray*)downloads;
-(void)removeDownloadsAtIndexes: (NSIndexSet*)anIndexSet;
-(void)cancelDownloadsAtIndexes: (NSIndexSet*)anIndexSet;
-(void)openDownloadAtIndex: (NSInteger)index;
-(id)delegate;
-(void)setDelegate: (id<DownloadManagerDelegate>)aDelegate;
@end

View File

@ -6,7 +6,7 @@
@implementation DownloadItem
-(id)initWithManager: (DownloadManager*)aManager destination: (NSURL*)aDestination size: (NSInteger)aSize index: (NSUInteger)anIndex ctx: (struct download_context*)aCtx {
if (self = [super init]) {
if ((self = [super init])) {
error = nil;
index = anIndex;
written = 0;
@ -196,7 +196,7 @@
}
-(id)init {
if (self = [super init]) {
if ((self = [super init])) {
downloads = [[NSMutableArray alloc] init];
delegate = nil;
}
@ -246,4 +246,10 @@
[items makeObjectsPerformSelector: @selector(cancel)];
}
-(void)openDownloadAtIndex: (NSInteger)anIndex {
DownloadItem *item = [downloads objectAtIndex: anIndex];
NSString *path = [[item destination] absoluteString];
[[NSWorkspace sharedWorkspace] openFile: path];
}
@end

View File

@ -7,7 +7,7 @@
@implementation DownloadsWindowController
-(id)init {
if (self = [super initWithWindowNibName: @"Downloads"]) {
if ((self = [super initWithWindowNibName: @"Downloads"])) {
//...
}
return self;
@ -89,7 +89,7 @@
-(BOOL)validateMenuItem: (NSMenuItem*)aMenuItem {
NSInteger tag = [aMenuItem tag];
if (tag == TAG_MENU_REMOVE || tag == TAG_MENU_CANCEL) {
if (tag == TAG_MENU_REMOVE || tag == TAG_MENU_CANCEL || tag == TAG_MENU_OPEN) {
return [tableView numberOfSelectedRows] > 0;
}
return YES;
@ -115,5 +115,15 @@
[[DownloadManager defaultDownloadManager] cancelDownloadsAtIndexes: indices];
}
-(void)open: (id)sender {
NSMutableIndexSet *indices = [NSMutableIndexSet indexSet];
NSEnumerator *selectedRows = [tableView selectedRowEnumerator];
id row = [selectedRows nextObject];
if (row != nil) {
[[DownloadManager defaultDownloadManager] openDownloadAtIndex: [row integerValue]];
}
}
@end