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
;
52 Category box
= (Category
)categories
[tile
.Group
];
55 if (GroupInScope (tile
.Group
))
59 public void SubtractHit (Uri uri
)
61 foreach (Category box
in categories
.Values
) {
62 foreach (Tile tile
in box
.AllTiles
) {
63 if (tile
.Hit
.Uri
.Equals (uri
)) {
64 if (tile
.State
== StateType
.Selected
)
65 OnTileSelected (null, EventArgs
.Empty
);
73 public void Finished (bool grabFocus
)
75 Category first
= null;
78 foreach (Category category
in categories
.Values
) {
79 if (category
.Visible
) {
90 first
.Select (grabFocus
, !others
);
93 public MatchType MatchState
{
95 bool hiddenMatches
= false;
96 foreach (Category category
in categories
.Values
) {
98 return MatchType
.Matched
;
99 else if (!category
.Empty
)
100 hiddenMatches
= true;
103 return hiddenMatches
? MatchType
.NoneInScope
: MatchType
.None
;
107 private void OnTileSelected (object tile
, EventArgs args
)
109 if (tile
== selection
)
112 if (TileSelected
!= null)
113 TileSelected ((Tiles
.Tile
)tile
);
115 if (selection
!= null)
116 selection
.State
= StateType
.Normal
;
117 selection
= (Gtk
.Widget
)tile
;
118 if (selection
!= null)
119 selection
.State
= StateType
.Selected
;
122 private ScopeType scope
;
123 public ScopeType Scope
{
126 foreach (TileGroup
group in categories
.Keys
) {
127 Category category
= (Category
)categories
[group];
128 if (!GroupInScope (group))
130 else if (!category
.Empty
)
136 private bool GroupInScope (TileGroup
group)
139 case ScopeType
.Everywhere
:
142 case ScopeType
.Applications
:
143 return group == TileGroup
.Application
;
145 case ScopeType
.Calendar
:
146 return group == TileGroup
.Calendar
;
148 case ScopeType
.Contacts
:
149 return group == TileGroup
.Contact
;
151 case ScopeType
.Documents
:
152 return group == TileGroup
.Documents
;
154 case ScopeType
.Conversations
:
155 return group == TileGroup
.Conversations
;
157 case ScopeType
.Images
:
158 return group == TileGroup
.Image
;
160 case ScopeType
.Media
:
161 return group == TileGroup
.Audio
|| group == TileGroup
.Video
;
167 public SortType Sort
{
169 foreach (Category category
in categories
.Values
)
170 category
.Sort
= value;
176 foreach (Category box
in categories
.Values
) {