private void OpenPrinters_Changed(object sender, OpenPrintersChangedEventArgs e)
        {
            var activePrinter = e.Printer;

            if (e.Operation == OpenPrintersChangedEventArgs.OperationType.Add)
            {
                if (activePrinter.Settings.PrinterSelected)
                {
                    // Create and switch to new printer tab
                    tabControl.ActiveTab = this.CreatePrinterTab(activePrinter, theme);
                    tabControl.RefreshTabPointers();
                }
            }
            else
            {
                // Close existing printer tabs
                if (tabControl.AllTabs.FirstOrDefault(t => t.TabContent is PrinterTabPage printerTab &&
                                                      printerTab.printer.Settings.ID == activePrinter.Settings.ID) is ITab tab &&
                    tab.TabContent is PrinterTabPage printerPage)
                {
                    tabControl.RemoveTab(tab);
                    tabControl.RefreshTabPointers();
                }
            }
        }
        private ChromeTab CreatePrinterTab(PrinterConfig printer, ThemeConfig theme)
        {
            // Printer page is in fixed position
            var tab1 = tabControl.AllTabs.Skip(1).FirstOrDefault();

            var printerTabPage = tab1?.TabContent as PrinterTabPage;

            if (printerTabPage == null ||
                printerTabPage.printer != printer)
            {
                // TODO - call save before remove
                // printerTabPage.sceneContext.SaveChanges();

                if (printerTabPage != null)
                {
                    tabControl.RemoveTab(tab1);
                }

                printerTab = new ChromeTab(
                    printer.Settings.GetValue(SettingsKey.printer_name),
                    printer.Settings.GetValue(SettingsKey.printer_name),
                    tabControl,
                    new PrinterTabPage(printer, theme, "unused_tab_title"),
                    theme,
                    tabImageUrl: ApplicationController.Instance.GetFavIconUrl(oemName: printer.Settings.GetValue(SettingsKey.make)),
                    hasClose: false)
                {
                    Name        = "3D View Tab",
                    MinimumSize = new Vector2(120, theme.TabButtonHeight)
                };

                PrinterSettings.SettingChanged.RegisterEvent((s, e) =>
                {
                    string settingsName = (e as StringEventArgs)?.Data;
                    if (settingsName != null && settingsName == SettingsKey.printer_name)
                    {
                        printerTab.Title = printer.Settings.GetValue(SettingsKey.printer_name);
                    }
                }, ref unregisterEvents);


                // Add printer into fixed position
                tabControl.AddTab(printerTab, 1);

                return(printerTab);
            }
            else if (printerTab != null)
            {
                tabControl.ActiveTab = tab1;
                return(tab1 as ChromeTab);
            }

            return(null);
        }
Example #3
0
        private void Workspaces_Changed(object sender, WorkspacesChangedEventArgs e)
        {
            var workspace     = e.Workspace;
            var activePrinter = workspace.Printer;

            if (e.Operation == WorkspacesChangedEventArgs.OperationType.Add ||
                e.Operation == WorkspacesChangedEventArgs.OperationType.Restore)
            {
                // Create printer or part tab
                bool      isPrinter = activePrinter?.Settings.PrinterSelected == true;
                ChromeTab newTab    = isPrinter ? CreatePrinterTab(workspace, theme) : CreatePartTab(workspace);

                if (e.Operation == WorkspacesChangedEventArgs.OperationType.Add)
                {
                    ApplicationController.Instance.MainTabKey = newTab.Key;
                }

                // Activate tab with previously active key
                if (newTab.Key == ApplicationController.Instance.MainTabKey)
                {
                    tabControl.ActiveTab = newTab;
                }
            }
            else
            {
                // Close existing printer tabs
                if (tabControl.AllTabs.FirstOrDefault(t => t.TabContent is PrinterTabPage printerTab &&
                                                      printerTab.printer.Settings.ID == activePrinter.Settings.ID) is ITab tab &&
                    tab.TabContent is PrinterTabPage printerPage)
                {
                    tabControl.RemoveTab(tab);
                }
            }

            tabControl.RefreshTabPointers();
        }
