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
.Name
, info
.Rows
);
37 box
= new TileCategory (info
.Name
, info
.Rows
, tileSizeGroup
);
39 PackStart (box
, false, false, 0);
41 categories
[info
.Group
] = box
;
44 // FIXME: Add the Best match category
47 public void AddHit (Tiles
.Tile tile
)
50 tile
.Selected
+= OnTileSelected
;
51 tile
.Deselected
+= OnTileDeselected
;
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
)) {
72 public void Finished (bool grabFocus
)
74 Category first
= null;
77 foreach (Category category
in categories
.Values
) {
78 if (category
.Visible
) {
89 first
.Select (grabFocus
, !others
);
92 public MatchType MatchState
{
94 bool hiddenMatches
= false;
95 foreach (Category category
in categories
.Values
) {
97 return MatchType
.Matched
;
98 else if (!category
.Empty
)
102 return hiddenMatches
? MatchType
.NoneInScope
: MatchType
.None
;
106 private void OnTileSelected (object tile
, EventArgs args
)
108 if (tile
== selection
)
111 if (TileSelected
!= null)
112 TileSelected ((Tiles
.Tile
)tile
);
114 if (selection
!= null)
115 selection
.State
= StateType
.Normal
;
116 selection
= (Gtk
.Widget
)tile
;
117 if (selection
!= null)
118 selection
.State
= StateType
.Selected
;
121 private void OnTileDeselected (object tile
, EventArgs args
)
123 if (tile
!= selection
)
125 OnTileSelected (null, args
);
128 private ScopeType scope
;
129 public ScopeType Scope
{
132 foreach (TileGroup
group in categories
.Keys
) {
133 Category category
= (Category
)categories
[group];
134 if (!GroupInScope (group))
136 else if (!category
.Empty
)
142 private bool GroupInScope (TileGroup
group)
145 case ScopeType
.Everywhere
:
148 case ScopeType
.Applications
:
149 return group == TileGroup
.Application
;
151 case ScopeType
.Contacts
:
152 return group == TileGroup
.Contact
;
154 case ScopeType
.Documents
:
155 return group == TileGroup
.Documents
;
157 case ScopeType
.Conversations
:
158 return group == TileGroup
.Conversations
;
160 case ScopeType
.Images
:
161 return group == TileGroup
.Image
;
163 case ScopeType
.Media
:
164 return group == TileGroup
.Audio
|| group == TileGroup
.Video
;
170 public SortType Sort
{
172 foreach (Category category
in categories
.Values
)
173 category
.Sort
= value;
179 foreach (Category box
in categories
.Values
) {