AbstractSettingsApplication.st
changeset 15901 8b3a58efae83
parent 15899 ea88da97ae6c
child 15902 b3c12e60a5b9
--- a/AbstractSettingsApplication.st	Sun Oct 11 10:29:18 2015 +0200
+++ b/AbstractSettingsApplication.st	Thu Oct 15 01:58:55 2015 +0200
@@ -146,7 +146,7 @@
 	instanceVariableNames:'languageHolder languageIndexHolder languageList
 		languageListHolder listOfLanguages translatedLanguages
 		noticeLabelHolder currentFlagAndLanguageChannel
-		currentLanguageLabel perLanguageResources'
+		currentLanguageLabel perLanguageResources useSystemLanguageHolder'
 	classVariableNames:''
 	poolDictionaries:''
 	privateIn:AbstractSettingsApplication
@@ -6063,6 +6063,29 @@
     ^ Label defaultFont asBold
 ! !
 
+!AbstractSettingsApplication::LanguageSettingsAppl class methodsFor:'help specs'!
+
+flyByHelpSpec
+    "This resource specification was automatically generated
+     by the UIHelpTool of ST/X."
+
+    "Do not manually edit this!! If it is corrupted,
+     the UIHelpTool may not be able to read the specification."
+
+    "
+     UIHelpTool openOnClass:HTTPServerSettingsAppl    
+    "
+
+    <resource: #help>
+
+    ^ super flyByHelpSpec addPairsFrom:#(
+
+#useSystemLanguage
+'If set, the operating system language (LANG variable) is used agaig in the next session\(and the setting here only affects the current session).\If clear, this language is also used in the next session.'
+
+)
+! !
+
 !AbstractSettingsApplication::LanguageSettingsAppl class methodsFor:'image specs'!
 
 defaultIcon
@@ -6088,92 +6111,100 @@
 
     <resource: #canvas>
 
-    ^
+    ^ 
     #(FullSpec
        name: windowSpec
