~ted/ubuntu/lucid/tomboy/with-patch

« back to all changes in this revision

Viewing changes to Tomboy/Tray.cs

  • Committer: Bazaar Package Importer
  • Author(s): Pedro Fragoso
  • Date: 2008-01-15 11:32:52 UTC
  • mfrom: (1.1.31 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20080115113252-p59wg7nqkl6vcg7a
Tags: 0.9.4-0ubuntu1
* New upstream release (LP: #181798)
  - Fix crash during note deletion 
  - Fix null reference exception 
  - Fix mnemonics in sync preferences dialog 
  - Fix fuse mount timeout for sync 
  - New port option for SSH sync 
  - New multi-select notes support in Search All Notes window
  - New config dialog for Insert Timestamp Add-in 
  - New gconf preference, middle-click paste on Tomboy icon
  - New gconf preference, disable ESC closing notes 
  - New paragraph within a bullet with SHIFT + ENTER
  - New bug numbers as links in Export to HTML 
  - New notebook notes can be created off notebook's context menu.
  - New sketching add-in (still incomplete, --enable-sketching)
  - New "Unfiled Notes" item to notebook list 
  - New drag note to "Unfiled Notes" to remove from notebook 
 * debian/tomboy.menu: updated

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
                }
31
31
 
32
32
                public NoteMenuItem (Note note, bool show_pin)
33
 
                        : base (GetDisplayName(note))
 
33
: base (GetDisplayName(note))
34
34
                {
35
35
                        this.note = note;
36
36
                        Image = new Gtk.Image (note_icon);
65
65
                        return FormatForLabel (display_name);
66
66
                }
67
67
 
68
 
                protected override void OnActivated () 
 
68
                protected override void OnActivated ()
69
69
                {
70
70
                        if (!inhibit_activate) {
71
71
                                if (note != null)
76
76
                protected override bool OnButtonPressEvent (Gdk.EventButton ev)
77
77
                {
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)
99
99
                {
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) {
114
114
                        if (!pinned && pin_img != null) {
115
115
                                pin_img.Pixbuf = pinup;
116
116
                        }
117
 
                        return base.OnLeaveNotifyEvent (ev);                    
 
117
                        return base.OnLeaveNotifyEvent (ev);
118
118
                }
119
119
        }
120
120
 
121
121
        public enum PanelOrientation { Horizontal, Vertical };
122
 
        
 
122
 
123
123
        public class TomboyTray : Gtk.EventBox
124
124
        {
125
125
                NoteManager manager;
130
130
                List<Gtk.MenuItem> recent_notes = new List<Gtk.MenuItem> ();
131
131
                int panel_size;
132
132
 
133
 
                public TomboyTray (NoteManager manager) 
134
 
                        : base ()
 
133
                public TomboyTray (NoteManager manager)
 
134
: base ()
135
135
                {
136
136
                        this.manager = manager;
137
137
                        // Load a 16x16-sized icon to ensure we don't end up with a
147
147
                        string tip_text = Catalog.GetString ("Tomboy Notes");
148
148
 
149
149
                        if ((bool) Preferences.Get (Preferences.ENABLE_KEYBINDINGS)) {
150
 
                                string shortcut = 
151
 
                                        GConfKeybindingToAccel.GetShortcut (
152
 
                                                Preferences.KEYBINDING_SHOW_NOTE_MENU);
 
150
                                string shortcut =
 
151
                                        GConfKeybindingToAccel.GetShortcut (
 
152
                                                Preferences.KEYBINDING_SHOW_NOTE_MENU);
153
153
                                if (shortcut != null)
154
154
                                        tip_text += String.Format (" ({0})", shortcut);
155
155
                        }
158
158
                        tips.SetTip (this, tip_text, null);
159
159
                        tips.Enable ();
160
160
                        tips.Sink ();
161
 
                        
 
161
 
162
162
                        SetupDragAndDrop ();
163
 
                        
 
163
 
164
164
                        recent_menu = MakeRecentNotesMenu ();
165
165
                        recent_menu.Hidden += MenuHidden;
166
166
                }
167
167
 
168
 
                void ButtonPress (object sender, Gtk.ButtonPressEventArgs args) 
 
168
                void ButtonPress (object sender, Gtk.ButtonPressEventArgs args)
169
169
                {
170
170
                        Gtk.Widget parent = (Gtk.Widget) sender;
171
171
 
176
176
                                args.RetVal = true;
177
177
                                break;
178
178
                        case 2:
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);
 
184
                                }
183
185
                                break;
184
186
                        }
185
187
                }
