private FlowLayoutWidget CreateMacroCommandContainer()
        {
            FlowLayoutWidget container = new FlowLayoutWidget(FlowDirection.TopToBottom);

            container.Margin = new BorderDouble(0, 5);
            BorderDouble elementMargin = new BorderDouble(top: 3);

            string     macroCommandLabelTxt     = "Macro Commands".Localize();
            string     macroCommandLabelTxtFull = string.Format("{0}:", macroCommandLabelTxt);
            TextWidget macroCommandLabel        = new TextWidget(macroCommandLabelTxtFull, 0, 0, 12);

            macroCommandLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            macroCommandLabel.HAnchor   = HAnchor.ParentLeftRight;
            macroCommandLabel.Margin    = new BorderDouble(0, 0, 0, 1);

            macroCommandInput = new MHTextEditWidget(windowController.ActiveMacro.GCode, pixelHeight: 120, multiLine: true, typeFace: ApplicationController.MonoSpacedTypeFace);
            macroCommandInput.DrawFromHintedCache();
            macroCommandInput.HAnchor = HAnchor.ParentLeftRight;
            macroCommandInput.VAnchor = VAnchor.ParentBottomTop;
            macroCommandInput.ActualTextEditWidget.VAnchor = VAnchor.ParentBottomTop;

            string shouldBeGCodeLabel     = "This should be in 'G-Code'".Localize();
            string shouldBeGCodeLabelFull = string.Format("{0}.", shouldBeGCodeLabel);

            macroCommandError           = new TextWidget(shouldBeGCodeLabelFull, 0, 0, 10);
            macroCommandError.TextColor = ActiveTheme.Instance.PrimaryTextColor;
            macroCommandError.HAnchor   = HAnchor.ParentLeftRight;
            macroCommandError.Margin    = elementMargin;

            container.AddChild(macroCommandLabel);
            container.AddChild(macroCommandInput);
            container.AddChild(macroCommandError);
            container.HAnchor = HAnchor.ParentLeftRight;
            container.VAnchor = VAnchor.ParentBottomTop;
            return(container);
        }
        public MacroDetailPage(GCodeMacro gcodeMacro, PrinterSettings printerSettings)
        {
            // Form validation fields
            MHTextEditWidget macroNameInput;
            MHTextEditWidget macroCommandInput;
            TextWidget       macroCommandError;
            TextWidget       macroNameError;

            this.HeaderText      = "Edit Macro".Localize();
            this.printerSettings = printerSettings;

            var elementMargin = new BorderDouble(top: 3);

            contentRow.Padding += 3;

            contentRow.AddChild(new TextWidget("Macro Name".Localize() + ":", 0, 0, 12)
            {
                TextColor = theme.Colors.PrimaryTextColor,
                HAnchor   = HAnchor.Stretch,
                Margin    = new BorderDouble(0, 0, 0, 1)
            });

            contentRow.AddChild(macroNameInput = new MHTextEditWidget(GCodeMacro.FixMacroName(gcodeMacro.Name))
            {
                HAnchor = HAnchor.Stretch
            });

            contentRow.AddChild(macroNameError = new TextWidget("Give the macro a name".Localize() + ".", 0, 0, 10)
            {
                TextColor = theme.Colors.PrimaryTextColor,
                HAnchor   = HAnchor.Stretch,
                Margin    = elementMargin
            });

            contentRow.AddChild(new TextWidget("Macro Commands".Localize() + ":", 0, 0, 12)
            {
                TextColor = theme.Colors.PrimaryTextColor,
                HAnchor   = HAnchor.Stretch,
                Margin    = new BorderDouble(0, 0, 0, 1)
            });

            macroCommandInput = new MHTextEditWidget(gcodeMacro.GCode, pixelHeight: 120, multiLine: true, typeFace: ApplicationController.GetTypeFace(NamedTypeFace.Liberation_Mono))
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch
            };
            macroCommandInput.ActualTextEditWidget.VAnchor = VAnchor.Stretch;
            macroCommandInput.DrawFromHintedCache();
            contentRow.AddChild(macroCommandInput);

            contentRow.AddChild(macroCommandError = new TextWidget("This should be in 'G-Code'".Localize() + ".", 0, 0, 10)
            {
                TextColor = theme.Colors.PrimaryTextColor,
                HAnchor   = HAnchor.Stretch,
                Margin    = elementMargin
            });

            var container = new FlowLayoutWidget
            {
                Margin  = new BorderDouble(0, 5),
                HAnchor = HAnchor.Stretch
            };

            contentRow.AddChild(container);

            var addMacroButton = theme.CreateDialogButton("Save".Localize());

            addMacroButton.Click += (s, e) =>
            {
                UiThread.RunOnIdle(() =>
                {
                    if (ValidateMacroForm())
                    {
                        // SaveActiveMacro
                        gcodeMacro.Name  = macroNameInput.Text;
                        gcodeMacro.GCode = macroCommandInput.Text;

                        if (!printerSettings.Macros.Contains(gcodeMacro))
                        {
                            printerSettings.Macros.Add(gcodeMacro);
                            printerSettings.Save();
                        }

                        this.DialogWindow.ChangeToPage(new MacroListPage(printerSettings));
                    }
                });
            };

            this.AddPageAction(addMacroButton);

            // Define field validation
            var validationMethods        = new ValidationMethods();
            var stringValidationHandlers = new FormField.ValidationHandler[] { validationMethods.StringIsNotEmpty };

            formFields = new List <FormField>
            {
                new FormField(macroNameInput, macroNameError, stringValidationHandlers),
                new FormField(macroCommandInput, macroCommandError, stringValidationHandlers)
            };
        }
