~ubuntu-branches/ubuntu/lucid/tomboy/lucid-proposed

« back to all changes in this revision

Viewing changes to Tomboy/Tray.cs

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge, Jo Shields, Sebastian Dröge
  • Date: 2009-03-06 11:02:03 UTC
  • mfrom: (1.2.1 upstream)
  • mto: (4.2.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 20.
  • Revision ID: james.westby@ubuntu.com-20090306110203-5nbuw7itgo5mn9e0
Tags: 0.12.2-3
[ Jo Shields ]
* debian/control:
  + Add Vcs-* fields

[ Sebastian Dröge ]
* Upload to unstable (Closes: #518414).
* debian/control:
  + Use Gnome# 2.20 for now.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
 
2
1
using System;
3
2
using System.Collections;
4
3
using System.Collections.Generic;
5
 
using System.Text;
6
4
using Mono.Unix;
7
5
using System.Runtime.InteropServices;
8
6
 
30
28
                }
31
29
 
32
30
                public NoteMenuItem (Note note, bool show_pin)
33
 
: base (GetDisplayName(note))
 
31
                        : base (GetDisplayName(note))
34
32
                {
35
33
                        this.note = note;
36
34
                        Image = new Gtk.Image (note_icon);
60
58
                static string GetDisplayName (Note note)
61
59
                {
62
60
                        string display_name = note.Title;
63
 
            int max_length = 40;
 
61
                        int max_length = 100;
64
62
 
65
63
                        if (note.IsNew) {
66
 
                string new_string = Catalog.GetString(" (new)");
67
 
                max_length -= new_string.Length;
 
64
                                string new_string = Catalog.GetString(" (new)");
 
65
                                max_length -= new_string.Length;
68
66
                                display_name = Ellipsify (display_name, max_length)
69
 
                    + new_string;
70
 
            } else {
71
 
                display_name = Ellipsify (display_name, max_length);
72
 
            }
 
67
                                        + new_string;
 
68
                        } else {
 
69
                                display_name = Ellipsify (display_name, max_length);
 
70
                        }
73
71
 
74
72
                        return FormatForLabel (display_name);
75
73
                }
76
74
 
77
 
        static string Ellipsify (string str, int max)
78
 
        {
79
 
            if(str.Length > max)
80
 
                return str.Substring(0, max - 1) + "...";
81
 
            return str;
82
 
        }
 
75
                static string Ellipsify (string str, int max)
 
76
                {
 
77
                        if(str.Length > max)
 
78
                                return str.Substring(0, max - 1) + "...";
 
79
                        return str;
 
80
                }
83
81
 
84
82
                protected override void OnActivated ()
85
83
                {
133
131
                        return base.OnLeaveNotifyEvent (ev);
134
132
                }
135
133
        }
136
 
 
137
 
        public enum PanelOrientation { Horizontal, Vertical };
138
 
 
139
 
        public class TomboyTray : Gtk.EventBox
 
134
        
 
135
        
 
136
        public class TomboyTrayIcon : Gtk.StatusIcon
 
