Beispiel #1
0
        public TextEditWithInlineCancel(ThemeConfig theme, string emptyText = null)
        {
            if (emptyText == null)
            {
                emptyText = "Search".Localize();
            }

            this.VAnchor = VAnchor.Center | VAnchor.Fit;
            this.HAnchor = HAnchor.Stretch;

            TextEditWidget = new MHTextEditWidget("", theme, messageWhenEmptyAndNotSelected: emptyText)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Center
            };
            this.AddChild(TextEditWidget);

            this.ResetButton        = theme.CreateSmallResetButton();
            ResetButton.HAnchor    |= HAnchor.Right;
            ResetButton.VAnchor    |= VAnchor.Center;
            ResetButton.Name        = "Close Search";
            ResetButton.ToolTipText = "Clear".Localize();

            this.AddChild(ResetButton);
        }
        public ZTuningWidget(PrinterSettings printerSettings, ThemeConfig theme, int extruderIndex)
        {
            this.extruderIndex   = extruderIndex;
            this.theme           = theme;
            this.printerSettings = printerSettings;
            this.HAnchor         = HAnchor.Fit;
            this.VAnchor         = VAnchor.Fit | VAnchor.Center;

            zOffsetStreamContainer = new FlowLayoutWidget(FlowDirection.LeftToRight)
            {
                Margin          = new BorderDouble(3, 0),
                Padding         = new BorderDouble(3),
                HAnchor         = HAnchor.Fit,
                VAnchor         = VAnchor.Center,
                BackgroundColor = theme.MinimalShade,
                Height          = 20
            };
            this.AddChild(zOffsetStreamContainer);

            double zoffset = printerSettings.GetValue <double>(SettingsKey.baby_step_z_offset);

            if (extruderIndex == 1)
            {
                zoffset = printerSettings.GetValue <double>(SettingsKey.baby_step_z_offset_1);
            }
            zOffsetStreamDisplay = new TextWidget(zoffset.ToString("0.##"), pointSize: theme.DefaultFontSize)
            {
                AutoExpandBoundsToText = true,
                TextColor = theme.TextColor,
                Margin    = new BorderDouble(5, 0, 8, 0),
                VAnchor   = VAnchor.Center
            };
            zOffsetStreamContainer.AddChild(zOffsetStreamDisplay);

            clearZOffsetButton             = theme.CreateSmallResetButton();
            clearZOffsetButton.Name        = "Clear ZOffset button";
            clearZOffsetButton.ToolTipText = extruderIndex == 0 ? "Clear ZOffset".Localize() : "Clear ZOffset 2".Localize();
            clearZOffsetButton.Visible     = zoffset != 0;
            clearZOffsetButton.Click      += (sender, e) =>
            {
                if (extruderIndex == 0)
                {
                    printerSettings.SetValue(SettingsKey.baby_step_z_offset, "0");
                }
                else
                {
                    printerSettings.SetValue(SettingsKey.baby_step_z_offset_1, "0");
                }
            };
            zOffsetStreamContainer.AddChild(clearZOffsetButton);

            // Register listeners
            printerSettings.SettingChanged += Printer_SettingChanged;
        }
Beispiel #3
0
        public ZTuningWidget(PrinterSettings printerSettings, ThemeConfig theme, bool allowRemoveButton = true)
        {
            this.theme             = theme;
            this.printerSettings   = printerSettings;
            this.allowRemoveButton = allowRemoveButton;
            this.HAnchor           = HAnchor.Fit;
            this.VAnchor           = VAnchor.Fit | VAnchor.Center;

            PrinterSettings.SettingChanged.RegisterEvent((s, e) =>
            {
                if ((e as StringEventArgs)?.Data == SettingsKey.baby_step_z_offset)
                {
                    OffsetStreamChanged(null, null);
                }
            }, ref unregisterEvents);

            zOffsetStreamContainer = new FlowLayoutWidget(FlowDirection.LeftToRight)
            {
                Margin          = new BorderDouble(3, 0),
                Padding         = new BorderDouble(3),
                HAnchor         = HAnchor.Fit,
                VAnchor         = VAnchor.Center,
                BackgroundColor = theme.MinimalShade,
                Height          = 20
            };
            this.AddChild(zOffsetStreamContainer);

            double zoffset = printerSettings.GetValue <double>(SettingsKey.baby_step_z_offset);

            zOffsetStreamDisplay = new TextWidget(zoffset.ToString("0.##"), pointSize: theme.DefaultFontSize)
            {
                AutoExpandBoundsToText = true,
                TextColor = ActiveTheme.Instance.PrimaryTextColor,
                Margin    = new BorderDouble(5, 0, 8, 0),
                VAnchor   = VAnchor.Center
            };
            zOffsetStreamContainer.AddChild(zOffsetStreamDisplay);

            clearZOffsetButton             = theme.CreateSmallResetButton();
            clearZOffsetButton.Name        = "Clear ZOffset button";
            clearZOffsetButton.ToolTipText = "Clear ZOffset".Localize();
            clearZOffsetButton.Visible     = allowRemoveButton && zoffset != 0;
            clearZOffsetButton.Click      += (sender, e) =>
            {
                printerSettings.SetValue(SettingsKey.baby_step_z_offset, "0");
            };
            zOffsetStreamContainer.AddChild(clearZOffsetButton);
        }
