Revision: 13000 http://sourceforge.net/p/skim-app/code/13000 Author: hofman Date: 2022-07-09 18:23:38 +0000 (Sat, 09 Jul 2022) Log Message: ----------- Implement newWindowForTab: to call openDocument: allowing only the types for the document.
Modified Paths: -------------- trunk/SKDocumentController.h trunk/SKDocumentController.m Modified: trunk/SKDocumentController.h =================================================================== --- trunk/SKDocumentController.h 2022-07-08 17:46:13 UTC (rev 12999) +++ trunk/SKDocumentController.h 2022-07-09 18:23:38 UTC (rev 13000) @@ -68,6 +68,7 @@ @interface SKDocumentController : NSDocumentController { BOOL openedFile; + Class openDocumentClass; } - (IBAction)newDocumentFromClipboard:(id)sender; Modified: trunk/SKDocumentController.m =================================================================== --- trunk/SKDocumentController.m 2022-07-08 17:46:13 UTC (rev 12999) +++ trunk/SKDocumentController.m 2022-07-09 18:23:38 UTC (rev 13000) @@ -84,11 +84,9 @@ #define WARNING_LIMIT 10 -#if SDK_BEFORE(10_12) -@interface NSResponder(NSWindowTabbing) -- (IBAction)newWindowForTab:(id)sender; +@interface NSDocumentController (SKPrivateDeclaration) +- (void)_setTabPlusButtonWasClicked:(BOOL)wasClicked; @end -#endif @interface NSDocumentController (SKDeprecated) // we don't want this to be flagged as deprecated, because Apple's replacement using UTIs is too buggy, and there's no replacement for this method @@ -122,8 +120,18 @@ } - (void)beginOpenPanel:(NSOpenPanel *)openPanel forTypes:(NSArray *)inTypes completionHandler:(void (^)(NSInteger result))completionHandler { - [openPanel setCanChooseDirectories:YES]; - [super beginOpenPanel:openPanel forTypes:inTypes completionHandler:completionHandler]; + if (openDocumentClass) + inTypes = [openDocumentClass readableTypes]; + else + [openPanel setCanChooseDirectories:YES]; + [super beginOpenPanel:openPanel forTypes:inTypes completionHandler:^(NSInteger result) { + completionHandler(result); + if (openDocumentClass) { + openDocumentClass = Nil; + if (result == NSFileHandlingPanelCancelButton && [self respondsToSelector:@selector(_setTabPlusButtonWasClicked:)]) + [self _setTabPlusButtonWasClicked:NO]; + } + }]; } static BOOL isPDFData(NSData *data) { @@ -217,6 +225,12 @@ return pdfData; } +// new empty documents make no sense, so open using the open panel +- (void)newWindowForTab:sender { + openDocumentClass = [sender isKindOfClass:[NSWindow class]] ? [[[sender windowController] document] class] : nil; + [self openDocument:sender]; +} + - (IBAction)newDocumentFromClipboard:(id)sender { NSPasteboard *pboard = [NSPasteboard generalPasteboard]; [self openDocumentWithImageFromPasteboard:pboard completionHandler:^(NSDocument *document1, BOOL documentWasAlreadyOpen1, NSError *error1){ @@ -632,11 +646,6 @@ } } -// By not responding to newWindowForTab: no "+" button is shown in the tab bar -- (BOOL)respondsToSelector:(SEL)aSelector { - return aSelector != @selector(newWindowForTab:) && [super respondsToSelector:aSelector]; -} - - (BOOL)validateUserInterfaceItem:(id <NSValidatedUserInterfaceItem>)anItem { if ([anItem action] == @selector(newDocumentFromClipboard:)) { NSPasteboard *pboard = [NSPasteboard generalPasteboard]; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ Skim-app-commit mailing list Skim-app-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/skim-app-commit