#UI_ENHANCEMENT
authorClaus Gittinger <cg@exept.de>
Thu, 29 Oct 2015 15:41:15 +0100
changeset 15932 31756c0844aa
parent 15931 b8b56366530f
child 15933 6d96850e24d3
#UI_ENHANCEMENT class: Tools::FontSettingsApplication better font seelction UI
Tools__FontSettingsApplication.st
--- a/Tools__FontSettingsApplication.st	Thu Oct 29 14:44:21 2015 +0100
+++ b/Tools__FontSettingsApplication.st	Thu Oct 29 15:41:15 2015 +0100
@@ -1,3 +1,5 @@
+"{ Encoding: utf8 }"
+
 "{ Package: 'stx:libtool' }"
 
 "{ NameSpace: Tools }"
@@ -10,7 +12,8 @@
 		textLabel labelLabel listsLabel menuLabel inputFieldLabel
 		inputFieldDef inputFieldFontLabelHolder otherLabel
 		linuxFontWorkaround otherDef tooltipDef tooltipFontLabelHolder
-		tooltipLabel useXftFontsOnly'
+		tooltipLabel useXftFontsOnly fontSizeSelectionHolder
+		lookSelectionHolder'
 	classVariableNames:''
 	poolDictionaries:''
 	category:'Interface-Smalltalk'
@@ -50,7 +53,10 @@
 'Reset fonts back to original default values (as specified in the window style-file and OS settings)'
 
 #changeToHighContrast
-'Change settings for higher contrast.\Useful for presentations and outdor operation'
+'Change settings for higher contrast.\Useful for presentations and outdor operation (bright sunlight)'
+
+#changeToNormalContrast
+'Change settings for normal contrast.'
 
 #changeToBigFonts
 'Change settings for bigger fonts.\Useful for presentations'
@@ -58,6 +64,12 @@
 #changeToHugeFonts
 'Change settings for huge fonts.\Useful for presentations'
 
+#changeToSmallFonts
+'Change settings for small fonts.\Useful on smaller screens (13 or 15 inch)'
+
+#changeToNormalFonts
+'Change settings for default font sizes.'
+
 #changeToSTXLook
 'Change settings for an ST/X-like look with fixed-width code fonts'
 
@@ -492,9 +504,9 @@
                 (CheckBoxSpec
                    label: 'Only Use Xft Fonts (Unix Only)'
                    name: 'CheckBox1'
+                   activeHelpKey: useXftFontsOnly
                    visibilityChannel: useXftFontsOnlyVisible
                    model: useXftFontsOnly
-                   activeHelpKey: useXftFontsOnly
                    translateLabel: true
                    extent: (Point 637 30)
                  )
@@ -517,70 +529,64 @@
                          tabable: true
                          model: changeToDefault
                        )
+                      (LabelSpec
+                         label: 'Font Size:'
+                         name: 'Label9'
+                         layout: (LayoutFrame 148 0.0 13 0 298 0 35 0)
+                         activeHelpKey: changeToSmallFonts
+                         translateLabel: true
+                         adjust: left
+                       )
+                      (ComboListSpec
+                         name: 'ComboList1'
+                         layout: (LayoutFrame 256 0 13 0 0 1 35 0)
+                         model: fontSizeSelectionHolder
+                         comboList: fontSizeListLabels
+                         useIndex: true
+                       )
                       (ActionButtonSpec
                          label: 'High Contrast'
-                         name: 'Button3'
-                         layout: (LayoutFrame 148 0.0 13 0 298 0 35 0)
+                         name: 'Button13'
+                         layout: (LayoutFrame 256 0.0 77 0 386 0 99 0)
                          activeHelpKey: changeToHighContrast
                          translateLabel: true
                          tabable: true
                          model: changeToHighContrast
                        )
