UserMessage.st
author Jan Vrany <jan.vrany@fit.cvut.cz>
Tue, 09 Nov 2010 16:24:28 +0000
branchjv
changeset 17807 06cc6c49e291
parent 17780 b6e42c92eba0
child 17814 b75a7f0c346b
permissions -rw-r--r--
merged with /trunk

"
 COPYRIGHT (c) 2006 by eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
"{ Package: 'stx:libbasic' }"

Object subclass:#UserMessage
	instanceVariableNames:'defaultString key catalogID'
	classVariableNames:''
	poolDictionaries:''
	category:'Interface-Internationalization'
!

!UserMessage class methodsFor:'documentation'!

copyright
"
 COPYRIGHT (c) 2006 by eXept Software AG
              All Rights Reserved

 This software is furnished under a license and may be used
 only in accordance with the terms of that license and with the
 inclusion of the above copyright notice.   This software may not
 be provided or otherwise made available to, or used by, any
 other person.  No title to or ownership of the software is
 hereby transferred.
"
!

documentation
"
    added for vw5i compatibility, which accesses messageCatalogs
    via:
          (#key << #catalogID >> 'defaultMessage')
    which creates an instance of UserMessage.

    Currently, this is a dummy operation in ST/X, however it is mapped onto
    the resource mechanism, if the given catalogID is the name of a class;
    i.e.
        (YesNoBox classResources string:'continue')
    can now also be written as:
        (#continue << #YesNoBox) 
"
! !

!UserMessage class methodsFor:'instance creation'!

key:aKeySymbol catalogID:aCatalogSymbol
     ^ self new key:aKeySymbol catalogID:aCatalogSymbol
!

key:aKeySymbol defaultString:aString
     ^ self new key:aKeySymbol defaultString:aString
! !

!UserMessage methodsFor:'accessing'!

catalogID
     ^ catalogID 
!

catalogID:aCatalogSymbol
     catalogID := aCatalogSymbol
!

defaultString
     ^ defaultString 
!

defaultString:aString
     defaultString := aString
!

key
     ^ key
!

key:aKeySymbol
     key := aKeySymbol.
!

key:aKeySymbol catalogID:aCatalogSymbol
     key := aKeySymbol.
     catalogID := aCatalogSymbol
!

key:aKeySymbol defaultString:aString
     key := aKeySymbol.
     defaultString := aString
! !

!UserMessage methodsFor:'converting'!

asString
    "for now: return the defaultString, ignoring the catalogID."

    |str|

    str := self lookupInMessageCatalog.
    str notNil ifTrue:[ ^ str ].
    defaultString notNil ifTrue:[
        ^ defaultString
    ].
    ^ key asString
!

expandMacros
    ^ self asString expandMacros

!

expandMacrosWith:arg1
    ^ self asString expandMacrosWith:arg1

!

string
    ^ self asString
! !

!UserMessage methodsFor:'printing & storing'!

displayString

    |stream|

    stream := '' writeStream.

    key storeOn:stream.
    stream nextPutAll:' << '.
    catalogID storeOn:stream.
    defaultString notNil ifTrue:[
        stream nextPutAll:' >> '.
        defaultString storeOn:stream.
    ].
    ^ stream contents.
! !

!UserMessage methodsFor:'utilities'!

<< aSymbol
    "set the catalogID"

    self catalogID:aSymbol
!

>> aString
    "set the default string"

    self defaultString:aString

    "
     (#theFooMessage << #myMessages >> 'cannot read subclass of metaclass') 
    "
!

lookupInMessageCatalog
    |messageCatalog|

    "/ for now - handle the case that the catalogID is
    "/ a classes name; in that case, ask its resourcePack.

    catalogID isSymbol ifTrue:[
        messageCatalog := Smalltalk at:catalogID.
    ] ifFalse:[
        messageCatalog := catalogID.
    ].
    messageCatalog isBehavior ifTrue:[
        messageCatalog := messageCatalog classResources.
    ].
    messageCatalog isNil ifTrue:[
        defaultString isNil ifTrue:[
            ^ 'Non-existant message (%1<<%2)' bindWith:key with:catalogID printString.
        ].
        ^ defaultString.
    ].

    ^ messageCatalog at:key ifAbsent:defaultString.

    "
     (#'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 ?' )
     (#'WARN_RENAME' << #BrowserView)
     (#'WARN_RENAME' << BrowserView classResources)
     (#dontKnow << #nonExistantMessageCatalog) asString
    "
! !

!UserMessage class methodsFor:'documentation'!

version
    ^ '$Id: UserMessage.st 10590 2010-11-09 16:24:28Z vranyj1 $'
!

version_CVS
    ^ 'Header: /cvs/stx/stx/libbasic/UserMessage.st,v 1.6 2009-10-02 00:08:10 cg Exp '
!

version_SVN
    ^ '$Id: UserMessage.st 10590 2010-11-09 16:24:28Z vranyj1 $'
! !