Exemplo n.º 1
0
 public TextScrollBar(TextScrollWidget textScrollWidget, int width)
     : base(width, 10)
 {
     this.textScrollWidget = textScrollWidget;
     Margin  = new BorderDouble(0, 5);
     VAnchor = Agg.UI.VAnchor.ParentBottomTop;
 }
Exemplo n.º 2
0
 public TextScrollBar(TextScrollWidget textScrollWidget, int width)
     : base(width, ScrollBar.ScrollBarWidth)
 {
     this.textScrollWidget = textScrollWidget;
     Margin          = new BorderDouble(0, 5);
     VAnchor         = Agg.UI.VAnchor.ParentBottomTop;
     BackgroundColor = RGBA_Bytes.LightGray;
 }
Exemplo n.º 3
0
		public TextScrollBar(TextScrollWidget textScrollWidget, int width)
			: base(width, ScrollBar.ScrollBarWidth)
		{
			this.textScrollWidget = textScrollWidget;
			Margin = new BorderDouble(0, 5);
			VAnchor = Agg.UI.VAnchor.ParentBottomTop;
			BackgroundColor = RGBA_Bytes.LightGray;
		}
Exemplo n.º 4
0
 public TextScrollBar(TextScrollWidget textScrollWidget, int width)
     : base(width, ScrollBar.ScrollBarWidth)
 {
     this.textScrollWidget = textScrollWidget;
     Margin          = new BorderDouble(0, 5);
     VAnchor         = Agg.UI.VAnchor.Stretch;
     BackgroundColor = Color.LightGray;
 }
