Пример #1
0
		public void TestDocumentRemove ()
		{
			var document = new Mono.TextEditor.TextDocument ();
			
			string top      = "1234567890\n";
			string testText =
			"12345678\n" +
			"1234567\n" +
			"123456\n" +
			"12345\n" +
			"1234\n" +
			"123\n" +
			"12\n" +
			"1\n" +
			"\n";
			document.Text = top + testText;
			document.Remove (0, top.Length);
			Assert.AreEqual (document.Text, testText);
			
			document.Remove (0, document.TextLength);
			DocumentLine line = document.GetLine (1);
			Assert.AreEqual (0, line.Offset);
			Assert.AreEqual (0, line.LengthIncludingDelimiter);
			Assert.AreEqual (0, document.TextLength);
			Assert.AreEqual (1, document.LineCount);
		}
        public void ReportTimings(Mono.TextEditor.TextDocument document)
        {
            if (count == 0)
            {
                // No timings recorded.
                return;
            }

            string extension = document.FileName.Extension;

            var average  = totalTime.TotalMilliseconds / count;
            var metadata = new TypingTimingMetadata {
                Average = average,
                First   = firstTime.Value.TotalMilliseconds,
                Maximum = maxTime.TotalMilliseconds,
                Dropped = droppedEvents
            };

            if (!string.IsNullOrEmpty(extension))
            {
                metadata.Extension = extension;
            }

            metadata.AddBuckets(buckets);
            MonoDevelop.SourceEditor.Counters.Typing.Inc(metadata);
        }
Пример #3
0
        public override Annotation[] GetAnnotations(FilePath repositoryPath)
        {
            List <Annotation> annotations = new List <Annotation> (Svn.GetAnnotations(this, repositoryPath, SvnRevision.First, SvnRevision.Base));
            Annotation        nextRev     = new Annotation(GettextCatalog.GetString("working copy"), "<uncommitted>", DateTime.MinValue);
            var baseDocument    = new Mono.TextEditor.TextDocument(GetBaseText(repositoryPath));
            var workingDocument = new Mono.TextEditor.TextDocument(File.ReadAllText(repositoryPath));

            // "SubversionException: blame of the WORKING revision is not supported"
            foreach (var hunk in baseDocument.Diff(workingDocument))
            {
                annotations.RemoveRange(hunk.RemoveStart - 1, hunk.Removed);
                for (int i = 0; i < hunk.Inserted; ++i)
                {
                    if (hunk.InsertStart + i >= annotations.Count)
                    {
                        annotations.Add(nextRev);
                    }
                    else
                    {
                        annotations.Insert(hunk.InsertStart - 1, nextRev);
                    }
                }
            }

            return(annotations.ToArray());
        }
        public void ReportTimings(Mono.TextEditor.TextDocument document)
        {
            if (count == 0)
            {
                // No timings recorded.
                return;
            }

            string extension = document.FileName.Extension;

            var metadata = new Dictionary <string, string> ();

            if (!string.IsNullOrEmpty(extension))
            {
                metadata ["Extension"] = extension;
            }

            var average = totalTime.TotalMilliseconds / count;

            metadata ["Average"] = average.ToString();
            metadata ["First"]   = firstTime.Value.TotalMilliseconds.ToString();
            metadata ["Maximum"] = maxTime.TotalMilliseconds.ToString();

            // Do we want to track the number of dropped events?
            // If there are any dropped events, something major happened to halt the event loop
            metadata ["Dropped"] = droppedEvents.ToString();

            // Add the buckets
            for (var bucket = 0; bucket < numberOfBuckets; bucket++)
            {
                metadata [$"Bucket{bucket}"] = buckets[bucket].ToString();
            }
            MonoDevelop.SourceEditor.Counters.Typing.Inc(metadata);
        }
Пример #5
0
        public void TestDocumentRemove()
        {
            var document = new Mono.TextEditor.TextDocument();

            string top      = "1234567890\n";
            string testText =
                "12345678\n" +
                "1234567\n" +
                "123456\n" +
                "12345\n" +
                "1234\n" +
                "123\n" +
                "12\n" +
                "1\n" +
                "\n";

            document.Text = top + testText;
            document.Remove(0, top.Length);
            Assert.AreEqual(document.Text, testText);

            document.Remove(0, document.TextLength);
            DocumentLine line = document.GetLine(1);

            Assert.AreEqual(0, line.Offset);
            Assert.AreEqual(0, line.LengthIncludingDelimiter);
            Assert.AreEqual(0, document.TextLength);
            Assert.AreEqual(1, document.LineCount);
        }
