Mercurial > projects > mde
comparison 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 |
comparison
equal
deleted
inserted
replaced
170:e45226d3deae | 171:7f7b2011b759 |
---|---|
24 module mde.content.ServiceContent; | 24 module mde.content.ServiceContent; |
25 | 25 |
26 import mde.content.AStringContent; | 26 import mde.content.AStringContent; |
27 | 27 |
28 /** Interface for ServiceContent and ServiceContentList. */ | 28 /** Interface for ServiceContent and ServiceContentList. */ |
29 interface IServiceContent { | 29 interface IServiceContent : IContent { |
30 void setContent (Content cont); | 30 void setContent (Content cont); |
31 } | 31 } |
32 | 32 |
33 /** A class for services acting on content. | 33 /** A class for services acting on content. |
34 * | 34 * |
85 } | 85 } |
86 return true; | 86 return true; |
87 } | 87 } |
88 // Doesn't support directly setting the value | 88 // Doesn't support directly setting the value |
89 override void opAssign (bool val) {} | 89 override void opAssign (bool val) {} |
90 | |
91 | |
92 /** Create all services. | |
93 * | |
94 * Each WidgetManager has it's own instance, but these share one clipboard, etc. | |
95 * | |
96 * Currently all clipboard operations convert to/from a string. | |
97 * TODO: Possible extensions: multi-item clipboard displaying value in menu, | |
98 * copying without converting everything to/from a string. */ | |
99 static ServiceContentList createItems (char[] name) { | |
100 char[] lName = "menus.services."~name; | |
101 auto ret = new ServiceContentList (lName); | |
102 | |
103 // Many use callbacks on a generic class type. For this, we should be sure of the type. | |
104 (new AStringService(lName~".copy")).addCallback ((IContent c) { | |
105 debug assert (cast(AStringService)c); | |
106 with (cast(AStringService)c) { | |
107 if (activeCont !is null) | |
108 clipboard = activeCont.toString(0); | |
109 } | |
110 }); | |
111 (new AStringService(lName~".paste")).addCallback ((IContent c) { | |
112 debug assert (cast(AStringService)c); | |
113 with (cast(AStringService)c) { | |
114 if (activeCont !is null) | |
115 activeCont = clipboard; | |
116 } | |
117 }); | |
118 | |
119 new ServiceContentList(lName~".calculator"); | |
120 (new IntService(lName~".calculator.increment")).addCallback ((IContent c) { | |
121 debug assert (cast(IntService)c); | |
122 with (cast(IntService)c) { | |
123 if (activeCont !is null) | |
124 activeCont = activeCont()+1; | |
125 } | |
126 }); | |
127 (new IntService(lName~".calculator.decrement")).addCallback ((IContent c) { | |
128 debug assert (cast(IntService)c); | |
129 with (cast(IntService)c) { | |
130 if (activeCont !is null) | |
131 activeCont = activeCont()-1; | |
132 } | |
133 }); | |
134 return ret; | |
135 } | |
136 | |
137 private: | |
138 static char[] clipboard; | |
139 //TODO: lock on clipboard: static Mutex mutex; | |
90 } | 140 } |
91 | |
92 /** Create all services. | |
93 * | |
94 * For now, all are under the menu. | |
95 * | |
96 * Currently all clipboard operations convert to/from a string. | |
97 * TODO: Possible extensions: multi-item clipboard displaying value in menu, | |
98 * copying without converting everything to/from a string. */ | |
99 static this () { | |
100 // Create ContentLists so they have the correct type. | |
101 new ServiceContentList ("menus.services"); | |
102 // Many use callbacks on a generic class type. For this, we should be sure of the type. | |
103 auto copy = new AStringService("menus.services.copy"); | |
104 copy.addCallback ((IContent c) { | |
105 debug assert (cast(AStringService)c); | |
106 with (cast(AStringService)c) { | |
107 if (activeCont !is null) | |
108 clipboard = activeCont.toString(0); | |
109 } | |
110 }); | |
111 auto paste = new AStringService("menus.services.paste"); | |
112 paste.addCallback ((IContent c) { | |
113 debug assert (cast(AStringService)c); | |
114 with (cast(AStringService)c) { | |
115 if (activeCont !is null) | |
116 activeCont = clipboard; | |
117 } | |
118 }); | |
119 | |
120 new ServiceContentList("menus.services.calculator"); | |
121 auto inc = new IntService("menus.services.calculator.increment"); | |
122 inc.addCallback ((IContent c) { | |
123 debug assert (cast(IntService)c); | |
124 with (cast(IntService)c) { | |
125 if (activeCont !is null) | |
126 activeCont = activeCont()+1; | |
127 } | |
128 }); | |
129 auto dec = new IntService("menus.services.calculator.decrement"); | |
130 dec.addCallback ((IContent c) { | |
131 debug assert (cast(IntService)c); | |
132 with (cast(IntService)c) { | |
133 if (activeCont !is null) | |
134 activeCont = activeCont()-1; | |
135 } | |
136 }); | |
137 } | |
138 private { | |
139 char[] clipboard; | |
140 } |