Revision: 22589
          http://sourceforge.net/p/bibdesk/svn/22589
Author:   hofman
Date:     2018-09-13 12:01:57 +0000 (Thu, 13 Sep 2018)
Log Message:
-----------
Add, remove, and move pubs between group methods only for category groups, 
handle static groups separately

Modified Paths:
--------------
    trunk/bibdesk/BibDocument_Actions.m
    trunk/bibdesk/BibDocument_DataSource.m
    trunk/bibdesk/BibDocument_Groups.h
    trunk/bibdesk/BibDocument_Groups.m
    trunk/bibdesk/BibItem.h
    trunk/bibdesk/BibItem.m

Modified: trunk/bibdesk/BibDocument_Actions.m
===================================================================
--- trunk/bibdesk/BibDocument_Actions.m 2018-09-13 06:30:43 UTC (rev 22588)
+++ trunk/bibdesk/BibDocument_Actions.m 2018-09-13 12:01:57 UTC (rev 22589)
@@ -124,7 +124,7 @@
                 continue;
             }
             // we don't overwrite inherited single valued fields, they already 
have the field set through inheritance
-                       op = [newBI addToGroup:group 
handleInherited:isSingleValued ? BDSKFieldActionIgnore : handleInherited];
+                       op = [newBI addToGroup:(BDSKCategoryGroup *)group 
handleInherited:isSingleValued ? BDSKFieldActionIgnore : handleInherited];
             if (op == BDSKFieldActionAsk) {
                 NSAlert *alert = [[[NSAlert alloc] init] autorelease];
                 [alert setMessageText:NSLocalizedString(@"Inherited Value", 
@"Message in alert dialog when trying to edit inherited value")];
@@ -134,7 +134,7 @@
                 // "Set" would end up choosing an arbitrary one
                 handleInherited = [alert runModal];
                 if (handleInherited != BDSKFieldActionIgnore) {
-                    [newBI addToGroup:group handleInherited:handleInherited];
+                    [newBI addToGroup:(BDSKCategoryGroup *)group 
handleInherited:handleInherited];
                     [changedFields addObject:groupField];
                 }
             } else if (op != BDSKFieldActionIgnore) {
@@ -196,8 +196,18 @@
        NSArray *pubs = [(NSArray *)contextInfo autorelease];
     if ([[alert suppressionButton]state] == NSOnState)
                [[NSUserDefaults standardUserDefaults] setBool:NO 
forKey:BDSKWarnOnRemovalFromGroupKey];
-    if (returnCode == NSAlertFirstButtonReturn)
-        [self removePublications:pubs fromGroups:[self selectedGroups]];
+    if (returnCode == NSAlertFirstButtonReturn) {
+        NSArray *selectedGroups = [self selectedGroups];
+        if ([self hasGroupTypeSelected:BDSKStaticGroupType]) {
+            NSArray *staticGroups = [selectedGroups 
filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"groupType = 
%lu", (unsigned long)BDSKStaticGroupType]];
+            [staticGroups 
makeObjectsPerformSelector:@selector(removePublicationsInArray:) 
withObject:pubs];
+            [[self undoManager] setActionName:NSLocalizedString(@"Remove From 
Group", @"Undo action name")];
+        }
+        if ([self hasGroupTypeSelected:BDSKCategoryGroupType]) {
+            NSArray *categoryGroups = [selectedGroups 
filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"groupType = 
%lu", (unsigned long)BDSKCategoryGroupType]];
+            [self removePublications:pubs fromGroups:categoryGroups];
+        }
+    }
 }
 
 // this method is called for the main table; it's a wrapper for delete or 
remove from group
@@ -230,7 +240,7 @@
                              
didEndSelector:@selector(removePubsAlertDidEnd:returnCode:contextInfo:) 
                                 contextInfo:[pubs retain]];
         } else {
-            [self removePublications:pubs fromGroups:selectedGroups];
+            [self removePubsAlertDidEnd:nil 
returnCode:NSAlertFirstButtonReturn contextInfo:[pubs retain]];
         }
        }
 }

Modified: trunk/bibdesk/BibDocument_DataSource.m
===================================================================
--- trunk/bibdesk/BibDocument_DataSource.m      2018-09-13 06:30:43 UTC (rev 
22588)
+++ trunk/bibdesk/BibDocument_DataSource.m      2018-09-13 12:01:57 UTC (rev 
22589)
@@ -992,7 +992,7 @@
         id name = [[(BDSKCategoryGroup *)group key] isPersonField] ? 