Пример #6
0
        // Returns a stream with the content of the file.
        // project and language parameters are optional
        public virtual Stream CreateFileContent(SolutionItem policyParent, Project project, string language, string fileName, string identifier)
        {
            Dictionary <string, string> tags = new Dictionary <string, string> ();

            ModifyTags(policyParent, project, language, identifier, fileName, ref tags);

            string content = CreateContent(project, tags, language);

            content = StringParserService.Parse(content, tags);
            string        mime      = DesktopService.GetMimeTypeForUri(fileName);
            CodeFormatter formatter = !string.IsNullOrEmpty(mime) ? CodeFormatterService.GetFormatter(mime) : null;

            if (formatter != null)
            {
                var formatted = formatter.FormatText(policyParent != null ? policyParent.Policies : null, content);
                if (formatted != null)
                {
                    content = formatted;
                }
            }

            MemoryStream ms = new MemoryStream();

            byte[] data;
            if (AddStandardHeader)
            {
                string header = StandardHeaderService.GetHeader(policyParent, fileName, true);
                data = System.Text.Encoding.UTF8.GetBytes(header);
                ms.Write(data, 0, data.Length);
            }

            Mono.TextEditor.TextDocument doc = new Mono.TextEditor.TextDocument();
            doc.Text = content;

            TextStylePolicy textPolicy = policyParent != null?policyParent.Policies.Get <TextStylePolicy> ("text/plain")
                                             : MonoDevelop.Projects.Policies.PolicyService.GetDefaultPolicy <TextStylePolicy> ("text/plain");

            string eolMarker = TextStylePolicy.GetEolMarker(textPolicy.EolMarker);

            byte[] eolMarkerBytes = System.Text.Encoding.UTF8.GetBytes(eolMarker);

            var tabToSpaces = textPolicy.TabsToSpaces? new string (' ', textPolicy.TabWidth) : null;

            foreach (Mono.TextEditor.DocumentLine line in doc.Lines)
            {
                var lineText = doc.GetTextAt(line.Offset, line.Length);
                if (tabToSpaces != null)
                {
                    lineText = lineText.Replace("\t", tabToSpaces);
                }
                data = System.Text.Encoding.UTF8.GetBytes(lineText);
                ms.Write(data, 0, data.Length);
                ms.Write(eolMarkerBytes, 0, eolMarkerBytes.Length);
            }

            ms.Position = 0;
            return(ms);
        }
 static bool IsBlankLine(Mono.TextEditor.TextDocument doc, Mono.TextEditor.DocumentLine line)
 {
     for (int i = 0; i < line.Length; i++)
     {
         if (!Char.IsWhiteSpace(doc.GetCharAt(line.Offset + i)))
         {
             return(false);
         }
     }
     return(true);
 }
Пример #8
0
        public void TestBufferCreationIssue()
        {
            var document = new Mono.TextEditor.TextDocument();

            for (int i = 1; i < 1000; i++)
            {
                var text = new string ('a', i);
                document.Text = text;
                Assert.AreEqual(i, document.TextLength);
                Assert.AreEqual(text, document.Text);
            }
        }
Пример #9
0
        public void TestVSTS524616()
        {
            var document = new Mono.TextEditor.TextDocument();

            document.Text = "test";
            string txt;

            document.TextChanging += delegate {
                txt = document.Text;
            };
            document.InsertText(0, "test");
            Assert.AreEqual("testtest", document.Text);
        }
Пример #10
0
        static string AddIndent(string text, string indent)
        {
            Mono.TextEditor.TextDocument doc = new Mono.TextEditor.TextDocument();
            doc.Text = text;
            StringBuilder result = new StringBuilder();

            foreach (var line in doc.Lines)
            {
                result.Append(indent);
                result.Append(doc.GetTextAt(line.SegmentIncludingDelimiter));
            }
            return(result.ToString());
        }
Пример #11
0
        public void ReportTimings(Mono.TextEditor.TextDocument document)
        {
            if (count == 0)
            {
                // No timings recorded.
                return;
            }

            string extension = document.FileName.Extension;

            var metadata = GetTypingTimingMetadata(extension);

            MonoDevelop.SourceEditor.Counters.Typing.Inc(metadata);
        }
Пример #12
0
        public void TestDocumentBug2Test()
        {
            var document = new Mono.TextEditor.TextDocument();

            string top      = "123\n456\n789\n0";
            string testText = "Hello World!";

            document.Text = top;

            document.Insert(top.Length, testText);

            DocumentLine line = document.GetLine(document.LineCount);

            Assert.AreEqual(top.Length - 1, line.Offset);
            Assert.AreEqual(testText.Length + 1, line.LengthIncludingDelimiter);
        }