137
        {
 
138
                TomboyTray tray;
 
139
                TomboyGConfXKeybinder keybinder;
 
140
 
 
141
                public TomboyTrayIcon (NoteManager manager)
 
142
                {
 
143
                        tray = new TomboyTray (manager, this);
 
144
                        keybinder = new TomboyGConfXKeybinder (manager, tray);
 
145
                        int panel_size = 22;
 
146
                        Pixbuf = GuiUtils.GetIcon ("tomboy", panel_size);
 
147
 
 
148
                        Tooltip = TomboyTrayUtils.GetToolTipText ();
 
149
                }
 
150
                
 
151
                public TomboyTray Tray
 
152
                {
 
153
                        get {
 
154
                                return tray;
 
155
                        }
 
156
                }
 
157
                
 
158
                protected override void OnActivate()
 
159
                {
 
160
                        ShowMenu (false);
 
161
                }
 
162
                
 
163
                protected override void OnPopupMenu (uint button, uint activate_time)
 
164
                {
 
165
                        if (button == 3)
 
166
                                GuiUtils.PopupMenu (MakeRightClickMenu (),
 
167
                                                    null, 
 
168
                                                    new Gtk.MenuPositionFunc (GetTrayMenuPosition));
 
169
                                
 
170
                }
 
171
                
 
172
                public void ShowMenu (bool select_first_item)
 
173
                {
 
174
                        TomboyTrayUtils.UpdateTomboyTrayMenu (tray, null);
 
175
                        if (select_first_item)
 
176
                                tray.TomboyTrayMenu.SelectFirst (false);
 
177
 
 
178
                        
 
179
                                
 
180
                        GuiUtils.PopupMenu (tray.TomboyTrayMenu, null, 
 
181
                                new Gtk.MenuPositionFunc (GetTrayMenuPosition));
 
182
                }
 
183
                
 
184
                public void GetTrayMenuPosition (Gtk.Menu menu,
 
185
                                             out int  x,
 
186
                                             out int  y,
 
187
                                             out bool push_in)
 
188
                {
 
189
                        // some default values in case something goes wrong
 
190
                        push_in = true;
 
191
                        x = 0;
 
192
                        y = 0;
 
193
                        
 
194
                        Gdk.Screen screen;
 
195
                        Gdk.Rectangle area;
 
196
                        Gtk.Orientation orientation;
 
197
                        GetGeometry (out screen, out area, out orientation);
 
198
                        
 
199
                        x = area.X;
 
200
                        y = area.Y;
 
201
                        
 
202
                        Gtk.Requisition menu_req = menu.SizeRequest ();
 
203
                        if (y + menu_req.Height >= screen.Height)
 
204
                                y -= menu_req.Height;
 
205
                        else
 
206
                                y += area.Height;
 
207
                }
 
208
                
 
209
                Gtk.Menu MakeRightClickMenu ()
 
210
                {
 
211
                        Gtk.Menu menu = new Gtk.Menu ();
 
212
 
 
213
                        Gtk.AccelGroup accel_group = new Gtk.AccelGroup ();
 
214
                        menu.AccelGroup = accel_group;
 
215
 
 
216
                        Gtk.ImageMenuItem item;
 
217
 
 
218
                        item = new Gtk.ImageMenuItem (Catalog.GetString ("_Preferences"));
 
219
                        item.Image = new Gtk.Image (Gtk.Stock.Preferences, Gtk.IconSize.Menu);
 
220
                        item.Activated += ShowPreferences;
 
221
                        menu.Append (item);
 
222
 
 
223
                        item = new Gtk.ImageMenuItem (Catalog.GetString ("_Help"));
 
224
                        item.Image = new Gtk.Image (Gtk.Stock.Help, Gtk.IconSize.Menu);
 
225
                        item.Activated += ShowHelpContents;
 
226
                        menu.Append (item);
 
227
 
 
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;
 
231
                        menu.Append (item);
 
232
 
 
233
                        menu.Append (new Gtk.SeparatorMenuItem ());
 
234
 
 
235
                        item = new Gtk.ImageMenuItem (Catalog.GetString ("_Quit"));
 
236
                        item.Image = new Gtk.Image (Gtk.Stock.Quit, Gtk.IconSize.Menu);
 
237
                        item.Activated += Quit;
 
238
                        menu.Append (item);
 
239
 
 
240
                        menu.ShowAll ();
 
241
                        return menu;
 
242
                }
 
243
 
 
244
                void ShowPreferences (object sender, EventArgs args)
 
245
                {
 
246
                        Tomboy.ActionManager ["ShowPreferencesAction"].Activate ();
 
247
                }
 
248
 
 
249
                void ShowHelpContents (object sender, EventArgs args)
 
250
                {
 
251
                        Tomboy.ActionManager ["ShowHelpAction"].Activate ();
 
252
                }
 
253
 
 
254
                void ShowAbout (object sender, EventArgs args)
 
255
                {
 
256
                        Tomboy.ActionManager ["ShowAboutAction"].Activate ();
 
257
                }
 
258
 
 
259
                void Quit (object sender, EventArgs args)
 
260
                {
 
261
                        Tomboy.ActionManager ["QuitTomboyAction"].Activate ();
 
262
                }
 
263
 
 
264
        }
 
265
        
 
266
        public class TomboyTray
