]> granicus.if.org Git - transmission/commitdiff
add an all/any button to the group rules sheet
authorMitchell Livingston <livings124@transmissionbt.com>
Sat, 13 Dec 2008 17:18:28 +0000 (17:18 +0000)
committerMitchell Livingston <livings124@transmissionbt.com>
Sat, 13 Dec 2008 17:18:28 +0000 (17:18 +0000)
macosx/GroupRules.xib
macosx/GroupsController.h
macosx/GroupsController.m
macosx/GroupsPrefsController.h
macosx/GroupsPrefsController.m

index 4685781538b6d45f2d76753220ec9879a3e7f5ae..86203478576009922073597582a64835b10832dd 100644 (file)
                                                <object class="NSTextField" id="332791107">
                                                        <reference key="NSNextResponder" ref="464768712"/>
                                                        <int key="NSvFlags">270</int>
-                                                       <string key="NSFrame">{{17, 81}, {437, 17}}</string>
+                                                       <string key="NSFrame">{{76, 81}, {378, 17}}</string>
                                                        <reference key="NSSuperview" ref="464768712"/>
                                                        <bool key="NSEnabled">YES</bool>
                                                        <object class="NSTextFieldCell" key="NSCell" id="835481534">
                                                                <int key="NSCellFlags">67239424</int>
                                                                <int key="NSCellFlags2">272629760</int>
-                                                               <string key="NSContents">description</string>
+                                                               <string key="NSContents">criteria mustbe met to assign a transfer on add.</string>
                                                                <object class="NSFont" key="NSSupport">
                                                                        <string key="NSName">LucidaGrande</string>
                                                                        <double key="NSSize">1.300000e+01</double>
                                                                </object>
                                                        </object>
                                                </object>
+                                               <object class="NSPopUpButton" id="197810941">
+                                                       <reference key="NSNextResponder" ref="464768712"/>
+                                                       <int key="NSvFlags">268</int>
+                                                       <string key="NSFrame">{{17, 77}, {57, 22}}</string>
+                                                       <reference key="NSSuperview" ref="464768712"/>
+                                                       <bool key="NSEnabled">YES</bool>
+                                                       <object class="NSPopUpButtonCell" key="NSCell" id="292386544">
+                                                               <int key="NSCellFlags">-2076049856</int>
+                                                               <int key="NSCellFlags2">133120</int>
+                                                               <object class="NSFont" key="NSSupport">
+                                                                       <string key="NSName">LucidaGrande</string>
+                                                                       <double key="NSSize">1.100000e+01</double>
+                                                                       <int key="NSfFlags">3100</int>
+                                                               </object>
+                                                               <reference key="NSControlView" ref="197810941"/>
+                                                               <int key="NSButtonFlags">109199615</int>
+                                                               <int key="NSButtonFlags2">129</int>
+                                                               <string key="NSAlternateContents"/>
+                                                               <string key="NSKeyEquivalent"/>
+                                                               <int key="NSPeriodicDelay">400</int>
+                                                               <int key="NSPeriodicInterval">75</int>
+                                                               <object class="NSMenuItem" key="NSMenuItem" id="47707498">
+                                                                       <reference key="NSMenu" ref="533472230"/>
+                                                                       <string key="NSTitle">All</string>
+                                                                       <string key="NSKeyEquiv"/>
+                                                                       <int key="NSKeyEquivModMask">1048576</int>
+                                                                       <int key="NSMnemonicLoc">2147483647</int>
+                                                                       <int key="NSState">1</int>
+                                                                       <object class="NSCustomResource" key="NSOnImage" id="205784288">
+                                                                               <string key="NSClassName">NSImage</string>
+                                                                               <string key="NSResourceName">NSMenuCheckmark</string>
+                                                                       </object>
+                                                                       <object class="NSCustomResource" key="NSMixedImage" id="293296343">
+                                                                               <string key="NSClassName">NSImage</string>
+                                                                               <string key="NSResourceName">NSMenuMixedState</string>
+                                                                       </object>
+                                                                       <string key="NSAction">_popUpItemAction:</string>
+                                                                       <reference key="NSTarget" ref="292386544"/>
+                                                               </object>
+                                                               <bool key="NSMenuItemRespectAlignment">YES</bool>
+                                                               <object class="NSMenu" key="NSMenu" id="533472230">
+                                                                       <string key="NSTitle">OtherViews</string>
+                                                                       <object class="NSMutableArray" key="NSMenuItems">
+                                                                               <bool key="EncodedWithXMLCoder">YES</bool>
+                                                                               <reference ref="47707498"/>
+                                                                               <object class="NSMenuItem" id="627736956">
+                                                                                       <reference key="NSMenu" ref="533472230"/>
+                                                                                       <string key="NSTitle">Any</string>
+                                                                                       <string key="NSKeyEquiv"/>
+                                                                                       <int key="NSKeyEquivModMask">1048576</int>
+                                                                                       <int key="NSMnemonicLoc">2147483647</int>
+                                                                                       <reference key="NSOnImage" ref="205784288"/>
+                                                                                       <reference key="NSMixedImage" ref="293296343"/>
+                                                                                       <string key="NSAction">_popUpItemAction:</string>
+                                                                                       <int key="NSTag">1</int>
+                                                                                       <reference key="NSTarget" ref="292386544"/>
+                                                                               </object>
+                                                                       </object>
+                                                                       <bool key="NSNoAutoenable">YES</bool>
+                                                               </object>
+                                                               <int key="NSPreferredEdge">1</int>
+                                                               <bool key="NSUsesItemFromMenu">YES</bool>
+                                                               <bool key="NSAltersState">YES</bool>
+                                                               <int key="NSArrowPosition">2</int>
+                                                       </object>
+                                               </object>
                                        </object>
                                        <string key="NSFrameSize">{471, 118}</string>
                                        <reference key="NSSuperview"/>
                                        </object>
                                        <int key="connectionID">22</int>
                                </object>
