UIDefaultsLoader: changed processing of "globals" so that they are first added to the properties table (instead of directly modifying defaults table), which is then parsed and copied to defaults table

this has the advantage that they can be referenced in other values, which did not work before (because they only existed in `defaults` table)

used for Tree.textForeground
verified with UIDefaultsDump that there are no side effects
This commit is contained in:
Karl Tauber
2020-09-12 18:13:34 +02:00
parent ecb94bac6d
commit 1697735162
4 changed files with 20 additions and 25 deletions

View File

@@ -26,9 +26,11 @@ import java.io.InputStream;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Locale; import java.util.Locale;
import java.util.Map; import java.util.Map;
import java.util.Map.Entry;
import java.util.Properties; import java.util.Properties;
import java.util.function.Function; import java.util.function.Function;
import java.util.logging.Level; import java.util.logging.Level;
@@ -203,37 +205,33 @@ class UIDefaultsLoader
return resolveValue( value, propertiesGetter ); return resolveValue( value, propertiesGetter );
}; };
// get globals, which override all other defaults that end with same suffix // get (and remove) globals, which override all other defaults that end with same suffix
HashMap<String, Object> globals = new HashMap<>(); HashMap<String, String> globals = new HashMap<>();
for( Map.Entry<Object, Object> e : properties.entrySet() ) { Iterator<Entry<Object, Object>> it = properties.entrySet().iterator();
while( it.hasNext() ) {
Entry<Object, Object> e = it.next();
String key = (String) e.getKey(); String key = (String) e.getKey();
if( !key.startsWith( GLOBAL_PREFIX ) ) if( key.startsWith( GLOBAL_PREFIX ) ) {
continue; globals.put( key.substring( GLOBAL_PREFIX.length() ), (String) e.getValue() );
it.remove();
String value = resolveValue( (String) e.getValue(), propertiesGetter );
try {
globals.put( key.substring( GLOBAL_PREFIX.length() ),
parseValue( key, value, null, resolver, addonClassLoaders ) );
} catch( RuntimeException ex ) {
logParseError( Level.SEVERE, key, value, ex );
} }
} }
// override UI defaults with globals // override UI defaults with globals
for( Object key : defaults.keySet() ) { for( Object okey : defaults.keySet() ) {
if( key instanceof String && ((String)key).contains( "." ) ) { if( okey instanceof String && ((String)okey).contains( "." ) ) {
String skey = (String) key; String key = (String) okey;
String globalKey = skey.substring( skey.lastIndexOf( '.' ) + 1 ); String globalKey = key.substring( key.lastIndexOf( '.' ) + 1 );
Object globalValue = globals.get( globalKey ); String globalValue = globals.get( globalKey );
if( globalValue != null ) if( globalValue != null && !properties.containsKey( key ) )
defaults.put( key, globalValue ); properties.put( key, globalValue );
} }
} }
// add non-global properties to UI defaults // parse and add properties to UI defaults
for( Map.Entry<Object, Object> e : properties.entrySet() ) { for( Map.Entry<Object, Object> e : properties.entrySet() ) {
String key = (String) e.getKey(); String key = (String) e.getKey();
if( key.startsWith( VARIABLE_PREFIX ) || key.startsWith( GLOBAL_PREFIX ) ) if( key.startsWith( VARIABLE_PREFIX ) )
continue; continue;
String value = resolveValue( (String) e.getValue(), propertiesGetter ); String value = resolveValue( (String) e.getValue(), propertiesGetter );

View File

@@ -46,8 +46,6 @@
*.background=@background *.background=@background
*.foreground=@foreground *.foreground=@foreground
*.textBackground=@background
*.textForeground=@foreground
*.caretForeground=@foreground *.caretForeground=@foreground
*.inactiveBackground=@background *.inactiveBackground=@background
*.inactiveForeground=@foreground *.inactiveForeground=@foreground

View File

@@ -671,6 +671,7 @@ Tree.editorBorder=1,1,1,1,@cellFocusColor
Tree.selectionInactiveBackground=@selectionInactiveBackground Tree.selectionInactiveBackground=@selectionInactiveBackground
Tree.selectionInactiveForeground=@selectionInactiveForeground Tree.selectionInactiveForeground=@selectionInactiveForeground
Tree.textBackground=$Tree.background Tree.textBackground=$Tree.background
Tree.textForeground=$Tree.foreground
Tree.selectionBorderColor=@cellFocusColor Tree.selectionBorderColor=@cellFocusColor
Tree.dropCellBackground=@dropCellBackground Tree.dropCellBackground=@dropCellBackground
Tree.dropCellForeground=@dropCellForeground Tree.dropCellForeground=@dropCellForeground

View File

@@ -46,8 +46,6 @@
*.background=@background *.background=@background
*.foreground=@foreground *.foreground=@foreground
*.textBackground=#ccc
*.textForeground=@foreground
*.caretForeground=@foreground *.caretForeground=@foreground
*.inactiveBackground=@background *.inactiveBackground=@background
*.inactiveForeground=@disabledText *.inactiveForeground=@disabledText