check for required font encoding BEFORE changing the
authorClaus Gittinger <cg@exept.de>
Fri, 18 Oct 1996 16:23:47 +0200
changeset 777 f00fc8691802
parent 776 f1a70d73582a
child 778 e0f6238c9dd5
check for required font encoding BEFORE changing the language setting
Launcher.st
--- a/Launcher.st	Fri Oct 18 15:30:15 1996 +0200
+++ b/Launcher.st	Fri Oct 18 16:23:47 1996 +0200
@@ -1410,7 +1410,7 @@
 !
 
 languageSetting 
-    |listOfLanguages translatedLanguages idx language  box|
+    |listOfLanguages translatedLanguages switch box|
 
     "
      get list of supported languages from the launchers resources ...
@@ -1424,25 +1424,73 @@
     box initialText:(Language).
     box action:[:newLanguage |
         self withWaitCursorDo:[
-            transcript showCR:'change language to ' , newLanguage , ' ...'.
+            |fontPref idx language oldLanguage enc answer matchingFonts|
+
             idx := translatedLanguages indexOf:newLanguage withoutSeparators.
             idx ~~ 0 ifTrue:[
                 language := listOfLanguages at:idx
             ] ifFalse:[
                 language := newLanguage
             ].
+
+            "/ check if the new language needs a differently encoded font;
+            "/ ask user to switch font and allow cancellation.
+            "/ Otherwise, you are left with unreadable menu & button items ...
+
+            oldLanguage := Smalltalk language.
             Smalltalk language:language asSymbol.
-            ResourcePack flushCachedResourcePacks
+            ResourcePack flushCachedResourcePacks.
+            fontPref := self class classResources at:'PREFERRED_FONT_ENCODING'.
+            Smalltalk language:oldLanguage.
+
+            switch := true.
+            enc := MenuView defaultFont encoding.
+            (fontPref match:enc) ifFalse:[
+                "/ look if there is one at all.
+                matchingFonts := Screen current listOfAvailableFonts select:[:f | fontPref match:f encoding].
+                matchingFonts size == 0 ifTrue:[
+                    (Dialog 
+                        confirm:(resources 
+                                    string:'your display does not offer any %1-encoded font.\\Change the language anyway ?\ (texts will probably be unreadable then)'
+                                      with:fontPref) withCRs)
+                    ifFalse:[
+                        switch := false
+                    ]
+                ] ifFalse:[
+                    answer := Dialog 
+                                confirmWithCancel:(resources 
+                                                        string:'menu font is not %1-encoded.\\Change it ?'
+                                                        with:fontPref) withCRs
+                                           labels:(resources
+                                                        array:#('cancel' 'no' 'yes'))
+                                           default:3.
+                    answer isNil ifTrue:[
+                        switch := false
+                    ] ifFalse:[
+                        answer ifTrue:[
+                            switch := (self fontBoxForEncoding:fontPref)
+                        ]
+                    ].
+                ].
+            ].
+
+            switch ifTrue:[
+                transcript showCR:'change language to ' , newLanguage , ' ...'.
+                Smalltalk language:language asSymbol.
+                ResourcePack flushCachedResourcePacks
+            ].
         ].
-        self reopenLauncher.
+        switch ifTrue:[
+            self reopenLauncher.
+        ]
     ].    
     box
         addHelpButtonFor:'Launcher/languageSetting.html'.
     box open.
     box destroy
 
-    "Modified: 5.7.1996 / 13:12:39 / cg"
     "Modified: 9.9.1996 / 22:43:27 / stefan"
+    "Modified: 18.10.1996 / 15:09:16 / cg"
 !
 
 memorySettings
@@ -3532,21 +3580,25 @@
 
     |contents fontPref enc newLauncher|
 
-    fontPref := self class classResources at:'PREFERRED_FONT_ENCODING'.
-    enc := MenuView defaultFont encoding.
-    (fontPref match:enc) ifFalse:[
-        (self confirm:'menu font is not ' , fontPref , '-encoded.\\Change it ?' withCRs)
-        ifTrue:[
-            self fontBoxForEncoding:fontPref
-        ]
-    ].
+"/ moved the stuff below to the language-setting
+"/ dialog (ask before changing the language, to have
+"/ proper texts in the dialogs).
+"/
+"/    fontPref := self class classResources at:'PREFERRED_FONT_ENCODING'.
+"/    enc := MenuView defaultFont encoding.
+"/    (fontPref match:enc) ifFalse:[
+"/        (self confirm:'menu font is not ' , fontPref , '-encoded.\\Change it ?' withCRs)
+"/        ifTrue:[
+"/            self fontBoxForEncoding:fontPref
+"/        ]
+"/    ].
 
     contents := transcript endEntry; list.
     newLauncher := self class open.
     newLauncher window waitUntilVisible.
     newLauncher transcript list:contents; hideCursor; scrollToBottom; cursorToEnd; showCursor
 
-    "Modified: 5.7.1996 / 14:00:40 / cg"
+    "Modified: 18.10.1996 / 15:04:06 / cg"
 !
 
 saveAllViews
@@ -3595,5 +3647,5 @@
 !Launcher class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libtool/Launcher.st,v 1.201 1996-10-18 13:30:15 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libtool/Launcher.st,v 1.202 1996-10-18 14:23:47 cg Exp $'
 ! !