Пример #13
0
            public static RemoveInfo GetRemoveInfo(Mono.TextEditor.TextDocument document, ref int pos)
            {
                int len = 0;

                while (pos > 0 && IsWhiteSpace(document.GetCharAt(pos)))
                {
                    --pos;
                    ++len;
                }
                if (len > 0)
                {
                    pos++;
                    return(new RemoveInfo(pos, len));
                }
                return(Empty);
            }
Пример #14
0
 public static void InformAutoSaveThread(Mono.TextEditor.TextDocument content)
 {
     if (content == null || !autoSaveEnabled)
     {
         return;
     }
     if (content.IsDirty)
     {
         queue.Enqueue(new FileContent(content.FileName, content));
         resetEvent.Set();
     }
     else
     {
         RemoveAutoSaveFile(content.FileName);
     }
 }
Пример #15
0
        public void TestDocumentBug1Test()
        {
            var document = new Mono.TextEditor.TextDocument ();

            string top    = "1234567890";
            document.Text = top;

            Assert.AreEqual (document.GetLine (1).LengthIncludingDelimiter, document.TextLength);

            document.Remove(0, document.TextLength);

            DocumentLine line = document.GetLine (1);
            Assert.AreEqual(0, line.Offset);
            Assert.AreEqual(0, line.LengthIncludingDelimiter);
            Assert.AreEqual(0, document.TextLength);
            Assert.AreEqual(1, document.LineCount);
        }
Пример #16
0
        public void TestDocumentBug1Test()
        {
            var document = new Mono.TextEditor.TextDocument();

            string top = "1234567890";

            document.Text = top;

            Assert.AreEqual(document.GetLine(1).LengthIncludingDelimiter, document.TextLength);

            document.Remove(0, document.TextLength);

            DocumentLine line = document.GetLine(1);

            Assert.AreEqual(0, line.Offset);
            Assert.AreEqual(0, line.LengthIncludingDelimiter);
            Assert.AreEqual(0, document.TextLength);
            Assert.AreEqual(1, document.LineCount);
        }
Пример #17
0
        public void SplitterTest()
        {
            var document = new Mono.TextEditor.TextDocument ();
            for (int i = 0; i < 100; i++) {
                document.Insert (0, new string ('c', i) + Environment.NewLine);
            }
            Assert.AreEqual (101, document.LineCount);
            for (int i = 0; i < 100; i++) {
                DocumentLine line = document.GetLine (i + 1 );
                Assert.AreEqual (99 - i, line.Length);
                Assert.AreEqual (Environment.NewLine.Length, line.DelimiterLength);
            }

            for (int i = 0; i < 100; i++) {
                DocumentLine line = document.GetLine (1);
                document.Remove (line.Length, line.DelimiterLength);
            }
            Assert.AreEqual (1, document.LineCount);
        }
Пример #18
0
		public void TestDocumentInsert ()
		{
			var document = new Mono.TextEditor.TextDocument ();
			
			string top  = "1234567890\n";
			string text =
			"12345678\n" +
			"1234567\n" +
			"123456\n" +
			"12345\n" +
			"1234\n" +
			"123\n" +
			"12\n" +
			"1\n" +
			"\n";
			
			document.Text = top;
			document.Insert (top.Length, text);
			Assert.AreEqual (top + text, document.Text);
		}
Пример #19
0
        public void TestDocumentInsert()
        {
            var document = new Mono.TextEditor.TextDocument();

            string top  = "1234567890\n";
            string text =
                "12345678\n" +
                "1234567\n" +
                "123456\n" +
                "12345\n" +
                "1234\n" +
                "123\n" +
                "12\n" +
                "1\n" +
                "\n";

            document.Text = top;
            document.Insert(top.Length, text);
            Assert.AreEqual(top + text, document.Text);
        }
Пример #20
0
		public void TestDocumentCreation ()
		{
			var document = new Mono.TextEditor.TextDocument ();
			
			string text = 
			"1234567890\n" +
			"12345678\n" +
			"1234567\n" +
			"123456\n" +
			"12345\n" +
			"1234\n" +
			"123\n" +
			"12\n" +
			"1\n" +
			"\n";
			document.Text = text;
			
			Assert.AreEqual (text, document.Text);
			Assert.AreEqual (11, document.LineCount);
		}
