From 2c3a59464192a1f942c36fcc08d1b452eca3f059 Mon Sep 17 00:00:00 2001 From: Max Date: Thu, 9 Feb 2017 21:11:14 +0100 Subject: Fix display of column type in FieldEditorController for JSON type (part of #2199) --- Source/SPFieldEditorController.m | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'Source/SPFieldEditorController.m') diff --git a/Source/SPFieldEditorController.m b/Source/SPFieldEditorController.m index 8c5c72ae..a32f32dc 100644 --- a/Source/SPFieldEditorController.m +++ b/Source/SPFieldEditorController.m @@ -249,7 +249,8 @@ typedef enum { if ([fieldType length]) [label appendString:fieldType]; - if (maxTextLength > 0) + //skip length for JSON type since it's a constant and MySQL doesn't display it either + if (maxTextLength > 0 && ![[fieldType uppercaseString] isEqualToString:SPMySQLJsonType]) [label appendFormat:@"(%lld) ", maxTextLength]; if (!_allowNULL) -- cgit v1.2.3 From ffe8c1326860b9510619f0efbbfe97be746c6956 Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 12 Feb 2017 03:59:59 +0100 Subject: Fix a minor memory leak --- Source/SPFieldEditorController.m | 1 + 1 file changed, 1 insertion(+) (limited to 'Source/SPFieldEditorController.m') diff --git a/Source/SPFieldEditorController.m b/Source/SPFieldEditorController.m index a32f32dc..07d3980f 100644 --- a/Source/SPFieldEditorController.m +++ b/Source/SPFieldEditorController.m @@ -195,6 +195,7 @@ typedef enum { } #endif + [self setEditedFieldInfo:nil]; if ( sheetEditData ) SPClear(sheetEditData); #ifndef SP_CODA if ( qlTypes ) SPClear(qlTypes); -- cgit v1.2.3 From 618e84a46786b90f731ad963c5e14ea78dcfe58e Mon Sep 17 00:00:00 2001 From: Max Lohrmann Date: Sun, 12 Feb 2017 18:33:06 +0100 Subject: * Add a JSON formatter * MySQL JSON type columns are now automatically formatted when opening them in the Field Editor --- Source/SPFieldEditorController.m | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) (limited to 'Source/SPFieldEditorController.m') diff --git a/Source/SPFieldEditorController.m b/Source/SPFieldEditorController.m index a32f32dc..19668d74 100644 --- a/Source/SPFieldEditorController.m +++ b/Source/SPFieldEditorController.m @@ -37,6 +37,7 @@ #include #import "SPCustomQuery.h" #import "SPTableContent.h" +#import "SPJSONFormatter.h" #import @@ -237,6 +238,7 @@ typedef enum { callerInstance = sender; _isGeometry = ([[fieldType uppercaseString] isEqualToString:@"GEOMETRY"]) ? YES : NO; + _isJSON = ([[fieldType uppercaseString] isEqualToString:SPMySQLJsonType]); // Set field label NSMutableString *label = [NSMutableString string]; @@ -250,7 +252,7 @@ typedef enum { [label appendString:fieldType]; //skip length for JSON type since it's a constant and MySQL doesn't display it either - if (maxTextLength > 0 && ![[fieldType uppercaseString] isEqualToString:SPMySQLJsonType]) + if (maxTextLength > 0 && !_isJSON) [label appendFormat:@"(%lld) ", maxTextLength]; if (!_allowNULL) @@ -353,7 +355,8 @@ typedef enum { encoding = anEncoding; - _isBlob = isFieldBlob; + // we don't want the hex/image controls for JSON + _isBlob = (!_isJSON && isFieldBlob); BOOL isBinary = ([[fieldType uppercaseString] isEqualToString:@"BINARY"] || [[fieldType uppercaseString] isEqualToString:@"VARBINARY"]); @@ -443,7 +446,18 @@ typedef enum { [editTextScrollView setHidden:NO]; } else { - stringValue = [sheetEditData retain]; + // If the input is a JSON type column we can format it. + // Since MySQL internally stores JSON in binary, it does not retain any formatting + do { + if(_isJSON) { + NSString *formatted = [SPJSONFormatter stringByFormattingString:sheetEditData]; + if(formatted) { + stringValue = [formatted retain]; + break; + } + } + stringValue = [sheetEditData retain]; + } while(0); [hexTextView setString:@""]; @@ -652,6 +666,12 @@ typedef enum { if(callerInstance) { id returnData = ( editSheetReturnCode && _isEditable ) ? (_isGeometry) ? [editTextView string] : sheetEditData : nil; + //for MySQLs JSON type remove the formatting again, since it won't be stored anyway + if(_isJSON) { + NSString *unformatted = [SPJSONFormatter stringByUnformattingString:returnData]; + if(unformatted) returnData = unformatted; + } + #ifdef SP_CODA /* patch */ if ( [callerInstance isKindOfClass:[SPCustomQuery class]] ) [(SPCustomQuery*)callerInstance processFieldEditorResult:returnData contextInfo:contextInfo]; -- cgit v1.2.3 From aee6a009a5355aa3c7c91f885685868e5294e71c Mon Sep 17 00:00:00 2001 From: Max Date: Sun, 12 Feb 2017 19:06:31 +0100 Subject: Fix an erroneous if condition (#2688) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In some rare cases this could have resulted in an unexpected „No data was updated“ error message --- Source/SPFieldEditorController.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'Source/SPFieldEditorController.m') diff --git a/Source/SPFieldEditorController.m b/Source/SPFieldEditorController.m index 21a220c7..0298973d 100644 --- a/Source/SPFieldEditorController.m +++ b/Source/SPFieldEditorController.m @@ -1380,7 +1380,7 @@ typedef enum { if([notification object] == editTextView) { // Do nothing if user really didn't changed text (e.g. for font size changing return) if(!editTextViewWasChanged && (editSheetWillBeInitialized - || (([[[notification object] textStorage] editedRange].length == 0) + || (([[[notification object] textStorage] editedRange].location == NSNotFound) && ([[[notification object] textStorage] changeInLength] == 0)))) { // Inform the undo-grouping about the caret movement selectionChanged = YES; -- cgit v1.2.3