code cleanup & refactoring
authorClaus Gittinger <cg@exept.de>
Mon, 13 Feb 2006 09:55:11 +0100
changeset 2098 37ea7570cd6b
parent 2097 7f078c4af09d
child 2099 306e2edb75bf
code cleanup & refactoring history mechanism cleaned
ToolApplicationModel.st
--- a/ToolApplicationModel.st	Mon Feb 13 09:50:23 2006 +0100
+++ b/ToolApplicationModel.st	Mon Feb 13 09:55:11 2006 +0100
@@ -32,6 +32,27 @@
 "
 !
 
+Object subclass:#HistoryEntry
+	instanceVariableNames:''
+	classVariableNames:''
+	poolDictionaries:''
+	privateIn:ToolApplicationModel
+!
+
+ToolApplicationModel::HistoryEntry subclass:#HistoryEntryForFile
+	instanceVariableNames:'filename'
+	classVariableNames:''
+	poolDictionaries:''
+	privateIn:ToolApplicationModel
+!
+
+ToolApplicationModel::HistoryEntry subclass:#HistoryEntryForMethod
+	instanceVariableNames:'methodClass methodSelector'
+	classVariableNames:''
+	poolDictionaries:''
+	privateIn:ToolApplicationModel
+!
+
 !ToolApplicationModel class methodsFor:'documentation'!
 
 copyright
@@ -1213,28 +1234,45 @@
 
 !ToolApplicationModel methodsFor:'history'!
 
-add:aHistoryEntry toHistory: aHistory
+add:aHistoryEntry toHistory:aHistory
     "adds aHistoryEntry (format: loadMessage -> evalString) at the top of aHistory,
      and checks for maximum size of the history"
 
-    aHistoryEntry key size = 0 ifTrue: [^nil].
-    aHistory remove: (aHistory detect: [:histEntry| histEntry key = aHistoryEntry key] ifNone: nil) ifAbsent: nil.
+    aHistory remove:aHistoryEntry ifAbsent:nil.
     aHistory addFirst: aHistoryEntry.
     [aHistory size > self class historyMaxSize] whileTrue: [aHistory removeLast]
 !
 
+addHistoryEntryForClass:classToAdd selector:selectorToAdd
+    "adds aHistoryEntry (format: loadMessage -> evalString) at the top of the history,
+     and checks for maximum size of the history"
+
+    |entry|
+
+    self assert:(classToAdd isBehavior).
+    entry := HistoryEntryForMethod class:classToAdd selector:selectorToAdd.
+    self addToHistory:entry
+!
+
+addHistoryEntryForFile:fileName
+    |entry|
+
+    entry := HistoryEntryForFile filename:fileName.
+    self addToHistory:entry
+!
+
 addToFileHistory: aHistoryEntry
     "adds aHistoryEntry (format: loadMessage -> evalString) at the top of the file-history,
      and checks for maximum size of the history"
 
-    self add: aHistoryEntry toHistory:self fileHistory
+    self add:aHistoryEntry toHistory:self fileHistory
 !
 
 addToHistory: aHistoryEntry
     "adds aHistoryEntry (format: loadMessage -> evalString) at the top of the history,
      and checks for maximum size of the history"
 
-    self add: aHistoryEntry toHistory:self history
+    self add:aHistoryEntry toHistory:self history
 !
 
 emptyFileHistory
@@ -1283,24 +1321,23 @@
     menu := Menu new receiver: self.
     anyItem := false.
 