+                               <object class="IBConnectionRecord">
+                                       <object class="IBOutletConnection" key="connection">
+                                               <string key="label">fRulesAllAnyButton</string>
+                                               <reference key="source" ref="1001"/>
+                                               <reference key="destination" ref="197810941"/>
+                                       </object>
+                                       <int key="connectionID">30</int>
+                               </object>
                        </object>
                        <object class="IBMutableOrderedSet" key="objectRecords">
                                <object class="NSArray" key="orderedObjects">
                                                        <bool key="EncodedWithXMLCoder">YES</bool>
                                                        <reference ref="929052796"/>
                                                        <reference ref="1048345917"/>
-                                                       <reference ref="332791107"/>
                                                        <reference ref="772030743"/>
+                                                       <reference ref="197810941"/>
+                                                       <reference ref="332791107"/>
                                                </object>
                                                <reference key="parent" ref="154698973"/>
                                        </object>
                                                <reference key="object" ref="1052460241"/>
                                                <reference key="parent" ref="929052796"/>
                                        </object>
+                                       <object class="IBObjectRecord">
+                                               <int key="objectID">23</int>
+                                               <reference key="object" ref="197810941"/>
+                                               <object class="NSMutableArray" key="children">
+                                                       <bool key="EncodedWithXMLCoder">YES</bool>
+                                                       <reference ref="292386544"/>
+                                               </object>
+                                               <reference key="parent" ref="464768712"/>
+                                       </object>
+                                       <object class="IBObjectRecord">
+                                               <int key="objectID">24</int>
+                                               <reference key="object" ref="292386544"/>
+                                               <object class="NSMutableArray" key="children">
+                                                       <bool key="EncodedWithXMLCoder">YES</bool>
+                                                       <reference ref="533472230"/>
+                                               </object>
+                                               <reference key="parent" ref="197810941"/>
+                                       </object>
+                                       <object class="IBObjectRecord">
+                                               <int key="objectID">25</int>
+                                               <reference key="object" ref="533472230"/>
+                                               <object class="NSMutableArray" key="children">
+                                                       <bool key="EncodedWithXMLCoder">YES</bool>
+                                                       <reference ref="47707498"/>
+                                                       <reference ref="627736956"/>
+                                               </object>
+                                               <reference key="parent" ref="292386544"/>
+                                       </object>
+                                       <object class="IBObjectRecord">
+                                               <int key="objectID">26</int>
+                                               <reference key="object" ref="47707498"/>
+                                               <reference key="parent" ref="533472230"/>
+                                       </object>
+                                       <object class="IBObjectRecord">
+                                               <int key="objectID">27</int>
+                                               <reference key="object" ref="627736956"/>
+                                               <reference key="parent" ref="533472230"/>
+                                       </object>
                                </object>
                        </object>
                        <object class="NSMutableDictionary" key="flattenedProperties">
                                        <string>11.IBPluginDependency</string>
                                        <string>12.IBPluginDependency</string>
                                        <string>2.IBPluginDependency</string>
