67
67
this.IconName = "tomboy";
68
68
this.DefaultWidth = 200;
69
69
this.current_matches = new Hashtable ();
72
accel_group = new Gtk.AccelGroup ();
73
AddAccelGroup (accel_group);
75
Gtk.Image image = new Gtk.Image (GuiUtils.GetIcon ("gnome-searchtool", 48));
71
AddAccelGroup (Tomboy.ActionManager.UI.AccelGroup);
73
menu_bar = CreateMenuBar ();
75
Gtk.Image image = new Gtk.Image (GuiUtils.GetIcon ("system-search", 48));
77
77
Gtk.Label label = new Gtk.Label (Catalog.GetString ("_Search:"));
148
149
matches_window.Add (tree);
149
150
matches_window.Show ();
151
close_button = new Gtk.Button (Gtk.Stock.Close);
152
close_button.Clicked += CloseClicked;
153
close_button.AddAccelerator ("activate",
155
(uint) Gdk.Key.Escape,
157
Gtk.AccelFlags.Visible);
158
close_button.Show ();
160
Gtk.HButtonBox button_box = new Gtk.HButtonBox ();
161
button_box.Layout = Gtk.ButtonBoxStyle.Edge;
162
button_box.Spacing = 8;
163
button_box.PackStart (note_count);
164
button_box.PackStart (close_button);
167
content_vbox = new Gtk.VBox (false, 8);
168
content_vbox.BorderWidth = 6;
169
content_vbox.PackStart (hbox, false, false, 0);
170
content_vbox.PackStart (matches_window);
171
content_vbox.PackStart (button_box, false, false, 0);
152
Gtk.HBox status_box = new Gtk.HBox (false, 8);
153
status_box.PackStart (note_count, true, true, 0);
156
Gtk.VBox vbox = new Gtk.VBox (false, 8);
157
vbox.BorderWidth = 6;
158
vbox.PackStart (hbox, false, false, 0);
159
vbox.PackStart (matches_window);
160
vbox.PackStart (status_box, false, false, 0);
163
// Use another VBox to place the MenuBar
164
// right at thetop of the window.
165
content_vbox = new Gtk.VBox (false, 0);
166
content_vbox.PackStart (menu_bar, false, false, 0);
167
content_vbox.PackStart (vbox, true, true, 0);
172
168
content_vbox.Show ();
174
170
this.Add (content_vbox);
175
171
this.DeleteEvent += OnDelete;
172
this.KeyPressEvent += OnKeyPressed; // For Escape
175
Gtk.MenuBar CreateMenuBar ()
177
ActionManager am = Tomboy.ActionManager;
178
Gtk.MenuBar menubar =
179
am.GetWidget ("/MainWindowMenubar") as Gtk.MenuBar;
181
am ["OpenNoteAction"].Activated += OnOpenNote;
182
am ["DeleteNoteAction"].Activated += OnDeleteNote;
183
am ["CloseWindowAction"].Activated += OnCloseWindow;
184
if (Tomboy.TrayIconShowing == false)
185
am ["CloseWindowAction"].Visible = false;
187
// Allow Escape to close the window as well as <Control>W
188
// Should be able to add Escape to the CloseAction. Can't do that
189
// until someone fixes AccelGroup.Connect:
190
// http://bugzilla.ximian.com/show_bug.cgi?id=76988)
192
// am.UI.AccelGroup.Connect ((uint) Gdk.Key.Escape,
194
// Gtk.AccelFlags.Mask,
200
void ShowMenuItem (Gtk.Widget widget)
178
205
void MakeRecentTree ()
180
207
Gtk.TargetEntry [] targets =
535
563
args.SelectionData.Text = note.Title;
566
void OnSelectionChanged (object sender, EventArgs args)
568
Note note = GetSelectedNote ();
570
Tomboy.ActionManager ["OpenNoteAction"].Sensitive = true;
571
Tomboy.ActionManager ["DeleteNoteAction"].Sensitive = true;
573
Tomboy.ActionManager ["OpenNoteAction"].Sensitive = false;
574
Tomboy.ActionManager ["DeleteNoteAction"].Sensitive = false;
579
void OnButtonPressed (object sender, Gtk.ButtonPressEventArgs args)
581
switch (args.Event.Button) {
582
case 3: // third mouse button (right-click)
583
Gtk.TreePath path = null;
584
Gtk.TreeViewColumn column = null;
586
if (tree.GetPathAtPos ((int) args.Event.X,
589
out column) == false)
592
Gtk.TreeSelection selection = tree.Selection;
593
if (selection.CountSelectedRows () == 0)
596
PopupContextMenuAtLocation ((int) args.Event.X,
603
void PopupContextMenuAtLocation (int x, int y)
605
Gtk.Menu menu = Tomboy.ActionManager.GetWidget (
606
"/MainWindowContextMenu") as Gtk.Menu;
608
Gtk.MenuPositionFunc pos_menu_func = null;
610
// Set up the funtion to position the context menu
611
// if we were called by the keyboard Gdk.Key.Menu.
612
if (x == 0 && y == 0)
613
pos_menu_func = PositionContextMenu;
615
menu.Popup (null, null,
618
Gtk.Global.CurrentEventTime);
621
// This is needed for when the user opens
622
// the context menu with the keyboard.
623
void PositionContextMenu (Gtk.Menu menu,
624
out int x, out int y, out bool push_in)
628
Gtk.TreeSelection selection;
630
// Set default "return" values
631
push_in = false; // not used
635
selection = tree.Selection;
636
if (!selection.GetSelected (out iter))
639
path = store_sort.GetPath (iter);
644
GetWidgetScreenPos (tree, ref pos_x, ref pos_y);
645
Gdk.Rectangle cell_rect = tree.GetCellArea (path, tree.Columns [0]);
647
// Add 100 to x so it's not be at the far left
648
x = pos_x + cell_rect.X + 100;
649
y = pos_y + cell_rect.Y;
652
// Walk the widget hiearchy to figure out
653
// where to position the context menu.
654
void GetWidgetScreenPos (Gtk.Widget widget, ref int x, ref int y)
659
if (widget is Gtk.Window) {
660
((Gtk.Window) widget).GetPosition (out widget_x, out widget_y);
662
GetWidgetScreenPos (widget.Parent, ref x, ref y);
664
// Special case the TreeView because it adds
665
// too much since it's in a scrolled window.
666
if (widget == tree) {
670
Gdk.Rectangle widget_rect = widget.Allocation;
671
widget_x = widget_rect.X;
672
widget_y = widget_rect.Y;
538
680
Note GetSelectedNote ()
570
712
return date.ToString (Catalog.GetString ("MMMM d yyyy, h:mm tt"));
573
void CloseClicked (object sender, EventArgs args)
715
void OnOpenNote (object sender, EventArgs args)
717
Note note = GetSelectedNote ();
721
note.Window.Present ();
724
void OnDeleteNote (object sender, EventArgs args)
726
Note note = GetSelectedNote ();
730
NoteUtils.ShowDeletionDialog (note, this);
733
void OnCloseWindow (object sender, EventArgs args)
575
735
// Disconnect external signal handlers to prevent bloweup
576
736
manager.NoteDeleted -= OnNotesChanged;
577
737
manager.NoteAdded -= OnNotesChanged;
578
738
manager.NoteRenamed -= OnNoteRenamed;
740
// The following code has to be done for the MenuBar to
741
// appear properly the next time this window is opened.
742
if (menu_bar != null) {
743
content_vbox.Remove (menu_bar);
744
ActionManager am = Tomboy.ActionManager;
745
am ["OpenNoteAction"].Activated -= OnOpenNote;
746
am ["DeleteNoteAction"].Activated -= OnDeleteNote;
747
am ["CloseWindowAction"].Activated -= OnCloseWindow;
754
if (Tomboy.TrayIconShowing == false)
755
Tomboy.ActionManager ["QuitTomboyAction"].Activate ();
585
758
void OnDelete (object sender, Gtk.DeleteEventArgs args)
587
CloseClicked (sender, EventArgs.Empty);
760
OnCloseWindow (sender, EventArgs.Empty);
588
761
args.RetVal = true;
764
void OnKeyPressed (object sender, Gtk.KeyPressEventArgs args)
766
switch (args.Event.Key) {
768
// Allow Escape to close the window
769
OnCloseWindow (this, EventArgs.Empty);
772
// Pop up the context menu if a note is selected
773
Note note = GetSelectedNote ();
775
PopupContextMenuAtLocation (0, 0);
591
781
protected override void OnShown ()
593
783
find_combo.Entry.GrabFocus ();
680
void OnKeyPressed (object obj, Gtk.KeyPressEventArgs args)
682
Gdk.EventKey eventKey = args.Event;
684
if (eventKey.Key == Gdk.Key.Delete &&
685
eventKey.State == 0 /* Gdk.ModifierType.None */) {
686
// Get the selected note and prompt for deletion
687
Note note = GetSelectedNote();
691
NoteUtils.ShowDeletionDialog (note, this);
695
870
void OnEntryActivated (object sender, EventArgs args)
697
872
if (entry_changed_timeout != null)