Author: ericwa
Date: Fri Mar 14 07:35:48 2014
New Revision: 10559

URL: http://svn.gna.org/viewcvs/etoile?rev=10559&view=rev
Log:
Typewriter: generate commit metadata for typing commits using 
COAttributedStringDiff

Modified:
    trunk/Etoile/Frameworks/CoreObject/Samples/CommonUI/EWUndoWindowController.m
    trunk/Etoile/Frameworks/CoreObject/Samples/CommonUI/Undo.xib
    
trunk/Etoile/Frameworks/CoreObject/Samples/Typewriter/EWTypewriterWindowController.h
    
trunk/Etoile/Frameworks/CoreObject/Samples/Typewriter/EWTypewriterWindowController.m

Modified: 
trunk/Etoile/Frameworks/CoreObject/Samples/CommonUI/EWUndoWindowController.m
URL: 
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Samples/CommonUI/EWUndoWindowController.m?rev=10559&r1=10558&r2=10559&view=diff
==============================================================================
--- 
trunk/Etoile/Frameworks/CoreObject/Samples/CommonUI/EWUndoWindowController.m    
    (original)
+++ 
trunk/Etoile/Frameworks/CoreObject/Samples/CommonUI/EWUndoWindowController.m    
    Fri Mar 14 07:35:48 2014
@@ -7,8 +7,12 @@
 
 #import "EWUndoWindowController.h"
 #import "EWGraphRenderer.h"
+#import "TypewriterDocument.h"
 #import <CoreObject/CoreObject.h>
 #import <CoreObject/COCommandGroup.h>
+#import <CoreObject/COCommandSetCurrentVersionForBranch.h>
+#import <CoreObject/COEditingContext+Private.h>
+#import <CoreObject/COAttributedStringDiff.h>
 #import <EtoileFoundation/Macros.h>
 
 @implementation EWUndoWindowController
@@ -164,6 +168,47 @@
        return node;
 }
 
+/*
+- (NSString *) detailedDescriptionOfNode: (COCommandGroup *)aCommand
+{
+       if ([[aCommand contents] count] != 1)
+               return nil;
+
+       if (![[[aCommand contents] firstObject] isKindOfClass: 
[COCommandSetCurrentVersionForBranch class]])
+               return nil;
+       
+       COCommandSetCurrentVersionForBranch *versionChange = [[aCommand 
contents] firstObject];
+       
+       COPersistentRoot *noteProot = [_track.editingContext 
persistentRootForUUID: [versionChange persistentRootUUID]];
+       if (noteProot == nil)
+               return nil;
+       
+       if (![[noteProot rootObject] isKindOfClass: [TypewriterDocument class]])
+               return nil;
+       
+       COObjectGraphContext *docGraph = [noteProot 
objectGraphContextForPreviewingRevision: [_track.editingContext 
revisionForRevisionUUID: versionChange.revisionUUID
+                                                                               
                                                                                
                                                                         
persistentRootUUID: versionChange.persistentRootUUID]];
+
+       COObjectGraphContext *oldDocGraph = [noteProot 
objectGraphContextForPreviewingRevision: [_track.editingContext 
revisionForRevisionUUID: versionChange.oldRevisionUUID
+                                                                               
                                                                                
                                                                                
persistentRootUUID: versionChange.persistentRootUUID]];
+                               
+       
+       TypewriterDocument *doc = docGraph.rootObject;
+       COAttributedString *as = doc.attrString;
+
+       TypewriterDocument *oldDoc =  oldDocGraph.rootObject;
+       COAttributedString *oldAs = oldDoc.attrString;
+
+       COAttributedStringDiff *diff = [[COAttributedStringDiff alloc] 
initWithFirstAttributedString: oldAs
+                                                                               
                                                                  
secondAttributedString: as
+                                                                               
                                                                                
                  source: nil];
+
+       NSString *desc = [diff description];
+       desc =[desc stringByReplacingOccurrencesOfString: @"\n" withString: @" 
"];
+       return desc;
+}
+*/
+
 /* NSTableViewDataSource */
 
 - (NSInteger)numberOfRowsInTableView:(NSTableView *)tableView
@@ -186,7 +231,14 @@
        {
                return node.date;
        }
