Revision: 27596
          http://sourceforge.net/p/bibdesk/svn/27596
Author:   hofman
Date:     2022-06-09 16:14:06 +0000 (Thu, 09 Jun 2022)
Log Message:
-----------
use document string encoding when saving window setup at end

Modified Paths:
--------------
    trunk/bibdesk/BibDocument.h
    trunk/bibdesk/BibDocument.m
    trunk/bibdesk/BibDocument_Search.m

Modified: trunk/bibdesk/BibDocument.h
===================================================================
--- trunk/bibdesk/BibDocument.h 2022-06-09 14:37:36 UTC (rev 27595)
+++ trunk/bibdesk/BibDocument.h 2022-06-09 16:14:06 UTC (rev 27596)
@@ -379,8 +379,7 @@
 
 // Private methods
 
-- (NSDictionary *)saveWindowSetupInExtendedAttributesAtURL:(NSURL *)anURL 
forEncoding:(NSStringEncoding)encoding;
-@property (nonatomic, readonly) NSDictionary 
*mainWindowSetupDictionaryFromExtendedAttributes;
+- (void)saveWindowSetupInExtendedAttributesAtURL:(NSURL *)anURL 
forEncoding:(NSStringEncoding)encoding resetLocal:(BOOL)reset;
 
 - (BOOL)boolForSetupKey:(NSString *)key;
 - (NSInteger)integerForSetupKey:(NSString *)key;

Modified: trunk/bibdesk/BibDocument.m
===================================================================
--- trunk/bibdesk/BibDocument.m 2022-06-09 14:37:36 UTC (rev 27595)
+++ trunk/bibdesk/BibDocument.m 2022-06-09 16:14:06 UTC (rev 27596)
@@ -192,7 +192,7 @@
 @implementation BibDocument
 
 @synthesize documentWindow, tableView, splitView, mainBox, mainView, 