-                      (ActionButtonSpec
-                         label: 'Big Fonts'
-                         name: 'Button4'
-                         layout: (LayoutFrame 309 0.0 13 0 459 0 35 0)
-                         activeHelpKey: changeToBigFonts
-                         translateLabel: true
-                         tabable: true
-                         model: changeToBigFonts
-                       )
-                      (ActionButtonSpec
-                         label: 'Huge Fonts'
-                         name: 'Button5'
-                         layout: (LayoutFrame 470 0.0 13 0 620 0 35 0)
-                         activeHelpKey: changeToHugeFonts
-                         translateLabel: true
-                         tabable: true
-                         model: changeToHugeFonts
-                       )
-                      (ActionButtonSpec
-                         label: 'ST/X Look'
-                         name: 'Button8'
+                      (LabelSpec
+                         label: 'Look:'
+                         name: 'Label10'
                          layout: (LayoutFrame 148 0.0 45 0 298 0 67 0)
                          activeHelpKey: changeToSTXLook
                          translateLabel: true
-                         tabable: true
-                         model: changeToSTXLook
+                         adjust: left
                        )
-                      (ActionButtonSpec
-                         label: 'Squeak Look'
-                         name: 'Button6'
-                         layout: (LayoutFrame 309 0.0 45 0 459 0 67 0)
-                         activeHelpKey: changeToSqueakLook
-                         translateLabel: true
-                         tabable: true
-                         model: changeToSqueakLook
+                      (ComboListSpec
+                         name: 'ComboList2'
+                         layout: (LayoutFrame 256 0 45 0 0 1 67 0)
+                         model: lookSelectionHolder
+                         comboList: lookListLabels
+                         useIndex: true
                        )
                       (ActionButtonSpec
-                         label: 'V''Age Look'
-                         name: 'Button7'
-                         layout: (LayoutFrame 470 0.0 45 0 620 0 67 0)
-                         activeHelpKey: changeToVisualAgeLook
-                         translateLabel: true
-                         tabable: true
-                         model: changeToVisualAgeLook
-                       )
-                      (ActionButtonSpec
-                         label: 'ST/X Look (Xft)'
+                         label: 'Use Xft Fonts'
                          name: 'Button10'
-                         layout: (LayoutFrame 148 0.0 77 0 298 0 99 0)
+                         layout: (LayoutFrame 0 0.0 77 0 130 0 99 0)
                          activeHelpKey: changeToSTXLookXft
                          translateLabel: true
                          tabable: true
-                         model: changeToSTXLookXft
+                         model: changeToUseXft
                          enableChannel: hasXftFonts
                        )
+                      (ActionButtonSpec
+                         label: 'Normal Contrast'
+                         name: 'Button14'
+                         layout: (LayoutFrame 400 0.0 77 0 530 0 99 0)
+                         activeHelpKey: changeToNormalContrast
+                         translateLabel: true
+                         tabable: true
+                         model: changeToNormalContrast
+                       )
                       )
                     
                    )
@@ -609,7 +615,7 @@
 !FontSettingsApplication methodsFor:'actions'!
 
 basicReadFontSettings
-    |prefs readFont|
+    |prefs readFont sz lookIdx idx|
   
     self useXftFontsOnly value:(UserPreferences current useXftFontsOnly).
     