-       return @(row);
+       else if ([[tableColumn identifier] isEqualToString: @"description"])
+       {
+               return [node localizedShortDescription];
+       }
+       else
+       {
+               return @(row);
+       }
 }
 
 - (void)tableView:(NSTableView *)tableView setObjectValue:(id)object 
forTableColumn:(NSTableColumn *)tableColumn row:(NSInteger)row

Modified: trunk/Etoile/Frameworks/CoreObject/Samples/CommonUI/Undo.xib
URL: 
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Samples/CommonUI/Undo.xib?rev=10559&r1=10558&r2=10559&view=diff
==============================================================================
--- trunk/Etoile/Frameworks/CoreObject/Samples/CommonUI/Undo.xib        
(original)
+++ trunk/Etoile/Frameworks/CoreObject/Samples/CommonUI/Undo.xib        Fri Mar 
14 07:35:48 2014
@@ -147,10 +147,28 @@
                                                                                
                                </object>
                                                                                
                                <reference key="NSTextColor" ref="1043563517"/>
                                                                                
                        </object>
-                                                                               
                        <object class="IBCustomCell" key="NSDataCell" 
id="255043031">
-                                                                               
                                <int key="NSCellFlags">0</int>
-                                                                               
                                <int key="NSCellFlags2">131072</int>
+                                                                               
                        <object class="NSTextFieldCell" key="NSDataCell" 
id="350472797">
+                                                                               
                                <int key="NSCellFlags">337641537</int>
+                                                                               
                                <int key="NSCellFlags2">272762880</int>
+                                                                               
                                <string key="NSContents">Text</string>
+                                                                               
                                <reference key="NSSupport" ref="26"/>
+                                                                               
                                <string key="NSCellIdentifier">_NS:9</string>
                                                                                
                                <reference key="NSControlView" ref="154456502"/>
+                                                                               
                                <object class="NSColor" key="NSBackgroundColor">
+                                                                               
                                        <int key="NSColorSpace">6</int>
+                                                                               
                                        <string 
key="NSCatalogName">System</string>
+                                                                               
                                        <string 
key="NSColorName">controlColor</string>
+                                                                               
                                        <object class="NSColor" key="NSColor" 
id="651919110">
+                                                                               
                                                <int key="NSColorSpace">3</int>
+                                                                               
                                                <bytes 
key="NSWhite">MC42NjY2NjY2NjY3AA</bytes>
+                                                                               
                                        </object>
+                                                                               
                                </object>
+                                                                               
                                <object class="NSColor" key="NSTextColor" 
id="672190575">
+                                                                               
                                        <int key="NSColorSpace">6</int>
+                                                                               
                                        <string 
key="NSCatalogName">System</string>
+                                                                               
                                        <string 
key="NSColorName">controlTextColor</string>
+                                                                               
                                        <reference key="NSColor" 
ref="804677898"/>
+                                                                               
                                </object>
                                                                                
                        </object>
                                                                                
                        <int key="NSResizingMask">3</int>
                                                                                
                        <bool key="NSIsResizeable">YES</bool>
@@ -188,17 +206,9 @@
                                                                                
                                        <int key="NSColorSpace">6</int>
                                                                                
                                        <string 
key="NSCatalogName">System</string>
                                                                                
                                        <string 
key="NSColorName">controlBackgroundColor</string>
-                                                                               
                                        <object class="NSColor" key="NSColor">
-                                                                               
                                                <int key="NSColorSpace">3</int>
-                                                                               
                                                <bytes 
key="NSWhite">MC42NjY2NjY2NjY3AA</bytes>
-                                                                               
                                        </object>
+                                                                               
                                        <reference key="NSColor" 
ref="651919110"/>
                                                                                
                                </object>
-                                                                               
                                <object class="NSColor" key="NSTextColor" 
id="672190575">
-                                                                               
                                        <int key="NSColorSpace">6</int>
-                                                                               
                                        <string 
key="NSCatalogName">System</string>
-                                                                               
                                        <string 
key="NSColorName">controlTextColor</string>
-                                                                               
                                        <reference key="NSColor" 
ref="804677898"/>
-                                                                               
                                </object>
+                                                                               
                                <reference key="NSTextColor" ref="672190575"/>
                                                                                
                        </object>
                                                                                
                        <int key="NSResizingMask">3</int>
                                                                                
                        <bool key="NSIsResizeable">YES</bool>
@@ -506,14 +516,6 @@
                                </object>
                                <object class="IBConnectionRecord">
                                        <object class="IBOutletConnection" 
