diff mde/content/ServiceContent.d @ 179:1f9d00f392bd default tip

Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now. Optimised when ServiceContentList.opCall is called, I think without breaking anything.
author Diggory Hardy <diggory.hardy@gmail.com>
date Tue, 15 Sep 2009 20:09:59 +0200
parents a1ba9157510e
children
line wrap: on
line diff
--- a/mde/content/ServiceContent.d	Tue Sep 15 10:36:37 2009 +0200
+++ b/mde/content/ServiceContent.d	Tue Sep 15 20:09:59 2009 +0200
@@ -33,7 +33,13 @@
     }
 }
 
-/** Interface for ServiceContent and ServiceContentList. */
+/** Interface for ServiceContent and ServiceContentList.
+ *
+ * When the value changes, needs to call callbacks from collapsible widgets and
+ * the like, to show/hide the button.
+ * 
+ * When ServiceContent buttons are pressed, they need to call event callbacks,
+ * doing the service. */
 interface IServiceContent : IContent {
     void setContent (Content cont);
 }
@@ -56,8 +62,11 @@
     override void setContent (Content cont) {
 	T oCont = activeCont;
 	activeCont = cast(T)cont;
-	if ((oCont !is null) != (activeCont !is null))
+	if ((oCont !is null) != (activeCont !is null)) {
+	    logger.trace ("00");
 	    endEvent;
+	    logger.trace ("01");
+	}
     }
     
     override bool opCall () {
@@ -80,22 +89,42 @@
 {
     this (char[] symbol) {
 	super (symbol);
+	foreach (child; list_) {
+	    if ((cast(IBoolContent)child)()) {
+		v = true;
+		break;
+	    }
+	}
+	endEvent;
     }
     
     void setContent (Content cont) {
 	foreach (child; list_) {
 	    (cast(IServiceContent)child).setContent (cont);
 	}
+	bool ov = v;
+	v = false;
+	foreach (child; list_) {
+	    if ((cast(IBoolContent)child)()) {
+		v = true;
+		break;
+	    }
+	}
+	if (v != ov) {
+	    debug logger.trace ("ServiceContentList.endEvent");
+	    endEvent;
+	}
     }
     
     override void append (Content x) {
 	assert (cast(IBoolContent) x, "Only IBoolContent children are allowed!");
 	list_ ~= x;
-	x.addCallback (&childChangeCB);
+	//NOTE: this should only ever be changed when setContent is called and after creation
+	//x.addCallback (&childChangeCB);
     }
     
     override bool opCall () {
-	debug logger.trace ("ServiceContentList.opCall");
+	debug logger.trace ("ServiceContentList.opCall: {}", symbol);
 	return v;
     }
     // Doesn't support directly setting the value
@@ -117,15 +146,19 @@
 	(new AStringService(lName~".copy")).addCallback (delegate void(IContent c) {
 	    debug assert (cast(AStringService)c);
 	    with (cast(AStringService)c) {
-		if (activeCont !is null)
+		if (activeCont !is null) {
 		    clipboard = activeCont.toString(0);
+		    debug logger.trace ("set clipboard to \"{}\"", clipboard);
+		}
 	    }
 	});
 	(new AStringService(lName~".paste")).addCallback (delegate void(IContent c) {
 	    debug assert (cast(AStringService)c);
 	    with (cast(AStringService)c) {
-		if (activeCont !is null)
+		if (activeCont !is null) {
 		    activeCont = clipboard;
+		    debug logger.trace ("assigned from clipboard: \"{}\"", activeCont.toString(0));
+		}
 	    }
 	});
 	
@@ -148,6 +181,7 @@
     }
     
 private:
+    /+NOTE: trying a different method
     void childChangeCB (IContent icont) {
 	if (v == false) {	// then value changes iff icont()
 	    debug assert (cast(IBoolContent) icont);
@@ -166,7 +200,7 @@
 	    if (!v)
 		endEvent;
 	}
-    }
+    }+/
     
     bool v = false;	// cache value so we can see when it changes
     static char[] clipboard;