105
108
Gdk.Pixmap pixmap)
110
if (applet_event_box == null)
110
113
Gtk.RcStyle rc_style = new Gtk.RcStyle ();
112
tray.ModifyStyle (rc_style);
114
applet_event_box.Style = null;
115
applet_event_box.ModifyStyle (rc_style);
115
118
case PanelAppletBackgroundType.ColorBackground:
116
tray.ModifyBg (Gtk.StateType.Normal, color);
119
applet_event_box.ModifyBg (Gtk.StateType.Normal, color);
118
121
case PanelAppletBackgroundType.NoBackground:
120
123
case PanelAppletBackgroundType.PixmapBackground:
121
Gtk.Style copy = tray.Style.Copy();
124
Gtk.Style copy = applet_event_box.Style.Copy();
122
125
copy.SetBgPixmap (Gtk.StateType.Normal, pixmap);
126
applet_event_box.Style = copy;
128
131
protected override void OnChangeSize (uint size)
133
if (applet_event_box == null)
133
tray.SetSizeRequest ((int) size, (int) size);
136
applet_event_box.SetSizeRequest ((int) size, (int) size);
137
public class TomboyTrayIcon : Gtk.Plug
140
public enum PanelOrientation { Horizontal, Vertical };
142
public class TomboyAppletEventBox : Gtk.EventBox
139
144
NoteManager manager;
141
TomboyGConfXKeybinder keybinder;
143
[DllImport ("libtomboy")]
144
private static extern IntPtr egg_tray_icon_new (string name);
146
public TomboyTrayIcon ()
147
: this (Tomboy.DefaultNoteManager)
151
public TomboyTrayIcon (NoteManager manager)
153
this.Raw = egg_tray_icon_new (Catalog.GetString ("Tomboy Notes"));
150
public TomboyAppletEventBox (NoteManager manager)
154
153
this.manager = manager;
156
tray = new TomboyTray (manager);
157
tray.ButtonPressEvent += ButtonPress;
159
keybinder = new TomboyGConfXKeybinder (manager, tray);
154
tray = new TomboyTray (manager, this);
156
// Load a 16x16-sized icon to ensure we don't end up with a
159
this.image = new Gtk.Image (GuiUtils.GetIcon ("tomboy", panel_size));
161
this.CanFocus = true;
162
this.ButtonPressEvent += ButtonPress;
166
string tip_text = TomboyTrayUtils.GetToolTipText ();
168
tips = new Gtk.Tooltips ();
169
tips.SetTip (this, tip_text, null);
176
public TomboyTray Tray
165
183
void ButtonPress (object sender, Gtk.ButtonPressEventArgs args)
167
185
Gtk.Widget parent = (Gtk.Widget) sender;
169
if (args.Event.Button == 3) {
170
Gtk.Menu menu = MakeRightClickMenu (parent);
171
GuiUtils.PopupMenu (menu, args.Event);
187
switch (args.Event.Button) {
189
TomboyTrayUtils.UpdateTomboyTrayMenu (tray, parent);
190
GuiUtils.PopupMenu (tray.TomboyTrayMenu, args.Event);
172
191
args.RetVal = true;
194
if ((bool) Preferences.Get (Preferences.ENABLE_ICON_PASTE)) {
195
// Give some visual feedback
196
Gtk.Drag.Highlight (this);
197
args.RetVal = PastePrimaryClipboard ();
198
Gtk.Drag.Unhighlight (this);
176
Gtk.Menu MakeRightClickMenu (Gtk.Widget parent)
178
Gtk.Menu menu = new Gtk.Menu ();
179
menu.AttachToWidget (parent, GuiUtils.DetachMenu);
181
Gtk.AccelGroup accel_group = new Gtk.AccelGroup ();
182
menu.AccelGroup = accel_group;
184
Gtk.ImageMenuItem item;
186
item = new Gtk.ImageMenuItem (Catalog.GetString ("_Preferences"));
187
item.Image = new Gtk.Image (Gtk.Stock.Preferences, Gtk.IconSize.Menu);
188
item.Activated += ShowPreferences;
191
item = new Gtk.ImageMenuItem (Catalog.GetString ("_Help"));
192
item.Image = new Gtk.Image (Gtk.Stock.Help, Gtk.IconSize.Menu);
193
item.Activated += ShowHelpContents;
196
item = new Gtk.ImageMenuItem (Catalog.GetString ("_About Tomboy"));
197
item.Image = new Gtk.Image (Gtk.Stock.About, Gtk.IconSize.Menu);
198
item.Activated += ShowAbout;
201
menu.Append (new Gtk.SeparatorMenuItem ());
203
item = new Gtk.ImageMenuItem (Catalog.GetString ("_Quit"));
204
item.Image = new Gtk.Image (Gtk.Stock.Quit, Gtk.IconSize.Menu);
205
item.Activated += Quit;
212
void ShowPreferences (object sender, EventArgs args)
214
Tomboy.ActionManager ["ShowPreferencesAction"].Activate ();
217
void ShowHelpContents (object sender, EventArgs args)
219
Tomboy.ActionManager ["ShowHelpAction"].Activate ();
222
void ShowAbout (object sender, EventArgs args)
224
Tomboy.ActionManager ["ShowAboutAction"].Activate ();
227
void Quit (object sender, EventArgs args)
229
Tomboy.ActionManager ["QuitTomboyAction"].Activate ();
232
public TomboyTray TomboyTray
204
void PrependTimestampedText (Note note, DateTime timestamp, string text)
206
NoteBuffer buffer = note.Buffer;
207
StringBuilder insert_text = new StringBuilder ();
209
insert_text.Append ("\n"); // initial newline
210
string date_format = Catalog.GetString ("dddd, MMMM d, h:mm tt");
211
insert_text.Append (timestamp.ToString (date_format));
212
insert_text.Append ("\n"); // begin content
213
insert_text.Append (text);
214
insert_text.Append ("\n"); // trailing newline
216
buffer.Undoer.FreezeUndo ();
218
// Insert the date and list of links...
219
Gtk.TextIter cursor = buffer.StartIter;
220
cursor.ForwardLines (1); // skip title
222
buffer.Insert (ref cursor, insert_text.ToString ());
224
// Make the date string a small font...
225
cursor = buffer.StartIter;
226
cursor.ForwardLines (2); // skip title & leading newline
228
Gtk.TextIter end = cursor;
229
end.ForwardToLineEnd (); // end of date
231
buffer.ApplyTag ("datetime", cursor, end);
233
// Select the text we've inserted (avoid trailing newline)...
235
end.ForwardChars (insert_text.Length - 1);
237
buffer.MoveMark (buffer.SelectionBound, cursor);
238
buffer.MoveMark (buffer.InsertMark, end);
240
buffer.Undoer.ThawUndo ();
243
bool PastePrimaryClipboard ()
245
Gtk.Clipboard clip = GetClipboard (Gdk.Selection.Primary);
246
string text = clip.WaitForText ();
248
if (text == null || text.Trim() == string.Empty)
251
Note link_note = manager.FindByUri (NoteManager.StartNoteUri);
252
if (link_note == null)
255
link_note.Window.Present ();
256
PrependTimestampedText (link_note,
263
// Used by TomboyApplet to modify the icon background.
264
public Gtk.Image Image
271
public void ShowMenu (bool select_first_item)
273
TomboyTrayUtils.UpdateTomboyTrayMenu (tray, this);
274
if (select_first_item)
275
tray.TomboyTrayMenu.SelectFirst (false);
277
GuiUtils.PopupMenu (tray.TomboyTrayMenu, null);
280
// Support dropping text/uri-lists and _NETSCAPE_URLs currently.
281
void SetupDragAndDrop ()
283
Gtk.TargetEntry [] targets =
284
new Gtk.TargetEntry [] {
285
new Gtk.TargetEntry ("text/uri-list", 0, 0),
286
new Gtk.TargetEntry ("_NETSCAPE_URL", 0, 0)
289
Gtk.Drag.DestSet (this,
290
Gtk.DestDefaults.All,
292
Gdk.DragAction.Copy);
294
DragDataReceived += OnDragDataReceived;
297
// Pop up Start Here and insert dropped links, in the form:
298
// Wednesday, December 8, 6:45 AM
299
// http://luna/kwiki/index.cgi?AdelaideUniThoughts
300
// http://www.beatniksoftware.com/blog/
301
// And select the inserted text.
303
// FIXME: Make undoable, make sure our date-sizing tag never "bleeds".
305
void OnDragDataReceived (object sender, Gtk.DragDataReceivedArgs args)
307
UriList uri_list = new UriList (args.SelectionData);
308
if (uri_list.Count == 0)
311
StringBuilder insert_text = new StringBuilder ();
312
bool more_than_one = false;
314
foreach (Uri uri in uri_list) {
316
insert_text.Append ("\n");
319
insert_text.Append (uri.LocalPath);
321
insert_text.Append (uri.ToString ());
323
more_than_one = true;
326
Note link_note = manager.FindByUri (NoteManager.StartNoteUri);
327
if (link_note != null) {
328
link_note.Window.Present ();
329
PrependTimestampedText (link_note,
331
insert_text.ToString ());
337
// For some reason, the first time we ask for the allocation,
338
// it's a 1x1 pixel. Prevent against this by returning a
339
// reasonable default. Setting the icon causes OnSizeAllocated
340
// to be called again anyhow.
341
int icon_size = panel_size;
346
// Control specifically which icon is used at the smaller sizes
347
// so that no scaling occurs. In the case of the panel applet,
348
// add a couple extra pixels of padding so it matches the behavior
349
// of the notification area tray icon. See bug #403500 for more
351
if (Tomboy.IsPanelApplet)
352
icon_size = icon_size - 2; // padding
355
else if (icon_size <= 31)
357
else if (icon_size <= 47)
360
Gdk.Pixbuf new_icon = GuiUtils.GetIcon ("tomboy", icon_size);
361
image.Pixbuf = new_icon;
365
/// Determine whether the tray is inside a horizontal or vertical
366
/// panel so the size of the icon can adjust correctly.
368
PanelOrientation GetPanelOrientation ()
370
if (this.ParentWindow == null) {
371
return PanelOrientation.Horizontal;
374
Gdk.Window top_level_window = this.ParentWindow.Toplevel;
376
Gdk.Rectangle rect = top_level_window.FrameExtents;
377
if (rect.Width < rect.Height)
378
return PanelOrientation.Vertical;
380
return PanelOrientation.Horizontal;
383
protected override void OnSizeAllocated (Gdk.Rectangle rect)
385
base.OnSizeAllocated (rect);
387
// Determine the orientation
388
if (GetPanelOrientation () == PanelOrientation.Horizontal) {
389
if (panel_size == Allocation.Height)
392
panel_size = Allocation.Height;
394
if (panel_size == Allocation.Width)
397
panel_size = Allocation.Width;