public static CompletionDataList CreateProvider (string text, string extension, bool isCtrlSpace) { string parsedText; string editorText; int cursorPosition = text.IndexOf ('$'); int endPos = text.IndexOf ('$', cursorPosition + 1); if (endPos == -1) parsedText = editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1); else { parsedText = text.Substring (0, cursorPosition) + new string (' ', endPos - cursorPosition) + text.Substring (endPos + 1); editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring (endPos + 1); cursorPosition = endPos - 1; } var tww = new MonoDevelop.CSharpBinding.Tests.TestWorkbenchWindow (); var sev = new MonoDevelop.CSharpBinding.Tests.TestViewContent (); var project = new AspNetAppProject ("C#"); project.FileName = UnitTests.TestBase.GetTempFile (".csproj"); string file = UnitTests.TestBase.GetTempFile (extension); project.AddFile (file); ProjectDomService.Load (project); ProjectDom dom = ProjectDomService.GetProjectDom (project); dom.ForceUpdate (true); ProjectDomService.Parse (project, file, delegate { return parsedText; }); ProjectDomService.Parse (project, file, delegate { return parsedText; }); sev.Project = project; sev.ContentName = file; sev.Text = editorText; sev.CursorPosition = cursorPosition; tww.ViewContent = sev; var doc = new MonoDevelop.Ide.Gui.Document (tww); doc.ParsedDocument = new MonoDevelop.AspNet.Parser.AspNetParser ().Parse (null, sev.ContentName, parsedText); foreach (var e in doc.ParsedDocument.Errors) Console.WriteLine (e); var textEditorCompletion = new MonoDevelop.AspNet.Gui.AspNetEditorExtension (); Initialize (textEditorCompletion, doc); int triggerWordLength = 1; CodeCompletionContext ctx = new CodeCompletionContext (); ctx.TriggerOffset = sev.CursorPosition; int line, column; sev.GetLineColumnFromPosition (sev.CursorPosition, out line, out column); ctx.TriggerLine = line; ctx.TriggerLineOffset = column - 1; if (isCtrlSpace) return textEditorCompletion.CodeCompletionCommand (ctx) as CompletionDataList; else return textEditorCompletion.HandleCodeCompletion (ctx, editorText[cursorPosition - 1] , ref triggerWordLength) as CompletionDataList; }
static WebFormsTestingEditorExtension CreateEditor(string text, string extension, out string editorText, out TestViewContent sev) { string parsedText; int cursorPosition = text.IndexOf('$'); int endPos = text.IndexOf('$', cursorPosition + 1); if (endPos == -1) { parsedText = editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1); } else { parsedText = text.Substring(0, cursorPosition) + new string (' ', endPos - cursorPosition) + text.Substring(endPos + 1); editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring(endPos + 1); cursorPosition = endPos - 1; } var project = new AspNetAppProject("C#"); project.References.Add(new ProjectReference(ReferenceType.Package, "System")); project.References.Add(new ProjectReference(ReferenceType.Package, "System.Web")); project.FileName = UnitTests.TestBase.GetTempFile(".csproj"); string file = UnitTests.TestBase.GetTempFile(extension); project.AddFile(file); var pcw = TypeSystemService.LoadProject(project); TypeSystemService.ForceUpdate(pcw); pcw.ReconnectAssemblyReferences(); sev = new TestViewContent(); sev.Project = project; sev.ContentName = file; sev.Text = editorText; sev.CursorPosition = cursorPosition; var tww = new TestWorkbenchWindow(); tww.ViewContent = sev; var doc = new TestDocument(tww); doc.Editor.Document.FileName = sev.ContentName; var parser = new WebFormsParser(); var parsedDoc = (WebFormsParsedDocument)parser.Parse(false, sev.ContentName, new StringReader(parsedText), project); doc.HiddenParsedDocument = parsedDoc; return(new WebFormsTestingEditorExtension(doc)); }
static RazorTestingEditorExtension CreateEditor(string text, bool isInCSharpContext, out string editorText, out TestViewContent sev) { string parsedText; int cursorPosition = text.IndexOf('$'); int endPos = text.IndexOf('$', cursorPosition + 1); if (endPos == -1) { parsedText = editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1); } else { parsedText = text.Substring(0, cursorPosition) + new string (' ', endPos - cursorPosition) + text.Substring(endPos + 1); editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring(endPos + 1); cursorPosition = endPos - 1; } var project = new AspNetAppProject("C#"); project.FileName = UnitTests.TestBase.GetTempFile(".csproj"); string file = UnitTests.TestBase.GetTempFile(extension); project.AddFile(file); var pcw = TypeSystemService.LoadProject(project); TypeSystemService.ForceUpdate(pcw); pcw.ReconnectAssemblyReferences(); sev = new TestViewContent(); sev.Project = project; sev.ContentName = file; sev.Text = editorText; sev.CursorPosition = cursorPosition; var tww = new TestWorkbenchWindow(); tww.ViewContent = sev; var doc = new Document(tww); var parser = new RazorTestingParser { Doc = doc }; var parsedDoc = parser.Parse(false, sev.ContentName, new StringReader(parsedText), project); return(new RazorTestingEditorExtension(doc, parsedDoc as RazorCSharpParsedDocument, isInCSharpContext)); }
static AspNetTestingEditorExtension CreateEditor (string text, string extension, out string editorText, out TestViewContent sev) { string parsedText; int cursorPosition = text.IndexOf ('$'); int endPos = text.IndexOf ('$', cursorPosition + 1); if (endPos == -1) parsedText = editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1); else { parsedText = text.Substring (0, cursorPosition) + new string (' ', endPos - cursorPosition) + text.Substring (endPos + 1); editorText = text.Substring (0, cursorPosition) + text.Substring (cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring (endPos + 1); cursorPosition = endPos - 1; } var project = new AspNetAppProject ("C#"); project.References.Add (new ProjectReference (ReferenceType.Package, "System")); project.References.Add (new ProjectReference (ReferenceType.Package, "System.Web")); project.FileName = UnitTests.TestBase.GetTempFile (".csproj"); string file = UnitTests.TestBase.GetTempFile (extension); project.AddFile (file); var pcw = TypeSystemService.LoadProject (project); TypeSystemService.ForceUpdate (pcw); pcw.ReconnectAssemblyReferences (); sev = new TestViewContent (); sev.Project = project; sev.ContentName = file; sev.Text = editorText; sev.CursorPosition = cursorPosition; var tww = new TestWorkbenchWindow (); tww.ViewContent = sev; var doc = new TestDocument (tww); doc.Editor.Document.FileName = sev.ContentName; var parser = new AspNetParser (); var parsedDoc = (AspNetParsedDocument) parser.Parse (false, sev.ContentName, new StringReader (parsedText), project); doc.HiddenParsedDocument = parsedDoc; return new AspNetTestingEditorExtension (doc); }
public static void AddView(AspNetAppProject project, string path, string name) { var provider = project.LanguageBinding.GetCodeDomProvider(); if (provider == null) { throw new InvalidOperationException("Project language has null CodeDOM provider"); } string outputFile = null; MvcTextTemplateHost host = null; AddViewDialog dialog = null; try { dialog = new AddViewDialog(project); dialog.ViewName = name; bool fileGood = false; while (!fileGood) { var resp = (Gtk.ResponseType)MessageService.RunCustomDialog(dialog); dialog.Hide(); if (resp != Gtk.ResponseType.Ok || !dialog.IsValid()) { return; } string ext = ".cshtml"; if (dialog.ActiveViewEngine == "Aspx") { ext = dialog.IsPartialView ? ".ascx" : ".aspx"; } if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); } outputFile = System.IO.Path.Combine(path, dialog.ViewName) + ext; if (System.IO.File.Exists(outputFile)) { fileGood = MessageService.AskQuestion("Overwrite file?", String.Format("The file '{0}' already exists.\n", dialog.ViewName) + "Would you like to overwrite it?", AlertButton.OverwriteFile, AlertButton.Cancel) != AlertButton.Cancel; } else { break; } } host = new MvcTextTemplateHost { LanguageExtension = provider.FileExtension, ItemName = dialog.ViewName, ViewDataTypeString = "" }; if (dialog.HasMaster) { host.IsViewContentPage = true; host.ContentPlaceholder = dialog.PrimaryPlaceHolder; host.MasterPage = dialog.MasterFile; host.ContentPlaceHolders = dialog.ContentPlaceHolders; } else if (dialog.IsPartialView) { host.IsViewUserControl = true; } else { host.IsViewPage = true; } if (dialog.IsStronglyTyped) { host.ViewDataTypeString = dialog.ViewDataTypeString; } host.ProcessTemplate(dialog.TemplateFile, outputFile); MonoDevelop.TextTemplating.TextTemplatingService.ShowTemplateHostErrors(host.Errors); } finally { if (host != null) { host.Dispose(); } if (dialog != null) { dialog.Destroy(); dialog.Dispose(); } } if (System.IO.File.Exists(outputFile)) { project.AddFile(outputFile); IdeApp.ProjectOperations.Save(project); } }
public static CompletionDataList CreateProvider(string text, string extension, bool isCtrlSpace) { string parsedText; string editorText; int cursorPosition = text.IndexOf('$'); int endPos = text.IndexOf('$', cursorPosition + 1); if (endPos == -1) { parsedText = editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1); } else { parsedText = text.Substring(0, cursorPosition) + new string (' ', endPos - cursorPosition) + text.Substring(endPos + 1); editorText = text.Substring(0, cursorPosition) + text.Substring(cursorPosition + 1, endPos - cursorPosition - 1) + text.Substring(endPos + 1); cursorPosition = endPos - 1; } var tww = new MonoDevelop.CSharpBinding.Tests.TestWorkbenchWindow(); var sev = new MonoDevelop.CSharpBinding.Tests.TestViewContent(); var project = new AspNetAppProject("C#"); project.FileName = UnitTests.TestBase.GetTempFile(".csproj"); string file = UnitTests.TestBase.GetTempFile(extension); project.AddFile(file); ProjectDomService.Load(project); ProjectDom dom = ProjectDomService.GetProjectDom(project); dom.ForceUpdate(true); ProjectDomService.Parse(project, file, delegate { return(parsedText); }); ProjectDomService.Parse(project, file, delegate { return(parsedText); }); sev.Project = project; sev.ContentName = file; sev.Text = editorText; sev.CursorPosition = cursorPosition; tww.ViewContent = sev; var doc = new MonoDevelop.Ide.Gui.Document(tww); doc.ParsedDocument = new MonoDevelop.AspNet.Parser.AspNetParser().Parse(null, sev.ContentName, parsedText); foreach (var e in doc.ParsedDocument.Errors) { Console.WriteLine(e); } var textEditorCompletion = new MonoDevelop.AspNet.Gui.AspNetEditorExtension(); Initialize(textEditorCompletion, doc); int triggerWordLength = 1; CodeCompletionContext ctx = new CodeCompletionContext(); ctx.TriggerOffset = sev.CursorPosition; int line, column; sev.GetLineColumnFromPosition(sev.CursorPosition, out line, out column); ctx.TriggerLine = line; ctx.TriggerLineOffset = column - 1; if (isCtrlSpace) { return(textEditorCompletion.CodeCompletionCommand(ctx) as CompletionDataList); } else { return(textEditorCompletion.HandleCodeCompletion(ctx, editorText[cursorPosition - 1], ref triggerWordLength) as CompletionDataList); } }
public static void AddController(AspNetAppProject project, string path, string name) { var provider = project.LanguageBinding.GetCodeDomProvider(); if (provider == null) { throw new InvalidOperationException("Project language has null CodeDOM provider"); } string outputFile = null; MvcTextTemplateHost host = null; AddControllerDialog dialog = null; try { dialog = new AddControllerDialog(project); if (!String.IsNullOrEmpty(name)) { dialog.ControllerName = name; } bool fileGood = false; while (!fileGood) { var resp = (Gtk.ResponseType)MessageService.RunCustomDialog(dialog); dialog.Hide(); if (resp != Gtk.ResponseType.Ok || !dialog.IsValid()) { return; } outputFile = System.IO.Path.Combine(path, dialog.ControllerName) + ".cs"; if (System.IO.File.Exists(outputFile)) { fileGood = MessageService.AskQuestion("Overwrite file?", String.Format("The file '{0}' already exists.\n", dialog.ControllerName) + "Would you like to overwrite it?", AlertButton.OverwriteFile, AlertButton.Cancel) != AlertButton.Cancel; } else { break; } } host = new MvcTextTemplateHost { LanguageExtension = provider.FileExtension, ItemName = dialog.ControllerName, NameSpace = project.DefaultNamespace + ".Controllers" }; host.ProcessTemplate(dialog.TemplateFile, outputFile); MonoDevelop.TextTemplating.TextTemplatingService.ShowTemplateHostErrors(host.Errors); } finally { if (host != null) { host.Dispose(); } if (dialog != null) { dialog.Destroy(); } } if (System.IO.File.Exists(outputFile)) { project.AddFile(outputFile); IdeApp.ProjectOperations.Save(project); } }