Author: ericwa
Date: Sun Mar 16 00:22:08 2014
New Revision: 10575

URL: http://svn.gna.org/viewcvs/etoile?rev=10575&view=rev
Log:
COPersistentRoot: add a  property, which is a thin wrapper around the  
property. Reason for adding is both Typewriter and ProjectDemo have 
incompatible homegrown versions of this idea, and probably every application 
will need it. NOTE: as mentioned in the comment, I don't know whether we should 
call this , , , etc... It's called  to match COObject's -name.

Modified:
    trunk/Etoile/Frameworks/CoreObject/Core/COPersistentRoot.h
    trunk/Etoile/Frameworks/CoreObject/Core/COPersistentRoot.m
    trunk/Etoile/Frameworks/CoreObject/Tests/Core/TestPersistentRoot.m

Modified: trunk/Etoile/Frameworks/CoreObject/Core/COPersistentRoot.h
URL: 
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Core/COPersistentRoot.h?rev=10575&r1=10574&r2=10575&view=diff
==============================================================================
--- trunk/Etoile/Frameworks/CoreObject/Core/COPersistentRoot.h  (original)
+++ trunk/Etoile/Frameworks/CoreObject/Core/COPersistentRoot.h  Sun Mar 16 
00:22:08 2014
@@ -260,7 +260,22 @@
  * See COPersistentRootAttributeExportSize, COPersistentRootAttributeUsedSize.
  */
 @property (nonatomic, readonly) NSDictionary *attributes;
-
+/**
+ * The user-facing name of the persistent root. This property is provided for
+ * convenience; it is implemented on top of the metadata property.
+ *
+ * Because it's stored in the metadata dictionary, changes to the name are 
visible
+ * across all revisions and branches.
+ *
+ * You could also store a document name in
+ * the root object's -name property (see -[COObject name]), which would have 
the
+ * expected consequences: changing the name would cause a new revision to be 
committed, 
+ * old revisions would still use the old name, and different branches could 
have different names
+ * for the document.
+ *
+ * TODO: Rename to -displayName or -label to emphasize that this is the 
user-facing name?
+ */
+@property (nonatomic, copy) NSString *name;
 
 /** @taskunit Accessing Branches */
 

Modified: trunk/Etoile/Frameworks/CoreObject/Core/COPersistentRoot.m
URL: 
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Core/COPersistentRoot.m?rev=10575&r1=10574&r2=10575&view=diff
==============================================================================
--- trunk/Etoile/Frameworks/CoreObject/Core/COPersistentRoot.m  (original)
+++ trunk/Etoile/Frameworks/CoreObject/Core/COPersistentRoot.m  Sun Mar 16 
00:22:08 2014
@@ -25,6 +25,11 @@
 
 NSString * const COPersistentRootDidChangeNotification = 
@"COPersistentRootDidChangeNotification";
 
+/**
+ * Metadata dictionary key used by the `name` property.
+ */
+NSString * const COPersistentRootName = @"org.etoile.coreobject.name";
+
 @implementation COPersistentRoot
 
 @synthesize parentContext = _parentContext, UUID = _UUID;
@@ -282,6 +287,25 @@
 - (NSDictionary *)attributes
 {
        return [[self store] attributesForPersistentRootWithUUID: _UUID];
+}
+
+- (NSString *) name
+{
+       return self.metadata[COPersistentRootName];
+}
+
+- (void) setName: (NSString *)name
+{
+       NSMutableDictionary *md = [[NSMutableDictionary alloc] 
initWithDictionary: self.metadata];
+       if (name == nil)
+       {
+               [md removeObjectForKey: COPersistentRootName];
+       }
+       else
+       {
+               md[COPersistentRootName] = [[NSString alloc] initWithString: 
name];
+       }
+       self.metadata = md;
 }
 
 #pragma mark Accessing Branches -

Modified: trunk/Etoile/Frameworks/CoreObject/Tests/Core/TestPersistentRoot.m
URL: 
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Tests/Core/TestPersistentRoot.m?rev=10575&r1=10574&r2=10575&view=diff
==============================================================================
--- trunk/Etoile/Frameworks/CoreObject/Tests/Core/TestPersistentRoot.m  
(original)
+++ trunk/Etoile/Frameworks/CoreObject/Tests/Core/TestPersistentRoot.m  Sun Mar 
16 00:22:08 2014
@@ -691,4 +691,51 @@
         }];
 }
 
+- (void) testNameBasic
+{
+       UKNil(persistentRoot.name);
+       UKFalse(persistentRoot.hasChanges);
+       
+       persistentRoot.name = @"todo";
+       
+       UKObjectsEqual(@"todo", persistentRoot.name);
+       UKTrue(persistentRoot.hasChanges);
+       [persistentRoot commit];
+       
+       [self checkPersistentRootWithExistingAndNewContext: persistentRoot
+                                                                               
           inBlock: ^(COEditingContext *testCtx, COPersistentRoot *testProot, 
COBranch *testBranch, BOOL isNewContext)
+        {
+                UKObjectsEqual(@"todo", persistentRoot.name);
+        }];
+}
+
+- (void) testNameSetToNil
+{
+       persistentRoot.name = @"todo";
+       [persistentRoot commit];
+       
+       persistentRoot.name = nil;
+       UKNil(persistentRoot.name);
+       UKTrue(persistentRoot.hasChanges);
+       [persistentRoot commit];
+       
+       [self checkPersistentRootWithExistingAndNewContext: persistentRoot
+                                                                               
           inBlock: ^(COEditingContext *testCtx, COPersistentRoot *testProot, 
COBranch *testBranch, BOOL isNewContext)
+        {
+                UKNil(persistentRoot.name);
+        }];
+}
+
+- (void) testNameCopies
+{
+       NSMutableString *ms = [NSMutableString new];
+       persistentRoot.name = ms;
+       
+       UKObjectsEqual(@"", persistentRoot.name);
+       UKRaisesException([(NSMutableString *)persistentRoot.name appendString: 
@"foo"]);
+       
+       [ms appendString: @"a"];
+       UKObjectsEqual(@"", persistentRoot.name);
+}
+
 @end


_______________________________________________
Etoile-cvs mailing list
Etoile-cvs@gna.org
https://mail.gna.org/listinfo/etoile-cvs

Reply via email to