// // IconViewController.m // Perforce // // Created by Adam Czubernat on 05.06.2013. // Copyright (c) 2013 Perforce Software, Inc. All rights reserved. // #import "IconViewController.h" #import "PSCollectionView.h" #import "PSCustomScrollView.h" #import "VersionsViewController.h" #import "HistoryViewController.h" @interface IconViewController () <P4ItemDelegate, QLPreviewPanelDataSource, QLPreviewPanelDelegate, NSMenuDelegate, NSPopoverDelegate> { __weak IBOutlet PSCollectionView *collectionView; IBOutlet NSView *loadingOverlay; __weak IBOutlet NSProgressIndicator *loadingOverlayIndicator; NSMutableArray *items; NSOperationQueue *thumbnailsQueue; BOOL isLoading; NSPopover *popover; // QuickLook QLPreviewPanel *quickLookPanel; NSArray *quickLookItems; NSImage *quickLookIconImage; } - (void)setItems:(NSArray *)items; - (void)loadThumbnails; - (void)showLoadingOverlay; @end @implementation IconViewController - (void)loadView { [super loadView]; [collectionView setFocusRingType:NSFocusRingTypeNone]; [collectionView registerForDraggedTypes:@[ NSFilenamesPboardType, P4PasteboardTypeFile ]]; [self setItems:items]; // Watch selection [collectionView addObserver:self forKeyPath:@"selectionIndexes" options:NSKeyValueObservingOptionNew | NSKeyValueObservingOptionInitial context:NULL]; } - (void)dealloc { [thumbnailsQueue cancelAllOperations]; [collectionView removeObserver:self forKeyPath:@"selectionIndexes"]; } - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context { NSArray *selection = [self selectedItems]; // Quicklook if (!quickLookPanel && [QLPreviewPanel sharedPreviewPanelExists]) [[QLPreviewPanel sharedPreviewPanel] updateController]; if (quickLookPanel) { quickLookItems = selection; [quickLookPanel reloadData]; } [super selectionChanged:selection]; } #pragma mark - Private - (void)setItems:(NSArray *)array { items = [array mutableCopy]; [collectionView setContent:items]; [self refresh]; [self loadThumbnails]; } - (void)loadThumbnails { [thumbnailsQueue cancelAllOperations]; thumbnailsQueue = [[NSOperationQueue alloc] init]; thumbnailsQueue.maxConcurrentOperationCount = 3; [items enumerateObjectsUsingBlock:^(P4Item *item, NSUInteger idx, BOOL *stop) { __weak NSCollectionViewItem *itemView = [collectionView itemAtIndex:idx]; // Thumbnail operation NSBlockOperation *op = [[NSBlockOperation alloc] init]; __weak NSOperation *weakOp = op; [op addExecutionBlock:^{ NSImage *image = [item previewWithSize:(NSSize) { 192.0, 160.0 }]; if ([weakOp isCancelled]) return ; [itemView performSelectorOnMainThread:@selector(setImage:) withObject:image waitUntilDone:NO]; }]; [thumbnailsQueue addOperation:op]; }]; } - (void)showLoadingOverlay { [loadingOverlay setFrame:self.view.bounds]; [self.view addSubview:loadingOverlay]; [loadingOverlayIndicator startAnimation:nil]; } #pragma mark - NSCollectionView delegate - (BOOL)collectionView:(NSCollectionView *)aCollectionView writeItemsAtIndexes:(NSIndexSet *)indexes toPasteboard:(NSPasteboard *)pasteboard { NSArray *draggedItems = [items objectsAtIndexes:indexes]; return [self writeItems:draggedItems toPasteboard:pasteboard]; } - (NSArray *)collectionView:(NSCollectionView *)collectionView namesOfPromisedFilesDroppedAtDestination:(NSURL *)dropURL forDraggedItemsAtIndexes:(NSIndexSet *)indexes { NSArray *draggedItems = [items objectsAtIndexes:indexes]; return [self namesOfPromisedItems:draggedItems droppedAtDestination:dropURL]; } - (NSImage *)collectionView:(NSCollectionView *)aCollectionView draggingImageForItemsAtIndexes:(NSIndexSet *)indexes withEvent:(NSEvent *)event offset:(NSPointPointer)dragImageOffset { NSImage *result = [collectionView draggingImageForItemsAtIndexes:indexes withEvent:event offset:dragImageOffset]; [result lockFocus]; if (indexes.count > 1) { NSPoint mouse = (CGPoint) { result.size.width * 0.5f - dragImageOffset->x, result.size.height * 0.5f - dragImageOffset->y, }; NSShadow *shadow = [[NSShadow alloc] init]; [shadow setShadowOffset:NSMakeSize(0.5, 0.5)]; [shadow setShadowBlurRadius:5.0]; [shadow setShadowColor:[NSColor blackColor]]; NSDictionary *attrs = @{ NSShadowAttributeName : shadow, NSForegroundColorAttributeName : [NSColor whiteColor], }; NSInteger cornerSize = 10.0f; NSGradient *gradient = [[NSGradient alloc] initWithStartingColor:[NSColor colorWithHexString:@"#FCC"] endingColor:[NSColor redColor]]; NSBezierPath *bezier = [NSBezierPath bezierPathWithRoundedRect:(CGRect) { mouse, {20.0f, 20.0f} } xRadius:cornerSize yRadius:cornerSize]; [gradient drawInBezierPath:bezier angle:90.0f]; BOOL copy = ([NSApp currentEvent].modifierFlags & NSAlternateKeyMask) != 0; NSString *str = [NSString stringWithFormat:@"%@%ld", copy ? @"+": @"", indexes.count]; NSAttributedString *attrStr = [[NSAttributedString alloc] initWithString:str attributes:attrs]; [attrStr drawAtPoint:(CGPoint) { mouse.x + (20.0f - attrStr.size.width) * 0.5f, mouse.y + (20.0f - attrStr.size.height) * 0.5f + 1, }]; [result unlockFocus]; } return result; } - (NSDragOperation)collectionView:(NSCollectionView *)aCollectionView validateDrop:(id<NSDraggingInfo>)draggingInfo proposedIndex:(NSInteger *)proposedDropIndex dropOperation:(NSCollectionViewDropOperation *)proposedDropOperation { // PSLog(@"dropindex %ld operation %d", (long)*proposedDropIndex, (int)*proposedDropOperation); NSDragOperation operation = NSDragOperationEvery; // Check if option key is pressed if ([[NSApp currentEvent] modifierFlags] & NSAlternateKeyMask) operation = NSDragOperationCopy; // Accept only file types if ([[[draggingInfo draggingPasteboard] types] indexOfObject:NSFilenamesPboardType] == -1) return NSDragOperationNone; if (*proposedDropIndex == -1) return NSDragOperationNone; if (*proposedDropOperation == NSCollectionViewDropBefore) { *proposedDropIndex = 0; return operation; } P4Item *target = [items objectAtIndex:*proposedDropIndex]; if (!target.isDirectory || !target.isEditable) { // Can't drop onto a file. Retarget to the column *proposedDropIndex = 0; *proposedDropOperation = NSCollectionViewDropBefore; if (!workingItem.isEditable) return NSDragOperationNone; } return operation; } - (BOOL)collectionView:(NSCollectionView *)aCollectionView acceptDrop:(id<NSDraggingInfo>)draggingInfo index:(NSInteger)index dropOperation:(NSCollectionViewDropOperation)dropOperation { // Find the target folder P4Item *target = nil; if (dropOperation == NSCollectionViewDropBefore) target = workingItem; else target = [items objectAtIndex:index]; return [self acceptDrop:draggingInfo target:target]; } #pragma mark NSResponder - (void)cancelOperation:(id)sender { NSIndexSet *indexes = [collectionView selectionIndexes]; if ([indexes count] != 1) return; NSInteger index = [indexes lastIndex]; IconViewItem *viewItem = (IconViewItem *)[collectionView itemAtIndex:index]; [viewItem abortEditing]; [self.view.window makeFirstResponder:collectionView]; } - (void)insertNewline:(id)sender { NSIndexSet *indexes = [collectionView selectionIndexes]; if ([indexes count] != 1) return; NSInteger index = [indexes lastIndex]; IconViewItem *viewItem = (IconViewItem *)[collectionView itemAtIndex:index]; P4Item *item = viewItem.representedObject; if (!item.isEditable) return; [viewItem beginEditing]; } #pragma mark - BrowserViewController Overrides - (NSArray *)selectedItems { NSMutableIndexSet *indexes = [[collectionView selectionIndexes] mutableCopy]; // Clip indexes beyond childrens array [indexes removeIndexesInRange:(NSRange) { items.count, NSIntegerMax }]; if (!indexes.count) return nil; return [items objectsAtIndexes:indexes]; } - (void)setWorkingItem:(P4Item *)item { [super setWorkingItem:item]; [collectionView setSelectionIndexes:nil]; [self setItems:workingItem.children]; } - (void)setSelectedIndexes:(NSIndexSet *)indexes { [collectionView setSelectionIndexes:indexes]; [collectionView scrollRectToVisible:[collectionView frameForItemAtIndex:indexes.firstIndex]]; } - (void)refresh { [items enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) { [[collectionView itemAtIndex:idx] setRepresentedObject:obj]; }]; } - (void)willLoadPath:(NSString *)path { isLoading = YES; [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(showLoadingOverlay) object:nil]; [self performSelector:@selector(showLoadingOverlay) withObject:nil afterDelay:0.25f]; } - (void)showVersions:(P4Item *)item { NSInteger idx = [[collectionView selectionIndexes] firstIndex]; IconViewItem *iconItem = (IconViewItem *)[collectionView itemAtIndex:idx]; VersionsViewController *controller = [[VersionsViewController alloc] initWithItem:item actionDelegate:[self.view.window windowController]]; popover = [[NSPopover alloc] init]; [popover setBehavior:NSPopoverBehaviorTransient]; [popover setContentViewController:controller]; [popover showRelativeToRect:[iconItem.view frame] ofView:[iconItem.view superview] preferredEdge:NSMaxXEdge]; popover.delegate = self; [(PSCustomScrollView *)self.view setScrollDisabled:YES]; // [popover setBehavior:NSPopoverBehaviorApplicationDefined]; // NSWindow *popoverWindow = popover.contentViewController.view.window; // [NSApp runModalForWindow:popoverWindow]; } - (void)showFolderHistory:(P4Item *)item { NSInteger idx = [[collectionView selectionIndexes] firstIndex]; IconViewItem *iconItem = (IconViewItem *)[collectionView itemAtIndex:idx]; HistoryViewController *controller = [[HistoryViewController alloc] initWithDirectoryItem:item actionDelegate:[self.view.window windowController]]; popover = [[NSPopover alloc] init]; [popover setBehavior:NSPopoverBehaviorTransient]; [popover setContentViewController:controller]; [popover showRelativeToRect:[iconItem.view frame] ofView:[iconItem.view superview] preferredEdge:NSMaxXEdge]; popover.delegate = self; [(PSCustomScrollView *)self.view setScrollDisabled:YES]; // [popover setBehavior:NSPopoverBehaviorApplicationDefined]; // NSWindow *popoverWindow = popover.contentViewController.view.window; // [NSApp runModalForWindow:popoverWindow]; } - (void)editItemName:(P4Item*)directoryItem { NSInteger index = [items indexOfObjectIdenticalTo:directoryItem]; if (index == NSNotFound) return; [collectionView scrollRectToVisible:[collectionView frameForItemAtIndex:index]]; IconViewItem *viewItem = (IconViewItem *)[collectionView itemAtIndex:index]; P4Item *item = viewItem.representedObject; if (!item.isEditable) return; [viewItem beginEditing]; } - (void)setBackgroundColor:(NSColor *)color { #warning TODO } - (void)setDraggingSourceOperationMask:(NSDragOperation)mask forLocal:(BOOL)isLocal { [collectionView setDraggingSourceOperationMask:mask forLocal:isLocal]; } #pragma mark - NSPopoverDelegate - (void)popoverDidClose:(NSNotification *)notification { [(PSCustomScrollView *)self.view setScrollDisabled:NO]; } #pragma mark - IconViewItemDelegate - (void)iconViewItemSelected:(IconViewItem *)iconItem { } - (void)iconViewItemOpened:(IconViewItem *)iconItem { P4Item *item = iconItem.representedObject; if ([item isDirectory]) { [self setWorkingItem:item]; } else { // Perform default item action P4ItemAction *action = [item defaultAction]; action.delegate = [self.view.window windowController]; [action performAction]; } } - (void)iconViewItemDidEndEditing:(IconViewItem *)iconViewItem { [self renameItem:iconViewItem.representedObject name:iconViewItem.title]; } #pragma mark - P4Item delegate - (void)itemDidLoad:(P4Item *)item { [super itemDidLoad:item]; if (isLoading) { isLoading = NO; [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(showLoadingOverlay) object:nil]; [loadingOverlay removeFromSuperview]; } else { if (item == workingItem) { // Did load children [self setItems:item.children]; } else if (item.parent == workingItem) { NSInteger idx = [items indexOfObjectIdenticalTo:item]; if (idx != NSNotFound) [[collectionView itemAtIndex:idx] setRepresentedObject:item]; } } } - (void)itemDidInvalidate:(P4Item *)item { } - (void)item:(id)item didFailWithError:(NSError *)error { [self failWithError:error]; [self itemDidLoad:item]; PSLog(@"IconView error: %@", error.localizedDescription); } #pragma mark - Quicklook Panel delegate - (BOOL)acceptsPreviewPanelControl:(QLPreviewPanel *)panel { return YES; } - (void)beginPreviewPanelControl:(QLPreviewPanel *)panel { quickLookPanel = panel; panel.delegate = self; panel.dataSource = self; } - (void)endPreviewPanelControl:(QLPreviewPanel *)panel { quickLookPanel = nil; } - (BOOL)previewPanel:(QLPreviewPanel *)panel handleEvent:(NSEvent *)event { // Redirect all key down events to the browser if ([event type] == NSKeyDown) { [collectionView keyDown:event]; return YES; } return NO; } - (NSInteger)numberOfPreviewItemsInPreviewPanel:(QLPreviewPanel *)panel { quickLookItems = [self selectedItems]; return quickLookItems.count; } - (id <QLPreviewItem>)previewPanel:(QLPreviewPanel *)panel previewItemAtIndex:(NSInteger)index { return [quickLookItems objectAtIndex:index]; } - (NSRect)previewPanel:(QLPreviewPanel *)panel sourceFrameOnScreenForPreviewItem:(id <QLPreviewItem>)item { NSIndexSet *indexes = [collectionView selectionIndexes]; if (!indexes.count) return CGRectZero; IconViewItem *iconItem = (id)[collectionView itemAtIndex:indexes.firstIndex]; quickLookIconImage = iconItem.iconView.image; // Get image frame CGRect imageRect = iconItem.iconView.frame; imageRect.origin = iconItem.iconView.superview.frame.origin; CGRect itemRect = [collectionView frameForItemAtIndex:indexes.firstIndex]; imageRect.origin.x += itemRect.origin.x; imageRect.origin.y += itemRect.origin.y; // Check that the icon rect is visible on screen CGRect visibleRect = [collectionView visibleRect]; if (!NSIntersectsRect(visibleRect, imageRect)) return CGRectZero; // Convert icon rect to screen coordinates imageRect = [collectionView convertRect:imageRect toView:nil]; imageRect = [collectionView.window convertRectToScreen:imageRect]; return imageRect; } - (id)previewPanel:(QLPreviewPanel *)panel transitionImageForPreviewItem:(id <QLPreviewItem>)item contentRect:(NSRect *)contentRect { return quickLookIconImage; } #pragma mark - Menu delegate - (void)menuNeedsUpdate:(NSMenu *)menu { [menu setAllowsContextMenuPlugIns:NO]; P4Item *item = nil; NSInteger index = [collectionView clickedIndex]; if (index == NSNotFound) { item = workingItem; [collectionView setSelectionIndexes:nil]; } else { NSIndexSet *set = [collectionView selectionIndexes]; if (set.count > 1 && [set containsIndex:index]) { // Multiple [menu setItems:[items objectsAtIndexes:set] delegate:[self.view.window windowController]]; return; } else { [collectionView setSelectionIndexes:[NSIndexSet indexSetWithIndex:index]]; item = [items objectAtIndex:index]; } } [menu setItem:item delegate:[self.view.window windowController]]; } @end
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 15071 | alan_petersen |
Populate -o //guest/perforce_software/piper/... //guest/alan_petersen/piper/.... |
||
//guest/perforce_software/piper/mac/main/Perforce/Classes/ViewControllers/IconView/IconViewController.m | |||||
#2 | 12961 | alan_petersen |
Piper 2.0 Mega Update New Features/Functionality - Added help menu redirecting to URL. - Added readonly property for creating new workspaces. - Added html hyperlinks for Copy link functionality. - Added functionality for managing Finder Favorite items in sidebar. - Redesigned the way mapping is stored in Piper. - First version of syncing finder sidebar items with workspace mapping. - Small sorting improvements. - Creating Projects directory inside users home folder. - Adding Projects folder to finder sidebar item. - Creating and removing symbolic links accordingly to mapped folders. - Preventing duplicate names in symbolic links. - Refreshing symbolic links on mapping change inside application. - Storing workspace and server details in p4 configuration for other applications to use. - Added contextual menu items for Finder integration. - Added services menu for Adobe Illustrator integration. - Keyboard shortcuts for Illustrator integration. - Code refactoring and fixes for mapping issues. - Added Finder functionality to edit all files in folder. - Added user friendly message when editing a file using Finder outside the workspace. - Implemented hidden automatic login when opening application using Finder integration. - Logging to file in ~/Library/Logs - Unified workspace and all files views to show both local and depot files and folders. - Removed my workspace view references and logic. - Editing unmapped files on server. - First version of adding file to unmapped folders. - Showing opened by and edit actions in column details for all depot files. - Improved mappings functionality. - Enabled same feature options for mapped and unmapped folders and files. - Redesigned from scratch mapping and unmapping procedures for adding and removing files. - Implemented cleaning workspace using new mapping functionality. Removed debug overlay coloring. - Automated workspace creation - Improvements in editing files already mapped to workspace. - Implemented deleting remote files. - Implemented first version of move operation for remote files. - Removing last workspace information when disconnecting from workspace using app menu. - Implemented editing and submitting using symbolic links in project folder. New finder menu service for symbolic links Show in Piper which acts like share link functionality. - New icons for files and folders not tracked in the filesystem. - Improvements in showing file using share link. - Switched to new way of retrieving files in order to show user changes. - Redesigned and implemented new functionality for chaining operations with mapping. - Improvements and redesign of Edit/add actions to use new chaining logic . Fixed issue with file edit. - Improvements in window showing when using services. - Simplified file loading so the local files appears only when remote are also loaded. - Improved deleting of untracked files to avoid mapping and marking for delete. - Enabling simple copy paste and moving of remote and local files. - Added abort for exception handling in order to force crashing application on critical failures - Added custom exception handling for catching runtime errors to log and crash instead of continuing in unstable state. - Changed file copying to use mark for add . - Simplified and fixed responding file representations to mapping changes. Bug Fixes - Fixed crash when synchronizing. - Fixed sync issue when downloading directory without file size information. - Fixed issue with unread list crashing when file is not existing on disk. - Fixed incorrect sync progress calculation. - Removed relative path issues. - Fixed many of case-sensitivity problems. - Fixed deprecated methods and related issues in OS X 10.10. - Fixed folder rename not updating in column view. Revised and fixed many potential problems from implicit casting. - Fixed missing sync button on fast sync completion. - Refreshing mapping on synchronization. Fixed symbolic links not appearing until app is restarted. - Fixed latest crashing of autosync. - Fixed loading indicator issues. - Fixed and redesigned submit dialog to work correctly with Submit All Files option in Finder. - Fixed multiple error messages on network outage. Redesigned showing errors in main window. - Fixed opening random locations when using Finder integration. - Fixed issue when panel was detached from parent window. - Fixed bug when creating new workspace wouldn't store default settings. - Fixed memory issues with network operations. - Fixes in relogging mappings and file listing. - Improvements in editing unmapped files. - Fixed crash when adding file outside workspace. - Fixed breadcrumbs control issue. - Fixed issue with double parent folders when opening unmapped files. - Fixed crashes on sync after mapping new files. - Fixed issue with editing file using Finder -- Merging code and additional fixes in add button functionality. - Fixed unsync not working - Fixed submit panel issue not selecting files with different name case. - Fixed missing revert and sync to workspace actions in some cases. - Fixed issue with Submit and Edit finder actions. Improvements in stability of finder integration. - Fixed issue with unsubmitted folders breaking status of files inside. - Fixed issue with added files not showing correct icon and status. - Fixed bug with file edit resulting in a new directory named exactly like a file. - Fixed issue with reloading of subpath resulting in untracked folders. - Fixed mapping issue when result was always view mapping not relative. - Fixed submit panel showing more than once. - Fixed illustrator services not working. - Fixed userdefaults preferences problem with workspace name being null. - Fixed userdefaults keypath problem of dot-containing workspace names. - Forcing recreating of browser to possibly prevent pre-10.10 errors with automatic workspace selection. - Fixed adding file to depot not presenting correct icon. - Fixed issues with reverting a file that was marked for add. - Presenting error when trying to submit untracked files. - Fixed issue when submit files service crashed when using unmapped files. - Fixed file representation disappearing when removing file. - Fixed issue with symlinks resolving working on 10.10 only. Issue related to workspace selection not showing. - Fixed error panel method calls unavailable in Mac OS versions before 10.10. Issue related to hanging error panels. - Fixed removing a local file resulting in action progress freezing. - Fixed open file not working after edit. - Fixing crash when mapping changed. Issue related to moving local file to unmapped folder and other similar cases. |
||
#1 | 11252 | alan_petersen | Rename/move file(s) | ||
//guest/perforce_software/piper/mac/Perforce/Classes/ViewControllers/IconView/IconViewController.m | |||||
#1 | 10744 | alan_petersen | Rename/move file(s) | ||
//guest/perforce_software/piper/Perforce/Classes/ViewControllers/IconView/IconViewController.m | |||||
#1 | 8919 | Matt Attaway | Initial add of Piper, a lightweight Perforce client for artists and designers. |