Пример #21
0
        static string StripHeaderAndBlankLines(string text, CodeDomProvider provider)
        {
            Mono.TextEditor.TextDocument doc = new Mono.TextEditor.TextDocument();
            doc.Text = text;
            int realStartLine = 0;

            for (int i = 1; i <= doc.LineCount; i++)
            {
                string lineText = doc.GetTextAt(doc.GetLine(i));
                // Microsoft.NET generates "auto-generated" tags where Mono generates "autogenerated" tags.
                if (lineText.Contains("</autogenerated>") || lineText.Contains("</auto-generated>"))
                {
                    realStartLine = i + 2;
                    break;
                }
            }

            // The Mono provider inserts additional blank lines, so strip them out
            // But blank lines might actually be significant in other languages.
            // We reformat the C# generated output to the user's coding style anyway, but the reformatter preserves blank lines
            if (provider is Microsoft.CSharp.CSharpCodeProvider)
            {
                bool previousWasBlank = false;
                for (int i = 1; i <= doc.LineCount; i++)
                {
                    Mono.TextEditor.DocumentLine line = doc.GetLine(i);
                    bool isBlank, isBracket;
                    CheckLine(doc, line, out isBlank, out isBracket);
                    if (isBlank && previousWasBlank && line.LengthIncludingDelimiter > 0)
                    {
                        doc.Remove(line.Offset, line.LengthIncludingDelimiter);
                        i--;
                    }
                    previousWasBlank = isBlank || isBracket;
                }
            }

            int offset = doc.GetLine(realStartLine).Offset;

            return(doc.GetTextAt(offset, doc.TextLength - offset));
        }
Пример #22
0
        public void TestDocumentCreation()
        {
            var document = new Mono.TextEditor.TextDocument();

            string text =
                "1234567890\n" +
                "12345678\n" +
                "1234567\n" +
                "123456\n" +
                "12345\n" +
                "1234\n" +
                "123\n" +
                "12\n" +
                "1\n" +
                "\n";

            document.Text = text;

            Assert.AreEqual(text, document.Text);
            Assert.AreEqual(11, document.LineCount);
        }
Пример #23
0
 static void CheckLine(Mono.TextEditor.TextDocument doc, Mono.TextEditor.DocumentLine line, out bool isBlank, out bool isBracket)
 {
     isBlank   = true;
     isBracket = false;
     for (int i = 0; i < line.LengthIncludingDelimiter; i++)
     {
         char c = doc.GetCharAt(line.Offset + i);
         if (c == '{')
         {
             isBracket = true;
             isBlank   = false;
         }
         else if (!Char.IsWhiteSpace(c))
         {
             isBlank = false;
             if (isBracket)
             {
                 isBracket = false;
                 break;
             }
         }
     }
 }
Пример #24
0
        public void SplitterTest()
        {
            var document = new Mono.TextEditor.TextDocument();

            for (int i = 0; i < 100; i++)
            {
                document.Insert(0, new string ('c', i) + Environment.NewLine);
            }
            Assert.AreEqual(101, document.LineCount);
            for (int i = 0; i < 100; i++)
            {
                DocumentLine line = document.GetLine(i + 1);
                Assert.AreEqual(99 - i, line.Length);
                Assert.AreEqual(Environment.NewLine.Length, line.DelimiterLength);
            }

            for (int i = 0; i < 100; i++)
            {
                DocumentLine line = document.GetLine(1);
                document.Remove(line.Length, line.DelimiterLength);
            }
            Assert.AreEqual(1, document.LineCount);
        }
Пример #25
0
 public FileContent(string fileName, Mono.TextEditor.TextDocument content)
 {
     this.FileName = fileName;
     this.Content  = content;
 }
