|
1 | 1 | /* |
2 | 2 | */ |
3 | 3 | using System; |
| 4 | +using System.IO; |
4 | 5 | using System.Linq; |
5 | 6 | using System.Threading.Tasks; |
6 | 7 | using AppKit; |
|
9 | 10 | using FigmaSharp.Controls.Cocoa.Services; |
10 | 11 | using FigmaSharp.Helpers; |
11 | 12 | using FigmaSharp.Models; |
| 13 | +using MonoDevelop.Core; |
12 | 14 | using MonoDevelop.Figma.Services; |
13 | 15 | using MonoDevelop.Ide; |
14 | 16 | using MonoDevelop.Projects; |
@@ -120,12 +122,43 @@ async Task GenerateBundle (string fileId, FigmaFileVersion version, string names |
120 | 122 | await currentProject.AddFigmaBundleViewAsync (figmaBundleView, savesInProject: false); |
121 | 123 | } |
122 | 124 |
|
| 125 | + CopyCodeTemplates(currentBundle, namesSpace); |
| 126 | + |
123 | 127 | await IdeApp.ProjectOperations.SaveAsync(currentProject); |
124 | 128 |
|
125 | 129 | IdeApp.Workbench.StatusBar.EndProgress (); |
126 | 130 | IdeApp.Workbench.StatusBar.AutoPulse = false; |
127 | 131 | } |
128 | 132 |
|
| 133 | + void CopyCodeTemplates(FigmaBundle bundle, string namesSpace) |
| 134 | + { |
| 135 | + FilePath assemblyLocation = typeof(FigmaPackageWindow).Assembly.Location; |
| 136 | + FilePath templateFileName = assemblyLocation.ParentDirectory.Combine("Templates", "Resources.template.cs"); |
| 137 | + |
| 138 | + FilePath destinationFileName = bundle.ResourcesDirectoryPath; |
| 139 | + destinationFileName = destinationFileName.Combine("Resources.cs"); |
| 140 | + |
| 141 | + if (currentProject.PathExistsInProject(destinationFileName)) |
| 142 | + { |
| 143 | + LoggingService.LogInfo("Resources.template.cs file already exists in project"); |
| 144 | + return; |
| 145 | + } |
| 146 | + |
| 147 | + if (File.Exists(destinationFileName)) |
| 148 | + { |
| 149 | + LoggingService.LogInfo("Resources.template.cs file already exists not replacing"); |
| 150 | + return; |
| 151 | + } |
| 152 | + |
| 153 | + string text = File.ReadAllText(templateFileName); |
| 154 | + text = text.Replace("NAMESPACE", namesSpace); |
| 155 | + |
| 156 | + File.WriteAllText(destinationFileName, text); |
| 157 | + |
| 158 | + var projectFile = new ProjectFile(destinationFileName, BuildAction.Compile); |
| 159 | + currentProject.AddFile(projectFile); |
| 160 | + } |
| 161 | + |
129 | 162 | private void CancelButton_Activated (object sender, EventArgs e) |
130 | 163 | { |
131 | 164 | this.Close (); |
|
0 commit comments