-    (self history 
-        collect: [:histEntry| histEntry value]) 
-            asSet 
-                asOrderedCollection 
-                    do:
-                        [:historyEntryType|    
-                            menu addItemGroup:
-                                    (self history 
-                                        select: [:histEntry| 
-                                            histEntry value = historyEntryType] 
-                                        thenCollect: [:histEntry|
-                                            anyItem := true.
-                                            MenuItem new 
-                                                label: histEntry key printString; 
-                                                value: histEntry value; 
-                                                argument: histEntry key; 
-                                                activeHelpKey: #historyMenuItem]).
-                        ]. 
+    ((self history 
+        collect: [:histEntry| histEntry class]) 
+            asSet asSortedCollection:[:a :b | a name < b name]) 
+                do:
+                    [:historyEntryType|    
+                        menu addItemGroup:
+                                (self history 
+                                    select: [:histEntry| 
+                                        histEntry class = historyEntryType] 
+                                    thenCollect: [:histEntry|
+                                        anyItem := true.
+                                        MenuItem new 
+                                            label: histEntry printStringInMenu; 
+                                            value: #loadFromHistoryEntry: ; 
+                                            argument: histEntry; 
+                                            activeHelpKey: #historyMenuItem]).
+                    ]. 
 
     clearItem := MenuItem new 
                         label: 'Clear History'; 
@@ -1323,7 +1360,7 @@
     [aHistory size > self class historyMaxSize] whileTrue: [aHistory removeLast]
 !
 
-removeFromHistory: aHistoryEntry
+removeFromHistory:aHistoryEntry
     "removes aHistoryEntry from the history"
 
     self remove:aHistoryEntry fromHistory: self history.
@@ -1394,6 +1431,10 @@
     super closeDownViews
 !
 
+loadFromHistoryEntry:aHistoryEntry
+    aHistoryEntry forceLoadIn:self
+!
+
 postOpenWith:aBuilder
     "starts the active help for this tool (if turned on in the settings)
      and updates the info label and the fonts (from the settings)"
@@ -1427,8 +1468,100 @@
     "Modified: / 31.7.1998 / 18:46:21 / cg"
 ! !
 
+!ToolApplicationModel::HistoryEntry methodsFor:'comparing'!
+
+sameAsHistoryEntryForFile:aHistoryEntryForFile
+    ^ false
+!
+
+sameAsHistoryEntryForMethod:aHistoryEntryForMethod
+    ^ false
+! !
+
+!ToolApplicationModel::HistoryEntryForFile class methodsFor:'instance creation'!
+
+filename:arg
+    ^ self new filename:arg
+! !
+
+!ToolApplicationModel::HistoryEntryForFile methodsFor:'accessing'!
+
+filename
+    ^ filename
+!
+
+filename:something
+    filename := something.
+! !
+
+!ToolApplicationModel::HistoryEntryForFile methodsFor:'comparing'!
+
+= aHistoryEntry
+    ^ aHistoryEntry sameAsHistoryEntryForFile:self
+!
+
+sameAsHistoryEntryForFile:aHistoryEntryForFile
+    ^ aHistoryEntryForFile filename = filename
+! !
+
+!ToolApplicationModel::HistoryEntryForFile methodsFor:'loading'!
+
+forceLoadIn:anEditor
+    anEditor loadFromFile:filename
+! !
+
+!ToolApplicationModel::HistoryEntryForFile methodsFor:'printing'!
+
+printStringInMenu
+    ^ filename
+! !
+
+!ToolApplicationModel::HistoryEntryForMethod class methodsFor:'instance creation'!
+
+class:classToAdd selector:selectorToAdd
+    ^ self new class:classToAdd selector:selectorToAdd
+! !
+
+!ToolApplicationModel::HistoryEntryForMethod methodsFor:'accessing'!
+
+class:aClass selector:aSelector
+    methodClass := aClass.
+    methodSelector := aSelector
+!
+
+methodClass
+    ^ methodClass
+!
+
+methodSelector
+    ^ methodSelector
+! !
+
+!ToolApplicationModel::HistoryEntryForMethod methodsFor:'comparing'!
+
+= aHistoryEntry
+    ^ aHistoryEntry sameAsHistoryEntryForMethod:self
+!
+
+sameAsHistoryEntryForMethod:aHistoryEntryForMethod
+    ^ aHistoryEntryForMethod methodClass = methodClass
+    and:[ aHistoryEntryForMethod methodSelector = methodSelector ]
+! !
+
+!ToolApplicationModel::HistoryEntryForMethod methodsFor:'loading'!
+
+forceLoadIn:anEditor
+    anEditor loadFromClass:methodClass andSelector:methodSelector
+! !
+
+!ToolApplicationModel::HistoryEntryForMethod methodsFor:'printing'!
+
+printStringInMenu
+    ^ methodClass name , ' >> ' , methodSelector
+! !
+
 !ToolApplicationModel class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/ToolApplicationModel.st,v 1.123 2006-01-17 12:12:52 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/ToolApplicationModel.st,v 1.124 2006-02-13 08:55:11 cg Exp $'
 ! !