fix: present LUT browser through FxPlug host window and refine native controls
这个提交包含在:
1 父节点
61ea1c64a0
当前提交
2e7ab4b052
7 个文件已更改
+113
-40
没有与搜索条件相匹配的文件
+55
-20
@@ -100,12 +100,14 @@ static NSString *const DYBrowserFolderPreference=@"com.dayu.color.lookLUTPreview
|
||||
@end
|
||||
@implementation DYBrowserWork @end
|
||||
|
||||
@interface DYLUTBrowser () <NSWindowDelegate,NSSearchFieldDelegate> {
|
||||
@interface DYLUTBrowser () <NSWindowDelegate,NSPopoverDelegate,NSSearchFieldDelegate> {
|
||||
DYLUTLibrary *_library;
|
||||
NSData *_preview;
|
||||
NSString *_selectedPath,*_folder;
|
||||
NSDictionary *_palette;
|
||||
void (^_selection)(NSString *);
|
||||
void (^_closeAction)(void);
|
||||
NSPopover *_popover;
|
||||
DYBrowserCanvas *_root,*_folderDocument,*_gridDocument;
|
||||
NSScrollView *_folderScroll,*_gridScroll;
|
||||
NSTextField *_titleLabel,*_countLabel,*_statusLabel,*_sizeLabel,*_emptyLabel;
|
||||
@@ -119,7 +121,7 @@ static NSString *const DYBrowserFolderPreference=@"com.dayu.color.lookLUTPreview
|
||||
NSCache *_thumbnailCache;
|
||||
dispatch_queue_t _previewQueue;
|
||||
DYBrowserWork *_work;
|
||||
BOOL _closed,_sizing;
|
||||
BOOL _closed,_sizing,_visible,_remoteMode,_importing;
|
||||
}
|
||||
@end
|
||||
|
||||
@@ -157,6 +159,9 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
|
||||
[[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];
|
||||
[_gridDocument addSubview:_emptyLabel];
|
||||
_root.postsFrameChangedNotifications=YES;_root.postsBoundsChangedNotifications=YES;
|
||||
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(browserRootResized:) name:NSViewFrameDidChangeNotification object:_root];
|
||||
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(browserRootResized:) name:NSViewBoundsDidChangeNotification object:_root];
|
||||
[self reloadLibrary:nil];[self updatePalette:palette];[self layoutBrowser];
|
||||
}
|
||||
return self;
|
||||
@@ -164,7 +169,8 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
|
||||
- (void)dealloc{
|
||||
[NSObject cancelPreviousPerformRequestsWithTarget:self];[[NSNotificationCenter defaultCenter]removeObserver:self];
|
||||
_work.cancelled=YES;_work.owner=nil;[_work release];self.window.delegate=nil;
|
||||
[_library release];[_preview release];[_selectedPath release];[_folder release];[_palette release];[_selection release];
|
||||
_popover.delegate=nil;[_popover close];[_popover release];[_root removeFromSuperview];
|
||||
[_library release];[_preview release];[_selectedPath release];[_folder release];[_palette release];[_selection release];[_closeAction release];
|
||||
[_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];
|
||||
@@ -172,21 +178,49 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
|
||||
dispatch_release(_previewQueue);[super dealloc];
|
||||
}
|
||||
- (void)showRelativeToView:(NSView *)view{
|
||||
if(_closed)return;
|
||||
NSWindow *parent=view.window;
|
||||
if(parent){
|
||||
NSRect frame=self.window.frame,parentFrame=parent.frame;
|
||||
NSScreen *screen=parent.screen?:NSScreen.mainScreen;NSRect safe=screen.visibleFrame;
|
||||
NSPoint p=NSMakePoint(NSMidX(parentFrame)-frame.size.width/2,NSMidY(parentFrame)-frame.size.height/2);
|
||||
p.x=MAX(NSMinX(safe),MIN(p.x,NSMaxX(safe)-frame.size.width));p.y=MAX(NSMinY(safe),MIN(p.y,NSMaxY(safe)-frame.size.height));[self.window setFrameOrigin:p];
|
||||
}else [self.window center];
|
||||
[self showWindow:nil];[self.window makeKeyAndOrderFront:nil];
|
||||
if(_closed||_remoteMode||!view.window)return;
|
||||
if(_popover.shown)return;
|
||||
// A plug-in process is prohibited from making its own NSPanel key. Only
|
||||
// FxRemoteWindow or a host-anchored popover may present this content.
|
||||
self.window.contentView=[[[NSView alloc]initWithFrame:NSMakeRect(0,0,1,1)]autorelease];
|
||||
[_root removeFromSuperview];_root.frame=NSMakeRect(0,0,760,560);_root.autoresizingMask=NSViewWidthSizable|NSViewHeightSizable;
|
||||
_popover=[[NSPopover alloc]init];_popover.behavior=NSPopoverBehaviorTransient;_popover.animates=YES;_popover.delegate=self;_popover.contentSize=NSMakeSize(760,560);
|
||||
NSViewController *controller=[[[NSViewController alloc]init]autorelease];controller.view=_root;_popover.contentViewController=controller;
|
||||
[self layoutBrowser];
|
||||
@try {[_popover showRelativeToRect:view.bounds ofView:view preferredEdge:NSRectEdgeMaxX];_visible=_popover.shown;}
|
||||
@catch(NSException *exception){[self finishClosing];}
|
||||
}
|
||||
- (BOOL)visible{return !_closed&&(_remoteMode?_visible:_popover.shown);}
|
||||
- (void)showInRemoteParent:(NSView *)parent close:(void (^)(void))closeAction{
|
||||
if(_closed||!parent||self.visible)return;
|
||||
_remoteMode=YES;_visible=YES;[_closeAction release];_closeAction=[closeAction copy];
|
||||
self.window.contentView=[[[NSView alloc]initWithFrame:NSMakeRect(0,0,1,1)]autorelease];
|
||||
[_root removeFromSuperview];_root.frame=parent.bounds;_root.autoresizingMask=NSViewWidthSizable|NSViewHeightSizable;parent.autoresizesSubviews=YES;_root.hidden=NO;
|
||||
[parent addSubview:_root];[self layoutBrowser];[_root setNeedsDisplay:YES];
|
||||
NSAccessibilityPostNotification(parent,NSAccessibilityLayoutChangedNotification);
|
||||
}
|
||||
- (void)browserRootResized:(NSNotification *)notification{if(!_closed)[self layoutBrowser];}
|
||||
- (void)windowDidResize:(NSNotification *)notification{[self layoutBrowser];}
|
||||
- (void)windowWillClose:(NSNotification *)notification{
|
||||
- (void)windowWillClose:(NSNotification *)notification{[self finishClosing];}
|
||||
- (BOOL)popoverShouldClose:(NSPopover *)popover{return !_importing;}
|
||||
- (void)popoverDidClose:(NSNotification *)notification{[self finishClosing];}
|
||||
- (void)close{
|
||||
if(_closed)return;
|
||||
if(_popover.shown){[_popover close];if(!_closed)[self finishClosing];}
|
||||
else [self finishClosing];
|
||||
}
|
||||
- (void)finishClosing{
|
||||
if(_closed)return;
|
||||
// The API owner's completion may release this controller synchronously.
|
||||
[self retain];
|
||||
[NSObject cancelPreviousPerformRequestsWithTarget:self];
|
||||
_closed=YES;_work.cancelled=YES;_work.owner=nil;
|
||||
_closed=YES;_visible=NO;_work.cancelled=YES;_work.owner=nil;
|
||||
_popover.delegate=nil;if(_popover.shown)[_popover close];
|
||||
[_root removeFromSuperview];[_queuedPaths removeAllObjects];[_thumbnailCache removeAllObjects];
|
||||
[_selection release];_selection=nil;
|
||||
void (^closeAction)(void)=[_closeAction copy];[_closeAction release];_closeAction=nil;
|
||||
if(closeAction)closeAction();[closeAction release];
|
||||
[self release];
|
||||
}
|
||||
- (void)layoutBrowser{
|
||||
CGFloat w=_root.bounds.size.width,h=_root.bounds.size.height,left=162;
|
||||
@@ -214,6 +248,7 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
|
||||
browserPalette[@"background"]=[NSColor colorWithCalibratedRed:.035 green:.08 blue:.12 alpha:1];
|
||||
[_palette release];_palette=[browserPalette copy];_root.palette=_palette;_folderDocument.palette=_palette;_gridDocument.palette=_palette;
|
||||
self.window.backgroundColor=DYBrowserColor(_palette,@"background");self.window.appearance=[NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
|
||||
_root.appearance=[NSAppearance appearanceNamed:NSAppearanceNameDarkAqua];
|
||||
for(NSTextField *label in @[_titleLabel,_countLabel,_statusLabel,_sizeLabel,_emptyLabel])label.textColor=DYBrowserColor(_palette,label==_titleLabel?@"text":@"secondary");
|
||||
for(NSButton *button in @[_importFiles,_importFolder,_reveal,_refresh,_none,_done])button.contentTintColor=DYBrowserColor(_palette,@"accent");
|
||||
_search.textColor=DYBrowserColor(_palette,@"text");_search.backgroundColor=DYBrowserColor(_palette,@"field");
|
||||
@@ -332,16 +367,16 @@ static NSButton *BrowserButton(NSString *title,id target,SEL action){NSButton *b
|
||||
}
|
||||
- (void)done:(id)sender{[self close];}
|
||||
- (void)showImportError:(NSError *)error{
|
||||
if(!error)return;NSAlert *alert=[[[NSAlert alloc]init]autorelease];alert.messageText=@"LUT 导入未完成";alert.informativeText=error.localizedDescription?:@"请选择有效的 .cube LUT 文件。";[alert addButtonWithTitle:@"好"];[alert beginSheetModalForWindow:self.window completionHandler:nil];
|
||||
if(!error||_closed)return;NSAlert *alert=[[[NSAlert alloc]init]autorelease];alert.messageText=@"LUT 导入未完成";alert.informativeText=error.localizedDescription?:@"请选择有效的 .cube LUT 文件。";[alert addButtonWithTitle:@"好"];
|
||||
_importing=YES;[alert runModal];_importing=NO;
|
||||
}
|
||||
- (void)importPanelForFolders:(BOOL)folders{
|
||||
NSOpenPanel *panel=[NSOpenPanel openPanel];panel.canChooseFiles=!folders;panel.canChooseDirectories=folders;panel.allowsMultipleSelection=YES;panel.title=folders?@"导入 LUT 文件夹":@"导入 LUT 文件";panel.message=folders?@"所选文件夹中的 .cube 文件会按目录复制到大鱼调色 LUT 库。":@"选择要复制到大鱼调色 LUT 库的 .cube 文件。";
|
||||
if(!folders)panel.allowedFileTypes=@[@"cube"];
|
||||
[panel beginSheetModalForWindow:self.window completionHandler:^(NSModalResponse response){
|
||||
if(response!=NSModalResponseOK||_closed)return;NSError *error=nil;NSArray *imported=[_library importURLs:panel.URLs error:&error];
|
||||
if(!imported){[self showImportError:error];return;}
|
||||
[self rebuildFolders];[self rebuildGrid];[self setStatus:[NSString stringWithFormat:@"已导入 %lu 个 LUT",(unsigned long)imported.count]];
|
||||
}];
|
||||
_importing=YES;NSModalResponse response=[panel runModal];_importing=NO;
|
||||
if(response!=NSModalResponseOK||_closed)return;NSError *error=nil;NSArray *imported=[_library importURLs:panel.URLs error:&error];
|
||||
if(!imported){[self showImportError:error];return;}
|
||||
[self rebuildFolders];[self rebuildGrid];[self setStatus:[NSString stringWithFormat:@"已导入 %lu 个 LUT",(unsigned long)imported.count]];
|
||||
}
|
||||
- (void)importFiles:(id)sender{[self importPanelForFolders:NO];}
|
||||
- (void)importFolder:(id)sender{[self importPanelForFolders:YES];}
|
||||
|
||||
在新工单中引用
屏蔽一个用户