HistoryManager.st
changeset 494 6bc61cd32f7c
parent 320 661e503430ae
child 497 abebd0d145e5
--- a/HistoryManager.st	Sat Oct 12 18:23:44 1996 +0200
+++ b/HistoryManager.st	Sat Oct 12 21:48:28 1996 +0200
@@ -18,7 +18,7 @@
 	category:'System-Changes-History'
 !
 
-!HistoryManager class methodsFor:'documentation'!
+!HistoryManager  class methodsFor:'documentation'!
 
 copyright 
 "
@@ -63,7 +63,7 @@
 "
 ! !
 
-!HistoryManager class methodsFor:'initialization'!
+!HistoryManager  class methodsFor:'initialization'!
 
 initMe
     "setup theOneAndOnly instance of myself (if not already present"
@@ -83,7 +83,7 @@
     "Modified: 20.4.1996 / 20:34:09 / cg"
 ! !
 
-!HistoryManager class methodsFor:'instance creation'!
+!HistoryManager  class methodsFor:'instance creation'!
 
 new
     "because there can be only ONE HistoryManager, new must me redefiend"
@@ -103,7 +103,7 @@
     "Modified: 11.08.1995 / 17:01:29 / robert"
 ! !
 
-!HistoryManager class methodsFor:'accessing'!
+!HistoryManager  class methodsFor:'accessing'!
 
 instance
     "return the one and only historyManager instance"
@@ -122,7 +122,7 @@
     "Modified: 20.4.1996 / 20:31:32 / cg"
 ! !
 
-!HistoryManager class methodsFor:'activation / deactivation'!
+!HistoryManager  class methodsFor:'activation / deactivation'!
 
 activate
     "activate the HistoryManagement"
@@ -155,7 +155,7 @@
     "Modified: 20.4.1996 / 20:31:53 / cg"
 ! !
 
-!HistoryManager class methodsFor:'change and update'!
+!HistoryManager  class methodsFor:'change and update'!
 
 update:what with:aParameter from:changedObject
     "intercepts system restart - reinstall mySelf as dependent of all classes"
@@ -175,7 +175,7 @@
     "Created: 15.6.1996 / 15:25:53 / cg"
 ! !
 
-!HistoryManager class methodsFor:'helpers'!
+!HistoryManager  class methodsFor:'helpers'!
 
 getAllHistoriesFrom:someString
     "returns anArray of HistoryLines from a string.
@@ -327,37 +327,34 @@
 
 !HistoryManager methodsFor:'updateHistory'!
 
-addHistoryTo:someString forceModification:forceModification forceCreation:forceCreation
+addHistory:what to:someString
     "private - add a historyLine at end to the sourceCode;
      check for multiple lines of the same user and merge into one.
-     If forceModification is true or a history already exists in someString,
-     add a 'Modified' line; otherwise, add a 'Created' line."
+     What may be one of #modification or #creation, to choose among
+     'Modified' or 'Created' lines."
 
     | histLines pos wStream sourceCode previousHistories
       newLine |
 
     "Check whether we want a history to be added"    
     historyMode ifFalse:[
-	^ someString
+        ^ someString
     ].
+
     previousHistories := self class getAllHistoriesFrom:someString.
 
+    what == #creation ifTrue:[
+        newLine := (HistoryLine newCreated).
+    ] ifFalse:[
+        newLine := (HistoryLine new)
+    ].
+
     "extract source body."
     previousHistories isEmpty ifTrue: [
-	sourceCode := someString withoutSeparators.
-	forceModification ifTrue:[
-	    newLine := (HistoryLine new)
-	] ifFalse:[
-	    newLine := (HistoryLine newCreated).
-	]
+        sourceCode := someString withoutSeparators.
     ] ifFalse: [
-	pos := (previousHistories first) firstPositionInSourceCode.
-	sourceCode := (someString copyFrom: 1 to: pos - 1) withoutSeparators.
-	forceCreation ifTrue:[
-	    newLine := (HistoryLine newCreated).
-	] ifFalse:[
-	    newLine := (HistoryLine new)
-	]
+        pos := (previousHistories first) firstPositionInSourceCode.
+        sourceCode := (someString copyFrom: 1 to: pos - 1) withoutSeparators.
     ].
 
     "add the actual user's historyLine."