230
232
 
231
233
                        if (text == null || text.Trim() == string.Empty)
232
234
                                return false;
233
 
                        
 
235
 
234
236
                        Note link_note = manager.FindByUri (NoteManager.StartNoteUri);
235
237
                        if (link_note == null)
236
238
                                return false;
237
239
 
238
240
                        link_note.Window.Present ();
239
 
                        PrependTimestampedText (link_note, 
240
 
                                                DateTime.Now, 
241
 
                                                text);
 
241
                        PrependTimestampedText (link_note,
 
242
                                                DateTime.Now,
 
243
                                                text);
242
244
 
243
245
                        return true;
244
246
                }
245
 
                
 
247
 
246
248
                Gtk.Menu MakeRecentNotesMenu ()
247
249
                {
248
250
                        Gtk.Menu menu =
249
 
                                Tomboy.ActionManager.GetWidget ("/TrayIconMenu") as Gtk.Menu;
250
 
                        
251
 
                        bool enable_keybindings = (bool) 
252
 
                                Preferences.Get (Preferences.ENABLE_KEYBINDINGS);
 
251
                                Tomboy.ActionManager.GetWidget ("/TrayIconMenu") as Gtk.Menu;
 
252
 
 
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 (
260
 
                                                item,
261
 
                                                Preferences.KEYBINDING_CREATE_NEW_NOTE);
262
 
                                
 
262
                                                item,
 
263
                                                Preferences.KEYBINDING_CREATE_NEW_NOTE);
 
264
 
263
265
                                // Show Search All Notes Keybinding
264
266
                                item =
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 (
269
 
                                                item,
270
 
                                                Preferences.KEYBINDING_CREATE_NEW_NOTE);
271
 
                                
272
 
                                // Open Start Here Keybinding                   
 
271
                                                item,
 
272
                                                Preferences.KEYBINDING_CREATE_NEW_NOTE);
 
273
 
 
274
                                // Open Start Here Keybinding
273
275
                                item =
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 (
278
 
                                                item,
279
 
                                                Preferences.KEYBINDING_OPEN_RECENT_CHANGES);
280
 
                        }                               
281
 
                        
 
280
                                                item,
 
281
                                                Preferences.KEYBINDING_OPEN_RECENT_CHANGES);
 
282
                        }
 
283
 
282
284
                        return menu;
283
285
                }
284
 
                
 
286
 
285
287
                void MenuHidden (object sender, EventArgs args)
286
288
                {
287
289
                        // Remove the old dynamic items
288
290
                        RemoveRecentlyChangedNotes ();
289
291
                }
290
 
                
 
292
 
291
293
                void AddRecentlyChangedNotes ()
292
294
                {
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;
298
 
                        
 
300
 
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
 
308
                        
 
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);
 
320
                                        insertion_point++;
 
321
                                }
 
322
                        }
 
323
                        
 
324
                        recent_menu.ReorderChild (searchNotesItem, insertion_point);
 
325
                        insertion_point++;
306
326
 
307
327
                        DateTime days_ago = DateTime.Today.AddDays (-3);
308
328
                        
 
329
                        // Prevent template notes from appearing in the menu
 
330
                        Tag template_tag = TagManager.GetOrCreateSystemTag (TagManager.TemplateNoteSystemTag);
 
331
 
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)
313
336
                                        continue;
 
337
                                
 
338
                                // Skip template notes
 
339
                                if (note.ContainsTag (template_tag))
 
340
                                        continue;
314
341
 
315
342
                                bool show = false;
316
 
                                
 
343
 
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
319
346
                                // list.
320
347
                                if (note.IsPinned) {
321
348
                                        show = true;
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)
326
353
                                                show = true;
327
354
                                }
328
355
 
329
356
                                if (show) {
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);
335
 
                                        
 
362
 
336
363
                                        list_size++;
337
364
                                }
338
365
                        }
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);
345
372
                                else
346
 
                                        recent_menu.Insert (item, 2);
 
373
                                        recent_menu.Insert (item, insertion_point);
347
374
                                recent_notes.Add (item);
348
375
 
349
376
                                list_size++;
350
377
 
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 (
355
 
                                                item, 
356
 
                                                Preferences.KEYBINDING_OPEN_START_HERE);
 
382
                                                item,
 
383
                                                Preferences.KEYBINDING_OPEN_START_HERE);
357
384
                        }
358
385
 
359
 
                        int insertion_point = 2;        // If menu opens downard