Beispiel #4
0
        public SearchInputBox(ThemeConfig theme, string emptyText = null)
        {
            this.VAnchor = VAnchor.Center | VAnchor.Fit;
            this.HAnchor = HAnchor.Stretch;

            searchInput = new MHTextEditWidget("", theme, messageWhenEmptyAndNotSelected: emptyText ?? "Search".Localize())
            {
                Name    = "Search Library Edit",
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Center
            };
            this.AddChild(searchInput);

            var resetButton = theme.CreateSmallResetButton();

            resetButton.HAnchor    |= HAnchor.Right;
            resetButton.VAnchor    |= VAnchor.Center;
            resetButton.Name        = "Close Search";
            resetButton.ToolTipText = "Clear".Localize();

            this.AddChild(resetButton);

            this.ResetButton = resetButton;
        }
Beispiel #5
0
        public SliceSettingsRow(PrinterConfig printer, SettingsContext settingsContext, SliceSettingData settingData, ThemeConfig theme, bool fullRowSelect = false)
            : base(settingData.PresentationName.Localize(), settingData.HelpText.Localize(), theme, fullRowSelect: fullRowSelect)
        {
            this.printer         = printer;
            this.settingData     = settingData;
            this.settingsContext = settingsContext;

            using (this.LayoutLock())
            {
                this.AddChild(dataArea = new FlowLayoutWidget
                {
                    VAnchor         = VAnchor.Fit | VAnchor.Center,
                    DebugShowBounds = debugLayout
                });

                this.AddChild(unitsArea = new GuiWidget()
                {
                    HAnchor         = HAnchor.Absolute,
                    VAnchor         = VAnchor.Fit | VAnchor.Center,
                    Width           = 50 * GuiWidget.DeviceScale,
                    DebugShowBounds = debugLayout
                });

                // Populate unitsArea as appropriate
                // List elements contain list values in the field which normally contains label details, skip generation of invalid labels
                if (settingData.DataEditType != SliceSettingData.DataEditTypes.LIST &&
                    settingData.DataEditType != SliceSettingData.DataEditTypes.HARDWARE_PRESENT)
                {
                    unitsArea.AddChild(
                        new WrappedTextWidget(settingData.Units.Localize(), pointSize: theme.FontSize8, textColor: theme.TextColor)
                    {
                        Margin = new BorderDouble(5, 0),
                    });
                }

                restoreArea = new GuiWidget()
                {
                    HAnchor         = HAnchor.Absolute,
                    VAnchor         = VAnchor.Fit | VAnchor.Center,
                    Width           = 20 * GuiWidget.DeviceScale,
                    DebugShowBounds = debugLayout
                };
                this.AddChild(restoreArea);

                this.Name = settingData.SlicerConfigName + " Row";

                if (settingData.ShowAsOverride &&
                    settingsContext.ViewFilter != NamedSettingsLayers.OEMSettings)
                {
                    restoreButton             = theme.CreateSmallResetButton();
                    restoreButton.HAnchor     = HAnchor.Right;
                    restoreButton.Margin      = 0;
                    restoreButton.Name        = "Restore " + settingData.SlicerConfigName;
                    restoreButton.ToolTipText = "Restore Default".Localize();
                    restoreButton.Click      += (sender, e) =>
                    {
                        // Revert the user override
                        settingsContext.ClearValue(settingData.SlicerConfigName);
                    };

                    restoreArea.AddChild(restoreButton);

                    restoreArea.Selectable = true;
                }
            }

            this.PerformLayout();
        }
        public ValidationErrorsPanel(IEnumerable <ValidationError> errors, ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            this.HAnchor         = HAnchor.Absolute;
            this.VAnchor         = VAnchor.Fit | VAnchor;
            this.BackgroundColor = theme.ResolveColor(theme.BackgroundColor, theme.PrimaryAccentColor.WithAlpha(30));

            var errorImage   = StaticData.Instance.LoadIcon("SettingsGroupError_16x.png", 16, 16).SetToColor(theme.TextColor);
            var warningImage = StaticData.Instance.LoadIcon("SettingsGroupWarning_16x.png", 16, 16).SetToColor(theme.TextColor);
            var infoImage    = StaticData.Instance.LoadIcon("StatusInfoTip_16x.png", 16, 16);

            foreach (var validationError in errors.OrderByDescending(e => e.ErrorLevel))
            {
                if (validationError.ErrorLevel == ValidationErrorLevel.Warning &&
                    UserSettings.Instance.get($"Ignore_{validationError.ID}") == "true")
                {
                    continue;
                }

                string errorText, errorDetails;

                if (validationError is SettingsValidationError settingsValidationError)
                {
                    errorText = string.Format(
                        "{0} {1}",
                        settingsValidationError.PresentationName,
                        validationError.ErrorLevel == ValidationErrorLevel.Error ? "Error".Localize() : "Warning".Localize());

                    errorDetails = validationError.Error + "\n\n" + settingsValidationError.Location;
                }
                else
                {
                    errorText    = validationError.Error;
                    errorDetails = validationError.Details ?? "";
                }

                var row = new SettingsRow(errorText, errorDetails, theme, validationError.ErrorLevel == ValidationErrorLevel.Error ? errorImage : warningImage, fullRowSelect: true)
                {
                    ArrowDirection = ArrowDirection.Left,
                    Name           = validationError.ID + " Row"
                };

                if (validationError.FixAction is NamedAction action)
                {
                    // Show fix button
                    var button = new LinkLabel(action.Title, theme, pointSize: theme.FontSize10)
                    {
                        VAnchor = VAnchor.Center,
                        Margin  = new BorderDouble(right: 8),
                        Enabled = action.IsEnabled == null || action.IsEnabled(),
                        Name    = validationError.ID + " Button"
                    };

                    if (!string.IsNullOrEmpty(action.ID))
                    {
                        button.Name = action.ID;
                    }

                    button.Click += (s, e) =>
                    {
                        // Invoke FixAction
                        action.Action.Invoke();
                        this.ClosePopup();
                    };

                    row.AddChild(button);

                    row.ActionWidget  = button;
                    row.FullRowSelect = true;
                }
                else
                {
                    // Show info indicator hinting that hover will reveal additional details
                    row.AddChild(new IconButton(infoImage, theme)
                    {
                        Selectable = false
                    });
                }

                if (validationError.ErrorLevel == ValidationErrorLevel.Warning)
                {
                    var dismissButton = theme.CreateSmallResetButton();
                    dismissButton.HAnchor     = HAnchor.Absolute;
                    dismissButton.Margin      = new BorderDouble(right: theme.ButtonHeight / 2 - dismissButton.Width / 2);
                    dismissButton.Name        = "Dismiss " + validationError.ID;
                    dismissButton.ToolTipText = "Dismiss".Localize();
                    dismissButton.Click      += (sender, e) =>
                    {
                        UserSettings.Instance.set($"Ignore_{validationError.ID}", "true");
                        this.ClosePopup();
                    };

                    row.AddChild(dismissButton);

                    // Enable selection without regard to FullRowSelect
                    dismissButton.Selectable = true;
                }

                this.AddChild(row);
            }
        }
        public TourPopover(ProductTour productTour, ThemeConfig theme, RectangleDouble targetBounds)
            : base(ArrowDirection.Left, 0, 7, 0)
        {
            this.HAnchor = HAnchor.Fit;
            this.VAnchor = VAnchor.Fit;
            this.theme   = theme;

            var targetWidget = productTour.ActiveItem.Widget;

            var column = new FlowLayoutWidget(FlowDirection.TopToBottom)
            {
                HAnchor = HAnchor.Fit,
                VAnchor = VAnchor.Fit
            };

            this.AddChild(column);

            var row = new GuiWidget()
            {
                Margin  = new BorderDouble(5),
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit
            };

            column.AddChild(row);

            var title = new TextWidget(productTour.ActiveItem.Title, pointSize: theme.DefaultFontSize, textColor: theme.PrimaryAccentColor)
            {
                HAnchor = HAnchor.Left,
                Margin  = new BorderDouble(top: 4, left: 4),
                VAnchor = VAnchor.Center,
            };

            row.AddChild(title);

            var closeButton = theme.CreateSmallResetButton();

            closeButton.HAnchor = HAnchor.Right;
            closeButton.VAnchor = VAnchor.Top;
            closeButton.Margin  = 0;
            closeButton.Click  += (s, e) =>
            {
                this.Parent.CloseOnIdle();
            };

            row.AddChild(closeButton);

            var body = this.CreateBodyWidgets(productTour);

            body.Padding = new BorderDouble(theme.DefaultContainerPadding).Clone(top: 0);
            column.AddChild(body);

            var totalWidth  = this.Width + this.DeviceMarginAndBorder.Width;
            var totalHeight = this.Height + this.DeviceMarginAndBorder.Height;

            var totalBounds = new RectangleDouble(0, 0, totalWidth, totalHeight);

            var targetCenterX = targetWidget.Width / 2;
            var targetCenterY = targetWidget.Height / 2;

            if (targetBounds.Right >= totalBounds.Width)
            {
                if (targetBounds.Bottom < totalBounds.Height / 2)
                {
                    if (targetBounds.Bottom - totalBounds.Height < 0)
                    {
                        // Down arrow
                        this.ArrowDirection = ArrowDirection.Down;

                        // Arrow centered on target in x, to the right
                        totalBounds      = this.GetTotalBounds();
                        this.ArrowOffset = (int)(totalBounds.Right - targetCenterX);

                        // Popover positioned above target, aligned right
                        this.Position = new Vector2(
                            this.LeftForAlignTargetRight(targetBounds.Right, totalBounds),
                            targetBounds.Top + 1);
                    }
                    else
                    {
                        // Right arrow
                        this.ArrowDirection = ArrowDirection.Right;

                        //  Arrow centered on target in y, to the top
                        totalBounds      = this.GetTotalBounds();
                        this.ArrowOffset = (int)(totalBounds.Height - targetCenterY);

                        // Popover positioned left of target, aligned top
                        this.Position = new Vector2(
                            this.LeftForAlignTargetRight(targetBounds.Right, totalBounds),
                            targetBounds.Top - totalBounds.Height);
                    }
                }
                else
                {
                    // Up arrow
                    this.ArrowDirection = ArrowDirection.Up;

                    // Arrow centered on target in x, to the right
                    totalBounds      = this.GetTotalBounds();
                    this.ArrowOffset = (int)(totalBounds.Right - targetCenterX);

                    // Popover positioned below target, aligned right
                    this.Position = new Vector2(
                        this.LeftForAlignTargetRight(targetBounds.Right, totalBounds),
                        targetBounds.Bottom - totalBounds.Height - 1);
                }
            }
            else
            {
                if (targetBounds.Bottom < totalBounds.Height)
                {
                    // Left arrow
                    this.ArrowDirection = ArrowDirection.Left;

                    // Arrow centered on target in y (or top - 20 if target larger than content)
                    totalBounds = this.GetTotalBounds();
                    if (targetWidget.Height > totalBounds.Height)
                    {
                        this.ArrowOffset = 20;
                    }
                    else
                    {
                        this.ArrowOffset = (int)targetCenterY;
                    }

                    // Popover positioned right of target, aligned top
                    this.Position = new Vector2(
                        targetBounds.Right + 1,
                        targetBounds.Top - totalBounds.Height);
                }
                else
                {
                    this.ArrowDirection = ArrowDirection.Up;

                    // Arrow centered on target in x, to the left
                    totalBounds      = this.GetTotalBounds();
                    this.ArrowOffset = (int)targetCenterX;

                    // Popover positioned below target, aligned left
                    this.Position = new Vector2(
                        targetBounds.Left,
                        targetBounds.Bottom - totalBounds.Height - 1);
                }
            }

            this.TagColor = theme.ResolveColor(theme.BackgroundColor, theme.AccentMimimalOverlay.WithAlpha(50));

            this.RebuildShape();
        }
        public ValidationErrorsPanel(IEnumerable <ValidationError> errors, ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            this.HAnchor         = HAnchor.Absolute;
            this.VAnchor         = VAnchor.Fit | VAnchor;
            this.BackgroundColor = theme.ResolveColor(theme.BackgroundColor, theme.PrimaryAccentColor.WithAlpha(30));

            var errorImage   = AggContext.StaticData.LoadIcon("SettingsGroupError_16x.png", 16, 16, theme.InvertIcons);
            var warningImage = AggContext.StaticData.LoadIcon("SettingsGroupWarning_16x.png", 16, 16, theme.InvertIcons);
            var infoImage    = AggContext.StaticData.LoadIcon("StatusInfoTip_16x.png", 16, 16);
            var fixIcon      = AggContext.StaticData.LoadIcon("noun_1306.png", 16, 16, theme.InvertIcons);

            foreach (var validationError in errors.OrderByDescending(e => e.ErrorLevel))
            {
                if (validationError.ErrorLevel == ValidationErrorLevel.Warning &&
                    UserSettings.Instance.get($"Ignore_{validationError.ID}") == "true")
                {
                    continue;
                }

                string errorText, errorDetails;

                var settingsValidationError = validationError as SettingsValidationError;
                if (settingsValidationError != null)
                {
                    errorText = string.Format(
                        "{0} {1}",
                        settingsValidationError.PresentationName,
                        validationError.ErrorLevel == ValidationErrorLevel.Error ? "Error".Localize() : "Warning".Localize());

                    errorDetails = validationError.Error;
                }
                else
                {
                    errorText    = validationError.Error;
                    errorDetails = validationError.Details ?? "";
                }

                var row = new SettingsRow(errorText, errorDetails, theme, validationError.ErrorLevel == ValidationErrorLevel.Error ? errorImage : warningImage)
                {
                    ArrowDirection = ArrowDirection.Left
                };

                if (validationError.FixAction is NamedAction action)
                {
                    // Show fix button
                    var button = new LinkLabel(action.Title, theme, pointSize: theme.FontSize10)
                    {
                        VAnchor = VAnchor.Center,
                        Margin  = new BorderDouble(right: 8),
                        Enabled = action.IsEnabled == null || action.IsEnabled()
                    };

                    if (!string.IsNullOrEmpty(action.ID))
                    {
                        button.Name = action.ID;
                    }

                    button.Click += (s, e) =>
                    {
                        // Invoke FixAction
                        action.Action.Invoke();

                        // Close popup on FixAction button click
                        if (this.Parents <PopupWidget>().FirstOrDefault() is PopupWidget popupWidget)
                        {
                            UiThread.RunOnIdle(popupWidget.CloseMenu);
                        }
                    };

                    row.AddChild(button);
                }
                else
                {
                    // Show info indicator hinting that hover will reveal additional details
                    var button = new IconButton(infoImage, theme)
                    {
                        Selectable = false
                    };
                    row.AddChild(button);
                }

                if (validationError.ErrorLevel == ValidationErrorLevel.Warning)
                {
                    var dismissButton = theme.CreateSmallResetButton();
                    dismissButton.HAnchor     = HAnchor.Absolute;
                    dismissButton.Margin      = new BorderDouble(right: theme.ButtonHeight / 2 - dismissButton.Width / 2);
                    dismissButton.Name        = "Dismiss " + validationError.ID;
                    dismissButton.ToolTipText = "Dismiss".Localize();
                    dismissButton.Click      += (sender, e) =>
                    {
                        UserSettings.Instance.set($"Ignore_{validationError.ID}", "true");
                    };

                    row.AddChild(dismissButton);
                }

                this.AddChild(row);
            }
        }