@@ -381,9 +378,10 @@
     "Modified: 11.8.1995 / 16:51:50 / robert"
     "Modified: 8.9.1995 / 17:55:38 / claus"
     "Modified: 13.12.1995 / 14:07:03 / cg"
+    "Created: 12.10.1996 / 20:33:35 / cg"
 !
 
-addHistoryToHistoryMethodOf:aClass
+addHistory:what toHistoryMethodOf:aClass
     "private - add a historyLine at end of the classes history methods
      source - if there is one"
 
@@ -398,19 +396,41 @@
     historyMethod notNil ifTrue:[
         oldSource := historyMethod source.
         oldSource notNil ifTrue:[
-            newSource := self addHistoryTo:oldSource forceModification:false forceCreation:false.
+            newSource := self 
+                            addHistory:what
+                            to:oldSource. 
             historyMethod source:newSource.
         ]
     ]
 
     "Modified: 20.4.1996 / 20:35:06 / cg"
+    "Created: 12.10.1996 / 20:31:50 / cg"
+!
+
+createHistoryMethodFor:aClass
+    "private - create a history method"
+
+    |cls|
+
+    aClass isMeta ifFalse:[
+        cls := aClass class.
+    ] ifTrue:[
+        cls := aClass
+    ].
+
+    Compiler
+        compile:'history' 
+        forClass:cls 
+        inCategory:'documentation'
+
+    "Modified: 12.10.1996 / 20:41:11 / cg"
 !
 
 update:something with:someArgument from:changedObject
     "arrive here, whenever any class changed somehow.
      (something contains aSymbol describing what happened)"
 
-    | sourceCode newMethod fileInOrRecompiling selector oldMethod|
+    | sourceCode newMethod fileInOrRecompiling selector oldMethod what|
 
 "/    changedObject == self ifTrue:[  "for development only"
 "/        self halt.
@@ -425,105 +445,114 @@
 
     fileInOrRecompiling ifFalse:[ 
 "/        Transcript showCR: '* noChange in history'. 
-	^ self 
+        ^ self 
     ].
     historyMode ifFalse:[
-	^ self
+        ^ self
     ].
 
     "
     Class Variables
     "
     (something == #definition) ifTrue:[
-	"add handling for classes here ..."        
-	"/ self addHistoryToHistoryMethodOf:changedObject.
+        "add handling for classes here ..."        
+        "/ self addHistory:#modification toHistoryMethodOf:changedObject.
     ].
 
     "this is a sub item of #definition"    
     (something == #classVariables) ifTrue:[
-	"
-	Transcript showCR: 'classVariables changed'.
-	"
-	"/ does not yet work;
-	"/ (someArgument does not contain the class we are interested in)
+        "/
+        "/ Transcript showCR: 'classVariables changed'.
+        "/
 
-	self addHistoryToHistoryMethodOf:changedObject.
-	^ self
+        "/ does not yet work;
+        "/ (someArgument does not contain the class we are interested in)
+
+        self addHistory:#modification toHistoryMethodOf:changedObject.
+        ^ self
     ].    
 
