You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by pa...@apache.org on 2019/06/11 12:28:37 UTC

[groovy] 03/04: Let the loop mode length be configurable from preferences

This is an automated email from the ASF dual-hosted git repository.

paulk pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 33c02e5ae73819c919df88345e1cab576c2de9f1
Author: Jacob Aae Mikkelsen <gi...@grydeske.dk>
AuthorDate: Sun Jun 9 15:32:52 2019 +0200

    Let the loop mode length be configurable from preferences
---
 .../src/main/groovy/groovy/console/ui/Console.groovy    |  3 ++-
 .../groovy/groovy/console/ui/ConsolePreferences.groovy  | 17 +++++++++++++++++
 .../main/resources/groovy/console/ui/Console.properties |  1 +
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy
index 32f42e9..46b63c1 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/Console.groovy
@@ -1290,7 +1290,8 @@ class Console implements CaretListener, HyperlinkListener, ComponentListener, Fo
                 interruptAction.enabled = false
                 systemOutInterceptor.removeConsoleId()
                 if( loopMode ) {
-                    Timer timer = new Timer(1000, {
+                    int delay = prefs.getInt('loopModeLength', ConsolePreferences.DEFAULT_LOOP_MODE_LENGTH_MILLIS)
+                    Timer timer = new Timer(delay, {
                         if( inputAreaContentHash == inputArea.getText().hashCode() ) {
                             runScriptImpl(selected)
                         }
diff --git a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ConsolePreferences.groovy b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ConsolePreferences.groovy
index e2e24b2..bf76d53 100644
--- a/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ConsolePreferences.groovy
+++ b/subprojects/groovy-console/src/main/groovy/groovy/console/ui/ConsolePreferences.groovy
@@ -30,10 +30,14 @@ class ConsolePreferences {
 
     // Default maximum number of characters to show on console at any time
     static int DEFAULT_MAX_OUTPUT_CHARS = 20000
+    static int DEFAULT_LOOP_MODE_LENGTH_MILLIS = 1000
 
     @Bindable
     int maxOutputChars
 
+    @Bindable
+    int loopModeLength
+
     private final console
     private final MessageSource T
 
@@ -45,6 +49,7 @@ class ConsolePreferences {
         T = new MessageSource(Console)
 
         maxOutputChars = console.loadMaxOutputChars()
+        loopModeLength = console.prefs.getInt('loopModeLength', DEFAULT_LOOP_MODE_LENGTH_MILLIS)
         console.maxOutputChars = maxOutputChars
     }
 
@@ -78,6 +83,16 @@ class ConsolePreferences {
                     }
 
                     hbox {
+                        label "${T['prefs.loop.mode.title']}:"
+
+                        formattedTextField value: loopModeLength, id: 'txtLoopModeLength',
+                                text:
+                        bind(target: this, targetProperty: 'loopModeLength',
+                                validator: this.&isInteger, converter: Integer.&parseInt),
+                        columns: 8
+                    }
+
+                    hbox {
                         checkBox T['prefs.output.file'], id: 'outputFileCheckBox', selected: false
                         hglue()
                         label T['prefs.output.file.name'], id: 'outputFileName',
@@ -119,10 +134,12 @@ class ConsolePreferences {
 
     private void onReset(EventObject event) {
         console.swing.txtMaxOutputChars.text = DEFAULT_MAX_OUTPUT_CHARS
+        console.swing.txtLoopModeLength.text = DEFAULT_LOOP_MODE_LENGTH_MILLIS
     }
 
     private void onClose(EventObject event) {
         console.prefs.putInt('maxOutputChars', maxOutputChars)
+        console.prefs.putInt('loopModeLength', loopModeLength)
         // For backwards compatibility 'maxOutputChars' remains defined in the Console class
         // and so we update the value to keep it in sync.
         if (maxOutputChars != console.maxOutputChars) {
diff --git a/subprojects/groovy-console/src/main/resources/groovy/console/ui/Console.properties b/subprojects/groovy-console/src/main/resources/groovy/console/ui/Console.properties
index 1ca57f8..cc56d57 100644
--- a/subprojects/groovy-console/src/main/resources/groovy/console/ui/Console.properties
+++ b/subprojects/groovy-console/src/main/resources/groovy/console/ui/Console.properties
@@ -40,6 +40,7 @@ cli.info.version=GroovyConsole {0}
 prefs.dialog.title=Preferences
 prefs.output.settings.title=Output Settings
 prefs.max.characters.output=Maximum Characters to Output
+prefs.loop.mode.title=Loop mode length (millis)
 prefs.reset.defaults=Reset To Defaults
 prefs.output.file=Output to file
 prefs.output.file.select=Select