Initialize() публичный Метод

public Initialize ( ) : void
Результат void
		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;
		}
        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);
        }
Пример #3
0
		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);
			}
		}
Пример #4
0
        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;
        }