Beispiel #9
0
        private void AddDisplay(PrinterSettings printerSettings,
                                ThemeConfig theme,
                                bool showClearButton,
                                string setting,
                                int toolIndex,
                                TextWidget widget)
        {
            GuiWidget clearZOffsetButton = null;

            void Printer_SettingChanged(object s, StringEventArgs e)
            {
                if (e?.Data == setting)
                {
                    double zOffset = printerSettings.GetValue <double>(setting);
                    bool   hasOverriddenZOffset = zOffset != 0;

                    if (clearZOffsetButton != null)
                    {
                        clearZOffsetButton.Visible = hasOverriddenZOffset;
                    }

                    widget.Text = zOffset.ToString("0.##");
                    DescribeExtruder(widget, toolIndex);
                }
            }

            var zOffsetStreamContainer = new FlowLayoutWidget(FlowDirection.LeftToRight)
            {
                Margin  = new BorderDouble(3, 0),
                Padding = new BorderDouble(3),
                HAnchor = HAnchor.Fit | HAnchor.Right,
                VAnchor = VAnchor.Absolute,
                Height  = 20 * GuiWidget.DeviceScale
            };

            this.AddChild(zOffsetStreamContainer);

            var zoffset = printerSettings.GetValue <double>(setting);

            zOffsetStreamContainer.AddChild(widget);

            if (showClearButton)
            {
                clearZOffsetButton             = theme.CreateSmallResetButton();
                clearZOffsetButton.Name        = "Clear ZOffset button";
                clearZOffsetButton.ToolTipText = "Clear ZOffset".Localize();
                clearZOffsetButton.Visible     = zoffset != 0;
                clearZOffsetButton.Click      += (sender, e) =>
                {
                    printerSettings.SetValue(setting, "0");
                };
                zOffsetStreamContainer.AddChild(clearZOffsetButton);
            }

            printerSettings.SettingChanged += Printer_SettingChanged;

            this.Closed += (s, e) =>
            {
                printerSettings.SettingChanged -= Printer_SettingChanged;
            };
        }
        public HardwareTabPage(ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            this.theme   = theme;
            this.Padding = 0;
            this.HAnchor = HAnchor.Stretch;
            this.VAnchor = VAnchor.Stretch;

            var toolbar = new Toolbar(theme.TabbarPadding, theme.CreateSmallResetButton())
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Fit,
                Padding = theme.ToolbarPadding
            };

            theme.ApplyBottomBorder(toolbar);

            toolbar.AddChild(new TextButton("Inventory".Localize(), theme)
            {
                Padding     = new BorderDouble(6, 0),
                MinimumSize = new Vector2(0, theme.ButtonHeight),
                Selectable  = false
            });

            this.AddChild(toolbar);

            var horizontalSplitter = new Splitter()
            {
                SplitterDistance   = UserSettings.Instance.LibraryViewWidth,
                SplitterSize       = theme.SplitterWidth,
                SplitterBackground = theme.SplitterBackground,
                HAnchor            = HAnchor.Stretch,
                VAnchor            = VAnchor.Stretch,
            };

            horizontalSplitter.DistanceChanged += (s, e) =>
            {
                UserSettings.Instance.LibraryViewWidth = horizontalSplitter.SplitterDistance;
            };

            this.AddChild(horizontalSplitter);

            var treeView = new HardwareTreeView(theme)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch,
                Width   = 300,
                Margin  = 5
            };

            treeView.NodeMouseDoubleClick += (s, e) =>
            {
                if (e is MouseEventArgs mouseEvent &&
                    s is GuiWidget clickedWidget &&
                    mouseEvent.Button == MouseButtons.Left &&
                    mouseEvent.Clicks == 2)
                {
                    if (treeView?.SelectedNode.Tag is PrinterInfo printerInfo)
                    {
                        ApplicationController.Instance.OpenPrinter(printerInfo);
                    }
                }
            };

            treeView.NodeMouseClick += (s, e) =>
            {
                if (e is MouseEventArgs mouseEvent &&
                    s is GuiWidget clickedWidget &&
                    mouseEvent.Button == MouseButtons.Right)
                {
                    UiThread.RunOnIdle(() =>
                    {
                        var popupMenu = new PopupMenu(ApplicationController.Instance.MenuTheme);

                        var openMenuItem    = popupMenu.CreateMenuItem("Open".Localize());
                        openMenuItem.Click += (s2, e2) =>
                        {
                            if (treeView?.SelectedNode.Tag is PrinterInfo printerInfo)
                            {
                                ApplicationController.Instance.OpenPrinter(printerInfo);
                            }
                        };

                        popupMenu.CreateSeparator();

                        var deleteMenuItem    = popupMenu.CreateMenuItem("Delete".Localize());
                        deleteMenuItem.Click += (s2, e2) =>
                        {
                            if (treeView.SelectedNode.Tag is PrinterInfo printerInfo)
                            {
                                // Delete printer
                                StyledMessageBox.ShowMessageBox(
                                    (deletePrinter) =>
                                {
                                    if (deletePrinter)
                                    {
                                        ProfileManager.Instance.DeletePrinter(printerInfo.ID);
                                    }
                                },
                                    "Are you sure you want to delete printer '{0}'?".Localize().FormatWith(printerInfo.Name),
                                    "Delete Printer?".Localize(),
                                    StyledMessageBox.MessageType.YES_NO,
                                    "Delete Printer".Localize());
                            }
                        };

                        popupMenu.ShowMenu(clickedWidget, mouseEvent);
                    });
                }
            };

            treeView.ScrollArea.HAnchor = HAnchor.Stretch;

            treeView.AfterSelect += (s, e) =>
            {
                if (treeView.SelectedNode.Tag is PrinterInfo printerInfo)
                {
                    horizontalSplitter.Panel2.CloseChildren();
                    horizontalSplitter.Panel2.AddChild(new PrinterDetails(printerInfo, theme, true)
                    {
                        HAnchor = HAnchor.MaxFitOrStretch,
                        VAnchor = VAnchor.Stretch,
                        Padding = theme.DefaultContainerPadding
                    });
                }
            };
            horizontalSplitter.Panel1.AddChild(treeView);

            horizontalSplitter.Panel2.AddChild(new GuiWidget()
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch,
            });
        }