-       window:
+       window: 
       (WindowSpec
-	 label: 'Language Settings'
-	 name: 'Language Settings'
-	 min: (Point 10 10)
-	 bounds: (Rectangle 0 0 571 878)
-       )
-       component:
+         label: 'Language Settings'
+         name: 'Language Settings'
+         min: (Point 10 10)
+         bounds: (Rectangle 0 0 571 878)
+       )
+       component: 
       (SpecCollection
-	 collection: (
-	  (LabelSpec
-	     label: 'Current Language:'
-	     name: 'Label1'
-	     layout: (LayoutFrame 0 0 0 0 -233 1 30 0)
-	     translateLabel: true
-	     labelChannel: currentLanguageLabel
-	     adjust: right
-	   )
-	  (LabelSpec
-	     label: 'Label'
-	     name: 'CurrentLang'
-	     layout: (LayoutFrame -233 1 0 0 0 1 30 0)
-	     style: bigLabelFont
-	     translateLabel: true
-	     labelChannel: currentFlagAndLanguageChannel
-	     adjust: left
-	   )
-	  (TextEditorSpec
-	     name: 'TextEditor1'
-	     layout: (LayoutFrame 0 0 32 0 0 1.0 240 0)
-	     model: noticeLabelHolder
-	     hasHorizontalScrollBar: true
-	     hasVerticalScrollBar: true
-	     miniScrollerHorizontal: true
-	     autoHideScrollBars: true
-	     isReadOnly: true
-	     hasKeyboardFocusInitially: false
-	     viewClassName: 'TextView'
-	     postBuildCallback: postBuildHelpLabel:
-	   )
-	  (InputFieldSpec
-	     name: 'EntryField1'
-	     layout: (LayoutFrame 2 0.0 240 0 -2 1.0 270 0)
-	     model: languageHolder
-	     acceptOnReturn: true
-	     acceptOnTab: true
-	     acceptOnLostFocus: true
-	     acceptOnPointerLeave: true
-	   )
-	  (SequenceViewSpec
-	     name: 'List1'
-	     layout: (LayoutFrame 2 0.0 270 0 -2 1.0 -30 1.0)
-	     model: languageIndexHolder
-	     hasHorizontalScrollBar: true
-	     hasVerticalScrollBar: true
-	     doubleClickSelector: doubleClick:
-	     useIndex: true
-	     sequenceList: languageListHolder
-	   )
-	  (HorizontalPanelViewSpec
-	     name: 'HorizontalPanel1'
-	     layout: (LayoutFrame 0 0 -30 1 0 1 0 1)
-	     horizontalLayout: center
-	     verticalLayout: center
-	     horizontalSpace: 3
-	     verticalSpace: 3
-	     component:
-	    (SpecCollection
-	       collection: (
-		(ActionButtonSpec
-		   label: 'Reread Language Resources'
-		   name: 'RereadResourcesButton'
-		   translateLabel: true
-		   resizeForLabel: true
-		   model: rereadResourceFiles
-		   useDefaultExtent: true
-		 )
-		)
-
-	     )
-	   )
-	  )
-
+         collection: (
+          (LabelSpec
+             label: 'Current Language:'
+             name: 'Label1'
+             layout: (LayoutFrame 0 0 0 0 -233 1 30 0)
+             translateLabel: true
+             labelChannel: currentLanguageLabel
+             adjust: right
+           )
+          (LabelSpec
+             label: 'Label'
+             name: 'CurrentLang'
+             layout: (LayoutFrame -233 1 0 0 0 1 30 0)
+             style: bigLabelFont
+             translateLabel: true
+             labelChannel: currentFlagAndLanguageChannel
+             adjust: left
+           )
+          (TextEditorSpec
+             name: 'TextEditor1'
+             layout: (LayoutFrame 0 0 32 0 0 1.0 240 0)
+             model: noticeLabelHolder
+             hasHorizontalScrollBar: true
+             hasVerticalScrollBar: true
+             miniScrollerHorizontal: true
+             autoHideScrollBars: true
+             isReadOnly: true
+             hasKeyboardFocusInitially: false
+             postBuildCallback: postBuildHelpLabel:
+             viewClassName: 'TextView'
+           )
+          (InputFieldSpec
+             name: 'EntryField1'
+             layout: (LayoutFrame 2 0.0 240 0 -2 1.0 270 0)
+             model: languageHolder
+             acceptOnReturn: true
+             acceptOnTab: true
+             acceptOnLostFocus: true
+             acceptOnPointerLeave: true
+           )
+          (SequenceViewSpec
+             name: 'List1'
+             layout: (LayoutFrame 2 0.0 300 0 -2 1.0 -30 1.0)
+             model: languageIndexHolder
+             hasHorizontalScrollBar: true
+             hasVerticalScrollBar: true
+             doubleClickSelector: doubleClick:
+             useIndex: true
+             sequenceList: languageListHolder
+           )
+          (HorizontalPanelViewSpec
+             name: 'HorizontalPanel1'
+             layout: (LayoutFrame 0 0 -30 1 0 1 0 1)
+             horizontalLayout: center
+             verticalLayout: center
+             horizontalSpace: 3
+             verticalSpace: 3
+             component: 
+            (SpecCollection
+               collection: (
+                (ActionButtonSpec
+                   label: 'Reread Language Resources'
+                   name: 'RereadResourcesButton'
+                   translateLabel: true
+                   resizeForLabel: true
+                   model: rereadResourceFiles
+                   useDefaultExtent: true
+                 )
+                )
+              
+             )
+           )
+          (CheckBoxSpec
+             label: 'Use OS Language on Startup'
+             name: 'CheckBox1'
+             layout: (LayoutFrame 0 0.0 275 0 0 1.0 297 0)
+             model: useSystemLanguageHolder
+             activeHelpKey: useSystemLanguage
+             translateLabel: true
+           )
+          )
+        
        )
      )
 ! !
@@ -6189,6 +6220,7 @@
 !AbstractSettingsApplication::LanguageSettingsAppl methodsFor:'actions'!
 
 basicReadSettings
+    self useSystemLanguageHolder value:(currentUserPrefs useSystemLanguage).
     self languageIndexHolder value:self currentLanguageIndex.
     self languageHolder value:self currentLanguage.
     self currentFlagAndLanguageChannel value:self currentLanguage.
@@ -6200,122 +6232,124 @@
     |fontPref fontPrefs language oldLanguage languageString territory enc
      answer matchingFonts l screen switch dialog anyWrong|
 
