Revision: 26155 http://sourceforge.net/p/bibdesk/svn/26155 Author: hofman Date: 2021-06-07 15:12:26 +0000 (Mon, 07 Jun 2021) Log Message: ----------- Make sure complex macro values are set when the expanded value may be the same
Modified Paths: -------------- trunk/bibdesk/BDSKMacroWindowController.h trunk/bibdesk/BDSKMacroWindowController.m Modified: trunk/bibdesk/BDSKMacroWindowController.h =================================================================== --- trunk/bibdesk/BDSKMacroWindowController.h 2021-06-07 09:52:36 UTC (rev 26154) +++ trunk/bibdesk/BDSKMacroWindowController.h 2021-06-07 15:12:26 UTC (rev 26155) @@ -90,12 +90,11 @@ @end -@interface MacroKeyFormatter : NSFormatter { - -} - +@interface MacroKeyFormatter : NSFormatter @end -@interface BDSKMacroTableView : BDSKTableView +@interface BDSKMacroTableView : BDSKTableView { + BOOL didSetValue; +} @end Modified: trunk/bibdesk/BDSKMacroWindowController.m =================================================================== --- trunk/bibdesk/BDSKMacroWindowController.m 2021-06-07 09:52:36 UTC (rev 26154) +++ trunk/bibdesk/BDSKMacroWindowController.m 2021-06-07 15:12:26 UTC (rev 26155) @@ -63,6 +63,10 @@ #define MACRO_COLUMNID @"macro" #define DEFINITION_COLUMNID @"definition" +@interface NSTableView (BDSKApplePrivate) +- (void)_dataSourceSetValue:(id)value forColumn:(NSTableColumn *)tableColumn row:(NSInteger)row; +@end + @implementation BDSKMacroWindowController @synthesize arrayController, tableView, closeButton, addRemoveButton, macroResolver; @@ -735,4 +739,46 @@ @end @implementation BDSKMacroTableView + +// private method called from -[NSTableView textDidEndEditing:] +- (void)_dataSourceSetValue:(id)value forColumn:(NSTableColumn *)tableColumn row:(NSInteger)row { + [super _dataSourceSetValue:value forColumn:tableColumn row:row]; + didSetValue = YES; +} + +- (void)textDidEndEditing:(NSNotification *)aNotification { + /* + NSTableView has an optimization of sorts where the value will not be set if the string in the cell + is equal to the old string. When you want to change e.g. year={2009} to year=2009, this becomes + a problem. I got fed up with deleting the old string, then setting the new raw string. + + Note that the current cell's objectValue is still the old value, so we have to work with the formatter + directly in order to get the (possibly complex) edited string. + */ + NSInteger editedRow = [self editedRow]; + NSInteger editedColumn = [self editedColumn]; + BOOL shouldCheckValue = NO; + id newValue = nil; + if (editedColumn >= 0 && editedRow >= 0 && [self respondsToSelector:@selector(_dataSourceSetValue:forColumn:row:)]) { + NSCell *editedCell = [self preparedCellAtColumn:editedColumn row:editedRow]; + NSFormatter *formatter = [editedCell formatter]; + id oldValue = [editedCell objectValue]; + newValue = [[aNotification object] string]; + if (formatter == nil || [formatter getObjectValue:&newValue forString:newValue errorDescription:NULL]) { + shouldCheckValue = [oldValue respondsToSelector:@selector(isEqualAsComplexString:)] && + [newValue respondsToSelector:@selector(isEqualAsComplexString:)] && + [oldValue isEqualAsComplexString:newValue] == NO; + } + newValue = [newValue copy]; + } + didSetValue = NO; + + [super textDidEndEditing:aNotification]; + + // only try setting if NSTableView did not, and if these are not equal as complex strings + if (didSetValue == NO && shouldCheckValue) + [self _dataSourceSetValue:newValue forColumn:[[self tableColumns] objectAtIndex:editedColumn] row:editedRow]; + [newValue release]; +} + @end This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ Bibdesk-commit mailing list Bibdesk-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bibdesk-commit