Revision: 14730
http://sourceforge.net/p/skim-app/code/14730
Author: hofman
Date: 2024-11-20 17:12:46 +0000 (Wed, 20 Nov 2024)
Log Message:
-----------
Add printing app delegate method, so we can print with a temporary document
without showing the document UI. Use the pdf doc from the tmpData to print in
this case.
Modified Paths:
--------------
trunk/SKApplicationController.m
trunk/SKMainDocument.m
Modified: trunk/SKApplicationController.m
===================================================================
--- trunk/SKApplicationController.m 2024-11-19 15:51:17 UTC (rev 14729)
+++ trunk/SKApplicationController.m 2024-11-20 17:12:46 UTC (rev 14730)
@@ -292,6 +292,57 @@
}
}
+- (void)document:(NSDocument *)document didPrint:(BOOL)didPrintSuccessfully
contextInfo:(void *)contextInfo {
+ if (contextInfo) {
+ void (^block)(BOOL) = (void(^)(BOOL))CFBridgingRelease(contextInfo);
+ block(didPrintSuccessfully);
+ }
+}
+
+- (NSApplicationPrintReply)application:(NSApplication *)sender
printFiles:(NSArray *)fileNames withSettings:(NSDictionary *)printSettings
showPrintPanels:(BOOL)showPrintPanels {
+ NSUInteger count = [fileNames count];
+ if ([fileNames count] == 0)
+ return NSPrintingFailure;
+
+ NSURL *fileURL = [NSURL fileURLWithPath:[fileNames firstObject]];
+ NSArray *nextFileNames = count > 1 ? [fileNames
subarrayWithRange:NSMakeRange(1, count - 1)] : nil;
+ // keep track to see whether we finished before this method returns
+ __block NSApplicationPrintReply reply = NSPrintingReplyLater;
+
+ [[NSDocumentController sharedDocumentController]
openDocumentWithContentsOfURL:fileURL display:NO completionHandler:^(NSDocument
*document, BOOL documentWasAlreadyOpen, NSError *error){
+ if (document) {
+ void (^block)(BOOL) = ^(BOOL success){
+ NSApplicationPrintReply aReply;
+ if (documentWasAlreadyOpen == NO)
+ [document close];
+ if (success == NO)
+ aReply = NSPrintingFailure;
+ else if (nextFileNames)
+ aReply = [self application:NSApp printFiles:nextFileNames
withSettings:printSettings showPrintPanels:showPrintPanels];
+ else
+ aReply = NSPrintingSuccess;
+ if (reply == NSPrintingReplyLater)
+ reply = aReply;
+ else if (aReply != NSPrintingReplyLater)
+ [NSApp replyToOpenOrPrint:aReply == NSPrintingSuccess ?
NSApplicationDelegateReplySuccess : NSApplicationDelegateReplyFailure];
+ };
+ [document printDocumentWithSettings:printSettings
showPrintPanel:showPrintPanels delegate:self
didPrintSelector:@selector(document:didPrint:contextInfo:) contextInfo:(void
*)CFBridgingRetain(block)];
+ } else {
+ if (reply != NSPrintingReplyLater)
+ [NSApp replyToOpenOrPrint:NSApplicationDelegateReplyFailure];
+ reply = NSPrintingFailure;
+ }
+ }];
+
+ if (reply == NSPrintingReplyLater) {
+ // set the block variable to note to the finishing block it needs to
reply
+ reply = NSPrintingCancelled;
+ return NSPrintingReplyLater;
+ } else {
+ return reply;
+ }
+}
+
- (void)applicationStartsTerminating:(NSNotification *)aNotification {
[currentDocumentsTimer invalidate];
currentDocumentsTimer = nil;
Modified: trunk/SKMainDocument.m
===================================================================
--- trunk/SKMainDocument.m 2024-11-19 15:51:17 UTC (rev 14729)
+++ trunk/SKMainDocument.m 2024-11-20 17:12:46 UTC (rev 14730)
@@ -999,6 +999,15 @@
NSPrintInfo *printInfo = [[self printInfo] copy];
PDFDocument *pdfDoc = [self pdfDocument];
+ // this can happen when the document is printed without display from the
app delegate
+ if (pdfDoc == nil && tmpData) {
+ pdfDoc = [tmpData pdfDocument];
+ if ([tmpData noteDicts]) {
+ pdfDoc = [pdfDoc copy];
+ [pdfDoc addSkimNotesWithProperties:[tmpData noteDicts]];
+ }
+ }
+
[[printInfo dictionary] setValue:[NSNumber
numberWithUnsignedInteger:[pdfDoc pageCount]] forKey:NSPrintLastPage];
[[printInfo dictionary] addEntriesFromDictionary:printSettings];
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
_______________________________________________
Skim-app-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/skim-app-commit