Revision: 27437
          http://sourceforge.net/p/bibdesk/svn/27437
Author:   hofman
Date:     2022-05-19 14:33:02 +0000 (Thu, 19 May 2022)
Log Message:
-----------
Remember initial value fioredit in complex string formatter, and return it when 
the returned value should be equal as a complext string. This will preserve 
inherited status of the string, sowe don't have to explicitly reset the value 
of the text field when editing ends or is aborted.

Modified Paths:
--------------
    trunk/bibdesk/BDSKComplexStringCell.m
    trunk/bibdesk/BDSKComplexStringEditor.h
    trunk/bibdesk/BDSKComplexStringEditor.m
    trunk/bibdesk/BDSKComplexStringFormatter.h
    trunk/bibdesk/BDSKComplexStringFormatter.m
    trunk/bibdesk/BDSKEditor.m
    trunk/bibdesk/BDSKTextImportController.m

Modified: trunk/bibdesk/BDSKComplexStringCell.m
===================================================================
--- trunk/bibdesk/BDSKComplexStringCell.m       2022-05-19 09:19:34 UTC (rev 
27436)
+++ trunk/bibdesk/BDSKComplexStringCell.m       2022-05-19 14:33:02 UTC (rev 
27437)
@@ -78,23 +78,15 @@
 }
 
 - (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 (notifyFormatter) {
-        [(BDSKComplexStringFormatter *)[self formatter] didStartEditor:textObj 
withObjectValue:value];
-        [value release];
-    }
+    if ([[self formatter] respondsToSelector:@selector(didStartEditor:)])
+        [(BDSKComplexStringFormatter *)[self formatter] 
didStartEditor:textObj];
 }
 
 - (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 (notifyFormatter) {
-        [(BDSKComplexStringFormatter *)[self formatter] didStartEditor:textObj 
withObjectValue:value];
-        [value release];
-    }
+    if ([[self formatter] respondsToSelector:@selector(didStartEditor:)])
+        [(BDSKComplexStringFormatter *)[self formatter] 
didStartEditor:textObj];
 }
 
 @end

Modified: trunk/bibdesk/BDSKComplexStringEditor.h
===================================================================
--- trunk/bibdesk/BDSKComplexStringEditor.h     2022-05-19 09:19:34 UTC (rev 
27436)
+++ trunk/bibdesk/BDSKComplexStringEditor.h     2022-05-19 14:33:02 UTC (rev 
27437)
@@ -39,14 +39,18 @@
 
 #import <Cocoa/Cocoa.h>
 
+@class BDSKComplexStringFormatter;
 
 @interface BDSKComplexStringEditor : NSWindowController {
     NSTextField *expandedValueTextField;
     NSImageView *focusRingView;
     NSBox *box;
+    BDSKComplexStringFormatter *formatter;
     NSText *editor;
 }
 
+- (id)initWithFormatter:(BDSKComplexStringFormatter *)aFormatter;
+
 - (void)attachToEditor:(NSText *)textObj withValue:(NSString *)value;
 
 - (void)remove;

Modified: trunk/bibdesk/BDSKComplexStringEditor.m
===================================================================
--- trunk/bibdesk/BDSKComplexStringEditor.m     2022-05-19 09:19:34 UTC (rev 
27436)
+++ trunk/bibdesk/BDSKComplexStringEditor.m     2022-05-19 14:33:02 UTC (rev 
27437)
@@ -64,15 +64,21 @@
 @synthesize expandedValueTextField, focusRingView, box;
 @dynamic attached;
 
+- (id)initWithFormatter:(BDSKComplexStringFormatter *)aFormatter {
+    self = [self initWithWindowNibName:@"ComplexStringEditor"];
+    if (self) {
+        // don't retain as it owns us
+        formatter = aFormatter;
+    }
+    return self;
+}
+
 - (void)dealloc {
+    formatter = nil;
     BDSKDESTROY(editor);
     [super dealloc];
 }
 