Exemplo n.º 5
0
        public TerminalWidget(bool showInWindow)
        {
            this.Name            = "TerminalWidget";
            this.BackgroundColor = backgroundColor;
            this.Padding         = new BorderDouble(5, 0);
            FlowLayoutWidget topLeftToRightLayout = new FlowLayoutWidget();

            topLeftToRightLayout.AnchorAll();

            {
                FlowLayoutWidget manualEntryTopToBottomLayout = new FlowLayoutWidget(FlowDirection.TopToBottom);
                manualEntryTopToBottomLayout.VAnchor |= Agg.UI.VAnchor.ParentTop;
                manualEntryTopToBottomLayout.Padding  = new BorderDouble(top: 8);

                {
                    FlowLayoutWidget topBarControls = new FlowLayoutWidget(FlowDirection.LeftToRight);
                    topBarControls.HAnchor |= HAnchor.ParentLeft;

                    {
                        string filterOutputChkTxt = LocalizedString.Get("Filter Output");

                        filterOutput                      = new CheckBox(filterOutputChkTxt);
                        filterOutput.Margin               = new BorderDouble(5, 5, 5, 2);
                        filterOutput.TextColor            = this.textColor;
                        filterOutput.CheckedStateChanged += (object sender, EventArgs e) =>
                        {
                            if (filterOutput.Checked)
                            {
                                textScrollWidget.SetLineStartFilter(new string[] { "<-wait", "<-ok", "->M105", "<-T" });
                            }
                            else
                            {
                                textScrollWidget.SetLineStartFilter(null);
                            }

                            UserSettings.Instance.Fields.SetBool(TerminalFilterOutputKey, filterOutput.Checked);
                        };

                        filterOutput.VAnchor = Agg.UI.VAnchor.ParentBottom;
                        topBarControls.AddChild(filterOutput);
                    }

                    {
                        string autoUpperCaseChkTxt = LocalizedString.Get("Auto Uppercase");

                        autoUppercase           = new CheckBox(autoUpperCaseChkTxt);
                        autoUppercase.Margin    = new BorderDouble(5, 5, 5, 2);
                        autoUppercase.Checked   = UserSettings.Instance.Fields.GetBool(TerminalAutoUppercaseKey, true);
                        autoUppercase.TextColor = this.textColor;
                        autoUppercase.VAnchor   = Agg.UI.VAnchor.ParentBottom;
                        topBarControls.AddChild(autoUppercase);
                        autoUppercase.CheckedStateChanged += (sender, e) =>
                        {
                            UserSettings.Instance.Fields.SetBool(TerminalAutoUppercaseKey, autoUppercase.Checked);
                        };
                        manualEntryTopToBottomLayout.AddChild(topBarControls);
                    }
                }

                {
                    FlowLayoutWidget leftToRight = new FlowLayoutWidget();
                    leftToRight.AnchorAll();

                    textScrollWidget = new TextScrollWidget(PrinterOutputCache.Instance.PrinterLines);
                    //outputScrollWidget.Height = 100;
                    Debug.WriteLine(PrinterOutputCache.Instance.PrinterLines);
                    textScrollWidget.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
                    textScrollWidget.TextColor       = ActiveTheme.Instance.PrimaryTextColor;
                    textScrollWidget.HAnchor         = HAnchor.ParentLeftRight;
                    textScrollWidget.VAnchor         = VAnchor.ParentBottomTop;
                    textScrollWidget.Margin          = new BorderDouble(0, 5);
                    textScrollWidget.Padding         = new BorderDouble(3, 0);

                    leftToRight.AddChild(textScrollWidget);

                    TextScrollBar textScrollBar = new TextScrollBar(textScrollWidget, 15);
                    leftToRight.AddChild(textScrollBar);

                    manualEntryTopToBottomLayout.AddChild(leftToRight);
                }

                FlowLayoutWidget manualEntryLayout = new FlowLayoutWidget(FlowDirection.LeftToRight);
                manualEntryLayout.BackgroundColor = this.backgroundColor;
                manualEntryLayout.HAnchor         = HAnchor.ParentLeftRight;
                {
                    manualCommandTextEdit = new MHTextEditWidget("", typeFace: ApplicationController.MonoSpacedTypeFace);
                    //manualCommandTextEdit.BackgroundColor = RGBA_Bytes.White;
                    manualCommandTextEdit.Margin  = new BorderDouble(right: 3);
                    manualCommandTextEdit.HAnchor = HAnchor.ParentLeftRight;
                    manualCommandTextEdit.VAnchor = VAnchor.ParentBottom;
                    manualCommandTextEdit.ActualTextEditWidget.EnterPressed += new KeyEventHandler(manualCommandTextEdit_EnterPressed);
                    manualCommandTextEdit.ActualTextEditWidget.KeyDown      += new KeyEventHandler(manualCommandTextEdit_KeyDown);
                    manualEntryLayout.AddChild(manualCommandTextEdit);
                }

                manualEntryTopToBottomLayout.AddChild(manualEntryLayout);

                Button clearConsoleButton = controlButtonFactory.Generate(LocalizedString.Get("Clear"));
                clearConsoleButton.Margin = new BorderDouble(0);
                clearConsoleButton.Click += (sender, e) =>
                {
                    PrinterOutputCache.Instance.Clear();
                };

                //Output Console text to screen
                Button exportConsoleTextButton = controlButtonFactory.Generate(LocalizedString.Get("Export..."));
                exportConsoleTextButton.Click += (sender, mouseEvent) =>
                {
                    UiThread.RunOnIdle(DoExportExportLog_Click);
                };

                Button closeButton = controlButtonFactory.Generate(LocalizedString.Get("Close"));
                closeButton.Click += (sender, e) =>
                {
                    UiThread.RunOnIdle(CloseWindow);
                };

                sendCommand        = controlButtonFactory.Generate(LocalizedString.Get("Send"));
                sendCommand.Click += new EventHandler(sendManualCommandToPrinter_Click);

                FlowLayoutWidget bottomRowContainer = new FlowLayoutWidget();
                bottomRowContainer.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
                bottomRowContainer.Margin  = new BorderDouble(0, 3);

                bottomRowContainer.AddChild(sendCommand);
                bottomRowContainer.AddChild(clearConsoleButton);
                bottomRowContainer.AddChild(exportConsoleTextButton);
                bottomRowContainer.AddChild(new HorizontalSpacer());

                if (showInWindow)
                {
                    bottomRowContainer.AddChild(closeButton);
                }

                manualEntryTopToBottomLayout.AddChild(bottomRowContainer);
                manualEntryTopToBottomLayout.AnchorAll();

                topLeftToRightLayout.AddChild(manualEntryTopToBottomLayout);
            }

            AddChild(topLeftToRightLayout);
            this.AnchorAll();
        }
