diff mde/content/AStringContent.d @ 162:2476790223b8

First drag and drop support: can drag from AStringContentWidget to any content editable. No visual feedback while dragging.
author Diggory Hardy <diggory.hardy@gmail.com>
date Fri, 22 May 2009 19:59:22 +0200
parents 9f035cd139c6
children 24d77c52243f
line wrap: on
line diff
--- a/mde/content/AStringContent.d	Thu May 21 22:15:40 2009 +0200
+++ b/mde/content/AStringContent.d	Fri May 22 19:59:22 2009 +0200
@@ -51,6 +51,21 @@
              : null;
     }
     
+    /** Set the content via conversion to/from string. */
+    override bool setContent (IContent c) {
+	AStringContent asc = cast (AStringContent) c;
+	if (asc !is null) {
+	    try {
+		sv = asc.toString (0);
+		endEdit;
+	    } catch (Exception) {	// invalid conversion; just reject c
+		return false;
+	    }
+	    return true;
+	}
+	return false;
+    }
+    
     /** Acts on a keystroke and returns the new value.
      *
      * Supports one-line editing: left/right, home/end, backspace/delete. */
@@ -223,6 +238,17 @@
 	super (symbol);
     }
     
+    // NOTE: the only point of this method is to avoid int->string->int conversions,
+    // and perhaps specialise (double->int rounding?)
+    override bool setContent (IContent c) {
+	IntContent ic = cast (IntContent) c;
+	if (ic !is null) {
+	    this = ic();
+	    return true;
+	}
+	return super.setContent (c);
+    }
+    
     void assignNoCng (int val) {
 	v = val;
 	sv = Int.toString (v);