Пример #26
0
		public override Annotation[] GetAnnotations (FilePath repositoryPath)
		{
			List<Annotation> annotations = new List<Annotation> (Svn.GetAnnotations (this, repositoryPath, SvnRevision.First, SvnRevision.Base));
			Annotation nextRev = new Annotation (GettextCatalog.GetString ("working copy"), "<uncommitted>", DateTime.MinValue);
			var baseDocument = new Mono.TextEditor.TextDocument (GetBaseText (repositoryPath));
			var workingDocument = new Mono.TextEditor.TextDocument (File.ReadAllText (repositoryPath));
			
			// "SubversionException: blame of the WORKING revision is not supported"
			foreach (var hunk in baseDocument.Diff (workingDocument)) {
				annotations.RemoveRange (hunk.RemoveStart - 1, hunk.Removed);
				for (int i = 0; i < hunk.Inserted; ++i) {
					if (hunk.InsertStart + i >= annotations.Count)
						annotations.Add (nextRev);
					else
						annotations.Insert (hunk.InsertStart - 1, nextRev);
				}
			}
			
			return annotations.ToArray ();
		}
        IEnumerable <DomRegion> SearchMember(IEntity member, ITypeResolveContext dom, FilePath fileName, Mono.TextEditor.TextEditorData editor, Mono.TextEditor.TextDocument buildDocument, List <LocalDocumentInfo.OffsetInfo> offsetInfos, ParsedDocument parsedDocument)
        {
            // TODO: Type system conversion.
            yield break;
//			var resolver = new NRefactoryResolver (dom, parsedDocument.CompilationUnit, ICSharpCode.OldNRefactory.SupportedLanguage.CSharp, editor, fileName);
//
//			var visitor = new FindMemberAstVisitor (buildDocument, member);
//			visitor.IncludeXmlDocumentation = IncludeDocumentation;
//			visitor.RunVisitor (resolver);
//
//			foreach (var result in visitor.FoundReferences) {
//				var offsetInfo = offsetInfos.FirstOrDefault (info => info.ToOffset <= result.Position && result.Position < info.ToOffset + info.Length);
//				if (offsetInfo == null)
//					continue;
//				var offset = offsetInfo.FromOffset + result.Position - offsetInfo.ToOffset;
//				var loc = editor.OffsetToLocation (offset);
//				yield return new DomRegion (fileName, loc.Line, loc.Column, loc.Line, loc.Column + result.Name.Lenhth);
//			}
        }
Пример #28
0
		public void TestBufferCreationIssue()
		{
			var document = new Mono.TextEditor.TextDocument ();

			for (int i = 1; i < 1000; i++) {
				var text = new string ('a', i);
				document.Text = text;
				Assert.AreEqual (i, document.TextLength);
				Assert.AreEqual (text, document.Text);
			}
		}
Пример #29
0
		static string AddIndent (string text, string indent)
		{
			Mono.TextEditor.TextDocument doc = new Mono.TextEditor.TextDocument ();
			doc.Text = text;
			StringBuilder result = new StringBuilder ();
			foreach (var line in doc.Lines) {
				result.Append (indent);
				result.Append (doc.GetTextAt (line));
			}
			return result.ToString ();
		}
Пример #30
0
        public void TestDocumentBug2Test()
        {
            var document = new Mono.TextEditor.TextDocument ();

            string top      = "123\n456\n789\n0";
            string testText = "Hello World!";

            document.Text = top;

            document.Insert (top.Length, testText);

            DocumentLine line = document.GetLine (document.LineCount);

            Assert.AreEqual (top.Length - 1, line.Offset);
            Assert.AreEqual (testText.Length + 1, line.LengthIncludingDelimiter);
        }
		public ReadonlyDocumentSnapshot (Mono.TextEditor.TextDocument textDocument)
		{
			snapshot = textDocument.CreateDocumentSnapshot ();
			version = new TextSourceVersionWrapper (textDocument.Version);
		}
Пример #32
0
		static string StripHeaderAndBlankLines (string text, CodeDomProvider provider)
		{
			Mono.TextEditor.TextDocument doc = new Mono.TextEditor.TextDocument ();
			doc.Text = text;
			int realStartLine = 0;
			for (int i = 1; i <= doc.LineCount; i++) {
				string lineText = doc.GetTextAt (doc.GetLine (i));
				// Microsoft.NET generates "auto-generated" tags where Mono generates "autogenerated" tags.
				if (lineText.Contains ("</autogenerated>") || lineText.Contains ("</auto-generated>")) {
					realStartLine = i + 2;
					break;
				}
			}
			
			// The Mono provider inserts additional blank lines, so strip them out
			// But blank lines might actually be significant in other languages.
			// We reformat the C# generated output to the user's coding style anyway, but the reformatter preserves blank lines
			if (provider is Microsoft.CSharp.CSharpCodeProvider) {
				bool previousWasBlank = false;
				for (int i = 1; i <= doc.LineCount; i++) {
					Mono.TextEditor.LineSegment line = doc.GetLine (i);
					bool isBlank, isBracket;
					CheckLine (doc, line, out isBlank, out isBracket);
					if (isBlank && previousWasBlank && line.LengthIncludingDelimiter > 0) {
						doc.Remove (line.Offset, line.LengthIncludingDelimiter);
						i--;
					}
					previousWasBlank = isBlank || isBracket;
				}
			}
			
			int offset = doc.GetLine (realStartLine).Offset;
			return doc.GetTextAt (offset, doc.TextLength - offset);
		}
