The Inbox: System-ct.1233.mcz

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

The Inbox: System-ct.1233.mcz

commits-2
A new version of System was added to project The Inbox:
http://source.squeak.org/inbox/System-ct.1233.mcz

==================== Summary ====================

Name: System-ct.1233
Author: ct
Time: 16 May 2021, 8:29:18.906267 pm
UUID: da744348-52c0-3a4b-9f66-26ce81d8af02
Ancestors: System-nice.1232

Makes TextDiffBuilder capable of building string patches (that use +/- prefixes instead of text attributes) or combined patches that use both prefixes and attributes.

Usage:

        | aTextDiffBuilder |
        aTextDiffBuilder := TextDiffBuilder from: 'Hello world\Squeak is great\Carpe Squeak!' withCRs to: 'Hello world\Squeak is awesine\Carpe Squeak!' withCRs.
        aTextDiffBuilder buildStringPatch edit.
        aTextDiffBuilder buildPrefixedDisplayPatch edit.
        aTextDiffBuilder buildDisplayPatch edit. "classic"

=============== Diff against System-nice.1232 ===============

Item was added:
+ ----- Method: Preferences class>>allowEtoyUserCustomEvents (in category 'standard queries') -----
+ allowEtoyUserCustomEvents
+ ^ self
+ valueOfFlag: #allowEtoyUserCustomEvents
+ ifAbsent: [false]!

Item was added:
+ ----- Method: TextDiffBuilder class>>insertTextAttributes (in category 'as yet unclassified') -----
+ insertTextAttributes
+
+ ^ InsertTextAttributes ifNil: [InsertTextAttributes :=
+ self userInterfaceTheme insertTextAttributes
+ ifNil: [{TextColor red}]]!

Item was added:
+ ----- Method: TextDiffBuilder class>>normalTextAttributes (in category 'as yet unclassified') -----
+ normalTextAttributes
+
+ ^ NormalTextAttributes ifNil: [NormalTextAttributes :=
+ self userInterfaceTheme normalTextAttributes
+ ifNil: [{TextEmphasis normal}]]!

Item was added:
+ ----- Method: TextDiffBuilder class>>removeTextAttributes (in category 'as yet unclassified') -----
+ removeTextAttributes
+
+ ^ RemoveTextAttributes ifNil: [RemoveTextAttributes :=
+ self userInterfaceTheme removeTextAttributes
+ ifNil: [{TextEmphasis struckOut. TextColor blue}]]!

Item was changed:
  ----- Method: TextDiffBuilder>>buildDisplayPatch (in category 'creating patches') -----
  buildDisplayPatch
 
+ ^ self buildPatchWithAttributes: true withPrefixes: false!
- | stream result |
- stream := AttributedTextStream new.
-
- "Lazy initialize the text attributes cache."
- NormalTextAttributes ifNil: [NormalTextAttributes := self userInterfaceTheme normalTextAttributes
- ifNil: [{TextEmphasis normal}]].
- InsertTextAttributes ifNil: [InsertTextAttributes := self userInterfaceTheme insertTextAttributes
- ifNil: [{TextColor red}]].
- RemoveTextAttributes ifNil: [RemoveTextAttributes := self userInterfaceTheme removeTextAttributes
- ifNil: [{TextEmphasis struckOut. TextColor blue}]].
-
- self
- patchSequenceDoIfMatch: [ :string |
- self print: string withAttributes: NormalTextAttributes on: stream ]
- ifInsert: [ :string |
- self print: string withAttributes: InsertTextAttributes on: stream ]
- ifRemove: [ :string |
- self print: string withAttributes: RemoveTextAttributes on: stream ].
- result := stream contents.
- (result notEmpty
- and: [result last = Character cr
- and: [(self lastIsCR: xLines) not
- and: [(self lastIsCR: yLines) not]]]) ifTrue:
- [result := result allButLast].
- ^result!

Item was added:
+ ----- Method: TextDiffBuilder>>buildPatch (in category 'creating patches') -----
+ buildPatch
+
+ | result |
+ result := String streamContents: [:stream |
+ self
+ patchSequenceDoIfMatch: [:string |
+ self print: string on: stream]
+ ifInsert: [:string |
+ self print: '+ ' , string on: stream]
+ ifRemove: [:string |
+ self print: '- ' , string on: stream]].
+ (result notEmpty
+ and: [result last = Character cr
+ and: [(self lastIsCR: xLines) not
+ and: [(self lastIsCR: yLines) not]]]) ifTrue:
+ [result := result allButLast].
+ ^ result!

Item was added:
+ ----- Method: TextDiffBuilder>>buildPatchWithAttributes:withPrefixes: (in category 'creating patches') -----
+ buildPatchWithAttributes: useAttributes withPrefixes: usePrefixes
+
+ | stream result |
+ stream := useAttributes ifFalse: [WriteStream on: String new] ifTrue: [AttributedTextStream new].
+
+ self
+ patchSequenceDoIfMatch: [:string |
+ useAttributes ifTrue: [stream currentAttributes: self class normalTextAttributes].
+ self print: string on: stream]
+ ifInsert: [:string |
+ useAttributes ifTrue: [stream currentAttributes: self class insertTextAttributes].
+ usePrefixes ifTrue: [string := '+ ' , string].
+ self print: string on: stream]
+ ifRemove: [:string |
+ useAttributes ifTrue: [stream currentAttributes: self class removeTextAttributes].
+ usePrefixes ifTrue: [string := '- ' , string].
+ self print: string on: stream].
+ result := stream contents.
+
+ (result notEmpty
+ and: [result last = Character cr
+ and: [(self lastIsCR: xLines) not
+ and: [(self lastIsCR: yLines) not]]]) ifTrue:
+ [result := result allButLast].
+
+ ^ result!

Item was added:
+ ----- Method: TextDiffBuilder>>buildPrefixedDisplayPatch (in category 'creating patches') -----
+ buildPrefixedDisplayPatch
+
+ ^ self buildPatchWithAttributes: true withPrefixes: true!

Item was added:
+ ----- Method: TextDiffBuilder>>buildStringPatch (in category 'creating patches') -----
+ buildStringPatch
+
+ ^ self buildPatchWithAttributes: false withPrefixes: true!

Item was added:
+ ----- Method: TextDiffBuilder>>print:on: (in category 'private') -----
+ print: aString on: stream
+
+ stream nextPutAll: aString.
+ (aString notEmpty and: [
+ aString last = Character cr or: [
+ aString endsWith: String crlf ] ])
+ ifFalse: [ stream cr ]!

Item was changed:
  ----- Method: TextDiffBuilder>>print:withAttributes:on: (in category 'private') -----
  print: aString withAttributes: attributes on: stream
 
+ self deprecated.
+ stream currentAttributes: attributes.
+ ^ self print: aString on: stream!
- stream
- currentAttributes: attributes;
- nextPutAll: aString.
- (aString notEmpty and: [
- aString last = Character cr or: [
- aString endsWith: String crlf ] ])
- ifFalse: [ stream cr ]!