2022-01-20 18:27:56 +00:00
|
|
|
// This file Copyright © 2007-2022 Transmission authors and contributors.
|
|
|
|
// It may be used under the MIT (SPDX: MIT) license.
|
|
|
|
// License text can be found in the licenses/ folder.
|
2007-12-17 16:06:20 +00:00
|
|
|
|
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"
|
2007-12-17 16:06:20 +00:00
|
|
|
|
2022-10-19 19:28:21 +00:00
|
|
|
static NSString* const kGroupTableViewDataType = @"GroupTableViewDataType";
|
2007-12-17 21:11:53 +00:00
|
|
|
|
2022-10-19 19:28:21 +00:00
|
|
|
typedef NS_ENUM(NSInteger, SegmentTag) {
|
|
|
|
SegmentTagAdd = 0,
|
|
|
|
SegmentTagRemove = 1,
|
|
|
|
};
|
2007-12-17 16:06:20 +00:00
|
|
|
|
2017-02-05 15:41:47 +00:00
|
|
|
@interface GroupsPrefsController ()
|
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
@property(nonatomic) IBOutlet NSTableView* fTableView;
|
|
|
|
@property(nonatomic) IBOutlet NSSegmentedControl* fAddRemoveControl;
|
|
|
|
|
|
|
|
@property(nonatomic) IBOutlet NSColorWell* fSelectedColorView;
|
|
|
|
@property(nonatomic) IBOutlet NSTextField* fSelectedColorNameField;
|
|
|
|
@property(nonatomic) IBOutlet NSButton* fCustomLocationEnableCheck;
|
|
|
|
@property(nonatomic) IBOutlet NSPopUpButton* fCustomLocationPopUp;
|
|
|
|
|
|
|
|
@property(nonatomic) IBOutlet NSButton* fAutoAssignRulesEnableCheck;
|
|
|
|
@property(nonatomic) IBOutlet NSButton* fAutoAssignRulesEditButton;
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
@property(nonatomic) IBOutlet NSWindow* groupRulesSheetWindow;
|
|
|
|
@property(nonatomic, weak) IBOutlet NSPredicateEditor* ruleEditor;
|
|
|
|
@property(nonatomic, weak) IBOutlet NSLayoutConstraint* ruleEditorHeightConstraint;
|
2017-02-05 15:41:47 +00:00
|
|
|
|
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
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)awakeFromNib
|
2007-12-17 16:06:20 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
[self.fTableView registerForDraggedTypes:@[ kGroupTableViewDataType ]];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.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
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSInteger)numberOfRowsInTableView:(NSTableView*)tableview
|
2007-12-17 16:06:20 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
return GroupsController.groups.numberOfGroups;
|
2007-12-17 16:06:20 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (id)tableView:(NSTableView*)tableView objectValueForTableColumn:(NSTableColumn*)tableColumn row:(NSInteger)row
|
2007-12-17 16:06:20 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
GroupsController* groupsController = GroupsController.groups;
|
|
|
|
NSInteger groupsIndex = [groupsController indexForRow:row];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSString* identifier = tableColumn.identifier;
|
|
|
|
if ([identifier isEqualToString:@"Color"])
|
|
|
|
{
|
|
|
|
return [groupsController imageForIndex:groupsIndex];
|
|
|
|
}
|
2007-12-17 16:06:20 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
return [groupsController nameForIndex:groupsIndex];
|
|
|
|
}
|
2007-12-17 16:06:20 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +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
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*)change context:(void*)context
|
2008-11-29 20:03:18 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (object == self.fSelectedColorView && self.fTableView.numberOfSelectedRows == 1)
|
2008-11-29 20:03:18 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSInteger index = [GroupsController.groups indexForRow:self.fTableView.selectedRow];
|
|
|
|
[GroupsController.groups setColor:self.fSelectedColorView.color forIndex:index];
|
|
|
|
self.fTableView.needsDisplay = YES;
|
2008-11-29 20:03:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)controlTextDidEndEditing:(NSNotification*)notification
|
2008-11-29 20:03:18 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (notification.object == self.fSelectedColorNameField)
|
2008-11-29 20:03:18 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSInteger index = [GroupsController.groups indexForRow:self.fTableView.selectedRow];
|
|
|
|
[GroupsController.groups setName:self.fSelectedColorNameField.stringValue forIndex:index];
|
|
|
|
self.fTableView.needsDisplay = YES;
|
2008-11-29 20:03:18 +00:00
|
|
|
}
|
2007-12-17 16:06:20 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)tableView:(NSTableView*)tableView writeRowsWithIndexes:(NSIndexSet*)rowIndexes toPasteboard:(NSPasteboard*)pboard
|
2007-12-17 21:11:53 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
[pboard declareTypes:@[ kGroupTableViewDataType ] owner:self];
|
2022-12-14 06:42:49 +00:00
|
|
|
[pboard setData:[NSKeyedArchiver archivedDataWithRootObject:rowIndexes requiringSecureCoding:YES error:nil]
|
|
|
|
forType:kGroupTableViewDataType];
|
2007-12-17 21:11:53 +00:00
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (NSDragOperation)tableView:(NSTableView*)tableView
|
|
|
|
validateDrop:(id<NSDraggingInfo>)info
|
|
|
|
proposedRow:(NSInteger)row
|
|
|
|
proposedDropOperation:(NSTableViewDropOperation)operation
|
2007-12-17 21:11:53 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSPasteboard* pasteboard = info.draggingPasteboard;
|
2022-10-19 19:28:21 +00:00
|
|
|
if ([pasteboard.types containsObject:kGroupTableViewDataType])
|
2007-12-17 21:11:53 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView setDropRow:row dropOperation:NSTableViewDropAbove];
|
2007-12-17 21:11:53 +00:00
|
|
|
return NSDragOperationGeneric;
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2007-12-17 21:11:53 +00:00
|
|
|
return NSDragOperationNone;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (BOOL)tableView:(NSTableView*)tableView
|
|
|
|
acceptDrop:(id<NSDraggingInfo>)info
|
|
|
|
row:(NSInteger)newRow
|
|
|
|
dropOperation:(NSTableViewDropOperation)operation
|
2007-12-17 21:11:53 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSPasteboard* pasteboard = info.draggingPasteboard;
|
2022-10-19 19:28:21 +00:00
|
|
|
if ([pasteboard.types containsObject:kGroupTableViewDataType])
|
2007-12-17 21:11:53 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
NSIndexSet* indexes = [NSKeyedUnarchiver unarchivedObjectOfClass:NSIndexSet.class fromData:[pasteboard dataForType:kGroupTableViewDataType]
|
2022-06-18 14:26:45 +00:00
|
|
|
error:nil];
|
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)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2012-01-04 00:06:30 +00:00
|
|
|
newRow--;
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2016-01-06 11:05:37 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView beginUpdates];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[GroupsController.groups moveGroupAtRow:oldRow toRow:newRow];
|
2016-01-06 11:05:37 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView moveRowAtIndex:oldRow toIndex:newRow];
|
|
|
|
[self.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;
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)addRemoveGroup:(id)sender
|
2007-12-17 16:06:20 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
if (NSColorPanel.sharedColorPanelExists)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2021-08-07 07:27:56 +00:00
|
|
|
[NSColorPanel.sharedColorPanel close];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
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
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
switch ([[sender cell] tagForSegment:[sender selectedSegment]])
|
2007-12-17 16:06:20 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
case SegmentTagAdd:
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView beginUpdates];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[GroupsController.groups addNewGroup];
|
2016-01-06 11:05:37 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
row = self.fTableView.numberOfRows;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView insertRowsAtIndexes:[NSIndexSet indexSetWithIndex:row] withAnimation:NSTableViewAnimationSlideUp];
|
|
|
|
[self.fTableView endUpdates];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
|
|
|
|
[self.fTableView scrollRowToVisible:row];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fSelectedColorNameField.window makeFirstResponder:self.fSelectedColorNameField];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
break;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-10-19 19:28:21 +00:00
|
|
|
case SegmentTagRemove:
|
2022-02-22 16:04:20 +00:00
|
|
|
row = self.fTableView.selectedRow;
|
2016-01-06 11:05:37 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView beginUpdates];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
[GroupsController.groups removeGroupWithRowIndex:row];
|
2016-01-06 11:05:37 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView removeRowsAtIndexes:[NSIndexSet indexSetWithIndex:row] withAnimation:NSTableViewAnimationSlideUp];
|
|
|
|
[self.fTableView endUpdates];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fTableView.numberOfRows > 0)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
if (row == self.fTableView.numberOfRows)
|
2010-04-10 15:48:09 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
--row;
|
2010-04-10 15:48:09 +00:00
|
|
|
}
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView selectRowIndexes:[NSIndexSet indexSetWithIndex:row] byExtendingSelection:NO];
|
|
|
|
[self.fTableView scrollRowToVisible:row];
|
2021-08-15 09:41:48 +00:00
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
break;
|
2007-12-17 16:06:20 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)customDownloadLocationSheetShow:(id)sender
|
2008-11-30 19:23:15 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSOpenPanel* panel = [NSOpenPanel openPanel];
|
2008-11-30 19:23:15 +00:00
|
|
|
|
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
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[panel beginSheetModalForWindow:self.fCustomLocationPopUp.window completionHandler:^(NSInteger result) {
|
|
|
|
NSInteger const index = [GroupsController.groups indexForRow:self.fTableView.selectedRow];
|
2021-10-31 15:18:27 +00:00
|
|
|
if (result == NSModalResponseOK)
|
2011-12-11 22:31:01 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +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-15 09:41:48 +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
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fCustomLocationPopUp selectItemAtIndex:0];
|
2011-12-11 22:31:01 +00:00
|
|
|
}];
|
2008-11-30 19:23:15 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (IBAction)toggleUseCustomDownloadLocation:(id)sender
|
2008-11-30 19:23:15 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSInteger index = [GroupsController.groups indexForRow:self.fTableView.selectedRow];
|
|
|
|
if (self.fCustomLocationEnableCheck.state == NSControlStateValueOn)
|
2008-11-30 19:23:15 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([GroupsController.groups customDownloadLocationForIndex:index])
|
|
|
|
{
|
|
|
|
[GroupsController.groups setUsesCustomDownloadLocation:YES forIndex:index];
|
|
|
|
}
|
2008-11-30 19:23:15 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[self customDownloadLocationSheetShow:nil];
|
|
|
|
}
|
2008-11-30 19:23:15 +00:00
|
|
|
}
|
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[GroupsController.groups setUsesCustomDownloadLocation:NO forIndex:index];
|
|
|
|
}
|
2008-11-30 19:23:15 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fCustomLocationPopUp.enabled = (self.fCustomLocationEnableCheck.state == NSControlStateValueOn);
|
2008-11-30 19:23:15 +00:00
|
|
|
}
|
|
|
|
|
2008-12-08 03:26:28 +00:00
|
|
|
#pragma mark -
|
|
|
|
#pragma mark Rule editor
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (IBAction)toggleUseAutoAssignRules:(id)sender
|
2008-12-08 03:26:28 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSInteger index = [GroupsController.groups indexForRow:self.fTableView.selectedRow];
|
|
|
|
if (self.fAutoAssignRulesEnableCheck.state == NSControlStateValueOn)
|
2008-12-08 03:26:28 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
if ([GroupsController.groups autoAssignRulesForIndex:index])
|
|
|
|
{
|
|
|
|
[GroupsController.groups setUsesAutoAssignRules:YES forIndex:index];
|
|
|
|
}
|
2008-12-08 03:26:28 +00:00
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[self orderFrontRulesSheet:nil];
|
|
|
|
}
|
2008-12-08 03:26:28 +00:00
|
|
|
}
|
|
|
|
else
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[GroupsController.groups setUsesAutoAssignRules:NO forIndex:index];
|
|
|
|
}
|
2008-12-08 03:26:28 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fAutoAssignRulesEditButton.enabled = self.fAutoAssignRulesEnableCheck.state == NSControlStateValueOn;
|
2008-12-08 03:26:28 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +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-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[NSBundle.mainBundle loadNibNamed:@"GroupRules" owner:self topLevelObjects:NULL];
|
|
|
|
}
|
2008-12-08 03:26:28 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSInteger index = [GroupsController.groups indexForRow:self.fTableView.selectedRow];
|
2021-08-15 09:41:48 +00:00
|
|
|
NSPredicate* predicate = [GroupsController.groups autoAssignRulesForIndex:index];
|
2021-08-07 07:27:56 +00:00
|
|
|
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)
|
2021-08-15 09:41:48 +00:00
|
|
|
{
|
|
|
|
[self.ruleEditor addRow:nil];
|
|
|
|
}
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fTableView.window beginSheet:self.groupRulesSheetWindow completionHandler:nil];
|
2008-12-08 03:26:28 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (IBAction)cancelRules:(id)sender
|
2008-12-08 03:26:28 +00:00
|
|
|
{
|
2019-02-03 04:20:43 +00:00
|
|
|
[self.fTableView.window endSheet:self.groupRulesSheetWindow];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSInteger index = [GroupsController.groups indexForRow:self.fTableView.selectedRow];
|
2021-08-15 09:41:48 +00:00
|
|
|
if (![GroupsController.groups autoAssignRulesForIndex:index])
|
2008-12-08 03:26:28 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
[GroupsController.groups setUsesAutoAssignRules:NO forIndex:index];
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fAutoAssignRulesEnableCheck.state = NO;
|
|
|
|
self.fAutoAssignRulesEditButton.enabled = NO;
|
2008-12-08 03:26:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (IBAction)saveRules:(id)sender
|
2008-12-08 03:26:28 +00:00
|
|
|
{
|
2019-02-03 04:20:43 +00:00
|
|
|
[self.fTableView.window endSheet:self.groupRulesSheetWindow];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
NSInteger index = [GroupsController.groups indexForRow:self.fTableView.selectedRow];
|
2021-08-15 09:41:48 +00:00
|
|
|
[GroupsController.groups setUsesAutoAssignRules:YES forIndex:index];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
NSPredicate* predicate = self.ruleEditor.objectValue;
|
|
|
|
[GroupsController.groups setAutoAssignRules:predicate forIndex:index];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fAutoAssignRulesEnableCheck.state = [GroupsController.groups usesAutoAssignRulesForIndex:index];
|
|
|
|
self.fAutoAssignRulesEditButton.enabled = self.fAutoAssignRulesEnableCheck.state == NSControlStateValueOn;
|
2008-12-08 03:26:28 +00:00
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)ruleEditorRowsDidChange:(NSNotification*)notification
|
2008-12-08 03:26:28 +00:00
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
NSScrollView* ruleEditorScrollView = self.ruleEditor.enclosingScrollView;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
CGFloat const rowHeight = self.ruleEditor.rowHeight;
|
|
|
|
CGFloat const bordersHeight = ruleEditorScrollView.frame.size.height - ruleEditorScrollView.contentSize.height;
|
2016-03-02 07:55:37 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
CGFloat const requiredRowCount = self.ruleEditor.numberOfRows;
|
|
|
|
CGFloat const 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
|
|
|
}
|
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
#pragma mark - Private
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)updateSelectedGroup
|
2008-11-29 21:29:06 +00:00
|
|
|
{
|
2022-10-19 19:28:21 +00:00
|
|
|
[self.fAddRemoveControl setEnabled:self.fTableView.numberOfSelectedRows > 0 forSegment:SegmentTagRemove];
|
2022-02-22 16:04:20 +00:00
|
|
|
if (self.fTableView.numberOfSelectedRows == 1)
|
2008-11-29 21:29:06 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSInteger const index = [GroupsController.groups indexForRow:self.fTableView.selectedRow];
|
|
|
|
self.fSelectedColorView.color = [GroupsController.groups colorForIndex:index];
|
|
|
|
self.fSelectedColorView.enabled = YES;
|
|
|
|
self.fSelectedColorNameField.stringValue = [GroupsController.groups nameForIndex:index];
|
|
|
|
self.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
|
|
|
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fAutoAssignRulesEnableCheck.state = [GroupsController.groups usesAutoAssignRulesForIndex:index];
|
|
|
|
self.fAutoAssignRulesEnableCheck.enabled = YES;
|
|
|
|
self.fAutoAssignRulesEditButton.enabled = (self.fAutoAssignRulesEnableCheck.state == NSControlStateValueOn);
|
2008-11-29 21:29:06 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fSelectedColorView.color = NSColor.whiteColor;
|
|
|
|
self.fSelectedColorView.enabled = NO;
|
|
|
|
self.fSelectedColorNameField.stringValue = @"";
|
|
|
|
self.fSelectedColorNameField.enabled = NO;
|
|
|
|
self.fCustomLocationEnableCheck.enabled = NO;
|
|
|
|
self.fCustomLocationPopUp.enabled = NO;
|
|
|
|
self.fAutoAssignRulesEnableCheck.enabled = NO;
|
|
|
|
self.fAutoAssignRulesEditButton.enabled = NO;
|
2008-11-29 21:29:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
- (void)refreshCustomLocationWithSingleGroup
|
2009-12-16 03:19:09 +00:00
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
NSInteger const index = [GroupsController.groups indexForRow:self.fTableView.selectedRow];
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +00:00
|
|
|
BOOL const hasCustomLocation = [GroupsController.groups usesCustomDownloadLocationForIndex:index];
|
2022-02-22 16:04:20 +00:00
|
|
|
self.fCustomLocationEnableCheck.state = hasCustomLocation;
|
|
|
|
self.fCustomLocationEnableCheck.enabled = YES;
|
|
|
|
self.fCustomLocationPopUp.enabled = hasCustomLocation;
|
2017-01-24 17:53:16 +00:00
|
|
|
|
2021-08-15 09:41:48 +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
|
|
|
{
|
2021-08-15 09:41:48 +00:00
|
|
|
ExpandedPathToPathTransformer* pathTransformer = [[ExpandedPathToPathTransformer alloc] init];
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fCustomLocationPopUp itemAtIndex:0].title = [pathTransformer transformedValue:location];
|
2021-08-15 09:41:48 +00:00
|
|
|
ExpandedPathToIconTransformer* iconTransformer = [[ExpandedPathToIconTransformer alloc] init];
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fCustomLocationPopUp itemAtIndex:0].image = [iconTransformer transformedValue:location];
|
2009-12-16 03:19:09 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-02-22 16:04:20 +00:00
|
|
|
[self.fCustomLocationPopUp itemAtIndex:0].title = @"";
|
|
|
|
[self.fCustomLocationPopUp itemAtIndex:0].image = nil;
|
2009-12-16 03:19:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-11-29 21:29:06 +00:00
|
|
|
@end
|