2007-12-17 16:06:20 +00:00
|
|
|
/******************************************************************************
|
2012-01-14 17:12:04 +00:00
|
|
|
* Copyright (c) 2007-2012 Transmission authors and contributors
|
2007-12-17 16:06:20 +00:00
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
|
|
|
|
* DEALINGS IN THE SOFTWARE.
|
|
|
|
*****************************************************************************/
|
|
|
|
|
2008-12-01 01:44:38 +00:00
|
|
|
#import "GroupsPrefsController.h"
|
2008-03-23 00:56:43 +00:00
|
|
|
#import "GroupsController.h"
|
2008-11-30 19:23:15 +00:00
|
|
|
#import "ExpandedPathToPathTransformer.h"
|
|
|
|
#import "ExpandedPathToIconTransformer.h"
|
2012-01-02 19:05:21 +00:00
|
|
|
#import "NSApplicationAdditions.h"
|
2007-12-17 16:06:20 +00:00
|
|
|
|
2007-12-17 21:11:53 +00:00
|
|
|
#define GROUP_TABLE_VIEW_DATA_TYPE @"GroupTableViewDataType"
|
|
|
|
|
2008-06-02 17:26:02 +00:00
|
|
|
#define ADD_TAG 0
|
|
|
|
#define REMOVE_TAG 1
|
2007-12-17 16:06:20 +00:00
|
|
|
|
2017-02-05 15:41:47 +00:00
|
|
|
@interface GroupsPrefsController ()
|
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
@property (nonatomic) IBOutlet NSWindow * groupRulesSheetWindow;
|
2017-07-29 16:14:22 +00:00
|
|
|
@property (nonatomic, weak) IBOutlet NSPredicateEditor * ruleEditor;
|
|
|
|
@property (nonatomic, weak) IBOutlet NSLayoutConstraint * ruleEditorHeightConstraint;
|
2017-02-05 15:41:47 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
2008-12-01 01:44:38 +00:00
|
|
|
@interface GroupsPrefsController (Private)
|
2007-12-17 16:06:20 +00:00
|
|
|
|
2008-12-08 03:55:08 +00:00
|
|
|
- (void) updateSelectedGroup;
|
2009-12-19 19:17:09 +00:00
|
|
|
- (void) refreshCustomLocationWithSingleGroup;
|
2007-12-17 16:06:20 +00:00
|
|
|
|
|
|
|
@end
|
|
|
|
|
2008-12-01 01:44:38 +00:00
|
|
|
@implementation GroupsPrefsController
|
2007-12-17 16:06:20 +00:00
|
|
|
|
2017-02-05 15:41:47 +00:00
|
|
|
@synthesize groupRulesSheetWindow;
|
|
|
|
@synthesize ruleEditor;
|
|
|
|
@synthesize ruleEditorHeightConstraint;
|
|
|
|
|
2007-12-17 16:06:20 +00:00
|
|
|
- (void) awakeFromNib
|
|
|
|
{
|
2017-07-08 08:23:05 +00:00
|
|
|
[fTableView registerForDraggedTypes: @[GROUP_TABLE_VIEW_DATA_TYPE]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-11-29 20:03:18 +00:00
|
|
|
[fSelectedColorView addObserver: self forKeyPath: @"color" options: 0 context: NULL];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-12-08 03:55:08 +00:00
|
|
|
[self updateSelectedGroup];
|
2007-12-17 16:06:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (NSInteger) numberOfRowsInTableView: (NSTableView *) tableview
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
return GroupsController.groups.numberOfGroups;
|
2007-12-17 16:06:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (id) tableView: (NSTableView *) tableView objectValueForTableColumn: (NSTableColumn *) tableColumn row: (NSInteger) row
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
GroupsController * groupsController = GroupsController.groups;
|
2008-11-04 00:34:13 +00:00
|
|
|
NSInteger groupsIndex = [groupsController indexForRow: row];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
NSString * identifier = tableColumn.identifier;
|
2007-12-17 16:06:20 +00:00
|
|
|
if ([identifier isEqualToString: @"Color"])
|
2008-05-31 02:38:44 +00:00
|
|
|
return [groupsController imageForIndex: groupsIndex];
|
2007-12-17 16:06:20 +00:00
|
|
|
else
|
2008-03-24 23:06:04 +00:00
|
|
|
return [groupsController nameForIndex: groupsIndex];
|
2007-12-17 16:06:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) tableViewSelectionDidChange: (NSNotification *) notification
|
2008-11-29 20:03:18 +00:00
|
|
|
{
|
2008-12-08 03:55:08 +00:00
|
|
|
[self updateSelectedGroup];
|
2008-11-29 20:03:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) observeValueForKeyPath: (NSString *) keyPath ofObject: (id) object change: (NSDictionary *) change context: (void *) context
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (object == fSelectedColorView && fTableView.numberOfSelectedRows == 1)
|
2008-11-29 20:03:18 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
NSInteger index = [GroupsController.groups indexForRow: fTableView.selectedRow];
|
|
|
|
[GroupsController.groups setColor: fSelectedColorView.color forIndex: index];
|
|
|
|
fTableView.needsDisplay = YES;
|
2008-11-29 20:03:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
- (void) controlTextDidEndEditing: (NSNotification *) notification
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (notification.object == fSelectedColorNameField)
|
2008-11-29 20:03:18 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
NSInteger index = [GroupsController.groups indexForRow: fTableView.selectedRow];
|
|
|
|
[GroupsController.groups setName: fSelectedColorNameField.stringValue forIndex: index];
|
|
|
|
fTableView.needsDisplay = YES;
|
2008-11-29 20:03:18 +00:00
|
|
|
}
|
2007-12-17 16:06:20 +00:00
|
|
|
}
|
|
|
|
|
2007-12-17 21:11:53 +00:00
|
|
|
- (BOOL) tableView: (NSTableView *) tableView writeRowsWithIndexes: (NSIndexSet *) rowIndexes toPasteboard: (NSPasteboard *) pboard
|
|
|
|
{
|
2017-07-08 08:23:05 +00:00
|
|
|
[pboard declareTypes: @[GROUP_TABLE_VIEW_DATA_TYPE] owner: self];
|
2007-12-17 21:11:53 +00:00
|
|
|
[pboard setData: [NSKeyedArchiver archivedDataWithRootObject: rowIndexes] forType: GROUP_TABLE_VIEW_DATA_TYPE];
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSDragOperation) tableView: (NSTableView *) tableView validateDrop: (id <NSDraggingInfo>) info
|
2008-11-04 00:34:13 +00:00
|
|
|
proposedRow: (NSInteger) row proposedDropOperation: (NSTableViewDropOperation) operation
|
2007-12-17 21:11:53 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
NSPasteboard * pasteboard = info.draggingPasteboard;
|
|
|
|
if ([pasteboard.types containsObject: GROUP_TABLE_VIEW_DATA_TYPE])
|
2007-12-17 21:11:53 +00:00
|
|
|
{
|
|
|
|
[fTableView setDropRow: row dropOperation: NSTableViewDropAbove];
|
|
|
|
return NSDragOperationGeneric;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-12-17 21:11:53 +00:00
|
|
|
return NSDragOperationNone;
|
|
|
|
}
|
|
|
|
|
2008-11-04 00:34:13 +00:00
|
|
|
- (BOOL) tableView: (NSTableView *) tableView acceptDrop: (id <NSDraggingInfo>) info row: (NSInteger) newRow
|
2008-03-23 00:56:43 +00:00
|
|
|
dropOperation: (NSTableViewDropOperation) operation
|
2007-12-17 21:11:53 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
NSPasteboard * pasteboard = info.draggingPasteboard;
|
|
|
|
if ([pasteboard.types containsObject: GROUP_TABLE_VIEW_DATA_TYPE])
|
2007-12-17 21:11:53 +00:00
|
|
|
{
|
2008-12-06 20:41:18 +00:00
|
|
|
NSIndexSet * indexes = [NSKeyedUnarchiver unarchiveObjectWithData: [pasteboard dataForType: GROUP_TABLE_VIEW_DATA_TYPE]];
|
2021-08-07 07:27:56 +00:00
|
|
|
NSInteger oldRow = indexes.firstIndex;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2012-01-04 00:06:30 +00:00
|
|
|
if (oldRow < newRow)
|
|
|
|
newRow--;
|
2016-01-06 11:05:37 +00:00
|
|
|
|
|
|
|
[fTableView beginUpdates];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
[GroupsController.groups moveGroupAtRow: oldRow toRow: newRow];
|
2016-01-06 11:05:37 +00:00
|
|
|
|
|
|
|
[fTableView moveRowAtIndex: oldRow toIndex: newRow];
|
|
|
|
[fTableView endUpdates];
|
2007-12-17 21:11:53 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-12-17 21:11:53 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2007-12-17 16:06:20 +00:00
|
|
|
- (void) addRemoveGroup: (id) sender
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (NSColorPanel.sharedColorPanelExists)
|
|
|
|
[NSColorPanel.sharedColorPanel close];
|
2008-11-29 21:46:34 +00:00
|
|
|
|
2008-11-29 21:03:47 +00:00
|
|
|
NSInteger row;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-12-17 16:06:20 +00:00
|
|
|
switch ([[sender cell] tagForSegment: [sender selectedSegment]])
|
|
|
|
{
|
|
|
|
case ADD_TAG:
|
2016-01-06 11:05:37 +00:00
|
|
|
[fTableView beginUpdates];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
[GroupsController.groups addNewGroup];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
row = fTableView.numberOfRows;
|
2016-01-06 11:05:37 +00:00
|
|
|
|
|
|
|
[fTableView insertRowsAtIndexes: [NSIndexSet indexSetWithIndex: row] withAnimation: NSTableViewAnimationSlideUp];
|
|
|
|
[fTableView endUpdates];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-08-28 23:40:11 +00:00
|
|
|
[fTableView selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection: NO];
|
2008-11-29 21:03:47 +00:00
|
|
|
[fTableView scrollRowToVisible: row];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
[fSelectedColorNameField.window makeFirstResponder: fSelectedColorNameField];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-12-17 16:06:20 +00:00
|
|
|
break;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-12-17 16:06:20 +00:00
|
|
|
case REMOVE_TAG:
|
2021-08-07 07:27:56 +00:00
|
|
|
row = fTableView.selectedRow;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2016-01-06 11:05:37 +00:00
|
|
|
|
|
|
|
[fTableView beginUpdates];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
[GroupsController.groups removeGroupWithRowIndex: row];
|
2016-01-06 11:05:37 +00:00
|
|
|
|
|
|
|
[fTableView removeRowsAtIndexes: [NSIndexSet indexSetWithIndex: row] withAnimation: NSTableViewAnimationSlideUp];
|
|
|
|
[fTableView endUpdates];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
if (fTableView.numberOfRows > 0)
|
2010-04-10 15:48:09 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (row == fTableView.numberOfRows)
|
2010-04-10 15:48:09 +00:00
|
|
|
--row;
|
2012-01-02 19:05:21 +00:00
|
|
|
[fTableView selectRowIndexes: [NSIndexSet indexSetWithIndex: row] byExtendingSelection: NO];
|
2012-01-03 01:53:53 +00:00
|
|
|
[fTableView scrollRowToVisible: row];
|
2010-04-10 15:48:09 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-12-17 16:06:20 +00:00
|
|
|
break;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2008-12-08 03:55:08 +00:00
|
|
|
[self updateSelectedGroup];
|
2007-12-17 16:06:20 +00:00
|
|
|
}
|
|
|
|
|
2008-11-30 19:23:15 +00:00
|
|
|
- (void) customDownloadLocationSheetShow: (id) sender
|
|
|
|
{
|
|
|
|
NSOpenPanel * panel = [NSOpenPanel openPanel];
|
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
panel.prompt = NSLocalizedString(@"Select", "Preferences -> Open panel prompt");
|
|
|
|
panel.allowsMultipleSelection = NO;
|
|
|
|
panel.canChooseFiles = NO;
|
|
|
|
panel.canChooseDirectories = YES;
|
|
|
|
panel.canCreateDirectories = YES;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
[panel beginSheetModalForWindow: fCustomLocationPopUp.window completionHandler: ^(NSInteger result) {
|
|
|
|
const NSInteger index = [GroupsController.groups indexForRow: fTableView.selectedRow];
|
2011-12-11 22:31:01 +00:00
|
|
|
if (result == NSFileHandlingPanelOKButton)
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
NSString * path = panel.URLs[0].path;
|
|
|
|
[GroupsController.groups setCustomDownloadLocation: path forIndex: index];
|
|
|
|
[GroupsController.groups setUsesCustomDownloadLocation: YES forIndex: index];
|
2011-12-11 22:31:01 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (![GroupsController.groups customDownloadLocationForIndex: index])
|
|
|
|
[GroupsController.groups setUsesCustomDownloadLocation: NO forIndex: index];
|
2011-12-11 22:31:01 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-12-11 22:31:01 +00:00
|
|
|
[self refreshCustomLocationWithSingleGroup];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2011-12-11 22:31:01 +00:00
|
|
|
[fCustomLocationPopUp selectItemAtIndex: 0];
|
|
|
|
}];
|
2008-11-30 19:23:15 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (IBAction) toggleUseCustomDownloadLocation: (id) sender
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
NSInteger index = [GroupsController.groups indexForRow: fTableView.selectedRow];
|
|
|
|
if (fCustomLocationEnableCheck.state == NSOnState)
|
2008-11-30 19:23:15 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if ([GroupsController.groups customDownloadLocationForIndex: index])
|
|
|
|
[GroupsController.groups setUsesCustomDownloadLocation: YES forIndex: index];
|
2008-11-30 19:23:15 +00:00
|
|
|
else
|
|
|
|
[self customDownloadLocationSheetShow: nil];
|
|
|
|
}
|
|
|
|
else
|
2021-08-07 07:27:56 +00:00
|
|
|
[GroupsController.groups setUsesCustomDownloadLocation: NO forIndex: index];
|
2008-11-30 19:23:15 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
fCustomLocationPopUp.enabled = (fCustomLocationEnableCheck.state == NSOnState);
|
2008-11-30 19:23:15 +00:00
|
|
|
}
|
|
|
|
|
2008-12-08 03:26:28 +00:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Rule editor
|
|
|
|
|
2016-09-11 10:22:49 +00:00
|
|
|
- (IBAction) toggleUseAutoAssignRules: (id) sender
|
2008-12-08 03:26:28 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
NSInteger index = [GroupsController.groups indexForRow: fTableView.selectedRow];
|
|
|
|
if (fAutoAssignRulesEnableCheck.state == NSOnState)
|
2008-12-08 03:26:28 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if ([GroupsController.groups autoAssignRulesForIndex: index])
|
|
|
|
[GroupsController.groups setUsesAutoAssignRules: YES forIndex: index];
|
2008-12-08 03:26:28 +00:00
|
|
|
else
|
|
|
|
[self orderFrontRulesSheet: nil];
|
|
|
|
}
|
|
|
|
else
|
2021-08-07 07:27:56 +00:00
|
|
|
[GroupsController.groups setUsesAutoAssignRules: NO forIndex: index];
|
2008-12-08 03:26:28 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
fAutoAssignRulesEditButton.enabled = fAutoAssignRulesEnableCheck.state == NSOnState;
|
2008-12-08 03:26:28 +00:00
|
|
|
}
|
|
|
|
|
2016-09-11 10:22:49 +00:00
|
|
|
- (IBAction) orderFrontRulesSheet: (id) sender
|
2008-12-08 03:26:28 +00:00
|
|
|
{
|
2017-02-05 15:41:47 +00:00
|
|
|
if (!self.groupRulesSheetWindow)
|
2021-08-07 07:27:56 +00:00
|
|
|
[NSBundle.mainBundle loadNibNamed: @"GroupRules" owner: self topLevelObjects: NULL];
|
2008-12-08 03:26:28 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
NSInteger index = [GroupsController.groups indexForRow: fTableView.selectedRow];
|
|
|
|
NSPredicate *predicate = [GroupsController.groups autoAssignRulesForIndex: index];
|
|
|
|
self.ruleEditor.objectValue = predicate;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
if (self.ruleEditor.numberOfRows == 0)
|
2017-02-05 15:41:47 +00:00
|
|
|
[self.ruleEditor addRow: nil];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2018-12-21 22:14:44 +00:00
|
|
|
[fTableView.window beginSheet:self.groupRulesSheetWindow completionHandler:nil];
|
2008-12-08 03:26:28 +00:00
|
|
|
}
|
|
|
|
|
2016-09-11 10:22:49 +00:00
|
|
|
- (IBAction) cancelRules: (id) sender
|
2008-12-08 03:26:28 +00:00
|
|
|
{
|
2017-02-05 15:41:47 +00:00
|
|
|
[self.groupRulesSheetWindow orderOut: nil];
|
|
|
|
[NSApp endSheet: self.groupRulesSheetWindow];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
NSInteger index = [GroupsController.groups indexForRow: fTableView.selectedRow];
|
|
|
|
if (![GroupsController.groups autoAssignRulesForIndex: index])
|
2008-12-08 03:26:28 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
[GroupsController.groups setUsesAutoAssignRules: NO forIndex: index];
|
|
|
|
fAutoAssignRulesEnableCheck.state = NO;
|
|
|
|
fAutoAssignRulesEditButton.enabled = NO;
|
2008-12-08 03:26:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-09-11 10:22:49 +00:00
|
|
|
- (IBAction) saveRules: (id) sender
|
2008-12-08 03:26:28 +00:00
|
|
|
{
|
2017-02-05 15:41:47 +00:00
|
|
|
[self.groupRulesSheetWindow orderOut: nil];
|
|
|
|
[NSApp endSheet: self.groupRulesSheetWindow];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
NSInteger index = [GroupsController.groups indexForRow: fTableView.selectedRow];
|
|
|
|
[GroupsController.groups setUsesAutoAssignRules: YES forIndex: index];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
NSPredicate * predicate = self.ruleEditor.objectValue;
|
|
|
|
[GroupsController.groups setAutoAssignRules: predicate forIndex: index];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
fAutoAssignRulesEnableCheck.state = [GroupsController.groups usesAutoAssignRulesForIndex: index];
|
|
|
|
fAutoAssignRulesEditButton.enabled = fAutoAssignRulesEnableCheck.state == NSOnState;
|
2008-12-08 03:26:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
- (void) ruleEditorRowsDidChange: (NSNotification *) notification
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
NSScrollView * ruleEditorScrollView = self.ruleEditor.enclosingScrollView;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
const CGFloat rowHeight = self.ruleEditor.rowHeight;
|
|
|
|
const CGFloat bordersHeight = ruleEditorScrollView.frame.size.height - ruleEditorScrollView.contentSize.height;
|
2016-03-02 07:55:37 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
const CGFloat requiredRowCount = self.ruleEditor.numberOfRows;
|
|
|
|
const CGFloat maxVisibleRowCount = (long)((NSHeight(self.ruleEditor.window.screen.visibleFrame) * 2 / 3) / rowHeight);
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
self.ruleEditorHeightConstraint.constant = MIN(requiredRowCount, maxVisibleRowCount) * rowHeight + bordersHeight;
|
|
|
|
ruleEditorScrollView.hasVerticalScroller = requiredRowCount > maxVisibleRowCount;
|
2008-12-08 03:26:28 +00:00
|
|
|
}
|
|
|
|
|
2007-12-17 16:06:20 +00:00
|
|
|
@end
|
2008-11-29 21:29:06 +00:00
|
|
|
|
2008-12-01 01:44:38 +00:00
|
|
|
@implementation GroupsPrefsController (Private)
|
2008-11-29 21:29:06 +00:00
|
|
|
|
2008-12-08 03:55:08 +00:00
|
|
|
- (void) updateSelectedGroup
|
2008-11-29 21:29:06 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
[fAddRemoveControl setEnabled: fTableView.numberOfSelectedRows > 0 forSegment: REMOVE_TAG];
|
|
|
|
if (fTableView.numberOfSelectedRows == 1)
|
2008-11-29 21:29:06 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
const NSInteger index = [GroupsController.groups indexForRow: fTableView.selectedRow];
|
|
|
|
fSelectedColorView.color = [GroupsController.groups colorForIndex: index];
|
|
|
|
fSelectedColorView.enabled = YES;
|
|
|
|
fSelectedColorNameField.stringValue = [GroupsController.groups nameForIndex: index];
|
|
|
|
fSelectedColorNameField.enabled = YES;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2009-12-19 19:17:09 +00:00
|
|
|
[self refreshCustomLocationWithSingleGroup];
|
2008-12-08 03:26:28 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
fAutoAssignRulesEnableCheck.state = [GroupsController.groups usesAutoAssignRulesForIndex: index];
|
|
|
|
fAutoAssignRulesEnableCheck.enabled = YES;
|
|
|
|
fAutoAssignRulesEditButton.enabled = (fAutoAssignRulesEnableCheck.state == NSOnState);
|
2008-11-29 21:29:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
fSelectedColorView.color = NSColor.whiteColor;
|
|
|
|
fSelectedColorView.enabled = NO;
|
|
|
|
fSelectedColorNameField.stringValue = @"";
|
|
|
|
fSelectedColorNameField.enabled = NO;
|
|
|
|
fCustomLocationEnableCheck.enabled = NO;
|
|
|
|
fCustomLocationPopUp.enabled = NO;
|
|
|
|
fAutoAssignRulesEnableCheck.enabled = NO;
|
|
|
|
fAutoAssignRulesEditButton.enabled = NO;
|
2008-11-29 21:29:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-12-19 19:17:09 +00:00
|
|
|
- (void) refreshCustomLocationWithSingleGroup
|
2009-12-16 03:19:09 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
const NSInteger index = [GroupsController.groups indexForRow: fTableView.selectedRow];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
const BOOL hasCustomLocation = [GroupsController.groups usesCustomDownloadLocationForIndex: index];
|
|
|
|
fCustomLocationEnableCheck.state = hasCustomLocation;
|
|
|
|
fCustomLocationEnableCheck.enabled = YES;
|
|
|
|
fCustomLocationPopUp.enabled = hasCustomLocation;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-07 07:27:56 +00:00
|
|
|
NSString * location = [GroupsController.groups customDownloadLocationForIndex: index];
|
2009-12-19 19:17:09 +00:00
|
|
|
if (location)
|
2009-12-16 03:19:09 +00:00
|
|
|
{
|
2017-07-29 16:14:22 +00:00
|
|
|
ExpandedPathToPathTransformer * pathTransformer = [[ExpandedPathToPathTransformer alloc] init];
|
2021-08-07 07:27:56 +00:00
|
|
|
[fCustomLocationPopUp itemAtIndex: 0].title = [pathTransformer transformedValue: location];
|
2017-07-29 16:14:22 +00:00
|
|
|
ExpandedPathToIconTransformer * iconTransformer = [[ExpandedPathToIconTransformer alloc] init];
|
2021-08-07 07:27:56 +00:00
|
|
|
[fCustomLocationPopUp itemAtIndex: 0].image = [iconTransformer transformedValue: location];
|
2009-12-16 03:19:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
[fCustomLocationPopUp itemAtIndex: 0].title = @"";
|
|
|
|
[fCustomLocationPopUp itemAtIndex: 0].image = nil;
|
2009-12-16 03:19:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-29 21:29:06 +00:00
|
|
|
@end
|