38 |
38 |
39 ! |
39 ! |
40 |
40 |
41 documentation |
41 documentation |
42 " |
42 " |
43 The UIHelpTool allows you to define help dictionaries for the widgets in |
43 The Help Tool allows you to define help dictionaries for the widgets in |
44 window applications. The tool are able to run stand alone or in other master |
44 window applications. The tool are able to run stand alone or in other master |
45 applications like the GUI Painter and the Menu Editor. |
45 applications like the GUI Painter and the Menu Editor. |
46 If the application responds to the selector #showHelp:aHelpText for:aView, |
46 If the application responds to the selector #showHelp:aHelpText for:aView, |
47 this selector is called by the widget's view when the mouse cursor moves over. |
47 this selector is called by the widget's view when the mouse cursor moves over. |
48 If the application does not responds to that selector, and the activeHelp mode |
48 If the application does not responds to that selector, and the activeHelp mode |
49 is enabled, an active help bubble is shown at the widget's view. |
49 is enabled, an active help bubble is shown at the widget's view. |
50 |
50 |
|
51 [instance variables:] |
|
52 specClass <Symbol> class implementing the help spec |
|
53 specSelector <Symbol> selector returning the help spec |
|
54 dictionary <Dictionary> dictionary containing pairs of help keys/texts |
|
55 dictionaries <Dictionary> dictionary containing pairs of help spec classes/help dictionaries |
|
56 listSelection <String> current selected help key |
|
57 maxCharsPerLine <Integer> maximum number of allowed characters per text line |
|
58 modifiedHolder <ValueHolder> value holder for setting as modified |
|
59 modified <Boolean> flag whether the help spec was modified |
|
60 |
51 [author:] |
61 [author:] |
52 Claus Atzkern, eXept Software AG |
62 Claus Atzkern, eXept Software AG |
53 Thomas Zwick, eXept Software AG |
63 Thomas Zwick, eXept Software AG |
54 " |
64 " |
55 ! ! |
65 ! ! |
56 |
66 |
57 !UIHelpTool class methodsFor:'instance creation'! |
67 !UIHelpTool class methodsFor:'instance creation'! |
58 |
68 |
59 openOnClass:aClass |
69 openOnClass:aClass |
|
70 "opens a Help Tool on aClass" |
|
71 |
60 " |
72 " |
61 UIHelpTool openOnClass:self |
73 UIHelpTool openOnClass:self |
62 " |
74 " |
63 |
75 |
64 UIHelpTool new openOnClass:aClass |
76 UIHelpTool new openOnClass:aClass |
65 |
77 |
66 ! ! |
78 ! ! |
67 |
79 |
68 !UIHelpTool class methodsFor:'accessing'! |
|
69 |
|
70 resourceType |
|
71 "get the type of resource of the method generated by the Help Tool" |
|
72 |
|
73 ^#help |
|
74 |
|
75 |
|
76 ! ! |
|
77 |
|
78 !UIHelpTool class methodsFor:'constants'! |
80 !UIHelpTool class methodsFor:'constants'! |
79 |
81 |
80 label |
82 label |
|
83 "returns the label; used if embedded as sub canvas in the GUI Painter or Menu Editor" |
81 |
84 |
82 ^'Help' |
85 ^'Help' |
83 ! ! |
86 ! ! |
84 |
87 |
85 !UIHelpTool class methodsFor:'help specs'! |
88 !UIHelpTool class methodsFor:'help specs'! |
432 ! ! |
435 ! ! |
433 |
436 |
434 !UIHelpTool methodsFor:'accessing'! |
437 !UIHelpTool methodsFor:'accessing'! |
435 |
438 |
436 dictionaries |
439 dictionaries |
437 "get the dictionary of the help dictionaries of the classes having help specs |
440 "returns the dictionary of the help dictionaries of the classes having help specs" |
438 " |
441 |
439 ^dictionaries |
442 ^dictionaries |
440 ! |
443 ! |
441 |
444 |
442 dictionaries:aDictionaryOfDictionaries |
445 dictionaries:aDictionaryOfDictionaries |
443 "set a dictionary of the help dictionaries of the classes having help specs |
446 "sets a dictionary of the help dictionaries of the classes having help specs" |
444 " |
447 |
445 (dictionaries := aDictionaryOfDictionaries) isNil ifTrue:[ |
448 (dictionaries := aDictionaryOfDictionaries) isNil ifTrue:[ |
446 dictionaries := Dictionary new. |
449 dictionaries := Dictionary new. |
447 ]. |
450 ]. |
448 self updateList. |
451 self updateList. |
449 ! |
452 ! |
450 |
453 |
451 dictionary |
454 dictionary |
452 "get the dictionary of the selected class |
455 "returns the dictionary of the selected class" |
453 " |
456 |
454 ^dictionary |
457 ^dictionary |
455 ! |
458 ! |
456 |
459 |
457 dictionary:aDictionary |
460 dictionary:aDictionary |
458 "set dictionary of the selected class |
461 "sets dictionary of the selected class" |
459 " |
462 |
460 (dictionary := aDictionary) isNil ifTrue:[ |
463 (dictionary := aDictionary) isNil ifTrue:[ |
461 dictionary := Dictionary new. |
464 dictionary := Dictionary new. |
462 ]. |
465 ]. |
463 self updateList |
466 self updateList |
464 ! |
467 ! |
465 |
468 |
466 helpKey |
469 helpKey |
467 "get the help key of selected help text |
470 "returns the help key of selected help text" |
468 " |
471 |
469 listSelection size ~~ 0 ifTrue:[ |
472 listSelection size ~~ 0 ifTrue:[ |
470 ^ listSelection asSymbol |
473 ^ listSelection asSymbol |
471 ]. |
474 ]. |
472 ^ nil |
475 ^ nil |
473 ! |
476 ! |
474 |
477 |
475 helpKey:aKey |
478 helpKey:aKey |
476 "set the help key into the selection channel in order to show the help text |
479 "sets the help key into the selection channel in order to show the help text" |
477 " |
480 |
478 |key| |
481 |key| |
479 aKey size ~~ 0 ifTrue:[ |
482 aKey size ~~ 0 ifTrue:[ |
480 key := aKey asString |
483 key := aKey asString |
481 ]. |
484 ]. |
482 self listModel value:key |
485 self listModel value:key |
483 |
486 |
484 ! |
487 ! |
485 |
488 |
486 modified |
489 modified |
487 "answer whether the help tool was modified |
490 "returns whether the help tool was modified" |
488 " |
491 |
489 ^modified |
492 ^modified |
490 ! |
493 ! |
491 |
494 |
492 modified: aBoolean |
495 modified: aBoolean |
493 "set the help tool as modified |
496 "sets the help tool as modified" |
494 " |
497 |
495 modified := aBoolean |
498 modified := aBoolean |
496 ! |
499 ! |
497 |
500 |
498 modifiedHolder:aValueHolder |
501 modifiedHolder:aValueHolder |
499 "set the value holder set to true in case of modifying attributes |
502 "sets the value holder to true in case of modifying attributes" |
500 " |
503 |
501 modifiedHolder notNil ifTrue:[ |
504 modifiedHolder notNil ifTrue:[ |
502 modifiedHolder removeDependent:self. |
505 modifiedHolder removeDependent:self. |
503 ]. |
506 ]. |
504 |
507 |
505 (modifiedHolder := aValueHolder) notNil ifTrue:[ |
508 (modifiedHolder := aValueHolder) notNil ifTrue:[ |
518 |
521 |
519 |
522 |
520 ! |
523 ! |
521 |
524 |
522 specClass |
525 specClass |
523 "get the class on which the help tool works |
526 "returns the class on which the help tool works" |
524 " |
527 |
525 ^specClass |
528 ^specClass |
526 ! ! |
529 ! ! |
527 |
530 |
528 !UIHelpTool methodsFor:'aspects'! |
531 !UIHelpTool methodsFor:'aspects'! |
529 |
532 |
530 listChannel |
533 listChannel |
531 "get the value holder of the help texts |
534 "returns the value holder of the help texts" |
532 " |
535 |
533 |holder| |
536 |holder| |
534 (holder := builder bindingAt:#listChannel) isNil ifTrue:[ |
537 (holder := builder bindingAt:#listChannel) isNil ifTrue:[ |
535 builder aspectAt:#listChannel put:(holder := OrderedCollection new asValue). |
538 builder aspectAt:#listChannel put:(holder := OrderedCollection new asValue). |
536 ]. |
539 ]. |
537 ^ holder |
540 ^ holder |
538 ! |
541 ! |
539 |
542 |
540 listModel |
543 listModel |
541 "get the value holder of the help key |
544 "returns the value holder of the help key" |
542 " |
545 |
543 |holder| |
546 |holder| |
544 (holder := builder bindingAt:#listModel) isNil ifTrue:[ |
547 (holder := builder bindingAt:#listModel) isNil ifTrue:[ |
545 holder := AspectAdaptor new subject:self; forAspect:#listSelection. |
548 holder := AspectAdaptor new subject:self; forAspect:#listSelection. |
546 builder aspectAt:#listModel put:holder. |
549 builder aspectAt:#listModel put:holder. |
547 ]. |
550 ]. |
548 ^ holder |
551 ^ holder |
549 ! |
552 ! |
550 |
553 |
551 listOfHelpSpecClasses |
554 listOfHelpSpecClasses |
552 "get the value holder of the specClass and its superclasses |
555 "returns the value holder of the specClass and its superclasses |
553 which are subclasses of ApplicationModel |
556 which are subclasses of ApplicationModel" |
554 " |
557 |
555 |holder| |
558 |holder| |
556 (holder := builder bindingAt:#listOfHelpSpecClasses) isNil ifTrue:[ |
559 (holder := builder bindingAt:#listOfHelpSpecClasses) isNil ifTrue:[ |
557 builder aspectAt:#listOfHelpSpecClasses put: (holder := List new) |
560 builder aspectAt:#listOfHelpSpecClasses put: (holder := List new) |
558 ]. |
561 ]. |
559 ^ holder |
562 ^ holder |
560 |
563 |
561 ! |
564 ! |
562 |
565 |
563 selectionOfHelpSpecClass |
566 selectionOfHelpSpecClass |
564 "get the value holder of the selected help spec class |
567 "returns the value holder of the selected help spec class" |
565 " |
568 |
566 |holder| |
569 |holder| |
567 (holder := builder bindingAt:#selectionOfHelpSpecClass) isNil ifTrue:[ |
570 (holder := builder bindingAt:#selectionOfHelpSpecClass) isNil ifTrue:[ |
568 builder aspectAt:#selectionOfHelpSpecClass put: (holder := ValueHolder new) |
571 builder aspectAt:#selectionOfHelpSpecClass put: (holder := ValueHolder new) |
569 ]. |
572 ]. |
570 ^ holder |
573 ^ holder |
602 |
605 |
603 self updateList |
606 self updateList |
604 ! |
607 ! |
605 |
608 |
606 buildFromClass: aClass andSelector: aSelector |
609 buildFromClass: aClass andSelector: aSelector |
|
610 "sets aSelector and reads the help dictionary from aClass" |
607 |
611 |
608 specSelector := aSelector. |
612 specSelector := aSelector. |
609 self buildFromClass:aClass |
613 self buildFromClass:aClass |
610 |
614 |
611 ! ! |
615 ! ! |
612 |
616 |
613 !UIHelpTool methodsFor:'callbacks'! |
617 !UIHelpTool methodsFor:'callbacks'! |
614 |
618 |
615 helpSpecClassSelected |
619 helpSpecClassSelected |
616 "extract the help dictionary from the selected class and make it current |
620 "extracts the help dictionary from the selected class and make it current" |
617 " |
621 |
618 |clsName| |
622 |clsName| |
619 |
623 |
620 clsName := self selectionOfHelpSpecClass value. |
624 clsName := self selectionOfHelpSpecClass value. |
621 |
625 |
622 (dictionary := dictionaries at: clsName ifAbsent: nil) isNil |
626 (dictionary := dictionaries at: clsName ifAbsent: nil) isNil |
708 ]. |
712 ]. |
709 ^ view |
713 ^ view |
710 ! |
714 ! |
711 |
715 |
712 extractHelpSpecForClass: aClass |
716 extractHelpSpecForClass: aClass |
713 "extract the help dictionary of aClass, it current and return it |
717 "extracts the help dictionary of aClass, it current and return it" |
714 " |
718 |
715 |helpSpecSuperClass superHelpSpecKeys helpSpec| |
719 |helpSpecSuperClass superHelpSpecKeys helpSpec| |
716 |
720 |
717 ((aClass class implements: specSelector) |
721 ((aClass class implements: specSelector) |
718 and: [(helpSpecSuperClass := aClass allSuperclasses detect: [:cls| cls class implements: specSelector] ifNone: nil) notNil]) |
722 and: [(helpSpecSuperClass := aClass allSuperclasses detect: [:cls| cls class implements: specSelector] ifNone: nil) notNil]) |
719 ifTrue: |
723 ifTrue: |
728 ]. |
732 ]. |
729 ^dictionary := Dictionary new |
733 ^dictionary := Dictionary new |
730 ! |
734 ! |
731 |
735 |
732 findHelpSpecForKey: aHelpKey |
736 findHelpSpecForKey: aHelpKey |
733 "find the help spec class including aHelpKey in its help dictionary and make it current |
737 "finds the help spec class including aHelpKey in its help dictionary and make it current" |
734 " |
738 |
735 |dictTemp| |
739 |dictTemp| |
736 |
740 |
737 aHelpKey isNil ifTrue: [^nil]. |
741 aHelpKey isNil ifTrue: [^nil]. |
738 dictTemp := dictionary. |
742 dictTemp := dictionary. |
739 self listOfHelpSpecClasses value do: |
743 self listOfHelpSpecClasses value do: |
865 forClass:cls class |
869 forClass:cls class |
866 inCategory:'help specs'. |
870 inCategory:'help specs'. |
867 ! |
871 ! |
868 |
872 |
869 installHelpSpecsOnClass:aClass |
873 installHelpSpecsOnClass:aClass |
870 "save the help dicts on aClass and its superclasses which are subclasses of ApplicationModel |
874 "saves the help dicts on aClass and its superclasses which are subclasses of ApplicationModel" |
871 " |
875 |
872 |cls helpSpecClasses| |
876 |cls helpSpecClasses| |
873 |
877 |
874 cls := self getHelpSpecClassFromClass:aClass. |
878 cls := self getHelpSpecClassFromClass:aClass. |
875 cls isNil ifTrue: [^self information:'No application class defined!!']. |
879 cls isNil ifTrue: [^self information:'No application class defined!!']. |
876 |
880 |
914 ^false |
918 ^false |
915 |
919 |
916 ! |
920 ! |
917 |
921 |
918 updateList |
922 updateList |
919 "update the list channel from dictionary |
923 "updates the list channel from dictionary" |
920 " |
924 |
921 self listChannel value: dictionary keys asSortedCollection |
925 self listChannel value: dictionary keys asSortedCollection |
922 ! ! |
926 ! ! |
923 |
927 |
924 !UIHelpTool methodsFor:'selection'! |
928 !UIHelpTool methodsFor:'selection'! |
925 |
929 |
926 listSelection |
930 listSelection |
927 "returns current selection |
931 "returns current selection" |
928 " |
932 |
929 ^ listSelection |
933 ^ listSelection |
930 ! |
934 ! |
931 |
935 |
932 listSelection:aSelection |
936 listSelection:aSelection |
933 "current selection changed |
937 "sets current selection" |
934 " |
938 |
935 |txt view sel| |
939 |txt view sel| |
936 |
940 |
937 aSelection isNil |
941 aSelection isNil |
938 ifTrue: [(builder componentAt: #listOfHelpKeysView) selection: nil] |
942 ifTrue: [(builder componentAt: #listOfHelpKeysView) selection: nil] |
939 ifFalse: [(dictionary includesKey: aSelection asSymbol) ifFalse: [self findHelpSpecForKey: aSelection]]. |
943 ifFalse: [(dictionary includesKey: aSelection asSymbol) ifFalse: [self findHelpSpecForKey: aSelection]]. |
974 ! ! |
978 ! ! |
975 |
979 |
976 !UIHelpTool methodsFor:'startup / release'! |
980 !UIHelpTool methodsFor:'startup / release'! |
977 |
981 |
978 closeRequest |
982 closeRequest |
979 "before closing the help tool, ask for permission |
983 "asks for permission before closing" |
980 " |
984 |
981 (self masterApplication isNil and:[self askForModification]) ifTrue:[super closeRequest] |
985 (self masterApplication isNil and:[self askForModification]) ifTrue:[super closeRequest] |
982 ! |
986 ! |
983 |
987 |
984 initialize |
988 initialize |
985 "initialize instance variables |
989 "initializes instance variables" |
986 " |
990 |
987 super initialize. |
991 super initialize. |
988 |
992 |
989 specSelector := #helpSpec. |
993 specSelector := #helpSpec. |
990 dictionary := Dictionary new. |
994 dictionary := Dictionary new. |
991 dictionaries := Dictionary new. |
995 dictionaries := Dictionary new. |
992 modified := false. |
996 modified := false. |
993 |
997 |
994 ! |
998 ! |
995 |
999 |
996 loadFromMessage:aString |
1000 loadFromMessage:aString |
997 "load a spec from class and selector" |
1001 "loads a help spec by evaluating aString" |
998 |
1002 |
999 (aString notNil and: [self askForModification]) |
1003 (aString notNil and: [self askForModification]) |
1000 ifTrue: |
1004 ifTrue: |
1001 [ |
1005 [ |
1002 |msg cls sel| |
1006 |msg cls sel| |
1013 ^false |
1017 ^false |
1014 |
1018 |
1015 ! |
1019 ! |
1016 |
1020 |
1017 openInterface:aSymbol |
1021 openInterface:aSymbol |
1018 "do not open as stand alone |
1022 "do not open as stand alone" |
1019 " |
1023 |
1020 |
1024 |
1021 |
1025 |
1022 ! |
1026 ! |
1023 |
1027 |
1024 openOnClass:aClass |
1028 openOnClass:aClass |
1025 "open the UIHelpTool on aClass |
1029 "opens the UIHelpTool on aClass" |
1026 " |
|
1027 |
1030 |
1028 super openInterface: #windowSpecForStandAlone. |
1031 super openInterface: #windowSpecForStandAlone. |
1029 self masterApplication isNil ifTrue: [(builder componentAt: #RemoveButton) beInvisible]. |
1032 self masterApplication isNil ifTrue: [(builder componentAt: #RemoveButton) beInvisible]. |
1030 builder window label: 'Help Tool'. |
1033 builder window label: 'Help Tool'. |
1031 self buildFromClass: aClass |
1034 self buildFromClass: aClass |
1032 ! ! |
1035 ! ! |
1033 |
1036 |
1034 !UIHelpTool methodsFor:'user actions'! |
1037 !UIHelpTool methodsFor:'user actions'! |
1035 |
1038 |
1036 accept |
1039 accept |
1037 "accept the help text |
1040 "accepts the help text" |
1038 " |
1041 |
1039 |view key txt list listChgd| |
1042 |view key txt list listChgd| |
1040 |
1043 |
1041 (listSelection size == 0 or:[(view := self editTextView) isNil]) ifFalse:[ |
1044 (listSelection size == 0 or:[(view := self editTextView) isNil]) ifFalse:[ |
1042 txt := view contents asString. |
1045 txt := view contents asString. |
1043 key := listSelection asSymbol. |
1046 key := listSelection asSymbol. |
1091 self warn: 'First select a help key!!' |
1094 self warn: 'First select a help key!!' |
1092 ] |
1095 ] |
1093 ! |
1096 ! |
1094 |
1097 |
1095 doLoad |
1098 doLoad |
1096 "open a Resource Selection Browser in order to get a resource message" |
1099 "opens a Resource Selection Browser in order to get a resource message" |
1097 |
1100 |
1098 self loadFromMessage: |
1101 self loadFromMessage: |
1099 (ResourceSelectionBrowser |
1102 (ResourceSelectionBrowser |
1100 request: 'Load ', self class resourceType asUppercaseFirst, ' Spec From Class' |
1103 request: 'Load Help Spec From Class' |
1101 onSuperclass: nil |
1104 onSuperclass: nil |
1102 andClass: specClass |
1105 andClass: specClass |
1103 andSelector: specSelector ? self class resourceType |
1106 andSelector: specSelector ? #help |
1104 withResourceTypes: (Array with: self class resourceType)) |
1107 withResourceTypes: (Array with: #help)). |
|
1108 |
|
1109 self updateInfoLabel |
1105 |
1110 |
1106 ! |
1111 ! |
1107 |
1112 |
1108 doNew |
1113 doNew |
1109 "reset the help tool |
1114 "resets the help tool" |
1110 " |
1115 |
1111 specClass := listSelection := nil. |
1116 specClass := listSelection := nil. |
1112 self dictionary: nil. |
1117 self dictionary: nil. |
1113 self dictionaries: nil. |
1118 self dictionaries: nil. |
1114 self listOfHelpSpecClasses removeAll. |
1119 self listOfHelpSpecClasses removeAll. |
1115 modified := false. |
1120 modified := false. |
1116 ! |
1121 ! |
1117 |
1122 |
1118 doReload |
1123 doReload |
1119 "reload the help dictionaries |
1124 "reloads the help dictionaries" |
1120 " |
1125 |
1121 |oldSel model| |
1126 |oldSel model| |
1122 |
1127 |
1123 model := self listModel. |
1128 model := self listModel. |
1124 oldSel := model value. |
1129 oldSel := model value. |
1125 model value:nil. |
1130 model value:nil. |