key="connection">
-                                               <string 
key="label">graphRenderer</string>
-                                               <reference key="source" 
ref="255043031"/>
-                                               <reference key="destination" 
ref="471673241"/>
-                                       </object>
-                                       <string key="id">ufv-1f-EYA</string>
-                               </object>
-                               <object class="IBConnectionRecord">
-                                       <object class="IBOutletConnection" 
key="connection">
                                                <string 
key="label">delegate</string>
                                                <reference key="source" 
ref="154456502"/>
                                                <reference key="destination" 
ref="578893345"/>
@@ -634,7 +636,7 @@
                                                <string 
key="id">7Wv-il-5FT</string>
                                                <reference key="object" 
ref="271933553"/>
                                                <array class="NSMutableArray" 
key="children">
-                                                       <reference 
ref="255043031"/>
+                                                       <reference 
ref="350472797"/>
                                                </array>
                                                <reference key="parent" 
ref="154456502"/>
                                        </object>
@@ -688,11 +690,6 @@
                                                <reference key="parent" 
ref="1036122882"/>
                                        </object>
                                        <object class="IBObjectRecord">
-                                               <string 
key="id">4ns-Js-9zy</string>
-                                               <reference key="object" 
ref="255043031"/>
-                                               <reference key="parent" 
ref="271933553"/>
-                                       </object>
-                                       <object class="IBObjectRecord">
                                                <string 
key="id">3Mn-QH-O7Q</string>
                                                <reference key="object" 
ref="422572411"/>
                                                <reference key="parent" 
ref="461634304"/>
@@ -730,6 +727,11 @@
                                                <string 
key="id">dlT-xd-2AY</string>
                                                <reference key="object" 
ref="487208779"/>
                                                <reference key="parent" 
ref="424234646"/>
+                                       </object>
+                                       <object class="IBObjectRecord">
+                                               <string 
key="id">PFm-ZK-yPl</string>
+                                               <reference key="object" 
ref="350472797"/>
+                                               <reference key="parent" 
ref="271933553"/>
                                        </object>
                                </array>
                        </object>
@@ -742,8 +744,6 @@
                                <boolean value="NO" key="-3.showNotes"/>
                                <string 
key="3Mn-QH-O7Q.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <string 
key="3fn-dM-qV6.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
-                               <string 
key="4ns-Js-9zy.CustomClassName">EWGraphLabelCell</string>
-                               <string 
key="4ns-Js-9zy.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <string 
key="7Wv-il-5FT.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <boolean value="NO" key="7Wv-il-5FT.showNotes"/>
                                <string 
key="ArB-uT-hdy.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -767,6 +767,7 @@
                                <string 
key="Oeu-Ve-LC8.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <reference key="Oeu-Ve-LC8.IBUserGuides" 
ref="0"/>
                                <boolean value="NO" key="Oeu-Ve-LC8.showNotes"/>
+                               <string 
key="PFm-ZK-yPl.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <string 
key="WXj-3B-l8x.IBPluginDependency">com.apple.InterfaceBuilder.CocoaPlugin</string>
                                <reference key="WXj-3B-l8x.IBUserGuides" 
ref="0"/>
                                <boolean value="NO" key="WXj-3B-l8x.showNotes"/>
@@ -811,25 +812,6 @@
                                        </object>
                                </object>
                                <object class="IBPartialClassDescription">
-                                       <string 
key="className">EWGraphLabelCell</string>
-                                       <string 
key="superclassName">NSCell</string>
-                                       <object class="NSMutableDictionary" 
key="outlets">
-                                               <string 
key="NS.key.0">graphRenderer</string>
-                                               <string 
key="NS.object.0">EWGraphRenderer</string>
-                                       </object>
-                                       <object class="NSMutableDictionary" 
key="toOneOutletInfosByName">
-                                               <string 
key="NS.key.0">graphRenderer</string>
-                                               <object 
class="IBToOneOutletInfo" key="NS.object.0">
-                                                       <string 
key="name">graphRenderer</string>
-                                                       <string 
key="candidateClassName">EWGraphRenderer</string>
-                                               </object>
-                                       </object>
-                                       <object 
class="IBClassDescriptionSource" key="sourceIdentifier">
-                                               <string 
key="majorKey">IBProjectSource</string>
-                                               <string 
key="minorKey">./Classes/EWGraphLabelCell.h</string>
-                                       </object>
-                               </object>
-                               <object class="IBPartialClassDescription">
                                        <string 
