Revision: 22428
          http://sourceforge.net/p/bibdesk/svn/22428
Author:   hofman
Date:     2018-07-17 21:49:00 +0000 (Tue, 17 Jul 2018)
Log Message:
-----------
Validate format sheet by trying to ending edit, force ending edit only when 
reverting the format

Modified Paths:
--------------
    trunk/bibdesk/BDSKFormatStringFormatter.m
    trunk/bibdesk/BibPref_AutoFile.m
    trunk/bibdesk/BibPref_CiteKey.m

Modified: trunk/bibdesk/BDSKFormatStringFormatter.m
===================================================================
--- trunk/bibdesk/BDSKFormatStringFormatter.m   2018-07-17 18:07:36 UTC (rev 
22427)
+++ trunk/bibdesk/BDSKFormatStringFormatter.m   2018-07-17 21:49:00 UTC (rev 
22428)
@@ -75,10 +75,9 @@
 
 - (NSAttributedString *)attributedStringForObjectValue:(id)obj 
withDefaultAttributes:(NSDictionary *)attrs{
     NSAttributedString *attrString = nil;
-    NSString *format = [[obj copy] autorelease];
     NSString *errorString = nil;
     
-       [BDSKFormatParser validateFormat:&format attributedFormat:&attrString 
forField:parseField error:&errorString];
+       [BDSKFormatParser validateFormat:&obj attributedFormat:&attrString 
forField:parseField error:&errorString];
     
     [attributedString release];
     attributedString = [attrString retain];
@@ -85,6 +84,16 @@
     [formatError release];
     formatError = [errorString retain];
     
+    if ([attrs count]) {
+        NSMutableAttributedString *mutableAttrString = [attrString 
mutableCopy];
+        NSMutableDictionary *mutableAttrs = [attrs mutableCopy];
+        [mutableAttrs removeObjectForKey:NSFontAttributeName];
+        [mutableAttrs removeObjectForKey:NSForegroundColorAttributeName];
+        [mutableAttrString addAttributes:mutableAttrs range:NSMakeRange(0, 
[attrString length])];
+        [mutableAttrs release];
+        attrString = [mutableAttrString autorelease];
+    }
+    
     return attrString;
 }
 
@@ -95,9 +104,7 @@
 
 - (BOOL)isPartialStringValid:(NSString **)partialStringPtr 
proposedSelectedRange:(NSRangePointer)proposedSelRangePtr 
originalString:(NSString *)origString 
originalSelectedRange:(NSRange)origSelRange errorDescription:(NSString **)error{
     NSAttributedString *attrString = nil;
-    NSString *format = [[*partialStringPtr copy] autorelease];
-    
-    format = [[self attributedStringForObjectValue:format 
withDefaultAttributes:nil] string];
+    NSString *format = [[self attributedStringForObjectValue:*partialStringPtr 
withDefaultAttributes:nil] string];
        
        if (NO == [format isEqualToString:*partialStringPtr]) {
                NSUInteger length = [format length];

Modified: trunk/bibdesk/BibPref_AutoFile.m
===================================================================
--- trunk/bibdesk/BibPref_AutoFile.m    2018-07-17 18:07:36 UTC (rev 22427)
+++ trunk/bibdesk/BibPref_AutoFile.m    2018-07-17 21:49:00 UTC (rev 22428)
@@ -169,7 +169,7 @@
                frame.size.width = MAX_FORMAT_WIDTH;
                [formatField setFrame:frame];
        }
-       [formatSheetField setAttributedStringValue:attrFormat];
+       [formatSheetField setStringValue:[attrFormat string]];
 }
 
 - (IBAction)setPapersFolderPathFromTextField:(id)sender{
@@ -380,8 +380,8 @@
        NSString *error = nil;
        NSString *otherButton = nil;
        
-       if ([formatSheet makeFirstResponder:nil] == NO)
-               [formatSheet endEditingFor:nil];
+       if ([formatSheet makeFirstResponder:nil])
+        return YES;
        
     error = [(BDSKFormatStringFormatter *)[formatSheetField formatter] 
formatError];
        if (error == nil) 
@@ -403,7 +403,6 @@
        NSInteger rv = [alert runModal];
        
        if (rv == NSAlertFirstButtonReturn){
-               [formatSheet makeFirstResponder:formatSheetField];
                return NO;
        } else if (rv == NSAlertThirdButtonReturn){
                formatString = [[sudc initialValues] 
objectForKey:BDSKLocalFileFormatKey];
@@ -411,6 +410,7 @@
                [[BDSKTypeManager sharedManager] setRequiredFieldsForLocalFile: 
[BDSKFormatParser requiredFieldsForFormat:formatString]];
        }
     // this will reset the formatSheetField string to the chosen default
+    [formatSheet endEditingFor:formatSheetField];
        [self updateFormatPreviewUI];
        return YES;
 }

Modified: trunk/bibdesk/BibPref_CiteKey.m
===================================================================
--- trunk/bibdesk/BibPref_CiteKey.m     2018-07-17 18:07:36 UTC (rev 22427)
+++ trunk/bibdesk/BibPref_CiteKey.m     2018-07-17 21:49:00 UTC (rev 22428)
@@ -141,7 +141,7 @@
                frame.size.width = MAX_FORMAT_WIDTH;
                [formatField setFrame:frame];
        }
-       [formatSheetField setAttributedStringValue:attrFormat];
+       [formatSheetField setStringValue:[attrFormat string]];
 }
 
 - (IBAction)citeKeyHelp:(id)sender{
@@ -288,12 +288,10 @@
        NSString *error = nil;
        NSString *otherButton = nil;
        
-       if ([formatSheet makeFirstResponder:nil] == NO)
-               [formatSheet endEditingFor:nil];
+       if ([formatSheet makeFirstResponder:nil])
+        return YES;
        
     error = [(BDSKFormatStringFormatter *)[formatSheetField formatter] 
formatError];
-       if (error == nil) 
-               return YES;
        
        formatString = [sud stringForKey:BDSKCiteKeyFormatKey];
        if ([BDSKFormatParser validateFormat:&formatString 
forField:BDSKCiteKeyString error:NULL]) {
@@ -311,7 +309,7 @@
        NSInteger rv = [alert runModal];
        
        if (rv == NSAlertFirstButtonReturn){
-               [formatSheet makeFirstResponder:formatSheetField];
+               //[formatSheet makeFirstResponder:formatSheetField];
                return NO;
        } else if (rv == NSAlertThirdButtonReturn){
                formatString = [[sudc initialValues] 
objectForKey:BDSKCiteKeyFormatKey];
@@ -319,6 +317,7 @@
                [[BDSKTypeManager sharedManager] setRequiredFieldsForCiteKey: 
[BDSKFormatParser requiredFieldsForFormat:formatString]];
        }
     // this will reset the formatSheetField string to the chosen default
+    [formatSheet endEditingFor:formatSheetField];
        [self updateFormatPresetUI];
        return YES;
 }
@@ -351,7 +350,6 @@
 - (void)setCiteKeyFormatInvalidWarning:(BOOL)set message:(NSString *)message{
     [formatWarningButton setToolTip:set ? message : nil];
        [formatWarningButton setHidden:set == NO];
-       //[formatSheetField setTextColor:(set ? [NSColor redColor] : [NSColor 
blackColor])]; // overdone?
 }
 
 @end

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to