corrade-vassal – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | vero | 1 | /* |
2 | * Copyright (c) 2006-2014, openmetaverse.org |
||
3 | * All rights reserved. |
||
4 | * |
||
5 | * - Redistribution and use in source and binary forms, with or without |
||
6 | * modification, are permitted provided that the following conditions are met: |
||
7 | * |
||
8 | * - Redistributions of source code must retain the above copyright notice, this |
||
9 | * list of conditions and the following disclaimer. |
||
10 | * - Neither the name of the openmetaverse.org nor the names |
||
11 | * of its contributors may be used to endorse or promote products derived from |
||
12 | * this software without specific prior written permission. |
||
13 | * |
||
14 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
||
15 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
||
16 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
||
17 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE |
||
18 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
||
19 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
||
20 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
||
21 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
||
22 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
||
23 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
||
24 | * POSSIBILITY OF SUCH DAMAGE. |
||
25 | */ |
||
26 | |||
27 | using System; |
||
28 | using System.Collections.Generic; |
||
29 | using System.Drawing; |
||
30 | using System.Windows.Forms; |
||
31 | |||
32 | namespace OpenMetaverse.GUI |
||
33 | { |
||
34 | |||
35 | /// <summary> |
||
36 | /// TreeView GUI component for browsing a client's inventory |
||
37 | /// </summary> |
||
38 | public class InventoryTree : TreeView |
||
39 | { |
||
40 | private GridClient _Client; |
||
41 | private ContextMenu _ContextMenu; |
||
42 | private UUID _SelectedItemID; |
||
43 | |||
44 | /// <summary> |
||
45 | /// Gets or sets the context menu associated with this control |
||
46 | /// </summary> |
||
47 | public ContextMenu Menu |
||
48 | { |
||
49 | get { return _ContextMenu; } |
||
50 | set { _ContextMenu = value; } |
||
51 | } |
||
52 | |||
53 | /// <summary> |
||
54 | /// Gets or sets the GridClient associated with this control |
||
55 | /// </summary> |
||
56 | public GridClient Client |
||
57 | { |
||
58 | get { return _Client; } |
||
59 | set { if (value != null) InitializeClient(value); } |
||
60 | } |
||
61 | |||
62 | /// <summary> |
||
63 | /// TreeView control for an unspecified client's inventory |
||
64 | /// </summary> |
||
65 | public InventoryTree() |
||
66 | { |
||
67 | EventHandler clickHandler = new EventHandler(defaultMenuItem_Click); |
||
68 | _ContextMenu = new ContextMenu(); |
||
69 | _ContextMenu.MenuItems.Add("Wear", clickHandler); |
||
70 | _ContextMenu.MenuItems.Add("Detach", clickHandler); |
||
71 | |||
72 | this.NodeMouseClick += new TreeNodeMouseClickEventHandler(InventoryTree_NodeMouseClick); |
||
73 | this.BeforeExpand += new TreeViewCancelEventHandler(InventoryTree_BeforeExpand); |
||
74 | } |
||
75 | |||
76 | /// <summary> |
||
77 | /// TreeView control for the specified client's inventory |
||
78 | /// </summary> |
||
79 | /// <param name="client"></param> |
||
80 | public InventoryTree(GridClient client) : this () |
||
81 | { |
||
82 | InitializeClient(client); |
||
83 | } |
||
84 | |||
85 | /// <summary> |
||
86 | /// Thread-safe method for clearing the TreeView control |
||
87 | /// </summary> |
||
88 | public void ClearNodes() |
||
89 | { |
||
90 | if (this.InvokeRequired) this.BeginInvoke((MethodInvoker)delegate { ClearNodes(); }); |
||
91 | else this.Nodes.Clear(); |
||
92 | } |
||
93 | |||
94 | /// <summary> |
||
95 | /// Thread-safe method for collapsing a TreeNode in the control |
||
96 | /// </summary> |
||
97 | /// <param name="node"></param> |
||
98 | public void CollapseNode(TreeNode node) |
||
99 | { |
||
100 | if (this.InvokeRequired) this.BeginInvoke((MethodInvoker)delegate { CollapseNode(node); }); |
||
101 | else if (!node.IsExpanded) node.Collapse(); |
||
102 | } |
||
103 | |||
104 | /// <summary> |
||
105 | /// Thread-safe method for expanding a TreeNode in the control |
||
106 | /// </summary> |
||
107 | /// <param name="node"></param> |
||
108 | public void ExpandNode(TreeNode node) |
||
109 | { |
||
110 | if (this.InvokeRequired) this.BeginInvoke((MethodInvoker)delegate { ExpandNode(node); }); |
||
111 | else if (!node.IsExpanded) node.Expand(); |
||
112 | } |
||
113 | |||
114 | /// <summary> |
||
115 | /// Thread-safe method for updating the contents of the specified folder UUID |
||
116 | /// </summary> |
||
117 | /// <param name="folderID"></param> |
||
118 | public void UpdateFolder(UUID folderID) |
||
119 | { |
||
120 | if (this.InvokeRequired) this.BeginInvoke((MethodInvoker)delegate { UpdateFolder(folderID); }); |
||
121 | else |
||
122 | { |
||
123 | TreeNode node = null; |
||
124 | TreeNodeCollection children; |
||
125 | |||
126 | if (folderID != Client.Inventory.Store.RootFolder.UUID) |
||
127 | { |
||
128 | TreeNode[] found = Nodes.Find(folderID.ToString(), true); |
||
129 | if (found.Length > 0) |
||
130 | { |
||
131 | node = found[0]; |
||
132 | children = node.Nodes; |
||
133 | } |
||
134 | else |
||
135 | { |
||
136 | Logger.Log("Received update for unknown TreeView node " + folderID, Helpers.LogLevel.Warning); |
||
137 | return; |
||
138 | } |
||
139 | } |
||
140 | else children = this.Nodes; |
||
141 | |||
142 | children.Clear(); |
||
143 | |||
144 | List<InventoryBase> contents = Client.Inventory.Store.GetContents(folderID); |
||
145 | if (contents.Count == 0) |
||
146 | { |
||
147 | TreeNode add = children.Add(null, "(empty)"); |
||
148 | add.ForeColor = Color.FromKnownColor(KnownColor.GrayText); |
||
149 | } |
||
150 | else |
||
151 | { |
||
152 | foreach (InventoryBase inv in contents) |
||
153 | { |
||
154 | string key = inv.UUID.ToString(); |
||
155 | |||
156 | children.Add(key, inv.Name); |
||
157 | if (inv is InventoryFolder) |
||
158 | { |
||
159 | children[key].Nodes.Add(null, "(loading...)").ForeColor = Color.FromKnownColor(KnownColor.GrayText); |
||
160 | } |
||
161 | } |
||
162 | } |
||
163 | } |
||
164 | } |
||
165 | |||
166 | private void InitializeClient(GridClient client) |
||
167 | { |
||
168 | _Client = client; |
||
169 | _Client.Inventory.FolderUpdated += Inventory_OnFolderUpdated; |
||
170 | _Client.Network.LoginProgress += Network_OnLogin; |
||
171 | } |
||
172 | |||
173 | private void defaultMenuItem_Click(object sender, EventArgs e) |
||
174 | { |
||
175 | MenuItem menuItem = (MenuItem)sender; |
||
176 | |||
177 | InventoryItem item = (InventoryItem)Client.Inventory.Store[_SelectedItemID]; |
||
178 | |||
179 | switch(menuItem.Text) |
||
180 | { |
||
181 | case "Wear": |
||
182 | { |
||
183 | Client.Appearance.Attach(item, AttachmentPoint.Default); |
||
184 | break; |
||
185 | } |
||
186 | case "Detach": |
||
187 | { |
||
188 | Client.Appearance.Detach(item); |
||
189 | break; |
||
190 | } |
||
191 | } |
||
192 | } |
||
193 | |||
194 | void Network_OnLogin(object sender, LoginProgressEventArgs e) |
||
195 | { |
||
196 | if (e.Status == LoginStatus.Success) |
||
197 | { |
||
198 | if (Client.Inventory.Store != null) |
||
199 | UpdateFolder(Client.Inventory.Store.RootFolder.UUID); |
||
200 | } |
||
201 | } |
||
202 | |||
203 | private void Inventory_OnFolderUpdated(object sender, FolderUpdatedEventArgs e) |
||
204 | { |
||
205 | UpdateFolder(e.FolderID); |
||
206 | } |
||
207 | |||
208 | void InventoryTree_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) |
||
209 | { |
||
210 | if (e.Button == MouseButtons.Right) |
||
211 | { |
||
212 | _SelectedItemID = new UUID(e.Node.Name); |
||
213 | _ContextMenu.Show(this, e.Location); |
||
214 | } |
||
215 | } |
||
216 | |||
217 | private void InventoryTree_BeforeExpand(object sender, TreeViewCancelEventArgs e) |
||
218 | { |
||
219 | InventoryFolder folder = (InventoryFolder)Client.Inventory.Store[new UUID(e.Node.Name)]; |
||
220 | Client.Inventory.RequestFolderContents(folder.UUID, _Client.Self.AgentID, true, true, InventorySortOrder.ByDate | InventorySortOrder.FoldersByName); |
||
221 | } |
||
222 | |||
223 | } |
||
224 | |||
225 | } |
||
226 |