Theme Editor:

- auto-activate completion popup when '$' is pressed
- use keys auto-complete in value if value contains '$'
- more fine grained detection what completion provider should be used
This commit is contained in:
Karl Tauber
2020-07-08 18:07:37 +02:00
parent 1b974379c8
commit 990da2b412
2 changed files with 55 additions and 9 deletions

View File

@@ -71,6 +71,21 @@ class FlatCompletionProvider
return (provider != null) ? provider.getCompletions( comp ) : null; return (provider != null) ? provider.getCompletions( comp ) : null;
} }
@Override
public boolean isAutoActivateOkay( JTextComponent tc ) {
int caretPosition = tc.getCaretPosition();
if( caretPosition <= 0 )
return false;
try {
char ch = tc.getText( caretPosition - 1, 1 ).charAt( 0 );
return ch == '$';
} catch( BadLocationException | IndexOutOfBoundsException ex ) {
// ignore
return false;
}
}
private CompletionProvider getProviderFor( JTextComponent comp ) { private CompletionProvider getProviderFor( JTextComponent comp ) {
RSyntaxTextArea rsta = (RSyntaxTextArea) comp; RSyntaxTextArea rsta = (RSyntaxTextArea) comp;
try { try {
@@ -90,21 +105,45 @@ class FlatCompletionProvider
if( lineBeforeCaret.trim().startsWith( "#" ) ) if( lineBeforeCaret.trim().startsWith( "#" ) )
return null; return null;
if( lineBeforeCaret.indexOf( '=' ) < 0 ) { // key
if( keyProvider == null ) if( lineBeforeCaret.indexOf( '=' ) < 0 )
keyProvider = KeyCompletionProvider.getInstance(); return getKeyProvider();
return keyProvider;
} else { // value
if( valueProvider == null ) for( int i = lineBeforeCaret.length() - 1; i >= 0; i-- ) {
valueProvider = new ValueCompletionProvider(); switch( lineBeforeCaret.charAt( i ) ) {
return valueProvider; case '=':
case '(':
return getValueProvider();
case '$':
return getKeyProvider();
case ' ':
case '\t':
return null;
} }
}
return null;
} catch( BadLocationException ex ) { } catch( BadLocationException ex ) {
// ignore // ignore
return null; return null;
} }
} }
private CompletionProvider getKeyProvider() {
if( keyProvider == null )
keyProvider = KeyCompletionProvider.getInstance();
return keyProvider;
}
private CompletionProvider getValueProvider() {
if( valueProvider == null )
valueProvider = new ValueCompletionProvider();
return valueProvider;
}
//---- class KeyCompletionProvider ---------------------------------------- //---- class KeyCompletionProvider ----------------------------------------
private static class KeyCompletionProvider private static class KeyCompletionProvider
@@ -205,7 +244,13 @@ class FlatCompletionProvider
params.add( param ); params.add( param );
} }
FunctionCompletion f = new FunctionCompletion( this, name, null ); FunctionCompletion f = new FunctionCompletion( this, name, null ) {
@Override
public String toString() {
return getDefinitionString().replace( "(", " (" );
}
};
f.setParams( params ); f.setParams( params );
addCompletion( f ); addCompletion( f );
} }

View File

@@ -79,6 +79,7 @@ class FlatThemeEditorPane
// autocomplete // autocomplete
CompletionProvider provider = new FlatCompletionProvider(); CompletionProvider provider = new FlatCompletionProvider();
AutoCompletion ac = new AutoCompletion( provider ); AutoCompletion ac = new AutoCompletion( provider );
ac.setAutoActivationEnabled( true );
ac.setParameterAssistanceEnabled( true ); ac.setParameterAssistanceEnabled( true );
ac.setChoicesWindowSize( UIScale.scale( 300 ), UIScale.scale( 400 ) ); ac.setChoicesWindowSize( UIScale.scale( 300 ), UIScale.scale( 400 ) );
ac.setDescriptionWindowSize( UIScale.scale( 300 ), UIScale.scale( 400 ) ); ac.setDescriptionWindowSize( UIScale.scale( 300 ), UIScale.scale( 400 ) );