protected async override void OnRun() { if (IdeApp.ProjectOperations.CurrentSelectedItem is ProjectFolder currentFolder && currentFolder.IsDocumentDirectoryBundle()) { var bundle = FigmaBundle.FromDirectoryPath(currentFolder.Path.FullPath); if (bundle == null) { return; } var includeImages = true; using var monitor = IdeApp.Workbench.ProgressMonitors.GetFigmaProgressMonitor( $"Regenerating ‘{bundle.Manifest.DocumentTitle}’…", $"‘{bundle.Manifest.DocumentTitle}’ regenerated successfully"); await Task.Run(() => { //we need to ask to figma server to get nodes as demmand var fileProvider = new ControlFileNodeProvider(bundle.ResourcesDirectoryPath); fileProvider.Load(bundle.DocumentFilePath); bundle.Reload(); var codeRendererService = new NativeViewCodeService(fileProvider) { TranslationService = new Services.MonoDevelopTranslationService() }; bundle.SaveAll(includeImages, fileProvider); }); await currentFolder.Project.IncludeBundleAsync(monitor, bundle, includeImages) .ConfigureAwait(true); } }
protected async override void OnRun() { if (IdeApp.ProjectOperations.CurrentSelectedItem is ProjectFolder currentFolder && currentFolder.IsDocumentDirectoryBundle()) { var bundle = FigmaBundle.FromDirectoryPath(currentFolder.Path.FullPath); if (bundle == null) { return; } var includeImages = true; IdeApp.Workbench.StatusBar.AutoPulse = true; IdeApp.Workbench.StatusBar.BeginProgress($"Regenerating ‘{bundle.Manifest.DocumentTitle}’…"); await Task.Run(() => { //we need to ask to figma server to get nodes as demmand var fileProvider = new FigmaLocalFileProvider(bundle.ResourcesDirectoryPath); fileProvider.Load(bundle.DocumentFilePath); bundle.Reload(); var codeRendererService = new NativeViewCodeService(fileProvider); bundle.SaveAll(includeImages); }); IdeApp.Workbench.StatusBar.EndProgress(); IdeApp.Workbench.StatusBar.AutoPulse = false; await currentFolder.Project.IncludeBundleAsync(bundle, includeImages) .ConfigureAwait(true); } }
public FigmaBundleViewBase GetBundleView(FigmaBundle bundle, string name, FigmaNode figmaNode) { //TODO: let's disable for now the special logic for about dialog. It needs a review //if (figmaNode.IsComponentContainer ()) { // return new FigmaContainerBundleWindow(bundle, name, figmaNode); //} if (figmaNode is IFigmaNodeContainer nodeContainer) { foreach (var figmaInstance in nodeContainer.children) { if (figmaInstance.IsWindowOfType(FigmaControlType.Window)) { return(new FigmaBundleWindow(bundle, name, figmaNode)); } if (figmaInstance.IsWindowOfType(FigmaControlType.WindowSheet)) { return(new FigmaBundleWindow(bundle, name, figmaNode)); } if (figmaInstance.IsWindowOfType(FigmaControlType.WindowPanel)) { return(new FigmaBundleWindow(bundle, name, figmaNode)); } } } return(new FigmaBundleView(bundle, name, figmaNode)); }
public FigmaBundleViewBase GetBundleView(FigmaBundle bundle, string name, FigmaNode figmaNode) { if (figmaNode.IsComponentContainer()) { return(new FigmaContainerBundleWindow(bundle, name, figmaNode)); } if (figmaNode is IFigmaNodeContainer nodeContainer) { foreach (var figmaInstance in nodeContainer.children) { if (figmaInstance.IsWindowOfType(FigmaControlType.Window)) { return(new FigmaBundleWindow(bundle, name, figmaNode)); } if (figmaInstance.IsWindowOfType(FigmaControlType.WindowSheet)) { return(new FigmaBundleWindow(bundle, name, figmaNode)); } if (figmaInstance.IsWindowOfType(FigmaControlType.WindowPanel)) { return(new FigmaBundleWindow(bundle, name, figmaNode)); } } } return(new FigmaBundleView(bundle, name, figmaNode)); }
internal async void Load(FigmaBundle bundle, Projects.Project project) { this.mainBundle = bundle; this.project = project; bundlePopUp.RemoveAllItems(); bundlePopUp.AddItem(bundle.Manifest.DocumentTitle); //loads current versions versionPopUp.RemoveAllItems(); versionPopUp.AddItem("Latest"); ShowLoading(true); EnableViews(false); var versionTask = Task.Run(() => { try { var query = new FigmaFileVersionQuery(bundle.FileId); var figmaFileVersions = FigmaSharp.AppContext.Api.GetFileVersions(query) .versions; var result = figmaFileVersions .GroupByCreatedAt() .ToArray(); return(result); } catch (Exception ex) { Console.WriteLine(ex); return(null); } }); var figmaDirectory = Path.GetDirectoryName(bundle.DirectoryPath); var currentProjectBundles = GetFromFigmaDirectory(figmaDirectory); versions = await versionTask; bundlePopUp.RemoveAllItems(); foreach (var figmaNode in currentProjectBundles) { bundlePopUp.AddItem(figmaNode.Manifest.DocumentTitle); } ShowLoading(false); EnableViews(true); if (versions != null && versions.Length > 0) { foreach (var version in versions) { versionMenu.AddItem(version); } } versionMenu.Generate(versionPopUp.Menu); //select current version var menu = versionMenu.GetMenuItem(bundle.Version); versionPopUp.SelectItem(menu); }
//TODO: Convert to Async public static IEnumerable <FigmaBundle> GetFigmaPackages(this Project sender) { var figmaFolder = sender.GetFigmaFolder(); foreach (var figmaProject in System.IO.Directory.GetDirectories(figmaFolder)) { yield return(FigmaBundle.FromDirectoryPath(figmaProject)); } }
static IEnumerable <FigmaBundle> GetFromFigmaDirectory(string directory) { foreach (var item in Directory.EnumerateDirectories(directory)) { var bundle = FigmaBundle.FromDirectoryPath(item); if (bundle != null) { yield return(bundle); } } }
private void CopyCSButton_Activated(object sender, EventArgs e) { if (currentSelectedNode == null) { return; } var className = currentSelectedNode.GetClassName(); var bundle = FigmaBundle.Empty("1234", null, string.Empty); var figmaBundleView = FigmaControlsContext.Current.GetBundleView(bundle, className, currentSelectedNode); var publicPartialClass = figmaBundleView.GetFigmaPartialDesignerClass(codeRenderer, translateStrings: translateButton.State == NSCellStateValue.On); var code = publicPartialClass.Generate(); CopyToLogView(code); }
private void CopyDesignerCSButton_Activated(object sender, EventArgs e) { if (currentSelectedNode == null) { return; } var bundle = FigmaBundle.Empty("1234", null, string.Empty); var className = currentSelectedNode.GetClassName(); var figmaBundleView = FigmaControlsContext.Current.GetBundleView(bundle, className, currentSelectedNode); var publicPartialClass = figmaBundleView.GetPublicPartialClass(); var code = publicPartialClass.Generate(); CopyToLogView(code); }
public static FigmaBundle CreateBundle(this Project project, string fileId, FigmaSharp.Models.FigmaFileVersion version, IFigmaFileProvider fileProvider, string namesSpace = null) { var figmaFolder = project.GetFigmaFolder(); if (!Directory.Exists(figmaFolder)) { Directory.CreateDirectory(figmaFolder); } //Bundle generation - We generate an empty bundle and store in the folder var fullBundlePath = Path.Combine(figmaFolder, fileId); var bundle = FigmaBundle.Empty(fileId, version, fullBundlePath, namesSpace); bundle.Reload(); return(bundle); }
protected override void OnRun() { var currentFolder = IdeApp.ProjectOperations.CurrentSelectedItem as ProjectFolder; if (currentFolder == null) { return; } var bundle = FigmaBundle.FromDirectoryPath(currentFolder.Path.FullPath); var figmaBundleWindow = new PackageUpdateWindow(); figmaBundleWindow.Load(bundle, currentFolder.Project); var currentIdeWindow = Components.Mac.GtkMacInterop.GetNSWindow(IdeApp.Workbench.RootWindow); currentIdeWindow.AddChildWindow(figmaBundleWindow, AppKit.NSWindowOrderingMode.Above); MessageService.PlaceDialog(figmaBundleWindow, MessageService.RootWindow); IdeServices.DesktopService.FocusWindow(figmaBundleWindow); }
public static async Task UpdateFigmaFilesAsync(this Project sender, IEnumerable <ProjectFile> projectFiles, FigmaBundle figmaBundle, FigmaFileVersion version, bool translateStrings) { var includeImages = true; var fileProvider = new FigmaRemoteFileProvider() { Version = version }; await fileProvider.LoadAsync(figmaBundle.FileId); Console.WriteLine($"[Done] Loaded Remote File provider for Version {version?.id ?? "Current"}"); var codeRendererService = new NativeViewCodeService(fileProvider); await Task.Run(() => { figmaBundle.Update(version, includeImages: includeImages); }); await sender.IncludeBundleAsync(figmaBundle, includeImages : includeImages); foreach (var designerFile in projectFiles) { if (designerFile.TryGetFigmaNode(fileProvider, out var figmaNode)) { var fileView = figmaBundle.GetFigmaFileView(figmaNode); fileView.GeneratePartialDesignerClass(codeRendererService, designerFile.FilePath.ParentDirectory, figmaBundle.Namespace, translateStrings); } } }
public static async Task IncludeBundleAsync(this Project currentProject, FigmaBundle bundle, bool includeImages = false, bool savesInProject = true) { Ide.IdeApp.Workbench.StatusBar.ShowMessage("Including files into current project…"); var figmaFolder = Path.Combine(currentProject.BaseDirectory.FullPath, FigmaBundle.FigmaDirectoryName); if (!currentProject.PathExistsInProject(figmaFolder)) { //we add figma folder in the case doesn't exists currentProject.AddDirectory(FileService.AbsoluteToRelativePath(currentProject.BaseDirectory, figmaFolder)); } //now we need to add the content //bundle var fullBundlePath = bundle.DirectoryPath; if (!currentProject.PathExistsInProject(fullBundlePath)) { currentProject.AddDirectory(FileService.AbsoluteToRelativePath(currentProject.BaseDirectory, fullBundlePath)); } //manifest var manifestFullDirectoryPath = bundle.ManifestFilePath; if (!currentProject.PathExistsInProject(manifestFullDirectoryPath)) { currentProject.AddFile(manifestFullDirectoryPath); } //document var documentFullDirectoryPath = bundle.DocumentFilePath; if (!currentProject.PathExistsInProject(documentFullDirectoryPath)) { currentProject.AddFile(documentFullDirectoryPath); } //TODO: images are not enabled by now if (includeImages) { //resources var resourcesDirectoryPath = bundle.ResourcesDirectoryPath; currentProject.AddDirectory(FileService.AbsoluteToRelativePath(currentProject.BaseDirectory, resourcesDirectoryPath)); //we add to the project for each resource inside the //foreach (var image in Directory.EnumerateFiles (resourcesDirectoryPath, "*.png")) { // currentProject.AddFile (image); //} var images = Directory.EnumerateFiles(resourcesDirectoryPath, $"*{FigmaBundle.ImageFormat}").Select(s => new FilePath(s)); foreach (var item in images) { if (!currentProject.PathExistsInProject(item)) { var projectFile = new ProjectFile(item, BuildAction.BundleResource); projectFile.Metadata.SetValue("LogicalName", projectFile.ResourceId, ""); currentProject.AddFile(projectFile); } } } if (savesInProject) { await IdeApp.ProjectOperations.SaveAsync(currentProject); } }
public override void BuildNode(ITreeBuilder builder, object dataObject, NodeInfo nodeInfo) { if (dataObject is Projects.ProjectFile file) { if (file.IsFigmaDesignerFile()) { nodeInfo.OverlayBottomLeft = HasError(file, file.DependsOnFile) ? figmaOverlayError : figmaOverlay; } else if (file.IsFigmaCSFile(out var designerFile)) { nodeInfo.OverlayBottomLeft = HasError(designerFile, file) ? figmaOverlayError : figmaOverlay; } } else if (dataObject is ProjectFolder pr) { if (pr.IsDocumentDirectoryBundle()) { FigmaBundle bundle = null; try { bundle = FigmaBundle.FromDirectoryPath(pr.Path.FullPath); } catch (Exception ex) { //if the bundle is removed by any reason whyle updating LoggingService.LogError("CustomFigmaFundlerNodeBuilder", ex); } if (bundle != null && bundle.Manifest != null && !string.IsNullOrEmpty(bundle.Manifest.DocumentTitle)) { nodeInfo.Label = bundle.Manifest.DocumentTitle; } else { nodeInfo.Label = pr.Path.FileNameWithoutExtension; } nodeInfo.ClosedIcon = nodeInfo.Icon = Context.GetIcon(Stock.Package); Task.Run(() => { var query = new FigmaFileVersionQuery(bundle.FileId); var figmaFileVersions = FigmaSharp.AppContext.Api.GetFileVersions(query).versions; return(figmaFileVersions .GroupByCreatedAt() .OrderByDescending(s => s.created_at) .FirstOrDefault()); }).ContinueWith(s => { if (s.Result != null && s.Result.id != bundle.Version.id) { Runtime.RunInMainThread(() => { nodeInfo.StatusIcon = Context.GetIcon(packageUpdateIcon); if (s.Result.IsNamed) { nodeInfo.StatusMessage = $"Update available: {s.Result.label}"; } else { nodeInfo.StatusMessage = $"Update available: {s.Result.created_at.ToString("g")}"; } }); } }); return; } if (pr.IsFigmaDirectory()) { nodeInfo.Label = FigmaFolderLabel; nodeInfo.ClosedIcon = nodeInfo.Icon = Context.GetIcon(Resources.Icons.FigmaPad); return; } } }
public static async Task UpdateFigmaFilesAsync(this Project sender, ProgressMonitor monitor, IEnumerable <ProjectFile> projectFiles, FigmaBundle figmaBundle, FigmaFileVersion version, bool translateStrings) { var includeImages = true; var fileProvider = new ControlRemoteNodeProvider() { Version = version }; await fileProvider.LoadAsync(figmaBundle.FileId); FigmaSharp.Services.LoggingService.LogInfo($"[Done] Loaded Remote File provider for Version {version?.id ?? "Current"}"); var codeRendererService = new NativeViewCodeService(fileProvider) { TranslationService = new Services.MonoDevelopTranslationService() }; await Task.Run(() => { figmaBundle.Update(version, fileProvider, includeImages: includeImages); }); await sender.IncludeBundleAsync(monitor, figmaBundle, includeImages : includeImages); foreach (var designerFile in projectFiles) { if (designerFile.TryGetFigmaNode(fileProvider, out var figmaNode)) { try { var fileView = figmaBundle.GetFigmaFileView(figmaNode); fileView.GeneratePartialDesignerClass(codeRendererService, designerFile.FilePath.ParentDirectory, figmaBundle.Namespace, translateStrings); await sender.FormatFileAsync(designerFile.FilePath); } catch (Exception ex) { FigmaSharp.Services.LoggingService.LogError($"Cannot update {designerFile.FilePath}' with '{figmaNode.name}' node.", ex); } } } }