Inheritance: MonoDevelop.Ide.Gui.Content.TextEditorExtension
		static CSharpTextEditorIndentation Setup (string input, out TestViewContent content)
		{
			TestWorkbenchWindow tww = new TestWorkbenchWindow ();
			content = new TestViewContent ();
			content.Data.Options.IndentStyle = IndentStyle.Auto;
			tww.ViewContent = content;
			content.ContentName = "a.cs";
			content.GetTextEditorData ().Document.MimeType = "text/x-csharp";

			Document doc = new Document (tww);

			var text = input;
			int endPos = text.IndexOf ('$');
			if (endPos >= 0)
				text = text.Substring (0, endPos) + text.Substring (endPos + 1);

			content.Text = text;
			content.CursorPosition = System.Math.Max (0, endPos);


			var compExt = new CSharpCompletionTextEditorExtension ();
			compExt.Initialize (doc);
			content.Contents.Add (compExt);
			
			var ext = new CSharpTextEditorIndentation ();
			CSharpTextEditorIndentation.OnTheFlyFormatting = true;
			ext.Initialize (doc);
			content.Contents.Add (ext);
			
			doc.UpdateParseDocument ();
			return ext;
		}
Beispiel #2
0
 static CSharpTextEditorIndentation()
 {
     CompletionWindowManager.WordCompleted += delegate(object sender, CodeCompletionContextEventArgs e) {
         IExtensibleTextEditor editor = e.Widget as IExtensibleTextEditor;
         if (editor == null)
         {
             return;
         }
         ITextEditorExtension textEditorExtension = editor.Extension;
         while (textEditorExtension != null && !(textEditorExtension is CSharpTextEditorIndentation))
         {
             textEditorExtension = textEditorExtension.Next;
         }
         CSharpTextEditorIndentation extension = textEditorExtension as CSharpTextEditorIndentation;
         if (extension == null)
         {
             return;
         }
         extension.stateTracker.UpdateEngine();
         if (extension.stateTracker.Engine.NeedsReindent)
         {
             extension.DoReSmartIndent();
         }
     };
 }
 void CheckOutput(TextEditorData data, string output, CSharpTextEditorIndentation engine = null)
 {
     if (engine == null)
         engine = new CSharpTextEditorIndentation ();
     engine.FixLineStart (data, CreateTracker (data), data.Caret.Line);
     int idx = output.IndexOf ('$');
     if (idx > 0)
         output = output.Substring (0, idx) + output.Substring (idx + 1);
     if (output != data.Text) {
         Console.WriteLine ("expected:");
         Console.WriteLine (output.Replace ("\t", "\\t").Replace (" ", "."));
         Console.WriteLine ("was:");
         Console.WriteLine (data.Text.Replace ("\t", "\\t").Replace (" ", "."));
     }
     Assert.AreEqual (output, data.Text);
     Assert.AreEqual (idx, data.Caret.Offset, "Caret offset mismatch.");
 }
        public void TestStringContination()
        {
            var data = Create ("\t\t\"Hello$World\"");
            MiscActions.InsertNewLine (data);

            var engine = new CSharpTextEditorIndentation {
                wasInStringLiteral = true
            };
            CheckOutput (data, "\t\t\"Hello\" +" + eolMarker + "\t\t\"$World\"", engine);
        }
        public void TestBug17896()
        {
            var data = Create ("\t\t\"This is a long test string.$        It contains spaces.\"");
            MiscActions.InsertNewLine (data);

            var engine = new CSharpTextEditorIndentation {
                wasInStringLiteral = true
            };
            CheckOutput (data, "\t\t\"This is a long test string.\" +" + eolMarker + "\t\t\"$        It contains spaces.\"", engine);
        }
        public void TestBug17766()
        {
            var data = Create (@"
            class Foo
            {
            $void Bar ()
            {
            }
            }
            ");
            var engine = new CSharpTextEditorIndentation ();

            var tww = new TestWorkbenchWindow ();
            var content = new TestViewContent (data);
            tww.ViewContent = content;
            content.ContentName = "a.cs";
            engine.Initialize (new Document (tww));
            MiscActions.RemoveTab (data);
            engine.KeyPress (Gdk.Key.Tab, '\t', Gdk.ModifierType.ShiftMask);
            CheckOutput (data, @"
            class Foo
            {
            $void Bar ()
            {
            }
            }
            ", engine);
        }
		public CSharpTextPasteHandler (CSharpTextEditorIndentation indent, ICSharpCode.NRefactory6.CSharp.IStateMachineIndentEngine decoratedEngine, OptionSet formattingOptions)
		{
			this.engine = new ICSharpCode.NRefactory6.CSharp.TextPasteIndentEngine (decoratedEngine, formattingOptions);
			this.indent = indent;
		}
Beispiel #8
0
 public CSharpTextPasteHandler(CSharpTextEditorIndentation indent, OptionSet optionSet)
 {
     this.indent    = indent;
     this.optionSet = optionSet;
 }
 public CSharpTextPasteHandler(CSharpTextEditorIndentation indent, ICSharpCode.NRefactory6.CSharp.IStateMachineIndentEngine decoratedEngine, OptionSet formattingOptions)
 {
     this.engine = new ICSharpCode.NRefactory6.CSharp.TextPasteIndentEngine(decoratedEngine, formattingOptions);
     this.indent = indent;
 }
		static async Task Simulate (string input, Action<TestViewContent, CSharpTextEditorIndentation> act)
		{
			TestWorkbenchWindow tww = new TestWorkbenchWindow ();
			var content = new TestViewContent ();
			content.Data.Options = new CustomEditorOptions {
				IndentStyle = IndentStyle.Auto
			};

			tww.ViewContent = content;
			content.ContentName = "/a.cs";
			content.Data.MimeType = "text/x-csharp";

			var doc = new Document (tww);

			var sb = new StringBuilder ();
			int cursorPosition = 0, selectionStart = -1, selectionEnd = -1;

			for (int i = 0; i < input.Length; i++) {
				var ch = input [i];
				switch (ch) {
				case '$':
					cursorPosition = sb.Length;
					break;
				case '<':
					if (i + 1 < input.Length) {
						if (input [i + 1] == '-') {
							selectionStart = sb.Length;
							i++;
							break;
						}
					}
					goto default;
				case '-':
					if (i + 1 < input.Length) {
						var next = input [i + 1];
						if (next == '>') {
							selectionEnd = sb.Length;
							i++;
							break;
						}
					}
					goto default;
				default:
					sb.Append (ch);
					break;
				}
			}
			content.Text = sb.ToString ();
			content.CursorPosition = cursorPosition;

			var project = Services.ProjectService.CreateProject ("C#");
			project.Name = "test";
			project.FileName = "test.csproj";
			project.Files.Add (new ProjectFile (content.ContentName, BuildAction.Compile)); 
			project.Policies.Set (Projects.Policies.PolicyService.InvariantPolicies.Get<CSharpFormattingPolicy> (), CSharpFormatter.MimeType);

			var solution = new MonoDevelop.Projects.Solution ();
			solution.AddConfiguration ("", true); 
			solution.DefaultSolutionFolder.AddItem (project);
			using (var monitor = new ProgressMonitor ())
				await TypeSystemService.Load (solution, monitor);
			content.Project = project;
			doc.SetProject (project);

			var compExt = new CSharpCompletionTextEditorExtension ();
			compExt.Initialize (doc.Editor, doc);
			content.Contents.Add (compExt);
			
			var ext = new CSharpTextEditorIndentation ();
			CSharpTextEditorIndentation.OnTheFlyFormatting = true;
			ext.Initialize (doc.Editor, doc);
			content.Contents.Add (ext);
			
			await doc.UpdateParseDocument ();
			if (selectionStart >= 0 && selectionEnd >= 0)
				content.GetTextEditorData ().SetSelection (selectionStart, selectionEnd);
			try {
				act (content, ext);
			} finally {
				TypeSystemService.Unload (solution);
			}
		}
        static CSharpTextEditorIndentation Setup(string input, out TestViewContent content)
        {
            TestWorkbenchWindow tww = new TestWorkbenchWindow ();
            content = new TestViewContent ();
            content.Data.Options.IndentStyle = IndentStyle.Auto;
            tww.ViewContent = content;
            content.ContentName = "a.cs";
            content.GetTextEditorData ().Document.MimeType = "text/x-csharp";

            Document doc = new Document (tww);

            var sb = new StringBuilder ();
            int cursorPosition = 0, selectionStart = -1, selectionEnd = -1;

            for (int i = 0; i < input.Length; i++) {
                var ch = input [i];
                switch (ch) {
                case '$':
                    cursorPosition = sb.Length;
                    break;
                case '<':
                    if (i + 1 < input.Length) {
                        if (input [i + 1] == '-') {
                            selectionStart = sb.Length;
                            i++;
                            break;
                        }
                    }
                    goto default;
                case '-':
                    if (i + 1 < input.Length) {
                        var next = input [i + 1];
                        if (next == '>') {
                            selectionEnd = sb.Length;
                            i++;
                            break;
                        }
                    }
                    goto default;
                default:
                    sb.Append (ch);
                    break;
                }
            }
            content.Text = sb.ToString ();
            content.CursorPosition = cursorPosition;

            var compExt = new CSharpCompletionTextEditorExtension ();
            compExt.Initialize (doc);
            content.Contents.Add (compExt);

            var ext = new CSharpTextEditorIndentation ();
            CSharpTextEditorIndentation.OnTheFlyFormatting = true;
            ext.Initialize (doc);
            content.Contents.Add (ext);

            doc.UpdateParseDocument ();
            if (selectionStart >= 0 && selectionEnd >= 0)
                content.GetTextEditorData ().SetSelection (selectionStart, selectionEnd);
            return ext;
        }