2 using System
.Collections
;
11 public delegate void TileHandler (Tiles
.Tile tile
);
13 public enum MatchType
{
19 public class GroupView
: VBox
{
21 public event TileHandler TileSelected
;
22 private Gtk
.SizeGroup tileSizeGroup
;
23 private Hashtable categories
;
24 private Gtk
.Widget selection
;
26 public GroupView () : base (false, 0)
28 categories
= new Hashtable ();
29 tileSizeGroup
= new Gtk
.SizeGroup (Gtk
.SizeGroupMode
.Both
);
32 foreach (Tiles
.TileGroupInfo info
in Tiles
.Utils
.GroupInfo
) {
34 if (info
.Group
== Tiles
.TileGroup
.Conversations
)
35 box
= new ConversationCategory (info
);
37 box
= new TileCategory (info
, tileSizeGroup
);
39 PackStart (box
, false, false, 0);
41 box
.CategoryToggle
+= OnCategoryToggle
;
42 categories
[info
.Group
] = box
;
45 // FIXME: Add the Best match category
48 public void AddHit (Tiles
.Tile tile
)
51 tile
.Selected
+= OnTileSelected
;
53 Category box
= (Category
)categories
[tile
.Group
];
56 if (GroupInScope (tile
.Group
))
60 public void SubtractHit (Uri uri
)
62 foreach (Category box
in categories
.Values
) {
63 foreach (Tile tile
in box
.AllTiles
) {
64 if (tile
.Hit
.Uri
.Equals (uri
)) {
65 if (tile
.State
== StateType
.Selected
)
66 OnTileSelected (null, EventArgs
.Empty
);
74 public void Finished (bool grabFocus
)
76 Category first
= null;
79 foreach (Category category
in categories
.Values
) {
80 if (category
.Visible
) {
91 first
.Select (grabFocus
, !others
);
94 public MatchType MatchState
{
96 bool hiddenMatches
= false;
97 foreach (Category category
in categories
.Values
) {
99 return MatchType
.Matched
;
100 else if (!category
.Empty
)
101 hiddenMatches
= true;
104 return hiddenMatches
? MatchType
.NoneInScope
: MatchType
.None
;
108 private void OnTileSelected (object tile
, EventArgs args
)
110 if (tile
== selection
)
113 if (TileSelected
!= null)
114 TileSelected ((Tiles
.Tile
)tile
);
116 if (selection
!= null)
117 selection
.State
= StateType
.Normal
;
118 selection
= (Gtk
.Widget
)tile
;
119 if (selection
!= null)
120 selection
.State
= StateType
.Selected
;
123 private ScopeType scope
;
124 public ScopeType Scope
{
127 foreach (TileGroup
group in categories
.Keys
) {
128 Category category
= (Category
)categories
[group];
129 if (!GroupInScope (group))
130 category
.Expanded
= false;
131 else if (!category
.Empty
)
132 category
.Expanded
= true;
137 private bool GroupInScope (TileGroup
group)
139 ScopeType scopetype
= Utils
.TileGroupToScopeType (group);
141 return (scope
& scopetype
) == scopetype
;
144 public SortType Sort
{
146 foreach (Category category
in categories
.Values
)
147 category
.Sort
= value;
153 foreach (Category box
in categories
.Values
) {
159 private void OnCategoryToggle (ScopeType catScope
)
161 // we're not using the set function cause we directly
162 // close/open the expander in Category.cs
163 scope
= scope ^ catScope
;
164 CategoryToggled (catScope
);
167 public delegate void CategoryToggledDelegate (ScopeType catScope
);
168 public event CategoryToggledDelegate CategoryToggled
;