Beispiel #1
0
        public void Initialize(bool useSyntaxColoring)
        {
            ContextMenuStrip oldContextMenuStrip = null;
            var oldEnabled = true;
            var oldText    = string.Empty;

            if (_simpleTextBox != null)
            {
                oldContextMenuStrip = _simpleTextBox.ContextMenuStrip;
                oldEnabled          = _simpleTextBox.Enabled;
                oldText             = _simpleTextBox.Text;
            }
            else if (_uiTextBox != null)
            {
                oldContextMenuStrip = _uiTextBox.ContextMenuStrip;
                oldEnabled          = _uiTextBox.Enabled;
                oldText             = _uiTextBox.Text;
            }

            BorderStyle = BorderStyle.None;
            Padding     = new Padding(1);
            BackColor   = SystemColors.WindowFrame;
            Controls.Clear();
            _simpleTextBox?.Dispose();
            _uiTextBox?.Dispose();
            _simpleTextBox = null;
            _uiTextBox     = null;
            if (useSyntaxColoring)
            {
                _uiTextBox = new AdvancedTextBox {
                    BorderStyle = BorderStyle.None, Multiline = true
                };
                InitializeBackingControl(_uiTextBox);
                UpdateFontAndColors(_uiTextBox);
            }
            else
            {
                _simpleTextBox = new SimpleTextBox {
                    BorderStyle = BorderStyle.None, Multiline = true
                };
                InitializeBackingControl(_simpleTextBox);
                UpdateFontAndColors(_simpleTextBox);
            }

            if (oldContextMenuStrip != null)
            {
                ContextMenuStrip = oldContextMenuStrip;
            }

            Enabled = oldEnabled;
            Text    = oldText;
        }