@@ -645,6 +651,24 @@
     self inputFieldDef value:(readFont value:#InputField value:EditField defaultFont).
     self tooltipDef value:(readFont value:#Tooltip value:ActiveHelpView defaultFont).
 
+    sz := TextView defaultFont size.
+    idx := self fontSizeListValues indexOf:sz.
+    idx ~~ 0 ifTrue:[
+        self fontSizeSelectionHolder value:idx.
+    ].
+    
+    lookIdx := nil.
+    (TextView defaultFont face = 'bold') ifTrue:[
+        lookIdx := (self lookListValues indexOf:#vage).
+    ] ifFalse:[
+        (TextView defaultFont isFixedWidth) ifTrue:[
+            lookIdx := (self lookListValues indexOf:#stx).
+        ] ifFalse:[    
+            lookIdx := (self lookListValues indexOf:#squeak).
+        ].
+    ].
+    self lookSelectionHolder value:lookIdx.
+    
     "Modified: / 10-10-2011 / 12:15:31 / Jan Vrany <jan.vrany@fit.cvut.cz>"
     "Created: / 06-02-2012 / 12:22:39 / cg"
 !
@@ -777,20 +801,42 @@
 
 changeTooltipFont
     self changeFontFor:self tooltipDef labelTitle:'Tooltops'.
+!
+
+fontSizeSelectionChanged
+    |idx sz|
+    
+    idx := self fontSizeSelectionHolder value.
+    sz := self fontSizeListValues at:idx ifAbsent:nil.
+    sz notNil ifTrue:[
+        self changeToFontsWithSize:sz
+    ].    
+!
+
+lookSelectionChanged
+    |idx look|
+    
+    idx := self lookSelectionHolder value.
+    look := self lookListValues at:idx ifAbsent:nil.
+    look notNil ifTrue:[
+        look == #stx ifTrue:[
+            self changeToSTXLook
+        ] ifFalse:[
+            look == #squeak ifTrue:[
+                self changeToSqueakLook
+            ] ifFalse:[
+                look == #vage ifTrue:[
+                    self changeToVisualAgeLook
+                ]
+            ]
+        ].    
+    ].    
 ! !
 
 !FontSettingsApplication methodsFor:'actions-common looks'!
 
 changeToBigFonts
-    |fixFont variableFont|
-
-"/    fixFont := (Font family:'courier cew' face:'bold' style:'roman' size:14).
-"/    variableFont := (Font family:'arial' face:'bold' style:'roman' size:14).
-    fixFont := (TextView defaultFont asSize:16).
-    variableFont := (Label defaultFont asSize:16).
-    self changeToFix:fixFont variable:variableFont.
-
-    "Created: / 06-02-2012 / 12:12:55 / cg"
+    self changeToFontsWithSize:16
 !
 
 changeToDefault
@@ -816,35 +862,71 @@
     "Created: / 06-02-2012 / 12:18:34 / cg"
 !
 
+changeToFontsWithSize:points
+    |f fixFont variableFont|
+
+    f := TextView defaultFont.
+    f := f asSize:points.
+    TextView defaultFont:f.
+
+    fixFont := (self textDef value "TextView defaultFont" asSize:points).
+    variableFont := (self labelDef value "Label defaultFont" asSize:points).
+    self changeToFix:fixFont variable:variableFont.
+!
+
 changeToHighContrast
     |fixFont variableFont|
 
-"/    fixFont := (Font family:'courier New' face:'bold' style:'roman' size:12).
-"/    variableFont := (Font family:'arial' face:'bold' style:'roman' size:12).
-    fixFont := (TextView defaultFont asSize:12) asFace:'bold'.
-    variableFont := (Label defaultFont asSize:12) asFace:'bold'.
+    fixFont := (self textDef value "TextView defaultFont") asFace:'bold'.
+    variableFont := (self labelDef value "Label defaultFont") asFace:'bold'.
     self changeToFix:fixFont variable:variableFont.
 
     "Created: / 06-02-2012 / 12:12:47 / cg"
 !
 
 changeToHugeFonts
+    self changeToFontsWithSize:18
+!
+
+changeToNormalContrast
     |fixFont variableFont|
 
-"/    fixFont := (Font family:'courier New' face:'bold' style:'roman' size:16).
-"/    variableFont := (Font family:'arial' face:'bold' style:'roman' size:16).
-    fixFont := (TextView defaultFont asSize:18).
-    variableFont := (Label defaultFont asSize:18).
+    fixFont := (self textDef value "TextView defaultFont") asFace:'medium'.
+    variableFont := (self labelDef value "Label defaultFont") asFace:'medium'.
     self changeToFix:fixFont variable:variableFont.
 
-    "Created: / 17-03-2012 / 09:06:18 / cg"
+    "Created: / 06-02-2012 / 12:12:47 / cg"
 !
 
 changeToSTXLook
+    self changeToSTXLookWithSize:(TextView defaultFont size)
+!
+
+changeToSTXLookSmall
+    |f|
+
+    f := TextView defaultFont.
+    f := f asSize:10.
+    TextView defaultFont:f.
+    
+    self changeToSTXLook.
+!
+
+changeToSTXLookSmallXft
+    |f|
+
+    f := TextView defaultFont.
+    f := f asSize:10.
+    TextView defaultFont:f.
+
+    self changeToSTXLookXft
+!
+
+changeToSTXLookWithSize:points
     |fixFont variableFont|
 
-    fixFont := (Font family:'courier new' face:'medium' style:'roman' size:(TextView defaultFont size)).
-    variableFont := (Font family:'arial' face:'medium' style:'roman' size:(TextView defaultFont size)).
+    fixFont := (Font family:'courier new' face:'medium' style:'roman' size:points).
+    variableFont := (Font family:'arial' face:'medium' style:'roman' size:points).
     self changeToFix:fixFont variable:variableFont.
 
     "Created: / 17-03-2012 / 11:23:16 / cg"
@@ -863,6 +945,10 @@
     self changeToFix:fixFont variable:variableFont.
 !
 
+changeToSmallFonts
+    self changeToFontsWithSize:10
+!
+
 changeToSqueakLook
     |variableFont|
 
@@ -872,6 +958,22 @@
     "Created: / 17-03-2012 / 11:22:59 / cg"
 !
 
+changeToUseXft
+
+    |fixFont variableFont|
+
+    Screen current supportsXFTFonts ifFalse:[
+        ^ self.
+    ].
+
+    TextView defaultFont:(XftFontDescription family:'Courier' face:'regular' style:'roman' size:(TextView defaultFont size)).
+    Label defaultFont:(XftFontDescription family:'Arial' face:'regular' style:'roman' size:(Label defaultFont size)).
+    
+    fixFont := (XftFontDescription family:'Courier' face:'regular' style:'roman' size:(TextView defaultFont size)).
+    variableFont := (XftFontDescription family:'Arial' face:'regular' style:'roman' size:(TextView defaultFont size)).
+    self changeToFix:fixFont variable:variableFont.
+!
+
 changeToVisualAgeLook
     |variableFont variableBoldFont|
 
@@ -922,6 +1024,34 @@
     ^ buttonsFontLabelHolder.
 !
 
+fontSizeLabelsAndValues
+    ^ #(
+        ('Default (12)' 12)
+        (nil nil)
+        ('Tiny (8)' 8)
+        ('Small (10)' 10)
+        ('Big (16)' 16)
+        ('Huge (18)' 18)
+        ('<keep as is>' nil)
+    )
+!
+
+fontSizeListLabels
+    ^ self fontSizeLabelsAndValues collect:[:each | each first].
+!
+
+fontSizeListValues
+    ^ self fontSizeLabelsAndValues collect:[:each | each second].
+!
+
+fontSizeSelectionHolder
+    fontSizeSelectionHolder isNil ifTrue:[
+        fontSizeSelectionHolder := nil asValue.
+        fontSizeSelectionHolder onChangeSend:#fontSizeSelectionChanged to:self.
+    ].
+    ^ fontSizeSelectionHolder
+!
+
 infoText
     ^ (self resources 
         string:'FONT_SETTINGS_INFO'
@@ -1003,6 +1133,31 @@
     ^ listsFontLabelHolder.
 !
 
+lookLabelsAndValues
+    ^ #(
+        ('ST/X Look (monospace font for code)' #stx)
+        ('Squeak Look (variable font for code)' #squeak)
+        ('V''Age Look (variable bold font for code)' #vage)
+        ('<keep as is>' nil)
+    )
+!
+
+lookListLabels
+    ^ self lookLabelsAndValues collect:[:each | each first].
+!
+
+lookListValues
+    ^ self lookLabelsAndValues collect:[:each | each second].
+!
+
+lookSelectionHolder
+    lookSelectionHolder isNil ifTrue:[
+        lookSelectionHolder := nil asValue.
+        lookSelectionHolder onChangeSend:#lookSelectionChanged to:self.
+    ].
+    ^ lookSelectionHolder
+!
+
 menuDef
     "return/create the 'menuDef' value holder (automatically generated)"