76
76
protected override bool OnButtonPressEvent (Gdk.EventButton ev)
78
78
if (pin_img != null &&
79
ev.X >= pin_img.Allocation.X &&
80
ev.X < pin_img.Allocation.X + pin_img.Allocation.Width) {
79
ev.X >= pin_img.Allocation.X &&
80
ev.X < pin_img.Allocation.X + pin_img.Allocation.Width) {
81
81
pinned = note.IsPinned = !pinned;
82
82
pin_img.Pixbuf = pinned ? pindown : pinup;
83
83
inhibit_activate = true;
98
98
protected override bool OnMotionNotifyEvent (Gdk.EventMotion ev)
100
100
if (!pinned && pin_img != null) {
101
if (ev.X >= pin_img.Allocation.X &&
102
ev.X < pin_img.Allocation.X + pin_img.Allocation.Width) {
101
if (ev.X >= pin_img.Allocation.X &&
102
ev.X < pin_img.Allocation.X + pin_img.Allocation.Width) {
103
103
if (pin_img.Pixbuf != pinup_active)
104
104
pin_img.Pixbuf = pinup_active;
105
105
} else if (pin_img.Pixbuf != pinup) {
147
147
string tip_text = Catalog.GetString ("Tomboy Notes");
149
149
if ((bool) Preferences.Get (Preferences.ENABLE_KEYBINDINGS)) {
151
GConfKeybindingToAccel.GetShortcut (
152
Preferences.KEYBINDING_SHOW_NOTE_MENU);
151
GConfKeybindingToAccel.GetShortcut (
152
Preferences.KEYBINDING_SHOW_NOTE_MENU);
153
153
if (shortcut != null)
154
154
tip_text += String.Format (" ({0})", shortcut);
158
158
tips.SetTip (this, tip_text, null);
162
162
SetupDragAndDrop ();
164
164
recent_menu = MakeRecentNotesMenu ();
165
165
recent_menu.Hidden += MenuHidden;
168
void ButtonPress (object sender, Gtk.ButtonPressEventArgs args)
168
void ButtonPress (object sender, Gtk.ButtonPressEventArgs args)
170
170
Gtk.Widget parent = (Gtk.Widget) sender;
176
176
args.RetVal = true;
179
// Give some visual feedback
180
Gtk.Drag.Highlight (this);
181
args.RetVal = PastePrimaryClipboard ();
182
Gtk.Drag.Unhighlight (this);
179
if ((bool) Preferences.Get (Preferences.ENABLE_ICON_PASTE)) {
180
// Give some visual feedback
181
Gtk.Drag.Highlight (this);
182
args.RetVal = PastePrimaryClipboard ();
183
Gtk.Drag.Unhighlight (this);
231
233
if (text == null || text.Trim() == string.Empty)
234
236
Note link_note = manager.FindByUri (NoteManager.StartNoteUri);
235
237
if (link_note == null)
238
240
link_note.Window.Present ();
239
PrependTimestampedText (link_note,
241
PrependTimestampedText (link_note,
246
248
Gtk.Menu MakeRecentNotesMenu ()
249
Tomboy.ActionManager.GetWidget ("/TrayIconMenu") as Gtk.Menu;
251
bool enable_keybindings = (bool)
252
Preferences.Get (Preferences.ENABLE_KEYBINDINGS);
251
Tomboy.ActionManager.GetWidget ("/TrayIconMenu") as Gtk.Menu;
253
bool enable_keybindings = (bool)
254
Preferences.Get (Preferences.ENABLE_KEYBINDINGS);
253
255
if (enable_keybindings) {
254
256
// Create New Note Keybinding
255
257
Gtk.MenuItem item =
256
Tomboy.ActionManager.GetWidget (
257
"/TrayIconMenu/NewNote") as Gtk.MenuItem;
258
Tomboy.ActionManager.GetWidget (
259
"/TrayIconMenu/TrayNewNotePlaceholder/TrayNewNote") as Gtk.MenuItem;
258
260
if (item != null)
259
261
GConfKeybindingToAccel.AddAccelerator (
261
Preferences.KEYBINDING_CREATE_NEW_NOTE);
263
Preferences.KEYBINDING_CREATE_NEW_NOTE);
263
265
// Show Search All Notes Keybinding
265
Tomboy.ActionManager.GetWidget (
266
"/TrayIconMenu/ShowSearchAllNotes") as Gtk.MenuItem;
267
Tomboy.ActionManager.GetWidget (
268
"/TrayIconMenu/ShowSearchAllNotes") as Gtk.MenuItem;
267
269
if (item != null)
268
270
GConfKeybindingToAccel.AddAccelerator (
270
Preferences.KEYBINDING_CREATE_NEW_NOTE);
272
// Open Start Here Keybinding
272
Preferences.KEYBINDING_CREATE_NEW_NOTE);
274
// Open Start Here Keybinding
274
Tomboy.ActionManager.GetWidget (
275
"/TrayIconMenu/OpenStartHereNote") as Gtk.MenuItem;
276
Tomboy.ActionManager.GetWidget (
277
"/TrayIconMenu/OpenStartHereNote") as Gtk.MenuItem;
276
278
if (item != null)
277
279
GConfKeybindingToAccel.AddAccelerator (
279
Preferences.KEYBINDING_OPEN_RECENT_CHANGES);
281
Preferences.KEYBINDING_OPEN_RECENT_CHANGES);
285
287
void MenuHidden (object sender, EventArgs args)
287
289
// Remove the old dynamic items
288
290
RemoveRecentlyChangedNotes ();
291
293
void AddRecentlyChangedNotes ()
293
295
int min_size = (int) Preferences.Get (Preferences.MENU_NOTE_COUNT);
295
297
int list_size = 0;
296
298
bool menuOpensUpward = MenuOpensUpward ();
297
299
NoteMenuItem item;
299
301
// Assume menu opens downward, move common items to top of menu
300
302
Gtk.MenuItem newNoteItem = Tomboy.ActionManager.GetWidget (
301
"/TrayIconMenu/TrayNewNote") as Gtk.MenuItem;
303
"/TrayIconMenu/TrayNewNotePlaceholder/TrayNewNote") as Gtk.MenuItem;
302
304
Gtk.MenuItem searchNotesItem = Tomboy.ActionManager.GetWidget (
303
"/TrayIconMenu/ShowSearchAllNotes") as Gtk.MenuItem;
305
"/TrayIconMenu/ShowSearchAllNotes") as Gtk.MenuItem;
304
306
recent_menu.ReorderChild (newNoteItem, 0);
305
recent_menu.ReorderChild (searchNotesItem, 1);
307
int insertion_point = 1; // If menu opens downward
309
// Find all child widgets under the TrayNewNotePlaceholder
310
// element. Make sure those added by add-ins are
311
// properly accounted for and reordered.
312
List<Gtk.Widget> newNotePlaceholderWidgets = new List<Gtk.Widget> ();
313
IList<Gtk.Widget> allChildWidgets =
314
Tomboy.ActionManager.GetPlaceholderChildren ("/TrayIconMenu/TrayNewNotePlaceholder");
315
foreach (Gtk.Widget child in allChildWidgets) {
316
if (child is Gtk.MenuItem &&
317
child != newNoteItem) {
318
newNotePlaceholderWidgets.Add (child);
319
recent_menu.ReorderChild (child, insertion_point);
324
recent_menu.ReorderChild (searchNotesItem, insertion_point);
307
327
DateTime days_ago = DateTime.Today.AddDays (-3);
329
// Prevent template notes from appearing in the menu
330
Tag template_tag = TagManager.GetOrCreateSystemTag (TagManager.TemplateNoteSystemTag);
309
332
// List the i most recently changed notes, any currently
310
333
// opened notes, and any pinned notes...
311
334
foreach (Note note in manager.Notes) {
312
335
if (note.IsSpecial)
338
// Skip template notes
339
if (note.ContainsTag (template_tag))
315
342
bool show = false;
317
344
// Test for note.IsPinned first so that all of the pinned notes
318
345
// are guaranteed to be included regardless of the size of the
320
347
if (note.IsPinned) {
322
349
} else if ((note.IsOpened && note.Window.IsMapped) ||
323
note.ChangeDate > days_ago ||
324
list_size < min_size) {
350
note.ChangeDate > days_ago ||
351
list_size < min_size) {
325
352
if (list_size <= max_size)
330
357
item = new NoteMenuItem (note, true);
331
// Add this widget to the menu (+2 to add after new+search)
332
recent_menu.Insert (item, list_size + 2);
358
// Add this widget to the menu (+insertion_point to add after new+search+...)
359
recent_menu.Insert (item, list_size + insertion_point);
333
360
// Keep track of this item so we can remove it later
334
361
recent_notes.Add (item);
341
368
if (start != null) {
342
369
item = new NoteMenuItem (start, false);
343
370
if (menuOpensUpward)
344
recent_menu.Insert (item, list_size + 2);
371
recent_menu.Insert (item, list_size + insertion_point);
346
recent_menu.Insert (item, 2);
373
recent_menu.Insert (item, insertion_point);
347
374
recent_notes.Add (item);
351
bool enable_keybindings = (bool)
352
Preferences.Get (Preferences.ENABLE_KEYBINDINGS);
378
bool enable_keybindings = (bool)
379
Preferences.Get (Preferences.ENABLE_KEYBINDINGS);
353
380
if (enable_keybindings)
354
381
GConfKeybindingToAccel.AddAccelerator (
356
Preferences.KEYBINDING_OPEN_START_HERE);
383
Preferences.KEYBINDING_OPEN_START_HERE);
359
int insertion_point = 2; // If menu opens downard
361
387
// FIXME: Rearrange this stuff to have less wasteful reordering
362
388
if (menuOpensUpward) {
363
389
// Relocate common items to bottom of menu
364
recent_menu.ReorderChild (searchNotesItem, list_size + 1);
365
recent_menu.ReorderChild (newNoteItem, list_size + 1);
390
insertion_point -= 1;
391
recent_menu.ReorderChild (searchNotesItem, list_size + insertion_point);
392
foreach (Gtk.Widget widget in newNotePlaceholderWidgets)
393
recent_menu.ReorderChild (widget, list_size + insertion_point);
394
recent_menu.ReorderChild (newNoteItem, list_size + insertion_point);
366
395
insertion_point = list_size;
369
398
Gtk.SeparatorMenuItem separator = new Gtk.SeparatorMenuItem ();
370
recent_menu.Insert (separator, insertion_point);
399
recent_menu.Insert (separator, insertion_point);
371
400
recent_notes.Add (separator);
374
403
bool MenuOpensUpward ()
377
406
this.GdkWindow.GetOrigin (out x, out y);
378
return y > 100; // FIXME: This can be better, I'm sure
407
return y > 100; // FIXME: This can be better, I'm sure
381
410
void RemoveRecentlyChangedNotes ()
383
412
foreach (Gtk.Widget item in recent_notes) {
384
413
recent_menu.Remove (item);
387
416
recent_notes.Clear ();
390
void UpdateRecentNotesMenu (Gtk.Widget parent)
419
void UpdateRecentNotesMenu (Gtk.Widget parent)
392
421
if (!menu_added) {
393
422
recent_menu.AttachToWidget (parent, GuiUtils.DetachMenu);
394
423
menu_added = true;
397
426
AddRecentlyChangedNotes ();
399
428
recent_menu.ShowAll ();
402
431
// Used by TomboyApplet to modify the icon background.
403
432
public Gtk.Image Image
405
get { return image; }
408
439
public void ShowMenu (bool select_first_item)
417
448
// Support dropping text/uri-lists and _NETSCAPE_URLs currently.
418
449
void SetupDragAndDrop ()
420
Gtk.TargetEntry [] targets =
421
new Gtk.TargetEntry [] {
422
new Gtk.TargetEntry ("text/uri-list", 0, 0),
423
new Gtk.TargetEntry ("_NETSCAPE_URL", 0, 0)
451
Gtk.TargetEntry [] targets =
452
new Gtk.TargetEntry [] {
453
new Gtk.TargetEntry ("text/uri-list", 0, 0),
454
new Gtk.TargetEntry ("_NETSCAPE_URL", 0, 0)
426
Gtk.Drag.DestSet (this,
427
Gtk.DestDefaults.All,
429
Gdk.DragAction.Copy);
457
Gtk.Drag.DestSet (this,
458
Gtk.DestDefaults.All,
460
Gdk.DragAction.Copy);
431
462
DragDataReceived += OnDragDataReceived;
434
465
// Pop up Start Here and insert dropped links, in the form:
435
// Wednesday, December 8, 6:45 AM
436
// http://luna/kwiki/index.cgi?AdelaideUniThoughts
437
// http://www.beatniksoftware.com/blog/
466
// Wednesday, December 8, 6:45 AM
467
// http://luna/kwiki/index.cgi?AdelaideUniThoughts
468
// http://www.beatniksoftware.com/blog/
438
469
// And select the inserted text.
440
471
// FIXME: Make undoable, make sure our date-sizing tag never "bleeds".
452
483
if (more_than_one)
453
484
insert_text.Append ("\n");
456
487
insert_text.Append (uri.LocalPath);
458
489
insert_text.Append (uri.ToString ());
460
491
more_than_one = true;
463
494
Note link_note = manager.FindByUri (NoteManager.StartNoteUri);
464
495
if (link_note != null) {
465
496
link_note.Window.Present ();
466
PrependTimestampedText (link_note,
468
insert_text.ToString ());
497
PrependTimestampedText (link_note,
499
insert_text.ToString ());
472
503
void InitPixbuf ()
474
505
// For some reason, the first time we ask for the allocation,
506
537
if (this.ParentWindow == null) {
507
538
return PanelOrientation.Horizontal;
510
541
Gdk.Window top_level_window = this.ParentWindow.Toplevel;
512
543
Gdk.Rectangle rect = top_level_window.FrameExtents;
513
544
if (rect.Width < rect.Height)
514
545
return PanelOrientation.Vertical;
516
547
return PanelOrientation.Horizontal;
524
555
if (GetPanelOrientation () == PanelOrientation.Horizontal) {
525
556
if (panel_size == Allocation.Height)
528
559
panel_size = Allocation.Height;
530
561
if (panel_size == Allocation.Width)
533
564
panel_size = Allocation.Width;
541
572
// This is a helper to take the XKeybinding string from GConf, and
542
573
// convert it to a widget accelerator label, so note menu items can
543
574
// display their global X keybinding.
576
[DllImport("libtomboy")]
607
[DllImport("libtomboy")]
577
608
static extern bool egg_accelerator_parse_virtual (string keystring,
579
out uint virtual_mods);
610
out uint virtual_mods);
581
612
[DllImport("libtomboy")]
582
613
static extern void egg_keymap_resolve_virtual_modifiers (
585
out Gdk.ModifierType real_mods);
616
out Gdk.ModifierType real_mods);
587
public static bool GetAccelKeys (string gconf_path,
589
out Gdk.ModifierType mods)
618
public static bool GetAccelKeys (string gconf_path,
620
out Gdk.ModifierType mods)
595
626
string binding = (string) Preferences.Get (gconf_path);
596
if (binding == null ||
597
binding == String.Empty ||
598
binding == "disabled")
627
if (binding == null ||
628
binding == String.Empty ||
629
binding == "disabled")
601
632
uint virtual_mods = 0;
602
633
if (!egg_accelerator_parse_virtual (binding,
607
638
Gdk.Keymap keymap = Gdk.Keymap.Default;
608
639
egg_keymap_resolve_virtual_modifiers (keymap.Handle,
618
public static void AddAccelerator (Gtk.MenuItem item, string gconf_path)
649
public static void AddAccelerator (Gtk.MenuItem item, string gconf_path)
621
652
Gdk.ModifierType mods;
623
654
if (GetAccelKeys (gconf_path, out keyval, out mods))
624
655
item.AddAccelerator ("activate",
628
Gtk.AccelFlags.Visible);
659
Gtk.AccelFlags.Visible);