~ubuntu-branches/ubuntu/lucid/tomboy/lucid-proposed

« back to all changes in this revision

Viewing changes to Tomboy/RecentChanges.cs

Tags: upstream-0.5.2
Import upstream version 0.5.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
10
10
        {
11
11
                NoteManager manager;
12
12
 
13
 
                Gtk.AccelGroup accel_group;
 
13
                Gtk.MenuBar menu_bar;
14
14
                Gtk.ComboBoxEntry find_combo;
15
15
                Gtk.Button clear_search_button;
16
16
                Gtk.CheckButton case_sensitive;
67
67
                        this.IconName = "tomboy";
68
68
                        this.DefaultWidth = 200;
69
69
                        this.current_matches = new Hashtable ();
70
 
 
71
 
                        // For Escape (Close)
72
 
                        accel_group = new Gtk.AccelGroup ();
73
 
                        AddAccelGroup (accel_group);
74
 
 
75
 
                        Gtk.Image image = new Gtk.Image (GuiUtils.GetIcon ("gnome-searchtool", 48));
 
70
                        
 
71
                        AddAccelGroup (Tomboy.ActionManager.UI.AccelGroup);
 
72
 
 
73
                        menu_bar = CreateMenuBar ();
 
74
                        
 
75
                        Gtk.Image image = new Gtk.Image (GuiUtils.GetIcon ("system-search", 48));
76
76
 
77
77
                        Gtk.Label label = new Gtk.Label (Catalog.GetString ("_Search:"));
78
78
                        label.Xalign = 1;
118
118
                        tree.Show ();
119
119
 
120
120
                        note_count = new Gtk.Label ();
 
121
                        note_count.Xalign = 0;
121
122
                        note_count.Show ();
122
123
 
123
124
                        // Update on changes to notes
148
149
                        matches_window.Add (tree);
149
150
                        matches_window.Show ();
150
151
 
151
 
                        close_button = new Gtk.Button (Gtk.Stock.Close);
152
 
                        close_button.Clicked += CloseClicked;
153
 
                        close_button.AddAccelerator ("activate",
154
 
                                                     accel_group,
155
 
                                                     (uint) Gdk.Key.Escape, 
156
 
                                                     0,
157
 
                                                     Gtk.AccelFlags.Visible);
158
 
                        close_button.Show ();
159
 
 
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);
165
 
                        button_box.Show ();
166
 
 
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);
 
154
                        status_box.Show ();
 
155
                        
 
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);
 
161
                        vbox.Show ();
 
162
 
 
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 ();
173
169
 
174
170
                        this.Add (content_vbox);
175
171
                        this.DeleteEvent += OnDelete;
176
 
                }
177
 
 
 
172
                        this.KeyPressEvent += OnKeyPressed; // For Escape
 
173
                }
 
174
                
 
175
                Gtk.MenuBar CreateMenuBar ()
 
176
                {
 
177
                        ActionManager am = Tomboy.ActionManager;
 
178
                        Gtk.MenuBar menubar =
 
179
                                am.GetWidget ("/MainWindowMenubar") as Gtk.MenuBar;
 
180
                        
 
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;
 
186
                        
 
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)
 
191
                        //
 
192
                        //      am.UI.AccelGroup.Connect ((uint) Gdk.Key.Escape,
 
193
                        //                      0,
 
194
                        //                      Gtk.AccelFlags.Mask,
 
195
                        //                      OnCloseWindow);
 
196
                        
 
197
                        return menubar;
 
198
                }
 
199
                
 
200
                void ShowMenuItem (Gtk.Widget widget)
 
201
                {
 
202
                        widget.Show ();
 
203
                }
 
204
                
178
205
                void MakeRecentTree ()
