author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Sat, 24 Oct 2009 16:48:19 +0100 | |
branch | jv |
changeset 17732 | a1892eeca6c0 |
parent 17711 | 39faaaf888b4 |
child 17734 | 406b1590afe8 |
permissions | -rw-r--r-- |
6117 | 1 |
"{ Package: 'stx:libbasic' }" |
5996 | 2 |
|
3 |
Object subclass:#UserMessage |
|
4 |
instanceVariableNames:'defaultString key catalogID' |
|
5 |
classVariableNames:'' |
|
6 |
poolDictionaries:'' |
|
7 |
category:'Interface-Internationalization' |
|
8 |
! |
|
9 |
||
6008 | 10 |
!UserMessage class methodsFor:'documentation'! |
11 |
||
12 |
documentation |
|
13 |
" |
|
14 |
added for vw5i compatibility, which accesses messageCatalogs |
|
15 |
via: |
|
16 |
(#key << #catalogID >> 'defaultMessage') |
|
17 |
which creates an instance of UserMessage. |
|
18 |
||
19 |
Currently, this is a dummy operation in ST/X, however it is mapped onto |
|
20 |
the resource mechanism, if the given catalogID is the name of a class; |
|
21 |
i.e. |
|
22 |
(YesNoBox classResources string:'continue') |
|
23 |
can now also be written as: |
|
24 |
(#continue << #YesNoBox) |
|
25 |
" |
|
26 |
! ! |
|
5996 | 27 |
|
28 |
!UserMessage class methodsFor:'instance creation'! |
|
29 |
||
30 |
key:aKeySymbol catalogID:aCatalogSymbol |
|
31 |
^ self new key:aKeySymbol catalogID:aCatalogSymbol |
|
32 |
! |
|
33 |
||
34 |
key:aKeySymbol defaultString:aString |
|
35 |
^ self new key:aKeySymbol defaultString:aString |
|
36 |
! ! |
|
37 |
||
38 |
!UserMessage methodsFor:'accessing'! |
|
39 |
||
40 |
catalogID |
|
41 |
^ catalogID |
|
42 |
! |
|
43 |
||
44 |
catalogID:aCatalogSymbol |
|
45 |
catalogID := aCatalogSymbol |
|
46 |
! |
|
47 |
||
48 |
defaultString |
|
49 |
^ defaultString |
|
50 |
! |
|
51 |
||
52 |
defaultString:aString |
|
53 |
defaultString := aString |
|
54 |
! |
|
55 |
||
56 |
key |
|
57 |
^ key |
|
58 |
! |
|
59 |
||
60 |
key:aKeySymbol |
|
61 |
key := aKeySymbol. |
|
62 |
! |
|
63 |
||
64 |
key:aKeySymbol catalogID:aCatalogSymbol |
|
65 |
key := aKeySymbol. |
|
66 |
catalogID := aCatalogSymbol |
|
67 |
! |
|
68 |
||
69 |
key:aKeySymbol defaultString:aString |
|
70 |
key := aKeySymbol. |
|
71 |
defaultString := aString |
|
72 |
! ! |
|
73 |
||
74 |
!UserMessage methodsFor:'converting'! |
|
75 |
||
76 |
asString |
|
77 |
"for now: return the defaultString, ignoring the catalogID." |
|
78 |
||
79 |
|str| |
|
80 |
||
81 |
str := self lookupInMessageCatalog. |
|
82 |
str notNil ifTrue:[ ^ str ]. |
|
83 |
defaultString notNil ifTrue:[ |
|
84 |
^ defaultString |
|
85 |
]. |
|
86 |
^ key asString |
|
6117 | 87 |
! |
88 |
||
89 |
expandMacros |
|
90 |
^ self asString expandMacros |
|
91 |
||
92 |
! |
|
93 |
||
94 |
expandMacrosWith:arg1 |
|
95 |
^ self asString expandMacrosWith:arg1 |
|
96 |
||
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
97 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
98 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
99 |
string |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
100 |
^ self asString |
5996 | 101 |
! ! |
102 |
||
6591 | 103 |
!UserMessage methodsFor:'printing & storing'! |
104 |
||
105 |
displayString |
|
106 |
||
107 |
|stream| |
|
108 |
||
109 |
stream := '' writeStream. |
|
110 |
||
111 |
key storeOn:stream. |
|
112 |
stream nextPutAll:' << '. |
|
113 |
catalogID storeOn:stream. |
|
6887 | 114 |
defaultString notNil ifTrue:[ |
115 |
stream nextPutAll:' >> '. |
|
116 |
defaultString storeOn:stream. |
|
117 |
]. |
|
6591 | 118 |
^ stream contents. |
119 |
! ! |
|
120 |
||
5996 | 121 |
!UserMessage methodsFor:'utilities'! |
122 |
||
123 |
<< aSymbol |
|
124 |
"set the catalogID" |
|
125 |
||
126 |
self catalogID:aSymbol |
|
127 |
! |
|
128 |
||
129 |
>> aString |
|
130 |
"set the default string" |
|
131 |
||
132 |
self defaultString:aString |
|
133 |
||
134 |
" |
|
135 |
(#theFooMessage << #myMessages >> 'cannot read subclass of metaclass') |
|
136 |
" |
|
137 |
! |
|
138 |
||
139 |
lookupInMessageCatalog |
|
6887 | 140 |
|messageCatalog| |
5996 | 141 |
|
6887 | 142 |
"/ for now - handle the case that the catalogID is |
5996 | 143 |
"/ a classes name; in that case, ask its resourcePack. |
144 |
||
6887 | 145 |
catalogID isSymbol ifTrue:[ |
146 |
messageCatalog := Smalltalk at:catalogID. |
|
147 |
] ifFalse:[ |
|
148 |
messageCatalog := catalogID. |
|
149 |
]. |
|
150 |
messageCatalog isBehavior ifTrue:[ |
|
151 |
messageCatalog := messageCatalog classResources. |
|
5996 | 152 |
]. |
6887 | 153 |
messageCatalog isNil ifTrue:[ |
154 |
defaultString isNil ifTrue:[ |
|
155 |
^ 'Non-existant message (%1<<%2)' bindWith:key with:catalogID printString. |
|
156 |
]. |
|
157 |
^ defaultString. |
|
158 |
]. |
|
159 |
||
160 |
^ messageCatalog at:key ifAbsent:defaultString. |
|
5996 | 161 |
|
162 |
" |
|
163 |
(#'WARN_RENAME' << #BrowserView >> 'A class named %1 already exists (in ''%2'')\\that class will no longer be visible (i.e. removed) if you continue.\\Continue ?' ) |
|
6887 | 164 |
(#'WARN_RENAME' << #BrowserView) |
165 |
(#'WARN_RENAME' << BrowserView classResources) |
|
166 |
(#dontKnow << #nonExistantMessageCatalog) asString |
|
5996 | 167 |
" |
168 |
! ! |
|
169 |
||
170 |
!UserMessage class methodsFor:'documentation'! |
|
171 |
||
172 |
version |
|
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
173 |
^ '$Id: UserMessage.st 10473 2009-10-24 15:48:19Z vranyj1 $' |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
174 |
! |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
175 |
|
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
176 |
version_CVS |
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
177 |
^ '§Header: /cvs/stx/stx/libbasic/UserMessage.st,v 1.6 2009/10/02 00:08:10 cg Exp §' |
5996 | 178 |
! ! |
17732
a1892eeca6c0
trunk merged into jv branch
Jan Vrany <jan.vrany@fit.cvut.cz>
parents:
17711
diff
changeset
|
179 |