Exemple #3
0
        public MarkdownEditPage(UIField uiField)
        {
            this.WindowTitle = "MatterControl - " + "Markdown Edit".Localize();
            this.HeaderText  = "Edit Page".Localize() + ":";

            var tabControl = new SimpleTabs(theme, new GuiWidget())
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch,
            };

            tabControl.TabBar.BackgroundColor = theme.TabBarBackground;
            tabControl.TabBar.Padding         = 0;

            contentRow.AddChild(tabControl);
            contentRow.Padding = 0;

            var editContainer = new GuiWidget()
            {
                HAnchor         = HAnchor.Stretch,
                VAnchor         = VAnchor.Stretch,
                Padding         = theme.DefaultContainerPadding,
                BackgroundColor = theme.BackgroundColor
            };

            editWidget = new MHTextEditWidget("", theme, multiLine: true, typeFace: ApplicationController.GetTypeFace(NamedTypeFace.Liberation_Mono))
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch,
                Name    = this.Name
            };
            editWidget.DrawFromHintedCache();
            editWidget.ActualTextEditWidget.VAnchor = VAnchor.Stretch;

            editContainer.AddChild(editWidget);

            markdownWidget = new MarkdownWidget(theme, true)
            {
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch,
                Margin  = 0,
                Padding = 0,
            };

            var previewTab = new ToolTab("Preview", "Preview".Localize(), tabControl, markdownWidget, theme, hasClose: false)
            {
                Name = "Preview Tab"
            };

            tabControl.AddTab(previewTab);

            var editTab = new ToolTab("Edit", "Edit".Localize(), tabControl, editContainer, theme, hasClose: false)
            {
                Name = "Edit Tab"
            };

            tabControl.AddTab(editTab);

            tabControl.ActiveTabChanged += (s, e) =>
            {
                if (tabControl.SelectedTabIndex == 1)
                {
                    markdownWidget.Markdown = editWidget.Text;
                }
            };

            tabControl.SelectedTabIndex = 0;

            var saveButton = theme.CreateDialogButton("Save".Localize());

            saveButton.Click += (s, e) =>
            {
                uiField.SetValue(
                    editWidget.Text.Replace("\n", "\\n"),
                    userInitiated: true);

                this.DialogWindow.CloseOnIdle();
            };
            this.AddPageAction(saveButton);

            var link = new LinkLabel("Markdown Help", theme)
            {
                Margin  = new BorderDouble(right: 20),
                VAnchor = VAnchor.Center
            };

            link.Click += (s, e) =>
            {
                ApplicationController.Instance.LaunchBrowser("https://guides.github.com/features/mastering-markdown/");
            };
            footerRow.AddChild(link, 0);
        }
		private FlowLayoutWidget CreateMacroCommandContainer()
		{
			FlowLayoutWidget container = new FlowLayoutWidget(FlowDirection.TopToBottom);
			container.Margin = new BorderDouble(0, 5);
			BorderDouble elementMargin = new BorderDouble(top: 3);

			string macroCommandLabelTxt = LocalizedString.Get("Macro Commands");
			string macroCommandLabelTxtFull = string.Format("{0}:", macroCommandLabelTxt);
			TextWidget macroCommandLabel = new TextWidget(macroCommandLabelTxtFull, 0, 0, 12);
			macroCommandLabel.TextColor = ActiveTheme.Instance.PrimaryTextColor;
			macroCommandLabel.HAnchor = HAnchor.ParentLeftRight;
			macroCommandLabel.Margin = new BorderDouble(0, 0, 0, 1);

			macroCommandInput = new MHTextEditWidget(windowController.ActiveMacro.GCode, pixelHeight: 120, multiLine: true, typeFace: ApplicationController.MonoSpacedTypeFace);
			macroCommandInput.DrawFromHintedCache();
			macroCommandInput.HAnchor = HAnchor.ParentLeftRight;
			macroCommandInput.VAnchor = VAnchor.ParentBottomTop;
			macroCommandInput.ActualTextEditWidget.VAnchor = VAnchor.ParentBottomTop;

			string shouldBeGCodeLabel = LocalizedString.Get("This should be in 'G-Code'");
			string shouldBeGCodeLabelFull = string.Format("{0}.", shouldBeGCodeLabel);
			macroCommandError = new TextWidget(shouldBeGCodeLabelFull, 0, 0, 10);
			macroCommandError.TextColor = ActiveTheme.Instance.PrimaryTextColor;
			macroCommandError.HAnchor = HAnchor.ParentLeftRight;
			macroCommandError.Margin = elementMargin;

			container.AddChild(macroCommandLabel);
			container.AddChild(macroCommandInput);
			container.AddChild(macroCommandError);
			container.HAnchor = HAnchor.ParentLeftRight;
			container.VAnchor = VAnchor.ParentBottomTop;
			return container;
		}