From 188e3a10c275196f3e6e483312bffd2da39e518d Mon Sep 17 00:00:00 2001 From: Matt Ward Date: Fri, 26 Mar 2021 18:06:54 +0000 Subject: [PATCH] [Extension] Generate Resources.cs file in project Use Resources.template.cs and generate a Resources.cs file in the project's Figma Resources directory. --- .../Views/FigmaPackageWindow.cs | 33 +++++++++++++++++++ .../MonoDevelop.Figma.csproj | 4 +++ .../Properties/Manifest.addin.xml | 1 + 3 files changed, 38 insertions(+) diff --git a/tools/MonoDevelop.Figma/.figma/ea4pU30ht61lUJXcr0TFIF/Views/FigmaPackageWindow.cs b/tools/MonoDevelop.Figma/.figma/ea4pU30ht61lUJXcr0TFIF/Views/FigmaPackageWindow.cs index c2054071..19ade915 100644 --- a/tools/MonoDevelop.Figma/.figma/ea4pU30ht61lUJXcr0TFIF/Views/FigmaPackageWindow.cs +++ b/tools/MonoDevelop.Figma/.figma/ea4pU30ht61lUJXcr0TFIF/Views/FigmaPackageWindow.cs @@ -1,6 +1,7 @@ /* */ using System; +using System.IO; using System.Linq; using System.Threading.Tasks; using AppKit; @@ -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; @@ -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); + + File.WriteAllText(destinationFileName, text); + + var projectFile = new ProjectFile(destinationFileName, BuildAction.Compile); + currentProject.AddFile(projectFile); + } + private void CancelButton_Activated (object sender, EventArgs e) { this.Close (); diff --git a/tools/MonoDevelop.Figma/MonoDevelop.Figma.csproj b/tools/MonoDevelop.Figma/MonoDevelop.Figma.csproj index 252891ef..3300a27a 100644 --- a/tools/MonoDevelop.Figma/MonoDevelop.Figma.csproj +++ b/tools/MonoDevelop.Figma/MonoDevelop.Figma.csproj @@ -133,6 +133,10 @@ + + Templates\Resources.template.cs + PreserveNewest + diff --git a/tools/MonoDevelop.Figma/Properties/Manifest.addin.xml b/tools/MonoDevelop.Figma/Properties/Manifest.addin.xml index 8e87a2ae..8ae87aaa 100644 --- a/tools/MonoDevelop.Figma/Properties/Manifest.addin.xml +++ b/tools/MonoDevelop.Figma/Properties/Manifest.addin.xml @@ -5,6 +5,7 @@ +