Beispiel #11
0
        public SimpleTab(string tabLabel, SimpleTabs parentTabControl, GuiWidget tabContent, ThemeConfig theme, string tabImageUrl = null, bool hasClose = true, double pointSize = 12, ImageBuffer iconImage = null)
        {
            this.HAnchor = HAnchor.Fit;
            this.VAnchor = VAnchor.Fit | VAnchor.Bottom;
            this.Padding = 0;
            this.Margin  = 0;
            this.theme   = theme;

            this.TabContent       = tabContent;
            this.parentTabControl = parentTabControl;

            if (iconImage != null)
            {
                tabPill = new TabPill(tabLabel, ActiveTheme.Instance.PrimaryTextColor, iconImage, pointSize);
            }
            else
            {
                tabPill = new TabPill(tabLabel, ActiveTheme.Instance.PrimaryTextColor, tabImageUrl, pointSize);
            }
            tabPill.Margin = (hasClose) ? new BorderDouble(right: 16) : 0;

            this.AddChild(tabPill);

            if (hasClose)
            {
                var closeButton = theme.CreateSmallResetButton();
                closeButton.HAnchor     = HAnchor.Right;
                closeButton.Margin      = new BorderDouble(right: 7, top: 1);
                closeButton.Name        = "Close Tab Button";
                closeButton.ToolTipText = "Close".Localize();
                closeButton.Click      += (sender, e) =>
                {
                    UiThread.RunOnIdle(() =>
                    {
                        if (TabContent is PrinterTabPage printerTab &&
                            printerTab.printer.Connection.PrinterIsPrinting)
                        {
                            StyledMessageBox.ShowMessageBox(
                                (bool response) =>
                            {
                                if (response)
                                {
                                    UiThread.RunOnIdle(() =>
                                    {
                                        this.parentTabControl.RemoveTab(this);
                                        this.CloseClicked?.Invoke(this, null);
                                    });
                                }
                            },
                                "Cancel the current print?".Localize(),
                                "Cancel Print?".Localize(),
                                StyledMessageBox.MessageType.YES_NO,
                                "Cancel Print".Localize(),
                                "Continue Printing".Localize());
                        }
                        else                         // need to handle asking about saving a
                        {
                            UiThread.RunOnIdle(() =>
                            {
                                this.parentTabControl.RemoveTab(this);
                                this.CloseClicked?.Invoke(this, null);
                            });
                        }
                    });