From d9cdfc85871a1ea8b9c16c4756d804199c80d2ce Mon Sep 17 00:00:00 2001 From: "mark%moxienet.com" Date: Mon, 6 Feb 2006 21:26:26 +0000 Subject: [PATCH] 230320 Add Move to Trash command and Delete button to Downloads window. Patch by Bruce Davidson . Icon by Jasper Hauser . Thanks also to Nick Kreeger and Ludovic Hirlimann . Project file kicked by the usual suspect. r=kreeger sr=pink --- camino/Camino.xcode/project.pbxproj | 23 ++++++ camino/resources/images/toolbar/dl_trash.tif | 0 .../English.lproj/Localizable.strings | Bin 32382 -> 32654 bytes camino/src/download/ProgressDlgController.mm | 74 ++++++++++++++++-- camino/src/download/ProgressViewController.h | 6 +- camino/src/download/ProgressViewController.mm | 22 +++++- 6 files changed, 115 insertions(+), 10 deletions(-) create mode 100644 camino/resources/images/toolbar/dl_trash.tif diff --git a/camino/Camino.xcode/project.pbxproj b/camino/Camino.xcode/project.pbxproj index 48b94906e9b..c95fd93ff9c 100644 --- a/camino/Camino.xcode/project.pbxproj +++ b/camino/Camino.xcode/project.pbxproj @@ -3589,6 +3589,20 @@ settings = { }; }; + 34D112DD08E9B17400989FD5 = { + isa = PBXFileReference; + lastKnownFileType = image.tiff; + name = dl_trash.tif; + path = resources/images/toolbar/dl_trash.tif; + refType = 2; + sourceTree = SOURCE_ROOT; + }; + 34D112DE08E9B17400989FD5 = { + fileRef = 34D112DD08E9B17400989FD5; + isa = PBXBuildFile; + settings = { + }; + }; //340 //341 //342 @@ -4689,6 +4703,7 @@ 0FBB8CC808D260D800D58D8D, 0FBB8CC908D260D800D58D8D, 0FBB8CCA08D260D800D58D8D, + 34D112DE08E9B17400989FD5, 0F01117408F2FE7C00423C02, 0FEA7E650926BFC600B06154, 0F8FC52F092ED71C0042429E, @@ -8623,6 +8638,7 @@ 0F01117508F2FE7C00423C02, 0FEA7E660926BFC600B06154, 0F8FC52E092ED71C0042429E, + 4DD988E708EB7D3700AD0788, ); isa = PBXResourcesBuildPhase; runOnlyForDeploymentPostprocessing = 0; @@ -13083,6 +13099,12 @@ settings = { }; }; + 4DD988E708EB7D3700AD0788 = { + fileRef = 34D112DD08E9B17400989FD5; + isa = PBXBuildFile; + settings = { + }; + }; //790 //791 //792 @@ -15257,6 +15279,7 @@ }; F5264FCB020D4C25010001CA = { children = ( + 34D112DD08E9B17400989FD5, 3FC0FB8305A0D2F4002F47DE, 3FC0FB8405A0D2F4002F47DE, 3FC0FB8505A0D2F4002F47DE, diff --git a/camino/resources/images/toolbar/dl_trash.tif b/camino/resources/images/toolbar/dl_trash.tif new file mode 100644 index 00000000000..e69de29bb2d diff --git a/camino/resources/localized/English.lproj/Localizable.strings b/camino/resources/localized/English.lproj/Localizable.strings index 89e92ae1b027c1f41c7a240ff0513faeb708d997..8e1239505450f6d5dafc28081749acd6f4ac01b0 100644 GIT binary patch delta 190 zcmezOhq3QJ4F%)aQ3IPD_Ixd+2 delta 23 fcmeDC&-m{Tb%@ * Josh Aas * Nick Kreeger + * Bruce Davidson * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -55,6 +56,7 @@ static NSString* const kProgressWindowFrameSaveName = @"ProgressWindow"; -(void)showErrorSheetForDownload:(id )progressDisplay withStatus:(nsresult)inStatus; -(void)rebuildViews; -(NSArray*)selectedProgressViewControllers; +-(ProgressViewController*)progressViewControllerAtIndex:(unsigned)inIndex; -(void)deselectDLInstancesInArray:(NSArray*)instances; -(void)scrollIntoView:(ProgressViewController*)controller; -(void)killDownloadTimer; @@ -167,32 +169,44 @@ static id gSharedProgressController = nil; [[self selectedProgressViewControllers] makeObjectsPerformSelector:@selector(open:) withObject:sender]; } -// remove all selected instances, don't remove anything that is active as a guard against bad things --(IBAction)remove:(id)sender +// +// Take care of selecting a download instance to replace the selection being removed +// +-(void)setSelectionForRemovalOfItems:(NSArray*) selectionToRemove { // take care of selecting a download instance to replace the selection being removed NSArray* selected = [self selectedProgressViewControllers]; unsigned int selectedCount = [selected count]; if (selectedCount == 0) return; - + unsigned int indexOfLastSelection = [mProgressViewControllers indexOfObject:[selected lastObject]]; // if dl instance after last selection exists, select it or look for something else to select if ((indexOfLastSelection + 1) < [mProgressViewControllers count]) { [(ProgressViewController*)[mProgressViewControllers objectAtIndex:(indexOfLastSelection + 1)] setSelected:YES]; } else { // find the first unselected DL instance before the last one marked for removal and select it - // use an int in the loop, not unsigned because we might make it negative + // use an int in the loop, not unsigned because we might make it negative for (int i = ([mProgressViewControllers count] - 1); i >= 0; i--) { ProgressViewController* curProgressViewController = [mProgressViewControllers objectAtIndex:i]; if (![curProgressViewController isSelected]) { - [curProgressViewController setSelected:YES]; - break; + [curProgressViewController setSelected:YES]; + break; } } } + mSelectionPivotIndex = -1; // nothing is selected any more so nothing to pivot on +} + +// remove all selected instances, don't remove anything that is active as a guard against bad things +-(IBAction)remove:(id)sender +{ + NSArray* selected = [self selectedProgressViewControllers]; + unsigned int selectedCount = [selected count]; + + [self setSelectionForRemovalOfItems:selected]; // now remove stuff for (unsigned int i = 0; i < selectedCount; i++) @@ -206,6 +220,24 @@ static id gSharedProgressController = nil; [self saveProgressViewControllers]; } +// delete the selected download(s), moving files to trash and clearing them from the list +-(IBAction)deleteDownloads:(id)sender +{ + NSArray* selected = [self selectedProgressViewControllers]; + unsigned int selectedCount = [selected count]; + + [self setSelectionForRemovalOfItems:selected]; + + // now remove stuff, don't need to check if active, the toolbar/menu validates + for (unsigned int i = 0; i < selectedCount; i++) { + [[selected objectAtIndex:i] deleteFile:sender]; + [self removeDownload:[selected objectAtIndex:i]]; + } + + [self rebuildViews]; + [self saveProgressViewControllers]; +} + -(IBAction)pause:(id)sender { [[self selectedProgressViewControllers] makeObjectsPerformSelector:@selector(pause:) withObject:sender]; @@ -465,6 +497,11 @@ static id gSharedProgressController = nil; return selectedArray; } +-(ProgressViewController*)progressViewControllerAtIndex:(unsigned)inIndex +{ + return (ProgressViewController*) [mProgressViewControllers objectAtIndex:inIndex]; +} + -(void)scrollIntoView:(ProgressViewController*)controller { NSView* dlView = [controller view]; @@ -784,6 +821,19 @@ static id gSharedProgressController = nil; return [[self window] isKeyWindow]; } +-(BOOL)shouldAllowMoveToTrashAction +{ + NSEnumerator* progViewEnum = [[self selectedProgressViewControllers] objectEnumerator]; + ProgressViewController* curController; + while ((curController = [progViewEnum nextObject])) + { + if ([curController isActive] || ![curController fileExists]) { + return NO; + } + } + return YES; +} + -(BOOL)fileExistsForSelectedItems { NSEnumerator* progViewEnum = [[self selectedProgressViewControllers] objectEnumerator]; @@ -857,6 +907,9 @@ static id gSharedProgressController = nil; else if (action == @selector(resume:)) { return [self shouldAllowResumeAction]; } + else if (action == @selector(deleteDownloads:)) { + return [self shouldAllowMoveToTrashAction]; + } return YES; } @@ -974,6 +1027,13 @@ static id gSharedProgressController = nil; [theItem setAction:@selector(cleanUpDownloads:)]; [theItem setImage:[NSImage imageNamed:@"dl_clearall.tif"]]; } + else if ([itemIdentifier isEqualToString:@"movetotrashbutton"]) { + [theItem setToolTip:NSLocalizedString(@"dlTrashButtonTooltip", nil)]; + [theItem setLabel:NSLocalizedString(@"dlTrashButtonLabel", nil)]; + [theItem setPaletteLabel:NSLocalizedString(@"dlTrashButtonLabel", nil)]; + [theItem setAction:@selector(deleteDownloads:)]; + [theItem setImage:[NSImage imageNamed:@"dl_trash.tif"]]; + } else if ([itemIdentifier isEqualToString:@"pauseresumebutton"]) { [self setPauseResumeToolbarItem:theItem]; } @@ -985,7 +1045,7 @@ static id gSharedProgressController = nil; -(NSArray *)toolbarAllowedItemIdentifiers:(NSToolbar *)toolbar { - return [NSArray arrayWithObjects:@"cleanupbutton", @"removebutton", @"cancelbutton", @"pauseresumebutton", @"openbutton", @"revealbutton", NSToolbarFlexibleSpaceItemIdentifier, nil]; + return [NSArray arrayWithObjects:@"cleanupbutton", @"removebutton", @"cancelbutton", @"pauseresumebutton", @"openbutton", @"revealbutton", @"movetotrashbutton", NSToolbarFlexibleSpaceItemIdentifier, nil]; } -(NSArray *)toolbarDefaultItemIdentifiers:(NSToolbar *)toolbar diff --git a/camino/src/download/ProgressViewController.h b/camino/src/download/ProgressViewController.h index d7a7058224b..b9452aebacc 100644 --- a/camino/src/download/ProgressViewController.h +++ b/camino/src/download/ProgressViewController.h @@ -24,6 +24,7 @@ * Simon Fraser * Josh Aas * Nick Kreeger + * Bruce Davidson * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -106,18 +107,19 @@ enum { -(IBAction)remove:(id)sender; -(IBAction)reveal:(id)sender; -(IBAction)open:(id)sender; +-(IBAction)deleteFile:(id)sender; -(IBAction)pause:(id)sender; -(IBAction)resume:(id)sender; -(BOOL)isActive; -(BOOL)isCanceled; +-(BOOL)isSelected; -(BOOL)isPaused; -(BOOL)fileExists; --(BOOL)isSelected; --(void)setSelected:(BOOL)inSelected; -(void)checkFileExists; +-(void)setSelected:(BOOL)inSelected; -(NSDictionary*)downloadInfoDictionary; diff --git a/camino/src/download/ProgressViewController.mm b/camino/src/download/ProgressViewController.mm index 19f4ae3ed53..f4b50024474 100644 --- a/camino/src/download/ProgressViewController.mm +++ b/camino/src/download/ProgressViewController.mm @@ -24,6 +24,7 @@ * Simon Fraser * Josh Aas * Nick Kreeger + * Bruce Davidson * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or @@ -351,6 +352,19 @@ static void FileSystemNotificationProc(FNMessage message, OptionBits flags, void [self refreshDownloadInfo]; } +// Delete the file we downloaded and remove this item from the list +-(IBAction)deleteFile:(id)sender +{ + NSString* fileName = [mDestPath lastPathComponent]; + NSString* path = [mDestPath stringByDeletingLastPathComponent]; + + [[NSWorkspace sharedWorkspace] performFileOperation:NSWorkspaceRecycleOperation + source:path + destination:@"" + files:[NSArray arrayWithObject:fileName] + tag:nil]; +} + -(void)downloadDidEnd { if (!mDownloadDone) { // some error conditions can cause this to get called twice @@ -570,6 +584,7 @@ static void FileSystemNotificationProc(FNMessage message, OptionBits flags, void NSMenuItem *removeItem; NSMenuItem *pauseResumeItem; // alternates pause and resume NSMenuItem *openItem; + NSMenuItem *deleteItem; NSMenuItem *copySourceURLItem; revealItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"dlRevealCMLabel", nil) @@ -588,6 +603,8 @@ static void FileSystemNotificationProc(FNMessage message, OptionBits flags, void action:@selector(remove:) keyEquivalent:@""]; openItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"dlOpenCMLabel", nil) action:@selector(open:) keyEquivalent:@""]; + deleteItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"dlTrashCMLabel", nil) + action:@selector(deleteDownloads:) keyEquivalent:@""]; copySourceURLItem = [[NSMenuItem alloc] initWithTitle:NSLocalizedString(@"dlCopySourceURLCMLabel", nil) action:@selector(copySourceURL:) keyEquivalent:@""]; [revealItem setTarget:mProgressWindowController]; @@ -595,6 +612,7 @@ static void FileSystemNotificationProc(FNMessage message, OptionBits flags, void [pauseResumeItem setTarget:mProgressWindowController]; [removeItem setTarget:mProgressWindowController]; [openItem setTarget:mProgressWindowController]; + [deleteItem setTarget:mProgressWindowController]; [copySourceURLItem setTarget:self]; [menu addItem:revealItem]; @@ -602,6 +620,7 @@ static void FileSystemNotificationProc(FNMessage message, OptionBits flags, void [menu addItem:pauseResumeItem]; [menu addItem:removeItem]; [menu addItem:openItem]; + [menu addItem:deleteItem]; [menu addItem:[NSMenuItem separatorItem]]; [menu addItem:copySourceURLItem]; @@ -610,6 +629,7 @@ static void FileSystemNotificationProc(FNMessage message, OptionBits flags, void [pauseResumeItem release]; [removeItem release]; [openItem release]; + [deleteItem release]; [copySourceURLItem release]; return [menu autorelease]; @@ -621,7 +641,7 @@ static void FileSystemNotificationProc(FNMessage message, OptionBits flags, void if (action == @selector(cancel:)) { return ((!mUserCancelled) && (!mDownloadDone)); } - if (action == @selector(remove:)) { + if (action == @selector(remove:) || action == @selector(deleteDownloads:)) { return (mUserCancelled || mDownloadDone); } return YES;