// // P4UnreadItem.m // Perforce // // Created by Adam Czubernat on 15/11/2013. // Copyright (c) 2013 Perforce Software, Inc. All rights reserved. // #import "P4UnreadItem.h" @interface P4UnreadItem () - (id)initWithDictionary:(NSDictionary *)dictionary parentItem:(P4Item *)parent; @end @implementation P4UnreadItem #pragma mark - P4Item Override - (id)init { self = [super init]; if (self) { flags.directory = YES; name = @"Unread"; localPath = @"unread://"; [[P4Workspace sharedInstance] addObserver:self]; } return self; } - (id)defaultAction { if (!flags.tracked) return nil; if (status) return [P4ItemAction actionForItem:self name:@"Open" selector:@selector(open)]; return [P4ItemAction actionForItem:self name:@"Open and Checkout" selector:@selector(openWithCheckout)]; } - (NSColor *)overlay { if (flags.loading || flags.tracked) return nil; return [NSColor grayColor]; } - (NSArray *)actions { if (flags.directory) return nil; NSMutableArray *actions = (NSMutableArray *)[super actions]; return actions; } - (NSArray *)actionsForItems:(NSArray *)items { NSMutableArray *actions = (NSMutableArray *)[super actionsForItems:items]; [actions addObject:[P4ItemAction actionForItems:items name:@"Mark selected as read" selector:@selector(markItemsAsRead:)]]; return actions; } - (void)loadPath:(NSString *)path { children = nil; flags.loading = YES; [[P4Workspace sharedInstance] listUnreadFiles:nil response:^(P4Operation *operation, NSArray *response) { if (operation.errors) { [self failWithError:operation.error]; return; } // Serialize children from response NSMutableArray *array = [NSMutableArray arrayWithCapacity:512]; for (NSDictionary *childDict in response) { P4UnreadItem *child = [[P4UnreadItem alloc] initWithDictionary:childDict parentItem:self]; [array addObject:child]; } // Sort files alphanumerically children = array; [self sortChildren]; [self finishLoading]; }]; } #pragma mark - Private - (id)initWithDictionary:(NSDictionary *)dictionary parentItem:(P4Item *)parentItem { if (self = [super init]) { P4Workspace *p4 = [P4Workspace sharedInstance]; parent = parentItem; metadata = dictionary; flags.unread = YES; flags.directory = NO; // Only leaves remotePath = [dictionary objectForKey:@"depotFile"]; name = remotePath.lastPathComponent; // Create local path localPath = [dictionary objectForKey:@"clientFile"]; NSString *client = [dictionary objectForKey:@"client"] ?: @""; NSString *clientPrefix = [NSString stringWithFormat:@"//%@/", client]; if ([localPath hasPrefix:clientPrefix]) { localPath = [localPath substringFromIndex:clientPrefix.length]; localPath = [[p4 root] stringByAppendingPath:localPath]; } // Set metadata status = [metadata objectForKey:@"action"]; NSString *user = [metadata objectForKey:@"otherOpen0"]; NSDictionary *info = [p4 userInfo:user]; statusOwner = [info objectForKey:@"Email"] ?: user; flags.tracked = [metadata objectForKey:@"isMapped"] != nil; [self refreshTags]; // Shelved and unread if (remotePath) flags.shelved = [p4 shelvedForPaths:@[ remotePath ]].count > 0; if (localPath) flags.unread = [p4 unreadForPaths:@[ localPath ]].count > 0; } return self; } #pragma mark P4Workspace Events - (void)file:(NSString *)filePath updated:(NSDictionary *)info { if (!self->children) return; // Not loaded P4Item *item = [self cachedItemForPath:filePath]; if (item) return; // Nothing changed // Update children by adding new item P4Item *newItem = [[P4UnreadItem alloc] initWithDictionary:info parentItem:self]; // Add item to parent NSMutableArray *array = [NSMutableArray arrayWithArray:self->children]; [array addObject:newItem]; // Sort files alphanumerically self->children = array; [self sortChildren]; [self finishLoading]; } - (void)file:(NSString *)filePath revertedAction:(NSDictionary *)info { if (!self->children) return; // Not loaded P4Item *item = [self cachedItemForPath:filePath]; if (!item) return; // Nothing changed NSMutableArray *array = [NSMutableArray arrayWithArray:self->children]; [array removeObject:item]; self->children = array; [self finishLoading]; [item invalidate]; } @end
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 16507 | perforce_software | Move to main branch. | ||
//guest/perforce_software/piper/mac/R1.0/Perforce/Classes/Items/P4UnreadItem.m | |||||
#1 | 11254 | alan_petersen |
Populate //guest/perforce_software/piper/mac/R1.0/... from //guest/perforce_software/piper/mac/main/.... |
||
//guest/perforce_software/piper/mac/main/Perforce/Classes/Items/P4UnreadItem.m | |||||
#1 | 11252 | alan_petersen | Rename/move file(s) | ||
//guest/perforce_software/piper/mac/Perforce/Classes/Items/P4UnreadItem.m | |||||
#1 | 10744 | alan_petersen | Rename/move file(s) | ||
//guest/perforce_software/piper/Perforce/Classes/Items/P4UnreadItem.m | |||||
#1 | 8919 | Matt Attaway | Initial add of Piper, a lightweight Perforce client for artists and designers. |