Mercurial > projects > mde
diff mde/content/ServiceContent.d @ 171:7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Moved WMScreen.createRootWidget to WidgetManager.createWidgets.
Put childContext under a popupHandler widget.
TODO: implement IChildWidget.setContent(Content) (see AParentWidget.d:237).
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Sun, 26 Jul 2009 11:04:17 +0200 |
parents | e45226d3deae |
children | a1ba9157510e |
line wrap: on
line diff
--- a/mde/content/ServiceContent.d Mon Jun 29 21:20:16 2009 +0200 +++ b/mde/content/ServiceContent.d Sun Jul 26 11:04:17 2009 +0200 @@ -26,7 +26,7 @@ import mde.content.AStringContent; /** Interface for ServiceContent and ServiceContentList. */ -interface IServiceContent { +interface IServiceContent : IContent { void setContent (Content cont); } @@ -87,54 +87,54 @@ } // Doesn't support directly setting the value override void opAssign (bool val) {} + + + /** Create all services. + * + * Each WidgetManager has it's own instance, but these share one clipboard, etc. + * + * Currently all clipboard operations convert to/from a string. + * TODO: Possible extensions: multi-item clipboard displaying value in menu, + * copying without converting everything to/from a string. */ + static ServiceContentList createItems (char[] name) { + char[] lName = "menus.services."~name; + auto ret = new ServiceContentList (lName); + + // Many use callbacks on a generic class type. For this, we should be sure of the type. + (new AStringService(lName~".copy")).addCallback ((IContent c) { + debug assert (cast(AStringService)c); + with (cast(AStringService)c) { + if (activeCont !is null) + clipboard = activeCont.toString(0); + } + }); + (new AStringService(lName~".paste")).addCallback ((IContent c) { + debug assert (cast(AStringService)c); + with (cast(AStringService)c) { + if (activeCont !is null) + activeCont = clipboard; + } + }); + + new ServiceContentList(lName~".calculator"); + (new IntService(lName~".calculator.increment")).addCallback ((IContent c) { + debug assert (cast(IntService)c); + with (cast(IntService)c) { + if (activeCont !is null) + activeCont = activeCont()+1; + } + }); + (new IntService(lName~".calculator.decrement")).addCallback ((IContent c) { + debug assert (cast(IntService)c); + with (cast(IntService)c) { + if (activeCont !is null) + activeCont = activeCont()-1; + } + }); + return ret; + } + +private: + static char[] clipboard; + //TODO: lock on clipboard: static Mutex mutex; } - -/** Create all services. -* -* For now, all are under the menu. -* -* Currently all clipboard operations convert to/from a string. -* TODO: Possible extensions: multi-item clipboard displaying value in menu, -* copying without converting everything to/from a string. */ -static this () { - // Create ContentLists so they have the correct type. - new ServiceContentList ("menus.services"); - // Many use callbacks on a generic class type. For this, we should be sure of the type. - auto copy = new AStringService("menus.services.copy"); - copy.addCallback ((IContent c) { - debug assert (cast(AStringService)c); - with (cast(AStringService)c) { - if (activeCont !is null) - clipboard = activeCont.toString(0); - } - }); - auto paste = new AStringService("menus.services.paste"); - paste.addCallback ((IContent c) { - debug assert (cast(AStringService)c); - with (cast(AStringService)c) { - if (activeCont !is null) - activeCont = clipboard; - } - }); - - new ServiceContentList("menus.services.calculator"); - auto inc = new IntService("menus.services.calculator.increment"); - inc.addCallback ((IContent c) { - debug assert (cast(IntService)c); - with (cast(IntService)c) { - if (activeCont !is null) - activeCont = activeCont()+1; - } - }); - auto dec = new IntService("menus.services.calculator.decrement"); - dec.addCallback ((IContent c) { - debug assert (cast(IntService)c); - with (cast(IntService)c) { - if (activeCont !is null) - activeCont = activeCont()-1; - } - }); -} -private { - char[] clipboard; -}