aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPCustomQuery.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2011-09-21 00:38:56 +0000
committerrowanbeentje <rowan@beent.je>2011-09-21 00:38:56 +0000
commit549d28e50a35d432531926a6916755dbe26d91c4 (patch)
treecf5ef7d9440fedb7226ea60e7f2b22d5907d428e /Source/SPCustomQuery.m
parent6278cbbf9d76d69f44d1d7ddf34792b9e0310272 (diff)
downloadsequelpro-549d28e50a35d432531926a6916755dbe26d91c4.tar.gz
sequelpro-549d28e50a35d432531926a6916755dbe26d91c4.tar.bz2
sequelpro-549d28e50a35d432531926a6916755dbe26d91c4.zip
Rework linebreak handling in content and custom query result views, as triggered by Issue #1184:
- Display table cells on a single line for preview purposes - Display gray pilcrow/reverse pilcrow placeholders instead of linebreaks - If a cell contains linebreaks, automatically trigger sheet editing mode - Handle newly displayed linebreaks in column width detection - If using the up/down arrow keys in a field editor, allow them to select the previous/next line within an editor if appropriat (instead of always moving to the previous/next row)
Diffstat (limited to 'Source/SPCustomQuery.m')
-rw-r--r--Source/SPCustomQuery.m54
1 files changed, 35 insertions, 19 deletions
diff --git a/Source/SPCustomQuery.m b/Source/SPCustomQuery.m
index c10d62d3..bb32eb41 100644
--- a/Source/SPCustomQuery.m
+++ b/Source/SPCustomQuery.m
@@ -2398,7 +2398,6 @@
if ( aTableView == customQueryView ) {
NSDictionary *columnDefinition;
- BOOL isBlob = NO;
// Retrieve the column defintion
for(id c in cqColumnDefinition) {
@@ -2409,15 +2408,28 @@
}
// Check if current field is a blob
- if([[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"textdata"]
- || [[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"blobdata"])
- isBlob = YES;
- else
- isBlob = NO;
+ BOOL isBlob = ([[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"textdata"]
+ || [[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"blobdata"]);
- if ([multipleLineEditingButton state] == NSOnState || isBlob) {
+ // Determine whether to open the sheet for editing; do so if the multipleLineEditingButton is enabled,
+ // or if the column was a blob or a text, or if it contains linebreaks.
+ BOOL useFieldEditor = NO;
+#ifndef SP_REFACTOR
+ if ([multipleLineEditingButton state] == NSOnState) useFieldEditor = YES;
+#endif
+ if (!useFieldEditor && ![[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"enum"] && isBlob) useFieldEditor = YES;
+ if (!useFieldEditor) {
+ id cellValue = [resultData cellDataAtRow:rowIndex column:[[aTableColumn identifier] integerValue]];
+ if (![cellValue isNSNull]
+ && [[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"string"]
+ && [cellValue rangeOfCharacterFromSet:[NSCharacterSet newlineCharacterSet] options:NSLiteralSearch].location != NSNotFound)
+ {
+ useFieldEditor = YES;
+ }
+ }
- if(fieldEditor) [fieldEditor release], fieldEditor = nil;
+ if (useFieldEditor) {
+ if (fieldEditor) [fieldEditor release], fieldEditor = nil;
fieldEditor = [[SPFieldEditorController alloc] init];
// Remember edited row for reselecting and setting the scroll view after reload
@@ -3829,7 +3841,7 @@
row = [customQueryView editedRow];
column = [customQueryView editedColumn];
- // Retrieve the column defintion
+ // Retrieve the column definition
NSNumber *colIdentifier = [NSArrayObjectAtIndex([customQueryView tableColumns], column) identifier];
for(id c in cqColumnDefinition) {
if([[c objectForKey:@"datacolumnindex"] isEqualToNumber:colIdentifier]) {
@@ -3869,19 +3881,23 @@
shouldBeginEditing = NO;
}
- BOOL isBlob = NO;
+ NSString *fieldType = [columnDefinition objectForKey:@"typegrouping"];
+ isFieldEditable = shouldBeginEditing;
// Check if current field is a blob
- if([[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"textdata"]
- || [[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"blobdata"])
- isBlob = YES;
- else
- isBlob = NO;
-
- isFieldEditable = shouldBeginEditing;
+ BOOL isBlob = ([fieldType isEqualToString:@"textdata"] || [fieldType isEqualToString:@"blobdata"]);
- // Check if current edited field is a blob or should be displayed in field editor sheet
- if (isBlob || [multipleLineEditingButton state] == NSOnState)
+ // Use the field editor sheet instead of inline editing if the target field is a text, blob, or binary
+ // type; if it contains linebreaks; or if the force-editing button is enabled.
+ BOOL useFieldEditor = NO;
+#ifndef SP_REFACTOR
+ if ([multipleLineEditingButton state] == NSOnState) useFieldEditor = YES;
+#endif
+ if (!useFieldEditor && fieldType && ![fieldType isEqualToString:@"enum"] && isBlob) useFieldEditor = YES;
+ if (!useFieldEditor && [[aFieldEditor string] rangeOfCharacterFromSet:[NSCharacterSet newlineCharacterSet]].location != NSNotFound) useFieldEditor = YES;
+
+ // Open the field editor sheet if required
+ if (useFieldEditor)
{
[customQueryView setFieldEditorSelectedRange:[aFieldEditor selectedRange]];