key="className">EWGraphRenderer</string>
                                        <string 
key="superclassName">NSObject</string>
                                        <object 
class="IBClassDescriptionSource" key="sourceIdentifier">

Modified: 
trunk/Etoile/Frameworks/CoreObject/Samples/Typewriter/EWTypewriterWindowController.h
URL: 
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Samples/Typewriter/EWTypewriterWindowController.h?rev=10559&r1=10558&r2=10559&view=diff
==============================================================================
--- 
trunk/Etoile/Frameworks/CoreObject/Samples/Typewriter/EWTypewriterWindowController.h
        (original)
+++ 
trunk/Etoile/Frameworks/CoreObject/Samples/Typewriter/EWTypewriterWindowController.h
        Fri Mar 14 07:35:48 2014
@@ -40,8 +40,6 @@
        // Tracking text changes
        BOOL changedByUser;
        NSTimer *coalescingTimer;
-       NSString *affectedText;
-       NSString *replacementText;
 }
 
 @property (nonatomic, readonly) NSTableView *notesTable;

Modified: 
trunk/Etoile/Frameworks/CoreObject/Samples/Typewriter/EWTypewriterWindowController.m
URL: 
http://svn.gna.org/viewcvs/etoile/trunk/Etoile/Frameworks/CoreObject/Samples/Typewriter/EWTypewriterWindowController.m?rev=10559&r1=10558&r2=10559&view=diff
==============================================================================
--- 
trunk/Etoile/Frameworks/CoreObject/Samples/Typewriter/EWTypewriterWindowController.m
        (original)
+++ 
trunk/Etoile/Frameworks/CoreObject/Samples/Typewriter/EWTypewriterWindowController.m
        Fri Mar 14 07:35:48 2014
@@ -14,6 +14,7 @@
 #import "EWNoteListDataSource.h"
 #import "PrioritySplitViewDelegate.h"
 #import "EWHistoryWindowController.h"
+#import <CoreObject/COAttributedStringDiff.h>
 
 @implementation EWTypewriterWindowController
 
@@ -444,26 +445,6 @@
 {
        changedByUser = YES;
        
-       NSLog(@"should add %@", replacementString);
-       
-       // These are just used to provide commit metadata
-       
-       if (affectedText == nil)
-               affectedText = @"";
-       
-       if (replacementText == nil)
-               replacementText = @"";
-       
-       // This is a complete hack (just append together the modified regions 
and replacement
-       // text of possibly disjoint edits) but it produces commit descriptions 
that are usually helpful
-       
-       if (affectedCharRange.length > 0)
-               affectedText = [affectedText stringByAppendingString:
-                                               [[[aTextView textStorage] 
string] substringWithRange: affectedCharRange]];
-       
-       if ([replacementString length] > 0)
-               replacementText = [replacementText stringByAppendingString: 
replacementString];
-       
        return YES;
 }
 
@@ -486,6 +467,8 @@
        NSString *editedText = [[textStorage string] substringWithRange: 
[textStorage editedRange]];
        
        NSLog(@"Text storage did process editing. %@ edited range: %@ = %@", 
notification.userInfo, NSStringFromRange([textStorage editedRange]), 
editedText);
+       
+       // FIXME: I don't think this is needed
        [textView setNeedsDisplay: YES];
        
        if (changedByUser)