+                                       <string>23.IBPluginDependency</string>
+                                       <string>24.IBPluginDependency</string>
+                                       <string>25.IBEditorWindowLastContentRect</string>
+                                       <string>25.IBPluginDependency</string>
+                                       <string>26.IBPluginDependency</string>
+                                       <string>27.IBPluginDependency</string>
                                        <string>3.IBPluginDependency</string>
                                        <string>4.IBPluginDependency</string>
                                        <string>5.IBPluginDependency</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+                                       <string>{{291, 385}, {84, 37}}</string>
+                                       <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+                                       <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+                                       <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+                                       <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+                                       <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                        <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
                                </object>
                        </object>
                        <nil key="sourceID"/>
-                       <int key="maxID">22</int>
+                       <int key="maxID">30</int>
                </object>
                <object class="IBClassDescriber" key="IBDocument.Classes">
                        <object class="NSMutableArray" key="referencedPartialClassDescriptions">
                                                        <string>fGroupRulesPrefsContainer</string>
                                                        <string>fGroupRulesSheetWindow</string>
                                                        <string>fRuleEditor</string>
+                                                       <string>fRulesAllAnyButton</string>
                                                        <string>fRulesSheetCancelButton</string>
                                                        <string>fRulesSheetDescriptionField</string>
                                                        <string>fRulesSheetOKButton</string>
                                                        <string>NSView</string>
                                                        <string>NSWindow</string>
                                                        <string>NSRuleEditor</string>
+                                                       <string>NSPopUpButton</string>
                                                        <string>NSButton</string>
                                                        <string>NSTextField</string>
                                                        <string>NSButton</string>
index 3d9958d9531c3de4e44980523f5dcb31eba33c13..ede75ca734683f57c83839446721e97f9204bea7 100644 (file)
@@ -57,6 +57,9 @@
 - (NSArray *) autoAssignRulesForIndex: (NSInteger) index;
 - (void) setAutoAssignRules: (NSArray *) rules forIndex: (NSInteger) index;
 
+- (BOOL) rulesNeedAllForIndex: (NSInteger) index;
+- (void) setRulesNeedAllForIndex: (BOOL) all forIndex: (NSInteger) index;
+
 - (void) addNewGroup;
 - (void) removeGroupWithRowIndex: (NSInteger) row;
 
index d7c5dd4bba41ae495879a83d6686a3adf9e6716c..93864951059166e84c1373b19a91fe6a4c9bb876 100644 (file)
@@ -239,6 +239,25 @@ GroupsController * fGroupsInstance = nil;
     }
 }
 
+- (BOOL) rulesNeedAllForIndex: (NSInteger) index
+{
+    NSInteger orderIndex = [self rowValueForIndex: index];
+    if (orderIndex == -1)
+        return YES;
+    
+    NSNumber * enforceAll = [[fGroups objectAtIndex: orderIndex] objectForKey: @"AssignRulesNeedAll"];
+    return !enforceAll || [enforceAll boolValue];
+}
+
+- (void) setRulesNeedAllForIndex: (BOOL) all forIndex: (NSInteger) index
+{
+    NSMutableDictionary * group = [fGroups objectAtIndex: [self rowValueForIndex: index]];
+    
+    [group setObject: [NSNumber numberWithBool: all] forKey: @"AssignRulesNeedAll"];
+    
+    [[GroupsController groups] saveGroups];
+}
+
 - (void) addNewGroup
 {
     //find the lowest index
@@ -430,7 +449,8 @@ GroupsController * fGroupsInstance = nil;
     if (!rules || [rules count] == 0)
         return NO;
     
-    #warning should rules be dict instead of array?
+    const BOOL needAll = [self rulesNeedAllForIndex: index];
+    
     NSEnumerator * iterator = [rules objectEnumerator];
     NSArray * rule = nil;
     while ((rule = [iterator nextObject]))
@@ -444,39 +464,36 @@ GroupsController * fGroupsInstance = nil;
         else
             continue;
         
+        BOOL match = NO;
+        
         NSStringCompareOptions options = NSCaseInsensitiveSearch;
         if ([place isEqualToString: @"ends"])
             options += NSBackwardsSearch;
-        BOOL match = NO;
         
         NSEnumerator * enumerator = [values objectEnumerator];
         NSString * value;
         while (!match && (value = [enumerator nextObject]))
         {
             NSRange result = [value rangeOfString: givenValue options: options];
+            
             if ([place isEqualToString: @"begins"])
-            {
-                if (result.location == 0)
-                    match = YES;
-            }
+                match = result.location == 0;
             else if ([place isEqualToString: @"contains"])
-            {
-                if (result.location != NSNotFound)
-                    match = YES;
-            }
+                match = result.location != NSNotFound;
             else if ([place isEqualToString: @"ends"])
-            {
-                if (NSMaxRange(result) == [value length])
-                    match = YES;
-            }
+                match = NSMaxRange(result) == [value length];
             else
                 break;
         }
         
-        if (!match)
+        if (match && !needAll)
+            return YES;
+        else if (!match && needAll)
             return NO;
+        else;
     }
