perf: virtualize LUT directory rows as well as thumbnails for large libraries
这个提交包含在:
1 父节点
87baa785fd
当前提交
838037a7e0
4 个文件已更改
+45
-21
没有与搜索条件相匹配的文件
+24
-13
@@ -116,7 +116,7 @@ static NSString *const DYBrowserFolderPreference=@"com.dayu.color.lookLUTPreview
|
||||
NSSlider *_sizeSlider;
|
||||
NSMutableArray *_folderButtons;
|
||||
NSMutableDictionary *_tiles;
|
||||
NSArray *_visibleEntries;
|
||||
NSArray *_visibleEntries,*_folderPaths;
|
||||
NSMutableSet *_queuedPaths;
|
||||
NSCache *_thumbnailCache;
|
||||
dispatch_queue_t _previewQueue;
|
||||
@@ -160,6 +160,8 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
|
||||
_gridScroll=[[NSScrollView alloc]initWithFrame:NSZeroRect];_gridScroll.hasVerticalScroller=YES;_gridScroll.autohidesScrollers=YES;_gridScroll.borderType=NSNoBorder;_gridScroll.drawsBackground=NO;_gridScroll.accessibilityLabel=@"LUT 缩略图网格";
|
||||
_folderDocument=[[DYBrowserCanvas alloc]initWithFrame:NSZeroRect];_folderDocument.fillKey=@"card";_folderDocument.palette=_palette;_folderDocument.accessibilityLabel=@"LUT 文件夹";_folderScroll.documentView=_folderDocument;
|
||||
_gridDocument=[[DYBrowserCanvas alloc]initWithFrame:NSZeroRect];_gridDocument.palette=_palette;_gridDocument.accessibilityLabel=@"LUT 缩略图";_gridScroll.documentView=_gridDocument;
|
||||
_folderScroll.contentView.postsBoundsChangedNotifications=YES;
|
||||
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(folderScrolled:) name:NSViewBoundsDidChangeNotification object:_folderScroll.contentView];
|
||||
_gridScroll.contentView.postsBoundsChangedNotifications=YES;
|
||||
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(gridScrolled:) name:NSViewBoundsDidChangeNotification object:_gridScroll.contentView];
|
||||
for(NSView *view in @[_titleLabel,_countLabel,_statusLabel,_sizeLabel,_search,_importFiles,_importFolder,_reveal,_refresh,_none,_done,_sizeSlider,_folderScroll,_gridScroll])[_root addSubview:view];
|
||||
@@ -180,7 +182,7 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
|
||||
[_root release];[_folderDocument release];[_gridDocument release];[_folderScroll release];[_gridScroll release];
|
||||
[_titleLabel release];[_countLabel release];[_statusLabel release];[_sizeLabel release];[_emptyLabel release];[_search release];
|
||||
[_importFiles release];[_importFolder release];[_reveal release];[_refresh release];[_none release];[_done release];[_sizeSlider release];
|
||||
[_folderButtons release];[_tiles release];[_visibleEntries release];[_queuedPaths release];[_thumbnailCache release];
|
||||
[_folderButtons release];[_folderPaths release];[_tiles release];[_visibleEntries release];[_queuedPaths release];[_thumbnailCache release];
|
||||
dispatch_release(_previewQueue);[super dealloc];
|
||||
}
|
||||
- (void)showRelativeToView:(NSView *)view{
|
||||
@@ -239,9 +241,9 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
|
||||
_sizeLabel.frame=NSMakeRect(left+101,h-39,74,18);_sizeSlider.frame=NSMakeRect(left+173,h-41,MAX(70,MIN(150,w-left-420)),20);
|
||||
_done.frame=NSMakeRect(w-98,h-44,78,27);
|
||||
CGFloat statusX=NSMaxX(_sizeSlider.frame)+14;_statusLabel.frame=NSMakeRect(statusX,h-39,MAX(0,w-statusX-112),18);
|
||||
CGFloat fy=4,fw=MAX(100,_folderScroll.contentSize.width);
|
||||
for(DYBrowserFolderButton *button in _folderButtons){button.frame=NSMakeRect(4,fy,fw-8,33);fy+=35;}
|
||||
_folderDocument.frame=NSMakeRect(0,0,fw,MAX(fy,_folderScroll.contentSize.height));
|
||||
CGFloat fw=MAX(100,_folderScroll.contentSize.width);
|
||||
_folderDocument.frame=NSMakeRect(0,0,fw,MAX(_folderPaths.count*35+4,_folderScroll.contentSize.height));
|
||||
[self updateVisibleFolders];
|
||||
CGFloat available=MAX(80,_gridScroll.contentSize.width),tileWidth=_sizeSlider.doubleValue,gap=10;
|
||||
NSInteger columns=MAX(1,(NSInteger)floor((available+gap)/(tileWidth+gap)));tileWidth=MIN(tileWidth,(available-gap*(columns-1)-14)/columns);tileWidth=MAX(70,tileWidth);
|
||||
_columns=columns;_tileWidth=tileWidth;_tileHeight=ceil(tileWidth*9/16)+24;
|
||||
@@ -290,15 +292,24 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
|
||||
}
|
||||
- (void)setStatus:(NSString *)status{_statusLabel.stringValue=status?:@"";_statusLabel.toolTip=status;}
|
||||
- (void)rebuildFolders{
|
||||
for(NSView *view in _folderButtons)[view removeFromSuperview];[_folderButtons removeAllObjects];
|
||||
NSMutableArray *paths=[NSMutableArray arrayWithObject:@"*"];
|
||||
for(NSString *folder in _library.folders){NSString *top=folder.length?[folder componentsSeparatedByString:@"/"].firstObject:@"";if(![paths containsObject:top])[paths addObject:top];}
|
||||
if(![paths containsObject:_folder]){[_folder release];_folder=[@"*" copy];}
|
||||
for(NSString *path in paths){
|
||||
DYBrowserFolderButton *button=[[[DYBrowserFolderButton alloc]initWithFrame:NSZeroRect]autorelease];button.bordered=NO;button.target=self;button.action=@selector(folderClicked:);button.identifier=path;
|
||||
button.title=[path isEqualToString:@"*"]?@"全部 LUT":path.length?[@"▸ " stringByAppendingString:path]:@"未分类";button.toolTip=path.length?path:_library.rootURL.path;button.palette=_palette;button.chosen=[path isEqualToString:_folder];button.accessibilityLabel=[@"LUT 文件夹:" stringByAppendingString:button.title];
|
||||
[_folderDocument addSubview:button];[_folderButtons addObject:button];
|
||||
NSMutableArray *paths=[NSMutableArray arrayWithObject:@"*"];NSMutableSet *seen=[NSMutableSet setWithObject:@"*"];
|
||||
for(NSString *folder in _library.folders){NSString *top=folder.length?[folder componentsSeparatedByString:@"/"].firstObject:@"";if(![seen containsObject:top]){[paths addObject:top];[seen addObject:top];}}
|
||||
if(![seen containsObject:_folder]){[_folder release];_folder=[@"*" copy];}
|
||||
[_folderPaths release];_folderPaths=[paths copy];[self updateVisibleFolders];
|
||||
}
|
||||
- (void)folderScrolled:(NSNotification *)notification{if(!_layingOut)[self updateVisibleFolders];}
|
||||
- (void)updateVisibleFolders {
|
||||
if(_closed)return;NSRect visible=NSInsetRect(_folderScroll.contentView.bounds,0,-35);
|
||||
NSUInteger first=(NSUInteger)MAX(0,floor(NSMinY(visible)/35)),end=MIN(_folderPaths.count,(NSUInteger)MAX(0,ceil(NSMaxY(visible)/35)+1));
|
||||
NSMutableDictionary *existing=[NSMutableDictionary dictionary];for(NSButton *button in _folderButtons)existing[button.identifier]=button;
|
||||
NSMutableArray *buttons=[NSMutableArray array];
|
||||
for(NSUInteger i=first;i<end;i++){
|
||||
NSString *path=_folderPaths[i];DYBrowserFolderButton *button=existing[path];
|
||||
if(!button){button=[[[DYBrowserFolderButton alloc]initWithFrame:NSZeroRect]autorelease];button.bordered=NO;button.target=self;button.action=@selector(folderClicked:);button.identifier=path;
|
||||
button.title=[path isEqualToString:@"*"]?@"全部 LUT":path.length?[@"▸ " stringByAppendingString:path]:@"未分类";button.toolTip=path.length?path:_library.rootURL.path;button.palette=_palette;button.accessibilityLabel=[@"LUT 文件夹:" stringByAppendingString:button.title];[_folderDocument addSubview:button];}
|
||||
button.chosen=[path isEqualToString:_folder];button.frame=NSMakeRect(4,4+i*35,MAX(92,_folderScroll.contentSize.width-8),33);[button setNeedsDisplay:YES];[buttons addObject:button];
|
||||
}
|
||||
for(NSButton *button in _folderButtons)if(![buttons containsObject:button])[button removeFromSuperview];[_folderButtons setArray:buttons];
|
||||
}
|
||||
- (void)pollLibraryProgress:(NSTimer *)timer {
|
||||
if(_libraryTask)[self setStatus:_libraryTask.localizedDescription];
|
||||
|
||||
@@ -316,7 +316,8 @@ static BOOL DYLUTEnsureDirectory(NSURL *directory,NSURL *root,NSError **error) {
|
||||
if(scanError){if(error)*error=scanError;return NO;}
|
||||
[entries sortUsingComparator:^NSComparisonResult(NSDictionary *a,NSDictionary *b){return [a[@"relativePath"]localizedStandardCompare:b[@"relativePath"]];}];
|
||||
if(DYLUTCancelled(progress,error))return NO;
|
||||
@synchronized(self){[_entries release];_entries=[entries copy];[_folders release];_folders=[[folders.allObjects sortedArrayUsingSelector:@selector(localizedStandardCompare:)]copy];}return YES;
|
||||
NSArray *sortedFolders=[folders.allObjects sortedArrayUsingSelector:@selector(localizedStandardCompare:)];
|
||||
@synchronized(self){[_entries release];_entries=[entries copy];[_folders release];_folders=[sortedFolders copy];}return YES;
|
||||
}}
|
||||
- (NSArray *)importURLs:(NSArray<NSURL *> *)urls error:(NSError **)error {return [self importURLs:urls progress:nil error:error];}
|
||||
- (NSArray *)importURLs:(NSArray<NSURL *> *)urls progress:(NSProgress *)progress error:(NSError **)error {@synchronized(_fileLock){
|
||||
|
||||
在新工单中引用
屏蔽一个用户