Skip to content

Commit 188e3a1

Browse files
committed
[Extension] Generate Resources.cs file in project
Use Resources.template.cs and generate a Resources.cs file in the project's Figma Resources directory.
1 parent 8960755 commit 188e3a1

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

tools/MonoDevelop.Figma/.figma/ea4pU30ht61lUJXcr0TFIF/Views/FigmaPackageWindow.cs

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/*
22
*/
33
using System;
4+
using System.IO;
45
using System.Linq;
56
using System.Threading.Tasks;
67
using AppKit;
@@ -9,6 +10,7 @@
910
using FigmaSharp.Controls.Cocoa.Services;
1011
using FigmaSharp.Helpers;
1112
using FigmaSharp.Models;
13+
using MonoDevelop.Core;
1214
using MonoDevelop.Figma.Services;
1315
using MonoDevelop.Ide;
1416
using MonoDevelop.Projects;
@@ -120,12 +122,43 @@ async Task GenerateBundle (string fileId, FigmaFileVersion version, string names
120122
await currentProject.AddFigmaBundleViewAsync (figmaBundleView, savesInProject: false);
121123
}
122124

125+
CopyCodeTemplates(currentBundle, namesSpace);
126+
123127
await IdeApp.ProjectOperations.SaveAsync(currentProject);
124128

125129
IdeApp.Workbench.StatusBar.EndProgress ();
126130
IdeApp.Workbench.StatusBar.AutoPulse = false;
127131
}
128132

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+
129162
private void CancelButton_Activated (object sender, EventArgs e)
130163
{
131164
this.Close ();

tools/MonoDevelop.Figma/MonoDevelop.Figma.csproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@
133133
<ItemGroup>
134134
<None Include=".figma\ea4pU30ht61lUJXcr0TFIF\manifest.json" />
135135
<None Include=".figma\ea4pU30ht61lUJXcr0TFIF\document.figma" />
136+
<None Include="..\..\FigmaSharp.Controls\FigmaSharp.Controls.Cocoa\Converters\Templates\Resources.template.cs">
137+
<Link>Templates\Resources.template.cs</Link>
138+
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
139+
</None>
136140
</ItemGroup>
137141
<ItemGroup>
138142
<BundleResource Include=".figma\ea4pU30ht61lUJXcr0TFIF\Resources\motivation.png" />

tools/MonoDevelop.Figma/Properties/Manifest.addin.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<Import assembly="FigmaSharp.Cocoa.dll" />
66
<Import assembly="FigmaSharp.Controls.dll" />
77
<Import assembly="FigmaSharp.Controls.Cocoa.dll" />
8+
<Import file="Templates/Resource.template.cs" />
89
</Runtime>
910
<Extension path="/MonoDevelop/Ide/StartupHandlers">
1011
<Class class="MonoDevelop.Figma.Commands.FigmaInitCommand"/>

0 commit comments

Comments
 (0)