#UI_ENHANCEMENT by cg
authorClaus Gittinger <cg@exept.de>
Tue, 26 Apr 2016 11:36:10 +0200
changeset 16324 5f36246be507
parent 16322 1953cc62b7a6
child 16325 073884e3213d
#UI_ENHANCEMENT by cg class: AbstractSettingsApplication added: #discardChangesAndReadSettings fixed syntaxColor settings' discard action to restore original values.
AbstractSettingsApplication.st
--- a/AbstractSettingsApplication.st	Mon Apr 25 16:44:50 2016 +0200
+++ b/AbstractSettingsApplication.st	Tue Apr 26 11:36:10 2016 +0200
@@ -347,7 +347,7 @@
 		fullSelectorCheck syntaxColoring oldUserPreferences
 		syntaxFontSelector syntaxFonts syntaxElementList
 		syntaxElementSelection syntaxEmphasisList syntaxEmphasisSelection
-		emphasisDictionary resetListDictionary'
+		emphasisDictionary resetListDictionary changedSettings'
 	classVariableNames:''
 	poolDictionaries:''
 	privateIn:AbstractSettingsApplication
@@ -693,6 +693,10 @@
     "Created: / 14-10-2014 / 09:18:02 / Jan Vrany <jan.vrany@fit.cvut.cz>"
 !
 
+discardChangesAndReadSettings
+    self readSettings.
+!
+
 evaluateModified
     <resource: #obsolete>
     self obsoleteMethodWarning.
@@ -14615,17 +14619,17 @@
 
     <resource: #canvas>
 
-    ^
+    ^ 
     #(FullSpec
        name: windowSpec
-       window:
+       window: 
       (WindowSpec
          label: 'Code Format Settings'
          name: 'Code Format Settings'
          min: (Point 10 10)
          bounds: (Rectangle 0 0 613 685)
        )
