Revision: 22440
http://sourceforge.net/p/bibdesk/svn/22440
Author: hofman
Date: 2018-07-19 21:13:36 +0000 (Thu, 19 Jul 2018)
Log Message:
-----------
Update attributed format string only when the format string is changed,
convenience accessor for format error
Modified Paths:
--------------
trunk/bibdesk/BDSKFormatStringFormatter.h
trunk/bibdesk/BDSKFormatStringFormatter.m
trunk/bibdesk/BibPref_AutoFile.m
trunk/bibdesk/BibPref_CiteKey.m
Modified: trunk/bibdesk/BDSKFormatStringFormatter.h
===================================================================
--- trunk/bibdesk/BDSKFormatStringFormatter.h 2018-07-19 06:30:43 UTC (rev
22439)
+++ trunk/bibdesk/BDSKFormatStringFormatter.h 2018-07-19 21:13:36 UTC (rev
22440)
@@ -41,10 +41,10 @@
@interface BDSKFormatStringFormatter : NSFormatter {
NSString *parseField;
+ NSString *string;
NSAttributedString *attributedString;
NSString *formatError;
}
- (id)initWithField:(NSString *)field;
-- (NSAttributedString *)attributedString;
- (NSString *)formatError;
@end
Modified: trunk/bibdesk/BDSKFormatStringFormatter.m
===================================================================
--- trunk/bibdesk/BDSKFormatStringFormatter.m 2018-07-19 06:30:43 UTC (rev
22439)
+++ trunk/bibdesk/BDSKFormatStringFormatter.m 2018-07-19 21:13:36 UTC (rev
22440)
@@ -54,13 +54,12 @@
- (void)dealloc
{
BDSKDESTROY(parseField);
+ BDSKDESTROY(string);
BDSKDESTROY(attributedString);
BDSKDESTROY(formatError);
[super dealloc];
}
-- (NSAttributedString *)attributedString { return attributedString; }
-
- (NSString *)formatError { return formatError; }
- (NSString *)stringForObjectValue:(id)obj{
@@ -77,13 +76,19 @@
NSAttributedString *attrString = nil;
NSString *errorString = nil;
- [BDSKFormatParser validateFormat:&obj attributedFormat:&attrString
forField:parseField error:&errorString];
+ if ([obj isEqualToString:string]) {
+ attrString = attributedString;
+ } else {
+ [BDSKFormatParser validateFormat:&obj attributedFormat:&attrString
forField:parseField error:&errorString];
- [attributedString release];
- attributedString = [attrString retain];
- [formatError release];
- formatError = [errorString retain];
-
+ [string release];
+ string = [obj retain];
+ [attributedString release];
+ attributedString = [attrString retain];
+ [formatError release];
+ formatError = [errorString retain];
+ }
+
if ([attrs count]) {
NSMutableDictionary *mutableAttrs = [attrs mutableCopy];
[mutableAttrs removeObjectForKey:NSFontAttributeName];
@@ -99,8 +104,8 @@
return attrString;
}
-- (BOOL)getObjectValue:(id *)obj forString:(NSString *)string
errorDescription:(NSString **)error{
- *obj = string;
+- (BOOL)getObjectValue:(id *)obj forString:(NSString *)aString
errorDescription:(NSString **)error{
+ *obj = aString;
return YES;
}
Modified: trunk/bibdesk/BibPref_AutoFile.m
===================================================================
--- trunk/bibdesk/BibPref_AutoFile.m 2018-07-19 06:30:43 UTC (rev 22439)
+++ trunk/bibdesk/BibPref_AutoFile.m 2018-07-19 21:13:36 UTC (rev 22440)
@@ -54,6 +54,7 @@
@interface BibPref_AutoFile (Private)
+- (NSString *)formatError;
- (void)setLocalUrlFormatInvalidWarning:(NSString *)message;
- (void)updatePapersFolderUI;
- (void)updateFormatPresetUI;
@@ -315,7 +316,7 @@
[sud setObject:formatString forKey:BDSKLocalFileFormatKey];
}
else { //changed the text field or added from the repository
- if (nil != [(BDSKFormatStringFormatter *)[formatSheetField formatter]
formatError])
+ if ([self formatError])
return;
formatString = [formatSheetField stringValue];
[sud setObject:formatString forKey:BDSKLocalFileFormatKey];
@@ -331,12 +332,9 @@
if (fieldEditor == nil)
return;
// get the attributed string from the format parser
- BDSKFormatStringFormatter *formatter = (BDSKFormatStringFormatter
*)[formatSheetField formatter];
- NSAttributedString *attrString = [formatter attributedString];
NSString *string = [fieldEditor string];
+ NSAttributedString *attrString = [[formatSheetField formatter]
attributedStringForObjectValue:string withDefaultAttributes:nil];
// get the attributes of the parsed string and apply them to our
NSTextStorage; it may not be safe to set it directly at this point
- if ([string isEqualToString:[attrString string]] == NO)
- attrString = [formatter attributedStringForObjectValue:[fieldEditor
string] withDefaultAttributes:nil];
if ([string isEqualToString:[attrString string]]) {
NSTextStorage *textStorage = [fieldEditor textStorage];
[attrString enumerateAttributesInRange:NSMakeRange(0, [attrString
length]) options:0 usingBlock:^(NSDictionary *attrs, NSRange range, BOOL *stop){
@@ -349,14 +347,13 @@
if ([notification object] == formatSheetField) {
[self recolorFormatField];
- NSString *formatError = [(BDSKFormatStringFormatter
*)[formatSheetField formatter] formatError];
- [self setLocalUrlFormatInvalidWarning:formatError];
+ [self setLocalUrlFormatInvalidWarning:[self formatError]];
}
}
- (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText
*)fieldEditor {
if (control == formatSheetField)
- return [(BDSKFormatStringFormatter *)[formatSheetField formatter]
formatError] == nil;
+ return [self formatError] == nil;
return YES;
}
@@ -419,7 +416,7 @@
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert setMessageText:NSLocalizedString(@"Invalid Local File Format",
@"Message in alert dialog when entering invalid Local File format")];
- [alert setInformativeText:[(BDSKFormatStringFormatter
*)[formatSheetField formatter] formatError] ?: @""];
+ [alert setInformativeText:[self formatError] ?: @""];
[alert addButtonWithTitle:NSLocalizedString(@"Keep Editing", @"Button
title")];
if (currentIsValid)
[alert addButtonWithTitle:NSLocalizedString(@"Revert to Last",
@"Button title")];
@@ -430,6 +427,10 @@
#pragma mark Invalid format warning stuff
+- (NSString *)formatError {
+ return [(BDSKFormatStringFormatter *)[formatSheetField formatter]
formatError];
+}
+
- (IBAction)showLocalUrlFormatWarning:(id)sender{
NSString *msg = [sender toolTip];
Modified: trunk/bibdesk/BibPref_CiteKey.m
===================================================================
--- trunk/bibdesk/BibPref_CiteKey.m 2018-07-19 06:30:43 UTC (rev 22439)
+++ trunk/bibdesk/BibPref_CiteKey.m 2018-07-19 21:13:36 UTC (rev 22440)
@@ -51,6 +51,7 @@
@interface BibPref_CiteKey (Private)
+- (NSString *)formatError;
- (void)setCiteKeyFormatInvalidWarning:(NSString *)message;
- (void)updateFormatPresetUI;
- (void)updateFormatPreviewUI;
@@ -226,7 +227,7 @@
[sud setObject:formatString forKey:BDSKCiteKeyFormatKey];
}
else { //changed the text field or added from the repository
- if (nil != [(BDSKFormatStringFormatter *)[formatSheetField formatter]
formatError])
+ if ([self formatError])
return;
formatString = [formatSheetField stringValue];
[sud setObject:formatString forKey:BDSKCiteKeyFormatKey];
@@ -242,12 +243,9 @@
if (fieldEditor == nil)
return;
// get the attributed string from the format parser
- BDSKFormatStringFormatter *formatter = (BDSKFormatStringFormatter
*)[formatSheetField formatter];
- NSAttributedString *attrString = [formatter attributedString];
NSString *string = [fieldEditor string];
+ NSAttributedString *attrString = [[formatSheetField formatter]
attributedStringForObjectValue:string withDefaultAttributes:nil];
// get the attributes of the parsed string and apply them to our
NSTextStorage; it may not be safe to set it directly at this point
- if ([string isEqualToString:[attrString string]] == NO)
- attrString = [formatter attributedStringForObjectValue:[fieldEditor
string] withDefaultAttributes:nil];
if ([string isEqualToString:[attrString string]]) {
NSTextStorage *textStorage = [fieldEditor textStorage];
[attrString enumerateAttributesInRange:NSMakeRange(0, [attrString
length]) options:0 usingBlock:^(NSDictionary *attrs, NSRange range, BOOL *stop){
@@ -259,12 +257,11 @@
- (void)controlTextDidChange:(NSNotification *)notification {
[self recolorFormatField];
- NSString *formatError = [(BDSKFormatStringFormatter *)[formatSheetField
formatter] formatError];
- [self setCiteKeyFormatInvalidWarning:formatError];
+ [self setCiteKeyFormatInvalidWarning:[self formatError]];
}
- (BOOL)control:(NSControl *)control textShouldEndEditing:(NSText
*)fieldEditor {
- return [(BDSKFormatStringFormatter *)[formatSheetField formatter]
formatError] == nil;
+ return [self formatError] == nil;
}
- (void)handleFormatSelectionDidChange:(NSNotification *)notification {
@@ -326,7 +323,7 @@
NSAlert *alert = [[[NSAlert alloc] init] autorelease];
[alert setMessageText:NSLocalizedString(@"Invalid Cite Key Format",
@"Message in alert dialog when entering invalid cite key format")];
- [alert setInformativeText:[(BDSKFormatStringFormatter
*)[formatSheetField formatter] formatError] ?: @""];
+ [alert setInformativeText:[self formatError] ?: @""];
[alert addButtonWithTitle:NSLocalizedString(@"Keep Editing", @"Button
title")];
if (currentIsValid)
[alert addButtonWithTitle:NSLocalizedString(@"Revert to Last",
@"Button title")];
@@ -337,6 +334,10 @@
#pragma mark Invalid format warning stuff
+- (NSString *)formatError {
+ return [(BDSKFormatStringFormatter *)[formatSheetField formatter]
formatError];
+}
+
- (IBAction)showCiteKeyFormatWarning:(id)sender{
NSString *msg = [sender toolTip];
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