Пример #33
0
        void HandleTreeviewFilesTestExpandRow(object o, TestExpandRowArgs args)
        {
            TreeIter iter;

            if (changedpathstore.IterChildren(out iter, args.Iter))
            {
                string[] diff = changedpathstore.GetValue(iter, colDiff) as string[];
                if (diff != null)
                {
                    return;
                }

                string path = (string)changedpathstore.GetValue(args.Iter, colPath);
                changedpathstore.SetValue(iter, colDiff, new string[] { GettextCatalog.GetString("Loading data...") });
                var rev = SelectedRevision;
                ThreadPool.QueueUserWorkItem(delegate {
                    string text;
                    try {
                        text = info.Repository.GetTextAtRevision(path, rev);
                    } catch (Exception e) {
                        Application.Invoke(delegate {
                            LoggingService.LogError("Error while getting revision text", e);
                            MessageService.ShowError("Error while getting revision text.", "The file may not be part of the working copy.");
                        });
                        return;
                    }
                    Revision prevRev = null;
                    try {
                        prevRev = rev.GetPrevious();
                    } catch (Exception e) {
                        Application.Invoke(delegate {
                            LoggingService.LogError("Error while getting previous revision", e);
                            MessageService.ShowException(e, "Error while getting previous revision.");
                        });
                        return;
                    }
                    string[] lines;
                    // Indicator that the file was binary
                    if (text == null)
                    {
                        lines = new [] { " Binary files differ" };
                    }
                    else
                    {
                        var changedDocument = new Mono.TextEditor.TextDocument(text);
                        if (prevRev == null)
                        {
                            lines = new string[changedDocument.LineCount];
                            for (int i = 0; i < changedDocument.LineCount; i++)
                            {
                                lines[i] = "+ " + changedDocument.GetLineText(i + 1).TrimEnd('\r', '\n');
                            }
                        }
                        else
                        {
                            string prevRevisionText = "";
                            try {
                                prevRevisionText = info.Repository.GetTextAtRevision(path, prevRev);
                            } catch (Exception e) {
                                // The file did not exist at this point in time, so just treat it as empty
                            }

                            var originalDocument      = new Mono.TextEditor.TextDocument(prevRevisionText);
                            originalDocument.FileName = "Revision " + prevRev.ToString();
                            changedDocument.FileName  = "Revision " + rev.ToString();
                            lines = Mono.TextEditor.Utils.Diff.GetDiffString(originalDocument, changedDocument).Split('\n');
                        }
                    }
                    Application.Invoke(delegate {
                        changedpathstore.SetValue(iter, colDiff, lines);
                    });
                });
            }
        }
Пример #34
0
 public ReadonlyDocumentSnapshot(Mono.TextEditor.TextDocument textDocument)
 {
     snapshot = textDocument.CreateDocumentSnapshot();
     version  = new TextSourceVersionWrapper(textDocument.Version);
 }
