aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Interfaces/English.lproj/FieldEditorSheet.xib6
-rw-r--r--Source/CustomQuery.m124
-rw-r--r--Source/SPFieldEditorController.m13
3 files changed, 57 insertions, 86 deletions
diff --git a/Interfaces/English.lproj/FieldEditorSheet.xib b/Interfaces/English.lproj/FieldEditorSheet.xib
index e4f5ccdf..7a19f1a6 100644
--- a/Interfaces/English.lproj/FieldEditorSheet.xib
+++ b/Interfaces/English.lproj/FieldEditorSheet.xib
@@ -464,6 +464,7 @@
</object>
<string key="NSFrameSize">{667, 370}</string>
<reference key="NSSuperview" ref="983787914"/>
+ <reference key="NSNextKeyView" ref="459839028"/>
<reference key="NSDocView" ref="459839028"/>
<reference key="NSBGColor" ref="940290613"/>
<object class="NSCursor" key="NSCursor" id="956874367">
@@ -496,6 +497,7 @@
</object>
<string key="NSFrame">{{0, 39}, {667, 370}}</string>
<reference key="NSSuperview" ref="559857537"/>
+ <reference key="NSNextKeyView" ref="1068411389"/>
<int key="NSsFlags">528</int>
<reference key="NSVScroller" ref="977735067"/>
<reference key="NSHScroller" ref="426249328"/>
@@ -612,6 +614,7 @@
</object>
<string key="NSFrameSize">{667, 370}</string>
<reference key="NSSuperview" ref="604699677"/>
+ <reference key="NSNextKeyView" ref="702566211"/>
<reference key="NSDocView" ref="702566211"/>
<reference key="NSBGColor" ref="940290613"/>
<reference key="NSCursor" ref="956874367"/>
@@ -641,6 +644,7 @@
</object>
<string key="NSFrame">{{0, 39}, {667, 370}}</string>
<reference key="NSSuperview" ref="559857537"/>
+ <reference key="NSNextKeyView" ref="967441740"/>
<int key="NSsFlags">528</int>
<reference key="NSVScroller" ref="699979333"/>
<reference key="NSHScroller" ref="393370468"/>
@@ -684,7 +688,7 @@
<string key="NSScreenRect">{{0, 0}, {1280, 778}}</string>
<string key="NSMinSize">{560, 222}</string>
<string key="NSMaxSize">{3.40282e+38, 3.40282e+38}</string>
- <string key="NSFrameAutosaveName">SPEditSheet</string>
+ <string key="NSFrameAutosaveName"/>
</object>
</object>
<object class="IBObjectContainer" key="IBDocument.Objects">
diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m
index 461dfba8..1626c6e5 100644
--- a/Source/CustomQuery.m
+++ b/Source/CustomQuery.m
@@ -34,6 +34,7 @@
#import "TableDocument.h"
#import "TablesList.h"
#import "RegexKitLite.h"
+#import "SPFieldEditorController.h"
#define SP_MYSQL_DEV_SEARCH_URL @"http://search.mysql.com/search?q=%@&site=refman-%@"
#define SP_HELP_SEARCH_IN_MYSQL 0
@@ -1541,94 +1542,59 @@
// Check if the field can identified bijectively
if ( aTableView == customQueryView ) {
- // TODO: only for testing
- if([[NSApp currentEvent] modifierFlags] & NSCommandKeyMask) {
- if(!tempAlertWasShown) {
- NSRunCriticalAlertPanel (
- @"ATTENTION – ONLY FOR TESTING",
- @"Editing result fields in Custom Query is a BETA feature!\n\nPlease DO NOT USE that feature in production!\n\nAnyway we'd be glad if you take a bit time to test that feature on TEST data.\n\nThank you very much for testing.\n\nThe Sequel-Pro team",
- @"OK",
- nil,
- nil);
- tempAlertWasShown = YES;
- }
- NSDictionary *columnDefinition;
+ NSDictionary *columnDefinition;
+ BOOL noTableName = NO;
+ BOOL isBlob;
- // Retrieve the column defintion
- for(id c in cqColumnDefinition) {
- if([[c objectForKey:@"datacolumnindex"] isEqualToNumber:[aTableColumn identifier]]) {
- columnDefinition = [NSDictionary dictionaryWithDictionary:c];
- break;
- }
+ // Retrieve the column defintion
+ for(id c in cqColumnDefinition) {
+ if([[c objectForKey:@"datacolumnindex"] isEqualToNumber:[aTableColumn identifier]]) {
+ columnDefinition = [NSDictionary dictionaryWithDictionary:c];
+ break;
}
+ }
+ // Check if current field is a blob
+ if([[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"textdata"]
+ || [[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"blobdata"]) {
+ isBlob = YES;
+ } else {
+ isBlob = NO;
+ }
- // Check if current field is a blob
- if([[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"textdata"]
- || [[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"blobdata"]) {
- [errorText setStringValue:@"Editing blob data not yet supported."];
- NSBeep();
- return NO;
- }
-
- // Resolve the original table name for current column if AS was used
- NSString *tableForColumn = [columnDefinition objectForKey:@"org_table"];
-
- // No table name found indicates that the field's column contains data from more than one table as for UNION
- // or the field data are not bound to any table as in SELECT 1
- if(!tableForColumn || ![tableForColumn length]) {
- [errorText setStringValue:[NSString stringWithFormat:@"Couldn't identify field origin unambiguously. The column '%@' contains data from more or less than one table.", [columnDefinition objectForKey:@"name"]]];
- NSBeep();
- return NO;
- }
-
- NSString *fieldIDQueryString = [self argumentForRow:rowIndex ofTable:tableForColumn];
+ // Resolve the original table name for current column if AS was used
+ NSString *tableForColumn = [columnDefinition objectForKey:@"org_table"];
- // Actual check whether field can be identified bijectively
- int numberOfPossibleUpdateRows = [[[[mySQLConnection queryString:[NSString stringWithFormat:@"SELECT COUNT(*) FROM %@ %@", [tableForColumn backtickQuotedString], fieldIDQueryString]] fetchRowAsArray] objectAtIndex:0] intValue];
- if (numberOfPossibleUpdateRows == 1)
- return YES;
- else {
- [errorText setStringValue:[NSString stringWithFormat:@"Field is not editable. Couldn't identify field origin unambiguously (%d match%@).", numberOfPossibleUpdateRows, (numberOfPossibleUpdateRows>1)?@"es":@""]];
- NSBeep();
- return NO;
- }
- }
- // TODO: keep old behaviour for testing
- else {
- id theRow;
- NSString *theValue;
-
- //get the value
- theRow = [fullResult objectAtIndex:rowIndex];
-
- if ( [[theRow objectAtIndex:[[aTableColumn identifier] intValue]] isKindOfClass:[NSData class]] ) {
- theValue = [[NSString alloc] initWithData:[theRow objectAtIndex:[[aTableColumn identifier] intValue]]
- encoding:[mySQLConnection encoding]];
- if (theValue == nil) {
- theValue = [[NSString alloc] initWithData:[theRow objectAtIndex:[[aTableColumn identifier] intValue]]
- encoding:NSASCIIStringEncoding];
- }
- [theValue autorelease];
- } else if ( [[theRow objectAtIndex:[[aTableColumn identifier] intValue]] isMemberOfClass:[NSNull class]] ) {
- theValue = [prefs objectForKey:@"NullValue"];
- } else {
- theValue = [theRow objectAtIndex:[[aTableColumn identifier] intValue]];
- }
-
- [valueTextField setString:[theValue description]];
- [valueTextField selectAll:self];
- [NSApp beginSheet:valueSheet
- modalForWindow:tableWindow modalDelegate:self
- didEndSelector:nil contextInfo:nil];
- [NSApp runModalForWindow:valueSheet];
+ // No table name found indicates that the field's column contains data from more than one table as for UNION
+ // or the field data are not bound to any table as in SELECT 1
+ if(!tableForColumn || ![tableForColumn length])
+ noTableName = YES;
- [NSApp endSheet:valueSheet];
- [valueSheet orderOut:nil];
+ NSString *fieldIDQueryString = [self argumentForRow:rowIndex ofTable:tableForColumn];
- return NO;
+ // Actual check whether field can be identified bijectively
+ int numberOfPossibleUpdateRows = [[[[mySQLConnection queryString:[NSString stringWithFormat:@"SELECT COUNT(*) FROM %@ %@", [tableForColumn backtickQuotedString], fieldIDQueryString]] fetchRowAsArray] objectAtIndex:0] intValue];
+
+ BOOL isFieldEditable = (!noTableName && numberOfPossibleUpdateRows == 1) ? YES : NO;
+
+ // if(!isFieldEditable)
+ // [errorText setStringValue:[NSString stringWithFormat:@"Field is not editable. Couldn't identify field origin unambiguously (%d match%@).", numberOfPossibleUpdateRows, (numberOfPossibleUpdateRows>1)?@"es":@""]];
+
+ SPFieldEditorController *fieldEditor = [[SPFieldEditorController alloc] init];
+ id editData = [[fieldEditor editWithObject:[[fullResult objectAtIndex:rowIndex] objectAtIndex:[[aTableColumn identifier] intValue]]
+ usingEncoding:[mySQLConnection encoding] isObjectBlob:isBlob isEditable:NO withWindow:tableWindow] retain];
+
+ if ( editData ) {
+
}
+
+ [fieldEditor release];
+
+ if ( editData ) [editData release];
+
+ return NO;
+
} else {
return YES;
}
diff --git a/Source/SPFieldEditorController.m b/Source/SPFieldEditorController.m
index af5addf9..085a4933 100644
--- a/Source/SPFieldEditorController.m
+++ b/Source/SPFieldEditorController.m
@@ -72,16 +72,14 @@
if(!isEditable) {
[editSheetOkButton setTitle:NSLocalizedString(@"Close", @"close button title")];
+ [editSheetOkButton setKeyEquivalent:@"\033"]; // ESC key
[editSheetCancelButton setHidden:YES];
[editSheetOpenButton setEnabled:NO];
- } else {
- [editSheetOkButton setTitle:NSLocalizedString(@"OK", @"ok button title")];
- [editSheetCancelButton setHidden:NO];
- [editSheetOpenButton setEnabled:YES];
}
editSheetWillBeInitialized = YES;
+
encoding = anEncoding;
isBlob = isFieldBlob;
@@ -100,10 +98,13 @@
[editSheetSegmentControl setHidden:(!isBlob)];
// Set window's min size since no segment and quicklook buttons are hidden
- if(isBlob)
+ if(isBlob) {
+ [editSheet setFrameAutosaveName:@"SPFieldEditorBlobSheet"];
[editSheet setMinSize:NSMakeSize(560, 200)];
- else
+ } else {
+ [editSheet setFrameAutosaveName:@"SPFieldEditorTextSheet"];
[editSheet setMinSize:NSMakeSize(340, 150)];
+ }
[editTextView setEditable:isEditable];
[editImage setEditable:isEditable];