]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Fix: When a proposed completion is selected in a text field, the autosave is not...
authormiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 11 Sep 2012 06:10:47 +0000 (06:10 +0000)
committermiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 11 Sep 2012 06:10:47 +0000 (06:10 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@25709 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionField.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionFieldConfiguration.java

index 58fb0eb0e21d7c6a10175c767a256f17808d8069..bf328c09ea8ae3eb593fa7f360d6fc0e127e3482 100644 (file)
@@ -620,11 +620,22 @@ public class EquationTab extends LabelPropertyTabContributor implements Widget {
 \r
                        @Override\r
                        public void verifyKey(VerifyEvent event) {\r
-                               if(event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) {\r
-                                       if((event.stateMask & SWT.SHIFT) == 0) {\r
-                                               event.doit = false;\r
-                                               ((StyledText)event.widget).getParent().forceFocus();\r
-                                               expressionWidget.save();\r
+                               \r
+                               // Check if some of the expression fields has active completion assistant\r
+                               boolean isAnyAssistSessionActive = false;\r
+                               for (int i = 0; i < expressionWidget.getExpression().getExpressionFields().size(); ++i) {\r
+                                       if (expressionWidget.getExpression().getExpressionFields().get(i).isAssistSessionActive()) {\r
+                                               isAnyAssistSessionActive = true;\r
+                                               break;\r
+                                       }\r
+                               }\r
+                               if (!isAnyAssistSessionActive) {\r
+                                       if(event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) {\r
+                                               if((event.stateMask & SWT.SHIFT) == 0) {\r
+                                                       event.doit = false;\r
+                                                       ((StyledText)event.widget).getParent().forceFocus();\r
+                                                       expressionWidget.save();\r
+                                               }\r
                                        }\r
                                }\r
                        }\r
index 696c960a182c2592a2689eb75b29050a3f934314..7b79a518f632a135cbe6583f871868d67b5a6054 100644 (file)
@@ -69,6 +69,8 @@ public class ExpressionField extends Composite {
 \r
     IAnnotationAccess annotationAccess = new DefaultMarkerAnnotationAccess();\r
 \r
+    ExpressionFieldConfiguration expressionFieldConfiguration;\r
+    \r
     /**\r
      * Create a new expression field\r
      * @param parent\r
@@ -98,7 +100,8 @@ public class ExpressionField extends Composite {
                 styles);\r
         \r
         // Configuration for color management\r
-        _sourceViewer.configure(new ExpressionFieldConfiguration(cManager, allowedVariables, allowFunctions));\r
+        expressionFieldConfiguration = new ExpressionFieldConfiguration(cManager, allowedVariables, allowFunctions);\r
+        _sourceViewer.configure(expressionFieldConfiguration);\r
         AnnotationPainter painter = new AnnotationPainter(_sourceViewer, annotationAccess);\r
         _sourceViewer.addPainter(painter);\r
 \r
@@ -174,6 +177,7 @@ public class ExpressionField extends Composite {
                        }\r
 \r
                });\r
+        \r
     }\r
 \r
     /**\r
@@ -183,6 +187,10 @@ public class ExpressionField extends Composite {
     public SourceViewer getSourceViewer() {\r
         return this._sourceViewer;\r
     }\r
+    \r
+       public boolean isAssistSessionActive() {\r
+               return expressionFieldConfiguration.isAssistSessionActive();\r
+       }\r
 \r
     /**\r
      * Sets missing link annotations to given positions\r
index 11c82ee1d03bd4f07dec2d085b5d7f2d6addf1be..5521aa2d3348db328bbf38c2f73b4ed8c2fe2417 100644 (file)
@@ -15,7 +15,10 @@ import org.eclipse.jface.text.DefaultTextHover;
 import org.eclipse.jface.text.IDocument;\r
 import org.eclipse.jface.text.ITextHover;\r
 import org.eclipse.jface.text.TextAttribute;\r
+import org.eclipse.jface.text.contentassist.ContentAssistEvent;\r
 import org.eclipse.jface.text.contentassist.ContentAssistant;\r
+import org.eclipse.jface.text.contentassist.ICompletionListener;\r
+import org.eclipse.jface.text.contentassist.ICompletionProposal;\r
 import org.eclipse.jface.text.contentassist.IContentAssistant;\r
 import org.eclipse.jface.text.presentation.IPresentationReconciler;\r
 import org.eclipse.jface.text.presentation.PresentationReconciler;\r
@@ -38,16 +41,25 @@ import org.simantics.sysdyn.ui.utils.VariableNameUtils;
 \r
 public class ExpressionFieldConfiguration extends SourceViewerConfiguration {\r
 \r
-\r
+       private final long WAIT_BEFORE_STATUS_CHANGE = 100;\r
+       \r
        ColorManager colorManager;\r
        Table allowedVariables;\r
-       Boolean allowFunctions;\r
+       boolean allowFunctions;\r
+       boolean assistSessionActive; \r
+       CompletionProcessor completionProcessor;\r
        \r
        public ExpressionFieldConfiguration(ColorManager colorManager, Table allowedVariables, boolean allowFunctions) {\r
                super();\r
                this.colorManager = colorManager;\r
                this.allowedVariables = allowedVariables;\r
                this.allowFunctions = allowFunctions;\r
+               this.assistSessionActive = false;\r
+               this.completionProcessor = null;\r
+       }\r
+       \r
+       public boolean isAssistSessionActive() {\r
+               return assistSessionActive;\r
        }\r
        \r
        public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) {\r
@@ -122,13 +134,48 @@ public class ExpressionFieldConfiguration extends SourceViewerConfiguration {
        @Override\r
        public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) {\r
                ContentAssistant assistant = new ContentAssistant();\r
-               assistant.setContentAssistProcessor(new CompletionProcessor(allowedVariables, allowFunctions), "__dftl_partition_content_type");\r
+               completionProcessor = new CompletionProcessor(allowedVariables, allowFunctions);\r
+               assistant.setContentAssistProcessor(completionProcessor, "__dftl_partition_content_type");\r
                assistant.enableAutoActivation(true);\r
                assistant.enableAutoInsert(true);\r
                assistant.setAutoActivationDelay(0);\r
                assistant.setProposalPopupOrientation(IContentAssistant.PROPOSAL_OVERLAY);\r
                assistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE);\r
+               assistant.addCompletionListener(new CompletionListener());\r
                return assistant;\r
        }\r
+       \r
+       private class CompletionListener implements ICompletionListener {\r
+\r
+               @Override\r
+               public void assistSessionStarted(ContentAssistEvent event) {\r
+                       if (event.processor.equals(completionProcessor)) {\r
+                               assistSessionActive = true;\r
+                       }\r
+               }\r
 \r
+               @Override\r
+               public void assistSessionEnded(ContentAssistEvent event) {\r
+                       if (event.processor.equals(completionProcessor)) {\r
+                               Thread waitBeforeStateChange = new Thread() {\r
+                                       public void run() {\r
+                                               try {\r
+                                                       sleep(WAIT_BEFORE_STATUS_CHANGE);\r
+                                                       assistSessionActive = false;\r
+                                               } catch (InterruptedException e) {\r
+                                                       assistSessionActive = false;\r
+                                               }\r
+                                       }\r
+                               };\r
+                               waitBeforeStateChange.start();\r
+                       }\r
+               }\r
+\r
+               @Override\r
+               public void selectionChanged(ICompletionProposal proposal,\r
+                               boolean smartToggle) {\r
+               }\r
+               \r
+       }\r
+       \r
 }\r