3
using System.Collections;
5
using System.Runtime.InteropServices;
9
public class TomboyTray
15
static Gdk.Pixbuf tintin;
16
static Gdk.Pixbuf stock_notes;
20
tintin = GuiUtils.GetMiniIcon ("tintin.png");
21
stock_notes = GuiUtils.GetMiniIcon ("stock_notes.png");
24
public TomboyTray (NoteManager manager)
26
this.manager = manager;
28
Gtk.EventBox ev = new Gtk.EventBox ();
30
ev.ButtonPressEvent += ButtonPress;
31
ev.Add (new Gtk.Image (tintin));
33
string tip_text = Catalog.GetString ("Tomboy Notes");
36
GConfKeybindingToAccel.GetShortcut (
37
TomboyGConfXKeybinder.MENU_BINDING);
39
tip_text += String.Format (" ({0})", shortcut);
41
tips = new Gtk.Tooltips ();
42
tips.SetTip (ev, tip_text, null);
45
icon = new Egg.TrayIcon (Catalog.GetString ("Tomboy"));
50
public void ShowMenu ()
52
Gtk.Menu recent_menu = MakeRecentNotesMenu (icon);
53
GuiUtils.PopupMenu (recent_menu, null);
56
void ButtonPress (object sender, Gtk.ButtonPressEventArgs args)
58
Gtk.Widget parent = (Gtk.Widget) sender;
59
Gtk.Menu recent_menu = MakeRecentNotesMenu (parent);
60
GuiUtils.PopupMenu (recent_menu, args.Event);
63
Gtk.Menu MakeRecentNotesMenu (Gtk.Widget parent)
65
Gtk.Menu menu = new Gtk.Menu ();
66
menu.AttachToWidget (parent, null);
68
Gtk.ImageMenuItem item;
70
item = new Gtk.ImageMenuItem (Catalog.GetString ("Create _New Note"));
71
item.Image = new Gtk.Image (Gtk.Stock.New, Gtk.IconSize.Menu);
72
item.Activated += CreateNewNote;
75
GConfKeybindingToAccel.AddAccelerator (
77
TomboyGConfXKeybinder.NEW_NOTE_BINDING);
79
// FIXME: Pull this from GConf
84
DateTime two_days_ago = DateTime.Now.AddDays (-2);
86
// List the i most recently changed notes, and any
87
// currently opened notes...
88
foreach (Note note in manager.Notes) {
93
note.ChangeDate > two_days_ago ||
94
list_size < min_size) {
95
item = MakeNoteMenuItem (note);
100
if (list_size == max_size)
105
Gdk.ModifierType mods;
107
Note start = manager.Find (Catalog.GetString ("Start Here"));
109
item = MakeNoteMenuItem (start);
112
GConfKeybindingToAccel.AddAccelerator (
114
TomboyGConfXKeybinder.START_BINDING);
117
menu.Append (new Gtk.SeparatorMenuItem ());
119
item = new Gtk.ImageMenuItem (Catalog.GetString ("_Recent Changes"));
120
item.Image = new Gtk.Image (Gtk.Stock.SortAscending, Gtk.IconSize.Menu);
121
item.Activated += ViewRecentChanges;
124
GConfKeybindingToAccel.AddAccelerator (
126
TomboyGConfXKeybinder.RECENT_BINDING);
128
item = new Gtk.ImageMenuItem (Catalog.GetString ("_Search Notes..."));
129
item.Image = new Gtk.Image (Gtk.Stock.Find, Gtk.IconSize.Menu);
130
item.Activated += SearchNotes;
133
GConfKeybindingToAccel.AddAccelerator (
135
TomboyGConfXKeybinder.SEARCH_BINDING);
137
menu.Append (new Gtk.SeparatorMenuItem ());
139
item = new Gtk.ImageMenuItem (Catalog.GetString ("_Quit"));
140
item.Image = new Gtk.Image (Gtk.Stock.Quit, Gtk.IconSize.Menu);
141
item.Activated += Quit;
148
Gtk.ImageMenuItem MakeNoteMenuItem (Note note)
150
string display_name = note.Title;
152
display_name += Catalog.GetString (" (new)");
154
Gtk.ImageMenuItem item = new Gtk.ImageMenuItem (display_name);
155
item.Image = new Gtk.Image (stock_notes);
156
item.Data ["Note"] = note;
157
item.Activated += ShowNote;
162
void ShowNote (object sender, EventArgs args)
164
Note note = (Note) ((Gtk.Widget) sender).Data ["Note"];
166
note.Window.Present ();
169
void CreateNewNote (object sender, EventArgs args)
171
Note new_note = manager.Create ();
172
new_note.Window.Show ();
175
void SearchNotes (object sender, EventArgs args)
177
NoteFindDialog find_dialog = NoteFindDialog.GetInstance (manager);
178
find_dialog.Present ();
181
void ViewRecentChanges (object sender, EventArgs args)
183
Gtk.Window recent = new NoteRecentChanges (manager);
187
void Quit (object sender, EventArgs args)
189
Console.WriteLine ("Quitting Tomboy. Ciao!");
190
Environment.Exit (0);
193
// FIXME: If receiving a drag, pop up last window used, or a new
194
// window, or the recent list? I think recent list
198
// This is a helper to take the XKeybinding string from GConf, and
199
// convert it to a widget accelerator label, so note menu items can
200
// display their global X keybinding.
202
// FIXME: It would be totally sweet to allow setting the accelerator
203
// visually through the menuitem, and have the new value be stored in
207
public class GConfKeybindingToAccel
209
static GConf.Client client;
210
static Gtk.AccelGroup accel_group;
212
static GConfKeybindingToAccel ()
214
client = new GConf.Client ();
215
accel_group = new Gtk.AccelGroup ();
218
public static string GetShortcut (string gconf_path)
221
string binding = (string) client.Get (gconf_path);
222
if (binding == null ||
223
binding == String.Empty ||
224
binding == "disabled")
227
binding = binding.Replace ("<", "");
228
binding = binding.Replace (">", "-");
236
[DllImport("libtrayicon")]
237
static extern bool egg_accelerator_parse_virtual (string keystring,
239
out uint virtual_mods);
241
[DllImport("libtrayicon")]
242
static extern void egg_keymap_resolve_virtual_modifiers (IntPtr keymap,
244
out Gdk.ModifierType real_mods);
246
public static bool GetAccelKeys (string gconf_path,
248
out Gdk.ModifierType mods)
254
string binding = (string) client.Get (gconf_path);
255
if (binding == null ||
256
binding == String.Empty ||
257
binding == "disabled")
260
uint virtual_mods = 0;
261
if (!egg_accelerator_parse_virtual (binding,
266
Gdk.Keymap keymap = Gdk.Keymap.Default;
267
egg_keymap_resolve_virtual_modifiers (keymap.Handle,
277
public static void AddAccelerator (Gtk.MenuItem item, string gconf_path)
280
Gdk.ModifierType mods;
282
if (GetAccelKeys (gconf_path, out keyval, out mods))
283
item.AddAccelerator ("activate",
287
Gtk.AccelFlags.Visible);