aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2010-03-18 00:34:29 +0000
committerstuconnolly <stuart02@gmail.com>2010-03-18 00:34:29 +0000
commita8dc3ac2af642fb59c8fbed12c3a28038ef3a175 (patch)
treef3a9e068aeb9fbf5497a2d968539cbd19fc5ffda /Source
parent5b6e0e9760c7719456de1ac856daf27e509a42d3 (diff)
downloadsequelpro-a8dc3ac2af642fb59c8fbed12c3a28038ef3a175.tar.gz
sequelpro-a8dc3ac2af642fb59c8fbed12c3a28038ef3a175.tar.bz2
sequelpro-a8dc3ac2af642fb59c8fbed12c3a28038ef3a175.zip
Present a warning to the user when attempting to print the current table's content view which exceeds a set number of rows. This number is currently set to 1000 which can be changed via the hidden preference key 'PrintWarningRowLimit'. The approach to cancelling the print HTML generation thread may also need to be re-implemented to ensure that it is killed straight away, something that is currently not possible using NSThread. Rowan suggested using pthreads instead, but this should be discussed in terms of potential memory leaks and stability.
Diffstat (limited to 'Source')
-rw-r--r--Source/SPConstants.h5
-rw-r--r--Source/SPConstants.m5
-rw-r--r--Source/SPPrintController.h1
-rw-r--r--Source/SPPrintController.m59
-rw-r--r--Source/TableContent.m18
5 files changed, 74 insertions, 14 deletions
diff --git a/Source/SPConstants.h b/Source/SPConstants.h
index a7409ebc..0843a79c 100644
--- a/Source/SPConstants.h
+++ b/Source/SPConstants.h
@@ -89,7 +89,6 @@ extern NSString *SPDefaultEncoding;
extern NSString *SPUseMonospacedFonts;
extern NSString *SPDisplayTableViewVerticalGridlines;
extern NSString *SPCustomQueryMaxHistoryItems;
-extern NSString *SPDisplayServerVersionInWindowTitle;
// Tables Prefpane
extern NSString *SPReloadAfterAddingRow;
@@ -156,6 +155,10 @@ extern NSString *SPEditInSheetEnabled;
extern NSString *SPTableInformationPanelCollapsed;
extern NSString *SPTableColumnWidths;
+// Hidden Prefs
+extern NSString *SPPrintWarningRowLimit;
+extern NSString *SPDisplayServerVersionInWindowTitle;
+
// Import
extern NSString *SPCSVImportFieldTerminator;
extern NSString *SPCSVImportLineTerminator;
diff --git a/Source/SPConstants.m b/Source/SPConstants.m
index 7db91664..1b34b1c7 100644
--- a/Source/SPConstants.m
+++ b/Source/SPConstants.m
@@ -57,7 +57,6 @@ NSString *SPDefaultEncoding = @"DefaultEncoding";
NSString *SPUseMonospacedFonts = @"UseMonospacedFonts";
NSString *SPDisplayTableViewVerticalGridlines = @"DisplayTableViewVerticalGridlines";
NSString *SPCustomQueryMaxHistoryItems = @"CustomQueryMaxHistoryItems";
-NSString *SPDisplayServerVersionInWindowTitle = @"DisplayServerVersionInWindowTitle";
// Tables Prefpane
NSString *SPReloadAfterAddingRow = @"ReloadAfterAddingRow";
@@ -124,6 +123,10 @@ NSString *SPEditInSheetEnabled = @"EditInSheetEnabled";
NSString *SPTableInformationPanelCollapsed = @"TableInformationPanelCollapsed";
NSString *SPTableColumnWidths = @"tableColumnWidths";
+// Hidden Prefs
+NSString *SPPrintWarningRowLimit = @"PrintWarningRowLimit";
+NSString *SPDisplayServerVersionInWindowTitle = @"DisplayServerVersionInWindowTitle";
+
// Import
NSString *SPCSVImportFieldEnclosedBy = @"CSVImportFieldEnclosedBy";
NSString *SPCSVImportFieldEscapeCharacter = @"CSVImportFieldEscapeCharacter";
diff --git a/Source/SPPrintController.h b/Source/SPPrintController.h
index 5d259be5..3982b152 100644
--- a/Source/SPPrintController.h
+++ b/Source/SPPrintController.h
@@ -27,6 +27,7 @@
@interface TableDocument (SPPrintController)
+- (void)startPrintDocumentOperation;
- (void)generateHTMLForPrinting;
- (void)generateTableInfoHTMLForPrinting;
diff --git a/Source/SPPrintController.m b/Source/SPPrintController.m
index f83f3625..d12f764f 100644
--- a/Source/SPPrintController.m
+++ b/Source/SPPrintController.m
@@ -102,10 +102,61 @@
*/
- (IBAction)printDocument:(id)sender
{
+ // Only display warning for the 'Table Content' view
+ if ([tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 1) {
+
+ NSInteger rowLimit = [prefs integerForKey:SPPrintWarningRowLimit];
+
+ // Result count minus one because the first element is the column names
+ NSUInteger resultRows = ([[tableContentInstance currentResult] count] - 1);
+
+ if (resultRows > rowLimit) {
+
+ NSNumberFormatter *numberFormatter = [[[NSNumberFormatter alloc] init] autorelease];
+
+ [numberFormatter setNumberStyle:NSNumberFormatterDecimalStyle];
+
+ NSAlert *alert = [NSAlert alertWithMessageText:NSLocalizedString(@"Continue to print?", @"continue to print message")
+ defaultButton:NSLocalizedString(@"Print", @"print button")
+ alternateButton:NSLocalizedString(@"Cancel", @"cancel button")
+ otherButton:nil
+ informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"Are you sure you want to print the current content view of the table '%@'?\n\nIt currently contains %@ rows, which may take a significant amount of time to print.", @"continue to print informative message"), [self table], [numberFormatter stringFromNumber:[NSNumber numberWithLongLong:resultRows]]]];
+
+ NSArray *buttons = [alert buttons];
+
+ // Change the alert's cancel button to have the key equivalent of return
+ [[buttons objectAtIndex:0] setKeyEquivalent:@"p"];
+ [[buttons objectAtIndex:0] setKeyEquivalentModifierMask:NSCommandKeyMask];
+ [[buttons objectAtIndex:1] setKeyEquivalent:@"\r"];
+
+ [alert beginSheetModalForWindow:tableWindow modalDelegate:self didEndSelector:@selector(printWarningDidEnd:returnCode:contextInfo:) contextInfo:NULL];
+
+ return;
+ }
+ }
+
+ [self startPrintDocumentOperation];
+}
+
+/**
+ * Called when the print warning dialog is dismissed.
+ */
+- (void)printWarningDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo
+{
+ if (returnCode == NSAlertDefaultReturn) {
+ [self startPrintDocumentOperation];
+ }
+}
+
+/**
+ * Starts tge print document operation by spawning a new thread if required.
+ */
+- (void)startPrintDocumentOperation
+{
[self startTaskWithDescription:NSLocalizedString(@"Generating print document...", @"generating print document status message")];
BOOL isTableInformation = ([tableTabView indexOfTabViewItem:[tableTabView selectedTabViewItem]] == 3);
-
+
if ([NSThread isMainThread]) {
printThread = [[NSThread alloc] initWithTarget:self selector:(isTableInformation) ? @selector(generateTableInfoHTMLForPrinting) : @selector(generateHTMLForPrinting) object:nil];
@@ -263,7 +314,7 @@
NSString *HTMLString = [engine processTemplateInFileAtPath:[[NSBundle mainBundle] pathForResource:SPHTMLPrintTemplate ofType:@"html"] withVariables:printData];
// Check if the operation has been cancelled
- if ((printThread != nil) && (![NSThread isMainThread]) && ([printThread isCancelled])) {
+ if ((printThread != nil) && (![NSThread isMainThread]) && ([printThread isCancelled])) {
[pool drain];
[self endTask];
@@ -300,6 +351,8 @@
[printData setObject:heading forKey:@"heading"];
[printData setObject:[[NSUnarchiver unarchiveObjectWithData:[prefs objectForKey:SPCustomQueryEditorFont]] fontName] forKey:@"font"];
+ NSString *HTMLString = [engine processTemplateInFileAtPath:[[NSBundle mainBundle] pathForResource:SPHTMLTableInfoPrintTemplate ofType:@"html"] withVariables:printData];
+
// Check if the operation has been cancelled
if ((printThread != nil) && (![NSThread isMainThread]) && ([printThread isCancelled])) {
[pool drain];
@@ -310,8 +363,6 @@
return;
}
- NSString *HTMLString = [engine processTemplateInFileAtPath:[[NSBundle mainBundle] pathForResource:SPHTMLTableInfoPrintTemplate ofType:@"html"] withVariables:printData];
-
[self performSelectorOnMainThread:@selector(loadPrintWebViewWithHTMLString:) withObject:HTMLString waitUntilDone:NO];
[pool drain];
diff --git a/Source/TableContent.m b/Source/TableContent.m
index b0e5e8fe..c5090573 100644
--- a/Source/TableContent.m
+++ b/Source/TableContent.m
@@ -1421,11 +1421,13 @@
[alert beginSheetModalForWindow:tableWindow modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:contextInfo];
}
-//getter methods
-- (NSArray *)currentDataResult
-/*
- 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
+// Accessors
+
+/**
+ * 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.
*/
+- (NSArray *)currentDataResult
{
NSArray *tableColumns;
NSEnumerator *enumerator;
@@ -1480,11 +1482,11 @@
return currentResult;
}
-//getter methods
-- (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
+/**
+ * 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.
*/
+- (NSArray *)currentResult
{
NSArray *tableColumns;
NSEnumerator *enumerator;