public override ParsedDocument Parse(bool storeAst, string fileName, System.IO.TextReader content, Projects.Project project = null) { currentDocument = openDocuments.FirstOrDefault(d => d != null && d.FileName == fileName); // We need document and project to be loaded to correctly initialize Razor Host. this.project = project as DotNetProject; if (currentDocument == null && !TryAddDocument(fileName)) { return(new RazorCSharpParsedDocument(fileName, new RazorCSharpPageInfo())); } this.aspProject = project as AspMvcProject; EnsureParserInitializedFor(fileName); var errors = new List <Error> (); using (var source = new SeekableTextReader(content)) { var textChange = CreateTextChange(source); var parseResult = editorParser.CheckForStructureChanges(textChange); if (parseResult == PartialParseResult.Rejected) { parseComplete.WaitOne(); if (!capturedArgs.GeneratorResults.Success) { GetRazorErrors(errors); } } } ParseHtmlDocument(errors); CreateCSharpParsedDocument(); ClearLastChange(); RazorHostKind kind = RazorHostKind.WebPage; if (editorParser.Host is WebCodeRazorHost) { kind = RazorHostKind.WebCode; } else if (editorParser.Host is MonoDevelop.RazorGenerator.RazorHost) { kind = RazorHostKind.Template; } var pageInfo = new RazorCSharpPageInfo() { HtmlRoot = htmlParsedDocument, GeneratorResults = capturedArgs.GeneratorResults, Spans = editorParser.CurrentParseTree.Flatten(), CSharpParsedFile = parsedCodeFile, CSharpCode = csharpCode, Errors = errors, FoldingRegions = GetFoldingRegions(), Comments = comments, Compilation = CreateCompilation(), HostKind = kind, }; return(new RazorCSharpParsedDocument(fileName, pageInfo)); }
public AddViewDialog(AspMvcProject project) { this.project = project; this.Build(); provider = project.LanguageBinding.GetCodeDomProvider(); var viewEngines = GetProperViewEngines(); loadedTemplateList = new Dictionary <string, IList <string> > (); foreach (var engine in viewEngines) { viewEngineCombo.AppendText(engine); loadedTemplateList[engine] = project.GetCodeTemplates("AddView", engine); } viewEngineCombo.Active = 0; InitializeTemplateStore(loadedTemplateList); ContentPlaceHolders = new List <string> (); string siteMaster = project.VirtualToLocalPath("~/Views/Shared/Site.master", null); if (project.Files.GetFile(siteMaster) != null) { masterEntry.Text = "~/Views/Shared/Site.master"; } primaryPlaceholderCombo.Model = primaryPlaceholderStore; UpdateTypePanelSensitivity(null, null); UpdateMasterPanelSensitivity(null, null); Validate(); }
public AddViewDialog (AspMvcProject project) { this.project = project; this.Build (); provider = project.LanguageBinding.GetCodeDomProvider (); var viewEngines = GetProperViewEngines (); loadedTemplateList = new Dictionary<string, IList<string>> (); foreach (var engine in viewEngines) { viewEngineCombo.AppendText (engine); loadedTemplateList[engine] = project.GetCodeTemplates ("AddView", engine); } viewEngineCombo.Active = 0; InitializeTemplateStore (loadedTemplateList); ContentPlaceHolders = new List<string> (); string siteMaster = project.VirtualToLocalPath ("~/Views/Shared/Site.master", null); if (project.Files.GetFile (siteMaster) != null) masterEntry.Text = "~/Views/Shared/Site.master"; primaryPlaceholderCombo.Model = primaryPlaceholderStore; UpdateTypePanelSensitivity (null, null); UpdateMasterPanelSensitivity (null, null); Validate (); }
public AddControllerDialog (AspMvcProject project) { this.Build (); provider = project.LanguageBinding.GetCodeDomProvider (); loadedTemplateList = project.GetCodeTemplates ("AddController"); bool foundEmptyTemplate = false; int templateIndex = 0; foreach (string file in loadedTemplateList) { string name = System.IO.Path.GetFileNameWithoutExtension (file); templateCombo.AppendText (name); if (!foundEmptyTemplate) { if (name == "Empty") { templateCombo.Active = templateIndex; foundEmptyTemplate = true; } else templateIndex++; } } if (!foundEmptyTemplate) throw new Exception ("The Empty.tt template is missing."); nameEntry.Text = "Controller"; nameEntry.Position = 0; Validate (); }
public AddViewDialog(AspMvcProject project) { this.project = project; this.Build(); dataClassCombo = new DropDownBox(); int w, h; Gtk.Icon.SizeLookup(Gtk.IconSize.Menu, out w, out h); dataClassCombo.DefaultIconHeight = Math.Max(h, 16); dataClassCombo.DefaultIconWidth = Math.Max(w, 16); dataClassAlignment.Add(dataClassCombo); dataClassAlignment.QueueResize(); dataClassCombo.ShowAll(); provider = project.LanguageBinding.GetCodeDomProvider(); ContentPlaceHolders = new List <string> (); string siteMaster = project.VirtualToLocalPath("~/Views/Shared/Site.master", null); if (project.Files.GetFile(siteMaster) != null) { masterEntry.Text = "~/Views/Shared/Site.master"; } loadedTemplateList = project.GetCodeTemplates("AddView"); bool foundEmptyTemplate = false; int templateIndex = 0; foreach (string file in loadedTemplateList) { string name = PP.GetFileNameWithoutExtension(file); templateCombo.AppendText(name); if (!foundEmptyTemplate) { if (name == "Empty") { templateCombo.Active = templateIndex; foundEmptyTemplate = true; } else { templateIndex++; } } } if (!foundEmptyTemplate) { throw new Exception("The Empty.tt template is missing."); } primaryPlaceholderCombo.Model = primaryPlaceholderStore; UpdateTypePanelSensitivity(null, null); UpdateMasterPanelSensitivity(null, null); Validate(); }
public static void AddController(AspMvcProject 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) { Gtk.ResponseType 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); } }
public AddViewDialog (AspMvcProject project) { this.project = project; this.Build (); dataClassCombo = new MonoDevelop.SourceEditor.DropDownBox (); int w, h; Gtk.Icon.SizeLookup (Gtk.IconSize.Menu, out w, out h); dataClassCombo.DefaultIconHeight = Math.Max (h, 16); dataClassCombo.DefaultIconWidth = Math.Max (w, 16); dataClassAlignment.Add (dataClassCombo); dataClassAlignment.QueueResize (); dataClassCombo.ShowAll (); provider = project.LanguageBinding.GetCodeDomProvider (); ContentPlaceHolders = new List<string> (); string siteMaster = project.VirtualToLocalPath ("~/Views/Shared/Site.master", null); if (project.Files.GetFile (siteMaster) != null) masterEntry.Text = "~/Views/Shared/Site.master"; loadedTemplateList = project.GetCodeTemplates ("AddView"); bool foundEmptyTemplate = false; int templateIndex = 0; foreach (string file in loadedTemplateList) { string name = PP.GetFileNameWithoutExtension (file); templateCombo.AppendText (name); if (!foundEmptyTemplate){ if (name == "Empty") { templateCombo.Active = templateIndex; foundEmptyTemplate = true; } else templateIndex++; } } if (!foundEmptyTemplate) throw new Exception ("The Empty.tt template is missing."); primaryPlaceholderCombo.Model = primaryPlaceholderStore; UpdateTypePanelSensitivity (null, null); UpdateMasterPanelSensitivity (null, null); Validate (); }
public override ParsedDocument Parse (bool storeAst, string fileName, System.IO.TextReader content, Projects.Project project = null) { currentDocument = openDocuments.FirstOrDefault (d => d.FileName == fileName); // We need document and project to be loaded to correctly initialize Razor Host. if (project == null || (currentDocument == null && !TryAddDocument (fileName))) return new RazorCSharpParsedDocument (fileName, new RazorCSharpPageInfo ()); this.project = project as AspMvcProject; EnsureParserInitializedFor (fileName); var errors = new List<Error> (); using (var source = new SeekableTextReader (content)) { var textChange = CreateTextChange (source); var parseResult = editorParser.CheckForStructureChanges (textChange); if (parseResult == PartialParseResult.Rejected) { parseComplete.WaitOne (); if (!capturedArgs.GeneratorResults.Success) GetRazorErrors (errors); } } CreateHtmlDocument (); GetHtmlErrors (errors); CreateCSharpParsedDocument (); ClearLastChange (); var pageInfo = new RazorCSharpPageInfo () { HtmlRoot = htmlParsedDocument, GeneratorResults = capturedArgs.GeneratorResults, Spans = editorParser.CurrentParseTree.Flatten (), CSharpParsedFile = parsedCodeFile, CSharpCode = csharpCode, Errors = errors, FoldingRegions = GetFoldingRegions (), Comments = comments, Compilation = CreateCompilation () }; return new RazorCSharpParsedDocument (fileName, pageInfo); }
public AddControllerDialog(AspMvcProject project) { this.project = project; this.Build(); provider = project.LanguageBinding.GetCodeDomProvider(); loadedTemplateList = project.GetCodeTemplates("AddController"); bool foundEmptyTemplate = false; int templateIndex = 0; foreach (string file in loadedTemplateList) { string name = System.IO.Path.GetFileNameWithoutExtension(file); templateCombo.AppendText(name); if (!foundEmptyTemplate) { if (name == "Empty") { templateCombo.Active = templateIndex; foundEmptyTemplate = true; } else { templateIndex++; } } } if (!foundEmptyTemplate) { throw new Exception("The Empty.tt template is missing."); } nameEntry.Text = "Controller"; nameEntry.Position = 0; Validate(); }
public void AddController() { AspMvcProject project = CurrentNode.GetParentDataItem(typeof(AspMvcProject), true) as AspMvcProject; if (project == null) { return; } object currentItem = CurrentNode.DataItem; ProjectFolder folder = CurrentNode.GetParentDataItem(typeof(ProjectFolder), true) as ProjectFolder; string path = folder != null ? folder.Path : project.BaseDirectory; AddController(project, path, null); ITreeNavigator nav = Tree.GetNodeAtObject(currentItem); if (nav != null) { nav.Expanded = true; } }
//adapted from GtkCore void AddFile(string id) { AspMvcProject project = CurrentNode.GetParentDataItem(typeof(AspMvcProject), true) as AspMvcProject; if (project == null) { return; } object currentItem = CurrentNode.DataItem; ProjectFolder folder = CurrentNode.GetParentDataItem(typeof(ProjectFolder), true) as ProjectFolder; string path = folder != null? folder.Path : project.BaseDirectory; IdeApp.ProjectOperations.CreateProjectFile(project, path, id); IdeApp.ProjectOperations.Save(project); ITreeNavigator nav = Tree.GetNodeAtObject(currentItem); if (nav != null) { nav.Expanded = true; } }
public static void AddController(AspMvcProject 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); } }
public static void AddView(AspMvcProject 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(); } } if (System.IO.File.Exists(outputFile)) { project.AddFile(outputFile); IdeApp.ProjectOperations.Save(project); } }
public static void AddView (AspMvcProject 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; MonoDevelop.TextTemplating.RecyclableAppDomain.Handle handle = null; AddViewDialog dialog = null; try { dialog = new AddViewDialog (project); dialog.ViewName = name; bool fileGood = false; while (!fileGood) { Gtk.ResponseType resp = (Gtk.ResponseType) MessageService.RunCustomDialog (dialog); dialog.Hide (); if (resp != Gtk.ResponseType.Ok || ! dialog.IsValid ()) return; outputFile = System.IO.Path.Combine (path, dialog.ViewName) + (dialog.IsPartialView? ".ascx" : ".aspx"); if (System.IO.File.Exists (outputFile)) { fileGood = MessageService.AskQuestion ("Overwrite file?", "The file '{0}' already exists.\n" + "Would you like to overwrite it?", AlertButton.OverwriteFile, AlertButton.Cancel) != AlertButton.Cancel; } else break; } handle = MonoDevelop.TextTemplating.TextTemplatingService.GetTemplatingDomain (); handle.LoadAssembly (typeof (MvcTextTemplateHost).Assembly); host = MvcTextTemplateHost.Create (handle.Domain); host.LanguageExtension = provider.FileExtension; host.ViewDataTypeGenericString = ""; 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) { //TODO: use dialog.ViewDataType to construct // host.ViewDataTypeGenericString and host.ViewDataType } host.ProcessTemplate (dialog.TemplateFile, outputFile); MonoDevelop.TextTemplating.TextTemplatingService.ShowTemplateHostErrors (host.Errors); } finally { if (handle != null) handle.Dispose (); if (dialog != null) dialog.Destroy (); } if (System.IO.File.Exists (outputFile)) { project.AddFile (outputFile); IdeApp.ProjectOperations.Save (project); } }
public static void AddView (AspMvcProject 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) { Gtk.ResponseType 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 (); } if (System.IO.File.Exists (outputFile)) { project.AddFile (outputFile); IdeApp.ProjectOperations.Save (project); } }
public static void AddView(AspMvcProject 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; Mono.TextTemplating.TemplatingAppDomainRecycler.Handle handle = null; AddViewDialog dialog = null; try { dialog = new AddViewDialog(project); dialog.ViewName = name; bool fileGood = false; while (!fileGood) { Gtk.ResponseType resp = (Gtk.ResponseType)MessageService.RunCustomDialog(dialog); dialog.Hide(); if (resp != Gtk.ResponseType.Ok || !dialog.IsValid()) { return; } outputFile = System.IO.Path.Combine(path, dialog.ViewName) + (dialog.IsPartialView? ".ascx" : ".aspx"); if (System.IO.File.Exists(outputFile)) { fileGood = MessageService.AskQuestion("Overwrite file?", "The file '{0}' already exists.\n" + "Would you like to overwrite it?", AlertButton.OverwriteFile, AlertButton.Cancel) != AlertButton.Cancel; } else { break; } } handle = MonoDevelop.TextTemplating.TextTemplatingService.GetTemplatingDomain(); handle.AddAssembly(typeof(MvcTextTemplateHost).Assembly); host = MvcTextTemplateHost.Create(handle.Domain); host.LanguageExtension = provider.FileExtension; host.ViewDataTypeGenericString = ""; 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) { //TODO: use dialog.ViewDataType to construct // host.ViewDataTypeGenericString and host.ViewDataType } host.ProcessTemplate(dialog.TemplateFile, outputFile); MonoDevelop.TextTemplating.TextTemplatingService.ShowTemplateHostErrors(host.Errors); } finally { if (handle != null) { handle.Dispose(); } if (dialog != null) { dialog.Destroy(); } } if (System.IO.File.Exists(outputFile)) { project.AddFile(outputFile); IdeApp.ProjectOperations.Save(project); } }