~halega/+junk/sharpdevelop

« back to all changes in this revision

Viewing changes to src/Main/Base/Project/Src/Bookmarks/SDMarkerBookmark.cs

  • Committer: sk
  • Date: 2011-09-10 05:17:57 UTC
  • Revision ID: halega@halega.com-20110910051757-qfouz1llya9m6boy
4.1.0.7915 Release Candidate 1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// Copyright (c) AlphaSierraPapa for the SharpDevelop Team (for details please see \doc\copyright.txt)
 
2
// This code is distributed under the GNU LGPL (for details please see \doc\license.txt)
 
3
 
 
4
using System;
 
5
using ICSharpCode.AvalonEdit.Document;
 
6
using ICSharpCode.Core;
 
7
using ICSharpCode.NRefactory;
 
8
using ICSharpCode.SharpDevelop.Editor;
 
9
 
 
10
namespace ICSharpCode.SharpDevelop.Bookmarks
 
11
{
 
12
        /// <summary>
 
13
        /// A bookmark that is persistant across SharpDevelop sessions and has a text marker assigned to it.
 
14
        /// </summary>
 
15
        public abstract class SDMarkerBookmark : SDBookmark
 
16
        {
 
17
                public SDMarkerBookmark(FileName fileName, Location location) : base(fileName, location)
 
18
                {
 
19
                        //SetMarker();
 
20
                }
 
21
                
 
22
                ITextMarker marker;
 
23
                
 
24
                protected abstract ITextMarker CreateMarker(ITextMarkerService markerService);
 
25
                
 
26
                void SetMarker()
 
27
                {
 
28
                        RemoveMarker();
 
29
                        if (this.Document != null) {
 
30
                                ITextMarkerService markerService = this.Document.GetService(typeof(ITextMarkerService)) as ITextMarkerService;
 
31
                                if (markerService != null) {
 
32
                                        marker = CreateMarker(markerService);
 
33
                                }
 
34
                        }
 
35
                }
 
36
                
 
37
                protected override void OnDocumentChanged(EventArgs e)
 
38
                {
 
39
                        base.OnDocumentChanged(e);
 
40
                        SetMarker();
 
41
                }
 
42
                
 
43
                public virtual void RemoveMarker()
 
44
                {
 
45
                        if (marker != null) {
 
46
                                marker.Delete();
 
47
                                marker = null;
 
48
                        }
 
49
                }
 
50
        }
 
51
}