Revision: 22357
          http://sourceforge.net/p/bibdesk/svn/22357
Author:   hofman
Date:     2018-06-24 21:50:33 +0000 (Sun, 24 Jun 2018)
Log Message:
-----------
make specialized scripting properties of fields writable

Modified Paths:
--------------
    trunk/bibdesk/BDSKField.h
    trunk/bibdesk/BDSKField.m
    trunk/bibdesk/Scripting/BibDesk.sdef

Modified: trunk/bibdesk/BDSKField.h
===================================================================
--- trunk/bibdesk/BDSKField.h   2018-06-24 16:36:51 UTC (rev 22356)
+++ trunk/bibdesk/BDSKField.h   2018-06-24 21:50:33 UTC (rev 22357)
@@ -57,12 +57,16 @@
 - (void)setBibTeXString:(NSString *)newValue;
 
 - (NSInteger)integerValue;
+- (void)setIntegerValue:(NSInteger)newValue;
 
 - (NSString *)URLStringValue;
+- (void)setURLStringValue:(NSString *)newValue;
 
 - (NSURL *)fileURLValue;
+- (void)setFileURLValue:(NSURL *)newValue;
 
 - (NSString *)relativePathValue;
+- (void)setRelativePathValue:(NSString *)newValue;
 
 - (BOOL)isInherited;
 

Modified: trunk/bibdesk/BDSKField.m
===================================================================
--- trunk/bibdesk/BDSKField.m   2018-06-24 16:36:51 UTC (rev 22356)
+++ trunk/bibdesk/BDSKField.m   2018-06-24 21:50:33 UTC (rev 22357)
@@ -127,14 +127,62 @@
     return [bibItem integerValueOfField:name];
 }
 
+- (void)setIntegerValue:(NSInteger)newValue {
+    if ([[bibItem owner] isDocument] == NO) {
+        NSScriptCommand *cmd = [NSScriptCommand currentCommand];
+        [cmd setScriptErrorNumber:NSReceiversCantHandleCommandScriptError];
+        [cmd setScriptErrorString:NSLocalizedString(@"Cannot set property of 
external publication.",@"Error description")];
+    } else if ([name isBooleanField]) {
+        [bibItem setField:name toBoolValue:newValue];
+        [[bibItem undoManager] 
setActionName:NSLocalizedString(@"AppleScript",@"Undo action name for 
AppleScript")];
+    } else if ([name isTriStateField]) {
+        [bibItem setField:name toTriStateValue:newValue];
+        [[bibItem undoManager] 
setActionName:NSLocalizedString(@"AppleScript",@"Undo action name for 
AppleScript")];
+    } else if ([name isRatingField]) {
+        [bibItem setField:name toRatingValue:newValue];
+        [[bibItem undoManager] 
setActionName:NSLocalizedString(@"AppleScript",@"Undo action name for 
AppleScript")];
+    } else {
+        NSScriptCommand *cmd = [NSScriptCommand currentCommand];
+        [cmd setScriptErrorNumber:NSArgumentsWrongScriptError];
+    }
+}
+
 - (NSString *)URLStringValue {
     return [name isURLField] ? [[bibItem URLForField:name] absoluteString] : 
nil;
 }
 
+- (void)setURLStringValue:(NSString *)newValue {
+    if ([[bibItem owner] isDocument] == NO) {
+        NSScriptCommand *cmd = [NSScriptCommand currentCommand];
+        [cmd setScriptErrorNumber:NSReceiversCantHandleCommandScriptError];
+        [cmd setScriptErrorString:NSLocalizedString(@"Cannot set property of 
external publication.",@"Error description")];
+    } else if ([name isURLField]) {
+        [bibItem setField:name toURLValue:[NSURL URLWithString:newValue]];
+        [[bibItem undoManager] 
setActionName:NSLocalizedString(@"AppleScript",@"Undo action name for 
AppleScript")];
+    } else {
+        NSScriptCommand *cmd = [NSScriptCommand currentCommand];
+        [cmd setScriptErrorNumber:NSArgumentsWrongScriptError];
+    }
+}
+
 - (NSURL *)fileURLValue {
     return [name isLocalFileField] ? [bibItem localFileURLForField:name] : nil;
 }
 
+- (void)setFileURLValue:(NSURL *)newValue {
+    if ([[bibItem owner] isDocument] == NO) {
+        NSScriptCommand *cmd = [NSScriptCommand currentCommand];
+        [cmd setScriptErrorNumber:NSReceiversCantHandleCommandScriptError];
+        [cmd setScriptErrorString:NSLocalizedString(@"Cannot set property of 
external publication.",@"Error description")];
+    } else if ([name isLocalFileField]) {
+        [bibItem setField:name toURLValue:newValue];
+        [[bibItem undoManager] 
setActionName:NSLocalizedString(@"AppleScript",@"Undo action name for 
AppleScript")];
+    } else {
+        NSScriptCommand *cmd = [NSScriptCommand currentCommand];
+        [cmd setScriptErrorNumber:NSArgumentsWrongScriptError];
+    }
+}
+
 - (NSString *)relativePathValue {
     NSString *basePath = [bibItem basePath];
     NSString *path = [[self fileURLValue] path];
@@ -141,6 +189,20 @@
     return path && basePath ? [path relativePathFromPath:basePath] : nil;
 }
 
+- (void)setRelativePathValue:(NSString *)newValue {
+    if ([[bibItem owner] isDocument] == NO) {
+        NSScriptCommand *cmd = [NSScriptCommand currentCommand];
+        [cmd setScriptErrorNumber:NSReceiversCantHandleCommandScriptError];
+        [cmd setScriptErrorString:NSLocalizedString(@"Cannot set property of 
external publication.",@"Error description")];
+    } else if ([name isLocalFileField]) {
+        [bibItem setField:name toValue:newValue];
+        [[bibItem undoManager] 
setActionName:NSLocalizedString(@"AppleScript",@"Undo action name for 
AppleScript")];
+    } else {
+        NSScriptCommand *cmd = [NSScriptCommand currentCommand];
+        [cmd setScriptErrorNumber:NSArgumentsWrongScriptError];
+    }
+}
+
 - (BOOL)isInherited {
        return [[bibItem valueOfField:name] isInherited];
 }

Modified: trunk/bibdesk/Scripting/BibDesk.sdef
===================================================================
--- trunk/bibdesk/Scripting/BibDesk.sdef        2018-06-24 16:36:51 UTC (rev 
22356)
+++ trunk/bibdesk/Scripting/BibDesk.sdef        2018-06-24 21:50:33 UTC (rev 
22357)
@@ -1161,19 +1161,19 @@
                 description="The value of the field as raw BibTeX">
                 <cocoa key="bibTeXString"/>
             </property>
-            <property name="integer value" code="Intv" type="integer" 
access="r"
+            <property name="integer value" code="Intv" type="integer"
                 description="The integer value of the field">
                 <cocoa key="integerValue"/>
             </property>
-            <property name="URL value" code="URLv" type="text" access="r"
+            <property name="URL value" code="URLv" type="text"
                 description="The URL value of the remote URL field">
                 <cocoa key="URLStringValue"/>
             </property>
-            <property name="file value" code="Filv" type="file" access="r"
+            <property name="file value" code="Filv" type="file"
                 description="The file value of the local file field">
                 <cocoa key="fileURLValue"/>
             </property>
-            <property name="relative path value" code="rPtv" type="text" 
access="r"
+            <property name="relative path value" code="rPtv" type="text"
                 description="The relative path value of the local file field">
                 <cocoa key="relativePathValue"/>
             </property>

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