-       component:
+       component: 
       (SpecCollection
          collection: (
           (VerticalPanelViewSpec
@@ -14635,7 +14639,7 @@
              verticalLayout: topSpaceFit
              horizontalSpace: 3
              verticalSpace: 3
-             component:
+             component: 
             (SpecCollection
                collection: (
                 (VerticalPanelViewSpec
@@ -14644,108 +14648,108 @@
                    verticalLayout: bottom
                    horizontalSpace: 3
                    verticalSpace: 3
-                   component:
+                   component: 
                   (SpecCollection
                      collection: (
                       (ViewSpec
                          name: 'Box1'
-                         component:
+                         component: 
                         (SpecCollection
                            collection: (
                             (CheckBoxSpec
                                label: 'Space around Temporaries'
                                name: 'CheckBox3'
-                               layout: (LayoutFrame 0 0 0 0 250 0 30 0)
+                               layout: (LayoutFrame 0 0 0 0 270 0 30 0)
                                model: spaceAroundTemporaries
                                translateLabel: true
                              )
                             (CheckBoxSpec
                                label: 'Blank line after local Var Declaration'
                                name: 'CheckBox4'
-                               layout: (LayoutFrame 250 0 0 0 0 1 30 0)
+                               layout: (LayoutFrame 270 0 0 0 0 1 30 0)
                                model: emptyLineAfterTemporaries
                                translateLabel: true
                              )
                             )
-
+                          
                          )
                          extent: (Point 613 30)
                        )
                       (ViewSpec
                          name: 'Box11'
-                         component:
+                         component: 
                         (SpecCollection
                            collection: (
                             (CheckBoxSpec
                                label: 'Space after ''^'''
                                name: 'CheckBox5'
-                               layout: (LayoutFrame 0 0 0 0 250 0 30 0)
+                               layout: (LayoutFrame 0 0 0 0 270 0 30 0)
                                model: spaceAfterReturnToken
                                translateLabel: true
                              )
                             (CheckBoxSpec
                                label: 'Space after '':'' in Keywords'
                                name: 'CheckBox6'
-                               layout: (LayoutFrame 250 0 0 0 -5 1 30 0)
+                               layout: (LayoutFrame 270 0 0 0 -5 1 30 0)
                                model: spaceAfterKeywordSelector
                                translateLabel: true
                              )
                             )
-
+                          
                          )
                          extent: (Point 613 30)
                        )
                       (ViewSpec
                          name: 'Box15'
-                         component:
+                         component: 
                         (SpecCollection
                            collection: (
                             (CheckBoxSpec
                                label: 'Space after ''['''
                                name: 'CheckBox9'
-                               layout: (LayoutFrame 0 0 0 0 250 0 30 0)
+                               layout: (LayoutFrame 0 0 0 0 270 0 30 0)
                                model: spaceAfterBlockStart
                                translateLabel: true
                              )
                             (CheckBoxSpec
                                label: 'Space before '']'''
                                name: 'CheckBox10'
-                               layout: (LayoutFrame 250 0 0 0 -5 1 30 0)
+                               layout: (LayoutFrame 270 0 0 0 -5 1 30 0)
                                model: spaceBeforeBlockEnd
                                translateLabel: true
                              )
                             )
-
+                          
                          )
                          extent: (Point 613 30)
                        )
                       (ViewSpec
                          name: 'Box12'
-                         component:
+                         component: 
                         (SpecCollection
                            collection: (
                             (CheckBoxSpec
                                label: 'C-Style Blocks'
                                name: 'CheckBox8'
-                               layout: (LayoutFrame 0 0 0 0 250 0 30 0)
+                               layout: (LayoutFrame 0 0 0 0 270 0 30 0)
                                model: cStyleBlocks
                                translateLabel: true
                              )
                             (CheckBoxSpec
                                label: 'Block Args on new Line'
                                name: 'CheckBox7'
-                               layout: (LayoutFrame 250 0 0 0 -5 1 30 0)
+                               layout: (LayoutFrame 270 0 0 0 -5 1 30 0)
                                model: blockArgumentsOnNewLine
                                translateLabel: true
                              )
                             )
-
+                          
                          )
                          extent: (Point 613 30)
                        )
                       (ViewSpec
                          name: 'Box13'
-                         component:
+                         component: 
                         (SpecCollection
                            collection: (
                             (LabelSpec
@@ -14766,13 +14770,13 @@
                                acceptOnPointerLeave: true
                              )
                             )
-
+                          
                          )
                          extent: (Point 613 30)
                        )
                       (ViewSpec
                          name: 'Box16'
-                         component:
+                         component: 
                         (SpecCollection
                            collection: (
                             (LabelSpec
@@ -14793,7 +14797,7 @@
                                acceptOnPointerLeave: true
                              )
                             )
-
+                          
                          )
                          extent: (Point 613 30)
                        )
@@ -14803,7 +14807,7 @@
                          verticalLayout: bottom
                          horizontalSpace: 3
                          verticalSpace: 3
-                         component:
+                         component: 
                         (SpecCollection
                            collection: (
                             (ActionButtonSpec
@@ -14812,7 +14816,7 @@
                                translateLabel: true
                                tabable: true
                                model: resetToStxDefault
-                               extent: (Point 302 22)
+                               extent: (Point 300 22)
                              )
                             (ActionButtonSpec
                                label: 'Reset to RefactoryBrowser Default'
@@ -14820,15 +14824,15 @@
                                translateLabel: true
                                tabable: true
                                model: resetToRBDefault
-                               extent: (Point 302 22)
-                             )
-                            )
-
+                               extent: (Point 301 22)
+                             )
+                            )
+                          
                          )
                          extent: (Point 613 30)
                        )
                       )
-
+                    
                    )
                    extent: (Point 613 180)
                  )
@@ -14838,7 +14842,7 @@
                  )
                 (ViewSpec
                    name: 'Box14'
-                   component:
+                   component: 
                   (SpecCollection
                      collection: (
                       (LabelSpec
@@ -14859,12 +14863,12 @@
                          postBuildCallback: postBuildTextEditor:
                        )
                       )
-
+                    
                    )
                    extent: (Point 613 453)
                  )
                 )
-
+              
              )
            )
           (CheckBoxSpec
@@ -14875,7 +14879,7 @@
              translateLabel: true
            )
           )
-
+        
        )
      )
 ! !
@@ -17304,25 +17308,30 @@
 !AbstractSettingsApplication::SyntaxColorSettingsAppl class methodsFor:'defaults'!
 
 emphasisList
