133
131
return base.OnLeaveNotifyEvent (ev);
137
public enum PanelOrientation { Horizontal, Vertical };
139
public class TomboyTray : Gtk.EventBox
136
public class TomboyTrayIcon : Gtk.StatusIcon
139
TomboyGConfXKeybinder keybinder;
141
public TomboyTrayIcon (NoteManager manager)
143
tray = new TomboyTray (manager, this);
144
keybinder = new TomboyGConfXKeybinder (manager, tray);
146
Pixbuf = GuiUtils.GetIcon ("tomboy", panel_size);
148
Tooltip = TomboyTrayUtils.GetToolTipText ();
151
public TomboyTray Tray
158
protected override void OnActivate()
163
protected override void OnPopupMenu (uint button, uint activate_time)
166
GuiUtils.PopupMenu (MakeRightClickMenu (),
168
new Gtk.MenuPositionFunc (GetTrayMenuPosition));
172
public void ShowMenu (bool select_first_item)
174
TomboyTrayUtils.UpdateTomboyTrayMenu (tray, null);
175
if (select_first_item)
176
tray.TomboyTrayMenu.SelectFirst (false);
180
GuiUtils.PopupMenu (tray.TomboyTrayMenu, null,
181
new Gtk.MenuPositionFunc (GetTrayMenuPosition));
184
public void GetTrayMenuPosition (Gtk.Menu menu,
189
// some default values in case something goes wrong
196
Gtk.Orientation orientation;
197
GetGeometry (out screen, out area, out orientation);
202
Gtk.Requisition menu_req = menu.SizeRequest ();
203
if (y + menu_req.Height >= screen.Height)
204
y -= menu_req.Height;
209
Gtk.Menu MakeRightClickMenu ()
211
Gtk.Menu menu = new Gtk.Menu ();
213
Gtk.AccelGroup accel_group = new Gtk.AccelGroup ();
214
menu.AccelGroup = accel_group;
216
Gtk.ImageMenuItem item;
218
item = new Gtk.ImageMenuItem (Catalog.GetString ("_Preferences"));
219
item.Image = new Gtk.Image (Gtk.Stock.Preferences, Gtk.IconSize.Menu);
220
item.Activated += ShowPreferences;
223
item = new Gtk.ImageMenuItem (Catalog.GetString ("_Help"));
224
item.Image = new Gtk.Image (Gtk.Stock.Help, Gtk.IconSize.Menu);
225
item.Activated += ShowHelpContents;
228
item = new Gtk.ImageMenuItem (Catalog.GetString ("_About Tomboy"));
229
item.Image = new Gtk.Image (Gtk.Stock.About, Gtk.IconSize.Menu);
230
item.Activated += ShowAbout;
233
menu.Append (new Gtk.SeparatorMenuItem ());
235
item = new Gtk.ImageMenuItem (Catalog.GetString ("_Quit"));
236
item.Image = new Gtk.Image (Gtk.Stock.Quit, Gtk.IconSize.Menu);
237
item.Activated += Quit;
244
void ShowPreferences (object sender, EventArgs args)
246
Tomboy.ActionManager ["ShowPreferencesAction"].Activate ();
249
void ShowHelpContents (object sender, EventArgs args)
251
Tomboy.ActionManager ["ShowHelpAction"].Activate ();
254
void ShowAbout (object sender, EventArgs args)
256
Tomboy.ActionManager ["ShowAboutAction"].Activate ();
259
void Quit (object sender, EventArgs args)
261
Tomboy.ActionManager ["QuitTomboyAction"].Activate ();
266
public class TomboyTray
141
268
NoteManager manager;
144
Gtk.Menu recent_menu;
269
TomboyTrayIcon tray_icon = null;
270
TomboyAppletEventBox applet_event_box = null;
145
271
bool menu_added = false;
146
272
List<Gtk.MenuItem> recent_notes = new List<Gtk.MenuItem> ();
149
public TomboyTray (NoteManager manager)
275
protected TomboyTray (NoteManager manager)
152
277
this.manager = manager;
153
// Load a 16x16-sized icon to ensure we don't end up with a
156
this.image = new Gtk.Image (GuiUtils.GetIcon ("tomboy", panel_size));
158
this.CanFocus = true;
159
this.ButtonPressEvent += ButtonPress;
163
string tip_text = Catalog.GetString ("Tomboy Notes");
165
if ((bool) Preferences.Get (Preferences.ENABLE_KEYBINDINGS)) {
167
GConfKeybindingToAccel.GetShortcut (
168
Preferences.KEYBINDING_SHOW_NOTE_MENU);
169
if (shortcut != null)
170
tip_text += String.Format (" ({0})", shortcut);
173
tips = new Gtk.Tooltips ();
174
tips.SetTip (this, tip_text, null);
180
recent_menu = MakeRecentNotesMenu ();
181
recent_menu.Hidden += MenuHidden;
184
void ButtonPress (object sender, Gtk.ButtonPressEventArgs args)
186
Gtk.Widget parent = (Gtk.Widget) sender;
188
switch (args.Event.Button) {
190
UpdateRecentNotesMenu (parent);
191
GuiUtils.PopupMenu (recent_menu, args.Event);
195
if ((bool) Preferences.Get (Preferences.ENABLE_ICON_PASTE)) {
196
// Give some visual feedback
197
Gtk.Drag.Highlight (this);
198
args.RetVal = PastePrimaryClipboard ();
199
Gtk.Drag.Unhighlight (this);
205
void PrependTimestampedText (Note note, DateTime timestamp, string text)
207
NoteBuffer buffer = note.Buffer;
208
StringBuilder insert_text = new StringBuilder ();
210
insert_text.Append ("\n"); // initial newline
211
string date_format = Catalog.GetString ("dddd, MMMM d, h:mm tt");
212
insert_text.Append (timestamp.ToString (date_format));
213
insert_text.Append ("\n"); // begin content
214
insert_text.Append (text);
215
insert_text.Append ("\n"); // trailing newline
217
buffer.Undoer.FreezeUndo ();
219
// Insert the date and list of links...
220
Gtk.TextIter cursor = buffer.StartIter;
221
cursor.ForwardLines (1); // skip title
223
buffer.Insert (ref cursor, insert_text.ToString ());
225
// Make the date string a small font...
226
cursor = buffer.StartIter;
227
cursor.ForwardLines (2); // skip title & leading newline
229
Gtk.TextIter end = cursor;
230
end.ForwardToLineEnd (); // end of date
232
buffer.ApplyTag ("datetime", cursor, end);
234
// Select the text we've inserted (avoid trailing newline)...
236
end.ForwardChars (insert_text.Length - 1);
238
buffer.MoveMark (buffer.SelectionBound, cursor);
239
buffer.MoveMark (buffer.InsertMark, end);
241
buffer.Undoer.ThawUndo ();
244
bool PastePrimaryClipboard ()
246
Gtk.Clipboard clip = GetClipboard (Gdk.Selection.Primary);
247
string text = clip.WaitForText ();
249
if (text == null || text.Trim() == string.Empty)
252
Note link_note = manager.FindByUri (NoteManager.StartNoteUri);
253
if (link_note == null)
256
link_note.Window.Present ();
257
PrependTimestampedText (link_note,
264
Gtk.Menu MakeRecentNotesMenu ()
279
tray_menu = MakeTrayNotesMenu ();
280
tray_menu.Hidden += MenuHidden;
283
public TomboyTray (NoteManager manager, TomboyTrayIcon tray_icon)
286
this.tray_icon = tray_icon;
289
public TomboyTray (NoteManager manager, TomboyAppletEventBox applet_event_box)
292
this.applet_event_box = applet_event_box;
295
public void ShowMenu (bool select_first_item)
297
if (applet_event_box != null)
298
applet_event_box.ShowMenu (select_first_item);
299
else if (tray_icon != null)
300
tray_icon.ShowMenu (select_first_item);
303
Gtk.Menu MakeTrayNotesMenu ()
267
306
Tomboy.ActionManager.GetWidget ("/TrayIconMenu") as Gtk.Menu;
404
452
if (menuOpensUpward) {
405
453
// Relocate common items to bottom of menu
406
454
insertion_point -= 1;
407
recent_menu.ReorderChild (searchNotesItem, list_size + insertion_point);
455
tray_menu.ReorderChild (searchNotesItem, list_size + insertion_point);
408
456
foreach (Gtk.Widget widget in newNotePlaceholderWidgets)
409
recent_menu.ReorderChild (widget, list_size + insertion_point);
410
recent_menu.ReorderChild (newNoteItem, list_size + insertion_point);
457
tray_menu.ReorderChild (widget, list_size + insertion_point);
458
tray_menu.ReorderChild (newNoteItem, list_size + insertion_point);
411
459
insertion_point = list_size;
414
462
Gtk.SeparatorMenuItem separator = new Gtk.SeparatorMenuItem ();
415
recent_menu.Insert (separator, insertion_point);
463
tray_menu.Insert (separator, insertion_point);
416
464
recent_notes.Add (separator);
419
bool MenuOpensUpward ()
422
this.GdkWindow.GetOrigin (out x, out y);
423
return y > 100; // FIXME: This can be better, I'm sure
426
void RemoveRecentlyChangedNotes ()
428
foreach (Gtk.Widget item in recent_notes) {
429
recent_menu.Remove (item);
432
recent_notes.Clear ();
435
void UpdateRecentNotesMenu (Gtk.Widget parent)
438
recent_menu.AttachToWidget (parent, GuiUtils.DetachMenu);
442
AddRecentlyChangedNotes ();
444
recent_menu.ShowAll ();
447
// Used by TomboyApplet to modify the icon background.
448
public Gtk.Image Image
455
public void ShowMenu (bool select_first_item)
457
UpdateRecentNotesMenu (this);
458
if (select_first_item)
459
recent_menu.SelectFirst (false);
461
GuiUtils.PopupMenu (recent_menu, null);
464
// Support dropping text/uri-lists and _NETSCAPE_URLs currently.
465
void SetupDragAndDrop ()
467
Gtk.TargetEntry [] targets =
468
new Gtk.TargetEntry [] {
469
new Gtk.TargetEntry ("text/uri-list", 0, 0),
470
new Gtk.TargetEntry ("_NETSCAPE_URL", 0, 0)
473
Gtk.Drag.DestSet (this,
474
Gtk.DestDefaults.All,
476
Gdk.DragAction.Copy);
478
DragDataReceived += OnDragDataReceived;
481
// Pop up Start Here and insert dropped links, in the form:
482
// Wednesday, December 8, 6:45 AM
483
// http://luna/kwiki/index.cgi?AdelaideUniThoughts
484
// http://www.beatniksoftware.com/blog/
485
// And select the inserted text.
487
// FIXME: Make undoable, make sure our date-sizing tag never "bleeds".
489
void OnDragDataReceived (object sender, Gtk.DragDataReceivedArgs args)
491
UriList uri_list = new UriList (args.SelectionData);
492
if (uri_list.Count == 0)
495
StringBuilder insert_text = new StringBuilder ();
496
bool more_than_one = false;
498
foreach (Uri uri in uri_list) {
500
insert_text.Append ("\n");
503
insert_text.Append (uri.LocalPath);
505
insert_text.Append (uri.ToString ());
507
more_than_one = true;
510
Note link_note = manager.FindByUri (NoteManager.StartNoteUri);
511
if (link_note != null) {
512
link_note.Window.Present ();
513
PrependTimestampedText (link_note,
515
insert_text.ToString ());
521
// For some reason, the first time we ask for the allocation,
522
// it's a 1x1 pixel. Prevent against this by returning a
523
// reasonable default. Setting the icon causes OnSizeAllocated
524
// to be called again anyhow.
525
int icon_size = panel_size;
530
// Control specifically which icon is used at the smaller sizes
531
// so that no scaling occurs. In the case of the panel applet,
532
// add a couple extra pixels of padding so it matches the behavior
533
// of the notification area tray icon. See bug #403500 for more
535
if (Tomboy.IsPanelApplet)
536
icon_size = icon_size - 2; // padding
539
else if (icon_size <= 31)
541
else if (icon_size <= 47)
544
Gdk.Pixbuf new_icon = GuiUtils.GetIcon ("tomboy", icon_size);
545
image.Pixbuf = new_icon;
549
/// Determine whether the tray is inside a horizontal or vertical
550
/// panel so the size of the icon can adjust correctly.
552
PanelOrientation GetPanelOrientation ()
554
if (this.ParentWindow == null) {
555
return PanelOrientation.Horizontal;
558
Gdk.Window top_level_window = this.ParentWindow.Toplevel;
560
Gdk.Rectangle rect = top_level_window.FrameExtents;
561
if (rect.Width < rect.Height)
562
return PanelOrientation.Vertical;
564
return PanelOrientation.Horizontal;
567
protected override void OnSizeAllocated (Gdk.Rectangle rect)
569
base.OnSizeAllocated (rect);
571
// Determine the orientation
572
if (GetPanelOrientation () == PanelOrientation.Horizontal) {
573
if (panel_size == Allocation.Height)
576
panel_size = Allocation.Height;
578
if (panel_size == Allocation.Width)
581
panel_size = Allocation.Width;
467
public bool MenuOpensUpward ()
469
bool open_upwards = false;
471
Gdk.Screen screen = null;
473
if (applet_event_box != null) {
475
applet_event_box.GdkWindow.GetOrigin (out x, out y);
477
screen = applet_event_box.Screen;
478
} else if (tray_icon != null) {
480
Gtk.Orientation orientation;
481
tray_icon.GetGeometry(out screen, out area, out orientation);
485
Gtk.Requisition menu_req = tray_menu.SizeRequest ();
486
if (val + menu_req.Height >= screen.Height)
492
public bool IsMenuAdded
494
get { return menu_added; }
495
set { menu_added = value; }
498
public Gtk.Menu TomboyTrayMenu
500
get { return tray_menu; }
503
public NoteManager NoteManager
505
get { return manager; }
509
public class TomboyTrayUtils
512
public static string GetToolTipText ()
514
string tip_text = Catalog.GetString ("Tomboy Notes");
516
if ((bool) Preferences.Get (Preferences.ENABLE_KEYBINDINGS)) {
518
GConfKeybindingToAccel.GetShortcut (
519
Preferences.KEYBINDING_SHOW_NOTE_MENU);
520
if (shortcut != null)
521
tip_text += String.Format (" ({0})", shortcut);
527
public static void UpdateTomboyTrayMenu (TomboyTray tray, Gtk.Widget parent)
529
if (!tray.IsMenuAdded) {
531
tray.TomboyTrayMenu.AttachToWidget (parent, GuiUtils.DetachMenu);
532
tray.IsMenuAdded = true;
535
tray.AddRecentlyChangedNotes ();
537
tray.TomboyTrayMenu.ShowAll ();