Mercurial > projects > mde
annotate mde/content/ServiceContent.d @ 173:a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
author | Diggory Hardy <diggory.hardy@gmail.com> |
---|---|
date | Sat, 08 Aug 2009 15:53:10 +0200 |
parents | 7f7b2011b759 |
children | 1f9d00f392bd |
rev | line source |
---|---|
61
7cab2af4ba21
A little bit of progress on the content handling system (relevent code is likely to be revised).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
1 /* LICENSE BLOCK |
7cab2af4ba21
A little bit of progress on the content handling system (relevent code is likely to be revised).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
2 Part of mde: a Modular D game-oriented Engine |
170
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
3 Copyright © 2007-2009 Diggory Hardy |
61
7cab2af4ba21
A little bit of progress on the content handling system (relevent code is likely to be revised).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
4 |
7cab2af4ba21
A little bit of progress on the content handling system (relevent code is likely to be revised).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
5 This program is free software: you can redistribute it and/or modify it under the terms |
7cab2af4ba21
A little bit of progress on the content handling system (relevent code is likely to be revised).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
6 of the GNU General Public License as published by the Free Software Foundation, either |
7cab2af4ba21
A little bit of progress on the content handling system (relevent code is likely to be revised).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
7 version 2 of the License, or (at your option) any later version. |
7cab2af4ba21
A little bit of progress on the content handling system (relevent code is likely to be revised).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
8 |
7cab2af4ba21
A little bit of progress on the content handling system (relevent code is likely to be revised).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
9 This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; |
7cab2af4ba21
A little bit of progress on the content handling system (relevent code is likely to be revised).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
10 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
7cab2af4ba21
A little bit of progress on the content handling system (relevent code is likely to be revised).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
11 See the GNU General Public License for more details. |
7cab2af4ba21
A little bit of progress on the content handling system (relevent code is likely to be revised).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
12 |
7cab2af4ba21
A little bit of progress on the content handling system (relevent code is likely to be revised).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
13 You should have received a copy of the GNU General Public License |
7cab2af4ba21
A little bit of progress on the content handling system (relevent code is likely to be revised).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
14 along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
7cab2af4ba21
A little bit of progress on the content handling system (relevent code is likely to be revised).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
15 |
7cab2af4ba21
A little bit of progress on the content handling system (relevent code is likely to be revised).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
16 /** Content services. |
7cab2af4ba21
A little bit of progress on the content handling system (relevent code is likely to be revised).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
17 * |
170
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
18 * Each is a Content, so it can be used in a menu. Since the content being |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
19 * acted on is not passed when functions are called like this, it is set when |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
20 * a context menu is opened, which also allows the services to specify their |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
21 * compatibility with the content (type) passed (via BoolContent value and |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
22 * callbacks). |
61
7cab2af4ba21
A little bit of progress on the content handling system (relevent code is likely to be revised).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
23 */ |
170
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
24 module mde.content.ServiceContent; |
61
7cab2af4ba21
A little bit of progress on the content handling system (relevent code is likely to be revised).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
25 |
149
1125ba603af6
Some ideas for content service menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
26 import mde.content.AStringContent; |
1125ba603af6
Some ideas for content service menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
27 |
173
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
28 debug { |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
29 import tango.util.log.Log : Log, Logger; |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
30 private Logger logger; |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
31 static this () { |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
32 logger = Log.getLogger ("mde.gui.content.ServiceContent"); |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
33 } |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
34 } |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
35 |
170
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
36 /** Interface for ServiceContent and ServiceContentList. */ |
171
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
37 interface IServiceContent : IContent { |
170
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
38 void setContent (Content cont); |
61
7cab2af4ba21
A little bit of progress on the content handling system (relevent code is likely to be revised).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
39 } |
7cab2af4ba21
A little bit of progress on the content handling system (relevent code is likely to be revised).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
40 |
170
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
41 /** A class for services acting on content. |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
42 * |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
43 * Provides services for any content usable as type T, where T is some content |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
44 * type. |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
45 * |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
46 * The (boolean) value is true to indicate this service can act on the passed |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
47 * content type, false if not. */ |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
48 class ServiceContent(T : Content = AStringContent) : Content, IServiceContent, IBoolContent, IEventContent { |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
49 this (char[] symbol) { |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
50 super (symbol); |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
51 } |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
52 |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
53 /** Pass the content this service should prepare for. |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
54 * |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
55 * Stores the reference, because it won't be passed later. */ |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
56 override void setContent (Content cont) { |
173
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
57 T oCont = activeCont; |
170
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
58 activeCont = cast(T)cont; |
173
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
59 if ((oCont !is null) != (activeCont !is null)) |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
60 endEvent; |
170
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
61 } |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
62 |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
63 override bool opCall () { |
173
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
64 debug logger.trace ("ServiceContent.opCall: {}", symbol); |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
65 return activeCont !is null; |
170
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
66 } |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
67 // Doesn't support directly setting the value |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
68 override void opAssign (bool val) {} |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
69 |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
70 package: |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
71 T activeCont; |
61
7cab2af4ba21
A little bit of progress on the content handling system (relevent code is likely to be revised).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
72 } |
7cab2af4ba21
A little bit of progress on the content handling system (relevent code is likely to be revised).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
73 |
170
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
74 /** Aliases for common types */ |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
75 alias ServiceContent!(AStringContent) AStringService; |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
76 alias ServiceContent!(IntContent) IntService; ///ditto |
149
1125ba603af6
Some ideas for content service menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
77 |
170
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
78 /** A generic way to handle a list of type IContent. */ |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
79 class ServiceContentList : ContentList, IServiceContent, IBoolContent |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
80 { |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
81 this (char[] symbol) { |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
82 super (symbol); |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
83 } |
149
1125ba603af6
Some ideas for content service menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
105
diff
changeset
|
84 |
170
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
85 void setContent (Content cont) { |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
86 foreach (child; list_) { |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
87 (cast(IServiceContent)child).setContent (cont); |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
88 } |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
89 } |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
90 |
173
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
91 override void append (Content x) { |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
92 assert (cast(IBoolContent) x, "Only IBoolContent children are allowed!"); |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
93 list_ ~= x; |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
94 x.addCallback (&childChangeCB); |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
95 } |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
96 |
170
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
97 override bool opCall () { |
173
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
98 debug logger.trace ("ServiceContentList.opCall"); |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
99 return v; |
170
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
100 } |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
101 // Doesn't support directly setting the value |
e45226d3deae
Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
149
diff
changeset
|
102 override void opAssign (bool val) {} |
171
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
103 |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
104 |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
105 /** Create all services. |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
106 * |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
107 * Each WidgetManager has it's own instance, but these share one clipboard, etc. |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
108 * |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
109 * Currently all clipboard operations convert to/from a string. |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
110 * TODO: Possible extensions: multi-item clipboard displaying value in menu, |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
111 * copying without converting everything to/from a string. */ |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
112 static ServiceContentList createItems (char[] name) { |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
113 char[] lName = "menus.services."~name; |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
114 auto ret = new ServiceContentList (lName); |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
115 |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
116 // Many use callbacks on a generic class type. For this, we should be sure of the type. |
173
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
117 (new AStringService(lName~".copy")).addCallback (delegate void(IContent c) { |
171
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
118 debug assert (cast(AStringService)c); |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
119 with (cast(AStringService)c) { |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
120 if (activeCont !is null) |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
121 clipboard = activeCont.toString(0); |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
122 } |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
123 }); |
173
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
124 (new AStringService(lName~".paste")).addCallback (delegate void(IContent c) { |
171
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
125 debug assert (cast(AStringService)c); |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
126 with (cast(AStringService)c) { |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
127 if (activeCont !is null) |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
128 activeCont = clipboard; |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
129 } |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
130 }); |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
131 |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
132 new ServiceContentList(lName~".calculator"); |
173
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
133 (new IntService(lName~".calculator.increment")).addCallback (delegate void(IContent c) { |
171
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
134 debug assert (cast(IntService)c); |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
135 with (cast(IntService)c) { |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
136 if (activeCont !is null) |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
137 activeCont = activeCont()+1; |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
138 } |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
139 }); |
173
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
140 (new IntService(lName~".calculator.decrement")).addCallback (delegate void(IContent c) { |
171
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
141 debug assert (cast(IntService)c); |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
142 with (cast(IntService)c) { |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
143 if (activeCont !is null) |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
144 activeCont = activeCont()-1; |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
145 } |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
146 }); |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
147 return ret; |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
148 } |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
149 |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
150 private: |
173
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
151 void childChangeCB (IContent icont) { |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
152 if (v == false) { // then value changes iff icont() |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
153 debug assert (cast(IBoolContent) icont); |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
154 if ((cast(IBoolContent) icont)()) { |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
155 v = true; |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
156 endEvent; |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
157 } |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
158 } else { // we must check all children |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
159 v = false; |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
160 foreach (child; list_) { |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
161 if ((cast(IBoolContent)child)()) { |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
162 v = true; |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
163 break; |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
164 } |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
165 } |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
166 if (!v) |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
167 endEvent; |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
168 } |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
169 } |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
170 |
a1ba9157510e
Enabled ServiceContentList to call its callbacks when its value changes. Tried to fix some other bugs, but this is not a very clean commit, due to wanting to make some big changes to enable better use of invariants next.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
171
diff
changeset
|
171 bool v = false; // cache value so we can see when it changes |
171
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
172 static char[] clipboard; |
7f7b2011b759
Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents:
170
diff
changeset
|
173 //TODO: lock on clipboard: static Mutex mutex; |
61
7cab2af4ba21
A little bit of progress on the content handling system (relevent code is likely to be revised).
Diggory Hardy <diggory.hardy@gmail.com>
parents:
diff
changeset
|
174 } |