Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fix crash when trying to print on 10.13.4 (#3025)
  • Loading branch information
dmoagx committed Apr 12, 2018
1 parent d5056eb commit 85d65c3
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
6 changes: 3 additions & 3 deletions Source/SPBundleHTMLOutputController.m
Expand Up @@ -197,7 +197,7 @@ - (void)sheetDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSSt

- (IBAction)printDocument:(id)sender
{

#warning duplicate code with -[SPDatabaseDocument webView:didFinishLoadForFrame:]
NSPrintInfo *printInfo = [NSPrintInfo sharedPrintInfo];

NSSize paperSize = [printInfo paperSize];
Expand Down Expand Up @@ -225,8 +225,8 @@ - (IBAction)printDocument:(id)sender

NSPrintOperation *op = [NSPrintOperation printOperationWithView:[[[webView mainFrame] frameView] documentView] printInfo:printInfo];

// Perform the print operation on a background thread
[op setCanSpawnSeparateThread:YES];
// do not try to use webkit from a background thread!
[op setCanSpawnSeparateThread:NO];

// Add the ability to select the orientation to print panel
NSPrintPanel *printPanel = [op printPanel];
Expand Down
28 changes: 19 additions & 9 deletions Source/SPDatabaseDocument.m
Expand Up @@ -79,9 +79,7 @@
#import "SPBundleHTMLOutputController.h"
#endif
#import "SPTableTriggers.h"
#ifdef SP_CODA /* headers */
#import "SPTableStructure.h"
#endif
#import "SPPrintAccessory.h"
#import "MGTemplateEngine.h"
#import "ICUTemplateMatcher.h"
Expand Down Expand Up @@ -7279,8 +7277,8 @@ - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame

NSPrintOperation *op = [NSPrintOperation printOperationWithView:[[[printWebView mainFrame] frameView] documentView] printInfo:printInfo];

// Perform the print operation on a background thread
[op setCanSpawnSeparateThread:YES];
// do not try to use webkit from a background thread!
[op setCanSpawnSeparateThread:NO];

// Add the ability to select the orientation to print panel
NSPrintPanel *printPanel = [op printPanel];
Expand All @@ -7297,12 +7295,22 @@ - (void)webView:(WebView *)sender didFinishLoadForFrame:(WebFrame *)frame

[op setPrintPanel:printPanel];

[op runOperationModalForWindow:[self parentWindow]
delegate:self
didRunSelector:nil
contextInfo:nil];

/* -endTask has to be called first, since the toolbar caches the item enabled state before starting a sheet,
* disables all items and restores the cached state after the sheet ends. Because the database chooser is disabled
* during tasks, launching the sheet before calling -endTask first would result in the following flow:
* - toolbar item caches database chooser state as disabled (because of the active task)
* - sheet is shown
* - endTask reenables database chooser (has no effect because of the open sheet)
* - user dismisses sheet after some time
* - toolbar item restores cached state and disables database chooser again
* => Inconsistent UI: database chooser disabled when it should actually be enabled
*/
if ([self isWorking]) [self endTask];

[op runOperationModalForWindow:[self parentWindow]
delegate:self
didRunSelector:nil
contextInfo:nil];
}

/**
Expand Down Expand Up @@ -7590,6 +7598,8 @@ - (void)generateTableInfoHTMLForPrinting

/**
* Returns an array of columns for whichever view is being printed.
*
* MUST BE CALLED ON THE UI THREAD!
*/
- (NSArray *)columnNames
{
Expand Down
2 changes: 2 additions & 0 deletions Source/SPTableContent.m
Expand Up @@ -2373,6 +2373,8 @@ - (NSArray *)currentResult
/**
* Returns the current result (as shown in table content view) as array, the first object containing the field
* names as array, the following objects containing the rows as array.
*
* MUST BE CALLED ON THE UI THREAD!
*/
- (NSArray *)currentDataResultWithNULLs:(BOOL)includeNULLs hideBLOBs:(BOOL)hide
{
Expand Down

0 comments on commit 85d65c3

Please sign in to comment.