360
 
                        
 
386
 
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;
367
396
                        }
368
397
 
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);
372
401
                }
373
 
                
 
402
 
374
403
                bool MenuOpensUpward ()
375
404
                {
376
405
                        int x, y;
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
379
408
                }
380
 
                
 
409
 
381
410
                void RemoveRecentlyChangedNotes ()
382
411
                {
383
412
                        foreach (Gtk.Widget item in recent_notes) {
384
413
                                recent_menu.Remove (item);
385
414
                        }
386
 
                        
 
415
 
387
416
                        recent_notes.Clear ();
388
417
                }
389
 
                
390
 
                void UpdateRecentNotesMenu (Gtk.Widget parent) 
 
418
 
 
419
                void UpdateRecentNotesMenu (Gtk.Widget parent)
391
420
                {
392
421
                        if (!menu_added) {
393
422
                                recent_menu.AttachToWidget (parent, GuiUtils.DetachMenu);
394
423
                                menu_added = true;
395
424
                        }
396
 
                        
 
425
 
397
426
                        AddRecentlyChangedNotes ();
398
427
 
399
428
                        recent_menu.ShowAll ();
400
429
                }
401
 
                
 
430
 
402
431
                // Used by TomboyApplet to modify the icon background.
403
432
                public Gtk.Image Image
404
433
                {
405
 
                        get { return image; }
 
434
                        get {
 
435
                                return image;
 
436
                        }
406
437
                }
407
438
 
408
439
                public void ShowMenu (bool select_first_item)
417
448
                // Support dropping text/uri-lists and _NETSCAPE_URLs currently.
418
449
                void SetupDragAndDrop ()
419
450
                {
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)
424
 
                                };
 
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)
 
455
                        };
425
456
 
426
 
                        Gtk.Drag.DestSet (this, 
427
 
                                          Gtk.DestDefaults.All, 
428
 
                                          targets,
429
 
                                          Gdk.DragAction.Copy);
 
457
                        Gtk.Drag.DestSet (this,
 
458
                                          Gtk.DestDefaults.All,
 
459
                                          targets,
 
460
                                          Gdk.DragAction.Copy);
430
461
 
431
462
                        DragDataReceived += OnDragDataReceived;
432
463
                }
433
464
 
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.
439
470
                //
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");
454
485
 
455
 
                                if (uri.IsFile) 
 
486
                                if (uri.IsFile)
456
487
                                        insert_text.Append (uri.LocalPath);
457
488
                                else
458
489
                                        insert_text.Append (uri.ToString ());
459
490
 
460
491
                                more_than_one = true;
461
492
                        }
462
 
                        
 
493
 
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, 
467
 
                                                        DateTime.Now, 
468
 
                                                        insert_text.ToString ());
 
497
                                PrependTimestampedText (link_note,
 
498
                                                        DateTime.Now,
 
499
                                                        insert_text.ToString ());
469
500
                        }
470
501
                }
471
 
                
 
502
 
472
503
                void InitPixbuf ()
473
504
                {
474
505
                        // For some reason, the first time we ask for the allocation,
477
508
                        // to be called again anyhow.
478
509
                        if (panel_size < 16)
479
510
                                panel_size = 16;
480
 
                        
 
511
 
481
512
                        // Control specifically which icon is used at the smaller sizes
482
513
                        // so that no scaling occurs.  In the case of the panel applet,
483
514
                        // add a couple extra pixels of padding so it matches the behavior
485
516
                        // info.
486
517
                        int icon_size = panel_size;
487
518
                        if (Tomboy.IsPanelApplet)
488
 
                                icon_size = panel_size - 2;     // padding
 
519
                                icon_size = panel_size - 2; // padding
489
520
                        if (icon_size <= 21)
490
521
                                icon_size = 16;
491
522
                        else if (icon_size <= 31)
496
527
                        Gdk.Pixbuf new_icon = GuiUtils.GetIcon ("tomboy", icon_size);
497
528
                        image.Pixbuf = new_icon;
498
529
                }
499
 
                
 
530
 
500
531
                ///
501
532
                /// Determine whether the tray is inside a horizontal or vertical
502
533
                /// panel so the size of the icon can adjust correctly.
506
537
                        if (this.ParentWindow == null) {
507
538
                                return PanelOrientation.Horizontal;
508
539
                        }
509
 
                        
 
540
 
510
541
                        Gdk.Window top_level_window = this.ParentWindow.Toplevel;
511
 
                        
 
542
 