-    return YES;
+    
+    return needAll;
 }
 
 @end
index f51c400796d2cef3ea258447ad01ccfc592aa0c7..b4d264be2ae669f0cc45f234e13a345f4640c1ef 100644 (file)
@@ -44,6 +44,7 @@
     
     IBOutlet NSButton * fRulesSheetOKButton, * fRulesSheetCancelButton;
     IBOutlet NSTextField * fRulesSheetDescriptionField;
+    IBOutlet NSPopUpButton * fRulesAllAnyButton;
 }
 
 - (void) addRemoveGroup: (id) sender;
index 39c1a8b9746423e9c6ec93119501593cb1c13dca..8c230f4604b0b5935e46203adbd419a67920535b 100644 (file)
@@ -33,6 +33,9 @@
 #define ADD_TAG 0
 #define REMOVE_TAG 1
 
+#define RULES_ALL_TAG 0
+#define RULES_ANY_TAG 1
+
 @interface GroupsPrefsController (Private)
 
 - (void) updateSelectedGroup;
     
     [fRulesSheetOKButton setStringValue: NSLocalizedString(@"OK", "Groups -> rule editor -> button")];
     [fRulesSheetCancelButton setStringValue: NSLocalizedString(@"Cancel", "Groups -> rule editor -> button")];
-    [fRulesSheetDescriptionField setStringValue: NSLocalizedString(@"All criteria must be met to assign a transfer on add.",
-                                                    "Groups -> rule editor -> button")];
+    [fRulesSheetDescriptionField setStringValue: NSLocalizedString(@"criteria must be met to assign a transfer on add.",
+                                                    "Groups -> rule editor -> button (All/Any criteria must....)")];
+    
+    [[fRulesAllAnyButton itemAtIndex: [fRulesAllAnyButton indexOfItemWithTag: RULES_ALL_TAG]] setTitle:
+        NSLocalizedString(@"All", "Groups -> rule editor -> all/any")];
+    [[fRulesAllAnyButton itemAtIndex: [fRulesAllAnyButton indexOfItemWithTag: RULES_ANY_TAG]] setTitle:
+        NSLocalizedString(@"Any", "Groups -> rule editor -> all/any")];
     
     [fSelectedColorView addObserver: self forKeyPath: @"color" options: 0 context: NULL];
     
     [fRuleEditor removeRowsAtIndexes: [NSIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [fRuleEditor numberOfRows])]
         includeSubrows: YES];
 
-    NSInteger index = [[GroupsController groups] indexForRow: [fTableView selectedRow]];
+    const NSInteger index = [[GroupsController groups] indexForRow: [fTableView selectedRow]];
     NSArray * rules = [[GroupsController groups] autoAssignRulesForIndex: index];
     if (rules)
     {
             [fRuleEditor setCriteria: [rules objectAtIndex: i] andDisplayValues: [NSArray array] forRowAtIndex: i];
         }
     }
-
+    
     if ([fRuleEditor numberOfRows] == 0)
         [fRuleEditor addRow: nil];
-
+    
+    [fRulesAllAnyButton selectItemWithTag: [[GroupsController groups] rulesNeedAllForIndex: index] ? RULES_ALL_TAG : RULES_ANY_TAG];
+    
     [NSApp beginSheet: fGroupRulesSheetWindow modalForWindow: [fTableView window] modalDelegate: nil didEndSelector: NULL
         contextInfo: NULL];
 }
     [NSApp endSheet: fGroupRulesSheetWindow];
     
     NSInteger index = [[GroupsController groups] indexForRow: [fTableView selectedRow]];
+    [[GroupsController groups] setRulesNeedAllForIndex: [[fRulesAllAnyButton selectedItem] tag] == RULES_ALL_TAG forIndex: index];
     [[GroupsController groups] setUsesAutoAssignRules: YES forIndex: index];
     
     NSMutableArray * rules = [NSMutableArray arrayWithCapacity: [fRuleEditor numberOfRows]];