Exemplo n.º 6
0
        public TerminalWidget(bool showInWindow)
        {
            this.BackgroundColor = backgroundColor;
            this.Padding         = new BorderDouble(5, 0);
            FlowLayoutWidget topLeftToRightLayout = new FlowLayoutWidget();

            topLeftToRightLayout.AnchorAll();

            {
                FlowLayoutWidget manualEntryTopToBottomLayout = new FlowLayoutWidget(FlowDirection.TopToBottom);
                manualEntryTopToBottomLayout.VAnchor |= Agg.UI.VAnchor.ParentTop;
                manualEntryTopToBottomLayout.Padding  = new BorderDouble(top: 8);

                {
                    FlowLayoutWidget topBarControls = new FlowLayoutWidget(FlowDirection.LeftToRight);
                    topBarControls.HAnchor |= HAnchor.ParentLeft;

                    string autoUpperCaseChkTxt = LocalizedString.Get("Auto Uppercase");

                    autoUppercase           = new CheckBox(autoUpperCaseChkTxt);
                    autoUppercase.Margin    = new BorderDouble(5, 5, 5, 2);
                    autoUppercase.Checked   = true;
                    autoUppercase.TextColor = this.textColor;
                    autoUppercase.VAnchor   = Agg.UI.VAnchor.ParentBottom;
                    topBarControls.AddChild(autoUppercase);
                    manualEntryTopToBottomLayout.AddChild(topBarControls);
                }

                {
                    FlowLayoutWidget leftToRight = new FlowLayoutWidget();
                    leftToRight.AnchorAll();

                    textScrollWidget = new TextScrollWidget(PrinterOutputCache.Instance.PrinterLines);
                    //outputScrollWidget.Height = 100;
                    textScrollWidget.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
                    textScrollWidget.TextColor       = ActiveTheme.Instance.PrimaryTextColor;
                    textScrollWidget.HAnchor         = HAnchor.ParentLeftRight;
                    textScrollWidget.VAnchor         = VAnchor.ParentBottomTop;
                    textScrollWidget.Margin          = new BorderDouble(0, 5);
                    textScrollWidget.Padding         = new BorderDouble(3, 0);

                    leftToRight.AddChild(textScrollWidget);

                    TextScrollBar textScrollBar = new TextScrollBar(textScrollWidget, 15);
                    leftToRight.AddChild(textScrollBar);

                    manualEntryTopToBottomLayout.AddChild(leftToRight);
                }

                FlowLayoutWidget manualEntryLayout = new FlowLayoutWidget(FlowDirection.LeftToRight);
                manualEntryLayout.BackgroundColor = this.backgroundColor;
                manualEntryLayout.HAnchor         = HAnchor.ParentLeftRight;
                {
                    manualCommandTextEdit = new MHTextEditWidget("");
                    //manualCommandTextEdit.BackgroundColor = RGBA_Bytes.White;
                    manualCommandTextEdit.Margin  = new BorderDouble(right: 3);
                    manualCommandTextEdit.HAnchor = HAnchor.ParentLeftRight;
                    manualCommandTextEdit.VAnchor = VAnchor.ParentBottom;
                    manualCommandTextEdit.ActualTextEditWidget.EnterPressed += new KeyEventHandler(manualCommandTextEdit_EnterPressed);
                    manualCommandTextEdit.ActualTextEditWidget.KeyDown      += new KeyEventHandler(manualCommandTextEdit_KeyDown);
                    manualEntryLayout.AddChild(manualCommandTextEdit);
                }

                manualEntryTopToBottomLayout.AddChild(manualEntryLayout);

                Button clearConsoleButton = controlButtonFactory.Generate(LocalizedString.Get("Clear"));
                clearConsoleButton.Margin = new BorderDouble(0);
                clearConsoleButton.Click += (sender, e) =>
                {
                    PrinterOutputCache.Instance.Clear();
                };

                //Output Console text to screen
                Button exportConsoleTextButton = controlButtonFactory.Generate(LocalizedString.Get("Export..."));
                exportConsoleTextButton.Click += (sender, mouseEvent) =>
                {
                    UiThread.RunOnIdle(DoExportExportLog_Click);
                };

                Button closeButton = controlButtonFactory.Generate(LocalizedString.Get("Close"));
                closeButton.Click += (sender, e) =>
                {
                    UiThread.RunOnIdle(CloseWindow);
                };

                sendCommand        = controlButtonFactory.Generate(LocalizedString.Get("Send"));
                sendCommand.Click += new EventHandler(sendManualCommandToPrinter_Click);

                FlowLayoutWidget bottomRowContainer = new FlowLayoutWidget();
                bottomRowContainer.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
                bottomRowContainer.Margin  = new BorderDouble(0, 3);

                bottomRowContainer.AddChild(sendCommand);
                bottomRowContainer.AddChild(clearConsoleButton);
                bottomRowContainer.AddChild(exportConsoleTextButton);
                bottomRowContainer.AddChild(new HorizontalSpacer());

                if (showInWindow)
                {
                    bottomRowContainer.AddChild(closeButton);
                }

                manualEntryTopToBottomLayout.AddChild(bottomRowContainer);
                manualEntryTopToBottomLayout.AnchorAll();

                topLeftToRightLayout.AddChild(manualEntryTopToBottomLayout);
            }

            AddChild(topLeftToRightLayout);
            this.AnchorAll();
        }
