5 // Copyright 2004 Novell, Inc.
9 using System
.Collections
;
10 using System
.Diagnostics
;
11 using System
.Runtime
.InteropServices
;
24 // This class is from Tomboy, removed some functions which weren't needed
27 public static void GetMenuPosition (Gtk
.Menu menu
,
32 Gtk
.Requisition menu_req
= menu
.SizeRequest ();
34 menu
.AttachWidget
.GdkWindow
.GetOrigin (out x
, out y
);
36 if (y
+ menu_req
.Height
>= menu
.AttachWidget
.Screen
.Height
)
39 y
+= menu
.AttachWidget
.Allocation
.Height
;
44 static void DeactivateMenu (object sender
, EventArgs args
)
46 Gtk
.Menu menu
= (Gtk
.Menu
) sender
;
50 // Place the menu underneath an arbitrary parent widget. The
51 // parent widget must be set using menu.AttachToWidget before
53 public static void PopupMenu (Gtk
.Menu menu
, Gdk
.EventButton ev
)
55 menu
.Deactivated
+= DeactivateMenu
;
58 new Gtk
.MenuPositionFunc (GetMenuPosition
),
59 (ev
== null) ? 0 : ev
.Button
,
60 (ev
== null) ? Gtk
.Global
.CurrentEventTime
: ev
.Time
);
65 public class BestTray
: Gtk
.Plug
68 bool autostarted
= false;
70 Gtk
.EventBox eventbox
;
72 Beagle
.Util
.XKeybinder keybinder
;
74 [DllImport ("libbeagleuiglue")]
75 private static extern IntPtr
egg_tray_icon_new (string name
);
77 public BestTray (BestWindow bw
, bool autostarted
)
79 this.autostarted
= autostarted
;
81 Raw
= egg_tray_icon_new ("Search");
84 win
.DeleteEvent
+= new DeleteEventHandler (WindowDeleteEvent
);
86 eventbox
= new Gtk
.EventBox ();
87 eventbox
.CanFocus
= true;
88 eventbox
.ButtonPressEvent
+= new ButtonPressEventHandler (ButtonPress
);
90 Gdk
.Pixbuf smalldog
= Images
.GetPixbuf ("best.png");
91 eventbox
.Add (new Gtk
.Image (smalldog
.ScaleSimple (24, 24, Gdk
.InterpType
.Hyper
)));
93 KeyBinding binding
= Conf
.Searching
.ShowSearchWindowBinding
;
95 string tooltip
= String
.Format ("Beagle Search ({0})", binding
.ToReadableString ());
96 tips
= new Gtk
.Tooltips ();
97 tips
.SetTip (eventbox
, tooltip
, null);
103 keybinder
= new Beagle
.Util
.XKeybinder ();
104 keybinder
.Bind (binding
.ToString (),
105 new EventHandler (ShowBeaglePressed
));
108 private void ShowBeaglePressed (object o
, EventArgs args
)
110 if (!win
.WindowIsVisible
) {
118 void ButtonPress (object sender
, Gtk
.ButtonPressEventArgs args
)
120 Gdk
.EventButton eb
= args
.Event
;
121 if (eb
.Button
== 1) {
122 if (! win
.WindowIsVisible
) {
130 Gtk
.Menu recent_menu
= MakeMenu ((Gtk
.Widget
) sender
);
131 GuiUtils
.PopupMenu (recent_menu
, args
.Event
);
135 void WindowDeleteEvent (object sender
, DeleteEventArgs args
)
138 args
.RetVal
= (object)true;
141 void QuitEvent (object sender
, EventArgs args
)
144 HigMessageDialog dialog
= new HigMessageDialog (win
,
146 MessageType
.Question
,
148 Catalog
.GetString ("Disable Searching"),
149 Catalog
.GetString ("You are about to close the search tray. The search tray is automatically started at login-time. Would you like to disable it for future sessions?"));
151 Gtk
.ResponseType response
= (Gtk
.ResponseType
) dialog
.Run ();
153 if (response
== Gtk
.ResponseType
.Yes
) {
154 Conf
.Searching
.Autostart
= false;
157 // If the user doesn't want to have Best autostart, he probably doesn't
158 // want to keep the daemon around either. Bad call dude, bad call.
160 Process p
= new Process ();
161 p
.StartInfo
.UseShellExecute
= false;
162 p
.StartInfo
.FileName
= "beagle-shutdown";
166 } catch (Exception ex
) {}
169 win
.StoreSettingsInConf (true);
173 void QuickSearchEvent (object sender
, EventArgs args
)
175 string quickQuery
= (string) menu_to_query_map
[sender
];
177 if (! win
.WindowIsVisible
) {
179 win
.QuickSearch (quickQuery
);
181 win
.QuickSearch (quickQuery
);
186 private void ClearEvent (object sender
, EventArgs args
)
191 private void DetachWidget (Gtk
.Widget attach_widget
, Gtk
.Menu menu
)
195 Hashtable menu_to_query_map
= null;
197 private Gtk
.Menu
MakeMenu (Gtk
.Widget parent
)
199 Gtk
.Menu menu
= new Gtk
.Menu ();
200 menu
.AttachToWidget (parent
, new Gtk
.MenuDetachFunc (DetachWidget
));
202 Gtk
.ImageMenuItem item
;
204 // Quick Search menu items
205 ArrayList list
= win
.RetriveSearches ();
206 if (list
== null || list
.Count
== 0 ) {
207 item
= new Gtk
.ImageMenuItem (Catalog
.GetString ("No Recent Searches"));
208 item
.Sensitive
= false;
210 menu_to_query_map
= null;
212 item
= new Gtk
.ImageMenuItem (Catalog
.GetString ("Recent Searches"));
213 item
.Sensitive
= false;
214 item
.Image
= new Gtk
.Image (Images
.GetPixbuf ("icon-search.png"));
217 menu_to_query_map
= new Hashtable ();
219 foreach (string s
in list
) {
220 item
= new Gtk
.ImageMenuItem (s
);
221 item
.Activated
+= new EventHandler (QuickSearchEvent
);
223 menu_to_query_map
[item
] = s
;
227 if (list
!= null && list
.Count
> 0) {
228 item
= new Gtk
.ImageMenuItem (Catalog
.GetString ("Clear"));
229 item
.Image
= new Gtk
.Image (Gtk
.Stock
.Clear
, Gtk
.IconSize
.Menu
);
230 item
.Activated
+= new EventHandler (ClearEvent
);
234 menu
.Append (new Gtk
.SeparatorMenuItem ());
236 item
= new Gtk
.ImageMenuItem (Catalog
.GetString ("Quit"));
237 item
.Image
= new Gtk
.Image (Gtk
.Stock
.Quit
, Gtk
.IconSize
.Menu
);
238 item
.Activated
+= new EventHandler (QuitEvent
);