-
-    ^ #(
-        #normal
-        #underline
-        #'red underline'
-        #underwave
-        #'red underwave'
-        #bold
-        #boldUnderline
-        #'bold+red underline'
-        #boldUnderwave
-        #'bold+red underwave'
-        #italic
-        #italicUnderline
-        #'italic+red underline'
-        #italicUnderwave
-        #'italic+red underwave'
-        #reverse
-    )
+    ^ self emphasisMappingList collect:#first
+!
+
+emphasisMappingList
+    "self emphasisMappingList"
+    
+    ^ {
+        #( #'normal'                 #normal ) .
+        #( #'underline'              #underline) .
+         { 'red underline' .        { #underline . (#underlineColor->Color red) } } .
+        #( #'underwave'              #underwave) .
+         { 'red underwave' .        { #underwave . (#underlineColor->Color red) } } .
+        #( #'bold'                   #bold ) .
+        #( 'bold + underline'       #(bold underline) ) .
+         { 'bold + red underline' . { #bold . #underline . (#underlineColor->Color red) } } .  
+        #( 'bold + underwave'       #(bold underwave) ) .
+         { 'bold + red underwave' . { #bold . #underwave . (#underlineColor->Color red) } } .
+        #( #'italic'                 #italic ) .
+        #( 'italic + underline'     #(italic underline) ) .     
+         { 'italic + red underline'. { #italic . #underline . (#underlineColor->Color red) } } .    
+        #( 'italic + underwave'     #(italic underwave) ) . 
+         { 'italic + red underwave'. { #italic . #underwave . (#underlineColor->Color red) } } . 
+        #( #'reverse'                #reverse )
+    }
 !
 
 exampleText
@@ -17344,33 +17353,12 @@
     UnknonVar := 1.           "/ another bad variable
     "self bar:methodVar.  detect commented code easily"
     1 to:5 do:[:i | self at:i + 1].
+    [:blockArg | blockArg + 1].
     Transcript showCR:''some string'' , #someSymbol.
     ^ self.
 '.
 
     "Modified: / 14-02-2012 / 10:18:48 / cg"
-!
-
-fontList
-
-    ^ #(
-        normal
-        underline
-        #'red underline'
-        underwave
-        #'red underwave'
-        bold
-        boldUnderline
-        #'bold+red underline'
-        boldUnderwave
-        #'bold+red underwave'
-        italic
-        italicUnderline
-        #'italic+red underline'
-        italicUnderwave
-        #'italic+red underwave'
-        reverse
-    )
 ! !
 
 !AbstractSettingsApplication::SyntaxColorSettingsAppl class methodsFor:'help specs'!
@@ -17690,7 +17678,7 @@
 !
 
 basicReadSettings
-    |colorList resetListLoc|
+    |elementColorList elementList resetListLoc|
 
     oldUserPreferences notNil ifTrue:[
         (UserPreferences reset; current) addAll:oldUserPreferences
@@ -17699,14 +17687,19 @@
     super basicReadSettings.
 
     oldUserPreferences := currentUserPrefs copy.
-    colorList := UserPreferences syntaxColorNames.
+    elementColorList := UserPreferences syntaxColorNames.
+    elementList := elementColorList 
+                        collect:[:each | 
+                            (each endsWith:' Color') 
+                                ifTrue:[ each copyButLast:' Color' size ]
+                                ifFalse:[each]].
+                                
     resetListLoc := currentUserPrefs listOfPredefinedSyntaxColoringSchemes
-                collect:[:entry | entry second].
+                        collect:[:entry | entry second].
     self resetList value:resetListLoc.
     self resetListSelection value:resetListLoc first.
-    self syntaxEmphasisList value:self class emphasisList.
-    self syntaxElementList value:colorList.
-    self syntaxElementSelection value:(colorList at:1).
+    self syntaxElementList value:elementList.
+    self syntaxElementSelection value:(elementList at:1).
 !
 
 basicSaveSettings
@@ -17715,6 +17708,20 @@
     super basicSaveSettings.
 !
 
+discardChangesAndReadSettings
+    |prefs|
+
+    "/ UserPreferences reset.
+    prefs := currentUserPrefs. "/ UserPreferences current.
+    changedSettings keysAndValuesDo:[:k :v |
+        prefs at:k put:v
+    ].    
+    changedSettings := Dictionary new.            
+    "/ self flyByHelpSettingChanged.    "/ reinstall
+    self recolor.
+    super discardChangesAndReadSettings.
+!
+
 recolor
     |text dummyClass|
 
@@ -17854,26 +17861,38 @@
 !
 
 syntaxColorChanged
-    currentUserPrefs at:(self syntaxColorSelector) put:(self syntaxColor value).
+    |prefKey|
+    
+    prefKey := self syntaxColorSelector.
+    (changedSettings includesKey:prefKey) ifFalse:[
+        "/ remember previous value
+        changedSettings at:prefKey put:(currentUserPrefs at:prefKey ifAbsent:nil).
+    ].    
+    currentUserPrefs at:prefKey put:(self syntaxColor value).
     self recolor.
     self updateModifiedChannel
 !
 
 syntaxElementSelectionChanged
-
     | syntaxEmphasisValue |
 
     self syntaxColor value:(currentUserPrefs perform:(self syntaxColorSelector)).
     syntaxEmphasisValue := (currentUserPrefs perform:(self syntaxEmphasisSelector)).
     self syntaxEmphasisSelection value:(self getEmphasis:syntaxEmphasisValue).
-    self recolor.
+    "/ self recolor.
 !
 
 syntaxEmphasisSelectionChanged
-    |em|
-
-    em := self getEmphasis:self syntaxEmphasisSelection value.
-    currentUserPrefs at:(self syntaxEmphasisSelector) put:em.
+    |em prefKey|
+
+    prefKey := self syntaxEmphasisSelector.
+    (changedSettings includesKey:prefKey) ifFalse:[
+        "/ remember previous value
+        changedSettings at:prefKey put:(currentUserPrefs at:prefKey ifAbsent:nil).
+    ].
+    em := self getEmphasis:(self syntaxEmphasisSelection value ? 'normal') string.
+    currentUserPrefs at:prefKey put:em.
+
     self recolor.
     self updateModifiedChannel
 !
@@ -17911,6 +17930,13 @@
     self initializeEmphasisDictionary.
     super initialize.
 
+    self syntaxEmphasisList 
+        value:(self class emphasisList 
+                collect:[:lbl |
+                    lbl emphasizeAllWith:( self getEmphasis:lbl )
+                ]).
+
+    changedSettings := Dictionary new.            
     resetListDictionary := Dictionary new.
     currentUserPrefs listOfPredefinedSyntaxColoringSchemes do:[:entry |
         resetListDictionary at:(entry at:1) put:(entry at:2)
@@ -17920,38 +17946,13 @@
 initializeEmphasisDictionary
 
     emphasisDictionary := Dictionary new.
-    self class emphasisList do:[ : entry |
-        entry == #'red underline' ifTrue:[
-            emphasisDictionary at:entry put:(Array with:#underline with:(#underlineColor->Color red)).
-            emphasisDictionary at:(Array with:#underline with:(#underlineColor->Color red)) put:entry.
-        ] ifFalse:[
-            entry == #'red underwave' ifTrue:[
-                emphasisDictionary at:entry put:(Array with:#underwave with:(#underlineColor->Color red)).
-                emphasisDictionary at:(Array with:#underwave with:(#underlineColor->Color red)) put:entry.
-            ] ifFalse:[
-                entry == #'bold+red underline' ifTrue:[
-                    emphasisDictionary at:entry put:(Array with:#bold with:#underline with:(#underlineColor->Color red)).
-                    emphasisDictionary at:(Array with:#bold with:#underline with:(#underlineColor->Color red)) put:entry.
-                ] ifFalse:[
-                    entry == #'bold+red underwave' ifTrue:[
-                        emphasisDictionary at:entry put:(Array with:#bold with:#underwave with:(#underlineColor->Color red)).
-                        emphasisDictionary at:(Array with:#bold with:#underwave with:(#underlineColor->Color red)) put:entry.
-                    ] ifFalse:[
-                        entry == #'italic+red underline' ifTrue:[
-                            emphasisDictionary at:entry put:(Array with:#italic with:#underline with:(#underlineColor->Color red)).
-                            emphasisDictionary at:(Array with:#italic with:#underline with:(#underlineColor->Color red)) put:entry.
-                        ] ifFalse:[
-                            entry == #'italic+red underwave' ifTrue:[
-                                emphasisDictionary at:entry put:(Array with:#italic with:#underwave with:(#underlineColor->Color red)).
-                                emphasisDictionary at:(Array with:#italic with:#underwave with:(#underlineColor->Color red)) put:entry.
-                            ] ifFalse:[
-                                emphasisDictionary at:entry put:entry
-                            ]
-                        ]
-                    ]
-                ]
-            ]
-        ]
+    self class emphasisMappingList do:[ :mapping |
+        |name emphasis|
+        
+        name := mapping first.
+        emphasis := mapping second.
+        emphasisDictionary at:name put:emphasis.
+        emphasisDictionary at:emphasis put:name.
     ].
 !
 
@@ -17991,7 +17992,13 @@
 !
 
 syntaxColorSelector
-    ^ (self syntaxColorSelectorForElement:self syntaxElementSelection value)
+    |elementName key|
+    
+    elementName := key := self syntaxElementSelection value.
+    (elementName endsWith:' Color') ifFalse:[
+        key := elementName,' Color'.
+    ].    
+    ^ (self syntaxColorSelectorForElement:key)
 !
 
 syntaxColorSelectorForElement:aSyntaxElementsName
@@ -18001,8 +18008,11 @@
 !
 
 syntaxEmphasisSelector
-
-    ^ self syntaxEmphasisSelectorForElement:(self syntaxElementSelection value)
+    |elementName key|
+
+    elementName := self syntaxElementSelection value.
+    key := elementName,' Color'.
+    ^ self syntaxEmphasisSelectorForElement:key
 !
 
 syntaxEmphasisSelectorForElement:aSyntaxElementsName