Exemplo n.º 7
0
		public TerminalWidget(bool showInWindow)
		{
			this.BackgroundColor = backgroundColor;
			this.Padding = new BorderDouble(5, 0);
			FlowLayoutWidget topLeftToRightLayout = new FlowLayoutWidget();
			topLeftToRightLayout.AnchorAll();

			{
				FlowLayoutWidget manualEntryTopToBottomLayout = new FlowLayoutWidget(FlowDirection.TopToBottom);
				manualEntryTopToBottomLayout.VAnchor |= Agg.UI.VAnchor.ParentTop;
				manualEntryTopToBottomLayout.Padding = new BorderDouble(top: 8);

				{
					FlowLayoutWidget topBarControls = new FlowLayoutWidget(FlowDirection.LeftToRight);
					topBarControls.HAnchor |= HAnchor.ParentLeft;

					{
						string filterOutputChkTxt = LocalizedString.Get("Filter Output");

						filterOutput = new CheckBox(filterOutputChkTxt);
						filterOutput.Margin = new BorderDouble(5, 5, 5, 2);
						filterOutput.TextColor = this.textColor;
						filterOutput.CheckedStateChanged += (object sender, EventArgs e) =>
						{
							if (filterOutput.Checked)
							{
								textScrollWidget.SetLineStartFilter(new string[] { "<-wait", "<-ok", "->M105", "<-T" });
							}
							else
							{
								textScrollWidget.SetLineStartFilter(null);
							}

							UserSettings.Instance.Fields.SetBool(TerminalFilterOutputKey, filterOutput.Checked);
						};

						filterOutput.VAnchor = Agg.UI.VAnchor.ParentBottom;
						topBarControls.AddChild(filterOutput);
					}

					{
						string autoUpperCaseChkTxt = LocalizedString.Get("Auto Uppercase");

						autoUppercase = new CheckBox(autoUpperCaseChkTxt);
						autoUppercase.Margin = new BorderDouble(5, 5, 5, 2);
						autoUppercase.Checked = UserSettings.Instance.Fields.GetBool(TerminalAutoUppercaseKey, true);
						autoUppercase.TextColor = this.textColor;
						autoUppercase.VAnchor = Agg.UI.VAnchor.ParentBottom;
						topBarControls.AddChild(autoUppercase);
						autoUppercase.CheckedStateChanged += (sender, e) =>
						{
							UserSettings.Instance.Fields.SetBool(TerminalAutoUppercaseKey, autoUppercase.Checked);
						};
						manualEntryTopToBottomLayout.AddChild(topBarControls);
					}
				}

				{
					FlowLayoutWidget leftToRight = new FlowLayoutWidget();
					leftToRight.AnchorAll();

					textScrollWidget = new TextScrollWidget(PrinterOutputCache.Instance.PrinterLines);
					//outputScrollWidget.Height = 100;
					textScrollWidget.BackgroundColor = ActiveTheme.Instance.SecondaryBackgroundColor;
					textScrollWidget.TextColor = ActiveTheme.Instance.PrimaryTextColor;
					textScrollWidget.HAnchor = HAnchor.ParentLeftRight;
					textScrollWidget.VAnchor = VAnchor.ParentBottomTop;
					textScrollWidget.Margin = new BorderDouble(0, 5);
					textScrollWidget.Padding = new BorderDouble(3, 0);

					leftToRight.AddChild(textScrollWidget);

					TextScrollBar textScrollBar = new TextScrollBar(textScrollWidget, 15);
					leftToRight.AddChild(textScrollBar);

					manualEntryTopToBottomLayout.AddChild(leftToRight);
				}

				FlowLayoutWidget manualEntryLayout = new FlowLayoutWidget(FlowDirection.LeftToRight);
				manualEntryLayout.BackgroundColor = this.backgroundColor;
				manualEntryLayout.HAnchor = HAnchor.ParentLeftRight;
				{
					manualCommandTextEdit = new MHTextEditWidget("");
					//manualCommandTextEdit.BackgroundColor = RGBA_Bytes.White;
					manualCommandTextEdit.Margin = new BorderDouble(right: 3);
					manualCommandTextEdit.HAnchor = HAnchor.ParentLeftRight;
					manualCommandTextEdit.VAnchor = VAnchor.ParentBottom;
					manualCommandTextEdit.ActualTextEditWidget.EnterPressed += new KeyEventHandler(manualCommandTextEdit_EnterPressed);
					manualCommandTextEdit.ActualTextEditWidget.KeyDown += new KeyEventHandler(manualCommandTextEdit_KeyDown);
					manualEntryLayout.AddChild(manualCommandTextEdit);
				}

				manualEntryTopToBottomLayout.AddChild(manualEntryLayout);

				Button clearConsoleButton = controlButtonFactory.Generate(LocalizedString.Get("Clear"));
				clearConsoleButton.Margin = new BorderDouble(0);
				clearConsoleButton.Click += (sender, e) =>
				{
					PrinterOutputCache.Instance.Clear();
				};

				//Output Console text to screen
				Button exportConsoleTextButton = controlButtonFactory.Generate(LocalizedString.Get("Export..."));
				exportConsoleTextButton.Click += (sender, mouseEvent) =>
				{
					UiThread.RunOnIdle(DoExportExportLog_Click);
				};

				Button closeButton = controlButtonFactory.Generate(LocalizedString.Get("Close"));
				closeButton.Click += (sender, e) =>
				{
					UiThread.RunOnIdle(CloseWindow);
				};

				sendCommand = controlButtonFactory.Generate(LocalizedString.Get("Send"));
				sendCommand.Click += new EventHandler(sendManualCommandToPrinter_Click);

				FlowLayoutWidget bottomRowContainer = new FlowLayoutWidget();
				bottomRowContainer.HAnchor = Agg.UI.HAnchor.ParentLeftRight;
				bottomRowContainer.Margin = new BorderDouble(0, 3);

				bottomRowContainer.AddChild(sendCommand);
				bottomRowContainer.AddChild(clearConsoleButton);
				bottomRowContainer.AddChild(exportConsoleTextButton);
				bottomRowContainer.AddChild(new HorizontalSpacer());

				if (showInWindow)
				{
					bottomRowContainer.AddChild(closeButton);
				}

				manualEntryTopToBottomLayout.AddChild(bottomRowContainer);
				manualEntryTopToBottomLayout.AnchorAll();

				topLeftToRightLayout.AddChild(manualEntryTopToBottomLayout);
			}

			AddChild(topLeftToRightLayout);
			this.AnchorAll();
		}
