Revision: 26211 http://sourceforge.net/p/bibdesk/svn/26211 Author: hofman Date: 2021-06-12 09:35:22 +0000 (Sat, 12 Jun 2021) Log Message: ----------- Pass initial value to complex string editor, it may be inherited. Get it before editing as starting it changes the objectValue.
Modified Paths: -------------- trunk/bibdesk/BDSKComplexStringCell.m trunk/bibdesk/BDSKComplexStringEditor.h trunk/bibdesk/BDSKComplexStringEditor.m trunk/bibdesk/BDSKComplexStringFormatter.h trunk/bibdesk/BDSKComplexStringFormatter.m Modified: trunk/bibdesk/BDSKComplexStringCell.m =================================================================== --- trunk/bibdesk/BDSKComplexStringCell.m 2021-06-12 06:31:14 UTC (rev 26210) +++ trunk/bibdesk/BDSKComplexStringCell.m 2021-06-12 09:35:22 UTC (rev 26211) @@ -43,15 +43,23 @@ @implementation BDSKComplexStringCell - (void)editWithFrame:(NSRect)rect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)delegate event:(NSEvent *)event { + BOOL notifyFormatter = [[self formatter] respondsToSelector:@selector(didStartEditor:withObjectValue:)]; + id value = notifyFormatter ? [[self objectValue] retain] : nil; [super editWithFrame:rect inView:controlView editor:textObj delegate:delegate event:event]; - if ([[self formatter] respondsToSelector:@selector(didStartEditing:)]) - [(BDSKComplexStringFormatter *)[self formatter] didStartEditing:textObj]; + if (notifyFormatter) { + [(BDSKComplexStringFormatter *)[self formatter] didStartEditor:textObj withObjectValue:value]; + [value release]; + } } - (void)selectWithFrame:(NSRect)rect inView:(NSView *)controlView editor:(NSText *)textObj delegate:(id)delegate start:(NSInteger)selStart length:(NSInteger)selLength { + BOOL notifyFormatter = [[self formatter] respondsToSelector:@selector(didStartEditor:withObjectValue:)]; + id value = notifyFormatter ? [[self objectValue] retain] : nil; [super selectWithFrame:rect inView:controlView editor:textObj delegate:delegate start:selStart length:selLength]; - if ([[self formatter] respondsToSelector:@selector(didStartEditing:)]) - [(BDSKComplexStringFormatter *)[self formatter] didStartEditing:textObj]; + if (notifyFormatter) { + [(BDSKComplexStringFormatter *)[self formatter] didStartEditor:textObj withObjectValue:value]; + [value release]; + } } @end Modified: trunk/bibdesk/BDSKComplexStringEditor.h =================================================================== --- trunk/bibdesk/BDSKComplexStringEditor.h 2021-06-12 06:31:14 UTC (rev 26210) +++ trunk/bibdesk/BDSKComplexStringEditor.h 2021-06-12 09:35:22 UTC (rev 26211) @@ -50,7 +50,7 @@ - (id)initWithFormatter:(NSFormatter *)aFormatter; -- (void)attachToEditor:(NSText *)textObj; +- (void)attachToEditor:(NSText *)textObj withValue:(NSString *)value; - (void)remove; Modified: trunk/bibdesk/BDSKComplexStringEditor.m =================================================================== --- trunk/bibdesk/BDSKComplexStringEditor.m 2021-06-12 06:31:14 UTC (rev 26210) +++ trunk/bibdesk/BDSKComplexStringEditor.m 2021-06-12 09:35:22 UTC (rev 26211) @@ -48,6 +48,7 @@ @interface BDSKComplexStringEditor (Private) +- (void)displayValue:(NSString *)value isError:(BOOL)isError; - (BOOL)getEnclosingView:(NSView **)view scrollingView:(NSView **)contentView; - (void)editorFrameDidChange:(NSNotification *)notification; @@ -82,7 +83,7 @@ [super dealloc]; } -- (void)attachToEditor:(NSText *)textObj { +- (void)attachToEditor:(NSText *)textObj withValue:(NSString *)value { if ([self isAttached]) [self remove]; @@ -92,7 +93,7 @@ [self window]; // update the value - [self editorTextDidChange:nil]; + [self displayValue:value isError:NO]; // reset the frame and show the window [self editorFrameDidChange:nil]; // draw the focus ring we are covering when enabled @@ -191,6 +192,17 @@ @implementation BDSKComplexStringEditor (Private) +- (void)displayValue:(NSString *)string isError:(BOOL)isError { + [expandedValueTextField setObjectValue:string]; + if (isError) { + [expandedValueTextField setTextColor:[NSColor systemRedColor]]; + [expandedValueTextField setToolTip:[NSString stringWithFormat:NSLocalizedString(@"Invalid BibTeX string: %@. This change will not be recorded.", @"Tool tip message"), string]]; + } else { + [expandedValueTextField setTextColor:[NSColor controlTextColor]]; + [expandedValueTextField setToolTip:NSLocalizedString(@"This field contains macros and is being edited as it would appear in a BibTeX file. This is the expanded value.", @"Tool tip message")]; + } +} + - (BOOL)getEnclosingView:(NSView **)view scrollingView:(NSView **)contentView { *view = [editor superview]; *contentView = [[*view enclosingScrollView] contentView]; @@ -269,15 +281,10 @@ - (void)editorTextDidChange:(NSNotification *)notification { NSString *string = [editor string]; NSString *error = nil; - if ([formatter getObjectValue:&string forString:string errorDescription:&error]) { - [expandedValueTextField setObjectValue:string]; - [expandedValueTextField setTextColor:[NSColor controlTextColor]]; - [expandedValueTextField setToolTip:NSLocalizedString(@"This field contains macros and is being edited as it would appear in a BibTeX file. This is the expanded value.", @"Tool tip message")]; - } else { - [expandedValueTextField setObjectValue:error]; - [expandedValueTextField setTextColor:[NSColor systemRedColor]]; - [expandedValueTextField setToolTip:[NSString stringWithFormat:NSLocalizedString(@"Invalid BibTeX string: %@. This change will not be recorded.", @"Tool tip message"), string]]; - } + if ([formatter getObjectValue:&string forString:string errorDescription:&error]) + [self displayValue:string isError:NO]; + else + [self displayValue:error isError:YES]; } @end Modified: trunk/bibdesk/BDSKComplexStringFormatter.h =================================================================== --- trunk/bibdesk/BDSKComplexStringFormatter.h 2021-06-12 06:31:14 UTC (rev 26210) +++ trunk/bibdesk/BDSKComplexStringFormatter.h 2021-06-12 09:35:22 UTC (rev 26211) @@ -48,6 +48,6 @@ @property (nonatomic) BOOL editAsComplexString; -- (void)didStartEditing:(NSText *)textObj; +- (void)didStartEditor:(NSText *)textObj withObjectValue:(id)value; @end Modified: trunk/bibdesk/BDSKComplexStringFormatter.m =================================================================== --- trunk/bibdesk/BDSKComplexStringFormatter.m 2021-06-12 06:31:14 UTC (rev 26210) +++ trunk/bibdesk/BDSKComplexStringFormatter.m 2021-06-12 09:35:22 UTC (rev 26211) @@ -147,11 +147,11 @@ } } -- (void)didStartEditing:(NSText *)textObj { +- (void)didStartEditor:(NSText *)textObj withObjectValue:(id)value { if (editAsComplexString) { if (complexStringEditor == nil) complexStringEditor = [[BDSKComplexStringEditor alloc] initWithFormatter:self]; - [complexStringEditor attachToEditor:textObj]; + [complexStringEditor attachToEditor:textObj withValue:value]; } } 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