Esempio n. 1
0
 public StringFormattingCollection(MASMFormattingEditor editor, Control view)
 {
     this.editor = editor;
     this.view   = view;
 }
        protected virtual MASMFormattingEditor CreateLogDataEditor()
        {
            MASMFormattingEditor editor = new MASMFormattingEditor
            {
                Text = "Serial Port Data Editor",
            };

            editor.AvailableProperties = () =>
            {
                return(new List <string>(new MASM().UpdateOnce().GetPropertiesList()));
            };

            editor.Items.AddRange(this.Server.Settings.DataFormatter.FormattingItems);

            InputField globalPrefixField = new InputField {
                Text = this.Server.Settings.DataFormatter.GlobalPrefix
            };
            InputField globalPostfixField = new InputField {
                Text = this.Server.Settings.DataFormatter.GlobalPostfix
            };
            InputField decimalSeparatorField = new InputField {
                Text = this.Server.Settings.DataFormatter.DecimalSeparator
            };
            Dropdown encodingField = new Dropdown {
            };

            encodingField.FromEnum(this.Server.Settings.Encoding);
            InputField endOfLineCharField = new InputField {
                Text = this.Server.Settings.EndOfLineChar
            };


            PropertyContainer globalPrefixProperty = new PropertyContainer {
                Text = "Global Prefix"
            };
            PropertyContainer globalPostfixProperty = new PropertyContainer {
                Text = "Global Postfix"
            };
            PropertyContainer decimalSeparatorProperty = new PropertyContainer {
                Text = "Decimal Separator"
            };
            PropertyContainer encodingProperty = new PropertyContainer {
                Text = "Encoding"
            };
            PropertyContainer endOfLineCharProperty = new PropertyContainer {
                Text = "End Of Line Character"
            };


            globalPrefixProperty.Controls.Add(globalPrefixField);
            globalPostfixProperty.Controls.Add(globalPostfixField);
            decimalSeparatorProperty.Controls.Add(decimalSeparatorField);
            encodingProperty.Controls.Add(encodingField);
            endOfLineCharProperty.Controls.Add(endOfLineCharField);

            editor.AdditionalProperties.Add(globalPrefixProperty);
            editor.AdditionalProperties.Add(globalPostfixProperty);
            editor.AdditionalProperties.Add(decimalSeparatorProperty);
            editor.AdditionalProperties.Add(encodingProperty);
            editor.AdditionalProperties.Add(endOfLineCharProperty);

            editor.Apply += (object sender, EventArgs e) =>
            {
                if (editor.Items.Count != this.Server.Settings.DataFormatter.FormattingItems.Count)
                {
                    this.Server.Settings.DataFormatter.FormattingItems.Clear();
                    this.Server.Settings.DataFormatter.FormattingItems.AddRange(editor.Items);
                }
                else
                {
                    for (int i = 0; i < editor.Items.Count; i++)
                    {
                        this.Server.Settings.DataFormatter.FormattingItems[i] = editor.Items[i];
                    }
                }

                this.Server.Settings.DataFormatter.GlobalPrefix     = globalPrefixField.Text;
                this.Server.Settings.DataFormatter.GlobalPostfix    = globalPostfixField.Text;
                this.Server.Settings.DataFormatter.DecimalSeparator = decimalSeparatorField.Text;
                this.Server.Settings.Encoding      = encodingField.ToEnum(SerialPortEncoding.UTF8);
                this.Server.Settings.EndOfLineChar = endOfLineCharField.Text;

                editor.Dispose();
            };

            editor.Cancel += (object sender, EventArgs e) =>
            {
                editor.Dispose();
            };

            return(editor);
        }
        protected virtual MASMFormattingEditor CreateLogDataEditor()
        {
            MASMFormattingEditor editor = new MASMFormattingEditor
            {
                Text = "Log Data Editor",
            };

            editor.AvailableProperties = () =>
            {
                List <string> properties = new List <string>(new MASM().UpdateOnce().GetPropertiesList());

                if (Server.Settings.UseFrametimeMode == true)
                {
                    properties.Insert(0, "RTSS Frame duration");
                    properties.Insert(0, "RTSS Frame time");
                    properties.Insert(0, "RTSS Current frame");
                }

                return(properties);
            };

            editor.Items.AddRange(this.Server.Settings.DataFormatter.FormattingItems);

            InputField startTextField = new InputField {
                Text = this.Server.Settings.StartText
            };
            InputField finalTextField = new InputField {
                Text = this.Server.Settings.FinalText
            };
            InputField globalPrefixField = new InputField {
                Text = this.Server.Settings.DataFormatter.GlobalPrefix
            };
            InputField globalPostfixField = new InputField {
                Text = this.Server.Settings.DataFormatter.GlobalPostfix
            };
            InputField decimalSeparatorField = new InputField {
                Text = this.Server.Settings.DataFormatter.DecimalSeparator
            };

            PropertyContainer startTextProperty = new PropertyContainer {
                Text = "Start Text"
            };
            PropertyContainer finalTextProperty = new PropertyContainer {
                Text = "Final Text"
            };
            PropertyContainer globalPrefixProperty = new PropertyContainer {
                Text = "Global Prefix"
            };
            PropertyContainer globalPostfixProperty = new PropertyContainer {
                Text = "Global Postfix"
            };
            PropertyContainer decimalSeparatorProperty = new PropertyContainer {
                Text = "Decimal Separator"
            };

            startTextProperty.Controls.Add(startTextField);
            finalTextProperty.Controls.Add(finalTextField);
            globalPrefixProperty.Controls.Add(globalPrefixField);
            globalPostfixProperty.Controls.Add(globalPostfixField);
            decimalSeparatorProperty.Controls.Add(decimalSeparatorField);

            editor.AdditionalProperties.Add(startTextProperty);
            editor.AdditionalProperties.Add(finalTextProperty);
            editor.AdditionalProperties.Add(globalPrefixProperty);
            editor.AdditionalProperties.Add(globalPostfixProperty);
            editor.AdditionalProperties.Add(decimalSeparatorProperty);

            editor.Apply += (object sender, EventArgs e) =>
            {
                if (editor.Items.Count != this.Server.Settings.DataFormatter.FormattingItems.Count)
                {
                    this.Server.Settings.DataFormatter.FormattingItems.Clear();
                    this.Server.Settings.DataFormatter.FormattingItems.AddRange(editor.Items);
                }
                else
                {
                    for (int i = 0; i < editor.Items.Count; i++)
                    {
                        this.Server.Settings.DataFormatter.FormattingItems[i] = editor.Items[i];
                    }
                }

                this.Server.Settings.StartText = startTextField.Text;
                this.Server.Settings.FinalText = finalTextField.Text;
                this.Server.Settings.DataFormatter.GlobalPrefix     = globalPrefixField.Text;
                this.Server.Settings.DataFormatter.GlobalPostfix    = globalPostfixField.Text;
                this.Server.Settings.DataFormatter.DecimalSeparator = decimalSeparatorField.Text;

                editor.Dispose();
            };

            editor.Cancel += (object sender, EventArgs e) =>
            {
                editor.Dispose();
            };

            return(editor);
        }