Пример #35
0
		void HandleTreeviewFilesTestExpandRow (object o, TestExpandRowArgs args)
		{
			TreeIter iter;
			if (changedpathstore.IterChildren (out iter, args.Iter)) {
				string[] diff = changedpathstore.GetValue (iter, colDiff) as string[];
				if (diff != null)
					return;

				string path = (string)changedpathstore.GetValue (args.Iter, colPath);

				changedpathstore.SetValue (iter, colDiff, new string[] { GettextCatalog.GetString ("Loading data...") });
				var rev = SelectedRevision;
				ThreadPool.QueueUserWorkItem (delegate {
					string text = "";
					try {
						text = info.Repository.GetTextAtRevision (path, rev);
					} catch (Exception e) {
						Application.Invoke (delegate {
							LoggingService.LogError ("Error while getting revision text", e);
							MessageService.ShowError ("Error while getting revision text.", "The file may not be part of the working copy.");
						});
						return;
					}
					Revision prevRev = null;
					try {
						prevRev = rev.GetPrevious ();
					} catch (Exception e) {
						Application.Invoke (delegate {
							LoggingService.LogError ("Error while getting previous revision", e);
							MessageService.ShowException (e, "Error while getting previous revision.");
						});
						return;
					}
					string[] lines;
					// Indicator that the file was binary
					if (text == null) {
						lines = new [] { " Binary files differ" };
					} else {
						var changedDocument = new Mono.TextEditor.TextDocument (text);
						if (prevRev == null) {
							lines = new string [changedDocument.LineCount];
							for (int i = 0; i < changedDocument.LineCount; i++) {
								lines[i] = "+ " + changedDocument.GetLineText (i + 1).TrimEnd ('\r','\n');
							}
						} else {
							string prevRevisionText = "";
							try {
								prevRevisionText = info.Repository.GetTextAtRevision (path, prevRev);
							} catch (Exception e) {
								Application.Invoke (delegate {
									LoggingService.LogError ("Error while getting revision text", e);
									MessageService.ShowError ("Error while getting revision text.", "The file may not be part of the working copy.");
								});
								return;
							}

							if (String.IsNullOrEmpty (text)) {
								if (!String.IsNullOrEmpty (prevRevisionText)) {
									lines = new string [changedDocument.LineCount];
									for (int i = 0; i < changedDocument.LineCount; i++) {
										lines [i] = "- " + changedDocument.GetLineText (i + 1).TrimEnd ('\r','\n');
									}
								}
							}

							var originalDocument = new Mono.TextEditor.TextDocument (prevRevisionText);
							originalDocument.FileName = "Revision " + prevRev;
							changedDocument.FileName = "Revision " + rev;
							lines = Mono.TextEditor.Utils.Diff.GetDiffString (originalDocument, changedDocument).Split ('\n');
						}
					}
					Application.Invoke (delegate {
						changedpathstore.SetValue (iter, colDiff, lines);
					});
				});
			}
		}
        // Returns a stream with the content of the file.
        // project and language parameters are optional
        public virtual Stream CreateFileContent(SolutionItem policyParent, Project project, string language, string fileName, string identifier)
        {
            var model = GetTagModel(policyParent, project, language, identifier, fileName);

            //HACK: for API compat, CreateContent just gets the override, not the base model
            // but ProcessContent gets the entire model
            string content = CreateContent(project, model.OverrideTags, language);

            content = ProcessContent(content, model);

            string        mime      = DesktopService.GetMimeTypeForUri(fileName);
            CodeFormatter formatter = !string.IsNullOrEmpty(mime) ? CodeFormatterService.GetFormatter(mime) : null;

            if (formatter != null)
            {
                var formatted = formatter.FormatText(policyParent != null ? policyParent.Policies : null, content);
                if (formatted != null)
                {
                    content = formatted;
                }
            }

            var ms = new MemoryStream();

            var bom = Encoding.UTF8.GetPreamble();

            ms.Write(bom, 0, bom.Length);

            byte[] data;
            if (AddStandardHeader)
            {
                string header = StandardHeaderService.GetHeader(policyParent, fileName, true);
                data = System.Text.Encoding.UTF8.GetBytes(header);
                ms.Write(data, 0, data.Length);
            }

            Mono.TextEditor.TextDocument doc = new Mono.TextEditor.TextDocument();
            doc.Text = content;

            TextStylePolicy textPolicy = policyParent != null?policyParent.Policies.Get <TextStylePolicy> ("text/plain")
                                             : MonoDevelop.Projects.Policies.PolicyService.GetDefaultPolicy <TextStylePolicy> ("text/plain");

            string eolMarker = TextStylePolicy.GetEolMarker(textPolicy.EolMarker);

            byte[] eolMarkerBytes = System.Text.Encoding.UTF8.GetBytes(eolMarker);

            var tabToSpaces = textPolicy.TabsToSpaces? new string (' ', textPolicy.TabWidth) : null;

            foreach (Mono.TextEditor.DocumentLine line in doc.Lines)
            {
                var lineText = doc.GetTextAt(line.Offset, line.Length);
                if (tabToSpaces != null)
                {
                    lineText = lineText.Replace("\t", tabToSpaces);
                }
                data = System.Text.Encoding.UTF8.GetBytes(lineText);
                ms.Write(data, 0, data.Length);
                ms.Write(eolMarkerBytes, 0, eolMarkerBytes.Length);
            }

            ms.Position = 0;
            return(ms);
        }
		// Returns a stream with the content of the file.
		// project and language parameters are optional
		public virtual Stream CreateFileContent (SolutionItem policyParent, Project project, string language, string fileName, string identifier)
		{
			Dictionary<string, string> tags = new Dictionary<string, string> ();
			ModifyTags (policyParent, project, language, identifier, fileName, ref tags);
			
			string content = CreateContent (project, tags, language);
			content = StringParserService.Parse (content, tags);
			string mime = DesktopService.GetMimeTypeForUri (fileName);
			CodeFormatter formatter = !string.IsNullOrEmpty (mime) ? CodeFormatterService.GetFormatter (mime) : null;
			
			if (formatter != null) {
				var formatted = formatter.FormatText (policyParent != null ? policyParent.Policies : null, content);
				if (formatted != null)
					content = formatted;
			}
			
			MemoryStream ms = new MemoryStream ();
			byte[] data;
			if (AddStandardHeader) {
				string header = StandardHeaderService.GetHeader (policyParent, fileName, true);
				data = System.Text.Encoding.UTF8.GetBytes (header);
				ms.Write (data, 0, data.Length);
			}
			
			Mono.TextEditor.TextDocument doc = new Mono.TextEditor.TextDocument ();
			doc.Text = content;
			
			TextStylePolicy textPolicy = policyParent != null ? policyParent.Policies.Get<TextStylePolicy> ("text/plain")
				: MonoDevelop.Projects.Policies.PolicyService.GetDefaultPolicy<TextStylePolicy> ("text/plain");
			string eolMarker = TextStylePolicy.GetEolMarker (textPolicy.EolMarker);
			byte[] eolMarkerBytes = System.Text.Encoding.UTF8.GetBytes (eolMarker);
			
			var tabToSpaces = textPolicy.TabsToSpaces? new string (' ', textPolicy.TabWidth) : null;
			
			foreach (Mono.TextEditor.LineSegment line in doc.Lines) {
				var lineText = doc.GetTextAt (line.Offset, line.Length);
				if (tabToSpaces != null)
					lineText = lineText.Replace ("\t", tabToSpaces);
				data = System.Text.Encoding.UTF8.GetBytes (lineText);
				ms.Write (data, 0, data.Length);
				ms.Write (eolMarkerBytes, 0, eolMarkerBytes.Length);
			}
			
			ms.Position = 0;
			return ms;
		}
