]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
Improving the content assist in text fields (refs #2969):
authormiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 11 Sep 2012 10:11:18 +0000 (10:11 +0000)
committermiettinen <miettinen@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 11 Sep 2012 10:11:18 +0000 (10:11 +0000)
* ESC no longer destroys all changes if pressed when the popup box is open
* The equation doesn't need to be delimited by whitespace to make the auto completion work.
* The cursor is put in between the parenthesis of functions
* Variables are on top of the list
Small fix to completion processor in the charts: '_' character is now allowed too

git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@25710 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/CompletionProcessor.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/properties/widgets/expressions/ExpressionField.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/trend/chart/properties/RVIModifier.java

index d09666760b979a491d548a2a3112015bca277111..533fc146746f074e0cb6c540894918059a8af1cd 100644 (file)
@@ -49,9 +49,10 @@ public class CompletionProcessor implements IContentAssistProcessor {
        private char[] allowedCharacters = {\r
                'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','å','ä','ö',\r
                'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','Å','Ä','Ö',\r
-               '1','2','3','4','5','6','7','8','9','0','.',\r
-               '(',')'};\r
+               '1','2','3','4','5','6','7','8','9','0','.','_','(',')'};\r
            \r
+       private String allowedConnectedCharactersRegExp = "[\\Q({[:;,<=>+-*/^\\E]";\r
+       \r
        public CompletionProcessor(Table allowedVariables, boolean allowFunctions){\r
                this.allowedVariables = allowedVariables;\r
                \r
@@ -87,7 +88,10 @@ public class CompletionProcessor implements IContentAssistProcessor {
                                e.printStackTrace();\r
                        }\r
         }\r
-               Collections.sort(functions);\r
+        Collections.sort(functions);\r
+               for (int i = 0; i < functions.size(); ++i) {\r
+            functions.set(i, functions.get(i) + "()");\r
+               }\r
        }\r
 \r
        private ICompletionProposal[] collectProposals(String token, int offset) {\r
@@ -104,14 +108,6 @@ public class CompletionProcessor implements IContentAssistProcessor {
                }\r
                \r
                ArrayList<ICompletionProposal> resultArray = new ArrayList<ICompletionProposal>();\r
-               for (String function : functions) {\r
-                       if (token.length() == 0 || function.toUpperCase().startsWith(token.toUpperCase())) {\r
-                               resultArray.add(new CompletionProposal(function, \r
-                                               offset - token.length(),\r
-                                               token.length(), \r
-                                               function.length()));\r
-                       }       \r
-               }\r
                for (String variable : variables) {\r
                        if (token.length() == 0 || variable.toUpperCase().startsWith(token.toUpperCase())) {\r
                                resultArray.add(new CompletionProposal(variable, \r
@@ -120,6 +116,14 @@ public class CompletionProcessor implements IContentAssistProcessor {
                                                variable.length()));\r
                        }       \r
                }\r
+               for (String function : functions) {\r
+                       if (token.length() == 0 || function.toUpperCase().startsWith(token.toUpperCase())) {\r
+                               resultArray.add(new CompletionProposal(function, \r
+                                               offset - token.length(),\r
+                                               token.length(), \r
+                                               function.length() - 1));\r
+                       }       \r
+               }\r
                ICompletionProposal[] result = new ICompletionProposal[resultArray.size()];\r
                for (int i = 0; i < result.length; ++i) {\r
                        result[i] = resultArray.get(i);\r
@@ -131,7 +135,6 @@ public class CompletionProcessor implements IContentAssistProcessor {
        public ICompletionProposal[] computeCompletionProposals(\r
                        ITextViewer viewer, int offset) {\r
                String equation = viewer.getDocument().get();\r
-//             System.out.println(equation + "\noffset = " + offset);\r
 \r
                if (equation.length() == 0 \r
                                || offset == 0\r
@@ -140,14 +143,20 @@ public class CompletionProcessor implements IContentAssistProcessor {
                }\r
                \r
                equation = equation.substring(0, offset);\r
-//             System.out.println(equation + "\noffset = " + offset);\r
                \r
                // Split into tokens on whitespace characters\r
-               String[] tokens = equation.split("\\s+");\r
+               String[] tokens = equation.split("[\\s]");\r
                if (tokens.length == 0) {\r
                        return collectProposals("", offset);\r
                }\r
                String token = tokens[tokens.length - 1];\r
+               \r
+               // Split the last token on '+', '-', etc. characters \r
+               String tokensOfLastToken[] = token.split(allowedConnectedCharactersRegExp);\r
+               if (tokensOfLastToken.length == 0) {\r
+                       return collectProposals("", offset);\r
+               }\r
+               token = tokensOfLastToken[tokensOfLastToken.length - 1];\r
 //             System.out.println(token + "\noffset = " + offset);\r
 \r
                return collectProposals(token, offset);\r
index 7b79a518f632a135cbe6583f871868d67b5a6054..39e7381d955862507c718a1d50b108ea41cdffcc 100644 (file)
@@ -134,9 +134,12 @@ public class ExpressionField extends Composite {
 \r
             @Override\r
             public void keyPressed(KeyEvent e) {\r
-                if(e.keyCode == SWT.ESC && getExpression() != null) {\r
-                    ((StyledText)e.widget).setText(oldExpression);\r
-                    ((StyledText)e.widget).setSelection(getExpression().length());\r
+               // Check if the expression field has an active completion assistant\r
+                               if (!isAssistSessionActive()) {\r
+                                       if(e.keyCode == SWT.ESC && getExpression() != null) {\r
+                           ((StyledText)e.widget).setText(oldExpression);\r
+                           ((StyledText)e.widget).setSelection(getExpression().length());\r
+                                       }\r
                 }   \r
             }\r
         });\r
index 9a667b8e8894ac4e8f0d06b3ce334e2724dcc8a7..27246f5b005f62ead4926b2f8987cc98378f176c 100644 (file)
@@ -44,7 +44,7 @@ public class RVIModifier extends TextModifyListenerImpl<Resource> {
     private char[] alphaNumericCharacters = {\r
         'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z','å','ä','ö',\r
         'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','Å','Ä','Ö',\r
-        '1','2','3','4','5','6','7','8','9','0','.'};\r
+        '1','2','3','4','5','6','7','8','9','0','.','_'};\r
     \r
     /**\r
      * Create a new RVIModifier and attach a content proposal support to control\r