controlContentView, statusBar, groupOutlineView, groupSplitView, 
groupActionButton, groupAddButton, groupButtonView, groupFieldMenu, 
sidePreviewTabView, sidePreviewTextView, sideFileView, sidePreviewButton, 
sidePreviewButtonView, bottomPreviewTabView, bottomPreviewTextView, 
bottomFileView, bottomPreviewButton, actionMenuButton, groupActionMenuButton, 
searchField, groupMenu, actionMenu, alternateCopyMenu, sharingMenu, 
publications, shownPublications, groups, documentInfo, macroResolver, basePath;
-@dynamic mainWindowSetupDictionaryFromExtendedAttributes, mainDocument, 
atomData, MODSData, endNoteData, wordXMLData, numberOfSelectedPubs, 
numberOfClickedOrSelectedPubs, selectedPublications, 
clickedOrSelectedPublications, singleSelectedPublication, selectedFileURLs, 
clickedOrSelectedFileURLs, selectedRemoteURLs, clickedOrSelectedRemoteURLs, 
documentStringEncoding, sharingServices;
+@dynamic mainDocument, atomData, MODSData, endNoteData, wordXMLData, 
numberOfSelectedPubs, numberOfClickedOrSelectedPubs, selectedPublications, 
clickedOrSelectedPublications, singleSelectedPublication, selectedFileURLs, 
clickedOrSelectedFileURLs, selectedRemoteURLs, clickedOrSelectedRemoteURLs, 
documentStringEncoding, sharingServices;
 
 + (NSSet *)keyPathsForValuesAffectingValueForKey:(NSString *)key {
     NSSet *keyPaths = [super keyPathsForValuesAffectingValueForKey:key];
@@ -713,7 +713,7 @@
     [fileSearchController setDelegate:nil];
     [notesSearchIndex terminate];
     
-    [self saveWindowSetupInExtendedAttributesAtURL:[self fileURL] 
forEncoding:BDSKNoStringEncoding];
+    [self saveWindowSetupInExtendedAttributesAtURL:[self fileURL] 
forEncoding:[self documentStringEncoding] resetLocal:NO];
     
     // reset the previewer; don't send [self updatePreviews:] here, as the 
tableview will be gone by the time the queue posts the notification
     if ([[NSUserDefaults standardUserDefaults] boolForKey:BDSKUsesTeXKey]) {
@@ -782,8 +782,7 @@
 
 #pragma mark Setup from extended attributes
 
-// returns empty dictionary if no attributes set
-- (NSDictionary *)mainWindowSetupDictionaryFromExtendedAttributes {
+- (id)objectFromExtendedAttributesForSetupKey:(NSString *)key {
     if (mainWindowSetupDictionary == nil) {
         if ([self fileURL]) {
             mainWindowSetupDictionary = [[[SKNExtendedAttributeManager 
sharedNoSplitManager] 
propertyListFromExtendedAttributeNamed:BDSKMainWindowExtendedAttributeKey 
atPath:[[self fileURL] path] traverseLink:YES error:NULL] retain];
@@ -795,10 +794,10 @@
         if (nil == mainWindowSetupDictionary)
             mainWindowSetupDictionary = [[NSDictionary alloc] init];
     }
-    return mainWindowSetupDictionary;
+    return [mainWindowSetupDictionary objectForKey:key];
 }
 
-- (NSDictionary *)saveWindowSetupInExtendedAttributesAtURL:(NSURL *)anURL 
forEncoding:(NSStringEncoding)encoding {
+- (void)saveWindowSetupInExtendedAttributesAtURL:(NSURL *)anURL 
forEncoding:(NSStringEncoding)encoding resetLocal:(BOOL)reset {
     
     NSString *path = [anURL path];
     NSMutableDictionary *dictionary = nil;
@@ -806,7 +805,9 @@
     if (path && [[NSUserDefaults standardUserDefaults] 
boolForKey:BDSKDisableDocumentExtendedAttributesKey] == NO) {
         
         // We could set each of these as a separate attribute name on the 
file, but then we'd need to muck around with prepending 
net.sourceforge.bibdesk. to each key, and that seems messy.
-        dictionary = [[self mainWindowSetupDictionaryFromExtendedAttributes] 
mutableCopy];
+        if (mainWindowSetupDictionary == nil)
+            [self objectFromExtendedAttributesForSetupKey:@""];
+        dictionary = [mainWindowSetupDictionary mutableCopy];
         
         [dictionary setObject:[[[tableView tableColumnIdentifiers] 
arrayByRemovingObject:BDSKImportOrderString] 
arrayByRemovingObject:BDSKRelevanceString] forKey:BDSKShownColsNamesKey];
         [dictionary setObject:[self currentTableColumnWidthsAndIdentifiers] 
forKey:BDSKColumnWidthsKey];
@@ -884,42 +885,46 @@
                 }
             }
         }
+        
+        if (reset) {
+            [mainWindowSetupDictionary release];
+            mainWindowSetupDictionary = [dictionary copy];
+        }
+        [dictionary release];
     }
-    
-    return [dictionary autorelease];
 }
 
 - (BOOL)boolForSetupKey:(NSString *)key {
-    id value = [[self mainWindowSetupDictionaryFromExtendedAttributes] 
objectForKey:key];
+    id value = [self objectFromExtendedAttributesForSetupKey:key];
     return [value respondsToSelector:@selector(boolValue)] ? [value boolValue] 
: [[NSUserDefaults standardUserDefaults] boolForKey:key];
 }
 
 - (NSInteger)integerForSetupKey:(NSString *)key {
-    id value = [[self mainWindowSetupDictionaryFromExtendedAttributes] 
objectForKey:key];
+    id value = [self objectFromExtendedAttributesForSetupKey:key];
     return [value respondsToSelector:@selector(integerValue)] ? [value 
integerValue] : [[NSUserDefaults standardUserDefaults] integerForKey:key];
 }
 
 - (double)doubleForSetupKey:(NSString *)key {
-    id value = [[self mainWindowSetupDictionaryFromExtendedAttributes] 
objectForKey:key];
+    id value = [self objectFromExtendedAttributesForSetupKey:key];
     return [value respondsToSelector:@selector(doubleValue)] ? [value 
doubleValue] : [[NSUserDefaults standardUserDefaults] doubleForKey:key];
 }
 
 - (id)objectForSetupKey:(NSString *)key {
-    return [[self mainWindowSetupDictionaryFromExtendedAttributes] 
objectForKey:key] ?: [[NSUserDefaults standardUserDefaults] objectForKey:key];
+    return [self objectFromExtendedAttributesForSetupKey:key] ?: 
[[NSUserDefaults standardUserDefaults] objectForKey:key];
 }
 
 - (double)doubleForSetupKey:(NSString *)key defaultValue:(double)defaultValue {
-    id value = [[self mainWindowSetupDictionaryFromExtendedAttributes] 
objectForKey:key];
+    id value = [self objectFromExtendedAttributesForSetupKey:key];
     return [value respondsToSelector:@selector(doubleValue)] ? [value 
doubleValue] : defaultValue;
 }
 
 - (NSStringEncoding)stringEncodingForSetupKey:(NSString *)key 
defaultValue:(NSStringEncoding)defaultValue {
-    id value = [[self mainWindowSetupDictionaryFromExtendedAttributes] 
objectForKey:key];
+    id value = [self objectFromExtendedAttributesForSetupKey:key];
     return [value respondsToSelector:@selector(integerValue)] ? [value 
integerValue] : defaultValue;
 }
 
 - (id)objectForSetupKey:(NSString *)key defaultValue:(id)defaultValue {
-    return [[self mainWindowSetupDictionaryFromExtendedAttributes] 
objectForKey:key] ?: defaultValue;
+    return [self objectFromExtendedAttributesForSetupKey:key] ?: defaultValue;
 }
 
 #pragma mark -
@@ -1242,13 +1247,8 @@
         }
         
         // save our window setup if we save or export to BibTeX
-        if ([[self class] isNativeType:typeName] || [typeName 
isEqualToString:BDSKMinimalBibTeXDocumentType]) {
-            NSDictionary *dictionary = [self 
saveWindowSetupInExtendedAttributesAtURL:absoluteURL forEncoding:encoding];
-            if (dictionary && BDSKIsSaveOrSaveAsOperation(saveOperation)) {
-                [mainWindowSetupDictionary release];
-                mainWindowSetupDictionary = [dictionary copy];
-            }
-        }
+        if ([[self class] isNativeType:typeName] || [typeName 
isEqualToString:BDSKMinimalBibTeXDocumentType])
+            [self saveWindowSetupInExtendedAttributesAtURL:absoluteURL 
forEncoding:encoding resetLocal:BDSKIsSaveOrSaveAsOperation(saveOperation)];
     }
     
     return didSave;

Modified: trunk/bibdesk/BibDocument_Search.m
===================================================================
--- trunk/bibdesk/BibDocument_Search.m  2022-06-09 14:37:36 UTC (rev 27595)
+++ trunk/bibdesk/BibDocument_Search.m  2022-06-09 16:14:06 UTC (rev 27596)
@@ -106,7 +106,7 @@
     if(fileSearchController == nil) {
         fileSearchController = [[BDSKFileContentSearchController alloc] 
initForOwner:self];
         [fileSearchController setDelegate:self];
-        NSData *sortDescriptorData = [[self 
mainWindowSetupDictionaryFromExtendedAttributes] 
objectForKey:BDSKFileContentSearchSortDescriptorKey] ?: [[NSUserDefaults 
standardUserDefaults] dataForKey:BDSKFileContentSearchSortDescriptorKey];
+        NSData *sortDescriptorData = [self 
objectForSetupKey:BDSKFileContentSearchSortDescriptorKey];
         if(sortDescriptorData)
             [fileSearchController setSortDescriptorData:sortDescriptorData];
         [[[fileSearchController tableView] menu] setDelegate:self];

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



_______________________________________________
Bibdesk-commit mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/bibdesk-commit

Reply via email to