Exemplo n.º 1
0
        async void Load(FigmaFileVersion version = null, int pageIndex = 0)
        {
            if (string.IsNullOrEmpty(DocumentID))
            {
                return;
            }

            windowController.EnableButtons(false);

            if (response == null)
            {
                windowController.Title = string.Format("Opening “{0}”…", DocumentID);
            }

            FigmaSharp.AppContext.Current.SetAccessToken(Token);

            if (response == null || version != null)
            {
                fileProvider = new FigmaRemoteFileProvider()
                {
                    File = DocumentID, Version = version
                };
                fileProvider.ImageLinksProcessed += (sender, e) => {
                    InvokeOnMainThread(() => {
                        windowController.ToggleToolbarSpinner(toggle_on: false);
                    });
                };

                var embeddedSheetConverter  = new EmbededSheetDialogConverter(fileProvider);
                var embeddedWindowConverter = new EmbededWindowConverter(fileProvider);

                rendererService = new NativeViewRenderingService(fileProvider);
                rendererService.CustomConverters.Add(embeddedSheetConverter);
                rendererService.CustomConverters.Add(embeddedWindowConverter);

                embeddedWindowConverter.LivePreviewLoading += (s, e) => windowController.ToggleToolbarSpinner(true);
                embeddedWindowConverter.LivePreviewLoaded  += (s, e) => windowController.ToggleToolbarSpinner(false);
            }

            var scrollView = CreateScrollView();
            await rendererService.StartAsync(DocumentID, scrollView.ContentView, new FigmaViewRendererServiceOptions()
            {
                StartPage = pageIndex
            });

            windowController.ToggleToolbarSpinner(toggle_on: true);

            new StoryboardLayoutManager().Run(scrollView.ContentView, rendererService);
            response = fileProvider.Response;

            NativeScrollView.RemoveFromSuperview();
            MainScrollView = scrollView;

            NativeScrollView = (NSScrollView)scrollView.NativeObject;
            View.AddSubview(NativeScrollView);

            windowController.Window.Title           = windowController.Title = response.name;
            windowController.Window.BackgroundColor = NativeScrollView.BackgroundColor;

            windowController.UpdatePagesPopupButton(response.document, pageIndex);
            await windowController.UpdateVersionMenu(DocumentID);

            windowController.EnableButtons(true);

            RecentStore.SharedRecentStore.AddRecent(DocumentID, windowController.Window.Title);
            ToggleSpinner(toggle_on: false);
        }
        async void Load(FigmaFileVersion version = null, int pageIndex = 0)
        {
            if (string.IsNullOrEmpty(DocumentID))
            {
                return;
            }

            windowController.EnableButtons(false);

            if (response == null)
            {
                windowController.Title = string.Format("Opening “{0}”…", DocumentID);
            }

            if (response == null || version != null)
            {
                fileProvider = new ControlRemoteNodeProvider()
                {
                    File = DocumentID, Version = version
                };
                fileProvider.ImageLinksProcessed += (sender, e) => {
                    InvokeOnMainThread(() => {
                        windowController.ToggleToolbarSpinner(toggle_on: false);
                    });
                };

                var embeddedSheetConverter  = new EmbededSheetDialogConverter(fileProvider);
                var embeddedWindowConverter = new EmbededWindowConverter(fileProvider);

                rendererService = new ControlViewRenderingService(fileProvider);
                rendererService.CustomConverters.Add(embeddedSheetConverter);
                rendererService.CustomConverters.Add(embeddedWindowConverter);

                embeddedWindowConverter.LivePreviewLoading += (s, e) => windowController.ToggleToolbarSpinner(true);
                embeddedWindowConverter.LivePreviewLoaded  += (s, e) => windowController.ToggleToolbarSpinner(false);
            }

            var scrollView = CreateScrollView();
            await rendererService.StartAsync(DocumentID, scrollView.ContentView, new ViewRenderServiceOptions()
            {
                StartPage = pageIndex
            });

            windowController.ToggleToolbarSpinner(toggle_on: true);

            new StoryboardLayoutManager().Run(scrollView.ContentView, rendererService);
            response = fileProvider.Response;

            NativeScrollView.RemoveFromSuperview();
            MainScrollView   = scrollView;
            NativeScrollView = (NSScrollView)scrollView.NativeObject;
            View.AddSubview(NativeScrollView);

            if (response != null)
            {
                windowController.Window.Title = windowController.Title = response.name;

                // NOTE: Figma does not (yet) support color styles for the document background,
                // so for now use UnderPageBackgroundColor to get a good contrast in all themes
                //
                // windowController.Window.BackgroundColor = NativeScrollView.BackgroundColor;
                windowController.Window.BackgroundColor = NSColor.UnderPageBackgroundColor;
                NativeScrollView.BackgroundColor        = NSColor.UnderPageBackgroundColor;

                windowController.UpdatePagesPopupButton(response.document, pageIndex);
                await windowController.UpdateVersionMenu(DocumentID);

                windowController.EnableButtons(true);

                RecentStore.SharedRecentStore.AddRecent(DocumentID, windowController.Window.Title);
            }
            else
            {
                if (View.Window?.WindowController is DocumentWindowController controller)
                {
                    controller.ShowError(DocumentID);
                }

                var windowController = this.Storyboard.InstantiateControllerWithIdentifier("OpenLocationWindow") as NSWindowController;
                windowController.ShowWindow(null);

                this.View.Window.Close();
            }

            ToggleSpinner(toggle_on: false);
        }