From 0ba62cf14a45a56f6fe5069115d27b51ddcb93f5 Mon Sep 17 00:00:00 2001 From: miettinen Date: Tue, 11 Sep 2012 06:10:47 +0000 Subject: [PATCH] Fix: When a proposed completion is selected in a text field, the autosave is not initiated when the selection is accepted with enter. (refs #2969) git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@25709 ac1ea38d-2e2b-0410-8846-a27921b304fc --- .../sysdyn/ui/properties/EquationTab.java | 21 ++++++-- .../widgets/expressions/ExpressionField.java | 10 +++- .../ExpressionFieldConfiguration.java | 53 +++++++++++++++++-- 3 files changed, 75 insertions(+), 9 deletions(-) diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java index 58fb0eb0..bf328c09 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/EquationTab.java @@ -620,11 +620,22 @@ public class EquationTab extends LabelPropertyTabContributor implements Widget { @Override public void verifyKey(VerifyEvent event) { - if(event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) { - if((event.stateMask & SWT.SHIFT) == 0) { - event.doit = false; - ((StyledText)event.widget).getParent().forceFocus(); - expressionWidget.save(); + + // Check if some of the expression fields has active completion assistant + boolean isAnyAssistSessionActive = false; + for (int i = 0; i < expressionWidget.getExpression().getExpressionFields().size(); ++i) { + if (expressionWidget.getExpression().getExpressionFields().get(i).isAssistSessionActive()) { + isAnyAssistSessionActive = true; + break; + } + } + if (!isAnyAssistSessionActive) { + if(event.keyCode == SWT.CR || event.keyCode == SWT.KEYPAD_CR) { + if((event.stateMask & SWT.SHIFT) == 0) { + event.doit = false; + ((StyledText)event.widget).getParent().forceFocus(); + expressionWidget.save(); + } } } } diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionField.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionField.java index 696c960a..7b79a518 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionField.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionField.java @@ -69,6 +69,8 @@ public class ExpressionField extends Composite { IAnnotationAccess annotationAccess = new DefaultMarkerAnnotationAccess(); + ExpressionFieldConfiguration expressionFieldConfiguration; + /** * Create a new expression field * @param parent @@ -98,7 +100,8 @@ public class ExpressionField extends Composite { styles); // Configuration for color management - _sourceViewer.configure(new ExpressionFieldConfiguration(cManager, allowedVariables, allowFunctions)); + expressionFieldConfiguration = new ExpressionFieldConfiguration(cManager, allowedVariables, allowFunctions); + _sourceViewer.configure(expressionFieldConfiguration); AnnotationPainter painter = new AnnotationPainter(_sourceViewer, annotationAccess); _sourceViewer.addPainter(painter); @@ -174,6 +177,7 @@ public class ExpressionField extends Composite { } }); + } /** @@ -183,6 +187,10 @@ public class ExpressionField extends Composite { public SourceViewer getSourceViewer() { return this._sourceViewer; } + + public boolean isAssistSessionActive() { + return expressionFieldConfiguration.isAssistSessionActive(); + } /** * Sets missing link annotations to given positions diff --git a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionFieldConfiguration.java b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionFieldConfiguration.java index 11c82ee1..5521aa2d 100644 --- a/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionFieldConfiguration.java +++ b/org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionFieldConfiguration.java @@ -15,7 +15,10 @@ import org.eclipse.jface.text.DefaultTextHover; import org.eclipse.jface.text.IDocument; import org.eclipse.jface.text.ITextHover; import org.eclipse.jface.text.TextAttribute; +import org.eclipse.jface.text.contentassist.ContentAssistEvent; import org.eclipse.jface.text.contentassist.ContentAssistant; +import org.eclipse.jface.text.contentassist.ICompletionListener; +import org.eclipse.jface.text.contentassist.ICompletionProposal; import org.eclipse.jface.text.contentassist.IContentAssistant; import org.eclipse.jface.text.presentation.IPresentationReconciler; import org.eclipse.jface.text.presentation.PresentationReconciler; @@ -38,16 +41,25 @@ import org.simantics.sysdyn.ui.utils.VariableNameUtils; public class ExpressionFieldConfiguration extends SourceViewerConfiguration { - + private final long WAIT_BEFORE_STATUS_CHANGE = 100; + ColorManager colorManager; Table allowedVariables; - Boolean allowFunctions; + boolean allowFunctions; + boolean assistSessionActive; + CompletionProcessor completionProcessor; public ExpressionFieldConfiguration(ColorManager colorManager, Table allowedVariables, boolean allowFunctions) { super(); this.colorManager = colorManager; this.allowedVariables = allowedVariables; this.allowFunctions = allowFunctions; + this.assistSessionActive = false; + this.completionProcessor = null; + } + + public boolean isAssistSessionActive() { + return assistSessionActive; } public String[] getConfiguredContentTypes(ISourceViewer sourceViewer) { @@ -122,13 +134,48 @@ public class ExpressionFieldConfiguration extends SourceViewerConfiguration { @Override public IContentAssistant getContentAssistant(ISourceViewer sourceViewer) { ContentAssistant assistant = new ContentAssistant(); - assistant.setContentAssistProcessor(new CompletionProcessor(allowedVariables, allowFunctions), "__dftl_partition_content_type"); + completionProcessor = new CompletionProcessor(allowedVariables, allowFunctions); + assistant.setContentAssistProcessor(completionProcessor, "__dftl_partition_content_type"); assistant.enableAutoActivation(true); assistant.enableAutoInsert(true); assistant.setAutoActivationDelay(0); assistant.setProposalPopupOrientation(IContentAssistant.PROPOSAL_OVERLAY); assistant.setContextInformationPopupOrientation(IContentAssistant.CONTEXT_INFO_ABOVE); + assistant.addCompletionListener(new CompletionListener()); return assistant; } + + private class CompletionListener implements ICompletionListener { + + @Override + public void assistSessionStarted(ContentAssistEvent event) { + if (event.processor.equals(completionProcessor)) { + assistSessionActive = true; + } + } + @Override + public void assistSessionEnded(ContentAssistEvent event) { + if (event.processor.equals(completionProcessor)) { + Thread waitBeforeStateChange = new Thread() { + public void run() { + try { + sleep(WAIT_BEFORE_STATUS_CHANGE); + assistSessionActive = false; + } catch (InterruptedException e) { + assistSessionActive = false; + } + } + }; + waitBeforeStateChange.start(); + } + } + + @Override + public void selectionChanged(ICompletionProposal proposal, + boolean smartToggle) { + } + + } + } -- 2.47.1