#FEATURE by cg
class: UIHelpTool
added:
#doExtractUsedKeys
#hasKeyItemSelectedHolder
#hasSpecClassDefined
#store:forKey:
comment/format in:
#doSave
#editModelChanged
changed: #accept
class: UIHelpTool class
changed:
#helpTextMenu
#keyItemMenu
#listOfKeysMenu
--- a/UIHelpTool.st Fri May 18 18:01:09 2018 +0200
+++ b/UIHelpTool.st Thu May 24 16:34:42 2018 +0200
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
"
COPYRIGHT (c) 1995 by eXept Software AG
All Rights Reserved
@@ -345,6 +347,7 @@
"Do not manually edit this!! If it is corrupted,
the MenuEditor may not be able to read the specification."
+
"
MenuEditor new openOnClass:UIHelpTool andSelector:#helpTextMenu
(Menu new fromLiteralArrayEncoding:(UIHelpTool helpTextMenu)) startUp
@@ -353,25 +356,23 @@
<resource: #menu>
^
- #(#Menu
- #(
- #(#MenuItem
- #activeHelpKey: #commitOK
- #enabled: #contentsModifiedChannel
- #label: 'Accept'
- #itemValue: #accept
- #translateLabel: true
- )
- #(#MenuItem
- #activeHelpKey: #commitCancel
- #enabled: #contentsModifiedChannel
- #label: 'Cancel'
- #itemValue: #cancel
- #translateLabel: true
- )
- )
- nil
- nil
+ #(Menu
+ (
+ (MenuItem
+ activeHelpKey: commitOK
+ enabled: contentsModifiedChannel
+ label: 'Accept'
+ itemValue: accept
+ )
+ (MenuItem
+ activeHelpKey: commitCancel
+ enabled: contentsModifiedChannel
+ label: 'Cancel'
+ itemValue: cancel
+ )
+ )
+ nil
+ nil
)
!
@@ -382,6 +383,7 @@
"Do not manually edit this!! If it is corrupted,
the MenuEditor may not be able to read the specification."
+
"
MenuEditor new openOnClass:UIHelpTool andSelector:#keyItemMenu
(Menu new fromLiteralArrayEncoding:(UIHelpTool keyItemMenu)) startUp
@@ -390,18 +392,29 @@
<resource: #menu>
^
- #(#Menu
- #(
- #(#MenuItem
- #activeHelpKey: #deleteHelpTextKey
- #label: 'Delete'
- #itemValue: #doDelete
- #translateLabel: true
- )
- )
- nil
- nil
+ #(Menu
+ (
+ (MenuItem
+ activeHelpKey: deleteHelpTextKey
+ enabled: hasKeyItemSelectedHolder
+ label: 'Delete Key'
+ itemValue: doDelete
+ )
+ (MenuItem
+ label: '-'
+ )
+ (MenuItem
+ activeHelpKey: extractHelpTextKeys
+ label: 'Extract used Keys from Application'
+ itemValue: doExtractUsedKeys
+ enabled: hasSpecClassDefined
+ )
+ )
+ nil
+ nil
)
+
+ "Modified: / 24-05-2018 / 15:52:24 / Claus Gittinger"
!
listOfKeysMenu
@@ -411,6 +424,7 @@
"Do not manually edit this!! If it is corrupted,
the MenuEditor may not be able to read the specification."
+
"
MenuEditor new openOnClass:UIHelpTool andSelector:#listOfKeysMenu
(Menu new fromLiteralArrayEncoding:(UIHelpTool listOfKeysMenu)) startUp
@@ -419,17 +433,16 @@
<resource: #menu>
^
- #(#Menu
- #(
- #(#MenuItem
- #activeHelpKey: #deleteHelpTextKey
- #label: 'Delete'
- #itemValue: #doDelete
- #translateLabel: true
- )
- )
- nil
- nil
+ #(Menu
+ (
+ (MenuItem
+ activeHelpKey: deleteHelpTextKey
+ label: 'Delete'
+ itemValue: doDelete
+ )
+ )
+ nil
+ nil
)
!
@@ -647,6 +660,20 @@
^ contentsModifiedChannel
!
+hasKeyItemSelectedHolder
+ ^ BlockValue
+ with:[:m | m notNil]
+ argument:self keyItemModel
+
+ "Created: / 24-05-2018 / 15:48:51 / Claus Gittinger"
+!
+
+hasSpecClassDefined
+ ^ [ specClass notNil ]
+
+ "Created: / 24-05-2018 / 15:52:09 / Claus Gittinger"
+!
+
helpTextView
"the editView which shows the current help contents assigned to the key
"
@@ -832,7 +859,10 @@
editModelChanged
"called if the editModel changed
- "
+ cg: so does anyone think, that a comment like the above is useful?
+ this is called when the text in the edit field (which selects the current key)
+ is changed."
+
|key|
key := self helpKey.
@@ -863,6 +893,8 @@
].
].
keyItemModel value:nil.
+
+ "Modified (comment): / 24-05-2018 / 16:17:16 / Claus Gittinger"
!
update:something with:aParameter from:changedObject
@@ -1063,28 +1095,17 @@
!UIHelpTool methodsFor:'user actions'!
accept
- "accepts the help text
- "
- |helpKey helpItem root|
+ "accepts the help text;
+ take the contents of the helpTextView and store it under the current helpKey"
+
+ |helpKey|
helpKey := self helpKey.
helpKey isNil ifTrue:[^ self].
- root := classItemModel value.
- root isNil ifTrue:[^ self].
-
- helpItem := root detectItemWithKey:helpKey.
+ self store:(helpTextView contents) forKey:helpKey
- helpItem isNil ifTrue:[
- helpItem := KeyItem helpKey:helpKey helpText:(helpTextView contents).
- root add:helpItem sortBlock:[:a :b| a label < b label ].
- self updateIcons.
- ] ifFalse:[
- helpItem helpText:(helpTextView contents).
- ].
-
- contentsModifiedChannel value:false.
- keyItemModel triggerValue:helpItem.
+ "Modified: / 24-05-2018 / 16:31:25 / Claus Gittinger"
!
cancel
@@ -1124,6 +1145,61 @@
editModel value:nil.
!
+doExtractUsedKeys
+ "goes through the classes menu- and interface specs,
+ and extracts possible activeHelpKeys"
+
+ |allHelpKeys existingKeys cls missingKeys|
+
+ allHelpKeys := Set new.
+
+ specClass theMetaclass methodsDo:[:mthd |
+ |spec bodyNode retVal specArray menu|
+
+ (mthd hasMenuResource or:[mthd hasCanvasResource]) ifTrue:[
+ bodyNode := mthd parseTree body.
+ bodyNode lastIsReturn ifTrue:[
+ (retVal := bodyNode statements last value) isLiteralArray ifTrue:[
+ specArray := retVal value.
+ spec := specArray decodeAsLiteralArray.
+ spec do:[:eachSpec |
+ |k|
+
+ (k := eachSpec activeHelpKey) notNil ifTrue:[
+ allHelpKeys add:k.
+ ].
+ ].
+ ]
+ ].
+ ].
+ ].
+
+ existingKeys := Set new.
+ (cls := specClass theMetaclass whichClassImplements:self specSelector) notNil ifTrue:[
+ |specThere|
+
+ specThere := cls theNonMetaclass perform:self specSelector.
+ specThere isDictionary ifFalse:[
+ Transcript showCR:('oops - helpSpec from ',cls name,'>>',self specSelector,' is not a dictionary').
+ ] ifTrue:[
+ existingKeys addAll:(specThere keys).
+ ].
+ ].
+
+ missingKeys := OrderedCollection new.
+
+ allHelpKeys do:[:each |
+ (existingKeys includes:each) ifFalse:[
+ missingKeys add:each.
+ ].
+ ].
+ missingKeys do:[:eachKey |
+ self store:'no tooltip yet' forKey:eachKey
+ ].
+
+ "Created: / 24-05-2018 / 16:00:08 / Claus Gittinger"
+!
+
doLoad
"opens a Resource Selection Browser in order to get a resource message"
@@ -1153,11 +1229,12 @@
self information:'No class specified !!'.
^ nil
].
-"/ cg: the following test is rubbish !!
-"/ (specClass isSubclassOf:ApplicationModel) ifFalse:[
-"/ self information:(resources string:'Cannot save help into non-Application class').
-"/ ^ nil
-"/ ].
+
+ "/ cg: the following test is rubbish !!
+ "/ (specClass isSubclassOf:ApplicationModel) ifFalse:[
+ "/ self information:(resources string:'Cannot save help into non-Application class').
+ "/ ^ nil
+ "/ ].
classItemList do:[:aClassItem|
aClassItem theClass isNil ifTrue:[
@@ -1165,12 +1242,38 @@
].
aClassItem createHelpMethodNamed:(self specSelector)
].
+
+ "Modified (format): / 24-05-2018 / 16:25:31 / Claus Gittinger"
!
openDocumentation
"opens the documentation file of the Help Tool
"
self openHTMLDocument: 'tools/uipainter/HelpTool.html'
+!
+
+store:helpText forKey:helpKey
+ "store helpText under helpKey"
+
+ |helpItem root|
+
+ root := classItemModel value.
+ root isNil ifTrue:[^ self].
+
+ helpItem := root detectItemWithKey:helpKey.
+
+ helpItem isNil ifTrue:[
+ helpItem := KeyItem helpKey:helpKey helpText:helpText.
+ root add:helpItem sortBlock:[:a :b| a label < b label ].
+ self updateIcons.
+ ] ifFalse:[
+ helpItem helpText:(helpTextView contents).
+ ].
+
+ contentsModifiedChannel value:false.
+ keyItemModel triggerValue:helpItem.
+
+ "Created: / 24-05-2018 / 16:31:08 / Claus Gittinger"
! !
!UIHelpTool::ClassItem class methodsFor:'instance creation'!