+    currentUserPrefs useSystemLanguage:(self useSystemLanguageHolder value).
+    
     self withWaitCursorDo:[
-	languageString := translatedLanguages at:(self languageIndexHolder value).
-	language := self languageHolder value asString string.
-	(language includes:$-) ifTrue:[
-	    l := language asCollectionOfSubstringsSeparatedBy:$-.
-	    language := l at:1.
-	    territory := l at:2.
-	].
-	territory isNil ifTrue:[
-	    territory := language string copyTo:2
-	].
-
-	"/ 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 := UserPreferences current language.
-	Smalltalk language:language asSymbol.
-	ResourcePack flushCachedResourcePacks.
-
-	"/ refetch resources ...
-	resources := AbstractLauncherApplication classResources.
-	fontPrefs := resources at:'PREFERRED_FONT_ENCODINGS' default:nil.
-	fontPrefs isNil ifTrue:[
-	    fontPref := resources at:'PREFERRED_FONT_ENCODING' default:nil.
-	    fontPref isNil ifTrue:[
-		fontPrefs := #(#'iso10646-1')
-	    ] ifFalse:[
-		fontPrefs := #(#'iso10646-1') , (Array with:fontPref).
-	    ]
-	].
-
-	"/ 'normalize' names of encodings
-	fontPrefs := fontPrefs collect:[:each | (CharacterEncoder encoderFor:each asLowercase asSymbol ifAbsent:nil)].
-	fontPrefs := fontPrefs select:[:each | each notNil] thenCollect:[:each | each nameOfEncoding].
-	fontPrefs isEmpty ifTrue:[
-	    fontPrefs := #(#'iso10464-1')
-	].
-	fontPref := fontPrefs first.
-
-	Smalltalk setLanguage:#en.
-	ResourcePack flushCachedResourcePacks.
-	resources := AbstractLauncherApplication classResources.
-
-	switch := true.
-	anyWrong := false.
-	(Array
-	    with:MenuView defaultFont
-	    "/ with:ListView defaultFont
-	    with:EditTextView defaultFont
-	    with:Button defaultFont)
-	do:[:fn |
-	    enc := fn encoding.
-	    enc isNil ifFalse:[
-		(fontPrefs contains:[:pref | CharacterEncoder isEncoding:pref subSetOf:enc])
-		ifFalse:[
-		    anyWrong := true
-		].
-	    ].
-	].
-	anyWrong ifTrue:[
-	    "/ look if there is one at all.
-	    screen := Screen current.
-	    matchingFonts := screen listOfAvailableFonts
-				select:[:f | fontPrefs contains:[:pref |
-						CharacterEncoder
-						    isEncoding:pref subSetOf:(f encoding ? 'ascii')]].
-
-	    matchingFonts isEmpty ifTrue:[
-		"/ flush and try again - just in case, the font path has changed.
-		screen flushListOfAvailableFonts.
-		matchingFonts := screen listOfAvailableFonts
-				    select:[:f | fontPrefs contains:[:pref |
-						    CharacterEncoder
-							isEncoding:pref subSetOf:(f encoding ? 'ascii')]].
-	    ].
-	    matchingFonts isEmpty ifTrue:[
-		(Dialog
-		    confirm:(resources
-				string:'Your display does not seem to offer any appropriate font.\\Change the language anyway ?\ (Texts will probably be unreadable then)'
-				  with:fontPref) withCRs)
-		ifFalse:[
-		    switch := false
-		]
-	    ] ifFalse:[
-		answer := Dialog
-			    confirmWithCancel:(resources
-						    string:'Some font(s) 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 := (AbstractLauncherApplication::LauncherDialogs fontBoxForEncoding:fontPref)
-		    ]
-		].
-	    ].
-	].
-
-	switch ifTrue:[
-	    Transcript showCR:'Changing language setting to ' , languageString string , ' (' , language , ')...'.
-	    Smalltalk language:language asSymbol territory:(territory ? language) asSymbol.
-	    ResourcePack flushCachedResourcePacks.
-	    "/ ResourcePack flushCachedResourcePacks - already done by language-change
-	].
+        languageString := translatedLanguages at:(self languageIndexHolder value).
+        language := self languageHolder value asString string.
+        (language includes:$-) ifTrue:[
+            l := language asCollectionOfSubstringsSeparatedBy:$-.
+            language := l at:1.
+            territory := l at:2.
+        ].
+        territory isNil ifTrue:[
+            territory := language string copyTo:2
+        ].
+
+        "/ 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 := UserPreferences current language.
+        Smalltalk language:language asSymbol.
+        ResourcePack flushCachedResourcePacks.
+
+        "/ refetch resources ...
+        resources := AbstractLauncherApplication classResources.
+        fontPrefs := resources at:'PREFERRED_FONT_ENCODINGS' default:nil.
+        fontPrefs isNil ifTrue:[
+            fontPref := resources at:'PREFERRED_FONT_ENCODING' default:nil.
+            fontPref isNil ifTrue:[
+                fontPrefs := #(#'iso10646-1')
+            ] ifFalse:[
+                fontPrefs := #(#'iso10646-1') , (Array with:fontPref).
+            ]
+        ].
+
+        "/ 'normalize' names of encodings
+        fontPrefs := fontPrefs collect:[:each | (CharacterEncoder encoderFor:each asLowercase asSymbol ifAbsent:nil)].
+        fontPrefs := fontPrefs select:[:each | each notNil] thenCollect:[:each | each nameOfEncoding].
+        fontPrefs isEmpty ifTrue:[
+            fontPrefs := #(#'iso10464-1')
+        ].
+        fontPref := fontPrefs first.
+
+        Smalltalk setLanguage:#en.
+        ResourcePack flushCachedResourcePacks.
+        resources := AbstractLauncherApplication classResources.
+
+        switch := true.
+        anyWrong := false.
+        (Array
+            with:MenuView defaultFont
+            "/ with:ListView defaultFont
+            with:EditTextView defaultFont
+            with:Button defaultFont)
+        do:[:fn |
+            enc := fn encoding.
+            enc isNil ifFalse:[
+                (fontPrefs contains:[:pref | CharacterEncoder isEncoding:pref subSetOf:enc])
+                ifFalse:[
+                    anyWrong := true
+                ].
+            ].
+        ].
+        anyWrong ifTrue:[
+            "/ look if there is one at all.
+            screen := Screen current.
+            matchingFonts := screen listOfAvailableFonts
+                                select:[:f | fontPrefs contains:[:pref |
+                                                CharacterEncoder
+                                                    isEncoding:pref subSetOf:(f encoding ? 'ascii')]].
+
+            matchingFonts isEmpty ifTrue:[
+                "/ flush and try again - just in case, the font path has changed.
+                screen flushListOfAvailableFonts.
+                matchingFonts := screen listOfAvailableFonts
+                                    select:[:f | fontPrefs contains:[:pref |
+                                                    CharacterEncoder
+                                                        isEncoding:pref subSetOf:(f encoding ? 'ascii')]].
+            ].
+            matchingFonts isEmpty ifTrue:[
+                (Dialog
+                    confirm:(resources
+                                string:'Your display does not seem to offer any appropriate font.\\Change the language anyway ?\ (Texts will probably be unreadable then)'
+                                  with:fontPref) withCRs)
+                ifFalse:[
+                    switch := false
+                ]
+            ] ifFalse:[
+                answer := Dialog
+                            confirmWithCancel:(resources
+                                                    string:'Some font(s) 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 := (AbstractLauncherApplication::LauncherDialogs fontBoxForEncoding:fontPref)
+                    ]
+                ].
+            ].
+        ].
+
+        switch ifTrue:[
+            Transcript showCR:'Changing language setting to ' , languageString string , ' (' , language , ')...'.
+            Smalltalk language:language asSymbol territory:(territory ? language) asSymbol.
+            ResourcePack flushCachedResourcePacks.
+            "/ ResourcePack flushCachedResourcePacks - already done by language-change
+        ].
     ].
     switch ifTrue:[
-	(dialog := settingsDialog) notNil ifTrue:[
-	    dialog reopenLauncher.
-	] ifFalse:[
-	    NewLauncher current reopenLauncher.
-	].
-	DebugView newDebugger.
+        (dialog := settingsDialog) notNil ifTrue:[
+            dialog reopenLauncher.
+        ] ifFalse:[
+            NewLauncher current reopenLauncher.
+        ].
+        DebugView newDebugger.
     ].
     self updateForChangedLanguage.
 
@@ -6412,6 +6446,14 @@
 setNoticeLabel
     noticeLabelHolder
 	value: ((resources at:'LANG_MSG' default:'Select a Language') withCRs).
+!
+
+useSystemLanguageHolder
+    useSystemLanguageHolder isNil ifTrue:[
+        useSystemLanguageHolder := true asValue.
+        useSystemLanguageHolder onChangeSend:#updateModifiedChannel to:self.
+    ].
+    ^ useSystemLanguageHolder.
 ! !
 
 !AbstractSettingsApplication::LanguageSettingsAppl methodsFor:'help'!
@@ -6639,6 +6681,7 @@
 !
 
 hasUnsavedChanges
+    useSystemLanguageHolder value ~= currentUserPrefs useSystemLanguage ifTrue:[^ true].
     ^ languageIndexHolder value ~= self currentLanguageIndex
 
     "Modified: / 17-10-2006 / 17:51:09 / cg"