(id)[BibAuthor authorWithName:newName] : (id)newName;
         BDSKCategoryGroup *oldGroup = [group copy];
         [(BDSKCategoryGroup *)group setName:name];
-        [self movePublications:pubs fromGroup:oldGroup toGroup:group];
+        [self movePublications:pubs fromGroup:oldGroup 
toGroup:(BDSKCategoryGroup *)group];
         [oldGroup release];
         [pubs release];
     } else if([group isNameEditable]) {
@@ -1324,8 +1324,9 @@
     if ([pubs count] == 0)
         return NO;
     
+    BDSKGroupType groupType = [item groupType];
     // if dropping on the static group parent, create a new static groups 
using a common author name or keyword if available
-    if ([item isEqual:[groups staticParent]]) {
+    if (groupType == BDSKStaticParentGroupType) {
         BibItem *pub = [pubs lastObject];
         NSMutableSet *auths = [[NSMutableSet alloc] initForFuzzyAuthors];
         NSMutableSet *keywords = [[NSMutableSet alloc] initWithSet:[pub 
groupsForField:BDSKKeywordsString]];
@@ -1347,10 +1348,15 @@
         [groups addStaticGroup:group];
         [[self undoManager] setActionName:NSLocalizedString(@"Add Group", 
@"Undo action name")];
         [self selectGroup:group];
-    }  else if ([item isEqual:[groups libraryGroup]] == NO) {
-        // add to the group we're dropping on, /not/ the currently selected 
group; no need to add to all pubs group, though
+    }  else if (groupType == BDSKStaticGroupType) {
+        // add to the group we're dropping on, /not/ the currently selected 
group
+        [(BDSKStaticGroup *)item addPublicationsFromArray:pubs];
+        [[self undoManager] setActionName:NSLocalizedString(@"Add To Group", 
@"Undo action name")];
+    }  else if (groupType == BDSKCategoryGroupType) {
+        // add to the group we're dropping on, /not/ the currently selected 
group
         [self addPublications:pubs toGroup:item];
     }
+    
     if (isDragFromMainTable == NO && isDragFromGroupTable == NO && 
isDragFromDrawer == NO && [self hasGroupTypeSelected:BDSKLibraryGroupType] == 
NO)
         [self selectPublications:pubs];
     

Modified: trunk/bibdesk/BibDocument_Groups.h
===================================================================
--- trunk/bibdesk/BibDocument_Groups.h  2018-09-13 06:30:43 UTC (rev 22588)
+++ trunk/bibdesk/BibDocument_Groups.h  2018-09-13 12:01:57 UTC (rev 22589)
@@ -39,7 +39,7 @@
 #import "BibDocument.h"
 #import "BDSKGroup.h"
 
-@class BDSKSmartGroup, BDSKStaticGroup, BDSKExternalGroup, BDSKURLGroup, 
BDSKScriptGroup, BDSKWebGroup, BDSKCategoryParentGroup, BDSKFilterController, 
BDSKURLGroupSheetController, BDSKScriptGroupSheetController;
+@class BDSKSmartGroup, BDSKStaticGroup, BDSKCategoryGroup, BDSKExternalGroup, 
BDSKURLGroup, BDSKScriptGroup, BDSKWebGroup, BDSKCategoryParentGroup, 
BDSKFilterController, BDSKURLGroupSheetController, 
BDSKScriptGroupSheetController;
 
 @interface BibDocument (Groups)
 
@@ -57,9 +57,9 @@
 - (BOOL)selectGroup:(BDSKGroup *)aGroup;
 - (BOOL)selectGroups:(NSArray *)theGroups;
 
-- (BOOL)addPublications:(NSArray *)pubs toGroup:(BDSKGroup *)group;
+- (BOOL)addPublications:(NSArray *)pubs toGroup:(BDSKCategoryGroup *)group;
 - (BOOL)removePublications:(NSArray *)pubs fromGroups:(NSArray *)groupArray;
-- (BOOL)movePublications:(NSArray *)pubs fromGroup:(BDSKGroup *)group 
toGroup:(BDSKGroup *)newGroup;
+- (BOOL)movePublications:(NSArray *)pubs fromGroup:(BDSKCategoryGroup *)group 
toGroup:(BDSKCategoryGroup *)newGroup;
 
 - (IBAction)toggleGroupFieldAction:(id)sender;
 - (IBAction)changeGroupFieldAction:(id)sender;

Modified: trunk/bibdesk/BibDocument_Groups.m
===================================================================
--- trunk/bibdesk/BibDocument_Groups.m  2018-09-13 06:30:43 UTC (rev 22588)
+++ trunk/bibdesk/BibDocument_Groups.m  2018-09-13 12:01:57 UTC (rev 22589)
@@ -1256,15 +1256,7 @@
     return newPubs;
 }
 
-- (BOOL)addPublications:(NSArray *)pubs toGroup:(BDSKGroup *)group{
-    BDSKPRECONDITION(([group groupType] & (BDSKStaticGroupType | 
BDSKCategoryGroupType)) != 0);
-    
-    if ([group groupType] == BDSKStaticGroupType) {
-        [(BDSKStaticGroup *)group addPublicationsFromArray:pubs];
-               [[self undoManager] setActionName:NSLocalizedString(@"Add To 
Group", @"Undo action name")];
-        return YES;
-    }
-    
+- (BOOL)addPublications:(NSArray *)pubs toGroup:(BDSKCategoryGroup *)group{
     NSMutableArray *changedPubs = [NSMutableArray arrayWithCapacity:[pubs 
count]];
     NSMutableArray *oldValues = [NSMutableArray arrayWithCapacity:[pubs 
count]];
     NSMutableArray *newValues = [NSMutableArray arrayWithCapacity:[pubs 
count]];
@@ -1324,8 +1316,8 @@
        BDSKFieldAction handleInherited = BDSKFieldActionAsk;
        NSString *groupName = nil;
     
-    for (BDSKGroup *group in groupArray){
-               if(([group groupType] & (BDSKCategoryGroupType | 
BDSKStaticGroupType)) == 0)
+    for (BDSKCategoryGroup *group in groupArray){
+               if(([group groupType] & BDSKCategoryGroupType) == 0)
                        continue;
                
                if (groupName == nil)
@@ -1333,18 +1325,11 @@
                else
                        groupName = NSLocalizedString(@"selected groups", 
@"Partial status message");
                
-        if ([group groupType] == BDSKStaticGroupType) {
-            [(BDSKStaticGroup *)group removePublicationsInArray:pubs];
-            [[self undoManager] setActionName:NSLocalizedString(@"Remove From 
Group", @"Undo action name")];
-            count = [pubs count];
-            continue;
-        }
-        
         NSMutableArray *changedPubs = [NSMutableArray arrayWithCapacity:[pubs 
count]];
         NSMutableArray *oldValues = [NSMutableArray arrayWithCapacity:[pubs 
count]];
         NSMutableArray *newValues = [NSMutableArray arrayWithCapacity:[pubs 
count]];
         NSString *oldValue = nil;
-        NSString *field = [(BDSKCategoryGroup *)group key];
+        NSString *field = [group key];
                BDSKFieldAction rv;
         NSInteger tmpCount = 0;
                
@@ -1403,19 +1388,15 @@
     return YES;
 }
 
-- (BOOL)movePublications:(NSArray *)pubs fromGroup:(BDSKGroup *)group 
toGroup:(BDSKGroup *)newGroup{
+- (BOOL)movePublications:(NSArray *)pubs fromGroup:(BDSKCategoryGroup *)group 
toGroup:(BDSKCategoryGroup *)newGroup{
        NSInteger count = 0;
        BDSKFieldAction handleInherited = BDSKFieldActionAsk;
        BDSKFieldAction rv;
-       
-       if([group groupType] != BDSKCategoryGroupType)
-               return NO;
-    
     NSMutableArray *changedPubs = [NSMutableArray arrayWithCapacity:[pubs 
count]];
     NSMutableArray *oldValues = [NSMutableArray arrayWithCapacity:[pubs 
count]];
     NSMutableArray *newValues = [NSMutableArray arrayWithCapacity:[pubs 
count]];
     NSString *oldValue = nil;
-    NSString *field = [(BDSKCategoryGroup *)group key];
+    NSString *field = [group key];
        
        for (BibItem *pub in pubs){
                BDSKASSERT([pub isKindOfClass:[BibItem class]]);        

Modified: trunk/bibdesk/BibItem.h
===================================================================
--- trunk/bibdesk/BibItem.h     2018-09-13 06:30:43 UTC (rev 22588)
+++ trunk/bibdesk/BibItem.h     2018-09-13 12:01:57 UTC (rev 22589)
@@ -78,7 +78,7 @@
     BDSKFieldActionAsk = 3
 };
 
-@class BibDocument, BDSKGroup, BibAuthor, BDSKFieldCollection, BDSKTemplate, 
BDSKPublicationsArray, BDSKMacroResolver;
+@class BibDocument, BDSKCategoryGroup, BibAuthor, BDSKFieldCollection, 
BDSKTemplate, BDSKPublicationsArray, BDSKMacroResolver;
 @protocol BDSKParseableItem, BDSKOwner;
 
 /*!
@@ -830,9 +830,9 @@
 
 - (NSSet *)groupsForField:(NSString *)field;
 - (BOOL)isContainedInGroupNamed:(id)group forField:(NSString *)field;
-- (BDSKFieldAction)addToGroup:(BDSKGroup *)group 
handleInherited:(BDSKFieldAction)operation;
-- (BDSKFieldAction)removeFromGroup:(BDSKGroup *)group 
handleInherited:(BDSKFieldAction)operation;
-- (NSInteger)replaceGroup:(BDSKGroup *)group withGroup:(BDSKGroup *)aNewGroup 
handleInherited:(NSInteger)operation;
+- (BDSKFieldAction)addToGroup:(BDSKCategoryGroup *)group 
handleInherited:(BDSKFieldAction)operation;
+- (BDSKFieldAction)removeFromGroup:(BDSKCategoryGroup *)group 
handleInherited:(BDSKFieldAction)operation;
+- (NSInteger)replaceGroup:(BDSKCategoryGroup *)group 
withGroup:(BDSKCategoryGroup *)newGroup handleInherited:(NSInteger)operation;
 - (void)invalidateGroupNames;
 
 - (BOOL)isImported;

Modified: trunk/bibdesk/BibItem.m
===================================================================
--- trunk/bibdesk/BibItem.m     2018-09-13 06:30:43 UTC (rev 22588)
+++ trunk/bibdesk/BibItem.m     2018-09-13 12:01:57 UTC (rev 22589)
@@ -3079,9 +3079,8 @@
        return [[self groupsForField:field] containsObject:name];
 }
 
-- (BDSKFieldAction)addToGroup:(BDSKGroup *)aGroup 
handleInherited:(BDSKFieldAction)operation{
-       BDSKASSERT([aGroup groupType] == BDSKCategoryGroupType && [owner 
isDocument]);
-    BDSKCategoryGroup *group = (BDSKCategoryGroup *)aGroup;
+- (BDSKFieldAction)addToGroup:(BDSKCategoryGroup *)group 
handleInherited:(BDSKFieldAction)operation{
+       BDSKASSERT([owner isDocument]);
     
     // don't add it twice; this is typed as id because it may be a BibAuthor 
or NSString, so be careful
        id groupName = [group name];
@@ -3137,9 +3136,8 @@
        return operation;
 }
 
-- (BDSKFieldAction)removeFromGroup:(BDSKGroup *)aGroup 
handleInherited:(BDSKFieldAction)operation{
-       BDSKASSERT([aGroup groupType] == BDSKCategoryGroupType && [owner 
isDocument]);
-    BDSKCategoryGroup *group = (BDSKCategoryGroup *)aGroup;
+- (BDSKFieldAction)removeFromGroup:(BDSKCategoryGroup *)group 
handleInherited:(BDSKFieldAction)operation{
+       BDSKASSERT([owner isDocument]);
        id groupName = [group name];
        NSString *field = [group key];
        BDSKASSERT(field != nil && [field isEqualToString:BDSKPubTypeString] == 
NO);
@@ -3273,10 +3271,8 @@
        return operation;
 }
 
-- (NSInteger)replaceGroup:(BDSKGroup *)aGroup withGroup:(BDSKGroup *)aNewGroup 
handleInherited:(NSInteger)operation{
-       BDSKASSERT([aGroup groupType] == BDSKCategoryGroupType && [aNewGroup 
groupType] == BDSKCategoryGroupType && [owner isDocument]);
-    BDSKCategoryGroup *group = (BDSKCategoryGroup *)aGroup;
-    BDSKCategoryGroup *newGroup = (BDSKCategoryGroup *)aNewGroup;
+- (NSInteger)replaceGroup:(BDSKCategoryGroup *)group 
withGroup:(BDSKCategoryGroup *)newGroup handleInherited:(NSInteger)operation{
+       BDSKASSERT([owner isDocument]);
     id groupName = [group name];
     id newGroupName = [newGroup name];
        NSString *field = [group key];

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to