140
267
        {
141
268
                NoteManager manager;
142
 
                Gtk.Tooltips tips;
143
 
                Gtk.Image image;
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> ();
147
 
                int panel_size;
148
 
 
149
 
                public TomboyTray (NoteManager manager)
150
 
: base ()
 
273
                Gtk.Menu tray_menu;
 
274
                
 
275
                protected TomboyTray (NoteManager manager)
151
276
                {
152
277
                        this.manager = manager;
153
 
                        // Load a 16x16-sized icon to ensure we don't end up with a
154
 
                        // 1x1 pixel.
155
 
                        panel_size = 16;
156
 
                        this.image = new Gtk.Image (GuiUtils.GetIcon ("tomboy", panel_size));
157
 
 
158
 
                        this.CanFocus = true;
159
 
                        this.ButtonPressEvent += ButtonPress;
160
 
                        this.Add (image);
161
 
                        this.ShowAll ();
162
 
 
163
 
                        string tip_text = Catalog.GetString ("Tomboy Notes");
164
 
 
165
 
                        if ((bool) Preferences.Get (Preferences.ENABLE_KEYBINDINGS)) {
166
 
                                string shortcut =
167
 
                                        GConfKeybindingToAccel.GetShortcut (
168
 
                                                Preferences.KEYBINDING_SHOW_NOTE_MENU);
169
 
                                if (shortcut != null)
170
 
                                        tip_text += String.Format (" ({0})", shortcut);
171
 
                        }
172
 
 
173
 
                        tips = new Gtk.Tooltips ();
174
 
                        tips.SetTip (this, tip_text, null);
175
 
                        tips.Enable ();
176
 
                        tips.Sink ();
177
 
 
178
 
                        SetupDragAndDrop ();
179
 
 
180
 
                        recent_menu = MakeRecentNotesMenu ();
181
 
                        recent_menu.Hidden += MenuHidden;
182
 
                }
183
 
 
184
 
                void ButtonPress (object sender, Gtk.ButtonPressEventArgs args)
185
 
                {
186
 
                        Gtk.Widget parent = (Gtk.Widget) sender;
187
 
 
188
 
                        switch (args.Event.Button) {
189
 
                        case 1:
190
 
                                UpdateRecentNotesMenu (parent);
191
 
                                GuiUtils.PopupMenu (recent_menu, args.Event);
192
 
                                args.RetVal = true;
193
 
                                break;
194
 
                        case 2:
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);
200
 
                                }
201
 
                                break;
202
 
                        }
203
 
                }
204
 
 
205
 
                void PrependTimestampedText (Note note, DateTime timestamp, string text)
206
 
                {
207
 
                        NoteBuffer buffer = note.Buffer;
208
 
                        StringBuilder insert_text = new StringBuilder ();
209
 
 
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
216
 
 
217
 
                        buffer.Undoer.FreezeUndo ();
218
 
 
219
 
                        // Insert the date and list of links...
220
 
                        Gtk.TextIter cursor = buffer.StartIter;
221
 
                        cursor.ForwardLines (1); // skip title
222
 
 
223
 
                        buffer.Insert (ref cursor, insert_text.ToString ());
224
 
 
225
 
                        // Make the date string a small font...
226
 
                        cursor = buffer.StartIter;
227
 
                        cursor.ForwardLines (2); // skip title & leading newline
228
 
 
229
 
                        Gtk.TextIter end = cursor;
230
 
                        end.ForwardToLineEnd (); // end of date
231
 
 
232
 
                        buffer.ApplyTag ("datetime", cursor, end);
233
 
 
234
 
                        // Select the text we've inserted (avoid trailing newline)...
235
 
                        end = cursor;
236
 
                        end.ForwardChars (insert_text.Length - 1);
237
 
 
238
 
                        buffer.MoveMark (buffer.SelectionBound, cursor);
239
 
                        buffer.MoveMark (buffer.InsertMark, end);
240
 
 
241
 
                        buffer.Undoer.ThawUndo ();
242
 
                }
243
 
 
244
 
                bool PastePrimaryClipboard ()
245
 
                {
246
 
                        Gtk.Clipboard clip = GetClipboard (Gdk.Selection.Primary);
247
 
                        string text = clip.WaitForText ();
248
 
 
249
 
                        if (text == null || text.Trim() == string.Empty)
250
 
                                return false;
251
 
 
252
 
                        Note link_note = manager.FindByUri (NoteManager.StartNoteUri);
253
 
                        if (link_note == null)
254
 
                                return false;
255
 
 
256
 
                        link_note.Window.Present ();
257
 
                        PrependTimestampedText (link_note,
258
 
                                                DateTime.Now,
259
 
                                                text);
260
 
 
261
 
                        return true;
262
 
                }
263
 
 
264
 
                Gtk.Menu MakeRecentNotesMenu ()
 
278
                        
 
279
                        tray_menu = MakeTrayNotesMenu ();
 
280
                        tray_menu.Hidden += MenuHidden;
 
281
                }
 
