Move the sort items to a View menu and add a show details toggle. Patch from
[beagle.git] / search / UIManager.cs
blobabbec87497182b7554a6ca2c083d7dfc4df3c6ae
1 using Gtk;
2 using Mono.Unix;
3 using System;
4 using System.Diagnostics;
6 using Beagle.Util;
8 namespace Search {
10 public enum ScopeType {
11 Everywhere,
12 Applications,
13 Calendar,
14 Contacts,
15 Documents,
16 Conversations,
17 Images,
18 Media
21 public enum SortType {
22 Relevance,
23 Name,
24 Modified
27 public class UIManager : Gtk.UIManager {
29 private MainWindow main_window;
31 private Gtk.ActionGroup actions;
32 private Gtk.RadioActionEntry[] scope_entries, sort_entries;
33 private Gtk.ToggleActionEntry[] view_entries;
35 public UIManager (MainWindow main_window)
37 this.main_window = main_window;
39 actions = new ActionGroup ("Actions");
41 ActionEntry quit_action_entry;
42 if (MainWindow.IconEnabled) {
43 quit_action_entry = new ActionEntry ("Quit", Gtk.Stock.Close,
44 null, "<control>Q",
45 Catalog.GetString ("Close Desktop Search"),
46 Quit);
47 } else {
48 quit_action_entry = new ActionEntry ("Quit", Gtk.Stock.Quit,
49 null, "<control>Q",
50 Catalog.GetString ("Exit Desktop Search"),
51 Quit);
55 Gtk.ActionEntry[] entries = new ActionEntry[] {
56 new ActionEntry ("Search", null,
57 Catalog.GetString ("_Search"),
58 null, null, null),
59 new ActionEntry ("Actions", null,
60 Catalog.GetString ("_Actions"),
61 null, null, null),
62 new ActionEntry ("View", null,
63 Catalog.GetString ("_View"),
64 null, null, null),
65 new ActionEntry ("Help", null,
66 Catalog.GetString ("_Help"),
67 null, null, null),
69 quit_action_entry,
70 new ActionEntry ("Preferences", Gtk.Stock.Preferences,
71 null, null,
72 Catalog.GetString ("Exit Desktop Search"),
73 Preferences),
74 new ActionEntry ("Contents", Gtk.Stock.Help,
75 Catalog.GetString ("_Contents"),
76 "F1",
77 Catalog.GetString ("Help - Table of Contents"),
78 Help),
79 new ActionEntry ("About", Gnome.Stock.About,
80 null, null,
81 Catalog.GetString ("About Desktop Search"),
82 About),
83 new ActionEntry ("QuickTips", null,
84 Catalog.GetString ("Quick Tips"),
85 null, null, QuickTips),
86 new ActionEntry ("FocusSearchEntry", null, "",
87 "<control>K", null,
88 OnFocusSearchEntry),
89 new ActionEntry ("FocusSearchEntry2", null, "",
90 "<control>L", null,
91 OnFocusSearchEntry),
92 new ActionEntry ("HideWindow", null, "",
93 "Escape", null,
94 OnHideWindow),
95 new ActionEntry ("HideWindow2", null, "",
96 "<control>W", null,
97 OnHideWindow)
99 actions.Add (entries);
101 scope_entries = new RadioActionEntry[] {
102 new RadioActionEntry ("Everywhere", null,
103 Catalog.GetString ("_Everywhere"),
104 "<control>E",
105 Catalog.GetString ("Search everywhere"),
106 (int)ScopeType.Everywhere),
107 new RadioActionEntry ("Applications", null,
108 Catalog.GetString ("_Applications"),
109 null,
110 Catalog.GetString ("Search applications"),
111 (int)ScopeType.Applications),
112 new RadioActionEntry ("Contacts", null,
113 Catalog.GetString ("_Contacts"),
114 null,
115 Catalog.GetString ("Search contacts"),
116 (int)ScopeType.Contacts),
117 new RadioActionEntry ("Calendar", null,
118 Catalog.GetString ("Ca_lendar events"),
119 null,
120 Catalog.GetString ("Search calendar events"),
121 (int)ScopeType.Contacts),
122 new RadioActionEntry ("Documents", null,
123 Catalog.GetString ("_Documents"),
124 null,
125 Catalog.GetString ("Search documents"),
126 (int)ScopeType.Documents),
127 new RadioActionEntry ("Conversations", null,
128 Catalog.GetString ("Conve_rsations"),
129 null,
130 Catalog.GetString ("Search E-Mail and Instant Messaging logs"),
131 (int)ScopeType.Conversations),
132 new RadioActionEntry ("Images", null,
133 Catalog.GetString ("_Images"),
134 null,
135 Catalog.GetString ("Search images"),
136 (int)ScopeType.Images),
137 new RadioActionEntry ("Media", null,
138 Catalog.GetString ("_Media"),
139 null,
140 Catalog.GetString ("Search sound and video files"),
141 (int)ScopeType.Media),
143 actions.Add (scope_entries, (int)ScopeType.Everywhere, OnScopeChanged);
145 sort_entries = new RadioActionEntry[] {
146 new RadioActionEntry ("SortModified", null,
147 Catalog.GetString ("Sort by Date _Modified"), null,
148 Catalog.GetString ("Sort the most-recently-modified matches first"),
149 (int)SortType.Modified),
150 new RadioActionEntry ("SortName", null,
151 Catalog.GetString ("Sort by _Name"), null,
152 Catalog.GetString ("Sort matches by name"),
153 (int)SortType.Name),
154 new RadioActionEntry ("SortRelevance", null,
155 Catalog.GetString ("Sort by _Relevance"), null,
156 Catalog.GetString ("Sort the best matches first"),
157 (int)SortType.Relevance),
159 actions.Add (sort_entries, (int)SortType.Modified, OnSortChanged);
161 view_entries = new ToggleActionEntry[] {
162 new ToggleActionEntry ("ShowDetails", null,
163 Catalog.GetString ("Show Details"), null, null,
164 OnToggleDetails, true)
166 actions.Add (view_entries);
168 InsertActionGroup (actions, 0);
169 main_window.AddAccelGroup (AccelGroup);
170 AddUiFromString (ui_def);
173 public Gtk.MenuBar MenuBar {
174 get {
175 return (Gtk.MenuBar)GetWidget ("/MenuBar");
179 private bool sensitive = true;
180 public bool Sensitive {
181 get { return this.sensitive; }
182 set {
183 this.sensitive = value;
185 actions ["QuickTips"].Sensitive = value;
187 foreach (Gtk.RadioActionEntry rae in scope_entries)
188 actions [rae.name].Sensitive = value;
190 foreach (Gtk.RadioActionEntry rae in sort_entries)
191 actions [rae.name].Sensitive = value;
195 private const string ui_def =
196 "<ui>" +
197 " <menubar name='MenuBar'>" +
198 " <menu action='Search'>" +
199 " <menuitem action='Everywhere'/>" +
200 " <menuitem action='Applications'/>" +
201 " <menuitem action='Contacts'/>" +
202 " <menuitem action='Calendar'/>" +
203 " <menuitem action='Documents'/>" +
204 " <menuitem action='Conversations'/>" +
205 " <menuitem action='Images'/>" +
206 " <menuitem action='Media'/>" +
207 " <separator/>" +
208 " <menuitem action='Preferences'/>" +
209 " <menuitem action='Quit'/>" +
210 " </menu>" +
211 " <menu action='Actions'>" +
212 " </menu>" +
213 " <menu action='View'>" +
214 " <menuitem action='SortModified'/>" +
215 " <menuitem action='SortName'/>" +
216 " <menuitem action='SortRelevance'/>" +
217 " <separator/>" +
218 " <menuitem action='ShowDetails'/>" +
219 " </menu>" +
220 " <menu action='Help'>" +
221 " <menuitem action='Contents'/>" +
222 " <menuitem action='QuickTips'/>" +
223 " <menuitem action='About'/>" +
224 " </menu>" +
225 " </menubar>" +
226 " <accelerator action='FocusSearchEntry'/>" +
227 " <accelerator action='FocusSearchEntry2'/>" +
228 " <accelerator action='HideWindow'/>" +
229 " <accelerator action='HideWindow2'/>" +
230 "</ui>";
232 private void Preferences (object obj, EventArgs args)
234 Process p = new Process ();
235 p.StartInfo.UseShellExecute = false;
236 p.StartInfo.FileName = "beagle-settings";
238 try {
239 p.Start ();
240 } catch (Exception e) {
241 Console.WriteLine ("Could not start beagle-settings: {0}", e);
245 public delegate void ToggleDetailsDelegate (bool active);
246 public event ToggleDetailsDelegate ToggleDetails;
248 private void OnToggleDetails (object obj, EventArgs args)
250 if (ToggleDetails != null)
251 ToggleDetails ((obj as ToggleAction).Active);
254 public delegate void ShowQuickTipsDelegate ();
255 public event ShowQuickTipsDelegate ShowQuickTips;
257 private void QuickTips (object obj, EventArgs args)
259 if (ShowQuickTips != null)
260 ShowQuickTips ();
263 private void OnHideWindow (object obj, EventArgs args)
265 if (MainWindow.IconEnabled)
266 main_window.Hide ();
269 private void Quit (object obj, EventArgs args)
271 if (MainWindow.IconEnabled) {
272 main_window.Hide ();
273 } else {
274 Gtk.Application.Quit ();
278 private void Help (object obj, EventArgs args)
280 string address = "http://www.beagle-project.org/Getting_Started";
282 try {
283 Gnome.Url.Show (address);
284 } catch {
285 HigMessageDialog md = new HigMessageDialog (main_window, Gtk.DialogFlags.DestroyWithParent,
286 Gtk.MessageType.Error, Gtk.ButtonsType.Close,
287 Catalog.GetString ("Couldn't launch web browser"),
288 Catalog.GetString (String.Format ("Please point your web browser to '{0}' manually", address)));
289 md.Run ();
290 md.Destroy ();
294 private void About (object obj, EventArgs args)
296 Gdk.Pixbuf logo = Beagle.Images.GetPixbuf ("system-search.png");
298 string[] people = new string[] { "Anna Dirks <anna@novell.com>",
299 "Fredrik Hedberg <fredrik@avafan.com>",
300 "Lukas Lipka <lukas@pmad.net>",
301 "Joe Shaw <joeshaw@novell.com>",
302 "Jakub Steiner <jimmac@novell.com>",
303 "Dan Winship <danw@novell.com>" };
305 #pragma warning disable 612 // don't warn that Gnome.About is deprecated
306 Gnome.About about = new Gnome.About ("Beagle Search",
307 Beagle.Util.ExternalStringsHack.Version,
308 "Copyright 2005-2006 Novell, Inc.",
309 null, people, null, null,
310 logo);
311 about.Run ();
312 about.Dispose ();
313 #pragma warning restore 612
316 private void OnFocusSearchEntry (object obj, EventArgs args)
318 if (FocusSearchEntry != null)
319 FocusSearchEntry ();
322 public delegate void FocusSearchEntryDelegate ();
323 public event FocusSearchEntryDelegate FocusSearchEntry;
325 private void OnScopeChanged (object obj, Gtk.ChangedArgs args)
327 if (ScopeChanged != null)
328 ScopeChanged ((ScopeType)args.Current.CurrentValue);
331 public delegate void ScopeChangedDelegate (ScopeType scope);
332 public event ScopeChangedDelegate ScopeChanged;
334 private void OnSortChanged (object obj, Gtk.ChangedArgs args)
336 if (SortChanged != null)
337 SortChanged ((SortType)args.Current.CurrentValue);
340 public delegate void SortChangedDelegate (SortType scope);
341 public event SortChangedDelegate SortChanged;