Пример #38
0
			public FileContent (string fileName, Mono.TextEditor.TextDocument content)
			{
				this.FileName = fileName;
				this.Content = content;
			}
Пример #39
0
		static string AddIndent (string text, string indent)
		{
			var doc = new Mono.TextEditor.TextDocument ();
			doc.Text = text;
			var result = new StringBuilder ();
			foreach (var line in doc.Lines) {
				result.Append (indent);
				result.Append (doc.GetTextAt (line.SegmentIncludingDelimiter));
			}
			return result.ToString ();
		}
		// Returns a stream with the content of the file.
		// project and language parameters are optional
		public virtual Stream CreateFileContent (SolutionItem policyParent, Project project, string language, string fileName, string identifier)
		{
			var model = GetTagModel (policyParent, project, language, identifier, fileName);

			//HACK: for API compat, CreateContent just gets the override, not the base model
			// but ProcessContent gets the entire model
			string content = CreateContent (project, model.OverrideTags, language);

			content = ProcessContent (content, model);

			string mime = DesktopService.GetMimeTypeForUri (fileName);
			CodeFormatter formatter = !string.IsNullOrEmpty (mime) ? CodeFormatterService.GetFormatter (mime) : null;
			
			if (formatter != null) {
				var formatted = formatter.FormatText (policyParent != null ? policyParent.Policies : null, content);
				if (formatted != null)
					content = formatted;
			}
			
			var ms = new MemoryStream ();

			var bom = Encoding.UTF8.GetPreamble ();
			ms.Write (bom, 0, bom.Length);

			byte[] data;
			if (AddStandardHeader) {
				string header = StandardHeaderService.GetHeader (policyParent, fileName, true);
				data = System.Text.Encoding.UTF8.GetBytes (header);
				ms.Write (data, 0, data.Length);
			}
			
			Mono.TextEditor.TextDocument doc = new Mono.TextEditor.TextDocument ();
			doc.Text = content;
			
			TextStylePolicy textPolicy = policyParent != null ? policyParent.Policies.Get<TextStylePolicy> ("text/plain")
				: MonoDevelop.Projects.Policies.PolicyService.GetDefaultPolicy<TextStylePolicy> ("text/plain");
			string eolMarker = TextStylePolicy.GetEolMarker (textPolicy.EolMarker);
			byte[] eolMarkerBytes = System.Text.Encoding.UTF8.GetBytes (eolMarker);
			
			var tabToSpaces = textPolicy.TabsToSpaces? new string (' ', textPolicy.TabWidth) : null;
			
			foreach (Mono.TextEditor.DocumentLine line in doc.Lines) {
				var lineText = doc.GetTextAt (line.Offset, line.Length);
				if (tabToSpaces != null)
					lineText = lineText.Replace ("\t", tabToSpaces);
				data = System.Text.Encoding.UTF8.GetBytes (lineText);
				ms.Write (data, 0, data.Length);
				ms.Write (eolMarkerBytes, 0, eolMarkerBytes.Length);
			}
			
			ms.Position = 0;
			return ms;
		}