Example #4
0
        private ChromeTab CreatePrinterTab(PrinterConfig printer, ThemeConfig theme, string tabTitle)
        {
            // Printer page is in fixed position
            var tab1 = tabControl.AllTabs.Skip(1).FirstOrDefault();

            var printerTabPage = tab1?.TabContent as PrinterTabPage;

            if (printerTabPage == null ||
                printerTabPage.printer != printer)
            {
                // TODO - call save before remove
                // printerTabPage.sceneContext.SaveChanges();

                if (printerTabPage != null)
                {
                    tabControl.RemoveTab(tab1);
                }

                printerTab = new ChromeTab(
                    tabTitle,
                    tabControl,
                    new PrinterTabPage(printer, theme, tabTitle.ToUpper()),
                    theme,
                    tabImageUrl: ApplicationController.Instance.GetFavIconUrl(oemName: printer.Settings.GetValue(SettingsKey.make)),
                    hasClose: false)
                {
                    Name        = "3D View Tab",
                    MinimumSize = new Vector2(120, theme.TabButtonHeight)
                };

                // Add printer into fixed position
                tabControl.AddTab(printerTab, 1);

                return(printerTab);
            }
            else if (printerTab != null)
            {
                tabControl.ActiveTab = tab1;
                return(tab1 as ChromeTab);
            }

            return(null);
        }
