Added FilterDeb from Kevin Kubasik.
[beagle.git] / search / UIManager.cs
blobd20381f62a84303c6c22fd3d9993f357eb820052
1 using Gtk;
2 using Mono.Unix;
3 using System;
4 using System.Diagnostics;
6 namespace Search {
8 public enum ScopeType {
9 Everywhere,
10 Applications,
11 Contacts,
12 Documents,
13 Conversations,
14 Images,
15 Media
18 public enum SortType {
19 Relevance,
20 Name,
21 Modified
24 public class UIManager : Gtk.UIManager {
26 private MainWindow main_window;
28 private Gtk.ActionGroup actions;
29 private Gtk.RadioActionEntry[] scope_entries, sort_entries;
31 public UIManager (MainWindow main_window)
33 this.main_window = main_window;
35 actions = new ActionGroup ("Actions");
37 ActionEntry quit_action_entry;
38 if (MainWindow.IconEnabled) {
39 quit_action_entry = new ActionEntry ("Quit", Gtk.Stock.Close,
40 null, "<control>Q",
41 Catalog.GetString ("Close Desktop Search"),
42 Quit);
43 } else {
44 quit_action_entry = new ActionEntry ("Quit", Gtk.Stock.Quit,
45 null, "<control>Q",
46 Catalog.GetString ("Exit Desktop Search"),
47 Quit);
51 Gtk.ActionEntry[] entries = new ActionEntry[] {
52 new ActionEntry ("Search", null,
53 Catalog.GetString ("_Search"),
54 null, null, null),
55 new ActionEntry ("Actions", null,
56 Catalog.GetString ("_Actions"),
57 null, null, null),
58 new ActionEntry ("SortBy", null,
59 Catalog.GetString ("Sor_t"),
60 null, null, null),
61 new ActionEntry ("Help", null,
62 Catalog.GetString ("_Help"),
63 null, null, null),
65 quit_action_entry,
66 new ActionEntry ("Preferences", Gtk.Stock.Preferences,
67 null, null,
68 Catalog.GetString ("Exit Desktop Search"),
69 Preferences),
70 new ActionEntry ("Contents", Gtk.Stock.Help,
71 Catalog.GetString ("_Contents"),
72 "F1",
73 Catalog.GetString ("Help - Table of Contents"),
74 Help),
75 new ActionEntry ("About", Gnome.Stock.About,
76 null, null,
77 Catalog.GetString ("About Desktop Search"),
78 About),
79 new ActionEntry ("QuickTips", null,
80 Catalog.GetString ("Quick Tips"),
81 null, null, QuickTips),
82 new ActionEntry ("FocusSearchEntry", null, "",
83 "<control>K", null,
84 OnFocusSearchEntry),
85 new ActionEntry ("FocusSearchEntry2", null, "",
86 "<control>L", null,
87 OnFocusSearchEntry),
88 new ActionEntry ("HideWindow", null, "",
89 "Escape", null,
90 Quit),
91 new ActionEntry ("HideWindow2", null, "",
92 "<control>W", null,
93 Quit)
95 actions.Add (entries);
97 scope_entries = new RadioActionEntry[] {
98 new RadioActionEntry ("Everywhere", null,
99 Catalog.GetString ("_Everywhere"),
100 "<control>E",
101 Catalog.GetString ("Search everywhere"),
102 (int)ScopeType.Everywhere),
103 new RadioActionEntry ("Applications", null,
104 Catalog.GetString ("_Applications"),
105 null,
106 Catalog.GetString ("Search applications"),
107 (int)ScopeType.Applications),
108 new RadioActionEntry ("Contacts", null,
109 Catalog.GetString ("_Contacts"),
110 null,
111 Catalog.GetString ("Search contacts"),
112 (int)ScopeType.Contacts),
113 new RadioActionEntry ("Documents", null,
114 Catalog.GetString ("_Documents"),
115 null,
116 Catalog.GetString ("Search documents"),
117 (int)ScopeType.Documents),
118 new RadioActionEntry ("Conversations", null,
119 Catalog.GetString ("Conve_rsations"),
120 null,
121 Catalog.GetString ("Search E-Mail and Instant Messaging logs"),
122 (int)ScopeType.Conversations),
123 new RadioActionEntry ("Images", null,
124 Catalog.GetString ("Images"),
125 null,
126 Catalog.GetString ("Search images"),
127 (int)ScopeType.Images),
128 new RadioActionEntry ("Media", null,
129 Catalog.GetString ("Media"),
130 null,
131 Catalog.GetString ("Search sound and video files"),
132 (int)ScopeType.Media),
134 actions.Add (scope_entries, (int)ScopeType.Everywhere, OnScopeChanged);
136 sort_entries = new RadioActionEntry[] {
137 new RadioActionEntry ("Modified", null,
138 Catalog.GetString ("Date _Modified"), null,
139 Catalog.GetString ("Sort the most-recently-modified matches first"),
140 (int)SortType.Modified),
141 new RadioActionEntry ("Name", null,
142 Catalog.GetString ("_Name"), null,
143 Catalog.GetString ("Sort matches by name"),
144 (int)SortType.Name),
145 new RadioActionEntry ("Relevance", null,
146 Catalog.GetString ("_Relevance"), null,
147 Catalog.GetString ("Sort the best matches first"),
148 (int)SortType.Relevance),
150 actions.Add (sort_entries, (int)SortType.Modified, OnSortChanged);
152 InsertActionGroup (actions, 0);
153 main_window.AddAccelGroup (AccelGroup);
154 AddUiFromString (ui_def);
157 public Gtk.MenuBar MenuBar {
158 get {
159 return (Gtk.MenuBar)GetWidget ("/MenuBar");
163 private bool sensitive = true;
164 public bool Sensitive {
165 get { return this.sensitive; }
166 set {
167 this.sensitive = value;
169 actions ["QuickTips"].Sensitive = value;
171 foreach (Gtk.RadioActionEntry rae in scope_entries)
172 actions [rae.name].Sensitive = value;
174 foreach (Gtk.RadioActionEntry rae in sort_entries)
175 actions [rae.name].Sensitive = value;
179 private const string ui_def =
180 "<ui>" +
181 " <menubar name='MenuBar'>" +
182 " <menu action='Search'>" +
183 " <menuitem action='Everywhere'/>" +
184 " <menuitem action='Applications'/>" +
185 " <menuitem action='Contacts'/>" +
186 " <menuitem action='Documents'/>" +
187 " <menuitem action='Conversations'/>" +
188 " <menuitem action='Images'/>" +
189 " <menuitem action='Media'/>" +
190 " <separator/>" +
191 " <menuitem action='Preferences'/>" +
192 " <menuitem action='Quit'/>" +
193 " </menu>" +
194 " <menu action='Actions'>" +
195 " </menu>" +
196 " <menu action='SortBy'>" +
197 " <menuitem action='Modified'/>" +
198 " <menuitem action='Name'/>" +
199 " <menuitem action='Relevance'/>" +
200 " </menu>" +
201 " <menu action='Help'>" +
202 " <menuitem action='Contents'/>" +
203 " <menuitem action='QuickTips'/>" +
204 " <menuitem action='About'/>" +
205 " </menu>" +
206 " </menubar>" +
207 " <accelerator action='FocusSearchEntry'/>" +
208 " <accelerator action='FocusSearchEntry2'/>" +
209 " <accelerator action='HideWindow'/>" +
210 " <accelerator action='HideWindow2'/>" +
211 "</ui>";
213 private void Preferences (object obj, EventArgs args)
215 Process p = new Process ();
216 p.StartInfo.UseShellExecute = false;
217 p.StartInfo.FileName = "beagle-settings";
219 try {
220 p.Start ();
221 } catch (Exception e) {
222 Console.WriteLine ("Could not start beagle-settings: {0}", e);
226 public delegate void ShowQuickTipsDelegate ();
227 public event ShowQuickTipsDelegate ShowQuickTips;
229 private void QuickTips (object obj, EventArgs args)
231 if (ShowQuickTips != null)
232 ShowQuickTips ();
235 private void Quit (object obj, EventArgs args)
237 if (MainWindow.IconEnabled) {
238 main_window.Hide ();
239 } else {
240 Gtk.Application.Quit ();
244 private void Help (object obj, EventArgs args)
246 Gnome.Url.Show ("http://www.beagle-project.org/Getting_Started");
249 private void About (object obj, EventArgs args)
251 Gdk.Pixbuf logo = Beagle.Images.GetPixbuf ("system-search.png");
253 string[] people = new string[] { "Anna Dirks <anna@novell.com>",
254 "Fredrik Hedberg <fredrik@avafan.com>",
255 "Lukas Lipka <lukas@pmad.net>",
256 "Joe Shaw <joeshaw@novell.com>",
257 "Jakub Steiner <jimmac@novell.com>",
258 "Dan Winship <danw@novell.com>" };
260 #pragma warning disable 612 // don't warn that Gnome.About is deprecated
261 Gnome.About about = new Gnome.About ("Beagle Search",
262 Beagle.Util.ExternalStringsHack.Version,
263 "Copyright 2005-2006 Novell, Inc.",
264 null, people, null, null,
265 logo);
266 about.Run ();
267 about.Dispose ();
268 #pragma warning restore 612
271 private void OnFocusSearchEntry (object obj, EventArgs args)
273 if (FocusSearchEntry != null)
274 FocusSearchEntry ();
277 public delegate void FocusSearchEntryDelegate ();
278 public event FocusSearchEntryDelegate FocusSearchEntry;
280 private void OnScopeChanged (object obj, Gtk.ChangedArgs args)
282 if (ScopeChanged != null)
283 ScopeChanged ((ScopeType)args.Current.CurrentValue);
286 public delegate void ScopeChangedDelegate (ScopeType scope);
287 public event ScopeChangedDelegate ScopeChanged;
289 private void OnSortChanged (object obj, Gtk.ChangedArgs args)
291 if (SortChanged != null)
292 SortChanged ((SortType)args.Current.CurrentValue);
295 public delegate void SortChangedDelegate (SortType scope);
296 public event SortChangedDelegate SortChanged;