179
206
                {
180
207
                        Gtk.TargetEntry [] targets = 
195
222
                        tree.RulesHint = true;
196
223
                        tree.RowActivated += OnRowActivated;
197
224
                        tree.DragDataGet += OnDragDataGet;
198
 
                        tree.KeyPressEvent += OnKeyPressed;
 
225
                        tree.Selection.Changed += OnSelectionChanged;
 
226
                        tree.ButtonPressEvent += OnButtonPressed;
199
227
 
200
228
                        tree.EnableModelDragSource (Gdk.ModifierType.Button1Mask,
201
229
                                                    targets,
534
562
 
535
563
                        args.SelectionData.Text = note.Title;
536
564
                }
 
565
                
 
566
                void OnSelectionChanged (object sender, EventArgs args)
 
567
                {
 
568
                        Note note = GetSelectedNote ();
 
569
                        if (note != null) {
 
570
                                Tomboy.ActionManager ["OpenNoteAction"].Sensitive = true;
 
571
                                Tomboy.ActionManager ["DeleteNoteAction"].Sensitive = true;
 
572
                        } else {
 
573
                                Tomboy.ActionManager ["OpenNoteAction"].Sensitive = false;
 
574
                                Tomboy.ActionManager ["DeleteNoteAction"].Sensitive = false;
 
575
                        }
 
576
                }
 
577
                
 
578
                [GLib.ConnectBefore]
 
579
                void OnButtonPressed (object sender, Gtk.ButtonPressEventArgs args)
 
580
                {
 
581
                        switch (args.Event.Button) {
 
582
                        case 3: // third mouse button (right-click)
 
583
                                Gtk.TreePath path = null;
 
584
                                Gtk.TreeViewColumn column = null;
 
585
                                
 
586
                                if (tree.GetPathAtPos ((int) args.Event.X,
 
587
                                                (int) args.Event.Y,
 
588
                                                out path,
 
589
                                                out column) == false)
 
590
                                        break;
 
591
                                
 
592
                                Gtk.TreeSelection selection = tree.Selection;
 
593
                                if (selection.CountSelectedRows () == 0)
 
594
                                        break;
 
595
                                
 
596
                                PopupContextMenuAtLocation ((int) args.Event.X,
 
597
                                                (int) args.Event.Y);
 
598
 
 
599
                                break;
 
600
                        }
 
601
                }
 
602
                
 
603
                void PopupContextMenuAtLocation (int x, int y)
 
604
                {
 
605
                        Gtk.Menu menu = Tomboy.ActionManager.GetWidget (
 
606
                                        "/MainWindowContextMenu") as Gtk.Menu;
 
607
                        menu.ShowAll ();
 
608
                        Gtk.MenuPositionFunc pos_menu_func = null;
 
609
                        
 
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;
 
614
                                
 
615
                        menu.Popup (null, null,
 
616
                                        pos_menu_func,
 
617
                                        0,
 
618
                                        Gtk.Global.CurrentEventTime);
 
619
                }
 
620
                
 
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)
 
625
                {
 
626
                        Gtk.TreeIter iter;
 
627
                        Gtk.TreePath path;
 
628
                        Gtk.TreeSelection selection;
 
629
                        
 
630
                        // Set default "return" values
 
631
                        push_in = false; // not used
 
632
                        x = 0;
 
633
                        y = 0;
 
634
                        
 
635
                        selection = tree.Selection;
 
636
                        if (!selection.GetSelected (out iter))
 
637
                                return;
 
638
                        
 
639
                        path = store_sort.GetPath (iter);
 
640
                        
 
641
                        int pos_x = 0;
 
642
                        int pos_y = 0;
 
643
                        
 
644
                        GetWidgetScreenPos (tree, ref pos_x, ref pos_y);
 
645
                        Gdk.Rectangle cell_rect = tree.GetCellArea (path, tree.Columns [0]);
 
646
                        
 
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;
 
650
                }
 
651
                
 
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)
 
