Beispiel #1
0
        public void StackView_Orientation(string orientation)
        {
            var stackViewLayer = provider.FindByName(orientation);

            Assert.NotNull(stackViewLayer);

            var service = new NativeViewCodeService(provider, converters);
            var options = new CodeRenderServiceOptions()
            {
                ScanChildren    = false,
                ShowComments    = false,
                ShowAddChild    = false,
                ShowSize        = false,
                ShowConstraints = false
            };

            var nodeName = "stackViewView";
            var builder  = new StringBuilder();

            service.GetCode(builder, new CodeNode(stackViewLayer, nodeName), currentRendererOptions: options);
            builder.ReplaceDefaultNameTag(nodeName);

            Assert.IsNotEmpty(builder.ToString());
            Assert.True(builder.ToString().Contains($"{nodeName}.Orientation = NSUserInterfaceLayoutOrientation.{orientation};"));
        }
Beispiel #2
0
        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);
            }
        }
        async Task <ProjectFile> CreateBundleView(FigmaBundleViewBase figmaBundleView, Project currentProject, INodeProvider fileProvider, bool translateStrings)
        {
            var bundle = figmaBundleView.Bundle;

            await fileProvider.LoadAsync(bundle.DocumentFilePath);

            var converters            = FigmaControlsContext.Current.GetConverters();
            var codePropertyConverter = FigmaControlsContext.Current.GetCodePropertyConverter();
            var codeRendererService   = new NativeViewCodeService(fileProvider, converters, codePropertyConverter)
            {
                TranslationService = new Services.MonoDevelopTranslationService()
            };

            figmaBundleView.Generate(outputDirectory, codeRendererService, namesSpace: bundle.Namespace, translateStrings: translateStrings);

            var partialDesignerClassFilePath = Path.Combine(outputDirectory, figmaBundleView.PartialDesignerClassName);
            var publicCsClassFilePath        = Path.Combine(outputDirectory, figmaBundleView.PublicCsClassName);

            var designerProjectFile = currentProject.AddFile(partialDesignerClassFilePath);
            var csProjectFile       = currentProject.AddFile(publicCsClassFilePath);

            designerProjectFile.DependsOn = csProjectFile.FilePath;
            designerProjectFile.Metadata.SetValue(FigmaFile.FigmaPackageId, bundle.FileId);

            if (!figmaBundleView.FigmaNode.TryGetNodeCustomName(out string customName))
            {
                customName = figmaBundleView.FigmaNode.name;
            }

            designerProjectFile.Metadata.SetValue(FigmaFile.FigmaNodeCustomName, customName);
            return(csProjectFile);
        }
Beispiel #4
0
        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);
                }
            }
        }
Beispiel #5
0
        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);
            }
        }
Beispiel #6
0
        async Task GenerateBundle(string fileId, FigmaFileVersion version, string namesSpace, bool includeImages, bool translateLabels)
        {
            IdeApp.Workbench.StatusBar.AutoPulse = true;
            IdeApp.Workbench.StatusBar.BeginProgress($"Adding package ‘{fileId}’…");

            //we need to ask to figma server to get nodes as demmand
            var fileProvider = new ControlRemoteNodeProvider();
            await fileProvider.LoadAsync(fileId);

            //bundle generation
            var currentBundle = await Task.Run(() =>
            {
                var bundle = currentProject.CreateBundle(fileId, version, fileProvider, namesSpace);
                bundle.SaveAll(includeImages, fileProvider);
                return(bundle);
            });

            //now we need to add to Monodevelop all the stuff
            await currentProject.IncludeBundleAsync(currentBundle, includeImages, savesInProject : false);

            //to generate all layers we need a code renderer
            var codeRendererService = new NativeViewCodeService(fileProvider)
            {
                TranslationService = new MonoDevelopTranslationService()
            };

            var mainFigmaNodes = fileProvider.GetMainGeneratedLayers();

            foreach (var figmaNode in mainFigmaNodes)
            {
                if (!(figmaNode is FigmaFrame) || (figmaNode is FigmaGroup))
                {
                    continue;
                }
                var figmaBundleView = currentBundle.GetFigmaFileView(figmaNode);
                figmaBundleView.Generate(codeRendererService, writePublicClassIfExists: false, namesSpace: currentBundle.Namespace, translateLabels);

                await currentProject.AddFigmaBundleViewAsync(figmaBundleView, savesInProject : false);
            }

            await IdeApp.ProjectOperations.SaveAsync(currentProject);

            IdeApp.Workbench.StatusBar.EndProgress();
            IdeApp.Workbench.StatusBar.AutoPulse = false;
        }
Beispiel #7
0
        public void StackView_Children()
        {
            var stackViewLayer = provider.FindByName(mainNodeName);

            Assert.NotNull(stackViewLayer);

            var service = new NativeViewCodeService(provider, converters);
            var options = new CodeRenderServiceOptions()
            {
                ShowComments    = false,
                ShowSize        = false,
                ShowConstraints = false
            };

            var builder = new StringBuilder();

            service.GetCode(builder, new CodeNode(stackViewLayer), currentRendererOptions: options);

            Assert.IsNotEmpty(builder.ToString());
        }
Beispiel #8
0
        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);
                    }
                }
            }
        }
Beispiel #9
0
        public void SkippedNodes()
        {
            var window = provider.FindByName("MyWindow");

            Assert.NotNull(window);

            var service = new NativeViewCodeService(provider, converters);
            var options = new CodeRenderServiceOptions()
            {
                ShowComments    = false,
                ShowSize        = false,
                ShowConstraints = false
            };

            var builder = new StringBuilder();

            service.GetCode(builder, new CodeNode(window), currentRendererOptions: options);
            string code = builder.ToString();

            StringAssert.DoesNotContain("labelToBeSkipped", code);
            StringAssert.Contains("labelToBeDisplayed", code);
        }