public void SimpleIntegration() { Buffer buffer = new Buffer("Directory/Test.cs", "Test.cs", SettingsMode.Normal); buffer.Controller.InitText(@"public class Test { public void Method0() { } public void Method1() { } }" ); TextNodesList list = new TextNodesList(buffer, new Settings(null)); string error; string shellError; Properties.CommandInfo commandInfo = new Properties.CommandInfo(); commandInfo.command = "buildin-cs:c#"; list.Build(commandInfo, Encoding.UTF8, out error, out shellError); Assert.AreEqual( "Test.cs\n" + "class Test (1)\n" + "\t+ void Method0() (3)\n" + "\t+ void Method1() (7)", list.Controller.Lines.GetText()); }
public void Build(Properties.CommandInfo commandInfo, Encoding encoding, out string error, out string shellError) { TextNodeParser buildinParser = null; string command = commandInfo.command; int index = command.IndexOf(':'); if (index != -1) { customSyntax = command.Substring(index + 1).Trim(); command = command.Substring(0, index).Trim(); } foreach (TextNodeParser parser in buildinParsers) { if (parser.name == command) { buildinParser = parser; break; } } error = null; shellError = null; Node node = null; if (buildinParser != null) { node = buildinParser.Parse(buffer.Controller.Lines); } else { Process p = new Process(); p.StartInfo.RedirectStandardOutput = true; p.StartInfo.RedirectStandardError = true; p.StartInfo.RedirectStandardInput = true; p.StartInfo.StandardOutputEncoding = encoding; p.StartInfo.StandardErrorEncoding = encoding; p.StartInfo.UseShellExecute = false; p.StartInfo.FileName = "cmd.exe"; p.StartInfo.Arguments = "/C " + command; p.Start(); p.StandardInput.Write(buffer.Controller.Lines); p.StandardInput.Close(); string output = p.StandardOutput.ReadToEnd(); string errors = p.StandardError.ReadToEnd(); p.WaitForExit(); if (!string.IsNullOrEmpty(errors)) { shellError = errors; } else { try { node = new Parser().Load(output); } catch (System.Exception e) { error = "Parsing error: " + e.Message + "\nSee \"" + settings.getTextNodes.name + "\" for more info"; } } } if (node == null) { if (error == null) { error = "Empty output\nSee \"" + settings.getTextNodes.name + "\" for more info"; } return; } tabSize = settings.tabSize.GetValue(null); lines = Controller.Lines; lines.ClearAllUnsafely(); places = new List <Place>(); AddLine(buffer.Name, new Place(-1, -1), true); AppendNodeOrNodesList(node); if (lines.LinesCount == 0) { lines.AddLineUnsafely(new Line(32)); } else { lines.CutLastLineBreakUnsafely(); } Place target = buffer.Controller.Lines.SoftNormalizedPlaceOf(buffer.Controller.LastSelection.caret); for (int i = places.Count; i-- > 0;) { if (places[i].iLine <= target.iLine) { Place place = new Place(0, i); if (place.iLine < 0) { place.iLine = 0; } else if (place.iLine >= buffer.Controller.Lines.LinesCount) { place.iLine = buffer.Controller.Lines.LinesCount; } Controller.PutCursor(place, false); break; } } showEncoding = false; Controller.isReadonly = true; additionKeyMap = new KeyMap(); { KeyAction action = new KeyAction("&View\\Nodes list\\Close nodes list", DoCloseBuffer, null, false); additionKeyMap.AddItem(new KeyItem(Keys.Escape, null, action)); additionKeyMap.AddItem(new KeyItem(Keys.Control | Keys.OemOpenBrackets, null, action)); } { KeyAction action = new KeyAction("&View\\Nodes list\\Jump to node", DoJumpTo, null, false); additionKeyMap.AddItem(new KeyItem(Keys.Enter, null, action)); } }