~ubuntu-branches/ubuntu/gutsy/tomboy/gutsy-updates

« back to all changes in this revision

Viewing changes to Tomboy/Tray.cs

  • Committer: Bazaar Package Importer
  • Author(s): Sebastian Dröge
  • Date: 2006-11-16 21:24:14 UTC
  • mfrom: (1.1.7 upstream) (2.1.1 etch)
  • Revision ID: james.westby@ubuntu.com-20061116212414-i9mqu3nnn90ulo7m
Tags: 0.5.0-0ubuntu1
* New upstream release
* debian/patches/52_applet-crash.patch:
  + Dropped, merged upstream
* debian/control,
  debian/patches/52_external-dbus-sharp.patch:
  + Build depend on libdbus-1-cil and build against it instead of the
    bundled version
* debian/rules:
  + Install DBus service file into the correct directory
* debian/patches/53_tomboy-tray-icon.patch:
  + Correctly set the icon for the trayicon

Show diffs side-by-side

added added

removed removed

Lines of Context:
7
7
 
8
8
namespace Tomboy
9
9
{
 
10
        public class NoteMenuItem : Gtk.ImageMenuItem
 
11
        {
 
12
                Note note;
 
13
                Gtk.Image pin_img;
 
14
                bool pinned;
 
15
                bool inhibit_activate;
 
16
 
 
17
                static Gdk.Pixbuf note_icon;
 
18
                static Gdk.Pixbuf pinup;
 
19
                static Gdk.Pixbuf pinup_active;
 
20
                static Gdk.Pixbuf pindown;
 
21
 
 
22
                static NoteMenuItem ()
 
23
                {
 
24
                        // Cache this since we use it a lot.
 
25
                        note_icon = GuiUtils.GetIcon ("tomboy-note", 16);
 
26
                        pinup = GuiUtils.GetIcon ("pinup", 16);
 
27
                        pinup_active = GuiUtils.GetIcon ("pinup-active", 16);
 
28
                        pindown = GuiUtils.GetIcon ("pindown", 16);
 
29
                }
 
30
 
 
31
                public NoteMenuItem (Note note, bool show_pin)
 
32
                        : base (GetDisplayName(note))
 
33
                {
 
34
                        this.note = note;
 
35
                        Image = new Gtk.Image (note_icon);
 
36
 
 
37
                        if (show_pin) {
 
38
                                Gtk.HBox box = new Gtk.HBox (false, 0);
 
39
                                Gtk.Widget child = Child;
 
40
                                Remove (child);
 
41
                                box.PackStart (child, true, true, 0);
 
42
                                Add (box);
 
43
                                box.Show();
 
44
 
 
45
                                pinned = note.IsPinned;
 
46
                                pin_img = new Gtk.Image(pinned ? pindown : pinup);
 
47
                                pin_img.Show();
 
48
                                box.PackStart (pin_img, false, false, 0);
 
49
                        }
 
50
                }
 
51
 
 
52
                static string FormatForLabel (string name)
 
53
                {
 
54
                        // Replace underscores ("_") with double-underscores ("__")
 
55
                        // so Note menuitems are not created with mnemonics.
 
56
                        return name.Replace ("_", "__");
 
57
                }
 
58
 
 
59
                static string GetDisplayName (Note note)
 
60
                {
 
61
                        string display_name = note.Title;
 
62
                        if (note.IsNew)
 
63
                                display_name += Catalog.GetString (" (new)");
 
64
                        return FormatForLabel (display_name);
 
65
                }
 
66
 
 
67
                protected override void OnActivated () 
 
68
                {
 
69
                        if (!inhibit_activate) {
 
70
                                if (note != null)
 
71
                                        note.Window.Present ();
 
72
                        }
 
73
                }
 
74
 
 
75
                protected override bool OnButtonPressEvent (Gdk.EventButton ev)
 
76
                {
 
77
                        if (pin_img != null &&
 
78
                            ev.X >= pin_img.Allocation.X && 
 
79
                            ev.X < pin_img.Allocation.X + pin_img.Allocation.Width) {
 
80
                                pinned = note.IsPinned = !pinned;
 
81
                                pin_img.Pixbuf = pinned ? pindown : pinup;
 
82
                                inhibit_activate = true;
 
83
                                return true;
 
84
                        }
 
85
                        return base.OnButtonPressEvent (ev);
 
86
                }
 
87
 
 
88
                protected override bool OnButtonReleaseEvent (Gdk.EventButton ev)
 
89
                {
 
90
                        if (inhibit_activate) {
 
91
                                inhibit_activate = false;
 
92
                                return true;
 
93
                        }
 
94
                        return base.OnButtonReleaseEvent (ev);
 
95
                }
 
96
 
 
97
                protected override bool OnMotionNotifyEvent (Gdk.EventMotion ev)
 
98
                {
 
99
                        if (!pinned && pin_img != null) {
 
100
                                if (ev.X >= pin_img.Allocation.X && 
 
101
                                    ev.X < pin_img.Allocation.X + pin_img.Allocation.Width) {
 
102
                                        if (pin_img.Pixbuf != pinup_active)
 
103
                                                pin_img.Pixbuf = pinup_active;
 
104
                                } else if (pin_img.Pixbuf != pinup) {
 
105
                                        pin_img.Pixbuf = pinup;
 
106
                                }
 
107
                        }
 
108
                        return base.OnMotionNotifyEvent (ev);
 
109
                }
 
110
 
 
111
                protected override bool OnLeaveNotifyEvent (Gdk.EventCrossing ev)
 
112
                {
 
113
                        if (!pinned && pin_img != null) {
 
114
                                pin_img.Pixbuf = pinup;
 
115
                        }
 
116
                        return base.OnLeaveNotifyEvent (ev);                    
 
117
                }
 
118
        }
 
119
 
10
120
        public class TomboyTray : Gtk.EventBox
11
121
        {
12
122
                NoteManager manager;
15
125
                PreferencesDialog prefs_dlg;
16
126
                int icon_size_last = -1;
17
127
 
18
 
                static Gdk.Pixbuf note_icon;
19
 
 
20
 
                static TomboyTray ()
21
 
                {
22
 
                        // Cache this since we use it a lot.
23
 
                        note_icon = GuiUtils.GetIcon ("tomboy", 16);
24
 
                }
25
 
 
26
128
                public TomboyTray (NoteManager manager) 
27
129
                        : base ()
28
130
                {
152
254
                                        item, 
153
255
                                        Preferences.KEYBINDING_CREATE_NEW_NOTE);
154
256
 
155
 
                        // FIXME: Pull this from GConf
156
 
                        int min_size = 5;
 
257
                        int min_size = (int) Preferences.Get (Preferences.MENU_NOTE_COUNT);
157
258
                        int max_size = 18;
158
259
                        int list_size = 0;
159
260
 
160
 
                        DateTime two_days_ago = DateTime.Today.AddDays (-2);
 
261
                        DateTime days_ago = DateTime.Today.AddDays (-3);
161
262
 
162
 
                        // List the i most recently changed notes, and any
163
 
                        // currently opened notes...
 
263
                        // List the i most recently changed notes, any currently
 
264
                        // opened notes, and any pinned notes...
164
265
                        foreach (Note note in manager.Notes) {
165
266
                                if (note.IsSpecial)
166
267
                                        continue;
167
268
 
168
 
                                if ((note.IsOpened && note.Window.IsMapped) || 
169
 
                                    note.ChangeDate > two_days_ago ||
 
269
                                bool show = false;
 
270
                                
 
271
                                if ((note.IsOpened && note.Window.IsMapped) ||
 
272
                                    note.ChangeDate > days_ago ||
170
273
                                    list_size < min_size) {
171
 
                                        item = MakeNoteMenuItem (note);
 
274
                                        if (list_size <= max_size)
 
275
                                                show = true;
 
276
                                } else if (note.IsPinned) {
 
277
                                        show = true;
 
278
                                }
 
279
 
 
280
                                if (show) {
 
281
                                        item = new NoteMenuItem (note, true);
172
282
                                        menu.Append (item);
173
 
 
174
 
                                        if (++list_size == max_size)
175
 
                                            break;
 
283
                                        list_size++;
176
284
                                }
177
285
                        }
178
286
 
179
287
                        Note start = manager.Find (Catalog.GetString ("Start Here"));
180
288
                        if (start != null) {
181
 
                                item = MakeNoteMenuItem (start);
 
289
                                item = new NoteMenuItem (start, false);
182
290
                                menu.Append (item);
183
291
 
184
292
                                if (enable_keybindings)
199
307
                                        item, 
200
308
                                        Preferences.KEYBINDING_OPEN_RECENT_CHANGES);
201
309
 
202
 
                        item = new Gtk.ImageMenuItem (Catalog.GetString ("_Search Notes..."));
203
 
                        item.Image = new Gtk.Image (Gtk.Stock.Find, Gtk.IconSize.Menu);
204
 
                        item.Activated += SearchNotes;
205
 
                        menu.Append (item);
206
 
 
207
 
                        if (enable_keybindings)
208
 
                                GConfKeybindingToAccel.AddAccelerator (
209
 
                                        item, 
210
 
                                        Preferences.KEYBINDING_OPEN_SEARCH);
211
 
 
212
310
                        menu.ShowAll ();
213
311
                        return menu;
214
312
                }
215
313
 
216
 
                Gtk.ImageMenuItem MakeNoteMenuItem (Note note)
217
 
                {
218
 
                        string display_name = note.Title;
219
 
                        if (note.IsNew)
220
 
                                display_name += Catalog.GetString (" (new)");
221
 
 
222
 
                        display_name = FormatForLabel (display_name);
223
 
 
224
 
                        Gtk.ImageMenuItem item = new Gtk.ImageMenuItem (display_name);
225
 
                        item.Image = new Gtk.Image (note_icon);
226
 
                        item.Data ["Note"] = note;
227
 
                        item.Activated += ShowNote;
228
 
 
229
 
                        return item;
230
 
                }
231
 
 
232
 
                string FormatForLabel (string name)
233
 
                {
234
 
                        // Replace underscores ("_") with double-underscores ("__")
235
 
                        // so Note menuitems are not created with mnemonics.
236
 
                        return name.Replace ("_", "__");
237
 
                }
238
 
 
239
 
                void ShowNote (object sender, EventArgs args) 
240
 
                {
241
 
                        Note note = (Note) ((Gtk.Widget) sender).Data ["Note"];
242
 
                        if (note != null)
243
 
                                note.Window.Present ();
244
 
                }
245
 
 
246
314
                void CreateNewNote (object sender, EventArgs args) 
247
315
                {
248
316
                        try {
262
330
                        }
263
331
                }
264
332
 
265
 
                void SearchNotes (object sender, EventArgs args) 
266
 
                {
267
 
                        NoteFindDialog find_dialog = NoteFindDialog.GetInstance (manager);
268
 
                        find_dialog.Present ();
269
 
                }
270
 
 
271
333
                void ViewRecentChanges (object sender, EventArgs args)
272
334
                {
273
 
                        Gtk.Window recent = new NoteRecentChanges (manager);
274
 
                        recent.Show ();
 
335
                        NoteRecentChanges.GetInstance (manager).Present ();
275
336
                }
276
337
 
277
338
                // Used by TomboyApplet to modify the icon background.
307
368
                public void ShowAbout ()
308
369
                {
309
370
                        string [] authors = new string [] {
310
 
                                "Alex Graveley <alex@beatniksoftware.com>"
 
371
                                "Alex Graveley <alex@beatniksoftware.com>",
 
372
                                "Boyd Timothy <btimothy@gmail.com>",
 
373
                                "David Trowbridge <trowbrds@gmail.com>",
 
374
                                "Ryan Lortie <desrt@desrt.ca>",
 
375
                                "Sandy Armstrong <sanfordarmstrong@gmail.com>",
 
376
                                "Sebastian Rittau <srittau@jroger.in-berlin.de>"
311
377
                        };
312
378
 
313
379
                        string [] documenters = new string [] {