Exemplo n.º 1
0
 }                        //文件的文件名
 public bool isModified() //判断文件是否被修改(判断是否修改并且保存了)
 {
     if (CurrentContent.Equals(SourceContent))
     {
         return(false);
     }
     else
     {
         return(true);
     }
 }
Exemplo n.º 2
0
        public bool SetContent(DocumentViewerContent content, IContentType contentType)
        {
            if (content == null)
            {
                throw new ArgumentNullException(nameof(content));
            }
            if (contentType == null)
            {
                contentType = defaultContentType;
            }

            HideCancelButton();

            var newContent = new CurrentContent(content, contentType);

            if (currentContent.Equals(newContent))
            {
                return(false);
            }
            currentContent          = newContent;
            spanReferenceCollection = newContent.Content.GetCustomData <SpanDataCollection <ReferenceAndId> >(DocumentViewerContentDataIds.SpanReference) ?? SpanDataCollection <ReferenceAndId> .Empty;

            TextView.TextBuffer.ChangeContentType(contentType, null);
            cachedColorsList.Clear();
            cachedColorsList.Add(0, content.ColorCollection);

            // If it's the same text, don't update text buffer and caret. It can be the same text if
            // it's not been cached, eg. it's the resources or some other content with UI content.
            // This simulates the cached code path above which also doesn't move the caret. And as
            // an added bonus, it will use less memory and CPU.
            bool sameText = IsSameTextAsCurrentSnapshot(TextView.TextSnapshot, content.Text);

            if (!sameText)
            {
                TextView.TextBuffer.Replace(new Span(0, TextView.TextBuffer.CurrentSnapshot.Length), content.Text);
                TextView.Caret.MoveTo(new SnapshotPoint(TextView.TextSnapshot, 0));
                TextView.Caret.EnsureVisible();
                TextView.Selection.Clear();
            }

            return(true);
        }