Adium

Changeset 13422

Show
Ignore:
Timestamp:
09/11/2005 10:20:05 PM (3 years ago)
Author:
evands
Message:

Merged [13408]: Fixed problems in the Add Contact window when no groups exist. Added a New Group... item to the Groups popup menu.
Fixes #1551. Closes #1552.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/adium-0.8/Source/AdiumChatEvents.m

    r13406 r13422  
    1111#import <Adium/AIListContact.h> 
    1212#import <Adium/AIListObject.h> 
    13 #import <AIUtilities/AIImageAdditions.h> 
     13#import <AIUtilities/ESImageAdditions.h> 
    1414 
    1515@implementation AdiumChatEvents 
  • branches/adium-0.8/Source/AIContactController.h

    r13113 r13422  
    120120- (AIListContact *)existingContactWithService:(AIService *)inService account:(AIAccount *)inAccount UID:(NSString *)inUID; 
    121121- (AIListGroup *)groupWithUID:(NSString *)groupUID; 
     122- (AIListGroup *)existingGroupWithUID:(NSString *)groupUID; 
    122123- (NSMutableArray *)allContactsInGroup:(AIListGroup *)inGroup subgroups:(BOOL)subGroups onAccount:(AIAccount *)inAccount; 
    123124- (NSMenu *)menuOfAllContactsInContainingObject:(AIListObject<AIContainingObject> *)inGroup withTarget:(id)target; 
  • branches/adium-0.8/Source/AIContactController.m

    r13223 r13422  
    20342034        } else { 
    20352035                if(!(group = [groupDict objectForKey:groupUID])) { 
    2036                         //NSArray               *groupNest = [groupUID componentsSeparatedByString:@":"]; 
    2037                         //NSString      *groupName = [groupNest lastObject]; 
    2038                         //AIListGroup *targetGroup; 
    2039  
    20402036                        //Create 
    20412037                        group = [[AIListGroup alloc] initWithUID:groupUID]; 
    2042                         //[group setStatusObject:groupName forKey:@"FormattedUID" notify:YES]; 
    20432038 
    20442039                        //Place new groups at the bottom of our list (by giving them the largest ordering index) 
    2045 //                      largestOrder += 1.0; 
    2046 //                      [group setOrderIndex:largestOrder]; 
    20472040                        float orderIndex = [group orderIndex]; 
    20482041                        if (orderIndex > nextOrderIndex) nextOrderIndex = orderIndex + 1; 
    20492042 
    2050                         //add 
     2043                        //Add 
    20512044                        [self _updateAllAttributesOfObject:group]; 
    20522045                        [groupDict setObject:group forKey:groupUID]; 
    20532046 
    20542047                        //Add to target group 
    2055                         //if([groupNest count] == 1) { 
    2056                         //     targetGroup = contactList
    2057                         //} else { 
    2058                         //     targetGroup = [self groupWithUID:[groupUID substringToIndex:[groupUID length] - ([groupName length] + 1)]]; 
    2059                         //} 
    2060                         [/*targetGroup*/contactList addObject:group]; 
    2061                         [self _listChangedGroup:/*targetGroup*/contactList object:group]; 
     2048                        [contactList addObject:group]; 
     2049                        [self _listChangedGroup:contactList object:group]
     2050                         
     2051                        //Add to the contact list 
     2052                        [contactList addObject:group]; 
     2053                        [self _listChangedGroup:contactList object:group]; 
     2054 
    20622055                        [group release]; 
    20632056                } 
     
    20652058 
    20662059        return(group); 
     2060} 
     2061 
     2062- (AIListGroup *)existingGroupWithUID:(NSString *)groupUID 
     2063{ 
     2064        AIListGroup             *group; 
     2065 
     2066        if (!groupUID || ![groupUID length] || [groupUID isEqualToString:ADIUM_ROOT_GROUP_NAME]) { 
     2067                //Return our root group if it is requested 
     2068                group = contactList; 
     2069        } else { 
     2070                group = [groupDict objectForKey:groupUID]; 
     2071        } 
     2072         
     2073        return group; 
    20672074} 
    20682075 
  • branches/adium-0.8/Source/AIContentController.h

    r13406 r13422  
    2525@protocol AITextEntryView, AIEventHandler; 
    2626 
    27 @class AIAccount, AIChat, AIListContact, AIListObject, AIContentObject, AdiumContentFiltering
     27@class AIAccount, AIChat, AIListContact, AIListObject, AIContentObject, AdiumContentFiltering, AdiumChatEvents
    2828 
    2929typedef enum { 
     
    9090         
    9191        AdiumContentFiltering   *adiumContentFiltering; 
     92        AdiumChatEvents                 *adiumChatEvents; 
    9293 
    9394    NSMutableSet                        *openChats; 
  • branches/adium-0.8/Source/AINewContactWindowController.m

    r10866 r13422  
    1818#import "AIContactController.h" 
    1919#import "AINewContactWindowController.h" 
     20#import "AINewGroupWindowController.h" 
     21#import <AIUtilities/AIMenuAdditions.h> 
    2022#import <AIUtilities/AIPopUpButtonAdditions.h> 
     23#import <AIUtilities/AIStringAdditions.h> 
    2124#import <Adium/AIAccount.h> 
    2225#import <Adium/AIListContact.h> 
     
    2629 
    2730#define ADD_CONTACT_PROMPT_NIB  @"AddContact" 
     31#define DEFAULT_GROUP_NAME              AILocalizedString(@"Contacts",nil) 
    2832 
    2933@interface AINewContactWindowController (PRIVATE) 
     
    180184                        [[popUp_targetGroup selectedItem] representedObject] :  
    181185                        nil); 
    182          
     186 
     187        if (!group) group = [[adium contactController] groupWithUID:DEFAULT_GROUP_NAME]; 
     188 
    183189        while(account = [enumerator nextObject]){ 
    184190                if([account contactListEditable] && 
     
    299305{ 
    300306        AIListObject    *selectedObject; 
    301         AIListGroup             *group; 
    302          
     307        NSMenu                  *menu; 
    303308        //Rebuild the menu 
    304         [popUp_targetGroup setMenu:[[adium contactController] menuOfAllGroupsInGroup:nil withTarget:self]]; 
    305  
     309        menu = [[adium contactController] menuOfAllGroupsInGroup:nil withTarget:self]; 
     310         
     311        //Add a default group name to the menu if there are no groups listed 
     312        if ([menu numberOfItems] == 0) { 
     313                [menu addItemWithTitle:DEFAULT_GROUP_NAME 
     314                                                target:self 
     315                                                action:@selector(selectGroup:) 
     316                                 keyEquivalent:@""]; 
     317        } 
     318         
     319        [menu addItem:[NSMenuItem separatorItem]]; 
     320        [menu addItemWithTitle:[AILocalizedString(@"New Group",nil) stringByAppendingEllipsis] 
     321                                        target:self 
     322                                        action:@selector(newGroup:) 
     323                         keyEquivalent:@""]; 
     324         
    306325        //Select the group of the currently selected object on the contact list 
    307326        selectedObject = [[adium contactController] selectedListObject]; 
    308  
    309         if(selectedObject != nil) { 
    310                 //Find the first containing object which is an AIListGroup, starting with the selected object itself 
    311                 group = (AIListGroup*)selectedObject; 
    312                 while (group && ![group isKindOfClass:[AIListGroup class]]){ 
    313                         group = (AIListGroup*)[group containingObject]; 
    314                 } 
    315                  
    316                 if(group){ 
    317                         [popUp_targetGroup selectItemWithRepresentedObject:group];                       
    318                 }else if([popUp_targetGroup numberOfItems] > 0){ 
    319                         [popUp_targetGroup selectItemAtIndex:0]; 
    320                 } 
    321                  
    322         } 
     327        while (selectedObject && ![selectedObject isKindOfClass:[AIListGroup class]]) { 
     328                selectedObject = [selectedObject containingObject]; 
     329        } 
     330         
     331        [popUp_targetGroup setMenu:menu]; 
     332         
     333        //If there was no selected group, just select the first item 
     334        if (selectedObject) { 
     335                if (![popUp_targetGroup selectItemWithRepresentedObject:selectedObject]) { 
     336                        [popUp_targetGroup selectItemAtIndex:0];                         
     337                } 
     338                 
     339        } else { 
     340                [popUp_targetGroup selectItemAtIndex:0]; 
     341        } 
     342
     343 
     344/* 
     345 * @brief Prompt the user to add a new group immediately 
     346 */ 
     347- (void)newGroup:(id)sender 
     348
     349        AINewGroupWindowController      *newGroupWindowController; 
     350         
     351        newGroupWindowController = [AINewGroupWindowController promptForNewGroupOnWindow:[self window]]; 
     352         
     353        //Observe for the New Group window to close 
     354        [[adium notificationCenter] addObserver:self 
     355                                                                   selector:@selector(newGroupDidEnd:)  
     356                                                                           name:@"NewGroupWindowControllerDidEnd" 
     357                                                                         object:[newGroupWindowController window]];      
     358
     359 
     360- (void)newGroupDidEnd:(NSNotification *)inNotification 
     361
     362        NSWindow        *window = [inNotification object]; 
     363         
     364        if ([[window windowController] isKindOfClass:[AINewGroupWindowController class]]) { 
     365                NSString        *newGroupUID = [[window windowController] newGroupUID]; 
     366                AIListGroup *group = [[adium contactController] existingGroupWithUID:newGroupUID]; 
     367                 
     368                //Rebuild the group menu 
     369                [self buildGroupMenu]; 
     370                 
     371                /* Select the new group if it exists; otherwise select the first group (so we don't still have New Group... selected). 
     372                        * If the user canceled, group will be nil since the group doesn't exist. 
     373                        */ 
     374                if (![popUp_targetGroup selectItemWithRepresentedObject:group]) { 
     375                        [popUp_targetGroup selectItemAtIndex:0];                         
     376                } 
     377                 
     378                [[self window] performSelector:@selector(makeKeyAndOrderFront:) 
     379                                                        withObject:self 
     380                                                        afterDelay:0]; 
     381        } 
     382         
     383        //Stop observing 
     384        [[adium notificationCenter] removeObserver:self 
     385                                                                                  name:@"NewGroupWindowControllerDidEnd"  
     386                                                                                object:window]; 
    323387} 
    324388 
  • branches/adium-0.8/Source/AINewGroupWindowController.h

    r9675 r13422  
    2727} 
    2828 
    29 + (void)promptForNewGroupOnWindow:(NSWindow *)parentWindow; 
     29+ (AINewGroupWindowController *)promptForNewGroupOnWindow:(NSWindow *)parentWindow; 
     30- (NSString *)newGroupUID; 
    3031- (IBAction)cancel:(id)sender; 
    3132- (IBAction)addGroup:(id)sender; 
  • branches/adium-0.8/Source/AINewGroupWindowController.m

    r10862 r13422  
    3131 * @param parentWindow Window on which to show as a sheet. Pass nil for a panel prompt. 
    3232 */ 
    33 + (void)promptForNewGroupOnWindow:(NSWindow *)parentWindow 
     33+ (AINewGroupWindowController *)promptForNewGroupOnWindow:(NSWindow *)parentWindow 
    3434{ 
    35         AINewGroupWindowController      *newGroupWindow
     35        AINewGroupWindowController      *newGroupWindowController
    3636         
    37         newGroupWindow = [[self alloc] initWithWindowNibName:ADD_GROUP_PROMPT_NIB]; 
     37        newGroupWindowController = [[self alloc] initWithWindowNibName:ADD_GROUP_PROMPT_NIB]; 
    3838         
    3939        if(parentWindow){ 
    40                 [NSApp beginSheet:[newGroupWindow window] 
     40                [NSApp beginSheet:[newGroupWindowController window] 
    4141                   modalForWindow:parentWindow 
    42                         modalDelegate:newGroupWindow 
     42                        modalDelegate:newGroupWindowController 
    4343                   didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) 
    4444                          contextInfo:nil]; 
    4545        }else{ 
    46                 [newGroupWindow showWindow:nil]; 
     46                [newGroupWindowController showWindow:nil]; 
    4747        } 
    4848         
     49        return newGroupWindowController; 
    4950} 
    5051 
     
    6970- (void)sheetDidEnd:(NSWindow *)sheet returnCode:(int)returnCode contextInfo:(void *)contextInfo 
    7071{ 
     72        [[adium notificationCenter] postNotificationName:@"NewGroupWindowControllerDidEnd" 
     73                                                                                          object:sheet]; 
    7174    [sheet orderOut:nil]; 
    7275} 
     
    8487} 
    8588 
     89/* 
     90 * @brief UID of the new group 
     91 */ 
     92- (NSString *)newGroupUID 
     93{ 
     94        return [[[textField_groupName stringValue] copy] autorelease]; 
     95} 
     96 
    8697/*! 
    8798 * @brief Add the group 
     
    89100- (IBAction)addGroup:(id)sender 
    90101{ 
    91         [[adium contactController] groupWithUID:[textField_groupName stringValue]]; 
     102        AIListGroup *group = [[adium contactController] groupWithUID:[self newGroupUID]]; 
    92103         
    93104        if([[self window] isSheet]){