Beispiel #2
0
        public void Initialize(bool useSyntaxColoring)
        {
            ContextMenuStrip oldContextMenuStrip = null;
            var oldEnabled = true;

            if (_simpleTextBox != null)
            {
                oldContextMenuStrip = _simpleTextBox.ContextMenuStrip;
                oldEnabled          = _simpleTextBox.Enabled;
            }
            else if (_uiTextBox != null)
            {
                oldContextMenuStrip = _uiTextBox.ContextMenuStrip;
                oldEnabled          = _uiTextBox.Enabled;
            }

            BorderStyle = BorderStyle.None;
            Padding     = new Padding(1);
            BackColor   = SystemColors.WindowFrame;
            Controls.Clear();
            _simpleTextBox?.Dispose();
            _richTextBoxTemp?.Dispose();
            _uiTextBox?.Dispose();
            _simpleTextBox   = null;
            _uiTextBox       = null;
            _richTextBoxTemp = null;
            if (useSyntaxColoring)
            {
                _richTextBoxTemp = new RichTextBox();
                _uiTextBox       = new RichTextBox {
                    BorderStyle = BorderStyle.None, Multiline = true
                };
                InitializeBackingControl(_uiTextBox);

                // avoid selection when centered and clicking to the left
                _uiTextBox.MouseDown += (sender, args) =>
                {
                    var charIndex = _uiTextBox.GetCharIndexFromPosition(args.Location);
                    if (Configuration.Settings.General.CenterSubtitleInTextBox &&
                        _mouseMoveSelectionLength == 0 &&
                        (charIndex == 0 || charIndex >= 0 && _uiTextBox.Text[charIndex - 1] == '\n'))
                    {
                        _uiTextBox.SelectionLength = 0;
                    }
                };
                _uiTextBox.MouseMove += (sender, args) =>
                {
                    _mouseMoveSelectionLength = _uiTextBox.SelectionLength;
                };
                _uiTextBox.KeyDown += (sender, args) =>
                {
                    // fix annoying "beeps" when moving cursor position
                    if ((args.KeyData == Keys.Left || args.KeyData == Keys.PageUp) && _uiTextBox.SelectionStart == 0)
                    {
                        args.SuppressKeyPress = true;
                    }
                    else if (args.KeyData == Keys.Up && _uiTextBox.SelectionStart <= _uiTextBox.Text.IndexOf('\n'))
                    {
                        args.SuppressKeyPress = true;
                    }
                    else if (args.KeyData == Keys.Home && (_uiTextBox.SelectionStart == 0 || _uiTextBox.SelectionStart > 0 && _uiTextBox.Text[_uiTextBox.SelectionStart - 1] == '\n'))
                    {
                        args.SuppressKeyPress = true;
                    }
                    else if (args.KeyData == (Keys.Home | Keys.Control) && _uiTextBox.SelectionStart == 0)
                    {
                        args.SuppressKeyPress = true;
                    }
                    else if (args.KeyData == Keys.End && (_uiTextBox.SelectionStart >= _uiTextBox.Text.Length || _uiTextBox.SelectionStart + 1 < _uiTextBox.Text.Length && _uiTextBox.Text[_uiTextBox.SelectionStart] == '\n'))
                    {
                        args.SuppressKeyPress = true;
                    }
                    else if (args.KeyData == (Keys.End | Keys.Control) && _uiTextBox.SelectionStart >= _uiTextBox.Text.Length)
                    {
                        args.SuppressKeyPress = true;
                    }
                    else if (args.KeyData == Keys.Right && _uiTextBox.SelectionStart >= _uiTextBox.Text.Length)
                    {
                        args.SuppressKeyPress = true;
                    }
                    else if (args.KeyData == Keys.Down && _uiTextBox.SelectionStart >= _uiTextBox.Text.Length)
                    {
                        args.SuppressKeyPress = true;
                    }
                    else if (args.KeyData == Keys.PageDown && _uiTextBox.SelectionStart >= _uiTextBox.Text.Length)
                    {
                        args.SuppressKeyPress = true;
                    }
                };
            }
            else
            {
                _simpleTextBox = new SimpleTextBox {
                    BorderStyle = BorderStyle.None, Multiline = true
                };
                _simpleTextBox.KeyDown += (sender, args) =>
                {
                    if (args.KeyData == (Keys.Control | Keys.Back))
                    {
                        UiUtil.ApplyControlBackspace(_simpleTextBox);
                        args.SuppressKeyPress = true;
                    }
                };
                InitializeBackingControl(_simpleTextBox);
            }

            UpdateFontAndColors();
            if (oldContextMenuStrip != null)
            {
                ContextMenuStrip = oldContextMenuStrip;
            }

            Enabled = oldEnabled;
        }
