Ignore:
Timestamp:
Nov 30, 2008, 7:23:15 PM (12 years ago)
Author:
livings124
Message:

patch from ciaran for #757 to add separate download locations for each group (when added)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/GroupsWindowController.m

    r7193 r7210  
    2626#import "GroupsController.h"
    2727#import "NSApplicationAdditions.h"
     28#import "ExpandedPathToPathTransformer.h"
     29#import "ExpandedPathToIconTransformer.h"
    2830
    2931#define GROUP_TABLE_VIEW_DATA_TYPE @"GroupTableViewDataType"
     
    176178}
    177179
     180- (void) customDownloadLocationSheetShow: (id) sender
     181{
     182    NSOpenPanel * panel = [NSOpenPanel openPanel];
     183
     184    [panel setPrompt: NSLocalizedString(@"Select", "Preferences -> Open panel prompt")];
     185    [panel setAllowsMultipleSelection: NO];
     186    [panel setCanChooseFiles: NO];
     187    [panel setCanChooseDirectories: YES];
     188    [panel setCanCreateDirectories: YES];
     189
     190    [panel beginSheetForDirectory: nil file: nil types: nil
     191        modalForWindow: [fCustomLocationPopUp window] modalDelegate: self didEndSelector:
     192        @selector(customDownloadLocationSheetClosed:returnCode:contextInfo:) contextInfo: nil];
     193}
     194
     195- (IBAction) toggleUseCustomDownloadLocation: (id) sender
     196{
     197    NSInteger index = [[GroupsController groups] indexForRow: [fTableView selectedRow]];
     198    if ([fCustomLocationEnableCheck state] == NSOnState)
     199    {
     200        if ([[GroupsController groups] customDownloadLocationForIndex: index])
     201            [[GroupsController groups] setUsesCustomDownloadLocation: YES forIndex: index];
     202        else
     203            [self customDownloadLocationSheetShow: nil];
     204    }
     205    else
     206        [[GroupsController groups] setUsesCustomDownloadLocation: NO forIndex: index];
     207
     208    [fCustomLocationPopUp setEnabled: ([fCustomLocationEnableCheck state] == NSOnState)];
     209}
     210
     211- (void) customDownloadLocationSheetClosed: (NSOpenPanel *) openPanel returnCode: (int) code contextInfo: (void *) info
     212{
     213    NSInteger index = [[GroupsController groups] indexForRow: [fTableView selectedRow]];
     214    NSString * path = [[GroupsController groups] customDownloadLocationForIndex: index];
     215    if (code == NSOKButton)
     216    {
     217        path = [[openPanel filenames] objectAtIndex: 0];
     218        [[GroupsController groups] setCustomDownloadLocation: path forIndex: index];
     219        [[GroupsController groups] setUsesCustomDownloadLocation: YES forIndex: index];
     220        [self updateSelectedColor]; // Update the popup's icon/title
     221    }
     222    else if (!path)
     223    {
     224        [[GroupsController groups] setUsesCustomDownloadLocation: NO forIndex: index];
     225        [fCustomLocationEnableCheck setState: NSOffState];
     226    }
     227
     228    [fCustomLocationPopUp selectItemAtIndex: 0];
     229}
     230
    178231@end
    179232
     
    190243        [fSelectedColorNameField setStringValue: [[GroupsController groups] nameForIndex: index]];
    191244        [fSelectedColorNameField setEnabled: YES];
     245        [fCustomLocationEnableCheck setState: [[GroupsController groups] usesCustomDownloadLocationForIndex: index]];
     246        [fCustomLocationPopUp setEnabled: ([fCustomLocationEnableCheck state] == NSOnState)];
     247        if ([[GroupsController groups] customDownloadLocationForIndex: index])
     248        {
     249            NSString * location = [[GroupsController groups] customDownloadLocationForIndex: index];
     250            ExpandedPathToPathTransformer * pathTransformer = [[[ExpandedPathToPathTransformer alloc] init] autorelease];
     251            [[fCustomLocationPopUp itemAtIndex: 0] setTitle: [pathTransformer transformedValue: location]];
     252            ExpandedPathToIconTransformer * iconTransformer = [[[ExpandedPathToIconTransformer alloc] init] autorelease];
     253            [[fCustomLocationPopUp itemAtIndex: 0] setImage: [iconTransformer transformedValue: location]];
     254        }
     255        else
     256        {
     257            [[fCustomLocationPopUp itemAtIndex: 0] setTitle: @""];
     258            [[fCustomLocationPopUp itemAtIndex: 0] setImage: nil];
     259        }
    192260    }
    193261    else
     
    197265        [fSelectedColorNameField setStringValue: @""];
    198266        [fSelectedColorNameField setEnabled: NO];
     267        [fCustomLocationEnableCheck setEnabled: NO];
     268        [fCustomLocationPopUp setEnabled: NO];
    199269    }
    200270}
Note: See TracChangeset for help on using the changeset viewer.