891 |
891 |
892 "Modified: / 31.10.1997 / 17:30:34 / cg" |
892 "Modified: / 31.10.1997 / 17:30:34 / cg" |
893 "Created: / 31.10.1997 / 17:32:49 / cg" |
893 "Created: / 31.10.1997 / 17:32:49 / cg" |
894 ! |
894 ! |
895 |
895 |
|
896 generateMenuMethodFor:menuSel inClass:targetClass |
|
897 |selector args showIt code alreadyInSuperclass numArgs method| |
|
898 |
|
899 selector := menuSel asSymbol. |
|
900 |
|
901 alreadyInSuperclass := targetClass superclass canUnderstand:selector. |
|
902 |
|
903 code := '!!' , targetClass name , ' methodsFor:''menu actions''!!\\'. |
|
904 |
|
905 selector = 'openAboutThisApplication' ifTrue:[ |
|
906 code := code , |
|
907 'openAboutThisApplication\' , |
|
908 ' "opens an about box for this application."\\' , |
|
909 ' "automatically generated by UIPainter ..."\\' , |
|
910 |
|
911 ' |rev box myClass clsRev image msg|\\' , |
|
912 |
|
913 ' rev := ''''.\' , |
|
914 ' myClass := self class.\' , |
|
915 |
|
916 ' (clsRev := myClass revision) notNil ifTrue:[\' , |
|
917 ' rev := '' (rev: '', clsRev printString, '')''].\\' , |
|
918 |
|
919 ' msg := Character cr asString , myClass name asBoldText, rev.\' , |
|
920 ' msg := (msg , ''\\*** add more info here ***\\'') withCRs.\\' , |
|
921 ' box := AboutBox title:msg.\' , |
|
922 |
|
923 ' "/ *** add a #defaultIcon method in the class\' , |
|
924 ' "/ *** and uncomment the following line:\' , |
|
925 ' "/ image := self class defaultIcon.\\' , |
|
926 ' image notNil ifTrue:[\' , |
|
927 ' box image:image\' , |
|
928 ' ].\' , |
|
929 ' box label:(resources string:''About %1'' with:myClass name).\' , |
|
930 ' box autoHideAfter:10 with:[].\' , |
|
931 ' box showAtPointer.\' , |
|
932 '!! !!\\'. |
|
933 ^ code withCRs |
|
934 ]. |
|
935 |
|
936 selector = 'menuOpen' ifTrue:[ |
|
937 code := code , |
|
938 'menuOpen\' , |
|
939 ' "automatically generated by UIPainter ..."\\' , |
|
940 ' "*** the code below opens a dialog for file selection"\' , |
|
941 ' "*** and invokes the #doOpen: method with the selected file."\' , |
|
942 ' "*** Please change as required and accept in the browser."\\' , |
|
943 ' |file|\\' , |
|
944 ' file :=\' , |
|
945 ' (FileSelectionBrowser\' , |
|
946 ' request: ''Open''\' , |
|
947 ' fileName: ''''\' , |
|
948 ' "/ inDirectory: lastOpenDirectory\' , |
|
949 ' withFileFilters: #(''*'')).\\' , |
|
950 ' file notNil ifTrue:[\' , |
|
951 ' "/ lastOpenDirectory := file asFilename directory.\' , |
|
952 ' self doOpen:file\' , |
|
953 ' ]\' , |
|
954 '!! !!\'. |
|
955 ^ code withCRs |
|
956 ]. |
|
957 |
|
958 numArgs := selector numArgs. |
|
959 method := selector. |
|
960 |
|
961 numArgs == 1 ifTrue:[ |
|
962 args := 'anArgument'. |
|
963 showIt := ''' , anArgument printString , '' ...''.\'. |
|
964 ] ifFalse:[ |
|
965 args := ''. |
|
966 showIt := ' ...''.\'. |
|
967 |
|
968 numArgs ~~ 0 ifTrue:[ |
|
969 method := ''. |
|
970 |
|
971 selector keywords keysAndValuesDo:[:i :key| |
|
972 method := method, key, 'arg', i printString, ' ' |
|
973 ] |
|
974 ] |
|
975 ]. |
|
976 |
|
977 code := code , |
|
978 method , args , '\' , |
|
979 ' "automatically generated by UIPainter ..."\\' , |
|
980 ' "*** the code below performs no action"\' , |
|
981 ' "*** (except for some feedback on the Transcript)"\' , |
|
982 ' "*** Please change as required and accept in the browser."\' , |
|
983 '\' . |
|
984 |
|
985 alreadyInSuperclass ifTrue:[ |
|
986 code := code , |
|
987 ' "action for ' , selector , ' is already provided in a superclass."\' , |
|
988 ' "It may be redefined here ..."\\'. |
|
989 ] ifFalse:[ |
|
990 code := code , |
|
991 ' "action to be added ..."\\'. |
|
992 ]. |
|
993 |
|
994 code := code , |
|
995 ' Transcript showCR:self class name, '': '. |
|
996 alreadyInSuperclass ifTrue:[ |
|
997 code := code , 'inherited '. |
|
998 ]. |
|
999 code := code , 'menu action for ' , selector , showIt. |
|
1000 |
|
1001 alreadyInSuperclass ifTrue:[ |
|
1002 code := code , |
|
1003 ' super ' , selector , args , '.\'. |
|
1004 ]. |
|
1005 |
|
1006 code := code , |
|
1007 '!! !!\\'. |
|
1008 ^ code withCRs |
|
1009 |
|
1010 "Created: / 23.8.1998 / 16:46:51 / cg" |
|
1011 "Modified: / 23.8.1998 / 18:13:05 / cg" |
|
1012 ! |
|
1013 |
|
1014 generateMenuMethods |
|
1015 "generate menu methods |
|
1016 - but do not overwrite existing ones. |
|
1017 Return a string ready to compile into the application class." |
|
1018 |
|
1019 |cls code skip menuSelector protoSpec thisCode |
|
1020 definedMethodSelectors iVars t |
|
1021 specArray fullSpec winSpec menuSpec |
|
1022 | |
|
1023 |
|
1024 className isNil ifTrue:[ |
|
1025 self warn:'Set first the class!!'. |
|
1026 ^ code |
|
1027 ]. |
|
1028 |
|
1029 (cls := self resolveName:className) isNil ifTrue:[ |
|
1030 self warn:'Class ', className asString, ' does not exist!!'. |
|
1031 ^ code |
|
1032 ]. |
|
1033 |
|
1034 specArray := treeView generateFullSpecForComponents:#(). |
|
1035 fullSpec := specArray decodeAsLiteralArray. |
|
1036 winSpec := fullSpec window. |
|
1037 menuSelector := winSpec menu. |
|
1038 |
|
1039 menuSelector isNil ifTrue:[ |
|
1040 self warn:'No menu defined (yet)'. |
|
1041 ^ code |
|
1042 ]. |
|
1043 (cls respondsTo:menuSelector) ifFalse:[ |
|
1044 self warn:'No menu defined (yet)'. |
|
1045 ^ code. |
|
1046 ]. |
|
1047 menuSpec := cls perform:menuSelector. |
|
1048 menuSpec := menuSpec decodeAsLiteralArray. |
|
1049 |
|
1050 definedMethodSelectors := IdentitySet new. |
|
1051 code := ''. |
|
1052 |
|
1053 menuSpec allItemsDo:[:item | |
|
1054 |sel| |
|
1055 |
|
1056 (sel := item value) notNil ifTrue:[ |
|
1057 (definedMethodSelectors includes:sel) ifFalse:[ |
|
1058 self generateCodeFrom:(Array with:sel) in:cls do:[:aSel| |
|
1059 thisCode := (self generateMenuMethodFor:aSel inClass:cls). |
|
1060 code := code, thisCode. |
|
1061 ]. |
|
1062 definedMethodSelectors add:sel. |
|
1063 ]. |
|
1064 ] |
|
1065 ]. |
|
1066 |
|
1067 (definedMethodSelectors includes:#menuOpen) ifTrue:[ |
|
1068 self generateCodeFrom:(Array with:#doOpen:) in:cls do:[:aSel| |
|
1069 thisCode := (self generateMenuMethodFor:aSel inClass:cls). |
|
1070 code := code, thisCode. |
|
1071 ]. |
|
1072 ]. |
|
1073 |
|
1074 ^ code |
|
1075 |
|
1076 "Created: / 23.8.1998 / 16:12:09 / cg" |
|
1077 "Modified: / 23.8.1998 / 18:12:23 / cg" |
|
1078 ! |
|
1079 |
896 generateValueMethodFor:aspect spec:protoSpec inClass:targetClass |
1080 generateValueMethodFor:aspect spec:protoSpec inClass:targetClass |
897 ^ ('!!' , targetClass name , ' methodsFor:''values''!!\\' , |
1081 ^ ('!!' , targetClass name , ' methodsFor:''values''!!\\' , |
898 aspect , '\' , |
1082 aspect , '\' , |
899 ' "automatically generated by UIPainter ..."\\' , |
1083 ' "automatically generated by UIPainter ..."\\' , |
900 ' "*** the code below returns a default value when invoked."\' , |
1084 ' "*** the code below returns a default value when invoked."\' , |