Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/*
*/
using System;
using System.IO;
using System.Linq;
using System.Threading.Tasks;
using AppKit;
Expand All @@ -9,6 +10,7 @@
using FigmaSharp.Controls.Cocoa.Services;
using FigmaSharp.Helpers;
using FigmaSharp.Models;
using MonoDevelop.Core;
using MonoDevelop.Figma.Services;
using MonoDevelop.Ide;
using MonoDevelop.Projects;
Expand Down Expand Up @@ -120,12 +122,43 @@ async Task GenerateBundle (string fileId, FigmaFileVersion version, string names
await currentProject.AddFigmaBundleViewAsync (figmaBundleView, savesInProject: false);
}

CopyCodeTemplates(currentBundle, namesSpace);

await IdeApp.ProjectOperations.SaveAsync(currentProject);

IdeApp.Workbench.StatusBar.EndProgress ();
IdeApp.Workbench.StatusBar.AutoPulse = false;
}

void CopyCodeTemplates(FigmaBundle bundle, string namesSpace)
{
FilePath assemblyLocation = typeof(FigmaPackageWindow).Assembly.Location;
FilePath templateFileName = assemblyLocation.ParentDirectory.Combine("Templates", "Resources.template.cs");

FilePath destinationFileName = bundle.ResourcesDirectoryPath;
destinationFileName = destinationFileName.Combine("Resources.cs");

if (currentProject.PathExistsInProject(destinationFileName))
{
LoggingService.LogInfo("Resources.template.cs file already exists in project");
return;
}

if (File.Exists(destinationFileName))
{
LoggingService.LogInfo("Resources.template.cs file already exists not replacing");
return;
}

string text = File.ReadAllText(templateFileName);
text = text.Replace("NAMESPACE", namesSpace);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we could change this key to something more unique like: {{NAMESPACE}}


File.WriteAllText(destinationFileName, text);

var projectFile = new ProjectFile(destinationFileName, BuildAction.Compile);
currentProject.AddFile(projectFile);
}

private void CancelButton_Activated (object sender, EventArgs e)
{
this.Close ();
Expand Down
4 changes: 4 additions & 0 deletions tools/MonoDevelop.Figma/MonoDevelop.Figma.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@
<ItemGroup>
<None Include=".figma\ea4pU30ht61lUJXcr0TFIF\manifest.json" />
<None Include=".figma\ea4pU30ht61lUJXcr0TFIF\document.figma" />
<None Include="..\..\FigmaSharp.Controls\FigmaSharp.Controls.Cocoa\Converters\Templates\Resources.template.cs">
<Link>Templates\Resources.template.cs</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<BundleResource Include=".figma\ea4pU30ht61lUJXcr0TFIF\Resources\motivation.png" />
Expand Down
1 change: 1 addition & 0 deletions tools/MonoDevelop.Figma/Properties/Manifest.addin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<Import assembly="FigmaSharp.Cocoa.dll" />
<Import assembly="FigmaSharp.Controls.dll" />
<Import assembly="FigmaSharp.Controls.Cocoa.dll" />
<Import file="Templates/Resource.template.cs" />
</Runtime>
<Extension path="/MonoDevelop/Ide/StartupHandlers">
<Class class="MonoDevelop.Figma.Commands.FigmaInitCommand"/>
Expand Down