corrade-vassal – Blame information for rev 1

Subversion Repositories:
Rev:
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;
29 using System.Collections.Generic;
30 using System.Drawing;
31 using System.Windows.Forms;
32  
33 namespace OpenMetaverse.GUI
34 {
35  
36 /// <summary>
37 /// ListView GUI component for viewing a client's group list
38 /// </summary>
39 public class GroupList : ListView
40 {
41 private GridClient _Client;
42 private ListColumnSorter _ColumnSorter = new ListColumnSorter();
43  
44 public delegate void GroupDoubleClickCallback(Group group);
45  
46 /// <summary>
47 /// Triggered when the user double clicks on a group in the list
48 /// </summary>
49 public event GroupDoubleClickCallback OnGroupDoubleClick;
50  
51 /// <summary>
52 /// Gets or sets the GridClient associated with this control
53 /// </summary>
54 public GridClient Client
55 {
56 get { return _Client; }
57 set { if (value != null) InitializeClient(value); }
58 }
59  
60 /// <summary>
61 /// TreeView control for an unspecified client's group list
62 /// </summary>
63 public GroupList()
64 {
65 ColumnHeader header1 = this.Columns.Add("Group");
66 header1.Width = this.Width + 20;
67  
68 this.DoubleBuffered = true;
69 this.ListViewItemSorter = _ColumnSorter;
70 this.View = View.Details;
71  
72 this.ColumnClick += new ColumnClickEventHandler(GroupList_ColumnClick);
73 this.DoubleClick += new System.EventHandler(GroupList_DoubleClick);
74 }
75  
76 /// <summary>
77 /// TreeView control for the specified client's group list
78 /// </summary>
79 public GroupList(GridClient client) : this()
80 {
81 InitializeClient(client);
82 }
83  
84 private void InitializeClient(GridClient client)
85 {
86 _Client = client;
87 _Client.Groups.CurrentGroups += Groups_CurrentGroups;
88 }
89  
90 void Groups_CurrentGroups(object sender, CurrentGroupsEventArgs e)
91 {
92 RefreshGroups(e.Groups);
93 }
94  
95 private void RefreshGroups(Dictionary<UUID, Group> groups)
96 {
97 if (this.InvokeRequired) this.BeginInvoke((MethodInvoker)delegate { RefreshGroups(groups); });
98 else
99 {
100 this.Items.Clear();
101 foreach (KeyValuePair<UUID, Group> group in groups)
102 this.Items.Add(group.Key.ToString(), group.Value.Name, null).Tag = group.Value;
103 }
104 }
105  
106 private void GroupList_ColumnClick(object sender, ColumnClickEventArgs e)
107 {
108 if ((_ColumnSorter.Ascending = (this.Sorting == SortOrder.Ascending))) this.Sorting = SortOrder.Descending;
109 else this.Sorting = SortOrder.Ascending;
110 this.ListViewItemSorter = _ColumnSorter;
111 }
112  
113 private void GroupList_DoubleClick(object sender, System.EventArgs e)
114 {
115 if (OnGroupDoubleClick != null)
116 {
117 ListView list = (ListView)sender;
118 if (list.SelectedItems.Count > 0 && list.SelectedItems[0].Tag is Group)
119 {
120 Group group = (Group)list.SelectedItems[0].Tag;
121 try { OnGroupDoubleClick(group); }
122 catch (Exception ex) { Logger.Log(ex.Message, Helpers.LogLevel.Error, Client, ex); }
123 }
124 }
125 }
126  
127 }
128 }