Beispiel #3
0
        public void Initialize(bool useSyntaxColoring)
        {
            ContextMenuStrip oldContextMenuStrip = null;
            var oldEnabled = true;
            var oldText    = string.Empty;

            if (_simpleTextBox != null)
            {
                oldContextMenuStrip = _simpleTextBox.ContextMenuStrip;
                oldEnabled          = _simpleTextBox.Enabled;
                oldText             = _simpleTextBox.Text;
            }
            else if (_uiTextBox != null)
            {
                oldContextMenuStrip = _uiTextBox.ContextMenuStrip;
                oldEnabled          = _uiTextBox.Enabled;
                oldText             = _uiTextBox.Text;
            }

            BorderStyle = BorderStyle.None;
            Padding     = new Padding(1);
            BackColor   = SystemColors.WindowFrame;
            Controls.Clear();
            _simpleTextBox?.Dispose();
            _richTextBoxTemp?.Dispose();
            _uiTextBox?.Dispose();
            _simpleTextBox   = null;
            _uiTextBox       = null;
            _richTextBoxTemp = null;
            if (useSyntaxColoring)
            {
                _richTextBoxTemp = new RichTextBox();
                _uiTextBox       = new RichTextBox {
                    BorderStyle = BorderStyle.None, Multiline = true
                };
                InitializeBackingControl(_uiTextBox);

                _uiTextBox.TextChanged += TextChangedHighlight;
                // avoid selection when centered and clicking to the left
                _uiTextBox.MouseDown += (sender, args) =>
                {
                    var charIndex = _uiTextBox.GetCharIndexFromPosition(args.Location);
                    if (Configuration.Settings.General.CenterSubtitleInTextBox &&
                        _mouseMoveSelectionLength == 0 &&
                        (charIndex == 0 || charIndex >= 0 && _uiTextBox.Text[charIndex - 1] == '\n'))
                    {
                        _uiTextBox.SelectionLength = 0;
                    }
                };
                _uiTextBox.MouseMove += (sender, args) =>
                {
                    _mouseMoveSelectionLength = _uiTextBox.SelectionLength;
                };
                _uiTextBox.KeyDown += (sender, args) =>
                {
                    // fix annoying "beeps" when moving cursor position
                    if ((args.KeyData == Keys.Left || args.KeyData == Keys.PageUp) && _uiTextBox.SelectionStart == 0)
                    {
                        args.SuppressKeyPress = true;
                    }
                    else if (args.KeyData == Keys.Up && _uiTextBox.SelectionStart <= _uiTextBox.Text.IndexOf('\n'))
                    {
                        args.SuppressKeyPress = true;
                    }
                    else if (args.KeyData == Keys.Home && (_uiTextBox.SelectionStart == 0 || _uiTextBox.SelectionStart > 0 && _uiTextBox.Text[_uiTextBox.SelectionStart - 1] == '\n'))
                    {
                        args.SuppressKeyPress = true;
                    }
                    else if (args.KeyData == (Keys.Home | Keys.Control) && _uiTextBox.SelectionStart == 0)
                    {
                        args.SuppressKeyPress = true;
                    }
                    else if (args.KeyData == Keys.End && (_uiTextBox.SelectionStart >= _uiTextBox.Text.Length || _uiTextBox.SelectionStart + 1 < _uiTextBox.Text.Length && _uiTextBox.Text[_uiTextBox.SelectionStart] == '\n'))
                    {
                        args.SuppressKeyPress = true;
                    }
                    else if (args.KeyData == (Keys.End | Keys.Control) && _uiTextBox.SelectionStart >= _uiTextBox.Text.Length)
                    {
                        args.SuppressKeyPress = true;
                    }
                    else if (args.KeyData == Keys.Right && _uiTextBox.SelectionStart >= _uiTextBox.Text.Length)
                    {
                        args.SuppressKeyPress = true;
                    }
                    else if (args.KeyData == Keys.Down && _uiTextBox.SelectionStart >= _uiTextBox.Text.Length)
                    {
                        args.SuppressKeyPress = true;
                    }
                    else if (args.KeyData == Keys.PageDown && _uiTextBox.SelectionStart >= _uiTextBox.Text.Length)
                    {
                        args.SuppressKeyPress = true;
                    }
                };
                _uiTextBox.Enter += (sender, args) =>
                {
                    var text = _uiTextBox.Text;
                    if (string.IsNullOrWhiteSpace(text) || text.Length > 1000)
                    {
                        if (Configuration.Settings.General.CenterSubtitleInTextBox)
                        {
                            SuspendLayout();
                            _richTextBoxTemp.Text = text;
                            _richTextBoxTemp.SelectAll();
                            _richTextBoxTemp.SelectionAlignment = HorizontalAlignment.Center;
                            ResumeLayout(false);
                            _uiTextBox.Rtf = _richTextBoxTemp.Rtf;
                        }
                    }
                };
            }
            else
            {
                _simpleTextBox = new SimpleTextBox {
                    BorderStyle = BorderStyle.None, Multiline = true
                };
                InitializeBackingControl(_simpleTextBox);
            }

            UpdateFontAndColors();
            if (oldContextMenuStrip != null)
            {
                ContextMenuStrip = oldContextMenuStrip;
            }

            Enabled = oldEnabled;
            Text    = oldText;
        }