Example #5
0
        public PartPreviewContent(ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            this.AnchorAll();

            var extensionArea = new LeftClipFlowLayoutWidget()
            {
                BackgroundColor = theme.TabBarBackground,
                VAnchor         = VAnchor.Stretch,
                Padding         = new BorderDouble(left: 8)
            };

            tabControl = new ChromeTabs(extensionArea, theme)
            {
                VAnchor         = VAnchor.Stretch,
                HAnchor         = HAnchor.Stretch,
                BackgroundColor = ActiveTheme.Instance.PrimaryBackgroundColor,
                BorderColor     = theme.MinimalShade,
                Border          = new BorderDouble(left: 1),
                NewTabPage      = () =>
                {
                    return(new StartTabPage(this, theme));
                }
            };
            tabControl.ActiveTabChanged += (s, e) =>
            {
                if (this.tabControl.ActiveTab?.TabContent is PartTabPage tabPage)
                {
                    var dragDropData = ApplicationController.Instance.DragDropData;

                    // Set reference on tab change
                    dragDropData.View3DWidget = tabPage.view3DWidget;
                    dragDropData.SceneContext = tabPage.sceneContext;
                }
            };

            // Force the ActionArea to be as high as ButtonHeight
            tabControl.TabBar.ActionArea.MinimumSize = new Vector2(0, theme.ButtonHeight);
            tabControl.TabBar.BackgroundColor        = theme.TabBarBackground;
            tabControl.TabBar.BorderColor            = theme.ActiveTabColor;

            // Force common padding into top region
            tabControl.TabBar.Padding = theme.TabbarPadding.Clone(top: theme.TabbarPadding.Top * 2, bottom: 0);

            // add in a what's new button
            var seeWhatsNewButton = new LinkLabel("What's New...".Localize(), theme)
            {
                Name        = "What's New Link",
                ToolTipText = "See what's new in this version of MatterControl".Localize(),
                VAnchor     = VAnchor.Center,
                Margin      = new BorderDouble(10, 0),
                TextColor   = theme.Colors.PrimaryTextColor
            };

            seeWhatsNewButton.Click += (s, e) => UiThread.RunOnIdle(() =>
            {
                UserSettings.Instance.set(UserSettingsKey.LastReadWhatsNew, JsonConvert.SerializeObject(DateTime.Now));
                DialogWindow.Show(new HelpPage("What's New"));
            });

            tabControl.TabBar.ActionArea.AddChild(seeWhatsNewButton);

            // add in the update available button
            var updateAvailableButton = new LinkLabel("Update Available".Localize(), theme)
            {
                Visible = false,
            };

            // make the function inline so we don't have to create members for the buttons
            EventHandler SetLinkButtonsVisibility = (s, e) =>
            {
                if (UserSettings.Instance.HasLookedAtWhatsNew())
                {
                    // hide it
                    seeWhatsNewButton.Visible = false;
                }

                if (UpdateControlData.Instance.UpdateStatus == UpdateControlData.UpdateStatusStates.UpdateAvailable)
                {
                    updateAvailableButton.Visible = true;
                    // if we are going to show the update link hide the whats new link no matter what
                    seeWhatsNewButton.Visible = false;
                }
                else
                {
                    updateAvailableButton.Visible = false;
                }
            };

            UserSettings.Instance.Changed += SetLinkButtonsVisibility;
            Closed += (s, e) => UserSettings.Instance.Changed -= SetLinkButtonsVisibility;

            RunningInterval showUpdateInterval = null;

            updateAvailableButton.VisibleChanged += (s, e) =>
            {
                if (!updateAvailableButton.Visible)
                {
                    if (showUpdateInterval != null)
                    {
                        showUpdateInterval.Continue = false;
                        showUpdateInterval          = null;
                    }
                    return;
                }

                showUpdateInterval = UiThread.SetInterval(() =>
                {
                    double displayTime  = 1;
                    double pulseTime    = 1;
                    double totalSeconds = 0;
                    var textWidgets     = updateAvailableButton.Descendants <TextWidget>().Where((w) => w.Visible == true).ToArray();
                    Color startColor    = theme.Colors.PrimaryTextColor;
                    // Show a highlight on the button as the user did not click it
                    Animation flashBackground = null;
                    flashBackground           = new Animation()
                    {
                        DrawTarget      = updateAvailableButton,
                        FramesPerSecond = 10,
                        Update          = (s1, updateEvent) =>
                        {
                            totalSeconds += updateEvent.SecondsPassed;
                            if (totalSeconds < displayTime)
                            {
                                double blend = AttentionGetter.GetFadeInOutPulseRatio(totalSeconds, pulseTime);
                                var color    = new Color(startColor, (int)((1 - blend) * 255));
                                foreach (var textWidget in textWidgets)
                                {
                                    textWidget.TextColor = color;
                                }
                            }
                            else
                            {
                                foreach (var textWidget in textWidgets)
                                {
                                    textWidget.TextColor = startColor;
                                }
                                flashBackground.Stop();
                            }
                        }
                    };
                    flashBackground.Start();
                }, 120);
            };

            updateAvailableButton.Name = "Update Available Link";
            SetLinkButtonsVisibility(this, null);
            updateAvailableButton.ToolTipText = "There is a new update available for download".Localize();
            updateAvailableButton.VAnchor     = VAnchor.Center;
            updateAvailableButton.Margin      = new BorderDouble(10, 0);
            updateAvailableButton.Click      += (s, e) => UiThread.RunOnIdle(() =>
            {
                UiThread.RunOnIdle(() =>
                {
                    UpdateControlData.Instance.CheckForUpdate();
                    DialogWindow.Show <CheckForUpdatesPage>();
                });
            });

            tabControl.TabBar.ActionArea.AddChild(updateAvailableButton);

            UpdateControlData.Instance.UpdateStatusChanged.RegisterEvent(SetLinkButtonsVisibility, ref unregisterEvents);

            this.AddChild(tabControl);

            ActiveSliceSettings.SettingChanged.RegisterEvent((s, e) =>
            {
                if (e is StringEventArgs stringEvent &&
                    stringEvent.Data == SettingsKey.printer_name &&
                    printerTab != null)
                {
                    printerTab.Text = ActiveSliceSettings.Instance.GetValue(SettingsKey.printer_name);
                }
            }, ref unregisterEvents);

            ActiveSliceSettings.ActivePrinterChanged.RegisterEvent((s, e) =>
            {
                var activePrinter = ApplicationController.Instance.ActivePrinter;

                // If ActivePrinter has been nulled and a printer tab is open, close it
                var tab1 = tabControl.AllTabs.Skip(1).FirstOrDefault();
                if ((activePrinter == null || !activePrinter.Settings.PrinterSelected) &&
                    tab1?.TabContent is PrinterTabPage)
                {
                    tabControl.RemoveTab(tab1);
                }
                else
                {
                    this.CreatePrinterTab(activePrinter, theme);
                }
            }, ref unregisterEvents);

            ApplicationController.Instance.NotifyPrintersTabRightElement(extensionArea);

            // Show fixed start page
            tabControl.AddTab(
                new ChromeTab("Start".Localize(), tabControl, tabControl.NewTabPage(), theme, hasClose: false)
            {
                MinimumSize = new Vector2(0, theme.TabButtonHeight),
                Name        = "Start Tab",
                Padding     = new BorderDouble(15, 0)
            });

            // Add a tab for the current printer
            if (ActiveSliceSettings.Instance.PrinterSelected)
            {
                this.CreatePrinterTab(ApplicationController.Instance.ActivePrinter, theme);
            }

            // Restore active tabs
            foreach (var bed in ApplicationController.Instance.Workspaces)
            {
                this.CreatePartTab("New Part", bed, theme);
            }
        }