512
543
                        Gdk.Rectangle rect = top_level_window.FrameExtents;
513
544
                        if (rect.Width < rect.Height)
514
545
                                return PanelOrientation.Vertical;
515
 
                        
 
546
 
516
547
                        return PanelOrientation.Horizontal;
517
548
                }
518
549
 
524
555
                        if (GetPanelOrientation () == PanelOrientation.Horizontal) {
525
556
                                if (panel_size == Allocation.Height)
526
557
                                        return;
527
 
                                
 
558
 
528
559
                                panel_size = Allocation.Height;
529
560
                        } else {
530
561
                                if (panel_size == Allocation.Width)
531
562
                                        return;
532
 
                                
 
563
 
533
564
                                panel_size = Allocation.Width;
534
565
                        }
535
 
                        
 
566
 
536
567
                        InitPixbuf ();
537
568
                }
538
569
        }
539
570
 
540
 
        // 
 
571
        //
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.
559
590
                {
560
591
                        try {
561
592
                                string binding = (string) Preferences.Get (gconf_path);
562
 
                                if (binding == null || 
563
 
                                    binding == String.Empty || 
564
 
                                    binding == "disabled")
 
593
                                if (binding == null ||
 
594
                                                binding == String.Empty ||
 
595
                                                binding == "disabled")
565
596
                                        return null;
566
597
 
567
598
                                binding = binding.Replace ("<", "");
569
600
 
570
601
                                return binding;
571
602
                        } catch {
572
 
                                return null;
573
 
                        }
 
603
                        return null;
574
604
                }
 
605
        }
575
606
 
576
 
                [DllImport("libtomboy")]
 
607
        [DllImport("libtomboy")]
577
608
                static extern bool egg_accelerator_parse_virtual (string keystring,
578
 
                                                                  out uint keysym,
579
 
                                                                  out uint virtual_mods);
 
609
                                        out uint keysym,
 
610
                                        out uint virtual_mods);
580
611
 
581
612
                [DllImport("libtomboy")]
582
613
                static extern void egg_keymap_resolve_virtual_modifiers (
583
 
                        IntPtr keymap,
584
 
                        uint virtual_mods,
585
 
                        out Gdk.ModifierType real_mods);
 
614
                                IntPtr keymap,
 
615
                                uint virtual_mods,
 
616
                                out Gdk.ModifierType real_mods);
586
617
 
587
 
                public static bool GetAccelKeys (string               gconf_path, 
588
 
                                                 out uint             keyval, 
589
 
                                                 out Gdk.ModifierType mods)
 
618
                public static bool GetAccelKeys (string               gconf_path,
 
619
                                                 out uint             keyval,
 
620
                                                 out Gdk.ModifierType mods)
590
621
                {
591
622
                        keyval = 0;
592
623
                        mods = 0;
593
624
 
594
625
                        try {
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")
599
630
                                        return false;
600
631
 
601
632
                                uint virtual_mods = 0;
602
633
                                if (!egg_accelerator_parse_virtual (binding,
603
 
                                                                    out keyval,
604
 
                                                                    out virtual_mods))
 
634
                                                                    out keyval,
 
635
                                                                    out virtual_mods))
605
636
                                        return false;
606
637
 
607
638
                                Gdk.Keymap keymap = Gdk.Keymap.Default;
608
639
                                egg_keymap_resolve_virtual_modifiers (keymap.Handle,
609
 
                                                                      virtual_mods,
610
 
                                                                      out mods);
 
640
                                                                      virtual_mods,
 
641
                                                                      out mods);
611
642
 
612
643
                                return true;
613
644
                        } catch {
614
 
                                return false;
615
 
                        }
 
645
                        return false;
616
646
                }
 
647
        }
617
648
 
618
 
                public static void AddAccelerator (Gtk.MenuItem item, string gconf_path)
 
649
        public static void AddAccelerator (Gtk.MenuItem item, string gconf_path)
619
650
                {
620
651
                        uint keyval;
621
652
                        Gdk.ModifierType mods;
622
653
 
623
654
                        if (GetAccelKeys (gconf_path, out keyval, out mods))
624
655
                                item.AddAccelerator ("activate",
625
 
                                                     accel_group,
626
 
                                                     keyval,
627
 
                                                     mods,
628
 
                                                     Gtk.AccelFlags.Visible);
 
656
                                                     accel_group,
 
657
                                                     keyval,
 
658
                                                     mods,
 
659
                                                     Gtk.AccelFlags.Visible);
629
660
                }
630
661
        }
631
662
}