annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
179
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
36 /** Interface for ServiceContent and ServiceContentList.
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
37 *
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
38 * When the value changes, needs to call callbacks from collapsible widgets and
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
39 * the like, to show/hide the button.
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
40 *
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
41 * When ServiceContent buttons are pressed, they need to call event callbacks,
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
42 * doing the service. */
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
43 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
44 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
45 }
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
46
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
47 /** 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
48 *
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 * 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
50 * 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
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 * 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
53 * 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
54 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
55 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
56 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
57 }
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
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 149
diff changeset
59 /** 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
60 *
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 * 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
62 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
63 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
64 activeCont = cast(T)cont;
179
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
65 if ((oCont !is null) != (activeCont !is null)) {
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
66 logger.trace ("00");
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
67 endEvent;
179
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
68 logger.trace ("01");
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
69 }
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
70 }
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
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 149
diff changeset
72 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
73 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
74 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
75 }
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 // 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
77 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
78
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 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
80 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
81 }
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
82
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
83 /** 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
84 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
85 alias ServiceContent!(IntContent) IntService; ///ditto
149
1125ba603af6 Some ideas for content service menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
86
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
87 /** 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
88 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
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 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
91 super (symbol);
179
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
92 foreach (child; list_) {
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
93 if ((cast(IBoolContent)child)()) {
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
94 v = true;
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
95 break;
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
96 }
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
97 }
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
98 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
99 }
149
1125ba603af6 Some ideas for content service menus.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 105
diff changeset
100
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
101 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
102 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
103 (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
104 }
179
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
105 bool ov = v;
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
106 v = false;
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
107 foreach (child; list_) {
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
108 if ((cast(IBoolContent)child)()) {
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
109 v = true;
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
110 break;
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
111 }
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
112 }
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
113 if (v != ov) {
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
114 debug logger.trace ("ServiceContentList.endEvent");
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
115 endEvent;
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
116 }
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
117 }
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 149
diff changeset
118
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
119 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
120 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
121 list_ ~= x;
179
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
122 //NOTE: this should only ever be changed when setContent is called and after creation
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
123 //x.addCallback (&childChangeCB);
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 }
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
125
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
126 override bool opCall () {
179
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
127 debug logger.trace ("ServiceContentList.opCall: {}", symbol);
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
128 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
129 }
e45226d3deae Context menu services not applicable to the current type can now be hidden.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 149
diff changeset
130 // 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
131 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
132
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
133
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
134 /** 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
135 *
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
136 * 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
137 *
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
138 * 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
139 * 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
140 * 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
141 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
142 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
143 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
144
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
145 // 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
146 (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
147 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
148 with (cast(AStringService)c) {
179
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
149 if (activeCont !is null) {
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
150 clipboard = activeCont.toString(0);
179
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
151 debug logger.trace ("set clipboard to \"{}\"", clipboard);
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
152 }
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
153 }
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
154 });
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
155 (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
156 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
157 with (cast(AStringService)c) {
179
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
158 if (activeCont !is null) {
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
159 activeCont = clipboard;
179
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
160 debug logger.trace ("assigned from clipboard: \"{}\"", activeCont.toString(0));
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
161 }
171
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
162 }
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
163 });
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
164
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
165 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
166 (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
167 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
168 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
169 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
170 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
171 }
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
172 });
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
173 (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
174 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
175 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
176 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
177 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
178 }
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
179 });
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
180 return ret;
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
181 }
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
182
7f7b2011b759 Partially complete commit: code runs but context menus don't work.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 170
diff changeset
183 private:
179
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
184 /+NOTE: trying a different method
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
185 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
186 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
187 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
188 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
189 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
190 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
191 }
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
192 } 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
193 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
194 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
195 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
196 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
197 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
198 }
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
199 }
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
200 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
201 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
202 }
179
1f9d00f392bd Fixed a bug where (non-resizible) widgets wouldn't get shrunk when minimal size decreases, meaning optional context menus are hiden properly now.
Diggory Hardy <diggory.hardy@gmail.com>
parents: 173
diff changeset
203 }+/
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
204
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
205 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
206 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
207 //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
208 }