public ProjectEntry(Project project) { Project = project; Name = project.Name; TypeGuid = project.ProjectDescriptor.SolutionNodeGuid; ObjectGuid = project.ProjectGuid; FilePath = project.FilePath; }
/// <summary> /// Creates a file from the current template. /// </summary> /// <param name="fileService">The file service the template should use to create files.</param> /// <param name="parentProject">The project that will hold the new created file. This value can be null if ProjectRequired is set to false.</param> /// <param name="filePath">The file path to save the file to.</param> /// <returns>A template result holding information about the created files.</returns> public TemplateResult CreateFile(IFileService fileService, Project parentProject, FilePath filePath) { if (fileService == null) throw new ArgumentNullException("fileService"); if (parentProject == null && ProjectRequired) throw new ArgumentNullException("parentProject"); var result = CreateFileCore(fileService, parentProject, filePath); OnFileCreated(new TemplateResultEventArgs(result)); return result; }
/// <inheritdoc /> protected override TemplateResult CreateFileCore(IFileService fileService, Project parentProject, FilePath filePath) { string @namespace = "MyNamespace"; if (parentProject != null && parentProject is NetProject) { @namespace = (parentProject as NetProject).RootNamespace; var relativePath = filePath.ParentDirectory.GetRelativePath(parentProject); if (!string.IsNullOrEmpty(relativePath)) @namespace += "." + relativePath.Replace(Path.DirectorySeparatorChar, '.'); } var language = (LanguageDescriptor.GetLanguageByPath(filePath) as NetLanguageDescriptor); var codeProvider = language.CodeProvider; var fileName = filePath.FileName; using (var stringWriter = new StringWriter()) { // generate source using (var writer = new IndentedTextWriter(stringWriter)) { codeProvider.GenerateCodeFromCompileUnit(CompileUnit, writer, new CodeGeneratorOptions() { BlankLinesBetweenMembers = true, BracingStyle = "C", }); } string source = stringWriter.ToString(); // replace auto generated message. var match = Regex.Match(source, string.Format("{0}[^\r\n]+\r\n[^{0}]", language.CommentPrefix)); if (match.Success) { source = source.Remove(0, match.Index + match.Length); } // VbCodeProvider adds two option statements which should be removed as well because they are specified by default in the project settings. if (language.Name == LanguageDescriptor.GetLanguage<VisualBasicLanguage>().Name) { match = _vbOptionsRegex.Match(source); if (match.Success) source = source.Remove(0, match.Index + match.Length); } // create file instance. source = source.Replace("%folder%", @namespace) .Replace("%file%", (string.IsNullOrEmpty(ObjectName) ? fileName : ObjectName)); var file = fileService.CreateFile(filePath, Encoding.UTF8.GetBytes(source)); return new TemplateResult(new CreatedFile(file, ExtensionToUse)); } }
public DirectoryNode(Project project, FilePath path, IconProvider iconProvider) : base(path) { if (project != null) { _project = project; project.ProjectFiles.InsertedItem += ProjectFiles_InsertedItem; project.ProjectFiles.RemovedItem += ProjectFiles_RemovedItem; } AddStub(); ImageIndex = SelectedImageIndex = (_iconProvider = iconProvider).GetImageIndex(new DirectoryInfo(path.FileName)); }
protected override TemplateResult CreateFileCore(IFileService fileService, Project parentProject, FilePath filePath) { string directory = filePath.ParentDirectory.FullPath; string fileName = filePath.FileName; string extension = filePath.Extension; var classFileResult = ClassFile.CreateFile(fileService, parentProject, filePath); var designerFileResult = DesignerClassFile.CreateFile(fileService, parentProject, new FilePath(directory, DesignerClassFile.Name.Replace("%file%", fileName) + extension)); var classFile = classFileResult.CreatedFiles[0].File as OpenedFile; var designerFile = designerFileResult.CreatedFiles[0].File as OpenedFile; designerFile.Dependencies.Add(classFile.FilePath.GetRelativePath(directory)); designerFile.SetContents(designerFile.GetContentsAsString().Replace("%file%", fileName)); designerFileResult.CreatedFiles[0].ExtensionToUse = ExtensionToUse; return new TemplateResult(classFileResult, designerFileResult); }
public CreateFileDialog(Project parentProject) { _parentProject = parentProject; InitializeComponent(); if (parentProject != null) { Text += " - " + parentProject.Name; } SetupMuiComponents(); if (parentProject != null) directoryTextBox.Text = parentProject.ProjectDirectory; List<TreeNode> rootNodes = new List<TreeNode>(); foreach (var entry in LanguageDescriptor.RegisteredLanguages) { if (entry.Templates.FirstOrDefault(x => x is FileTemplate) != null) { var node = GetLanguageOrderNode(rootNodes, entry.LanguageOrder); node.Nodes.Add(new TreeNode(entry.Name) { Tag = entry }); node.Expand(); } } languagesTreeView.Nodes.AddRange(rootNodes.ToArray()); templatesListView.SmallImageList = new ImageList() { ColorDepth = ColorDepth.Depth32Bit, ImageSize = new Size(24, 24), }; templatesListView.LargeImageList = new ImageList() { ColorDepth = ColorDepth.Depth32Bit, ImageSize = new Size(32, 32), }; }
public ProjectEventArgs(Project file) { TargetProject = file; }
/// <inheritdoc /> protected override TemplateResult CreateFileCore(IFileService fileService, Project parentProject, FilePath filePath) { var file = fileService.CreateFile(filePath, Encoding.UTF8.GetBytes(BaseSource)); Action(file); return new TemplateResult(new CreatedFile(file, ExtensionToUse)); }
public static void UserCreateFile(LiteExtensionHost extensionHost, Project currentProject, string directory) { using (var dlg = new CreateFileDialog(currentProject)) { if (!string.IsNullOrEmpty(directory)) { dlg.Directory = directory; } if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK) { var result = (dlg.Template as FileTemplate).CreateFile(extensionHost.FileService, currentProject, new FilePath(dlg.FileName)); foreach (var createdFile in result.CreatedFiles) { var openedFile = createdFile.File as OpenedFile; openedFile.Save(extensionHost.CreateOrGetReporter("Build")); if (currentProject != null) { currentProject.ProjectFiles.Add(new ProjectFileEntry(openedFile)); } createdFile.ExtensionToUse.OpenFile(openedFile); } } } }
/// <summary> /// Loads the underlying project. /// </summary> /// <param name = "reporter">The progress reporter to use for logging</param> public override void Load(IProgressReporter reporter) { foreach (var node in Nodes) node.Load(reporter); try { Project = Project.OpenProject(FilePath.FullPath); OnLoadComplete(new SolutionNodeLoadEventArgs()); } catch (Exception ex) { OnLoadComplete(new SolutionNodeLoadEventArgs(ex)); } }
public ProjectTemplateResult(Project project, params TemplateResult[] results) : base(results) { Project = project; }
/// <summary> /// Creates a file from the current template. /// </summary> /// <param name="fileService">The file service the template should use to create files.</param> /// <param name="parentProject">The project that will hold the new created file.</param> /// <param name="filePath">The file path to save the file to.</param> /// <returns>A template result holding information about the created files.</returns> protected abstract TemplateResult CreateFileCore(IFileService fileService, Project parentProject, FilePath filePath);