Revision: 7128
          http://skim-app.svn.sourceforge.net/skim-app/?rev=7128&view=rev
Author:   hofman
Date:     2011-02-25 12:24:30 +0000 (Fri, 25 Feb 2011)

Log Message:
-----------
Implement moveToTrash action in download controller

Modified Paths:
--------------
    trunk/SKDownloadController.h
    trunk/SKDownloadController.m

Modified: trunk/SKDownloadController.h
===================================================================
--- trunk/SKDownloadController.h        2011-02-25 11:55:06 UTC (rev 7127)
+++ trunk/SKDownloadController.h        2011-02-25 12:24:30 UTC (rev 7128)
@@ -64,11 +64,10 @@
 
 - (SKDownload *)addDownloadForURL:(NSURL *)aURL;
 
+- (IBAction)showDownloadPreferences:(id)sender;
 - (IBAction)clearDownloads:(id)sender;
-- (IBAction)removeDownload:(id)sender;
-- (IBAction)cancelDownload:(id)sender;
 
-- (IBAction)showDownloadPreferences:(id)sender;
+- (IBAction)moveToTrash:(id)sender;
 
 - (NSArray *)downloads;
 - (NSUInteger)countOfDownloads;

Modified: trunk/SKDownloadController.m
===================================================================
--- trunk/SKDownloadController.m        2011-02-25 11:55:06 UTC (rev 7127)
+++ trunk/SKDownloadController.m        2011-02-25 12:24:30 UTC (rev 7128)
@@ -212,6 +212,11 @@
 
 #pragma mark Actions
 
+- (IBAction)showDownloadPreferences:(id)sender {
+    SKDownloadPreferenceController *prefController = 
[[[SKDownloadPreferenceController alloc] init] autorelease];
+    [prefController beginSheetModalForWindow:[self window]];
+}
+
 - (IBAction)clearDownloads:(id)sender {
     NSInteger i = [self countOfDownloads];
     
@@ -222,7 +227,24 @@
     }
 }
 
-- (IBAction)cancelDownload:(id)sender {
+- (IBAction)moveToTrash:(id)sender {
+    SKDownload *download = nil;
+    NSInteger row = [tableView selectedRow];
+    if (row != -1)
+        download = [self objectInDownloadsAtIndex:row];
+    if (download && [download status] == SKDownloadStatusFinished) {
+        NSString *filePath = [download filePath];
+        NSString *folderPath = [filePath stringByDeletingLastPathComponent];
+        NSString *fileName = [filePath lastPathComponent];
+        NSInteger tag = 0;
+        
+        [[NSWorkspace sharedWorkspace] 
performFileOperation:NSWorkspaceRecycleOperation source:folderPath 
destination:nil files:[NSArray arrayWithObjects:fileName, nil] tag:&tag];
+    } else {
+        NSBeep();
+    }
+}
+
+- (void)cancelDownload:(id)sender {
     SKDownload *download = [sender 
respondsToSelector:@selector(representedObject)] ? [sender representedObject] : 
nil;
     
     if (download == nil) {
@@ -234,7 +256,7 @@
         [download cancel];
 }
 
-- (IBAction)resumeDownload:(id)sender {
+- (void)resumeDownload:(id)sender {
     SKDownload *download = [sender 
respondsToSelector:@selector(representedObject)] ? [sender representedObject] : 
nil;
     
     if (download == nil) {
@@ -246,7 +268,7 @@
         [download resume];
 }
 
-- (IBAction)removeDownload:(id)sender {
+- (void)removeDownload:(id)sender {
     SKDownload *download = [sender 
respondsToSelector:@selector(representedObject)] ? [sender representedObject] : 
nil;
     
     if (download == nil) {
@@ -259,11 +281,6 @@
         [[self mutableArrayValueForKey:DOWNLOADS_KEY] removeObject:download];
 }
 
-- (IBAction)showDownloadPreferences:(id)sender {
-    SKDownloadPreferenceController *prefController = 
[[[SKDownloadPreferenceController alloc] init] autorelease];
-    [prefController beginSheetModalForWindow:[self window]];
-}
-
 - (void)openDownloadedFile:(id)sender {
     SKDownload *download = [sender representedObject];
     
@@ -302,6 +319,16 @@
     }
 }
 
+#pragma mark Menu validation
+
+- (BOOL)validateMenuItem:(NSMenuItem *)menuItem {
+    if ([menuItem action] == @selector(moveToTrash:)) {
+        NSInteger row = [tableView selectedRow];
+        return (row != -1 && [[self objectInDownloadsAtIndex:row] status] == 
SKDownloadStatusFinished);
+    }
+    return YES;
+}
+
 #pragma mark SKDownloadDelegate
 
 - (void)downloadDidEnd:(SKDownload *)download {


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in 
Real-Time with Splunk. Collect, index and harness all the fast moving IT data 
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business 
insights. http://p.sf.net/sfu/splunk-dev2dev 
_______________________________________________
Skim-app-commit mailing list
Skim-app-commit@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/skim-app-commit

Reply via email to