From dcd0413d4cc106d1efe17cc225be7c325081a113 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Sun, 22 Aug 2010 21:59:43 +0000 Subject: =?UTF-8?q?=E2=80=A2=C2=A0first=20preparations=20to=20allow=20in?= =?UTF-8?q?=20cell=20editing=20in=20Custom=20Query=20(not=20yet=20active)?= =?UTF-8?q?=20=E2=80=A2=20view=20data=20editing=20-=20disable=20add/duplic?= =?UTF-8?q?ate/remove=20row=20for=20views=20-=20first=20improvements=20for?= =?UTF-8?q?=20editing=20navigation=20via=20keyboard=20-=20after=20editing?= =?UTF-8?q?=20avoid=20relaodTable=20instead=20use=20loadTableValues=20-=20?= =?UTF-8?q?outsourced:=20(NSInteger)fieldEditStatusForRow:andColumn:=20sin?= =?UTF-8?q?ce=20it=20will=20be=20used=20for=20keyboard=20editing=20navigat?= =?UTF-8?q?ion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interfaces/English.lproj/DBView.xib | 927 +++++++++++++++++++++++++++++++----- Source/SPCustomQuery.m | 49 +- Source/SPTableContent.h | 3 + Source/SPTableContent.m | 352 ++++++++------ 4 files changed, 1044 insertions(+), 287 deletions(-) diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib index 577c1e6b..d35fb900 100644 --- a/Interfaces/English.lproj/DBView.xib +++ b/Interfaces/English.lproj/DBView.xib @@ -23,6 +23,7 @@ YES + YES @@ -51,7 +52,7 @@ NSApplication - + 274 YES @@ -944,7 +945,7 @@ source - + 256 YES @@ -2230,7 +2231,6 @@ {{10, 7}, {706, 544}} - Structure @@ -2530,11 +2530,11 @@ -935051009 35 - + NSImage button_edit_mode - + NSImage button_edit_mode_selected @@ -2987,7 +2987,7 @@ customQuery - + 256 YES @@ -3021,7 +3021,7 @@ 266 - {{68, 1}, {611, 17}} + {{97, 1}, {582, 17}} YES @@ -3115,6 +3115,28 @@ YES + + + -2147483356 + {{62, -1}, {32, 25}} + + YES + + 67239424 + 134217728 + + + + -935051009 + 35 + + + + + 400 + 75 + + {{6, 11}, {696, 23}} @@ -3156,6 +3178,29 @@ 6418 + + YES + + YES + Apple HTML pasteboard type + Apple PDF pasteboard type + Apple PICT pasteboard type + Apple PNG pasteboard type + Apple URL pasteboard type + CorePasteboardFlavorType 0x6D6F6F76 + NSColor pasteboard type + NSFilenamesPboardType + NSStringPboardType + NeXT Encapsulated PostScript v1.2 pasteboard type + NeXT RTFD pasteboard type + NeXT Rich Text Format v1.0 pasteboard type + NeXT TIFF v4.0 pasteboard type + NeXT font pasteboard type + NeXT ruler pasteboard type + WebURLsWithTitlesPboardType + public.url + + {{0, 2}, {694, 14}} @@ -4141,6 +4186,7 @@ {{10, 7}, {706, 544}} + Custom Query @@ -5930,14 +5976,14 @@ - + 134217731 YES YES YES - + @@ -5954,6 +6000,7 @@ {943, 549} + NSView @@ -14499,6 +14546,30 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 7462 + + + value: values.EditInSheetEnabled + + + + + + value: values.EditInSheetEnabled + value + values.EditInSheetEnabled + 2 + + + 7465 + + + + multipleLineEditingButton + + + + 7466 + @@ -14549,7 +14620,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 134 - CustomQuery + SPCustomQuery 362 @@ -19619,6 +19690,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 + @@ -20391,6 +20463,20 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 + + 7463 + + + YES + + + + + + 7464 + + + @@ -21576,6 +21662,9 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 7457.IBAttributePlaceholdersKey 7457.IBPluginDependency 7458.IBPluginDependency + 7463.IBAttributePlaceholdersKey + 7463.IBPluginDependency + 7464.IBPluginDependency 748.IBPluginDependency 748.ImportedFromIB2 749.IBPluginDependency @@ -22912,7 +23001,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{52, 230}, {943, 549}} + {{337, 160}, {943, 549}} com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -23192,6 +23281,16 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + + ToolTip + + ToolTip + + Toggle between editing simple text cells as a spreadsheet or in pop-up sheets + + + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -23234,7 +23333,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 - 7462 + 7466 @@ -27940,127 +28039,699 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 - + YES - BWAnchoredButton - NSButton - - IBFrameworkSource - BWToolkitFramework.framework/Headers/BWAnchoredButton.h - - - - BWAnchoredButtonBar - NSView - - IBFrameworkSource - BWToolkitFramework.framework/Headers/BWAnchoredButtonBar.h - - - - BWAnchoredButtonCell - NSButtonCell - - IBFrameworkSource - BWToolkitFramework.framework/Headers/BWAnchoredButtonCell.h - - - - BWAnchoredPopUpButton - NSPopUpButton - - IBFrameworkSource - BWToolkitFramework.framework/Headers/BWAnchoredPopUpButton.h - - - - BWAnchoredPopUpButtonCell - NSPopUpButtonCell - - IBFrameworkSource - BWToolkitFramework.framework/Headers/BWAnchoredPopUpButtonCell.h - - - - BWGradientBox - NSView - - IBFrameworkSource - BWToolkitFramework.framework/Headers/BWGradientBox.h - - - - BWInsetTextField - NSTextField - - IBFrameworkSource - BWToolkitFramework.framework/Headers/BWInsetTextField.h - - - - BWSplitView - NSSplitView + SPCustomQuery + NSObject - toggleCollapse: - id + YES + + YES + chooseQueryFavorite: + chooseQueryHistory: + clearQueryHistory: + closeSheet: + copyQueryHistory: + filterQueryFavorites: + filterQueryHistory: + gearMenuItemSelected: + helpSearchFindNextInPage: + helpSearchFindPreviousInPage: + helpSegmentDispatcher: + helpSelectHelpTargetMySQL: + helpSelectHelpTargetPage: + helpSelectHelpTargetWeb: + helpTargetDispatcher: + runAllQueries: + runSelectedQueries: + saveQueryHistory: + showAutoHelpForCurrentWord: + showCompletionList: + showHelpForCurrentWord: + showHelpForSearchString: + toggleQueryInfoPaneCollapse: + + + YES + id + id + id + id + id + id + id + id + id + id + id + id + id + id + id + id + id + id + id + id + id + id + id + - toggleCollapse: - - toggleCollapse: - id + YES + + YES + chooseQueryFavorite: + chooseQueryHistory: + clearQueryHistory: + closeSheet: + copyQueryHistory: + filterQueryFavorites: + filterQueryHistory: + gearMenuItemSelected: + helpSearchFindNextInPage: + helpSearchFindPreviousInPage: + helpSegmentDispatcher: + helpSelectHelpTargetMySQL: + helpSelectHelpTargetPage: + helpSelectHelpTargetWeb: + helpTargetDispatcher: + runAllQueries: + runSelectedQueries: + saveQueryHistory: + showAutoHelpForCurrentWord: + showCompletionList: + showHelpForCurrentWord: + showHelpForSearchString: + toggleQueryInfoPaneCollapse: - - - IBFrameworkSource - BWToolkitFramework.framework/Headers/BWSplitView.h - - - - NSActionCell - NSCell - - IBFrameworkSource - AppKit.framework/Headers/NSActionCell.h - - - - NSApplication - NSResponder - - IBFrameworkSource - AppKit.framework/Headers/NSApplication.h - - - - NSApplication - - IBFrameworkSource - AppKit.framework/Headers/NSApplicationScripting.h - - - - NSApplication - - IBFrameworkSource - AppKit.framework/Headers/NSColorPanel.h - - - - NSApplication - - IBFrameworkSource - AppKit.framework/Headers/NSHelpManager.h - - - - NSApplication - - IBFrameworkSource - AppKit.framework/Headers/NSPageLayout.h - - + + YES + + chooseQueryFavorite: + id + + + chooseQueryHistory: + id + + + clearQueryHistory: + id + + + closeSheet: + id + + + copyQueryHistory: + id + + + filterQueryFavorites: + id + + + filterQueryHistory: + id + + + gearMenuItemSelected: + id + + + helpSearchFindNextInPage: + id + + + helpSearchFindPreviousInPage: + id + + + helpSegmentDispatcher: + id + + + helpSelectHelpTargetMySQL: + id + + + helpSelectHelpTargetPage: + id + + + helpSelectHelpTargetWeb: + id + + + helpTargetDispatcher: + id + + + runAllQueries: + id + + + runSelectedQueries: + id + + + saveQueryHistory: + id + + + showAutoHelpForCurrentWord: + id + + + showCompletionList: + id + + + showHelpForCurrentWord: + id + + + showHelpForSearchString: + id + + + toggleQueryInfoPaneCollapse: + id + + + + + YES + + YES + affectedRowsText + autohelpMenuItem + autoindentMenuItem + autopairMenuItem + autouppercaseKeywordsMenuItem + clearHistoryMenuItem + commentCurrentQueryMenuItem + commentLineOrSelectionMenuItem + completionListMenuItem + copyHistoryMenuItem + customQueryScrollView + customQueryView + editorFontMenuItem + encodingPopUp + errorText + helpNavigator + helpSearchField + helpSearchFieldCell + helpTargetSelector + helpWebView + helpWebViewWindow + multipleLineEditingButton + nextHistoryMenuItem + previousHistoryMenuItem + queryFavoriteNameTextField + queryFavoritesButton + queryFavoritesSaveAllMenuItem + queryFavoritesSaveAsMenuItem + queryFavoritesSearchField + queryFavoritesSearchFieldView + queryFavoritesSearchMenuItem + queryFavoritesSheet + queryHistoryButton + queryHistorySearchField + queryHistorySearchFieldView + queryHistorySearchMenuItem + queryInfoButton + queryInfoPaneSplitView + runAllButton + runAllMenuItem + runSelectionButton + runSelectionMenuItem + saveHistoryMenuItem + saveQueryFavoriteButton + saveQueryFavoriteGlobal + shiftLeftMenuItem + shiftRightMenuItem + tableDocumentInstance + tablesListInstance + textView + valueSheet + valueTextField + + + YES + id + NSMenuItem + NSMenuItem + NSMenuItem + NSMenuItem + NSMenuItem + NSMenuItem + NSMenuItem + NSMenuItem + NSMenuItem + NSScrollView + SPCopyTable + NSMenuItem + NSPopUpButton + id + NSSegmentedControl + NSSearchField + NSSearchFieldCell + NSSegmentedControl + WebView + NSWindow + id + NSMenuItem + NSMenuItem + NSTextField + id + NSMenuItem + NSMenuItem + NSSearchField + id + NSMenuItem + NSWindow + id + NSSearchField + id + NSMenuItem + NSButton + BWSplitView + id + NSMenuItem + id + NSMenuItem + NSMenuItem + NSButton + id + NSMenuItem + NSMenuItem + id + id + SPTextView + id + id + + + + YES + + YES + affectedRowsText + autohelpMenuItem + autoindentMenuItem + autopairMenuItem + autouppercaseKeywordsMenuItem + clearHistoryMenuItem + commentCurrentQueryMenuItem + commentLineOrSelectionMenuItem + completionListMenuItem + copyHistoryMenuItem + customQueryScrollView + customQueryView + editorFontMenuItem + encodingPopUp + errorText + helpNavigator + helpSearchField + helpSearchFieldCell + helpTargetSelector + helpWebView + helpWebViewWindow + multipleLineEditingButton + nextHistoryMenuItem + previousHistoryMenuItem + queryFavoriteNameTextField + queryFavoritesButton + queryFavoritesSaveAllMenuItem + queryFavoritesSaveAsMenuItem + queryFavoritesSearchField + queryFavoritesSearchFieldView + queryFavoritesSearchMenuItem + queryFavoritesSheet + queryHistoryButton + queryHistorySearchField + queryHistorySearchFieldView + queryHistorySearchMenuItem + queryInfoButton + queryInfoPaneSplitView + runAllButton + runAllMenuItem + runSelectionButton + runSelectionMenuItem + saveHistoryMenuItem + saveQueryFavoriteButton + saveQueryFavoriteGlobal + shiftLeftMenuItem + shiftRightMenuItem + tableDocumentInstance + tablesListInstance + textView + valueSheet + valueTextField + + + YES + + affectedRowsText + id + + + autohelpMenuItem + NSMenuItem + + + autoindentMenuItem + NSMenuItem + + + autopairMenuItem + NSMenuItem + + + autouppercaseKeywordsMenuItem + NSMenuItem + + + clearHistoryMenuItem + NSMenuItem + + + commentCurrentQueryMenuItem + NSMenuItem + + + commentLineOrSelectionMenuItem + NSMenuItem + + + completionListMenuItem + NSMenuItem + + + copyHistoryMenuItem + NSMenuItem + + + customQueryScrollView + NSScrollView + + + customQueryView + SPCopyTable + + + editorFontMenuItem + NSMenuItem + + + encodingPopUp + NSPopUpButton + + + errorText + id + + + helpNavigator + NSSegmentedControl + + + helpSearchField + NSSearchField + + + helpSearchFieldCell + NSSearchFieldCell + + + helpTargetSelector + NSSegmentedControl + + + helpWebView + WebView + + + helpWebViewWindow + NSWindow + + + multipleLineEditingButton + id + + + nextHistoryMenuItem + NSMenuItem + + + previousHistoryMenuItem + NSMenuItem + + + queryFavoriteNameTextField + NSTextField + + + queryFavoritesButton + id + + + queryFavoritesSaveAllMenuItem + NSMenuItem + + + queryFavoritesSaveAsMenuItem + NSMenuItem + + + queryFavoritesSearchField + NSSearchField + + + queryFavoritesSearchFieldView + id + + + queryFavoritesSearchMenuItem + NSMenuItem + + + queryFavoritesSheet + NSWindow + + + queryHistoryButton + id + + + queryHistorySearchField + NSSearchField + + + queryHistorySearchFieldView + id + + + queryHistorySearchMenuItem + NSMenuItem + + + queryInfoButton + NSButton + + + queryInfoPaneSplitView + BWSplitView + + + runAllButton + id + + + runAllMenuItem + NSMenuItem + + + runSelectionButton + id + + + runSelectionMenuItem + NSMenuItem + + + saveHistoryMenuItem + NSMenuItem + + + saveQueryFavoriteButton + NSButton + + + saveQueryFavoriteGlobal + id + + + shiftLeftMenuItem + NSMenuItem + + + shiftRightMenuItem + NSMenuItem + + + tableDocumentInstance + id + + + tablesListInstance + id + + + textView + SPTextView + + + valueSheet + id + + + valueTextField + id + + + + + IBDocumentRelativeSource + ../../Source/SPCustomQuery.h + + + + + YES + + BWAnchoredButton + NSButton + + IBFrameworkSource + BWToolkitFramework.framework/Headers/BWAnchoredButton.h + + + + BWAnchoredButtonBar + NSView + + IBFrameworkSource + BWToolkitFramework.framework/Headers/BWAnchoredButtonBar.h + + + + BWAnchoredButtonCell + NSButtonCell + + IBFrameworkSource + BWToolkitFramework.framework/Headers/BWAnchoredButtonCell.h + + + + BWAnchoredPopUpButton + NSPopUpButton + + IBFrameworkSource + BWToolkitFramework.framework/Headers/BWAnchoredPopUpButton.h + + + + BWAnchoredPopUpButtonCell + NSPopUpButtonCell + + IBFrameworkSource + BWToolkitFramework.framework/Headers/BWAnchoredPopUpButtonCell.h + + + + BWGradientBox + NSView + + IBFrameworkSource + BWToolkitFramework.framework/Headers/BWGradientBox.h + + + + BWInsetTextField + NSTextField + + IBFrameworkSource + BWToolkitFramework.framework/Headers/BWInsetTextField.h + + + + BWSplitView + NSSplitView + + toggleCollapse: + id + + + toggleCollapse: + + toggleCollapse: + id + + + + IBFrameworkSource + BWToolkitFramework.framework/Headers/BWSplitView.h + + + + NSActionCell + NSCell + + IBFrameworkSource + AppKit.framework/Headers/NSActionCell.h + + + + NSApplication + NSResponder + + IBFrameworkSource + AppKit.framework/Headers/NSApplication.h + + + + NSApplication + + IBFrameworkSource + AppKit.framework/Headers/NSApplicationScripting.h + + + + NSApplication + + IBFrameworkSource + AppKit.framework/Headers/NSColorPanel.h + + + + NSApplication + + IBFrameworkSource + AppKit.framework/Headers/NSHelpManager.h + + + + NSApplication + + IBFrameworkSource + AppKit.framework/Headers/NSPageLayout.h + + NSApplication @@ -29004,7 +29675,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 YES - {15, 15} + {10, 10} {8, 8} {32, 32} {128, 128} diff --git a/Source/SPCustomQuery.m b/Source/SPCustomQuery.m index 80ec1c33..c7e0a9bf 100644 --- a/Source/SPCustomQuery.m +++ b/Source/SPCustomQuery.m @@ -1766,7 +1766,8 @@ NSString *columnName = [columnDefinition objectForKey:@"org_name"]; // NSString *fieldIDQueryString = [self argumentForRow:rowIndex ofTable:tableForColumn]; - + fieldIDQueryString = [self argumentForRow:rowIndex ofTable:tableForColumn andDatabase:[columnDefinition objectForKey:@"db"]]; + // Check if the IDstring identifies the current field bijectively NSInteger numberOfPossibleUpdateRows = [[[[mySQLConnection queryString:[NSString stringWithFormat:@"SELECT COUNT(1) FROM %@.%@ %@", [[columnDefinition objectForKey:@"db"] backtickQuotedString], [tableForColumn backtickQuotedString], fieldIDQueryString]] fetchRowAsArray] objectAtIndex:0] integerValue]; if(numberOfPossibleUpdateRows == 1) { @@ -2149,36 +2150,40 @@ [errorText setStringValue:NSLocalizedString(@"Field is not editable. Field has no or multiple table or database origin(s).",@"field is not editable due to no table/database")]; } + // if ([multipleLineEditingButton state] == NSOnState || isBlob) { - SPFieldEditorController *fieldEditor = [[SPFieldEditorController alloc] init]; + SPFieldEditorController *fieldEditor = [[SPFieldEditorController alloc] init]; - // Remember edited row for reselecting and setting the scroll view after reload - editedRow = rowIndex; - editedScrollViewRect = [customQueryScrollView documentVisibleRect]; + // Remember edited row for reselecting and setting the scroll view after reload + editedRow = rowIndex; + editedScrollViewRect = [customQueryScrollView documentVisibleRect]; - // Set max text length - if ([[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"string"] - && [columnDefinition valueForKey:@"char_length"]) - [fieldEditor setTextMaxLength:[[columnDefinition valueForKey:@"char_length"] integerValue]]; + // Set max text length + if ([[columnDefinition objectForKey:@"typegrouping"] isEqualToString:@"string"] + && [columnDefinition valueForKey:@"char_length"]) + [fieldEditor setTextMaxLength:[[columnDefinition valueForKey:@"char_length"] integerValue]]; - id originalData = [resultData cellDataAtRow:rowIndex column:[[aTableColumn identifier] integerValue]]; - if ([originalData isNSNull]) originalData = [prefs objectForKey:SPNullValue]; + id originalData = [resultData cellDataAtRow:rowIndex column:[[aTableColumn identifier] integerValue]]; + if ([originalData isNSNull]) originalData = [prefs objectForKey:SPNullValue]; - id editData = [[fieldEditor editWithObject:originalData - fieldName:[columnDefinition objectForKey:@"name"] - usingEncoding:[mySQLConnection encoding] - isObjectBlob:isBlob - isEditable:isFieldEditable - withWindow:[tableDocumentInstance parentWindow]] retain]; + id editData = [[fieldEditor editWithObject:originalData + fieldName:[columnDefinition objectForKey:@"name"] + usingEncoding:[mySQLConnection encoding] + isObjectBlob:isBlob + isEditable:isFieldEditable + withWindow:[tableDocumentInstance parentWindow]] retain]; - if ( editData ) - [self tableView:aTableView setObjectValue:[editData copy] forTableColumn:aTableColumn row:rowIndex]; + if ( editData ) + [self tableView:aTableView setObjectValue:[editData copy] forTableColumn:aTableColumn row:rowIndex]; - [fieldEditor release]; + [fieldEditor release]; - if ( editData ) [editData release]; + if ( editData ) [editData release]; - return NO; + return NO; + + // } + return isFieldEditable; } else { return YES; diff --git a/Source/SPTableContent.h b/Source/SPTableContent.h index 51a01520..b1748c2d 100644 --- a/Source/SPTableContent.h +++ b/Source/SPTableContent.h @@ -105,6 +105,7 @@ NSArray *cqColumnDefinition; NSString *fieldIDQueryString; + BOOL isFirstChangeInView; } @@ -183,4 +184,6 @@ - (void)openContentFilterManager; - (void)makeContentFilterHaveFocus; +- (NSInteger)fieldEditStatusForRow:(NSInteger)rowIndex andColumn:(NSInteger)columnIndex; + @end diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m index 7b012f45..9e50bb67 100644 --- a/Source/SPTableContent.m +++ b/Source/SPTableContent.m @@ -91,6 +91,7 @@ secondBetweenValueToRestore = nil; tableRowsSelectable = YES; contentFilterManager = nil; + isFirstChangeInView = YES; isFiltered = NO; isLimited = NO; @@ -519,7 +520,7 @@ [[tableDocumentInstance parentWindow] makeFirstResponder:currentFirstResponder]; // Set the state of the table buttons - [addButton setEnabled:enableInteraction]; + [addButton setEnabled:(enableInteraction && [tablesListInstance tableType] == SPTableTypeTable)]; [copyButton setEnabled:NO]; [removeButton setEnabled:NO]; @@ -2623,6 +2624,60 @@ } } +/* + * Check if table cell is editable + * Returns the number of possible changes or + * -1 if no table name can be found or multiple table origins + */ +- (NSInteger)fieldEditStatusForRow:(NSInteger)rowIndex andColumn:(NSInteger)columnIndex +{ + NSDictionary *columnDefinition; + + // Retrieve the column defintion + for(id c in cqColumnDefinition) { + if([[c objectForKey:@"datacolumnindex"] isEqualToNumber:columnIndex]) { + columnDefinition = [NSDictionary dictionaryWithDictionary:c]; + break; + } + } + + // Resolve the original table name for current column if AS was used + NSString *tableForColumn = [columnDefinition objectForKey:@"org_table"]; + + // Get the database name which the field belongs to + NSString *dbForColumn = [columnDefinition objectForKey:@"db"]; + + // No table/database 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 or if column database is unset + if(!tableForColumn || ![tableForColumn length] || ![dbForColumn length]) + return -1; + + // if table and database name are given check if field can be identified unambiguously + NSString *fieldIDQueryStr = [self argumentForRow:rowIndex ofTable:tableForColumn andDatabase:[columnDefinition objectForKey:@"db"]]; + if(!fieldIDQueryStr) + return -1; + + [tableDocumentInstance startTaskWithDescription:NSLocalizedString(@"Checking field data for editing...", @"checking field data for editing task description")]; + + // Actual check whether field can be identified bijectively + MCPResult *tempResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SELECT COUNT(1) FROM %@.%@ %@", + [[columnDefinition objectForKey:@"db"] backtickQuotedString], + [tableForColumn backtickQuotedString], + fieldIDQueryStr]]; + + [tableDocumentInstance endTask]; + + if ([mySQLConnection queryErrored]) + return -1; + + NSArray *tempRow = [tempResult fetchRowAsArray]; + + if(![tempRow count]) + return -1; + + return [[tempRow objectAtIndex:0] integerValue]; + +} /* * Close an open sheet. */ @@ -3095,15 +3150,14 @@ NSBeep(); return; } + // Resolve the original column name if AS was used NSString *columnName = [columnDefinition objectForKey:@"org_name"]; [tableDocumentInstance startTaskWithDescription:NSLocalizedString(@"Updating field data...", @"updating field task description")]; - - NSString *fieldIDQueryStringB = [self argumentForRow:rowIndex ofTable:tableForColumn andDatabase:[columnDefinition objectForKey:@"db"]]; - [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryWillBePerformed" object:tableDocumentInstance]; + NSString *fieldIDQueryStringB = [self argumentForRow:rowIndex ofTable:tableForColumn andDatabase:[columnDefinition objectForKey:@"db"]]; // Check if the IDstring identifies the current field bijectively NSInteger numberOfPossibleUpdateRows = [[[[mySQLConnection queryString:[NSString stringWithFormat:@"SELECT COUNT(1) FROM %@.%@ %@", [[columnDefinition objectForKey:@"db"] backtickQuotedString], [tableForColumn backtickQuotedString], fieldIDQueryStringB]] fetchRowAsArray] objectAtIndex:0] integerValue]; @@ -3138,13 +3192,12 @@ [[columnDefinition objectForKey:@"db"] backtickQuotedString], [tableForColumn backtickQuotedString], [columnName backtickQuotedString], newObject, fieldIDQueryStringB]]; - [tableDocumentInstance endTask]; - // Check for errors while UPDATE if ([mySQLConnection queryErrored]) { SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), NSLocalizedString(@"Cancel", @"cancel button"), nil, [tableDocumentInstance parentWindow], self, nil, nil, [NSString stringWithFormat:NSLocalizedString(@"Couldn't write field.\nMySQL said: %@", @"message of panel when error while updating field to db"), [mySQLConnection getLastErrorMessage]]); + [tableDocumentInstance endTask]; [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance]; return; } @@ -3158,6 +3211,7 @@ } else { NSBeep(); } + [tableDocumentInstance endTask]; [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance]; return; } @@ -3172,12 +3226,25 @@ return; } - [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance]; - [tableDocumentInstance endTask]; // Reload table after each editing due to complex declarations - [self reloadTable:self]; + if(isFirstChangeInView) { + // Set up the table details for the new table, and trigger an interface update + // if the view was modified for the very first time + NSDictionary *tableDetails = [NSDictionary dictionaryWithObjectsAndKeys: + tableForColumn, @"name", + [tableDataInstance columns], @"columns", + [tableDataInstance columnNames], @"columnNames", + [tableDataInstance getConstraints], @"constraints", + nil]; + [self performSelectorOnMainThread:@selector(setTableDetails:) withObject:tableDetails waitUntilDone:YES]; + isFirstChangeInView = NO; + } + [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance]; + [tableDocumentInstance endTask]; + + [self loadTableValues]; return; @@ -3277,6 +3344,12 @@ - (void)tableViewSelectionDidChange:(NSNotification *)aNotification { + isFirstChangeInView = YES; + + + [addButton setEnabled:([tablesListInstance tableType] == SPTableTypeTable)]; + + // Check our notification object is our table content view if ([aNotification object] != tableContentView) return; @@ -3284,14 +3357,18 @@ if (isEditingRow && [tableContentView selectedRow] != currentlyEditingRow && ![self saveRowOnDeselect]) return; if (![tableDocumentInstance isWorking]) { - // Update the row selection count // and update the status of the delete/duplicate buttons - if ([tableContentView numberOfSelectedRows] > 0) { - [copyButton setEnabled:YES]; - [removeButton setEnabled:YES]; - } - else { + if([tablesListInstance tableType] == SPTableTypeTable) { + if ([tableContentView numberOfSelectedRows] > 0) { + [copyButton setEnabled:([tableContentView numberOfSelectedRows] == 1)]; + [removeButton setEnabled:YES]; + } + else { + [copyButton setEnabled:NO]; + [removeButton setEnabled:NO]; + } + } else { [copyButton setEnabled:NO]; [removeButton setEnabled:NO]; } @@ -3375,72 +3452,48 @@ // If a data come from a view check if the clicked table field is editable if([tablesListInstance tableType] == SPTableTypeView) { - NSDictionary *columnDefinition; - BOOL noTableName = NO; - BOOL otherErrorWasDisplayed = NO; - isFieldEditable = NO; - NSInteger numberOfPossibleUpdateRows = -1; - - // Retrieve the column defintion - for(id c in cqColumnDefinition) { - if([[c objectForKey:@"datacolumnindex"] isEqualToNumber:[aTableColumn identifier]]) { - columnDefinition = [NSDictionary dictionaryWithDictionary:c]; - break; - } - } - - // Resolve the original table name for current column if AS was used - NSString *tableForColumn = [columnDefinition objectForKey:@"org_table"]; - - // Get the database name which the field belongs to - NSString *dbForColumn = [columnDefinition objectForKey:@"db"]; - - // No table/database 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 or if column database is unset - if(!tableForColumn || ![tableForColumn length] || ![dbForColumn length]) - noTableName = YES; - - if(!noTableName) { - // if table and database name are given check if field can be identified unambiguously - fieldIDQueryString = [self argumentForRow:rowIndex ofTable:tableForColumn andDatabase:[columnDefinition objectForKey:@"db"]]; + NSInteger numberOfPossibleUpdateRows = [self fieldEditStatusForRow:rowIndex andColumn:[aTableColumn identifier]]; + isFieldEditable = (numberOfPossibleUpdateRows == 1) ? YES : NO; + NSPoint pos = [NSEvent mouseLocation]; + pos.y -= 20; + switch(numberOfPossibleUpdateRows) { + case -1: + [SPTooltip showWithObject:NSLocalizedString(@"Field is not editable. Field has no or multiple table or database origin(s).",@"field is not editable due to no table/database") + atLocation:pos + ofType:@"text"]; + isFieldEditable = NO; + // Allow to display blobs even it's not editable + if(!isBlob && [multipleLineEditingButton state] == NSOffState) + return NO; + break; - [tableDocumentInstance startTaskWithDescription:NSLocalizedString(@"Checking field data for editing...", @"checking field data for editing task description")]; + case 0: + [SPTooltip showWithObject:[NSString stringWithFormat:NSLocalizedString(@"Field is not editable. No matching record found.\nReload table or try to add a primary key field or more fields\nin the view declaration of '%@' to identify\nfield origin unambiguously.", @"Table Content result editing error - could not identify original row"), selectedTable] + atLocation:pos + ofType:@"text"]; - // Actual check whether field can be identified bijectively - numberOfPossibleUpdateRows = [[[[mySQLConnection queryString:[NSString stringWithFormat:@"SELECT COUNT(1) FROM %@.%@ %@", [[columnDefinition objectForKey:@"db"] backtickQuotedString], [tableForColumn backtickQuotedString], fieldIDQueryString]] fetchRowAsArray] objectAtIndex:0] integerValue]; + isFieldEditable = NO; + // Allow to display blobs even it's not editable + if(!isBlob && [multipleLineEditingButton state] == NSOffState) + return NO; + break; - [tableDocumentInstance endTask]; + case 1: + isFieldEditable = YES; + if(!isBlob && [multipleLineEditingButton state] == NSOffState) + return YES; + break; - isFieldEditable = (numberOfPossibleUpdateRows == 1) ? YES : NO; - - if(!isFieldEditable) { - fieldIDQueryString = nil; - otherErrorWasDisplayed = YES; - NSPoint pos = [NSEvent mouseLocation]; - pos.y -= 20; - if(numberOfPossibleUpdateRows == 0) - [SPTooltip showWithObject:[NSString stringWithFormat:NSLocalizedString(@"Field is not editable. No matching record found.\nReload table or try to add a primary key field or more fields\nin the view declaration of '%@' to identify\nfield origin unambiguously.", @"Table Content result editing error - could not identify original row"), tableForColumn] - atLocation:pos - ofType:@"text"]; - else - [SPTooltip showWithObject:[NSString stringWithFormat:NSLocalizedString(@"Field is not editable. Couldn't identify field origin unambiguously (%ld match%@).", @"Table Content result editing error - could not match row being edited uniquely"), (long)numberOfPossibleUpdateRows, (numberOfPossibleUpdateRows>1)?NSLocalizedString(@"es", @"Plural suffix for row count, eg 4 match*es*"):@""] - atLocation:pos - ofType:@"text"]; - // Allow to display blobs even it's not editable - if(!isBlob && [multipleLineEditingButton state] == NSOffState) - return NO; - } - } - if(!isFieldEditable && !otherErrorWasDisplayed) { - NSPoint pos = [NSEvent mouseLocation]; - pos.y -= 20; - [SPTooltip showWithObject:NSLocalizedString(@"Field is not editable. Field has no or multiple table or database origin(s).",@"field is not editable due to no table/database") + default: + [SPTooltip showWithObject:[NSString stringWithFormat:NSLocalizedString(@"Field is not editable. Couldn't identify field origin unambiguously (%ld match%@).", @"Table Content result editing error - could not match row being edited uniquely"), (long)numberOfPossibleUpdateRows, (numberOfPossibleUpdateRows>1)?NSLocalizedString(@"es", @"Plural suffix for row count, eg 4 match*es*"):@""] atLocation:pos ofType:@"text"]; - + + isFieldEditable = NO; // Allow to display blobs even it's not editable if(!isBlob && [multipleLineEditingButton state] == NSOffState) return NO; + } } @@ -3463,7 +3516,7 @@ withWindow:[tableDocumentInstance parentWindow]] retain]; if (editData) { - if (!isEditingRow) { + if (!isEditingRow && [tablesListInstance tableType] != SPTableTypeView) { [oldRow setArray:[tableValues rowContentsAtIndex:rowIndex]]; isEditingRow = YES; currentlyEditingRow = rowIndex; @@ -3629,13 +3682,15 @@ return; if ( ![[[tableDataInstance statusValues] objectForKey:@"Rows"] isNSNull] && selectedTable && [selectedTable length] && [tableDataInstance tableEncoding]) { - [addButton setEnabled:YES]; + [addButton setEnabled:([tablesListInstance tableType] == SPTableTypeTable)]; [self updatePaginationState]; [reloadButton setEnabled:YES]; } if ([tableContentView numberOfSelectedRows] > 0) { - [removeButton setEnabled:YES]; - [copyButton setEnabled:YES]; + if([tablesListInstance tableType] == SPTableTypeTable) { + [removeButton setEnabled:YES]; + [copyButton setEnabled:YES]; + } } [filterButton setEnabled:[fieldField isEnabled]]; tableRowsSelectable = YES; @@ -3651,8 +3706,6 @@ - (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command { - if([tablesListInstance tableType] == SPTableTypeView) return; - NSString *fieldType; NSUInteger row, column, i; @@ -3664,73 +3717,98 @@ { [[control window] makeFirstResponder:control]; - // Save the current line if it's the last field in the table - if ( column == ( [tableContentView numberOfColumns] - 1 ) ) { - [self addRowToDB]; + if([tablesListInstance tableType] == SPTableTypeView) { + // Check if next column is a blob column or not editable, and skip to the next non-blob column and editable field + if ( column != ( [tableContentView numberOfColumns] - 1 ) ) { + i = 1; + while ( + (fieldType = [[tableDataInstance columnWithName:[[NSArrayObjectAtIndex([tableContentView tableColumns], column+i) headerCell] stringValue]] objectForKey:@"typegrouping"]) + && ([fieldType isEqualToString:@"textdata"] || [fieldType isEqualToString:@"blobdata"]) + || [self fieldEditStatusForRow:row andColumn:[NSArrayObjectAtIndex([tableContentView tableColumns], column+i) identifier]] != 1 + ) { + i++; + + // If there are no columns after the latest blob or text column, save the current line. + if ( (column+i) >= [tableContentView numberOfColumns] ) { + return TRUE; + } + } + + [tableContentView editColumn:column+i row:row withEvent:nil select:YES]; + + } } else { + // Save the current line if it's the last field in the table + if ( column == ( [tableContentView numberOfColumns] - 1 ) ) { + [self addRowToDB]; + } else { - // Check if next column is a blob column, and skip to the next non-blob column - i = 1; - while ( - (fieldType = [[tableDataInstance columnWithName:[[NSArrayObjectAtIndex([tableContentView tableColumns], column+i) headerCell] stringValue]] objectForKey:@"typegrouping"]) - && ([fieldType isEqualToString:@"textdata"] || [fieldType isEqualToString:@"blobdata"]) - ) { - i++; - - // If there are no columns after the latest blob or text column, save the current line. - if ( (column+i) >= [tableContentView numberOfColumns] ) { - [self addRowToDB]; - return TRUE; + // Check if next column is a blob column, and skip to the next non-blob column + i = 1; + while ( + (fieldType = [[tableDataInstance columnWithName:[[NSArrayObjectAtIndex([tableContentView tableColumns], column+i) headerCell] stringValue]] objectForKey:@"typegrouping"]) + && ([fieldType isEqualToString:@"textdata"] || [fieldType isEqualToString:@"blobdata"]) + ) { + i++; + + // If there are no columns after the latest blob or text column, save the current line. + if ( (column+i) >= [tableContentView numberOfColumns] ) { + [self addRowToDB]; + return TRUE; + } } - } - // Edit the column after the blob column - [tableContentView editColumn:column+i row:row withEvent:nil select:YES]; + // Edit the column after the blob column + [tableContentView editColumn:column+i row:row withEvent:nil select:YES]; + } } return TRUE; } - - // Trap enter key - else if ( [textView methodForSelector:command] == [textView methodForSelector:@selector(insertNewline:)] ) - { - [[control window] makeFirstResponder:control]; - [self addRowToDB]; + + // Trap enter key + else if ( [textView methodForSelector:command] == [textView methodForSelector:@selector(insertNewline:)] ) + { + [[control window] makeFirstResponder:control]; + if([tablesListInstance tableType] != SPTableTypeView) + [self addRowToDB]; return TRUE; - } - - // Trap down arrow key - else if ( [textView methodForSelector:command] == [textView methodForSelector:@selector(moveDown:)] ) - { - NSUInteger newRow = row+1; - if (newRow>=tableRowsCount) return TRUE; //check if we're already at the end of the list - - [[control window] makeFirstResponder:control]; - [self addRowToDB]; - - if (newRow>=tableRowsCount) return TRUE; //check again. addRowToDB could reload the table and change the number of rows - if (column>=[tableValues columnCount]) return TRUE; //the column count could change too - - [tableContentView selectRowIndexes:[NSIndexSet indexSetWithIndex:newRow] byExtendingSelection:NO]; - [tableContentView editColumn:column row:newRow withEvent:nil select:YES]; + } + + // Trap down arrow key + else if ( [textView methodForSelector:command] == [textView methodForSelector:@selector(moveDown:)] ) + { + NSUInteger newRow = row+1; + if (newRow>=tableRowsCount) return TRUE; //check if we're already at the end of the list + + [[control window] makeFirstResponder:control]; + if([tablesListInstance tableType] != SPTableTypeView) + [self addRowToDB]; + + if (newRow>=tableRowsCount) return TRUE; //check again. addRowToDB could reload the table and change the number of rows + if (column>=[tableValues columnCount]) return TRUE; //the column count could change too + + [tableContentView selectRowIndexes:[NSIndexSet indexSetWithIndex:newRow] byExtendingSelection:NO]; + [tableContentView editColumn:column row:newRow withEvent:nil select:YES]; return TRUE; - } - - // Trap up arrow key - else if ( [textView methodForSelector:command] == [textView methodForSelector:@selector(moveUp:)] ) - { - if (row==0) return TRUE; //already at the beginning of the list - NSUInteger newRow = row-1; - - [[control window] makeFirstResponder:control]; - [self addRowToDB]; - - if (newRow>=tableRowsCount) return TRUE; // addRowToDB could reload the table and change the number of rows - if (column>=[tableValues columnCount]) return TRUE; //the column count could change too - - [tableContentView selectRowIndexes:[NSIndexSet indexSetWithIndex:newRow] byExtendingSelection:NO]; - [tableContentView editColumn:column row:newRow withEvent:nil select:YES]; + } + + // Trap up arrow key + else if ( [textView methodForSelector:command] == [textView methodForSelector:@selector(moveUp:)] ) + { + if (row==0) return TRUE; //already at the beginning of the list + NSUInteger newRow = row-1; + + [[control window] makeFirstResponder:control]; + if([tablesListInstance tableType] != SPTableTypeView) + [self addRowToDB]; + + if (newRow>=tableRowsCount) return TRUE; // addRowToDB could reload the table and change the number of rows + if (column>=[tableValues columnCount]) return TRUE; //the column count could change too + + [tableContentView selectRowIndexes:[NSIndexSet indexSetWithIndex:newRow] byExtendingSelection:NO]; + [tableContentView editColumn:column row:newRow withEvent:nil select:YES]; return TRUE; - } + } // Trap the escape key else if ( [[control window] methodForSelector:command] == [[control window] methodForSelector:@selector(_cancelKey:)] || @@ -3786,12 +3864,12 @@ if ([menuItem action] == @selector(removeRow:)) { [menuItem setTitle:([tableContentView numberOfSelectedRows] > 1) ? @"Delete Rows" : @"Delete Row"]; - return ([tableContentView numberOfSelectedRows] > 0); + return ([tableContentView numberOfSelectedRows] > 0 && [tablesListInstance tableType] == SPTableTypeTable); } // Duplicate row if ([menuItem action] == @selector(copyRow:)) { - return ([tableContentView numberOfSelectedRows] == 1); + return ([tableContentView numberOfSelectedRows] == 1 && [tablesListInstance tableType] == SPTableTypeTable); } return YES; -- cgit v1.2.3