DiffTextView.st
changeset 177 36c5c99b9ffb
parent 165 df29ee4514c1
child 178 609b67e6140a
equal deleted inserted replaced
176:78b701d5b04c 177:36c5c99b9ffb
     9  other person.  No title to or ownership of the software is
     9  other person.  No title to or ownership of the software is
    10  hereby transferred.
    10  hereby transferred.
    11 "
    11 "
    12 
    12 
    13 TwoColumnTextView subclass:#DiffTextView
    13 TwoColumnTextView subclass:#DiffTextView
    14 	 instanceVariableNames:''
    14 	 instanceVariableNames:'useColors showSeparators addedColor addedBgColor removedColor
       
    15 				removedBgColor changedColor changedBgColor'
    15 	 classVariableNames:''
    16 	 classVariableNames:''
    16 	 poolDictionaries:''
    17 	 poolDictionaries:''
    17 	 category:'Views-Text'
    18 	 category:'Views-Text'
    18 !
    19 !
    19 
    20 
    32  hereby transferred.
    33  hereby transferred.
    33 "
    34 "
    34 !
    35 !
    35 
    36 
    36 version
    37 version
    37     ^ '$Header: /cvs/stx/stx/libtool/DiffTextView.st,v 1.9 1995-11-11 15:39:50 cg Exp $'
    38     ^ '$Header: /cvs/stx/stx/libtool/DiffTextView.st,v 1.10 1995-11-16 16:27:16 cg Exp $'
    38 !
    39 !
    39 
    40 
    40 documentation
    41 documentation
    41 "
    42 "
    42     a view showing diff (see unix manual pages) output in a 
    43     a view showing diff (see unix manual pages) output in a 
    53 
    54 
    54 !DiffTextView class methodsFor:'defaults'!
    55 !DiffTextView class methodsFor:'defaults'!
    55 
    56 
    56 diffCommand
    57 diffCommand
    57     ^ 'diff -b'
    58     ^ 'diff -b'
       
    59 ! !
       
    60 
       
    61 
       
    62 !DiffTextView methodsFor:'initialization'!
       
    63 
       
    64 initStyle
       
    65     super initStyle.
       
    66 
       
    67     showSeparators := false.
       
    68 
       
    69     useColors := ColoredListEntry notNil.
       
    70     useColors ifTrue:[
       
    71 	device hasColors ifTrue:[
       
    72 	    addedColor := Color black.
       
    73 	    addedBgColor := Color green.
       
    74 
       
    75 	    removedColor := Color white.
       
    76 	    removedBgColor := Color red.
       
    77 
       
    78 	    changedColor := Color white.
       
    79 	    changedBgColor := Color blue.
       
    80 	] ifFalse:[
       
    81 	    addedBgColor := removedBgColor := changedBgColor := Color black.
       
    82 	    addedColor := removedColor := changedColor := Color white.
       
    83 	]
       
    84     ].
       
    85 
       
    86     "Created: 16.11.1995 / 16:59:48 / cg"
    58 ! !
    87 ! !
    59 
    88 
    60 !DiffTextView methodsFor:'private'!
    89 !DiffTextView methodsFor:'private'!
    61 
    90 
    62 updateListsFrom:text1 and:text2 diffs:diffList
    91 updateListsFrom:text1 and:text2 diffs:diffList
   100 
   129 
   101 	    "
   130 	    "
   102 	     except for the first chunk, add a separating line
   131 	     except for the first chunk, add a separating line
   103 	    "
   132 	    "
   104 	    l1 size ~~ 0 ifTrue:[
   133 	    l1 size ~~ 0 ifTrue:[
   105 		l1 add:'--------'.
   134 		showSeparators ifTrue:[
   106 		l2 add:'--------'.
   135 		    l1 add:'--------'.
       
   136 		    l2 add:'--------'.
       
   137 		]
   107 	    ].
   138 	    ].
   108 
   139 
   109 	    "
   140 	    "
   110 	     in cleanup ?
   141 	     in cleanup ?
   111 	    "
   142 	    "
   132 		op == $c ifTrue:[
   163 		op == $c ifTrue:[
   133 		    state := #changed.
   164 		    state := #changed.
   134 		] ifFalse:[
   165 		] ifFalse:[
   135 		    op == $a ifTrue:[
   166 		    op == $a ifTrue:[
   136 			state := #added.
   167 			state := #added.
   137 			l1 add:(text1 at:idx1).
       
   138 			idx1 := idx1 + 1.
       
   139 		    ] ifFalse:[
   168 		    ] ifFalse:[
   140 			op == $d ifTrue:[
   169 			op == $d ifTrue:[
   141 			    state := #deleted
   170 			    state := #deleted
       
   171 			] ifFalse:[
       
   172 			    self halt:'unexpected diff entry'.
   142 			]
   173 			]
   143 		    ]
   174 		    ]
   144 		].
   175 		].
   145 
   176 
   146 	    ].
   177 	    ].
   147 
   178 
       
   179 nr1 print. ' ' print. op print. ' ' print. nr2 print. ' , ' print. nr3 printNL.
       
   180 
       
   181 "/            state == #added ifTrue:[
       
   182 "/                l1 add:(text1 at:idx1).
       
   183 "/                idx1 := idx1 + 1.
       
   184 "/            ].
       
   185 
   148 	    "
   186 	    "
   149 	     copy over unchanged lines
   187 	     copy over unchanged lines
   150 	    "
   188 	    "
   151 	    any := false.
   189 	    any := false.
   152 	    [idx1 < nr1] whileTrue:[
   190 	    [idx1 < nr1] whileTrue:[
       
   191 '< add:' print. idx1 printNL.
   153 		l1 add:(text1 at:idx1).
   192 		l1 add:(text1 at:idx1).
   154 		idx1 := idx1 + 1.
   193 		idx1 := idx1 + 1.
   155 		any := true.
   194 		any := true.
   156 	    ].
   195 	    ].
   157 	    [idx2 < nr2] whileTrue:[
   196 	    [idx2 < nr2] whileTrue:[
       
   197 '> add:' print. idx2 printNL.
   158 		l2 add:(text2 at:idx2).
   198 		l2 add:(text2 at:idx2).
   159 		idx2 := idx2 + 1.
   199 		idx2 := idx2 + 1.
   160 		any := true.
   200 		any := true.
   161 	    ].
   201 	    ].
   162 
   202 
       
   203 	    state == #added ifTrue:[
       
   204 		l1 add:(text1 at:idx1).
       
   205 		idx1 := idx1 + 1.
       
   206 	    ].
       
   207 	    state == #deleted ifTrue:[
       
   208 		l2 add:(text2 at:idx2).
       
   209 		idx2 := idx2 + 1.
       
   210 	    ].
       
   211 
       
   212 
   163 	    "
   213 	    "
   164 	     add a separating line, except at end
   214 	     add a separating line, except at end
   165 	    "
   215 	    "
   166 	    any ifTrue:[
   216 	    any ifTrue:[
   167 		state ~~ #finish ifTrue:[
   217 		state ~~ #finish ifTrue:[
   168 		    l1 add:'--------'.
   218 		    showSeparators ifTrue:[
   169 		    l2 add:'--------'.
   219 			l1 add:'--------'.
       
   220 			l2 add:'--------'.
       
   221 		    ]
   170 		]
   222 		]
   171 	    ].
   223 	    ].
   172 
   224 
   173 	] ifFalse:[
   225 	] ifFalse:[
   174 	    state == #changed ifTrue:[
   226 	    state == #changed ifTrue:[
   175 		(entry at:1) == $< ifTrue:[
   227 		(entry at:1) == $< ifTrue:[
   176 		    l1 add:(text1 at:idx1).
   228 		    useColors ifTrue:[
       
   229 			l1 add:(ColoredListEntry string:(text1 at:idx1) foregroundColor:changedColor backgroundColor:changedBgColor).
       
   230 		    ] ifFalse:[
       
   231 			l1 add:(text1 at:idx1).
       
   232 		    ].
   177 		    idx1 := idx1 + 1
   233 		    idx1 := idx1 + 1
   178 		] ifFalse:[
   234 		] ifFalse:[
   179 		    (entry at:1) == $> ifTrue:[
   235 		    (entry at:1) == $> ifTrue:[
   180 			l2 add:(text2 at:idx2).
   236 			useColors ifTrue:[
       
   237 			    l2 add:(ColoredListEntry string:(text2 at:idx2) foregroundColor:changedColor backgroundColor:changedBgColor)
       
   238 			] ifFalse:[
       
   239 			    l2 add:(text2 at:idx2).
       
   240 			].
   181 			idx2 := idx2 + 1
   241 			idx2 := idx2 + 1
   182 		    ] ifFalse:[
   242 		    ] ifFalse:[
   183 			(entry at:1) == $- ifTrue:[
   243 			(entry at:1) == $- ifTrue:[
   184 			] ifFalse:[
   244 			] ifFalse:[
   185 			    state := #initial.
   245 			    state := #initial.
   188 		    ]
   248 		    ]
   189 		]
   249 		]
   190 	    ] ifFalse:[
   250 	    ] ifFalse:[
   191 		state == #added ifTrue:[
   251 		state == #added ifTrue:[
   192 		    (entry at:1) == $> ifTrue:[
   252 		    (entry at:1) == $> ifTrue:[
   193 			l2 add:(text2 at:idx2).
   253 			useColors ifTrue:[
       
   254 			    l2 add:(ColoredListEntry string:(text2 at:idx2) foregroundColor:addedColor backgroundColor:addedBgColor )
       
   255 			] ifFalse:[
       
   256 			    l2 add:(text2 at:idx2).
       
   257 			].
   194 			idx2 := idx2 + 1.
   258 			idx2 := idx2 + 1.
   195 			l1 add:nil
   259 			l1 add:nil
   196 		    ] ifFalse:[
   260 		    ] ifFalse:[
   197 			state := #initial.
   261 			state := #initial.
   198 			dIdx := dIdx - 1
   262 			dIdx := dIdx - 1
   199 		    ]
   263 		    ]
   200 		] ifFalse:[
   264 		] ifFalse:[
   201 		    state == #deleted ifTrue:[
   265 		    state == #deleted ifTrue:[
   202 			(entry at:1) == $< ifTrue:[
   266 			(entry at:1) == $< ifTrue:[
   203 			    l1 add:(text1 at:idx1).
   267 			    useColors ifTrue:[
       
   268 				l1 add:(ColoredListEntry string:(text1 at:idx1) foregroundColor:removedColor backgroundColor:removedBgColor ).
       
   269 			    ] ifFalse:[
       
   270 				l1 add:(text1 at:idx1).
       
   271 			    ].
   204 			    idx1 := idx1 + 1.
   272 			    idx1 := idx1 + 1.
   205 			    l2 add:nil
   273 			    l2 add:nil
   206 			] ifFalse:[
   274 			] ifFalse:[
   207 			    state := #initial.
   275 			    state := #initial.
   208 			    dIdx := dIdx - 1
   276 			    dIdx := dIdx - 1
   220     [l2 size < l1 size] whileTrue:[
   288     [l2 size < l1 size] whileTrue:[
   221 	l2 add:''.
   289 	l2 add:''.
   222     ].
   290     ].
   223     textView1 list:l1.
   291     textView1 list:l1.
   224     textView2 list:l2
   292     textView2 list:l2
       
   293 
       
   294     "Modified: 16.11.1995 / 17:09:35 / cg"
   225 ! !
   295 ! !
   226 
   296 
   227 !DiffTextView methodsFor:'accessing'!
   297 !DiffTextView methodsFor:'accessing'!
   228 
   298 
   229 text1:t1 text2:t2
   299 text1:t1 text2:t2