history support
authortz
Wed, 03 Dec 1997 15:15:18 +0100
changeset 745 9a306f58ea68
parent 744 363d53be9eb0
child 746 8e84030fcec8
history support
ToolApplicationModel.st
--- a/ToolApplicationModel.st	Mon Dec 01 19:51:00 1997 +0100
+++ b/ToolApplicationModel.st	Wed Dec 03 15:15:18 1997 +0100
@@ -1,10 +1,21 @@
 ApplicationModel subclass:#ToolApplicationModel
-	instanceVariableNames:'activeHelp'
+	instanceVariableNames:'activeHelp timeBlock'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Interface-Framework'
 !
 
+ToolApplicationModel class instanceVariableNames:'history'
+
+"
+ The following class instance variables are inherited by this class:
+
+	ApplicationModel - ClassResources
+	Model - 
+	Object - 
+"
+!
+
 !ToolApplicationModel class methodsFor:'documentation'!
 
 documentation
@@ -46,6 +57,21 @@
     ^label trimBlanks
 ! !
 
+!ToolApplicationModel class methodsFor:'history'!
+
+history
+
+    history isNil ifTrue: [history := OrderedCollection new].
+    ^history
+
+!
+
+historyMaxSize
+
+    ^10
+
+! !
+
 !ToolApplicationModel class methodsFor:'interface specs'!
 
 menuAbout
@@ -89,8 +115,8 @@
      handle the specification if its corrupted."
 
     "
-     MenuEditor new openOnClass:MyApplicationModel andSelector:#menuHelp
-     (Menu new fromLiteralArrayEncoding:(MyApplicationModel menuHelp)) startUp
+     MenuEditor new openOnClass:ToolApplicationModel andSelector:#menuHelp
+     (Menu new fromLiteralArrayEncoding:(ToolApplicationModel menuHelp)) startUp
     "
 
     <resource: #menu>
@@ -120,16 +146,24 @@
             )
              #(#MenuItem
                 #'label:' 'active help'
+                #'value:' #'activeHelp:'
+                #'indication:' #activeHelp
             )
           ) nil
           nil
       )
 ! !
 
+!ToolApplicationModel class methodsFor:'resources'!
+
+icon
+
+    <resource: #image>
+    ^(Depth2Image new) width: 19; height: 19; photometric:(#palette); bitsPerSample:(#(2 )); samplesPerPixel:(1); bits:(#[0 0 0 0 3 0 0 0 0 0 0 0 0 0 0 0 5 0 0 64 0 5 0 1 65 0 1 64 0 0 0 1 64 20 0 0 0 80 64 0 0 0 81 64 3 0 0 21 0 0 0 0 20 0 0 0 0 84 0 0 0 1 65 0 3 0 5 0 64 0 0 20 0 64 0 1 80 0 0 0 1 80 0 4 3 0 0 0 0 1 0 0 0 0 0]) ; colorMap:((OrderedCollection new add:(Color grey:9.41176); add:(Color red:0.0 green:80.7843 blue:18.8235); add:(Color black); add:(Color white); yourself)); yourself! !
+
 !ToolApplicationModel methodsFor:'accessing menu'!
 
 menuAbout
-    "this window spec was automatically generated by the UI Builder"
 
     ^ self class menuAbout
 
@@ -137,15 +171,52 @@
 !
 
 menuHelp
-    "this window spec was automatically generated by the UI Builder"
 
     ^ self class menuHelp
 
 
 ! !
 
+!ToolApplicationModel methodsFor:'aspects'!
+
+valueOfInfoLabel
+
+    |holder|
+
+    (holder := builder bindingAt:#valueOfInfoLabel) isNil ifTrue:[
+        builder aspectAt:#valueOfInfoLabel put:(holder :=  ValueHolder new).
+    ].
+    ^ holder
+
+!
+
+valueOfTimeLabel
+
+    |holder|
+
+    (holder := builder bindingAt:#valueOfTimeLabel) isNil ifTrue:[
+        builder aspectAt:#valueOfTimeLabel put:(holder :=  ValueHolder new).
+    ].
+    ^ holder
+
+! !
+
 !ToolApplicationModel methodsFor:'help'!
 
+activeHelp
+    "Answer whether active help is turned on for current application"
+
+    ^activeHelp
+!
+
+activeHelp: aValue
+    "toggle active help for current application"
+
+    (activeHelp := aValue)
+        ifTrue: [ActiveHelp startFor: self]
+        ifFalse: [ActiveHelp stopFor: self]
+!
+
 openAbout
     "show an about box"
 
@@ -212,8 +283,76 @@
     ]
 ! !
 
+!ToolApplicationModel methodsFor:'history'!
+
+addToHistory: aHistoryEntry
+
+    self history remove: (self history detect: [:histEntry| histEntry key = aHistoryEntry key] ifNone: nil) ifAbsent: nil.
+    self history addFirst: aHistoryEntry.
+    [self history size > self class historyMaxSize] whileTrue: [self history removeLast]
+!
+
+emptyHistory
+
+    ^self history removeAll
+!
+
+history
+
+    ^self class history
+!
+
+menuHistory
+
+    |menu a|
+    menu := Menu new receiver: self.
+
+    (self history collect: [:histEntry| histEntry value]) asSet asOrderedCollection do:
+    [:historyEntryType|    
+        menu addItemGroup: ((a := self history select: [:histEntry| histEntry value = historyEntryType]) collect: [:histEntry|  MenuItem new label: histEntry key; value: histEntry value; argument: histEntry key]).
+    ]. 
+    menu addItem: (MenuItem new label: 'empty history'; value: #emptyHistory).
+
+    ^menu
+!
+
+removeFromHistory: aHistoryEntry
+
+    self history remove: (self history detect: [:histEntry| histEntry key = aHistoryEntry key] ifNone: nil) ifAbsent: nil.
+    [self history size > self class historyMaxSize] whileTrue: [self history removeLast]
+! !
+
+!ToolApplicationModel methodsFor:'startup / release'!
+
+closeRequest
+
+    activeHelp ifTrue: [ActiveHelp stopFor: self].
+    Processor removeTimedBlock:timeBlock.
+    super closeRequest
+!
+
+initialize
+
+    activeHelp := false.
+    timeBlock := [self showTime].
+    Processor addTimedBlock: timeBlock afterSeconds: 1
+! !
+
+!ToolApplicationModel methodsFor:'window events'!
+
+showTime
+
+    |hours minutes suffix|
+    suffix := ' am '.
+    (hours := Time now hours) >= 12 ifTrue: [hours := hours - 12. suffix := ' pm '].
+    (minutes := Time now minutes printString) size = 1 ifTrue: [minutes := '0', minutes printString].
+    self valueOfTimeLabel value: hours printString, ':', minutes, suffix.
+    Processor addTimedBlock: timeBlock afterSeconds: 1
+
+! !
+
 !ToolApplicationModel class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libview2/ToolApplicationModel.st,v 1.1 1997-11-25 13:35:39 tz Exp $'
+    ^ '$Header: /cvs/stx/stx/libview2/ToolApplicationModel.st,v 1.2 1997-12-03 14:15:18 tz Exp $'
 ! !