282
                
 
283
                public TomboyTray (NoteManager manager, TomboyTrayIcon tray_icon)
 
284
                        : this (manager)
 
285
                {
 
286
                        this.tray_icon = tray_icon;
 
287
                }
 
288
                
 
289
                public TomboyTray (NoteManager manager, TomboyAppletEventBox applet_event_box)
 
290
                        : this (manager)
 
291
                {
 
292
                        this.applet_event_box = applet_event_box;
 
293
                }
 
294
                
 
295
                public void ShowMenu (bool select_first_item)
 
296
                {
 
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);
 
301
                }
 
302
                
 
303
                Gtk.Menu MakeTrayNotesMenu ()
265
304
                {
266
305
                        Gtk.Menu menu =
267
306
                                Tomboy.ActionManager.GetWidget ("/TrayIconMenu") as Gtk.Menu;
299
338
 
300
339
                        return menu;
301
340
                }
302
 
 
 
341
                
303
342
                void MenuHidden (object sender, EventArgs args)
304
343
                {
305
344
                        // Remove the old dynamic items
306
345
                        RemoveRecentlyChangedNotes ();
307
346
                }
 
347
                
 
348
                void RemoveRecentlyChangedNotes ()
 
349
                {
 
350
                        foreach (Gtk.Widget item in recent_notes) {
 
351
                                tray_menu.Remove (item);
 
352
                        }
308
353
 
309
 
                void AddRecentlyChangedNotes ()
 
354
                        recent_notes.Clear ();
 
355
                }
 
356
                
 
357
                public void AddRecentlyChangedNotes ()
310
358
                {
311
359
                        int min_size = (int) Preferences.Get (Preferences.MENU_NOTE_COUNT);
312
360
                        int max_size = 18;
319
367
                                                           "/TrayIconMenu/TrayNewNotePlaceholder/TrayNewNote") as Gtk.MenuItem;
320
368
                        Gtk.MenuItem searchNotesItem = Tomboy.ActionManager.GetWidget (
321
369
                                                               "/TrayIconMenu/ShowSearchAllNotes") as Gtk.MenuItem;
322
 
                        recent_menu.ReorderChild (newNoteItem, 0);
 
370
                        tray_menu.ReorderChild (newNoteItem, 0);
323
371
                        int insertion_point = 1; // If menu opens downward
324
372
                        
325
373
                        // Find all child widgets under the TrayNewNotePlaceholder
332
380
                                if (child is Gtk.MenuItem &&
333
381
                                    child != newNoteItem) {
334
382
                                        newNotePlaceholderWidgets.Add (child);
335
 
                                        recent_menu.ReorderChild (child, insertion_point);
 
383
                                        tray_menu.ReorderChild (child, insertion_point);
336
384
                                        insertion_point++;
337
385
                                }
338
386
                        }
339
387
                        
340
 
                        recent_menu.ReorderChild (searchNotesItem, insertion_point);
 
388
                        tray_menu.ReorderChild (searchNotesItem, insertion_point);
341
389
                        insertion_point++;
342
390
 
343
391
                        DateTime days_ago = DateTime.Today.AddDays (-3);
345
393
                        // Prevent template notes from appearing in the menu
346
394
                        Tag template_tag = TagManager.GetOrCreateSystemTag (TagManager.TemplateNoteSystemTag);
347
395
 
348
 
                        // List the i most recently changed notes, any currently
 
396
                        // List the most recently changed notes, any currently
349
397
                        // opened notes, and any pinned notes...
350
398
                        foreach (Note note in manager.Notes) {
351
399
                                if (note.IsSpecial)
372
420
                                if (show) {
373
421
                                        item = new NoteMenuItem (note, true);
374
422
                                        // Add this widget to the menu (+insertion_point to add after new+search+...)
375
 
                                        recent_menu.Insert (item, list_size + insertion_point);
 
423
                                        tray_menu.Insert (item, list_size + insertion_point);
376
424
                                        // Keep track of this item so we can remove it later
377
425
                                        recent_notes.Add (item);
378
426
 
384
432
                        if (start != null) {
385
433
                                item = new NoteMenuItem (start, false);
386
434
                                if (menuOpensUpward)
387
 
                                        recent_menu.Insert (item, list_size + insertion_point);
 
435
                                        tray_menu.Insert (item, list_size + insertion_point);
388
436
                                else
389
 
                                        recent_menu.Insert (item, insertion_point);
 
437
                                        tray_menu.Insert (item, insertion_point);
390
438
                                recent_notes.Add (item);
391
439
 
392
440
                                list_size++;
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;
412
460
                        }
413
461
 
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);
417
465
                }
