]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
bugfix for text replace in equation view
authorniemisto <niemisto@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 29 Jan 2010 15:28:57 +0000 (15:28 +0000)
committerniemisto <niemisto@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Fri, 29 Jan 2010 15:28:57 +0000 (15:28 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@13779 ac1ea38d-2e2b-0410-8846-a27921b304fc

org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/elements/TextElement.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/AuxiliaryExpressionViewFactor.java
org.simantics.sysdyn.ui/src/org/simantics/sysdyn/ui/equation/expressions/ExpressionField.java

index 53d32ab2bc3c921a616a62942338155a881787d8..5f8404c3d3adc3582e20b542ae226e4dede4e5ac 100644 (file)
@@ -184,14 +184,6 @@ public class TextElement extends RectangularElement implements Movable, Connecta
        \r
        @UpdateMethod\r
     boolean readHasExpression(ReadGraph g, Resource resource) {\r
-        try {\r
-            System.out.println("readHasExpression " +\r
-                    g.getRelatedValue(resource, \r
-                            g.getBuiltins().HasName));\r
-        } catch (DatabaseException e1) {\r
-            // TODO Auto-generated catch block\r
-            e1.printStackTrace();\r
-        }\r
         SysdynResource sr = SysdynResource.getInstance(g);\r
         try {\r
             hasEquation = \r
index 136ade16ea380c8d4148074a8dde71189134cef4..30f906a3bed1138a382156eb8ad48eb3a1db304a 100644 (file)
@@ -6,6 +6,8 @@ import java.util.Map;
 \r
 import org.eclipse.jface.layout.GridDataFactory;\r
 import org.eclipse.jface.layout.GridLayoutFactory;\r
+import org.eclipse.jface.text.BadLocationException;\r
+import org.eclipse.jface.text.IDocument;\r
 import org.eclipse.swt.SWT;\r
 import org.eclipse.swt.events.FocusAdapter;\r
 import org.eclipse.swt.events.FocusEvent;\r
@@ -54,7 +56,7 @@ public class AuxiliaryExpressionViewFactor implements IExpressionViewFactor {
 \r
             @Override\r
             public void focusLost(FocusEvent e) {\r
-                lastSelection = expression.getSelection();      \r
+                lastSelection = expression.getSelection();\r
             }\r
         });\r
         \r
@@ -118,13 +120,23 @@ public class AuxiliaryExpressionViewFactor implements IExpressionViewFactor {
 \r
     @Override\r
     public void replaceSelection(String var) {\r
-        if(this.expression != null) {\r
-            String oldExpression = expression.getExpression();\r
-            if(lastSelection == null)\r
-                lastSelection = new Point(0,0);\r
+        if(expression != null) {\r
+            IDocument doc = expression.getDocument();\r
+            try {\r
+                Point selection = expression.getSelection();\r
+                doc.replace(selection.x, selection.y, var);\r
+            } catch (BadLocationException e) {\r
+                // TODO Auto-generated catch block\r
+                e.printStackTrace();\r
+            }\r
+            \r
+            /*String oldExpression = expression.getExpression();\r
+            System.out.println("lastSelection = " + lastSelection);\r
+            \r
             String newExpression = oldExpression.substring(0, lastSelection.x) + var + oldExpression.substring(lastSelection.y);\r
             expression.setExpression(newExpression);\r
             expression.setSelection(lastSelection.x + var.length());\r
+            */\r
         }\r
     }\r
 \r
index 953a76f4e2e01af9930e05669e3731ac20967abd..a1619ea6873199855be9d616efd0d16e816c7a25 100644 (file)
@@ -136,7 +136,9 @@ public class ExpressionField extends Composite {
         this._sourceViewer.setSelectedRange(selection, 0);\r
     }\r
     \r
-\r
+    public IDocument getDocument() {\r
+        return _document;\r
+    }\r
     \r
 \r
 }\r