Commits

Anonymous committed c8a512e

Add background highlighting to diff lines

  • Participants
  • Parent commits b16fb90

Comments (0)

Files changed (2)

File English.lproj/Repo.xib

 		<string key="IBDocument.HIToolboxVersion">353.00</string>
 		<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
 			<bool key="EncodedWithXMLCoder">YES</bool>
+			<integer value="300330"/>
 			<integer value="300061"/>
-			<integer value="300349"/>
 		</object>
 		<object class="NSArray" key="IBDocument.PluginDependencies">
 			<bool key="EncodedWithXMLCoder">YES</bool>
 							<string key="NSKeyPath">currentOperation.outputAndError</string>
 							<object class="NSDictionary" key="NSOptions">
 								<string key="NS.key.0">NSContinuouslyUpdatesValue</string>
-								<integer value="1" key="NS.object.0"/>
+								<reference key="NS.object.0" ref="9"/>
 							</object>
 							<int key="NSNibBindingConnectorVersion">2</int>
 						</object>

File Source/RepoController.m

     NSDictionary *attrs = $dict({NSFontAttributeName, font},
                                 {NSParagraphStyleAttributeName, paraStyle});
     return [[NSAttributedString alloc] initWithString: code
-                                           attributes: attrs];
+                                            attributes: attrs];
+}
+
+static NSAttributedString* attributedStringForDiff( NSString *diff ) {
+    if (!diff) return nil;
+    NSFont *font = [NSFont fontWithName: @"Courier" size: 10.0f];
+    NSMutableAttributedString *result = [[NSMutableAttributedString alloc] initWithString:@""];
+    NSMutableParagraphStyle *paraStyle = [[NSMutableParagraphStyle alloc] init];
+    paraStyle.lineBreakMode = NSLineBreakByClipping;
+    for (NSString *line in [diff componentsSeparatedByCharactersInSet:[NSCharacterSet characterSetWithCharactersInString:@"\n"]]) {
+        Log(@"line: -%@-", line);
+        if (0 == [line length]) continue;
+        NSColor *bgColor;
+        switch ([line characterAtIndex:0]) {
+                case '+':
+                bgColor = [[NSColor greenColor] highlightWithLevel:0.5f];
+                break;
+            case '-':
+                bgColor = [[NSColor redColor] highlightWithLevel:0.5f];
+                break;
+            case '@':
+                bgColor = [[NSColor blueColor] highlightWithLevel:0.5f];
+                break;
+            default:
+                bgColor = [NSColor whiteColor];
+                break;
+        }
+        NSDictionary *attrs = $dict({NSFontAttributeName, font},
+                                    {NSParagraphStyleAttributeName, paraStyle},
+                                    {NSBackgroundColorAttributeName, bgColor});
+        [result appendAttributedString:[[NSAttributedString alloc] initWithString:[line stringByAppendingString:@"\n"]
+                                                                       attributes:attrs]];
+    }
+    return result;
 }
     
     
                 NSString *str = [revision diffFile: file withRevision: revision.parent error: &error];
                 if (!str)
                     str = error.localizedRecoverySuggestion;
-                text = attributedStringForSourceCode(str);
+                text = attributedStringForDiff(str);
             }
             break;
     }
-    
+    NSLog(@"dsfsafd");
     [_fileInfoView.textStorage setAttributedString: text];
     [[_fileInfoView textContainer] setContainerSize:NSMakeSize(10000000, 10000000)];
     [[_fileInfoView textContainer] setWidthTracksTextView:NO];