418
 
 
419
 
                bool MenuOpensUpward ()
420
 
                {
421
 
                        int x, y;
422
 
                        this.GdkWindow.GetOrigin (out x, out y);
423
 
                        return y > 100; // FIXME: This can be better, I'm sure
424
 
                }
425
 
 
426
 
                void RemoveRecentlyChangedNotes ()
427
 
                {
428
 
                        foreach (Gtk.Widget item in recent_notes) {
429
 
                                recent_menu.Remove (item);
430
 
                        }
431
 
 
432
 
                        recent_notes.Clear ();
433
 
                }
434
 
 
435
 
                void UpdateRecentNotesMenu (Gtk.Widget parent)
436
 
                {
437
 
                        if (!menu_added) {
438
 
                                recent_menu.AttachToWidget (parent, GuiUtils.DetachMenu);
439
 
                                menu_added = true;
440
 
                        }
441
 
 
442
 
                        AddRecentlyChangedNotes ();
443
 
 
444
 
                        recent_menu.ShowAll ();
445
 
                }
446
 
 
447
 
                // Used by TomboyApplet to modify the icon background.
448
 
                public Gtk.Image Image
449
 
                {
450
 
                        get {
451
 
                                return image;
452
 
                        }
453
 
                }
454
 
 
455
 
                public void ShowMenu (bool select_first_item)
456
 
                {
457
 
                        UpdateRecentNotesMenu (this);
458
 
                        if (select_first_item)
459
 
                                recent_menu.SelectFirst (false);
460
 
 
461
 
                        GuiUtils.PopupMenu (recent_menu, null);
462
 
                }
463
 
 
464
 
                // Support dropping text/uri-lists and _NETSCAPE_URLs currently.
465
 
                void SetupDragAndDrop ()
466
 
                {
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)
471
 
                        };
472
 
 
473
 
                        Gtk.Drag.DestSet (this,
474
 
                                          Gtk.DestDefaults.All,
475
 
                                          targets,
476
 
                                          Gdk.DragAction.Copy);
477
 
 
478
 
                        DragDataReceived += OnDragDataReceived;
479
 
                }
480
 
 
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.
486
 
                //
487
 
                // FIXME: Make undoable, make sure our date-sizing tag never "bleeds".
488
 
                //
489
 
                void OnDragDataReceived (object sender, Gtk.DragDataReceivedArgs args)
490
 
                {
491
 
                        UriList uri_list = new UriList (args.SelectionData);
492
 
                        if (uri_list.Count == 0)
493
 
                                return;
494
 
 
495
 
                        StringBuilder insert_text = new StringBuilder ();
496
 
                        bool more_than_one = false;
497
 
 
498
 
                        foreach (Uri uri in uri_list) {
499
 
                                if (more_than_one)
500
 
                                        insert_text.Append ("\n");
501
 
 
502
 
                                if (uri.IsFile)
503
 
                                        insert_text.Append (uri.LocalPath);
504
 
                                else
505
 
                                        insert_text.Append (uri.ToString ());
506
 
 
507
 
                                more_than_one = true;
508
 
                        }
509
 
 
510
 
                        Note link_note = manager.FindByUri (NoteManager.StartNoteUri);
511
 
                        if (link_note != null) {
512
 
                                link_note.Window.Present ();
513
 
                                PrependTimestampedText (link_note,
514
 
                                                        DateTime.Now,
515
 
                                                        insert_text.ToString ());
516
 
                        }
517
 
                }
518
 
 
519
 
                void InitPixbuf ()
520
 
                {
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;
526
 
                        if (icon_size < 16)
527
 
                                icon_size = 16;
528
 
 
529
 
 
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
534
 
                        // info.
535
 
                        if (Tomboy.IsPanelApplet)
536
 
                                icon_size = icon_size - 2; // padding
537
 
                        if (icon_size <= 21)
538
 
                                icon_size = 16;
539
 
                        else if (icon_size <= 31)
540
 
                                icon_size = 22;
541
 
                        else if (icon_size <= 47)
542
 
                                icon_size = 32;
543
 
 
544
 
                        Gdk.Pixbuf new_icon = GuiUtils.GetIcon ("tomboy", icon_size);
545
 
                        image.Pixbuf = new_icon;
546
 
                }