Exemplo n.º 8
0
        public TerminalWidget(PrinterConfig printer, ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            this.printer = printer;
            this.Name    = "TerminalWidget";
            this.Padding = new BorderDouble(5, 0);

            // Header
            var headerRow = new FlowLayoutWidget(FlowDirection.LeftToRight)
            {
                HAnchor = HAnchor.Left | HAnchor.Stretch,
                Padding = new BorderDouble(0, 8)
            };

            this.AddChild(headerRow);

            headerRow.AddChild(CreateVisibilityOptions(theme));

            autoUppercase = new CheckBox("Auto Uppercase".Localize(), textSize: theme.DefaultFontSize)
            {
                Margin    = new BorderDouble(left: 25),
                Checked   = UserSettings.Instance.Fields.GetBool(UserSettingsKey.TerminalAutoUppercase, true),
                TextColor = theme.TextColor,
                VAnchor   = VAnchor.Center
            };
            autoUppercase.CheckedStateChanged += (s, e) =>
            {
                UserSettings.Instance.Fields.SetBool(UserSettingsKey.TerminalAutoUppercase, autoUppercase.Checked);
            };
            headerRow.AddChild(autoUppercase);

            // Body
            var bodyRow = new FlowLayoutWidget()
            {
                Margin  = new BorderDouble(bottom: 4),
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch
            };

            this.AddChild(bodyRow);

            textScrollWidget = new TextScrollWidget(printer, printer.Connection.TerminalLog)
            {
                BackgroundColor = theme.MinimalShade,
                TextColor       = theme.TextColor,
                HAnchor         = HAnchor.Stretch,
                VAnchor         = VAnchor.Stretch,
                Margin          = 0,
                Padding         = new BorderDouble(3, 0)
            };
            bodyRow.AddChild(textScrollWidget);
            bodyRow.AddChild(new TextScrollBar(textScrollWidget, 15)
            {
                ThumbColor      = theme.AccentMimimalOverlay,
                BackgroundColor = theme.SlightShade,
                Margin          = 0
            });

            textScrollWidget.LineFilterFunction = lineData =>
            {
                var line       = lineData.Line;
                var output     = lineData.Direction == TerminalLine.MessageDirection.ToPrinter;
                var outputLine = line;

                var lineWithoutChecksum = GCodeFile.GetLineWithoutChecksum(line);

                // and set this as the output if desired
                if (output &&
                    !UserSettings.Instance.Fields.GetBool(UserSettingsKey.TerminalShowChecksum, true))
                {
                    outputLine = lineWithoutChecksum;
                }

                if (!output &&
                    lineWithoutChecksum == "ok" &&
                    !UserSettings.Instance.Fields.GetBool(UserSettingsKey.TerminalShowOks, true))
                {
                    return(null);
                }
                else if (output &&
                         lineWithoutChecksum.StartsWith("M105") &&
                         !UserSettings.Instance.Fields.GetBool(UserSettingsKey.TerminalShowTempRequests, true))
                {
                    return(null);
                }
                else if (output &&
                         (lineWithoutChecksum.StartsWith("G0 ") || lineWithoutChecksum.StartsWith("G1 ")) &&
                         !UserSettings.Instance.Fields.GetBool(UserSettingsKey.TerminalShowMovementRequests, true))
                {
                    return(null);
                }
                else if (!output &&
                         (lineWithoutChecksum.StartsWith("T") || lineWithoutChecksum.StartsWith("ok T")) &&
                         !UserSettings.Instance.Fields.GetBool(UserSettingsKey.TerminalShowTempResponse, true))
                {
                    return(null);
                }
                else if (!output &&
                         lineWithoutChecksum == "wait" &&
                         !UserSettings.Instance.Fields.GetBool(UserSettingsKey.TerminalShowWaitResponse, false))
                {
                    return(null);
                }

                if (UserSettings.Instance.Fields.GetBool(UserSettingsKey.TerminalShowInputOutputMarks, true))
                {
                    switch (lineData.Direction)
                    {
                    case TerminalLine.MessageDirection.FromPrinter:
                        outputLine = "→ " + outputLine;
                        break;

                    case TerminalLine.MessageDirection.ToPrinter:
                        outputLine = "← " + outputLine;
                        break;

                    case TerminalLine.MessageDirection.ToTerminal:
                        outputLine = "* " + outputLine;
                        break;
                    }
                }

                return(outputLine);
            };

            // Input Row
            var inputRow = new FlowLayoutWidget(FlowDirection.LeftToRight)
            {
                BackgroundColor = this.BackgroundColor,
                HAnchor         = HAnchor.Stretch,
                Margin          = new BorderDouble(bottom: 2)
            };

            this.AddChild(inputRow);

            manualCommandTextEdit = new MHTextEditWidget("", theme, typeFace: ApplicationController.GetTypeFace(NamedTypeFace.Liberation_Mono))
            {
                Margin  = new BorderDouble(right: 3),
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Bottom
            };
            manualCommandTextEdit.ActualTextEditWidget.EnterPressed += (s, e) =>
            {
                SendManualCommand();
            };
            manualCommandTextEdit.ActualTextEditWidget.KeyDown += (s, keyEvent) =>
            {
                bool changeToHistory = false;
                if (keyEvent.KeyCode == Keys.Up)
                {
                    commandHistoryIndex--;
                    if (commandHistoryIndex < 0)
                    {
                        commandHistoryIndex = 0;
                    }

                    changeToHistory = true;
                }
                else if (keyEvent.KeyCode == Keys.Down)
                {
                    commandHistoryIndex++;
                    if (commandHistoryIndex > commandHistory.Count - 1)
                    {
                        commandHistoryIndex = commandHistory.Count - 1;
                    }
                    else
                    {
                        changeToHistory = true;
                    }
                }
                else if (keyEvent.KeyCode == Keys.Escape)
                {
                    manualCommandTextEdit.Text = "";
                }

                if (changeToHistory && commandHistory.Count > 0)
                {
                    manualCommandTextEdit.Text = commandHistory[commandHistoryIndex];
                }
            };
            inputRow.AddChild(manualCommandTextEdit);

            // Footer
            var toolbarPadding = theme.ToolbarPadding;
            var footerRow      = new FlowLayoutWidget
            {
                HAnchor = HAnchor.Stretch,
                Padding = new BorderDouble(0, toolbarPadding.Bottom, toolbarPadding.Right, toolbarPadding.Top)
            };

            this.AddChild(footerRow);

            var sendButton = theme.CreateDialogButton("Send".Localize());

            sendButton.Margin = theme.ButtonSpacing;
            sendButton.Click += (s, e) =>
            {
                SendManualCommand();
            };
            footerRow.AddChild(sendButton);

            var clearButton = theme.CreateDialogButton("Clear".Localize());

            clearButton.Margin = theme.ButtonSpacing;
            clearButton.Click += (s, e) =>
            {
                printer.Connection.TerminalLog.Clear();
            };

            footerRow.AddChild(clearButton);

            var exportButton = theme.CreateDialogButton("Export".Localize());

            exportButton.Margin = theme.ButtonSpacing;
            exportButton.Click += (s, e) =>
            {
                UiThread.RunOnIdle(() =>
                {
                    AggContext.FileDialogs.SaveFileDialog(
                        new SaveFileDialogParams("Save as Text|*.txt")
                    {
                        Title             = "MatterControl: Terminal Log",
                        ActionButtonLabel = "Export",
                        FileName          = "print_log.txt"
                    },
                        (saveParams) =>
                    {
                        if (!string.IsNullOrEmpty(saveParams.FileName))
                        {
                            string filePathToSave = saveParams.FileName;

                            if (filePathToSave != null && filePathToSave != "")
                            {
                                try
                                {
                                    textScrollWidget.WriteToFile(filePathToSave);
                                }
                                catch (UnauthorizedAccessException ex)
                                {
                                    Debug.Print(ex.Message);

                                    printer.Connection.TerminalLog.WriteLine("");
                                    printer.Connection.TerminalLog.WriteLine("WARNING: Write Failed!".Localize());
                                    printer.Connection.TerminalLog.WriteLine("Can't access".Localize() + " " + filePathToSave);
                                    printer.Connection.TerminalLog.WriteLine("");

                                    UiThread.RunOnIdle(() =>
                                    {
                                        StyledMessageBox.ShowMessageBox(ex.Message, "Couldn't save file".Localize());
                                    });
                                }
                            }
                        }
                    });
                });
            };
            footerRow.AddChild(exportButton);

            footerRow.AddChild(new HorizontalSpacer());

            this.AnchorAll();
        }
