~ted/ubuntu/lucid/tomboy/with-patch

« back to all changes in this revision

Viewing changes to Tomboy/Watchers.cs

  • Committer: Bazaar Package Importer
  • Author(s): Pedro Fragoso
  • Date: 2008-01-15 11:32:52 UTC
  • mfrom: (1.1.31 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20080115113252-p59wg7nqkl6vcg7a
Tags: 0.9.4-0ubuntu1
* New upstream release (LP: #181798)
  - Fix crash during note deletion 
  - Fix null reference exception 
  - Fix mnemonics in sync preferences dialog 
  - Fix fuse mount timeout for sync 
  - New port option for SSH sync 
  - New multi-select notes support in Search All Notes window
  - New config dialog for Insert Timestamp Add-in 
  - New gconf preference, middle-click paste on Tomboy icon
  - New gconf preference, disable ESC closing notes 
  - New paragraph within a bullet with SHIFT + ENTER
  - New bug numbers as links in Export to HTML 
  - New notebook notes can be created off notebook's context menu.
  - New sketching add-in (still incomplete, --enable-sketching)
  - New "Unfiled Notes" item to notebook list 
  - New drag note to "Unfiled Notes" to remove from notebook 
 * debian/tomboy.menu: updated

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
        {
13
13
                bool editing_title;
14
14
                Gtk.TextTag title_tag;
15
 
                HIGMessageDialog title_taken_dialog = null; 
 
15
                HIGMessageDialog title_taken_dialog = null;
16
16
 
17
17
                public override void Initialize ()
18
18
                {
24
24
                        // Do nothing.
25
25
                }
26
26
 
27
 
                Gtk.TextIter TitleEnd 
 
27
                Gtk.TextIter TitleEnd
28
28
                {
29
29
                        get {
30
30
                                Gtk.TextIter line_end = Buffer.StartIter;
33
33
                        }
34
34
                }
35
35
 
36
 
                Gtk.TextIter TitleStart 
 
36
                Gtk.TextIter TitleStart
37
37
                {
38
 
                        get { return Buffer.StartIter; }
 
38
                        get {
 
39
                                return Buffer.StartIter;
 
40
                        }
39
41
                }
40
42
 
41
43
                public override void OnNoteOpened ()
43
45
                        Buffer.MarkSet += OnMarkSet;
44
46
                        Buffer.InsertText += OnInsertText;
45
47
                        Buffer.DeleteRange += OnDeleteRange;
46
 
                        
 
48
 
47
49
                        Window.Editor.FocusOutEvent += OnEditorFocusOut;
48
50
 
49
51
                        // FIXME: Needed because we hide on delete event, and
56
58
                        Buffer.RemoveAllTags (TitleStart, TitleEnd);
57
59
                        Buffer.ApplyTag (title_tag, TitleStart, TitleEnd);
58
60
                }
59
 
                
 
61
 
60
62
                void OnEditorFocusOut (object sender, Gtk.FocusOutEventArgs args)
61
63
                {
62
64
                        // TODO: Duplicated from Update(); refactor instead
147
149
                        string temp_title;
148
150
 
149
151
                        while (true) {
150
 
                                temp_title = String.Format (Catalog.GetString ("(Untitled {0})"), 
151
 
                                                            ++new_num);
 
152
                                temp_title = String.Format (Catalog.GetString ("(Untitled {0})"),
 
153
                                                            ++new_num);
152
154
                                if (Manager.Find (temp_title) == null)
153
155
                                        return temp_title;
154
156
                        }
179
181
                        Buffer.MoveMark (Buffer.SelectionBound, TitleStart);
180
182
                        Buffer.MoveMark (Buffer.InsertMark, TitleEnd);
181
183
 
182
 
                        string message = 
183
 
                                String.Format (Catalog.GetString ("A note with the title " +
184
 
                                                                  "<b>{0}</b> already exists. " +
185
 
                                                                  "Please choose another name " +
186
 
                                                                  "for this note before " +
187
 
                                                                  "continuing."),
188
 
                                               title);
189
 
                        
 
184
                        string message =
 
185
                                String.Format (Catalog.GetString ("A note with the title " +
 
186
                                                                  "<b>{0}</b> already exists. " +
 
187
                                                                  "Please choose another name " +
 
188
                                                                  "for this note before " +
 
189
                                                                  "continuing."),
 
190
                                               title);
 
191
 
190
192
                        /// Only pop open a warning dialog when one isn't already present
191
193
                        /// Had to add this check because this method is being called twice.
192
194
                        if (title_taken_dialog == null) {
193
195
                                title_taken_dialog =
194
 
                                        new HIGMessageDialog (Window,
195
 
                                                      Gtk.DialogFlags.DestroyWithParent,
196
 
                                                      Gtk.MessageType.Warning,
197
 
                                                      Gtk.ButtonsType.Ok,
198
 
                                                      Catalog.GetString ("Note title taken"),
199
 
                                                      message);
 
196
                                        new HIGMessageDialog (Window,
 
197
                                                              Gtk.DialogFlags.DestroyWithParent,
 
198
                                                              Gtk.MessageType.Warning,
 
199
                                                              Gtk.ButtonsType.Ok,
 
200
                                                              Catalog.GetString ("Note title taken"),
 
201
                                                              message);
200
202
                                title_taken_dialog.Modal = true;
201
203
                                title_taken_dialog.Response +=
202
 
                                        delegate (object sender, Gtk.ResponseArgs args) {
203
 
                                                title_taken_dialog.Destroy ();
204
 
                                                title_taken_dialog = null;
205
 
                                        };
 
204
                                delegate (object sender, Gtk.ResponseArgs args) {
 
205
                                        title_taken_dialog.Destroy ();
 
206
                                        title_taken_dialog = null;
 
207
                                };
206
208
                        }
207
 
                        
 
209
 
208
210
                        title_taken_dialog.Present ();
209
211
                }
210
212
        }
211
213
 
212
 
#if FIXED_GTKSPELL
 
214
        #if FIXED_GTKSPELL
213
215
        public class NoteSpellChecker : NoteAddin
214
216
        {
215
217
                IntPtr obj_ptr = IntPtr.Zero;
218
220
                static bool gtkspell_available_result;
219
221
 
220
222
                [DllImport ("libgtkspell")]
221
 
                static extern IntPtr gtkspell_new_attach (IntPtr text_view, 
222
 
                                                          string locale, 
223
 
                                                          IntPtr error);
 
223
                static extern IntPtr gtkspell_new_attach (IntPtr text_view,
 
224
                                        string locale,
 
225
                                        IntPtr error);
224
226
 
225
227
                [DllImport ("libgtkspell")]
226
228
                static extern void gtkspell_detach (IntPtr obj);
229
231
                {
230
232
                        try {
231
233
                                Gtk.TextView test_view = new Gtk.TextView ();
232
 
                                IntPtr test_ptr = gtkspell_new_attach (test_view.Handle, 
233
 
                                                                       null, 
234
 
                                                                       IntPtr.Zero);
 
234
                                IntPtr test_ptr = gtkspell_new_attach (test_view.Handle,
 
235
                                                                       null,
 
236
                                                                       IntPtr.Zero);
235
237
                                if (test_ptr != IntPtr.Zero)
236
238
                                        gtkspell_detach (test_ptr);
237
239
                                return true;
238
240
                        } catch {
239
 
                                return false;
240
 
                        }
 
241
                        return false;
241
242
                }
 
243
        }
242
244
 
243
 
                public static bool GtkSpellAvailable 
244
 
                {
245
 
                        get {
246
 
                                if (!gtkspell_available_tested) {
 
245
        public static bool GtkSpellAvailable
 
246
        {
 
247
                get {
 
248
                        if (!gtkspell_available_tested) {
247
249
                                        gtkspell_available_result = DetectGtkSpellAvailable ();
248
250
                                        gtkspell_available_tested = true;
249
251
                                }
291
293
                        }
292
294
 
293
295
                        if (obj_ptr == IntPtr.Zero) {
294
 
                                obj_ptr = gtkspell_new_attach (Window.Editor.Handle, 
295
 
                                                               null, 
296
 
                                                               IntPtr.Zero);
 
296
                                obj_ptr = gtkspell_new_attach (Window.Editor.Handle,
 
297
                                                               null,
 
298
                                                               IntPtr.Zero);
297
299
                        }
298
300
                }
299
301
 
325
327
                                // Remove misspelled tag for links & title
326
328
                                foreach (Gtk.TextTag tag in args.StartChar.Tags) {
327
329
                                        if (tag != args.Tag &&
328
 
                                            !NoteTagTable.TagIsSpellCheckable (tag)) {
 
330
                                                        !NoteTagTable.TagIsSpellCheckable (tag)) {
329
331
                                                remove = true;
330
332
                                                break;
331
333
                                        }
335
337
                        }
336
338
 
337
339
                        if (remove) {
338
 
                                Buffer.RemoveTag ("gtkspell-misspelled", 
339
 
                                                  args.StartChar, 
340
 
                                                  args.EndChar);
 
340
                                Buffer.RemoveTag ("gtkspell-misspelled",
 
341
                                                  args.StartChar,
 
342
                                                  args.EndChar);
341
343
                        }
342
344
                }
343
345
        }
344
 
#endif
 
346
        #endif
345
347
 
346
348
        public class NoteUrlWatcher : NoteAddin
347
349
        {
348
350
                NoteTag url_tag;
349
351
                Gtk.TextMark click_mark;
350
352
 
351
 
                const string URL_REGEX = 
352
 
                        @"((\b((news|http|https|ftp|file|irc)://|mailto:|(www|ftp)\.|\S*@\S*\.)|(^|\s)/\S+/|(^|\s)~/\S+)\S*\b/?)";
 
353
                const string URL_REGEX =
 
354
                        @"((\b((news|http|https|ftp|file|irc)://|mailto:|(www|ftp)\.|\S*@\S*\.)|(^|\s)/\S+/|(^|\s)~/\S+)\S*\b/?)";
353
355
 
354
356
                static Regex regex;
355
357
                static bool text_event_connected;
356
358
 
357
359
                static NoteUrlWatcher ()
358
360
                {
359
 
                        regex = new Regex (URL_REGEX, 
360
 
                                           RegexOptions.IgnoreCase | RegexOptions.Compiled);
 
361
                        regex = new Regex (URL_REGEX,
 
362
                                           RegexOptions.IgnoreCase | RegexOptions.Compiled);
361
363
                        text_event_connected = false;
362
364
                }
363
365
 
373
375
 
374
376
                public override void OnNoteOpened ()
375
377
                {
376
 
#if FIXED_GTKSPELL
 
378
                        #if FIXED_GTKSPELL
377
379
                        // NOTE: This hack helps avoid multiple URL opens for
378
380
                        // cases where the GtkSpell version is fixed to allow
379
381
                        // TagTable sharing.  This is because if the TagTable is
385
387
                                url_tag.Activated += OnUrlTagActivated;
386
388
                                text_event_connected = true;
387
389
                        }
388
 
#else
 
390
                        #else
389
391
                        url_tag.Activated += OnUrlTagActivated;
390
 
#endif
 
392
                        #endif
391
393
 
392
394
                        click_mark = Buffer.CreateMark (null, Buffer.StartIter, true);
393
395
 
412
414
                        // to /home/alex/foo.
413
415
                        if (url.StartsWith ("www."))
414
416
                                url = "http://" + url;
415
 
                        else if (url.StartsWith ("/") && 
416
 
                                 url.LastIndexOf ("/") > 1)
 
417
                        else if (url.StartsWith ("/") &&
 
418
                                        url.LastIndexOf ("/") > 1)
417
419
                                url = "file://" + url;
418
420
                        else if (url.StartsWith ("~/"))
419
 
                                url = "file://" + 
420
 
                                        Path.Combine (Environment.GetEnvironmentVariable ("HOME"),
421
 
                                                      url.Substring (2));
 
421
                                url = "file://" +
 
422
                                      Path.Combine (Environment.GetEnvironmentVariable ("HOME"),
 
423
                                                    url.Substring (2));
422
424
                        else if (url.IndexOf ("@") > 1 &&
423
 
                                 url.IndexOf (".") > 3 &&
424
 
                                 !url.StartsWith ("mailto:"))
 
425
                                        url.IndexOf (".") > 3 &&
 
426
                                        !url.StartsWith ("mailto:"))
425
427
                                url = "mailto:" + url;
426
428
 
427
429
                        return url;
428
430
                }
429
431
 
430
 
                void OpenUrl (string url) 
 
432
                void OpenUrl (string url)
431
433
                {
432
434
                        if (url != string.Empty) {
433
435
                                Logger.Log ("Opening url '{0}'...", url);
439
441
                {
440
442
                        string message = String.Format ("{0}: {1}", url, error);
441
443
 
442
 
                        HIGMessageDialog dialog = 
443
 
                                new HIGMessageDialog (Window,
444
 
                                                      Gtk.DialogFlags.DestroyWithParent,
445
 
                                                      Gtk.MessageType.Info,
446
 
                                                      Gtk.ButtonsType.Ok,
447
 
                                                      Catalog.GetString ("Cannot open location"),
448
 
                                                      message);
 
444
                        HIGMessageDialog dialog =
 
445
                                new HIGMessageDialog (Window,
 
446
                                                      Gtk.DialogFlags.DestroyWithParent,
 
447
                                                      Gtk.MessageType.Info,
 
448
                                                      Gtk.ButtonsType.Ok,
 
449
                                                      Catalog.GetString ("Cannot open location"),
 
450
                                                      message);
449
451
                        dialog.Run ();
450
452
                        dialog.Destroy ();
451
453
                }
452
454
 
453
455
                bool OnUrlTagActivated (NoteTag      sender,
454
 
                                        NoteEditor   editor,
455
 
                                        Gtk.TextIter start, 
456
 
                                        Gtk.TextIter end)
 
456
                                        NoteEditor   editor,
 
457
                                        Gtk.TextIter start,
 
458
                                        Gtk.TextIter end)
457
459
                {
458
460
                        string url = GetUrl (start, end);
459
461
                        try {
468
470
 
469
471
                void ApplyUrlToBlock (Gtk.TextIter start, Gtk.TextIter end)
470
472
                {
471
 
                        NoteBuffer.GetBlockExtents (ref start, 
472
 
                                                    ref end, 
473
 
                                                    256 /* max url length */,
474
 
                                                    url_tag);
 
473
                        NoteBuffer.GetBlockExtents (ref start,
 
474
                                                    ref end,
 
475
                                                    256 /* max url length */,
 
476
                                                    url_tag);
475
477
 
476
478
                        Buffer.RemoveTag (url_tag, start, end);
477
479
 
478
 
                        for (Match match = regex.Match (start.GetSlice (end)); 
479
 
                             match.Success; 
480
 
                             match = match.NextMatch ()) {
 
480
                        for (Match match = regex.Match (start.GetSlice (end));
 
481
                                        match.Success;
 
482
                                        match = match.NextMatch ()) {
481
483
                                System.Text.RegularExpressions.Group group = match.Groups [1];
482
484
 
483
485
                                /*
484
486
                                Logger.Log ("Highlighting url: '{0}' at offset {1}",
485
 
                                            group,
486
 
                                            group.Index);
 
487
                                     group,
 
488
                                     group.Index);
487
489
                                */
488
490
 
489
491
                                Gtk.TextIter start_cpy = start;
515
517
                        int x, y;
516
518
 
517
519
                        Window.Editor.WindowToBufferCoords (Gtk.TextWindowType.Text,
518
 
                                                            (int) args.Event.X,
519
 
                                                            (int) args.Event.Y,
520
 
                                                            out x,
521
 
                                                            out y);
 
520
                                                            (int) args.Event.X,
 
521
                                                            (int) args.Event.Y,
 
522
                                                            out x,
 
523
                                                            out y);
522
524
                        Gtk.TextIter click_iter = Window.Editor.GetIterAtLocation (x, y);
523
525
 
524
526
                        // Move click_mark to click location
591
593
 
592
594
                static bool text_event_connected;
593
595
 
594
 
                public override void Initialize () 
 
596
                public override void Initialize ()
595
597
                {
596
598
                        Manager.NoteDeleted += OnNoteDeleted;
597
599
                        Manager.NoteAdded += OnNoteAdded;
611
613
 
612
614
                public override void OnNoteOpened ()
613
615
                {
614
 
#if FIXED_GTKSPELL
 
616
                        #if FIXED_GTKSPELL
615
617
                        // NOTE: This avoid multiple link opens for cases where
616
618
                        // the GtkSpell version is fixed to allow TagTable
617
619
                        // sharing.  This is because if the TagTable is shared,
623
625
                                broken_link_tag.Activated += OnLinkTagActivated;
624
626
                                text_event_connected = true;
625
627
                        }
626
 
#else
 
628
                        #else
627
629
                        link_tag.Activated += OnLinkTagActivated;
628
630
                        broken_link_tag.Activated += OnLinkTagActivated;
629
 
#endif
 
631
                        #endif
630
632
 
631
633
                        Buffer.InsertText += OnInsertText;
632
634
                        Buffer.DeleteRange += OnDeleteRange;
693
695
                                if (range.Text.ToLower () != old_title_lower)
694
696
                                        continue;
695
697
 
696
 
                                Logger.Log ("Replacing '{0}' with '{1}'", 
697
 
                                            range.Text, 
698
 
                                            renamed.Title);
 
698
                                Logger.Log ("Replacing '{0}' with '{1}'",
 
699
                                            range.Text,
 
700
                                            renamed.Title);
699
701
 
700
702
                                Gtk.TextIter start_iter = range.Start;
701
703
                                Gtk.TextIter end_iter = range.End;
718
720
                        title_end.ForwardChars (hit.End);
719
721
 
720
722
                        // Only link against whole words/phrases
721
 
                        if ((!title_start.StartsWord () && !title_start.StartsSentence ()) || 
722
 
                            (!title_end.EndsWord() && !title_end.EndsSentence()))
 
723
                        if ((!title_start.StartsWord () && !title_start.StartsSentence ()) ||
 
724
                                        (!title_end.EndsWord() && !title_end.EndsSentence()))
723
725
                                return;
724
726
 
725
727
                        // Don't create links inside URLs
726
728
                        if (title_start.HasTag (url_tag))
727
729
                                return;
728
730
 
729
 
                        Logger.Log ("Matching Note title '{0}' at {1}-{2}...", 
730
 
                                    hit.Key,
731
 
                                    hit.Start,
732
 
                                    hit.End);
 
731
                        Logger.Log ("Matching Note title '{0}' at {1}-{2}...",
 
732
                                    hit.Key,
 
733
                                    hit.Start,
 
734
                                    hit.End);
733
735
 
734
736
                        Buffer.RemoveTag (broken_link_tag, title_start, title_end);
735
737
                        Buffer.ApplyTag (link_tag, title_start, title_end);
736
738
                }
737
739
 
738
 
                void HighlightNoteInBlock (Note find_note, Gtk.TextIter start, Gtk.TextIter end) 
 
740
                void HighlightNoteInBlock (Note find_note, Gtk.TextIter start, Gtk.TextIter end)
739
741
                {
740
742
                        string buffer_text = start.GetText (end).ToLower();
741
743
                        string find_title_lower = find_note.Title.ToLower ();
746
748
                                if (idx < 0)
747
749
                                        break;
748
750
 
749
 
                                TrieHit hit = new TrieHit (idx, 
750
 
                                                           idx + find_title_lower.Length,
751
 
                                                           find_title_lower,
752
 
                                                           find_note);
 
751
                                TrieHit hit = new TrieHit (idx,
 
752
                                                           idx + find_title_lower.Length,
 
753
                                                           find_title_lower,
 
754
                                                           find_note);
753
755
                                DoHighlight (hit, start, end);
754
756
 
755
757
                                idx += find_title_lower.Length;
756
758
                        }
757
759
                }
758
760
 
759
 
                void HighlightInBlock (Gtk.TextIter start, Gtk.TextIter end) 
 
761
                void HighlightInBlock (Gtk.TextIter start, Gtk.TextIter end)
760
762
                {
761
763
                        ArrayList hits = Manager.TitleTrie.FindMatches (start.GetSlice (end));
762
764
                        foreach (TrieHit hit in hits) {
764
766
                        }
765
767
                }
766
768
 
767
 
                void UnhighlightInBlock (Gtk.TextIter start, Gtk.TextIter end) 
 
769
                void UnhighlightInBlock (Gtk.TextIter start, Gtk.TextIter end)
768
770
                {
769
771
                        Buffer.RemoveTag (link_tag, start, end);
770
772
                }
774
776
                        Gtk.TextIter start = args.Start;
775
777
                        Gtk.TextIter end = args.End;
776
778
 
777
 
                        NoteBuffer.GetBlockExtents (ref start, 
778
 
                                                    ref end, 
779
 
                                                    Manager.TitleTrie.MaxLength,
780
 
                                                    link_tag);
 
779
                        NoteBuffer.GetBlockExtents (ref start,
 
780
                                                    ref end,
 
781
                                                    Manager.TitleTrie.MaxLength,
 
782
                                                    link_tag);
781
783
 
782
784
                        UnhighlightInBlock (start, end);
783
785
                        HighlightInBlock (start, end);
790
792
 
791
793
                        Gtk.TextIter end = args.Pos;
792
794
 
793
 
                        NoteBuffer.GetBlockExtents (ref start, 
794
 
                                                    ref end, 
795
 
                                                    Manager.TitleTrie.MaxLength,
796
 
                                                    link_tag);
 
795
                        NoteBuffer.GetBlockExtents (ref start,
 
796
                                                    ref end,
 
797
                                                    Manager.TitleTrie.MaxLength,
 
798
                                                    link_tag);
797
799
 
798
800
                        UnhighlightInBlock (start, end);
799
801
                        HighlightInBlock (start, end);
807
809
                        if (link == null) {
808
810
                                Logger.Log ("Creating note '{0}'...", link_name);
809
811
                                try {
810
 
                                    link = Manager.Create (link_name);
 
812
                                        link = Manager.Create (link_name);
811
813
                                } catch {
812
 
                                    // Fail silently.
813
 
                                }
 
814
                                // Fail silently.
814
815
                        }
815
 
                        
816
 
                        // FIXME: We used to also check here for (link != this.Note), but
817
 
                        // somehow this was causing problems receiving clicks for the
818
 
                        // wrong instance of a note (see bug #413234).  Since a
819
 
                        // link:internal tag is never applied around text that's the same
820
 
                        // as the current note's title, it's safe to omit this check and
821
 
                        // also works around the bug.
822
 
                        if (link != null) {
 
816
                }
 
817
 
 
818
                // FIXME: We used to also check here for (link != this.Note), but
 
819
                // somehow this was causing problems receiving clicks for the
 
820
                // wrong instance of a note (see bug #413234).  Since a
 
821
                // link:internal tag is never applied around text that's the same
 
822
                // as the current note's title, it's safe to omit this check and
 
823
                // also works around the bug.
 
824
                if (link != null) {
823
825
                                Logger.Log ("Opening note '{0}' on click...", link_name);
824
826
                                link.Window.Present ();
825
827
                                return true;
829
831
                }
830
832
 
831
833
                bool OnLinkTagActivated (NoteTag      sender,
832
 
                                         NoteEditor   editor,
833
 
                                         Gtk.TextIter start, 
834
 
                                         Gtk.TextIter end)
 
834
                                         NoteEditor   editor,
 
835
                                         Gtk.TextIter start,
 
836
                                         Gtk.TextIter end)
835
837
                {
836
838
                        return OpenOrCreateLink (start, end);
837
839
                }
844
846
                // NOTE: \p{Lu} is Unicode uppercase and \p{Ll} is lowercase.
845
847
                const string WIKIWORD_REGEX = @"\b((\p{Lu}+[\p{Ll}0-9]+){2}([\p{Lu}\p{Ll}0-9])*)\b";
846
848
 
847
 
                static Regex regex; 
 
849
                static Regex regex;
848
850
 
849
851
                static NoteWikiWatcher ()
850
852
                {
884
886
                        }
885
887
                }
886
888
 
887
 
                static string [] PatronymicPrefixes = 
888
 
                        new string [] { "Mc", "Mac", "Le", "La", "De", "Van" };
 
889
                static string [] PatronymicPrefixes =
 
890
                        new string [] { "Mc", "Mac", "Le", "La", "De", "Van" };
889
891
 
890
892
                bool IsPatronymicName (string word)
891
893
                {
892
894
                        foreach (string prefix in PatronymicPrefixes) {
893
895
                                if (word.StartsWith (prefix) &&
894
 
                                    char.IsUpper (word [prefix.Length]))
 
896
                                                char.IsUpper (word [prefix.Length]))
895
897
                                        return true;
896
898
                        }
897
899
 
900
902
 
901
903
                void ApplyWikiwordToBlock (Gtk.TextIter start, Gtk.TextIter end)
902
904
                {
903
 
                        NoteBuffer.GetBlockExtents (ref start, 
904
 
                                                    ref end, 
905
 
                                                    80 /* max wiki name */,
906
 
                                                    broken_link_tag);
 
905
                        NoteBuffer.GetBlockExtents (ref start,
 
906
                                                    ref end,
 
907
                                                    80 /* max wiki name */,
 
908
                                                    broken_link_tag);
907
909
 
908
910
                        Buffer.RemoveTag (broken_link_tag, start, end);
909
911
 
910
 
                        for (Match match = regex.Match (start.GetText (end)); 
911
 
                             match.Success; 
912
 
                             match = match.NextMatch ()) {
 
912
                        for (Match match = regex.Match (start.GetText (end));
 
913
                                        match.Success;
 
914
                                        match = match.NextMatch ()) {
913
915
                                System.Text.RegularExpressions.Group group = match.Groups [1];
914
916
 
915
917
                                if (IsPatronymicName (group.ToString ()))
916
918
                                        continue;
917
919
 
918
920
                                Logger.Log ("Highlighting wikiword: '{0}' at offset {1}",
919
 
                                            group,
920
 
                                            group.Index);
 
921
                                            group,
 
922
                                            group.Index);
921
923
 
922
924
                                Gtk.TextIter start_cpy = start;
923
925
                                start_cpy.ForwardChars (group.Index);
977
979
                }
978
980
 
979
981
                [GLib.ConnectBefore]
980
 
                void OnEditorKeyPress (object sender, Gtk.KeyPressEventArgs args) 
 
982
                void OnEditorKeyPress (object sender, Gtk.KeyPressEventArgs args)
981
983
                {
982
984
                        switch (args.Event.Key) {
983
985
                        case Gdk.Key.Shift_L:
1001
1003
                                foreach (Gtk.TextTag tag in iter.Tags) {
1002
1004
                                        if (NoteTagTable.TagIsActivatable (tag)) {
1003
1005
                                                args.RetVal = tag.ProcessEvent (Window.Editor,
1004
 
                                                                                args.Event,
1005
 
                                                                                iter);
 
1006
                                                                                args.Event,
 
1007
                                                                                iter);
1006
1008
                                                if ((bool) args.RetVal)
1007
1009
                                                        break;
1008
1010
                                        }
1012
1014
                }
1013
1015
 
1014
1016
                [GLib.ConnectBefore]
1015
 
                void OnEditorKeyRelease (object sender, Gtk.KeyReleaseEventArgs args) 
 
1017
                void OnEditorKeyRelease (object sender, Gtk.KeyReleaseEventArgs args)
1016
1018
                {
1017
1019
                        switch (args.Event.Key) {
1018
1020
                        case Gdk.Key.Shift_L:
1034
1036
                        int pointer_x, pointer_y;
1035
1037
                        Gdk.ModifierType pointer_mask;
1036
1038
 
1037
 
                        Window.Editor.GdkWindow.GetPointer (out pointer_x, 
1038
 
                                                            out pointer_y, 
1039
 
                                                            out pointer_mask);
 
1039
                        Window.Editor.GdkWindow.GetPointer (out pointer_x,
 
1040
                                                            out pointer_y,
 
1041
                                                            out pointer_mask);
1040
1042
 
1041
1043
                        bool hovering = false;
1042
 
                        
 
1044
 
1043
1045
                        // Figure out if we're on a link by getting the text
1044
1046
                        // iter at the mouse point, and checking for tags that
1045
1047
                        // start with "link:"...
1046
1048
 
1047
1049
                        int buffer_x, buffer_y;
1048
1050
                        Window.Editor.WindowToBufferCoords (Gtk.TextWindowType.Widget,
1049
 
                                                            pointer_x, 
1050
 
                                                            pointer_y,
1051
 
                                                            out buffer_x, 
1052
 
                                                            out buffer_y);
1053
 
                        
 
1051
                                                            pointer_x,
 
1052
                                                            pointer_y,
 
1053
                                                            out buffer_x,
 
1054
                                                            out buffer_y);
 
1055
 
1054
1056
                        Gtk.TextIter iter = Window.Editor.GetIterAtLocation (buffer_x, buffer_y);
1055
1057
 
1056
1058
                        foreach (Gtk.TextTag tag in iter.Tags) {
1060
1062
                                }
1061
1063
                        }
1062
1064
 
1063
 
                        // Don't show hand if Shift or Control is pressed 
 
1065
                        // Don't show hand if Shift or Control is pressed
1064
1066
                        bool avoid_hand = (pointer_mask & (Gdk.ModifierType.ShiftMask |
1065
 
                                                           Gdk.ModifierType.ControlMask)) != 0;
 
1067
                                                           Gdk.ModifierType.ControlMask)) != 0;
1066
1068
 
1067
1069
                        if (hovering != hovering_on_link) {
1068
1070
                                hovering_on_link = hovering;
1070
1072
                                Gdk.Window win = Window.Editor.GetWindow (Gtk.TextWindowType.Text);
1071
1073
                                if (hovering && !avoid_hand)
1072
1074
                                        win.Cursor = hand_cursor;
1073
 
                                else 
 
1075
                                else
1074
1076
                                        win.Cursor = normal_cursor;
1075
1077
                        }
1076
1078
                }
1077
1079
        }
1078
 
        
 
1080
 
1079
1081
        public class NoteTagsWatcher : NoteAddin
1080
1082
        {
1081
1083
                static NoteTagsWatcher ()
1104
1106
                                Logger.Debug ("\t{0}", tag.Name);
1105
1107
                        }
1106
1108
                }
1107
 
                
 
1109
 
1108
1110
                void OnTagAdded (Note note, Tag tag)
1109
1111
                {
1110
1112
                        Logger.Debug ("Tag added to {0}: {1}", note.Title, tag.Name);
1111
1113
                }
1112
 
                
 
1114
 
1113
1115
                void OnTagRemoving (Note note, Tag tag)
1114
1116
                {
1115
1117
                        Logger.Debug ("Removing tag from {0}: {1}", note.Title, tag.Name);
1116
1118
                }
1117
 
                
 
1119
 
1118
1120
                // <summary>
1119
1121
                // Keep the TagManager clean by removing tags that are no longer
1120
1122
                // tagging any other notes.
1122
1124
                void OnTagRemoved (Note note, string tag_name)
1123
1125
                {
1124
1126
                        Tag tag = TagManager.GetTag (tag_name);
1125
 
Logger.Debug ("Watchers.OnTagRemoved popularity count: {0}", tag.Popularity);
 
1127
                        Logger.Debug ("Watchers.OnTagRemoved popularity count: {0}", tag.Popularity);
1126
1128
                        if (tag.Popularity == 0)
1127
1129
                                TagManager.RemoveTag (tag);
1128
1130
                }