4 using System
.Diagnostics
;
8 public enum ScopeType
{
19 public enum SortType
{
25 public class UIManager
: Gtk
.UIManager
{
27 private MainWindow main_window
;
29 private Gtk
.ActionGroup actions
;
30 private Gtk
.RadioActionEntry
[] scope_entries
, sort_entries
;
32 public UIManager (MainWindow main_window
)
34 this.main_window
= main_window
;
36 actions
= new ActionGroup ("Actions");
38 ActionEntry quit_action_entry
;
39 if (MainWindow
.IconEnabled
) {
40 quit_action_entry
= new ActionEntry ("Quit", Gtk
.Stock
.Close
,
42 Catalog
.GetString ("Close Desktop Search"),
45 quit_action_entry
= new ActionEntry ("Quit", Gtk
.Stock
.Quit
,
47 Catalog
.GetString ("Exit Desktop Search"),
52 Gtk
.ActionEntry
[] entries
= new ActionEntry
[] {
53 new ActionEntry ("Search", null,
54 Catalog
.GetString ("_Search"),
56 new ActionEntry ("Actions", null,
57 Catalog
.GetString ("_Actions"),
59 new ActionEntry ("SortBy", null,
60 Catalog
.GetString ("Sor_t"),
62 new ActionEntry ("Help", null,
63 Catalog
.GetString ("_Help"),
67 new ActionEntry ("Preferences", Gtk
.Stock
.Preferences
,
69 Catalog
.GetString ("Exit Desktop Search"),
71 new ActionEntry ("Contents", Gtk
.Stock
.Help
,
72 Catalog
.GetString ("_Contents"),
74 Catalog
.GetString ("Help - Table of Contents"),
76 new ActionEntry ("About", Gnome
.Stock
.About
,
78 Catalog
.GetString ("About Desktop Search"),
80 new ActionEntry ("QuickTips", null,
81 Catalog
.GetString ("Quick Tips"),
82 null, null, QuickTips
),
83 new ActionEntry ("FocusSearchEntry", null, "",
86 new ActionEntry ("FocusSearchEntry2", null, "",
89 new ActionEntry ("HideWindow", null, "",
92 new ActionEntry ("HideWindow2", null, "",
96 actions
.Add (entries
);
98 scope_entries
= new RadioActionEntry
[] {
99 new RadioActionEntry ("Everywhere", null,
100 Catalog
.GetString ("_Everywhere"),
102 Catalog
.GetString ("Search everywhere"),
103 (int)ScopeType
.Everywhere
),
104 new RadioActionEntry ("Applications", null,
105 Catalog
.GetString ("_Applications"),
107 Catalog
.GetString ("Search applications"),
108 (int)ScopeType
.Applications
),
109 new RadioActionEntry ("Contacts", null,
110 Catalog
.GetString ("_Contacts"),
112 Catalog
.GetString ("Search contacts"),
113 (int)ScopeType
.Contacts
),
114 new RadioActionEntry ("Calendar", null,
115 Catalog
.GetString ("Ca_lendar events"),
117 Catalog
.GetString ("Search calendar events"),
118 (int)ScopeType
.Contacts
),
119 new RadioActionEntry ("Documents", null,
120 Catalog
.GetString ("_Documents"),
122 Catalog
.GetString ("Search documents"),
123 (int)ScopeType
.Documents
),
124 new RadioActionEntry ("Conversations", null,
125 Catalog
.GetString ("Conve_rsations"),
127 Catalog
.GetString ("Search E-Mail and Instant Messaging logs"),
128 (int)ScopeType
.Conversations
),
129 new RadioActionEntry ("Images", null,
130 Catalog
.GetString ("_Images"),
132 Catalog
.GetString ("Search images"),
133 (int)ScopeType
.Images
),
134 new RadioActionEntry ("Media", null,
135 Catalog
.GetString ("_Media"),
137 Catalog
.GetString ("Search sound and video files"),
138 (int)ScopeType
.Media
),
140 actions
.Add (scope_entries
, (int)ScopeType
.Everywhere
, OnScopeChanged
);
142 sort_entries
= new RadioActionEntry
[] {
143 new RadioActionEntry ("Modified", null,
144 Catalog
.GetString ("Date _Modified"), null,
145 Catalog
.GetString ("Sort the most-recently-modified matches first"),
146 (int)SortType
.Modified
),
147 new RadioActionEntry ("Name", null,
148 Catalog
.GetString ("_Name"), null,
149 Catalog
.GetString ("Sort matches by name"),
151 new RadioActionEntry ("Relevance", null,
152 Catalog
.GetString ("_Relevance"), null,
153 Catalog
.GetString ("Sort the best matches first"),
154 (int)SortType
.Relevance
),
156 actions
.Add (sort_entries
, (int)SortType
.Modified
, OnSortChanged
);
158 InsertActionGroup (actions
, 0);
159 main_window
.AddAccelGroup (AccelGroup
);
160 AddUiFromString (ui_def
);
163 public Gtk
.MenuBar MenuBar
{
165 return (Gtk
.MenuBar
)GetWidget ("/MenuBar");
169 private bool sensitive
= true;
170 public bool Sensitive
{
171 get { return this.sensitive; }
173 this.sensitive
= value;
175 actions
["QuickTips"].Sensitive
= value;
177 foreach (Gtk
.RadioActionEntry rae
in scope_entries
)
178 actions
[rae
.name
].Sensitive
= value;
180 foreach (Gtk
.RadioActionEntry rae
in sort_entries
)
181 actions
[rae
.name
].Sensitive
= value;
185 private const string ui_def
=
187 " <menubar name='MenuBar'>" +
188 " <menu action='Search'>" +
189 " <menuitem action='Everywhere'/>" +
190 " <menuitem action='Applications'/>" +
191 " <menuitem action='Contacts'/>" +
192 " <menuitem action='Calendar'/>" +
193 " <menuitem action='Documents'/>" +
194 " <menuitem action='Conversations'/>" +
195 " <menuitem action='Images'/>" +
196 " <menuitem action='Media'/>" +
198 " <menuitem action='Preferences'/>" +
199 " <menuitem action='Quit'/>" +
201 " <menu action='Actions'>" +
203 " <menu action='SortBy'>" +
204 " <menuitem action='Modified'/>" +
205 " <menuitem action='Name'/>" +
206 " <menuitem action='Relevance'/>" +
208 " <menu action='Help'>" +
209 " <menuitem action='Contents'/>" +
210 " <menuitem action='QuickTips'/>" +
211 " <menuitem action='About'/>" +
214 " <accelerator action='FocusSearchEntry'/>" +
215 " <accelerator action='FocusSearchEntry2'/>" +
216 " <accelerator action='HideWindow'/>" +
217 " <accelerator action='HideWindow2'/>" +
220 private void Preferences (object obj
, EventArgs args
)
222 Process p
= new Process ();
223 p
.StartInfo
.UseShellExecute
= false;
224 p
.StartInfo
.FileName
= "beagle-settings";
228 } catch (Exception e
) {
229 Console
.WriteLine ("Could not start beagle-settings: {0}", e
);
233 public delegate void ShowQuickTipsDelegate ();
234 public event ShowQuickTipsDelegate ShowQuickTips
;
236 private void QuickTips (object obj
, EventArgs args
)
238 if (ShowQuickTips
!= null)
242 private void OnHideWindow (object obj
, EventArgs args
)
244 if (MainWindow
.IconEnabled
)
248 private void Quit (object obj
, EventArgs args
)
250 if (MainWindow
.IconEnabled
) {
253 Gtk
.Application
.Quit ();
257 private void Help (object obj
, EventArgs args
)
259 Gnome
.Url
.Show ("http://www.beagle-project.org/Getting_Started");
262 private void About (object obj
, EventArgs args
)
264 Gdk
.Pixbuf logo
= Beagle
.Images
.GetPixbuf ("system-search.png");
266 string[] people
= new string[] { "Anna Dirks <anna@novell.com>",
267 "Fredrik Hedberg <fredrik@avafan.com>",
268 "Lukas Lipka <lukas@pmad.net>",
269 "Joe Shaw <joeshaw@novell.com>",
270 "Jakub Steiner <jimmac@novell.com>",
271 "Dan Winship <danw@novell.com>" };
273 #pragma warning disable 612 // don't warn that Gnome.About is deprecated
274 Gnome
.About about
= new Gnome
.About ("Beagle Search",
275 Beagle
.Util
.ExternalStringsHack
.Version
,
276 "Copyright 2005-2006 Novell, Inc.",
277 null, people
, null, null,
281 #pragma warning restore 612
284 private void OnFocusSearchEntry (object obj
, EventArgs args
)
286 if (FocusSearchEntry
!= null)
290 public delegate void FocusSearchEntryDelegate ();
291 public event FocusSearchEntryDelegate FocusSearchEntry
;
293 private void OnScopeChanged (object obj
, Gtk
.ChangedArgs args
)
295 if (ScopeChanged
!= null)
296 ScopeChanged ((ScopeType
)args
.Current
.CurrentValue
);
299 public delegate void ScopeChangedDelegate (ScopeType scope
);
300 public event ScopeChangedDelegate ScopeChanged
;
302 private void OnSortChanged (object obj
, Gtk
.ChangedArgs args
)
304 if (SortChanged
!= null)
305 SortChanged ((SortType
)args
.Current
.CurrentValue
);
308 public delegate void SortChangedDelegate (SortType scope
);
309 public event SortChangedDelegate SortChanged
;