547
 
 
548
 
                ///
549
 
                /// Determine whether the tray is inside a horizontal or vertical
550
 
                /// panel so the size of the icon can adjust correctly.
551
 
                ///
552
 
                PanelOrientation GetPanelOrientation ()
553
 
                {
554
 
                        if (this.ParentWindow == null) {
555
 
                                return PanelOrientation.Horizontal;
556
 
                        }
557
 
 
558
 
                        Gdk.Window top_level_window = this.ParentWindow.Toplevel;
559
 
 
560
 
                        Gdk.Rectangle rect = top_level_window.FrameExtents;
561
 
                        if (rect.Width < rect.Height)
562
 
                                return PanelOrientation.Vertical;
563
 
 
564
 
                        return PanelOrientation.Horizontal;
565
 
                }
566
 
 
567
 
                protected override void OnSizeAllocated (Gdk.Rectangle rect)
568
 
                {
569
 
                        base.OnSizeAllocated (rect);
570
 
 
571
 
                        // Determine the orientation
572
 
                        if (GetPanelOrientation () == PanelOrientation.Horizontal) {
573
 
                                if (panel_size == Allocation.Height)
574
 
                                        return;
575
 
 
576
 
                                panel_size = Allocation.Height;
577
 
                        } else {
578
 
                                if (panel_size == Allocation.Width)
579
 
                                        return;
580
 
 
581
 
                                panel_size = Allocation.Width;
582
 
                        }
583
 
 
584
 
                        InitPixbuf ();
585
 
                }
 
466
                
 
467
                public bool MenuOpensUpward ()
 
468
                {
 
469
                        bool open_upwards = false;
 
470
                        int val = 0;
 
471
                        Gdk.Screen screen = null;
 
472
                        
 
473
                        if (applet_event_box != null) {
 
474
                                int x, y;
 
475
                                applet_event_box.GdkWindow.GetOrigin (out x, out y);
 
476
                                val = y;
 
477
                                screen = applet_event_box.Screen;
 
478
                        } else if (tray_icon != null) {
 
479
                                Gdk.Rectangle area;
 
480
                                Gtk.Orientation orientation;
 
481
                                tray_icon.GetGeometry(out screen, out area, out orientation);
 
482
                                val = area.Y;
 
483
                        }
 
484
                        
 
485
                        Gtk.Requisition menu_req = tray_menu.SizeRequest ();
 
486
                        if (val + menu_req.Height >= screen.Height)
 
487
                                open_upwards = true;
 
488
 
 
489
                        return open_upwards;
 
490
                }
 
491
 
 
492
                public bool IsMenuAdded
 
493
                {
 
494
                        get { return menu_added; }
 
495
                        set { menu_added = value; }
 
496
                }
 
497
 
 
498
                public Gtk.Menu TomboyTrayMenu
 
499
                {
 
500
                        get { return tray_menu; }
 
501
                }
 
502
                
 
503
                public NoteManager NoteManager
 
504
                {
 
505
                        get { return manager; }
 
506
                }
 
507
        }
 
508
        
 
509
        public class TomboyTrayUtils
 
510
        {
 
511
        
 
512
                public static string GetToolTipText ()
 
513
                {
 
514
                        string tip_text = Catalog.GetString ("Tomboy Notes");
 
515
 
 
516
                        if ((bool) Preferences.Get (Preferences.ENABLE_KEYBINDINGS)) {
 
517
                                string shortcut =
 
518
                                        GConfKeybindingToAccel.GetShortcut (
 
519
                                                Preferences.KEYBINDING_SHOW_NOTE_MENU);
 
520
                                if (shortcut != null)
 
521
                                        tip_text += String.Format (" ({0})", shortcut);
 
522
                        }
 
523
                        
 
524
                        return tip_text;
 
525
                }
 
526
                
 
527
                public static void UpdateTomboyTrayMenu (TomboyTray tray, Gtk.Widget parent)
 
528
                {
 
529
                        if (!tray.IsMenuAdded) {
 
530
                                if (parent != null)
 
531
                                        tray.TomboyTrayMenu.AttachToWidget (parent, GuiUtils.DetachMenu);
 
532
                                tray.IsMenuAdded = true;
 
533
                        }
 
534
 
 
535
                        tray.AddRecentlyChangedNotes ();
 
536
 
 
537
                        tray.TomboyTrayMenu.ShowAll ();
 
538
                }
 
539
        
586
540
        }
587
541
 
588
542
        //