@@ -514,31 +497,66 @@
 
 - (void) commitTextChangesAsCheckpoint: (BOOL)isCheckpoint
 {
-       if (isCheckpoint)
-       {
-               selectedNote.currentBranch.shouldMakeEmptyCommit = YES;
-       }
-       
-       if (replacementText == nil && [affectedText length] > 0)
-       {
-               [self commitWithIdentifier: @"modify-text" 
descriptionArguments: @[Trim(affectedText)] coalesce: YES isMinorTextEdit: 
!isCheckpoint];
-       }
-       else if ([replacementText isEqualToString: @""] && [affectedText 
length] > 0)
-       {
-               [self commitWithIdentifier: @"delete-text" 
descriptionArguments: @[Trim(affectedText)] coalesce: YES isMinorTextEdit: 
!isCheckpoint];
-       }
-       else if ([replacementText length] > 0 && [affectedText isEqualToString: 
@""])
-       {
-               [self commitWithIdentifier: @"insert-text" 
descriptionArguments: @[Trim(replacementText)] coalesce: YES isMinorTextEdit: 
!isCheckpoint];
-       }
-       else if ([replacementText length] > 0 && [affectedText length] > 0)
-       {
-               [self commitWithIdentifier: @"replace-text" 
descriptionArguments: @[Trim(affectedText), Trim(replacementText)] coalesce: 
YES isMinorTextEdit: !isCheckpoint];
-       }
-       else
-       {
-               NSLog(@"%@: got -textStorageDidProcessEditing:, but it wasn't 
caused by us.. ignoring", self);
-       }
+       // Use COAttributedStringDiff to generate commit metadata that 
summarizes
+       // simple changes. Otherwise, if several edits were made, just record 
the change as "Typing"
+       
+       TypewriterDocument *doc = [selectedNote rootObject];
+       COAttributedString *as = doc.attrString;
+       
+       TypewriterDocument *oldDoc = [[selectedNote 
objectGraphContextForPreviewingRevision: [selectedNote currentRevision]] 
rootObject];
+       COAttributedString *oldAs = oldDoc.attrString;
+       
+       COAttributedStringDiff *diff = [[COAttributedStringDiff alloc] 
initWithFirstAttributedString: oldAs
+                                                                               
                                                                  
secondAttributedString: as
+                                                                               
                                                                                
                  source: nil];
+       NSString *identifier = @"typing";
+       NSArray *descArgs = @[];
+       
+       if ([diff.operations count] == 1)
+       {
+               COAttributedStringOperation *op = diff.operations[0];
+               
+               NSString *opRangeString = [[oldAs string] substringWithRange: 
op.range];
+               NSString *opRangeStringTrimmed = Trim(opRangeString);
+               
+               if ([op isKindOfClass: 
[COAttributedStringDiffOperationAddAttribute class]])
+               {
+                       identifier = @"modify-text";
+                       descArgs = @[opRangeStringTrimmed];
+               }
+               else if ([op isKindOfClass: 
[COAttributedStringDiffOperationRemoveAttribute class]])
+               {
+                       identifier = @"modify-text";
+                       descArgs = @[opRangeStringTrimmed];
+               }
+               else if ([op isKindOfClass: 
[COAttributedStringDiffOperationDeleteRange class]])
+               {
+                       identifier = @"delete-text";
+                       descArgs = @[opRangeStringTrimmed];
+               }
+               else if ([op isKindOfClass: 
[COAttributedStringDiffOperationInsertAttributedSubstring class]])
+               {
+                       COObjectGraphContext *insertedSubstringCtx = 
[COObjectGraphContext new];
+                       [insertedSubstringCtx setItemGraph: 
((COAttributedStringDiffOperationInsertAttributedSubstring 
*)op).attributedStringItemGraph];
+                       COAttributedString *insertedSubstring = 
insertedSubstringCtx.rootObject;
+                       NSString *insertedTextTrimmed = Trim([insertedSubstring 
string]);
+                                               
+                       identifier = @"insert-text";
+                       descArgs = @[insertedTextTrimmed];
+               }
+               else if ([op isKindOfClass: 
[COAttributedStringDiffOperationReplaceRange class]])
+               {
+                       COObjectGraphContext *insertedSubstringCtx = 
[COObjectGraphContext new];
+                       [insertedSubstringCtx setItemGraph: 
((COAttributedStringDiffOperationReplaceRange *)op).attributedStringItemGraph];
+                       COAttributedString *insertedSubstring = 
insertedSubstringCtx.rootObject;
+                       NSString *insertedTextTrimmed = Trim([insertedSubstring 
string]);
+                       
+                       identifier = @"replace-text";
+                       descArgs = @[opRangeStringTrimmed, insertedTextTrimmed];
+               }
+       }
+
+       [self commitWithIdentifier: identifier descriptionArguments: descArgs];
 }
 
 - (void) coalescingTimer: (NSTimer *)timer
@@ -553,8 +571,6 @@
 
                [coalescingTimer invalidate];
                coalescingTimer = nil;
-               affectedText = nil;
-               replacementText = nil;
        }
 }
 


_______________________________________________
Etoile-cvs mailing list
[email protected]
https://mail.gna.org/listinfo/etoile-cvs

Reply via email to