-- (NSString *)windowNibName {
-    return @"ComplexStringEditor";
-}
-
 - (void)attachToEditor:(NSText *)textObj withValue:(NSString *)value {
        if ([self isAttached]) 
                [self remove];
@@ -290,7 +296,7 @@
 - (void)editorTextDidChange:(NSNotification *)notification {
        NSString *string = [editor string];
     NSString *error = nil;
-    if ([[expandedValueTextField formatter] getObjectValue:&string 
forString:string errorDescription:&error])
+    if ([formatter getObjectValue:&string forString:string 
errorDescription:&error])
         [self displayValue:string isError:NO];
     else
         [self displayValue:error isError:YES];

Modified: trunk/bibdesk/BDSKComplexStringFormatter.h
===================================================================
--- trunk/bibdesk/BDSKComplexStringFormatter.h  2022-05-19 09:19:34 UTC (rev 
27436)
+++ trunk/bibdesk/BDSKComplexStringFormatter.h  2022-05-19 14:33:02 UTC (rev 
27437)
@@ -41,6 +41,7 @@
 @interface BDSKComplexStringFormatter : NSFormatter {
     BDSKMacroResolver *macroResolver;
        BOOL editAsComplexString;
+    NSString *editedValue;
     BDSKComplexStringEditor *complexStringEditor;
 }
 
@@ -48,6 +49,6 @@
 
 @property (nonatomic) BOOL editAsComplexString;
 
-- (void)didStartEditor:(NSText *)textObj withObjectValue:(id)value;
+- (void)didStartEditor:(NSText *)textObj;
 
 @end

Modified: trunk/bibdesk/BDSKComplexStringFormatter.m
===================================================================
--- trunk/bibdesk/BDSKComplexStringFormatter.m  2022-05-19 09:19:34 UTC (rev 
27436)
+++ trunk/bibdesk/BDSKComplexStringFormatter.m  2022-05-19 14:33:02 UTC (rev 
27437)
@@ -70,6 +70,7 @@
         [complexStringEditor remove];
     BDSKDESTROY(complexStringEditor);
     BDSKDESTROY(macroResolver);
+    BDSKDESTROY(editedValue);
     [super dealloc];
 }
 
@@ -83,6 +84,8 @@
        NSString *string = [self stringForObjectValue:obj];
        if ([obj isComplex])
         editAsComplexString = YES;
+    [editedValue release];
+    editedValue  = [obj retain];
     return editAsComplexString && [NSString isEmptyAsComplexString:string] == 
NO ? [string stringAsBibTeXString] : string;
 }
 
@@ -130,6 +133,9 @@
             *error = NSLocalizedString(@"Unbalanced braces", @"error 
description");
     }
     
+    if ([string isEqualAsComplexString:editedValue])
+        string = editedValue;
+    
     if (string == nil)
         return NO;
     else if (obj)
@@ -147,11 +153,11 @@
     }
 }
 
-- (void)didStartEditor:(NSText *)textObj withObjectValue:(id)value {
+- (void)didStartEditor:(NSText *)textObj {
     if (editAsComplexString) {
         if (complexStringEditor == nil)
-            complexStringEditor = [[BDSKComplexStringEditor alloc] init];
-        [complexStringEditor attachToEditor:textObj withValue:value];
+            complexStringEditor = [[BDSKComplexStringEditor alloc] 
initWithFormatter:self];
+        [complexStringEditor attachToEditor:textObj withValue:editedValue];
     }
 }
 

Modified: trunk/bibdesk/BDSKEditor.m
===================================================================
--- trunk/bibdesk/BDSKEditor.m  2022-05-19 09:19:34 UTC (rev 27436)
+++ trunk/bibdesk/BDSKEditor.m  2022-05-19 14:33:02 UTC (rev 27437)
@@ -365,12 +365,9 @@
 
 - (void)abortEditingControl:(NSControl *)control atRow:(NSInteger)row {
     [control abortEditing];
-    if (row != -1) {
+    if (row != -1)
         // controlTextDidEndEditing: is not called when calling abortEditing
         [tableCellFormatter setEditAsComplexString:NO];
-        // restore the value,in case it was inherited
-        [control setObjectValue:[publication valueOfField:[fields 
objectAtIndex:row]] ?: @""];
-    }
     [self setEditing:NO];
 }
 
@@ -1156,6 +1153,9 @@
 }
 
 - (IBAction)changeValue:(id)sender {
+    if (editorFlags.isEditable == NO)
+        return;
+    
     NSInteger row = [tableView rowForView:sender];
     if (row == -1)
         return;
@@ -1164,12 +1164,9 @@
     NSString *oldValue = [publication valueOfField:field] ?: @"";
     NSString *value = [sender objectValue] ?: @"";
     
-    if (editorFlags.isEditable && NO == [value 
isEqualAsComplexString:oldValue]) {
+    if (NO == [value isEqualAsComplexString:oldValue]) {
         [self recordChangingField:field toValue:value];
         // button should be update implicitly by the bibDidChange notification
-    } else if ([oldValue isInherited]) {
-        // just selecting also changes the objectValue
-        [sender setObjectValue:oldValue];
     }
 }
 

Modified: trunk/bibdesk/BDSKTextImportController.m
===================================================================
--- trunk/bibdesk/BDSKTextImportController.m    2022-05-19 09:19:34 UTC (rev 
27436)
+++ trunk/bibdesk/BDSKTextImportController.m    2022-05-19 14:33:02 UTC (rev 
27437)
@@ -396,8 +396,6 @@
     NSString *oldValue = [[self publication] valueOfField:key];
     if (NO == [value isEqualAsComplexString:oldValue])
         [self recordChangingField:key toValue:value];
-    else if ([oldValue isInherited])
-        [sender setObjectValue:oldValue];
 }
 
 - (IBAction)editSelectedFieldAsRawBibTeX:(id)sender{

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

Reply via email to