-    "
-     new Class creation
-    "
+    "/
+    "/ new Class creation
+    "/
     ((changedObject == Smalltalk) and:[something == #newClass]) ifTrue:[
-	"/ 
-	"/  add myself as dependents in order to get future change notifications
-	"/ 
-	someArgument addDependent: self.
-	someArgument class addDependent: self.   "for class methods"
-	someArgument history:(self addHistoryTo:String new forceModification:false forceCreation:false).  "append historyString for new class"
+        "/ 
+        "/  add myself as dependents in order to get future change notifications
+        "/ 
+        self createHistoryMethodFor:someArgument.
+        self addHistory:#creation toHistoryMethodOf:someArgument.
+
+        someArgument addDependent: self.
+        someArgument class addDependent: self.   "for class methods"
+        ^ self
     ].
 
-    "
-     changed methods
-    "
+    "/
+    "/ changed methods
+    "/
     changedObject isBehavior ifTrue:[
-	something = #methodDictionary ifTrue:[
-	    someArgument isArray ifTrue:[
-		selector := someArgument at:1.
-		oldMethod := someArgument at:2
-	    ] ifFalse:[
-		selector := someArgument
-	    ].
+        something = #methodDictionary ifTrue:[
+            someArgument isArray ifTrue:[
+                selector := someArgument at:1.
+                oldMethod := someArgument at:2
+            ] ifFalse:[
+                selector := someArgument
+            ].
 
-	    "/
-	    "/ fetch sourceString of the method
-	    "/
-	    sourceCode := changedObject sourceCodeAt:selector.
-	    sourceCode isNil ifTrue:[
-		"method has been deleted"
+            "/
+            "/ fetch sourceString of the method
+            "/
+            sourceCode := changedObject sourceCodeAt:selector.
+            sourceCode isNil ifTrue:[
+                "method has been deleted"
 "/                Transcript showCR: 'method has been deleted'.
-	    ] ifFalse:[
-		newMethod := changedObject compiledMethodAt:selector.
+            ] ifFalse:[
+                newMethod := changedObject compiledMethodAt:selector.
 
-		oldMethod notNil ifTrue:[
-		    (oldMethod source asString withTabsExpanded = sourceCode asString withTabsExpanded) ifTrue:[
-			 "/ no change (accepted same code again ?)
-			^ self
-		    ].
-		].
+                oldMethod notNil ifTrue:[
+                    (oldMethod source asString withTabsExpanded = sourceCode asString withTabsExpanded) ifTrue:[
+                         "/ no change (accepted same code again ?)
+                        ^ self
+                    ].
+                ].
 
-		"/
-		"/ dont add historylines to documentation methods ...
-		"/
-		(changedObject isMeta not
-		or:[newMethod category ~= 'documentation']) ifTrue:[
-		    sourceCode := self addHistoryTo:sourceCode forceModification:(oldMethod notNil) forceCreation:(oldMethod isNil).
-		    newMethod source: sourceCode.
+                "/
+                "/ dont add historylines to documentation methods ...
+                "/
+                (changedObject isMeta not
+                or:[newMethod category ~= 'documentation']) ifTrue:[
+                    oldMethod notNil ifTrue:[
+                        what := #modification
+                    ] ifFalse:[
+                        what := #creation
+                    ].
+                    sourceCode := self addHistory:what to:sourceCode.
+                    newMethod source: sourceCode.
 "/                Transcript showCR: 'history updated / added'.
-		]
-	    ].
-	    ^self
-	]. 
+                ]
+            ].
+            ^self
+        ]. 
 
-	something == #comment ifTrue:[
-	    "in someArgument steht jetzt der alte kommentar"
-	    ^ self.
-	] ifFalse:[
-	    "it is a class definition"
+        something == #comment ifTrue:[
+            "in someArgument steht jetzt der alte kommentar"
+            ^ self.
+        ] ifFalse:[
+            "it is a class definition"
 "/            Transcript show: 'Class definition: ', changedObject printString;cr.
-	    self addHistoryToHistoryMethodOf:changedObject.
-	].
+            self addHistory:#modification toHistoryMethodOf:changedObject.
+        ].
     ].
 
     ^self
 
     "Modified: 27.8.1995 / 02:14:43 / claus"
-    "Modified: 13.12.1995 / 14:06:20 / cg"
+    "Modified: 12.10.1996 / 20:47:40 / cg"
 ! !
 
-!HistoryManager class methodsFor:'documentation'!
+!HistoryManager  class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic3/HistoryManager.st,v 1.29 1996-06-15 13:26:04 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic3/HistoryManager.st,v 1.30 1996-10-12 19:48:28 cg Exp $'
 ! !
 HistoryManager initialize!