655
                {
 
656
                        int widget_x;
 
657
                        int widget_y;
 
658
                        
 
659
                        if (widget is Gtk.Window) {
 
660
                                ((Gtk.Window) widget).GetPosition (out widget_x, out widget_y);
 
661
                        } else {
 
662
                                GetWidgetScreenPos (widget.Parent, ref x, ref y);
 
663
                                
 
664
                                // Special case the TreeView because it adds
 
665
                                // too much since it's in a scrolled window.
 
666
                                if (widget == tree) {
 
667
                                        widget_x = 2;
 
668
                                        widget_y = 2;
 
669
                                } else {
 
670
                                        Gdk.Rectangle widget_rect = widget.Allocation;
 
671
                                        widget_x = widget_rect.X;
 
672
                                        widget_y = widget_rect.Y;
 
673
                                }
 
674
                        }
 
675
                        
 
676
                        x += widget_x;
 
677
                        y += widget_y;
 
678
                }
537
679
 
538
680
                Note GetSelectedNote ()
539
681
                {
569
711
                        } else
570
712
                                return date.ToString (Catalog.GetString ("MMMM d yyyy, h:mm tt"));
571
713
                }
572
 
 
573
 
                void CloseClicked (object sender, EventArgs args)
 
714
                
 
715
                void OnOpenNote (object sender, EventArgs args)
 
716
                {
 
717
                        Note note = GetSelectedNote ();
 
718
                        if (note == null)
 
719
                                return;
 
720
                                
 
721
                        note.Window.Present ();
 
722
                }
 
723
                
 
724
                void OnDeleteNote (object sender, EventArgs args)
 
725
                {
 
726
                        Note note = GetSelectedNote ();
 
727
                        if (note == null)
 
728
                                return;
 
729
                        
 
730
                        NoteUtils.ShowDeletionDialog (note, this);
 
731
                }
 
732
                
 
733
                void OnCloseWindow (object sender, EventArgs args)
574
734
                {
575
735
                        // Disconnect external signal handlers to prevent bloweup
576
736
                        manager.NoteDeleted -= OnNotesChanged;
577
737
                        manager.NoteAdded -= OnNotesChanged;
578
738
                        manager.NoteRenamed -= OnNoteRenamed;
579
 
 
 
739
                        
 
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;
 
748
                        }
 
749
                        
580
750
                        Hide ();
581
751
                        Destroy ();
582
752
                        instance = null;
 
753
 
 
754
                        if (Tomboy.TrayIconShowing == false)
 
755
                                Tomboy.ActionManager ["QuitTomboyAction"].Activate ();
583
756
                }
584
757
                
585
758
                void OnDelete (object sender, Gtk.DeleteEventArgs args)
586
759
                {
587
 
                        CloseClicked (sender, EventArgs.Empty);
 
760
                        OnCloseWindow (sender, EventArgs.Empty);
588
761
                        args.RetVal = true;
589
762
                }
590
763
                
 
764
                void OnKeyPressed (object sender, Gtk.KeyPressEventArgs args)
 
765
                {
 
766
                        switch (args.Event.Key) {
 
767
                        case Gdk.Key.Escape:
 
768
                                // Allow Escape to close the window
 
769
                                OnCloseWindow (this, EventArgs.Empty);
 
770
                                break;
 
771
                        case Gdk.Key.Menu:
 
772
                                // Pop up the context menu if a note is selected
 
773
                                Note note = GetSelectedNote ();
 
774
                                if (note != null)
 
775
                                        PopupContextMenuAtLocation (0, 0);
 
776
 
 
777
                                break;
 
778
                        }
 
779
                }
 
780
                
591
781
                protected override void OnShown ()
592
782
                {
593
783
                        find_combo.Entry.GrabFocus ();
677
867
                        }
678
868
                }
679
869
 
680
 
                void OnKeyPressed (object obj, Gtk.KeyPressEventArgs args)
681
 
                {
682
 
                        Gdk.EventKey eventKey = args.Event;
683
 
 
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();
688
 
                                if (note == null)
689
 
                                        return;
690
 
 
691
 
                                NoteUtils.ShowDeletionDialog (note, this);
692
 
                        }               
693
 
                }
694
 
                
695
870
                void OnEntryActivated (object sender, EventArgs args)
696
871
                {
697
872
                        if (entry_changed_timeout != null)