Revision: 4445
http://skim-app.svn.sourceforge.net/skim-app/?rev=4445&view=rev
Author: hofman
Date: 2008-08-25 16:56:40 +0000 (Mon, 25 Aug 2008)
Log Message:
-----------
Use bindings for download window. Pass a dictionary as object value to the
progressCell, so it can have all the necessary information. Add dependent keys
for KVO.
Modified Paths:
--------------
trunk/English.lproj/DownloadsWindow.nib/classes.nib
trunk/English.lproj/DownloadsWindow.nib/info.nib
trunk/English.lproj/DownloadsWindow.nib/keyedobjects.nib
trunk/SKDownload.h
trunk/SKDownload.m
trunk/SKDownloadController.h
trunk/SKDownloadController.m
trunk/SKProgressCell.h
trunk/SKProgressCell.m
Modified: trunk/English.lproj/DownloadsWindow.nib/classes.nib
===================================================================
--- trunk/English.lproj/DownloadsWindow.nib/classes.nib 2008-08-23 23:05:14 UTC
(rev 4444)
+++ trunk/English.lproj/DownloadsWindow.nib/classes.nib 2008-08-25 16:56:40 UTC
(rev 4445)
@@ -1,54 +1,174 @@
-{
- IBClasses = (
- {
- CLASS = BDSKGradientView;
- LANGUAGE = ObjC;
- SUPERCLASS = NSView;
- },
- {
- ACTIONS = {
- "" = id;
- };
- CLASS = FirstResponder;
- LANGUAGE = ObjC;
- SUPERCLASS = NSObject;
- },
- {
- CLASS = NSObject;
- LANGUAGE = ObjC;
- },
- {
- ACTIONS = {
- cancelDownload = id;
- clearDownloads = id;
- dismissDownloadsPreferences = id;
- removeDownload = id;
- showDownloadPreferences = id;
- };
- CLASS = SKDownloadController;
- LANGUAGE = ObjC;
- OUTLETS = {
- clearButton = NSButton;
- preferencesSheet = NSWindow;
- tableView = SKTableView;
- };
- SUPERCLASS = NSWindowController;
- },
- {
- CLASS = SKProgressCell;
- LANGUAGE = ObjC;
- SUPERCLASS = NSTextFieldCell;
- },
- {
- ACTIONS = {
- delete = id;
- scrollToBeginningOfDocument = id;
- scrollToEndOfDocument = id;
- };
- CLASS = SKTableView;
- LANGUAGE = ObjC;
- SUPERCLASS = NSTableView;
- }
- );
- IBVersion = 1;
-}
\ No newline at end of file
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+ <key>IBClasses</key>
+ <array>
+ <dict>
+ <key>CLASS</key>
+ <string>BDSKGradientView</string>
+ <key>LANGUAGE</key>
+ <string>ObjC</string>
+ <key>SUPERCLASS</key>
+ <string>NSView</string>
+ </dict>
+ <dict>
+ <key>CLASS</key>
+ <string>NSUserDefaultsController</string>
+ <key>LANGUAGE</key>
+ <string>ObjC</string>
+ <key>SUPERCLASS</key>
+ <string>NSController</string>
+ </dict>
+ <dict>
+ <key>CLASS</key>
+ <string>NSWindowController</string>
+ <key>LANGUAGE</key>
+ <string>ObjC</string>
+ <key>SUPERCLASS</key>
+ <string>NSResponder</string>
+ </dict>
+ <dict>
+ <key>CLASS</key>
+ <string>NSMenu</string>
+ <key>LANGUAGE</key>
+ <string>ObjC</string>
+ <key>SUPERCLASS</key>
+ <string>NSObject</string>
+ </dict>
+ <dict>
+ <key>ACTIONS</key>
+ <dict>
+ <key>changeDashPattern</key>
+ <string>id</string>
+ <key>changeEndLineStyle</key>
+ <string>id</string>
+ <key>changeLineStyle</key>
+ <string>id</string>
+ <key>changeLineWidth</key>
+ <string>id</string>
+ <key>changeStartLineStyle</key>
+ <string>id</string>
+ </dict>
+ <key>CLASS</key>
+ <string>NSObject</string>
+ <key>LANGUAGE</key>
+ <string>ObjC</string>
+ </dict>
+ <dict>
+ <key>CLASS</key>
+ <string>NSWindow</string>
+ <key>LANGUAGE</key>
+ <string>ObjC</string>
+ <key>SUPERCLASS</key>
+ <string>NSResponder</string>
+ </dict>
+ <dict>
+ <key>ACTIONS</key>
+ <dict>
+ <key>cancelDownload</key>
+ <string>id</string>
+ <key>clearDownloads</key>
+ <string>id</string>
+ <key>dismissDownloadsPreferences</key>
+ <string>id</string>
+ <key>removeDownload</key>
+ <string>id</string>
+ <key>showDownloadPreferences</key>
+ <string>id</string>
+ </dict>
+ <key>CLASS</key>
+ <string>SKDownloadController</string>
+ <key>LANGUAGE</key>
+ <string>ObjC</string>
+ <key>OUTLETS</key>
+ <dict>
+ <key>arrayController</key>
+ <string>NSArrayController</string>
+ <key>clearButton</key>
+ <string>NSButton</string>
+ <key>preferencesSheet</key>
+ <string>NSWindow</string>
+ <key>tableView</key>
+ <string>SKTableView</string>
+ </dict>
+ <key>SUPERCLASS</key>
+ <string>NSWindowController</string>
+ </dict>
+ <dict>
+ <key>CLASS</key>
+ <string>NSScrollView</string>
+ <key>LANGUAGE</key>
+ <string>ObjC</string>
+ <key>SUPERCLASS</key>
+ <string>NSView</string>
+ </dict>
+ <dict>
+ <key>CLASS</key>
+ <string>SKProgressCell</string>
+ <key>LANGUAGE</key>
+ <string>ObjC</string>
+ <key>SUPERCLASS</key>
+ <string>NSTextFieldCell</string>
+ </dict>
+ <dict>
+ <key>CLASS</key>
+ <string>NSView</string>
+ <key>LANGUAGE</key>
+ <string>ObjC</string>
+ <key>SUPERCLASS</key>
+ <string>NSResponder</string>
+ </dict>
+ <dict>
+ <key>ACTIONS</key>
+ <dict>
+ <key></key>
+ <string>id</string>
+ </dict>
+ <key>CLASS</key>
+ <string>FirstResponder</string>
+ <key>LANGUAGE</key>
+ <string>ObjC</string>
+ <key>SUPERCLASS</key>
+ <string>NSObject</string>
+ </dict>
+ <dict>
+ <key>CLASS</key>
+ <string>NSCell</string>
+ <key>LANGUAGE</key>
+ <string>ObjC</string>
+ <key>SUPERCLASS</key>
+ <string>NSObject</string>
+ </dict>
+ <dict>
+ <key>ACTIONS</key>
+ <dict>
+ <key>copy</key>
+ <string>id</string>
+ <key>delete</key>
+ <string>id</string>
+ <key>scrollToBeginningOfDocument</key>
+ <string>id</string>
+ <key>scrollToEndOfDocument</key>
+ <string>id</string>
+ </dict>
+ <key>CLASS</key>
+ <string>SKTableView</string>
+ <key>LANGUAGE</key>
+ <string>ObjC</string>
+ <key>SUPERCLASS</key>
+ <string>NSTableView</string>
+ </dict>
+ <dict>
+ <key>CLASS</key>
+ <string>NSResponder</string>
+ <key>LANGUAGE</key>
+ <string>ObjC</string>
+ <key>SUPERCLASS</key>
+ <string>NSObject</string>
+ </dict>
+ </array>
+ <key>IBVersion</key>
+ <string>1</string>
+</dict>
+</plist>
Modified: trunk/English.lproj/DownloadsWindow.nib/info.nib
===================================================================
--- trunk/English.lproj/DownloadsWindow.nib/info.nib 2008-08-23 23:05:14 UTC
(rev 4444)
+++ trunk/English.lproj/DownloadsWindow.nib/info.nib 2008-08-25 16:56:40 UTC
(rev 4445)
@@ -2,16 +2,20 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN"
"http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
- <key>IBDocumentLocation</key>
- <string>100 77 356 240 0 0 1440 938 </string>
<key>IBFramework Version</key>
- <string>489.0</string>
+ <string>672</string>
+ <key>IBLastKnownRelativeProjectPath</key>
+ <string>../Skim.xcodeproj</string>
+ <key>IBOldestOS</key>
+ <integer>5</integer>
<key>IBOpenObjects</key>
<array>
- <integer>5</integer>
<integer>30</integer>
+ <integer>6</integer>
</array>
<key>IBSystem Version</key>
- <string>9C7010</string>
+ <string>9E17</string>
+ <key>targetFramework</key>
+ <string>IBCocoaFramework</string>
</dict>
</plist>
Modified: trunk/SKDownload.h
===================================================================
--- trunk/SKDownload.h 2008-08-23 23:05:14 UTC (rev 4444)
+++ trunk/SKDownload.h 2008-08-25 16:56:40 UTC (rev 4445)
@@ -38,6 +38,10 @@
#import <Cocoa/Cocoa.h>
+extern NSString *SKDownloadFileNameKey;
+extern NSString *SKDownloadStatusKey;
+extern NSString *SKDownloadProgressIndicatorKey;
+
enum {
SKDownloadStatusUndefined,
SKDownloadStatusStarting,
@@ -78,6 +82,8 @@
- (NSProgressIndicator *)progressIndicator;
+- (NSDictionary *)info;
+
- (void)startDownload;
- (void)cancelDownload;
- (void)resumeDownload;
@@ -86,6 +92,8 @@
- (BOOL)canCancel;
- (BOOL)canResume;
+- (void)removeProgressIndicatorFromSuperview;
+
@end
Modified: trunk/SKDownload.m
===================================================================
--- trunk/SKDownload.m 2008-08-23 23:05:14 UTC (rev 4444)
+++ trunk/SKDownload.m 2008-08-25 16:56:40 UTC (rev 4445)
@@ -39,7 +39,12 @@
#import "SKDownload.h"
#import <ApplicationServices/ApplicationServices.h>
#import "Files_SKExtensions.h"
+#import "SKRuntime.h"
+NSString *SKDownloadFileNameKey = @"fileName";
+NSString *SKDownloadStatusKey = @"status";
+NSString *SKDownloadProgressIndicatorKey = @"progressIndicator";
+
@interface SKDownload (Private)
- (void)setStatus:(int)newStatus;
- (void)setFilePath:(NSString *)newFilePath;
@@ -51,6 +56,19 @@
@implementation SKDownload
++ (NSArray *)infoKeys {
+ return [NSArray arrayWithObjects:SKDownloadFileNameKey,
SKDownloadStatusKey, SKDownloadProgressIndicatorKey, nil];
+}
+
++ (void)intialize {
+ [self setKeys:[NSArray arrayWithObjects:@"filePath", nil]
triggerChangeNotificationsForDependentKey:@"fileName"];
+ [self setKeys:[NSArray arrayWithObjects:@"filePath", nil]
triggerChangeNotificationsForDependentKey:@"fileIcon"];
+ [self setKeys:[NSArray arrayWithObjects:SKDownloadStatusKey, nil]
triggerChangeNotificationsForDependentKey:@"canCancel"];
+ [self setKeys:[NSArray arrayWithObjects:SKDownloadStatusKey, nil]
triggerChangeNotificationsForDependentKey:@"canResume"];
+ [self setKeys:[self infoKeys]
triggerChangeNotificationsForDependentKey:@"info"];
+ OBINITIALIZE;
+}
+
- (id)initWithURL:(NSURL *)aURL delegate:(id)aDelegate {
if (self = [super init]) {
URL = [aURL retain];
@@ -197,6 +215,19 @@
return progressIndicator;
}
+- (NSDictionary *)info {
+ NSMutableDictionary *info = [NSMutableDictionary dictionary];
+ NSEnumerator *keyEnum = [[[self class] infoKeys] objectEnumerator];
+ NSString *key;
+ while (key = [keyEnum nextObject])
+ [info setValue:[self valueForKey:key] forKey:key];
+ return info;
+}
+
+- (void)removeProgressIndicatorFromSuperview {
+ [progressIndicator removeFromSuperview];
+}
+
#pragma mark Actions
- (void)startDownload {
Modified: trunk/SKDownloadController.h
===================================================================
--- trunk/SKDownloadController.h 2008-08-23 23:05:14 UTC (rev 4444)
+++ trunk/SKDownloadController.h 2008-08-25 16:56:40 UTC (rev 4445)
@@ -41,6 +41,7 @@
@class SKTableView;
@interface SKDownloadController : NSWindowController {
+ IBOutlet NSArrayController *arrayController;
IBOutlet SKTableView *tableView;
IBOutlet NSButton *clearButton;
IBOutlet NSWindow *preferencesSheet;
@@ -58,4 +59,10 @@
- (IBAction)showDownloadPreferences:(id)sender;
- (IBAction)dismissDownloadsPreferences:(id)sender;
+- (NSArray *)downloads;
+- (unsigned)countOfDownloads;
+- (id)objectInDownloadsAtIndex:(unsigned)anIndex;
+- (void)insertObject:(id)obj inDownloadsAtIndex:(unsigned)anIndex;
+- (void)removeObjectFromDownloadsAtIndex:(unsigned)anIndex;
+
@end
Modified: trunk/SKDownloadController.m
===================================================================
--- trunk/SKDownloadController.m 2008-08-23 23:05:14 UTC (rev 4444)
+++ trunk/SKDownloadController.m 2008-08-25 16:56:40 UTC (rev 4445)
@@ -48,13 +48,9 @@
static NSString *SKDownloadsWindowFrameAutosaveName = @"SKDownloadsWindow";
-static NSString *SKDownloadsWindowProgressColumnIdentifier = @"progress";
-static NSString *SKDownloadsWindowIconColumnIdentifier = @"icon";
static NSString *SKDownloadsWindowCancelColumnIdentifier = @"cancel";
static NSString *SKDownloadsWindowResumeColumnIdentifier = @"resume";
-static NSString *SKDownloadFileNameKey = @"fileName";
-
@implementation SKDownloadController
static SKDownloadController *sharedDownloadController = nil;
@@ -68,7 +64,7 @@
}
- (id)init {
- if (sharedDownloadController == nil && (sharedDownloadController = self =
[super init])) {
+ if (sharedDownloadController == nil && (sharedDownloadController = self =
[super initWithWindowNibName:@"DownloadsWindow"])) {
downloads = [[NSMutableArray alloc] init];
}
return sharedDownloadController;
@@ -87,32 +83,8 @@
- (unsigned)retainCount { return UINT_MAX; }
-- (NSString *)windowNibName { return @"DownloadsWindow"; }
-
-- (void)reloadTableView {
- NSEnumerator *downloadEnum = [downloads objectEnumerator];
- SKDownload *download;
- while (download = [downloadEnum nextObject])
- [[download progressIndicator] removeFromSuperview];
- [tableView reloadData];
-}
-
-- (void)updateButtons {
- BOOL enable = NO;
- NSEnumerator *downloadEnum = [downloads objectEnumerator];
- SKDownload *download;
- while (download = [downloadEnum nextObject]) {
- if ([download canCancel] == NO) {
- enable = YES;
- break;
- }
- }
- [clearButton setEnabled:enable];
-}
-
- (void)windowDidLoad {
[self setWindowFrameAutosaveName:SKDownloadsWindowFrameAutosaveName];
- [self updateButtons];
SKTypeSelectHelper *typeSelectHelper = [[[SKTypeSelectHelper alloc] init]
autorelease];
[typeSelectHelper setDataSource:self];
@@ -124,28 +96,60 @@
- (void)addDownloadForURL:(NSURL *)aURL {
if (aURL) {
SKDownload *download = [[[SKDownload alloc] initWithURL:aURL
delegate:self] autorelease];
- int row = [downloads count];
- [downloads addObject:download];
+ int row = [self countOfDownloads];
+ [[self mutableArrayValueForKey:@"downloads"] addObject:download];
[download startDownload];
- [self reloadTableView];
[tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:row]
byExtendingSelection:NO];
[tableView scrollRowToVisible:row];
}
}
+- (void)removeInvisibleProgressIndicators {
+ NSRect visibleRect = [tableView visibleRect];
+ int i = [self countOfDownloads];
+ while (i-- > 0) {
+ NSProgressIndicator *progressIndicator = [[self
objectInDownloadsAtIndex:i] progressIndicator];
+ if ([progressIndicator superview] && NO == NSIntersectsRect([tableView
rectOfRow:i], visibleRect))
+ [progressIndicator removeFromSuperview];
+ }
+}
+
+#pragma mark Accessors
+
+- (NSArray *)downloads {
+ return [[downloads copy] autorelease];
+}
+
+- (unsigned)countOfDownloads {
+ return [downloads count];
+}
+
+- (id)objectInDownloadsAtIndex:(unsigned)anIndex {
+ return [downloads objectAtIndex:anIndex];
+}
+
+- (void)insertObject:(id)obj inDownloadsAtIndex:(unsigned)anIndex {
+ [downloads insertObject:obj atIndex:anIndex];
+ [self removeInvisibleProgressIndicators];
+}
+
+- (void)removeObjectFromDownloadsAtIndex:(unsigned)anIndex {
+ SKDownload *download = [downloads objectAtIndex:anIndex];
+ [download setDelegate:nil];
+ [download cancelDownload];
+ [downloads removeObjectAtIndex:anIndex];
+ [self removeInvisibleProgressIndicators];
+}
+
#pragma mark Actions
- (IBAction)clearDownloads:(id)sender {
- int i = [downloads count];
+ int i = [self countOfDownloads];
- if (i) {
- while (i-- > 0) {
- SKDownload *download = [downloads objectAtIndex:i];
- if ([download status] != SKDownloadStatusDownloading)
- [downloads removeObjectAtIndex:i];
- }
- [self reloadTableView];
- [self updateButtons];
+ while (i-- > 0) {
+ SKDownload *download = [self objectInDownloadsAtIndex:i];
+ if ([download status] != SKDownloadStatusDownloading)
+ [self removeObjectFromDownloadsAtIndex:i];
}
}
@@ -155,11 +159,10 @@
if (download == nil) {
int row = [tableView clickedRow];
if (row != -1)
- download = [downloads objectAtIndex:row];
+ download = [self objectInDownloadsAtIndex:row];
}
- if (download && [download status] == SKDownloadStatusDownloading) {
+ if (download && [download status] == SKDownloadStatusDownloading)
[download cancelDownload];
- }
}
- (IBAction)resumeDownload:(id)sender {
@@ -168,13 +171,10 @@
if (download == nil) {
int row = [tableView clickedRow];
if (row != -1)
- download = [downloads objectAtIndex:row];
+ download = [self objectInDownloadsAtIndex:row];
}
- if (download && [download status] == SKDownloadStatusCanceled) {
+ if (download && [download status] == SKDownloadStatusCanceled)
[download resumeDownload];
- [tableView reloadData];
- [self updateButtons];
- }
}
- (IBAction)removeDownload:(id)sender {
@@ -183,15 +183,11 @@
if (download == nil) {
int row = [tableView clickedRow];
if (row != -1)
- download = [downloads objectAtIndex:row];
+ download = [self objectInDownloadsAtIndex:row];
}
- if (download) {
- [download cancelDownload];
- [downloads removeObject:download];
- [self reloadTableView];
- [self updateButtons];
- }
+ if (download)
+ [[self mutableArrayValueForKey:@"downloads"] removeObject:download];
}
- (IBAction)paste:(id)sender {
@@ -218,13 +214,12 @@
if (download && [download status] != SKDownloadStatusFinished) {
NSBeep();
- return;
+ } else {
+ NSURL *fileURL = [NSURL fileURLWithPath:[download filePath]];
+ NSError *error;
+ if (nil == [[NSDocumentController sharedDocumentController]
openDocumentWithContentsOfURL:fileURL display:YES error:&error])
+ [NSApp presentError:error];
}
-
- NSURL *fileURL = [NSURL fileURLWithPath:[download filePath]];
- NSError *error;
- if (nil == [[NSDocumentController sharedDocumentController]
openDocumentWithContentsOfURL:fileURL display:YES error:&error])
- [NSApp presentError:error];
}
- (void)revealDownloadedFile:(id)sender {
@@ -232,10 +227,9 @@
if (download && [download status] != SKDownloadStatusFinished) {
NSBeep();
- return;
+ } else {
+ [[NSWorkspace sharedWorkspace] selectFile:[download filePath]
inFileViewerRootedAtPath:nil];
}
-
- [[NSWorkspace sharedWorkspace] selectFile:[download filePath]
inFileViewerRootedAtPath:nil];
}
- (void)trashDownloadedFile:(id)sender {
@@ -243,27 +237,26 @@
if (download && [download status] != SKDownloadStatusFinished) {
NSBeep();
- return;
+ } else {
+ NSString *filePath = [download filePath];
+ NSString *folderPath = [filePath stringByDeletingLastPathComponent];
+ NSString *fileName = [filePath lastPathComponent];
+ int tag = 0;
+
+ [[NSWorkspace sharedWorkspace]
performFileOperation:NSWorkspaceRecycleOperation source:folderPath
destination:nil files:[NSArray arrayWithObjects:fileName, nil] tag:&tag];
}
-
- NSString *filePath = [download filePath];
- NSString *folderPath = [filePath stringByDeletingLastPathComponent];
- NSString *fileName = [filePath lastPathComponent];
- int tag = 0;
-
- [[NSWorkspace sharedWorkspace]
performFileOperation:NSWorkspaceRecycleOperation source:folderPath
destination:nil files:[NSArray arrayWithObjects:fileName, nil] tag:&tag];
}
#pragma mark SKDownloadDelegate
-- (void)downloadDidStart:(SKDownload *)download {
- [tableView reloadData];
- [self updateButtons];
+- (void)downloadDidUpdate:(SKDownload *)download {
+ unsigned int row = [downloads indexOfObject:download];
+ if (row != NSNotFound)
+ [tableView setNeedsDisplayInRect:[tableView rectOfRow:row]];
}
-- (void)downloadDidUpdate:(SKDownload *)download {
- [tableView reloadData];
- [self updateButtons];
+- (void)downloadDidStart:(SKDownload *)download {
+ [self downloadDidUpdate:download];
}
- (void)downloadDidEnd:(SKDownload *)download {
@@ -275,36 +268,25 @@
[NSApp presentError:error];
if ([[NSUserDefaults standardUserDefaults]
boolForKey:SKAutoRemoveFinishedDownloadsKey]) {
- [download cancelDownload];
- [downloads removeObject:download];
+ [[download retain] autorelease];
+ [[self mutableArrayValueForKey:@"downloads"]
removeObject:download];
// for the document to note that the file has been deleted
[document setFileURL:[NSURL fileURLWithPath:[download filePath]]];
- if ([downloads count] == 0 && [[NSUserDefaults
standardUserDefaults] boolForKey:SKAutoCloseDownloadsWindowKey])
+ if ([self countOfDownloads] == 0 && [[NSUserDefaults
standardUserDefaults] boolForKey:SKAutoCloseDownloadsWindowKey])
[[self window] close];
+ } else {
+ [self downloadDidUpdate:download];
}
+ } else {
+ [self downloadDidUpdate:download];
}
-
- [self reloadTableView];
- [self updateButtons];
}
#pragma mark NSTableViewDataSource
-- (int)numberOfRowsInTableView:(NSTableView *)tv {
- return [downloads count];
-}
+- (int)numberOfRowsInTableView:(NSTableView *)tv { return 0; }
-- (id)tableView:(NSTableView *)tv objectValueForTableColumn:(NSTableColumn
*)tableColumn row:(int)row {
- NSString *identifier = [tableColumn identifier];
- SKDownload *download = [downloads objectAtIndex:row];
-
- if ([identifier
isEqualToString:SKDownloadsWindowProgressColumnIdentifier]) {
- return [download fileName];
- } else if ([identifier
isEqualToString:SKDownloadsWindowIconColumnIdentifier]) {
- return [download fileIcon];
- }
- return nil;
-}
+- (id)tableView:(NSTableView *)tv objectValueForTableColumn:(NSTableColumn
*)tableColumn row:(int)row { return nil; }
- (NSDragOperation)tableView:(NSTableView*)tv validateDrop:(id
<NSDraggingInfo>)info proposedRow:(int)row
proposedDropOperation:(NSTableViewDropOperation)op {
NSPasteboard *pboard = [info draggingPasteboard];
@@ -335,14 +317,9 @@
- (void)tableView:(NSTableView *)tv willDisplayCell:(id)cell
forTableColumn:(NSTableColumn *)tableColumn row:(int)row {
NSString *identifier = [tableColumn identifier];
- SKDownload *download = [downloads objectAtIndex:row];
+ SKDownload *download = [self objectInDownloadsAtIndex:row];
- if ([identifier
isEqualToString:SKDownloadsWindowProgressColumnIdentifier]) {
- if ([cell respondsToSelector:@selector(setProgressIndicator:)])
- [(SKProgressCell *)cell setProgressIndicator:[download
progressIndicator]];
- if ([cell respondsToSelector:@selector(setStatus:)])
- [(SKProgressCell *)cell setStatus:[download status]];
- } else if ([identifier
isEqualToString:SKDownloadsWindowCancelColumnIdentifier]) {
+ if ([identifier isEqualToString:SKDownloadsWindowCancelColumnIdentifier]) {
if ([download canCancel]) {
[cell setImage:[NSImage imageNamed:@"Cancel"]];
[cell setAction:@selector(cancelDownload:)];
@@ -368,29 +345,27 @@
- (NSString *)tableView:(NSTableView *)aTableView toolTipForCell:(NSCell
*)cell rect:(NSRectPointer)rect tableColumn:(NSTableColumn *)tableColumn
row:(int)row mouseLocation:(NSPoint)mouseLocation {
NSString *toolTip = nil;
if ([[tableColumn identifier]
isEqualToString:SKDownloadsWindowCancelColumnIdentifier]) {
- if ([[downloads objectAtIndex:row] canCancel])
+ if ([[self objectInDownloadsAtIndex:row] canCancel])
toolTip = NSLocalizedString(@"Cancel download", @"Tool tip
message");
else
toolTip = NSLocalizedString(@"Remove download", @"Tool tip
message");
} else if ([[tableColumn identifier]
isEqualToString:SKDownloadsWindowResumeColumnIdentifier]) {
- if ([[downloads objectAtIndex:row] canResume])
+ if ([[self objectInDownloadsAtIndex:row] canResume])
toolTip = NSLocalizedString(@"Resume download", @"Tool tip
message");
+ } else {
+ toolTip = [[self objectInDownloadsAtIndex:row] filePath];
}
return toolTip;
}
- (void)tableView:(NSTableView *)aTableView deleteRowsWithIndexes:(NSIndexSet
*)rowIndexes {
unsigned int row = [rowIndexes firstIndex];
- SKDownload *download = [downloads objectAtIndex:row];
+ SKDownload *download = [self objectInDownloadsAtIndex:row];
- if ([download canCancel]) {
+ if ([download canCancel])
[download cancelDownload];
- } else {
- [download cancelDownload];
- [downloads removeObjectAtIndex:row];
- [self reloadTableView];
- [self updateButtons];
- }
+ else
+ [self removeObjectFromDownloadsAtIndex:row];
}
- (BOOL)tableView:(NSTableView *)aTableView
canDeleteRowsWithIndexes:(NSIndexSet *)rowIndexes {
@@ -400,7 +375,7 @@
- (NSMenu *)tableView:(NSTableView *)aTableView
menuForTableColumn:(NSTableColumn *)tableColumn row:(int)row {
NSMenu *menu = [[[NSMenu allocWithZone:[NSMenu menuZone]] init]
autorelease];
NSMenuItem *menuItem;
- SKDownload *download = [downloads objectAtIndex:row];
+ SKDownload *download = [self objectInDownloadsAtIndex:row];
[tableView selectRowIndexes:[NSIndexSet indexSetWithIndex:row]
byExtendingSelection:NO];
Modified: trunk/SKProgressCell.h
===================================================================
--- trunk/SKProgressCell.h 2008-08-23 23:05:14 UTC (rev 4444)
+++ trunk/SKProgressCell.h 2008-08-25 16:56:40 UTC (rev 4445)
@@ -39,15 +39,14 @@
#import <Cocoa/Cocoa.h>
[EMAIL PROTECTED] SKProgressCell : NSTextFieldCell {
- NSProgressIndicator *progressIndicator;
- int status;
-}
[EMAIL PROTECTED] SKProgressCell : NSTextFieldCell
- (NSProgressIndicator *)progressIndicator;
-- (void)setProgressIndicator:(NSProgressIndicator *)newProgressIndicator;
+- (NSString *)fileName;
+
- (int)status;
-- (void)setStatus:(int)newStatus;
+- (NSString *)statusDescription;
+
@end
Modified: trunk/SKProgressCell.m
===================================================================
--- trunk/SKProgressCell.m 2008-08-23 23:05:14 UTC (rev 4444)
+++ trunk/SKProgressCell.m 2008-08-25 16:56:40 UTC (rev 4445)
@@ -45,46 +45,52 @@
@implementation SKProgressCell
-- (void)dealloc {
- [progressIndicator release];
- [super dealloc];
+- (id)objectValueForKey:(NSString *)key {
+ id value = nil;
+ NSDictionary *info = [self objectValue];
+ if ([info respondsToSelector:@selector(objectForKey:)])
+ value = [info objectForKey:key];
+ return value;
}
-- (id)copyWithZone:(NSZone *)aZone {
- SKProgressCell *copy = [super copyWithZone:aZone];
- copy->progressIndicator = [progressIndicator retain];
- copy->status = status;
- return copy;
-}
-
- (NSProgressIndicator *)progressIndicator {
- return progressIndicator;
+ return [self objectValueForKey:SKDownloadProgressIndicatorKey];
}
-- (void)setProgressIndicator:(NSProgressIndicator *)newProgressIndicator {
- if (progressIndicator != newProgressIndicator) {
- [progressIndicator release];
- progressIndicator = [newProgressIndicator retain];
- }
+- (NSString *)fileName {
+ return [self objectValueForKey:SKDownloadFileNameKey];
}
- (int)status {
- return status;
+ return [[self objectValueForKey:SKDownloadStatusKey] intValue];
}
-- (void)setStatus:(int)newStatus {
- if (status != newStatus) {
- status = newStatus;
+- (NSString *)statusDescription {
+ switch ([self status]) {
+ case SKDownloadStatusStarting:
+ return [NSLocalizedString(@"Starting", @"Download status message")
stringByAppendingEllipsis];
+ case SKDownloadStatusDownloading:
+ return [NSLocalizedString(@"Downloading", @"Download status
message") stringByAppendingEllipsis];
+ case SKDownloadStatusFinished:
+ return NSLocalizedString(@"Finished", @"Download status message");
+ case SKDownloadStatusFailed:
+ return NSLocalizedString(@"Failed", @"Download status message");
+ case SKDownloadStatusCanceled:
+ return NSLocalizedString(@"Canceled", @"Download status message");
+ default:
+ return nil;
}
}
- (void)drawWithFrame:(NSRect)cellFrame inView:(NSView *)controlView {
- NSRect textRect = NSInsetRect(cellFrame, MARGIN_X, 0.0);
+ id value = [[[self objectValue] retain] autorelease];
+ NSProgressIndicator *progressIndicator = [self progressIndicator];
+ NSRect textRect, ignored;
- textRect.size.height = [self cellSize].height;
- if ([controlView isFlipped])
- textRect.origin.y = NSMaxY(cellFrame) - NSHeight(textRect);
+ [self setObjectValue:[self fileName]];
+ NSDivideRect(NSInsetRect(cellFrame, MARGIN_X, 0.0), &textRect, &ignored,
[self cellSize].height, [controlView isFlipped] ? NSMaxYEdge : NSMinYEdge);
[super drawWithFrame:textRect inView:controlView];
+ [self setObjectValue:value];
if (progressIndicator) {
NSRect barRect = NSInsetRect(cellFrame, MARGIN_X, 0.0);
@@ -98,53 +104,20 @@
if ([progressIndicator isDescendantOf:controlView] == NO)
[controlView addSubview:progressIndicator];
} else {
- if ([controlView isFlipped])
- textRect.origin.y = NSMinY(cellFrame);
- else
- textRect.origin.y = NSMaxY(cellFrame) - NSHeight(textRect);
- id value = [[[self objectValue] retain] autorelease];
- NSString *string = nil;
- switch (status) {
- case SKDownloadStatusStarting:
- string = [NSLocalizedString(@"Starting", @"Download status
message") stringByAppendingEllipsis];
- break;
- case SKDownloadStatusFinished:
- string = NSLocalizedString(@"Finished", @"Download status
message");
- break;
- case SKDownloadStatusFailed:
- string = NSLocalizedString(@"Failed", @"Download status
message");
- break;
- case SKDownloadStatusCanceled:
- string = NSLocalizedString(@"Canceled", @"Download status
message");
- break;
- }
- [self setObjectValue:string];
+ [self setObjectValue:[self statusDescription]];
+ NSDivideRect(NSInsetRect(cellFrame, MARGIN_X, 0.0), &textRect,
&ignored, [self cellSize].height, [controlView isFlipped] ? NSMinYEdge :
NSMaxYEdge);
[super drawWithFrame:textRect inView:controlView];
[self setObjectValue:value];
}
}
- (id)accessibilityAttributeValue:(NSString *)attribute {
- if ([attribute isEqualToString:NSAccessibilityValueAttribute] &&
progressIndicator == nil) {
- NSString *string = nil;
- switch (status) {
- case SKDownloadStatusStarting:
- string = [NSLocalizedString(@"Starting", @"Download status
message") stringByAppendingEllipsis];
- break;
- case SKDownloadStatusFinished:
- string = NSLocalizedString(@"Finished", @"Download status
message");
- break;
- case SKDownloadStatusFailed:
- string = NSLocalizedString(@"Failed", @"Download status
message");
- break;
- case SKDownloadStatusCanceled:
- string = NSLocalizedString(@"Canceled", @"Download status
message");
- break;
- }
- return [[super accessibilityAttributeValue:attribute]
stringByAppendingFormat:@"\n%@", string];
- } else {
- return [super accessibilityAttributeValue:attribute];
+ if ([attribute isEqualToString:NSAccessibilityValueAttribute]) {
+ NSString *statusDescription = [self statusDescription];
+ if (statusDescription)
+ return [[super accessibilityAttributeValue:attribute]
stringByAppendingFormat:@"\n%@", statusDescription];
}
+ return [super accessibilityAttributeValue:attribute];
}
@end
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit