protected override void Run()
 {
     var editor = IdeApp.Workbench.ActiveDocument.Editor;
     var currentLine = editor.GetLineByOffset(editor.Caret.Offset);
     NumberBookmark bookmark = new NumberBookmark(editor.FileName, currentLine.LineNumber, editor.Caret.Column, BookmarkNumber, BookmarkType);
     bookmark.LineContent = editor.GetLineText(currentLine.LineNumber).Trim();
     BookmarkService.Instance.AddBookmark(bookmark);
 }
        public void AddBookmark1()
        {
            NumberBookmark bookmark = new NumberBookmark("TestPath.cs", 10, 4, 2, BookmarkType.Local);
            BookmarkService.Instance.AddBookmark(bookmark);

            Assert.AreEqual(1, BookmarkService.Instance.BookmarkCount);

            bookmark = new NumberBookmark("TestPath.cs", 15, 20, 2, BookmarkType.Local);
            BookmarkService.Instance.AddBookmark(bookmark);
            Assert.AreEqual(1, BookmarkService.Instance.BookmarkCount);

            var bookmarkCheck = BookmarkService.Instance.GetBookmarkLocal("TestPath.cs", 2);
            Assert.AreEqual(15, bookmarkCheck.LineNumber);
            Assert.AreEqual(20, bookmarkCheck.Column);
        }
        public void ClearBookmarks()
        {
            ClearAllBookmarksHandler handler = new ClearAllBookmarksHandler();
            NumberBookmark bookmark = new NumberBookmark("TestPath.cs", 10, 4, 2, BookmarkType.Local);
            BookmarkService.Instance.AddBookmark(bookmark);

            bookmark = new NumberBookmark("TestPath.cs", 20, 4, 1, BookmarkType.Local);
            BookmarkService.Instance.AddBookmark(bookmark);

            bookmark = new NumberBookmark("TestPath1SAD.cs", 10, 4, 1, BookmarkType.Global);
            BookmarkService.Instance.AddBookmark(bookmark);

            Assert.AreEqual(3, BookmarkService.Instance.BookmarkCount);
            handler.RunTest();
            Assert.AreEqual(0, BookmarkService.Instance.BookmarkCount);
        }
        public void AddBookmark3()
        {
            NumberBookmark bookmark = new NumberBookmark("TestPath1SAD.cs", 10, 4, 3, BookmarkType.Global);
            BookmarkService.Instance.AddBookmark(bookmark);

            Assert.AreEqual(1, BookmarkService.Instance.BookmarkCount);

            bookmark = new NumberBookmark("TestPath.cs", 40, 20, 3, BookmarkType.Global);
            BookmarkService.Instance.AddBookmark(bookmark);

            Assert.AreEqual(1, BookmarkService.Instance.BookmarkCount);

            var bookmarkCheck = BookmarkService.Instance.GetBookmarkGlobal(3);
            Assert.AreEqual(40, bookmarkCheck.LineNumber);
            Assert.AreEqual(20, bookmarkCheck.Column);
            Assert.AreEqual("TestPath.cs", bookmark.FileName);
        }
        public void ToXml()
        {
            XmlDocument doc = new XmlDocument();
            var bookMark = new NumberBookmark();
            bookMark.FileName = "TestFile.cs";
            bookMark.LineNumber = 29;
            bookMark.Column = 10;
            bookMark.BookmarkType = BookmarkType.Global;
            bookMark.Number = 4;
            XmlElement element = bookMark.ToXml(doc);

            StringBuilder builder = new StringBuilder();
            XmlWriterSettings settings = new XmlWriterSettings();
            settings.Indent = false;
            settings.Encoding = Encoding.UTF8;
            settings.OmitXmlDeclaration = true;
            XmlWriter writer = XmlWriter.Create(builder, settings);
            element.WriteTo(writer);
            writer.Flush();
            string value = "<NumberBookmark Type=\"1\" Number=\"4\" FileName=\"TestFile.cs\" LineNumber=\"29\" Column=\"10\" />";
            Assert.AreEqual(value, builder.ToString());
        }
 public NumberBookmarkMarker(NumberBookmark bookmark)
 {
     Bookmark = bookmark;
 }
        private void RemoveMarkerFromDocument(NumberBookmark bookmark)
        {
            var document = GetActiveDocument();
            if (document == null)
                return;

            if (string.Equals(bookmark.FileName, document.FileName))
            {
                var line = document.GetLine(bookmark.LineNumber);
                if (line == null)
                    return;
                document.RemoveMarker(line, typeof (NumberBookmarkMarker));
                document.RequestUpdate(new LineUpdate(line.LineNumber));
                document.CommitDocumentUpdate();
            }
        }
 private void InternalDeleteBookmark(NumberBookmark bookmark)
 {
     bookmarks.Remove(bookmark);
     RemoveMarkerFromDocument(bookmark);
 }
 /// <summary>
 /// Deletes the bookmark and raise event for change
 /// </summary>
 /// <param name='bookmark'>
 /// Bookmark for deletion
 /// </param>
 internal void DeleteBookmark(NumberBookmark bookmark)
 {
     InternalDeleteBookmark(bookmark);
     RaiseBookmarksChange();
 }
        /// <summary>
        /// Adds the bookmark. Raises event for change
        /// </summary>
        /// <param name='bookmark'>
        /// Bookmark.
        /// </param>
        internal void AddBookmark(NumberBookmark bookmark)
        {
            NumberBookmark sameBookmark = null;
            //Check for same bookmar on differnt line
            if (bookmark.BookmarkType == BookmarkType.Local) //If local add file condition
            {
                sameBookmark = bookmarks.FirstOrDefault(b => string.Equals(b.FileName, bookmark.FileName, StringComparison.OrdinalIgnoreCase) &&
                    b.BookmarkType == BookmarkType.Local && b.Number == bookmark.Number &&
                    b.LineNumber != bookmark.LineNumber);
            } else
            {
                sameBookmark = bookmarks.FirstOrDefault(b => b.BookmarkType == BookmarkType.Global && b.Number == bookmark.Number
                    && !(string.Equals(b.FileName, bookmark.FileName) && b.LineNumber == bookmark.LineNumber));

            }
            if (sameBookmark != null)
            {
                InternalDeleteBookmark(sameBookmark);
            }

            //Same line differnet number - replace the bookmark
            var lineBookmark = bookmarks.FirstOrDefault(b => string.Equals(b.FileName, bookmark.FileName, StringComparison.OrdinalIgnoreCase) &&
                b.LineNumber == bookmark.LineNumber &&
                (b.Number != bookmark.Number || b.BookmarkType != bookmark.BookmarkType));
            if (lineBookmark != null)
            {
                InternalDeleteBookmark(lineBookmark);
            }

            //Same line same number and type - clear the bookmark
            var lineBookmarkSameNumber = bookmarks.FirstOrDefault(b => string.Equals(b.FileName, bookmark.FileName, StringComparison.OrdinalIgnoreCase) &&
                b.LineNumber == bookmark.LineNumber &&
                b.Number == bookmark.Number && b.BookmarkType == bookmark.BookmarkType);
            if (lineBookmarkSameNumber != null) //Clear bookmark.
            {
                DeleteBookmark(lineBookmarkSameNumber);
                return;
            }
            bookmarks.Add(bookmark);
            AddMarkerToLine(bookmark);
            RaiseBookmarksChange();
        }
        public void AddBookmark7()
        {
            NumberBookmark bookmark = new NumberBookmark("TestPath.cs", 20,17, 6, BookmarkType.Global);
            BookmarkService.Instance.AddBookmark(bookmark);

            Assert.AreEqual(1, BookmarkService.Instance.BookmarkCount);

            bookmark = new NumberBookmark("TestPath.cs", 20, 5, 6, BookmarkType.Global);
            BookmarkService.Instance.AddBookmark(bookmark);
            Assert.AreEqual(0, BookmarkService.Instance.BookmarkCount);
        }
        public void AddBookmark5()
        {
            NumberBookmark bookmark = new NumberBookmark("TestPath.cs", 15, 4, 5, BookmarkType.Local);
            BookmarkService.Instance.AddBookmark(bookmark);

            Assert.AreEqual(1, BookmarkService.Instance.BookmarkCount);

            bookmark = new NumberBookmark("TestPath.cs", 15, 20, 5, BookmarkType.Global);
            BookmarkService.Instance.AddBookmark(bookmark);
            Assert.AreEqual(1, BookmarkService.Instance.BookmarkCount);

            var bookmarkCheck = BookmarkService.Instance.GetBookmarkGlobal(5);
            Assert.AreEqual(15, bookmarkCheck.LineNumber);
            Assert.AreEqual(20, bookmarkCheck.Column);
            Assert.AreEqual("TestPath.cs", bookmark.FileName);
        }
        public void AddBookmark4()
        {
            NumberBookmark bookmark = new NumberBookmark("TestPath.cs", 15, 4, 2, BookmarkType.Local);
            BookmarkService.Instance.AddBookmark(bookmark);

            Assert.AreEqual(1, BookmarkService.Instance.BookmarkCount);

            bookmark = new NumberBookmark("TestPath.cs", 15, 20, 2, BookmarkType.Local);
            BookmarkService.Instance.AddBookmark(bookmark);
            Assert.AreEqual(0, BookmarkService.Instance.BookmarkCount);
        }
        internal static NumberBookmark FromXml(XmlElement elem)
        {
            if (string.Equals(elem.Name, BookmarkTag, StringComparison.OrdinalIgnoreCase))
            {
                NumberBookmark bookMark = new NumberBookmark();

                var fileName = elem.GetAttribute(FileNameTag);
                if (string.IsNullOrEmpty(fileName))
                    return null;
                bookMark.FileName = fileName;

                var bookmarkType = Parser.ParseInt(elem.GetAttribute(BookmarkTypeTag));
                if (!bookmarkType.HasValue)
                    return null;
                bookMark.BookmarkType = (BookmarkType)bookmarkType.Value;

                var number = Parser.ParseInt(elem.GetAttribute(BookmarkNumberTag));
                if (!number.HasValue)
                    return null;
                bookMark.Number = number.Value;

                var lineNumber = Parser.ParseInt(elem.GetAttribute(LineNumberTag));
                if (!lineNumber.HasValue)
                    return null;
                bookMark.LineNumber = lineNumber.Value;

                var column = Parser.ParseInt(elem.GetAttribute(ColumnTag));
                if (!column.HasValue)
                    return null;
                bookMark.Column = column.Value;

                return bookMark;
            }
            return null;
        }