Exemplo n.º 9
0
        public TerminalWidget(PrinterConfig printer, ThemeConfig theme)
            : base(FlowDirection.TopToBottom)
        {
            this.printer = printer;
            this.Name    = "TerminalWidget";
            this.Padding = new BorderDouble(5, 0);

            // Header
            var headerRow = new FlowLayoutWidget(FlowDirection.LeftToRight)
            {
                HAnchor = HAnchor.Left | HAnchor.Stretch,
                Padding = new BorderDouble(0, 8)
            };

            this.AddChild(headerRow);

            filterOutput = new CheckBox("Filter Output".Localize(), textSize: theme.DefaultFontSize)
            {
                TextColor = theme.TextColor,
                VAnchor   = VAnchor.Bottom,
            };
            filterOutput.CheckedStateChanged += (s, e) =>
            {
                if (filterOutput.Checked)
                {
                    textScrollWidget.SetLineStartFilter(new string[] { "<-wait", "<-ok", "<-T" });
                }
                else
                {
                    textScrollWidget.SetLineStartFilter(null);
                }

                UserSettings.Instance.Fields.SetBool(UserSettingsKey.TerminalFilterOutput, filterOutput.Checked);
            };
            headerRow.AddChild(filterOutput);

            autoUppercase = new CheckBox("Auto Uppercase".Localize(), textSize: theme.DefaultFontSize)
            {
                Margin    = new BorderDouble(left: 25),
                Checked   = UserSettings.Instance.Fields.GetBool(UserSettingsKey.TerminalAutoUppercase, true),
                TextColor = theme.TextColor,
                VAnchor   = VAnchor.Bottom
            };
            autoUppercase.CheckedStateChanged += (s, e) =>
            {
                UserSettings.Instance.Fields.SetBool(UserSettingsKey.TerminalAutoUppercase, autoUppercase.Checked);
            };
            headerRow.AddChild(autoUppercase);

            // Body
            var bodyRow = new FlowLayoutWidget()
            {
                Margin  = new BorderDouble(bottom: 4),
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Stretch
            };

            this.AddChild(bodyRow);

            textScrollWidget = new TextScrollWidget(printer, printer.Connection.TerminalLog.PrinterLines)
            {
                BackgroundColor = theme.MinimalShade,
                TextColor       = theme.TextColor,
                HAnchor         = HAnchor.Stretch,
                VAnchor         = VAnchor.Stretch,
                Margin          = 0,
                Padding         = new BorderDouble(3, 0)
            };
            bodyRow.AddChild(textScrollWidget);
            bodyRow.AddChild(new TextScrollBar(textScrollWidget, 15)
            {
                ThumbColor      = theme.AccentMimimalOverlay,
                BackgroundColor = theme.SlightShade,
                Margin          = 0
            });

            // Input Row
            var inputRow = new FlowLayoutWidget(FlowDirection.LeftToRight)
            {
                BackgroundColor = this.BackgroundColor,
                HAnchor         = HAnchor.Stretch,
                Margin          = new BorderDouble(bottom: 2)
            };

            this.AddChild(inputRow);

            manualCommandTextEdit = new MHTextEditWidget("", theme, typeFace: ApplicationController.GetTypeFace(NamedTypeFace.Liberation_Mono))
            {
                Margin  = new BorderDouble(right: 3),
                HAnchor = HAnchor.Stretch,
                VAnchor = VAnchor.Bottom
            };
            manualCommandTextEdit.ActualTextEditWidget.EnterPressed += (s, e) =>
            {
                SendManualCommand();
            };
            manualCommandTextEdit.ActualTextEditWidget.KeyDown += (s, keyEvent) =>
            {
                bool changeToHistory = false;
                if (keyEvent.KeyCode == Keys.Up)
                {
                    commandHistoryIndex--;
                    if (commandHistoryIndex < 0)
                    {
                        commandHistoryIndex = 0;
                    }
                    changeToHistory = true;
                }
                else if (keyEvent.KeyCode == Keys.Down)
                {
                    commandHistoryIndex++;
                    if (commandHistoryIndex > commandHistory.Count - 1)
                    {
                        commandHistoryIndex = commandHistory.Count - 1;
                    }
                    else
                    {
                        changeToHistory = true;
                    }
                }
                else if (keyEvent.KeyCode == Keys.Escape)
                {
                    manualCommandTextEdit.Text = "";
                }

                if (changeToHistory && commandHistory.Count > 0)
                {
                    manualCommandTextEdit.Text = commandHistory[commandHistoryIndex];
                }
            };
            inputRow.AddChild(manualCommandTextEdit);

            // Footer
            var toolbarPadding = theme.ToolbarPadding;
            var footerRow      = new FlowLayoutWidget
            {
                HAnchor = HAnchor.Stretch,
                Padding = new BorderDouble(0, toolbarPadding.Bottom, toolbarPadding.Right, toolbarPadding.Top)
            };

            this.AddChild(footerRow);

            var sendButton = theme.CreateDialogButton("Send".Localize());

            sendButton.Margin = theme.ButtonSpacing;
            sendButton.Click += (s, e) =>
            {
                SendManualCommand();
            };
            footerRow.AddChild(sendButton);

            var clearButton = theme.CreateDialogButton("Clear".Localize());

            clearButton.Margin = theme.ButtonSpacing;
            clearButton.Click += (s, e) =>
            {
                printer.Connection.TerminalLog.Clear();
            };
            footerRow.AddChild(clearButton);

            var exportButton = theme.CreateDialogButton("Export".Localize());

            exportButton.Margin = theme.ButtonSpacing;
            exportButton.Click += (s, e) =>
            {
                UiThread.RunOnIdle(() =>
                {
                    AggContext.FileDialogs.SaveFileDialog(
                        new SaveFileDialogParams("Save as Text|*.txt")
                    {
                        Title             = "MatterControl: Terminal Log",
                        ActionButtonLabel = "Export",
                        FileName          = "print_log.txt"
                    },
                        (saveParams) =>
                    {
                        if (!string.IsNullOrEmpty(saveParams.FileName))
                        {
                            string filePathToSave = saveParams.FileName;
                            if (filePathToSave != null && filePathToSave != "")
                            {
                                try
                                {
                                    textScrollWidget.WriteToFile(filePathToSave);
                                }
                                catch (UnauthorizedAccessException ex)
                                {
                                    Debug.Print(ex.Message);

                                    printer.Connection.TerminalLog.PrinterLines.Add("");
                                    printer.Connection.TerminalLog.PrinterLines.Add(writeFaildeWaring);
                                    printer.Connection.TerminalLog.PrinterLines.Add(cantAccessPath.FormatWith(filePathToSave));
                                    printer.Connection.TerminalLog.PrinterLines.Add("");

                                    UiThread.RunOnIdle(() =>
                                    {
                                        StyledMessageBox.ShowMessageBox(ex.Message, "Couldn't save file".Localize());
                                    });
                                }
                            }
                        }
                    });
                });
            };
            footerRow.AddChild(exportButton);

            footerRow.AddChild(new HorizontalSpacer());

            this.AnchorAll();
        }