Mercurial > projects > mde
comparison 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 |
comparison
equal
deleted
inserted
replaced
178:62aa8845edd2 | 179:1f9d00f392bd |
---|---|
31 static this () { | 31 static this () { |
32 logger = Log.getLogger ("mde.gui.content.ServiceContent"); | 32 logger = Log.getLogger ("mde.gui.content.ServiceContent"); |
33 } | 33 } |
34 } | 34 } |
35 | 35 |
36 /** Interface for ServiceContent and ServiceContentList. */ | 36 /** Interface for ServiceContent and ServiceContentList. |
37 * | |
38 * When the value changes, needs to call callbacks from collapsible widgets and | |
39 * the like, to show/hide the button. | |
40 * | |
41 * When ServiceContent buttons are pressed, they need to call event callbacks, | |
42 * doing the service. */ | |
37 interface IServiceContent : IContent { | 43 interface IServiceContent : IContent { |
38 void setContent (Content cont); | 44 void setContent (Content cont); |
39 } | 45 } |
40 | 46 |
41 /** A class for services acting on content. | 47 /** A class for services acting on content. |
54 * | 60 * |
55 * Stores the reference, because it won't be passed later. */ | 61 * Stores the reference, because it won't be passed later. */ |
56 override void setContent (Content cont) { | 62 override void setContent (Content cont) { |
57 T oCont = activeCont; | 63 T oCont = activeCont; |
58 activeCont = cast(T)cont; | 64 activeCont = cast(T)cont; |
59 if ((oCont !is null) != (activeCont !is null)) | 65 if ((oCont !is null) != (activeCont !is null)) { |
66 logger.trace ("00"); | |
60 endEvent; | 67 endEvent; |
68 logger.trace ("01"); | |
69 } | |
61 } | 70 } |
62 | 71 |
63 override bool opCall () { | 72 override bool opCall () { |
64 debug logger.trace ("ServiceContent.opCall: {}", symbol); | 73 debug logger.trace ("ServiceContent.opCall: {}", symbol); |
65 return activeCont !is null; | 74 return activeCont !is null; |
78 /** A generic way to handle a list of type IContent. */ | 87 /** A generic way to handle a list of type IContent. */ |
79 class ServiceContentList : ContentList, IServiceContent, IBoolContent | 88 class ServiceContentList : ContentList, IServiceContent, IBoolContent |
80 { | 89 { |
81 this (char[] symbol) { | 90 this (char[] symbol) { |
82 super (symbol); | 91 super (symbol); |
92 foreach (child; list_) { | |
93 if ((cast(IBoolContent)child)()) { | |
94 v = true; | |
95 break; | |
96 } | |
97 } | |
98 endEvent; | |
83 } | 99 } |
84 | 100 |
85 void setContent (Content cont) { | 101 void setContent (Content cont) { |
86 foreach (child; list_) { | 102 foreach (child; list_) { |
87 (cast(IServiceContent)child).setContent (cont); | 103 (cast(IServiceContent)child).setContent (cont); |
88 } | 104 } |
105 bool ov = v; | |
106 v = false; | |
107 foreach (child; list_) { | |
108 if ((cast(IBoolContent)child)()) { | |
109 v = true; | |
110 break; | |
111 } | |
112 } | |
113 if (v != ov) { | |
114 debug logger.trace ("ServiceContentList.endEvent"); | |
115 endEvent; | |
116 } | |
89 } | 117 } |
90 | 118 |
91 override void append (Content x) { | 119 override void append (Content x) { |
92 assert (cast(IBoolContent) x, "Only IBoolContent children are allowed!"); | 120 assert (cast(IBoolContent) x, "Only IBoolContent children are allowed!"); |
93 list_ ~= x; | 121 list_ ~= x; |
94 x.addCallback (&childChangeCB); | 122 //NOTE: this should only ever be changed when setContent is called and after creation |
123 //x.addCallback (&childChangeCB); | |
95 } | 124 } |
96 | 125 |
97 override bool opCall () { | 126 override bool opCall () { |
98 debug logger.trace ("ServiceContentList.opCall"); | 127 debug logger.trace ("ServiceContentList.opCall: {}", symbol); |
99 return v; | 128 return v; |
100 } | 129 } |
101 // Doesn't support directly setting the value | 130 // Doesn't support directly setting the value |
102 override void opAssign (bool val) {} | 131 override void opAssign (bool val) {} |
103 | 132 |
115 | 144 |
116 // Many use callbacks on a generic class type. For this, we should be sure of the type. | 145 // Many use callbacks on a generic class type. For this, we should be sure of the type. |
117 (new AStringService(lName~".copy")).addCallback (delegate void(IContent c) { | 146 (new AStringService(lName~".copy")).addCallback (delegate void(IContent c) { |
118 debug assert (cast(AStringService)c); | 147 debug assert (cast(AStringService)c); |
119 with (cast(AStringService)c) { | 148 with (cast(AStringService)c) { |
120 if (activeCont !is null) | 149 if (activeCont !is null) { |
121 clipboard = activeCont.toString(0); | 150 clipboard = activeCont.toString(0); |
151 debug logger.trace ("set clipboard to \"{}\"", clipboard); | |
152 } | |
122 } | 153 } |
123 }); | 154 }); |
124 (new AStringService(lName~".paste")).addCallback (delegate void(IContent c) { | 155 (new AStringService(lName~".paste")).addCallback (delegate void(IContent c) { |
125 debug assert (cast(AStringService)c); | 156 debug assert (cast(AStringService)c); |
126 with (cast(AStringService)c) { | 157 with (cast(AStringService)c) { |
127 if (activeCont !is null) | 158 if (activeCont !is null) { |
128 activeCont = clipboard; | 159 activeCont = clipboard; |
160 debug logger.trace ("assigned from clipboard: \"{}\"", activeCont.toString(0)); | |
161 } | |
129 } | 162 } |
130 }); | 163 }); |
131 | 164 |
132 new ServiceContentList(lName~".calculator"); | 165 new ServiceContentList(lName~".calculator"); |
133 (new IntService(lName~".calculator.increment")).addCallback (delegate void(IContent c) { | 166 (new IntService(lName~".calculator.increment")).addCallback (delegate void(IContent c) { |
146 }); | 179 }); |
147 return ret; | 180 return ret; |
148 } | 181 } |
149 | 182 |
150 private: | 183 private: |
184 /+NOTE: trying a different method | |
151 void childChangeCB (IContent icont) { | 185 void childChangeCB (IContent icont) { |
152 if (v == false) { // then value changes iff icont() | 186 if (v == false) { // then value changes iff icont() |
153 debug assert (cast(IBoolContent) icont); | 187 debug assert (cast(IBoolContent) icont); |
154 if ((cast(IBoolContent) icont)()) { | 188 if ((cast(IBoolContent) icont)()) { |
155 v = true; | 189 v = true; |
164 } | 198 } |
165 } | 199 } |
166 if (!v) | 200 if (!v) |
167 endEvent; | 201 endEvent; |
168 } | 202 } |
169 } | 203 }+/ |
170 | 204 |
171 bool v = false; // cache value so we can see when it changes | 205 bool v = false; // cache value so we can see when it changes |
172 static char[] clipboard; | 206 static char[] clipboard; |
173 //TODO: lock on clipboard: static Mutex mutex; | 207 //TODO: lock on clipboard: static Mutex mutex; |
174 } | 208 } |