Esempio n. 1
0
        private void ApplyCustomStyles_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Escape)
            {
                if (_intellisenseList != null && _intellisenseList.Focused)
                {
                    return;
                }

                DialogResult = DialogResult.Cancel;
            }
            else if (e.KeyData == UiUtil.HelpKeys)
            {
                if (_intellisenseList != null && _intellisenseList.Focused)
                {
                    return;
                }

                UiUtil.OpenUrl("https://www.nikse.dk/SubtitleEdit/AssaOverrideTags");
                e.SuppressKeyPress = true;
            }
            else if (MainTextBoxAssaIntellisense == e.KeyData)
            {
                if (_intellisenseList != null && _intellisenseList.Focused)
                {
                    _intellisenseList.Hide();
                }
                else
                {
                    _intellisenseList = DoIntellisense(seTextBox1, _intellisenseList);
                }

                e.SuppressKeyPress = true;
            }
            else if (MainTextBoxAssaRemoveTag == e.KeyData)
            {
                AssaTagHelper.RemoveTagAtCursor(seTextBox1);
                e.SuppressKeyPress = true;
            }
        }
Esempio n. 2
0
        private ListBox DoIntellisense(SETextBox tb, ListBox intellisenseListBox)
        {
            if (intellisenseListBox == null)
            {
                intellisenseListBox = new ListBox();
                Controls.Add(intellisenseListBox);
                intellisenseListBox.PreviewKeyDown += (o, args) =>
                {
                    if (args.KeyCode == Keys.Tab && intellisenseListBox.SelectedIndex >= 0)
                    {
                        if (intellisenseListBox.Items[intellisenseListBox.SelectedIndex] is AssaTagHelper.IntellisenseItem item)
                        {
                            AssaTagHelper.CompleteItem(tb, item);
                        }

                        intellisenseListBox.Hide();
                        System.Threading.SynchronizationContext.Current.Post(TimeSpan.FromMilliseconds(10), () => tb.Focus());
                    }
                };
                intellisenseListBox.KeyDown += (o, args) =>
                {
                    if (args.KeyCode == Keys.Enter && intellisenseListBox.SelectedIndex >= 0)
                    {
                        if (intellisenseListBox.Items[intellisenseListBox.SelectedIndex] is AssaTagHelper.IntellisenseItem item)
                        {
                            AssaTagHelper.CompleteItem(tb, item);
                        }

                        args.SuppressKeyPress = true;
                        args.Handled          = true;
                        intellisenseListBox.Hide();
                        tb.Focus();
                    }
                    else if (args.KeyCode == Keys.Escape || MainTextBoxAssaIntellisense == args.KeyData)
                    {
                        args.SuppressKeyPress = true;
                        args.Handled          = true;
                        intellisenseListBox.Hide();
                        tb.Focus();
                    }
                };
                intellisenseListBox.Click += (o, args) =>
                {
                    var index = intellisenseListBox.IndexFromPoint(((MouseEventArgs)args).Location);
                    if (index != ListBox.NoMatches)
                    {
                        if (intellisenseListBox.Items[index] is AssaTagHelper.IntellisenseItem item)
                        {
                            AssaTagHelper.CompleteItem(tb, item);
                        }

                        intellisenseListBox.Hide();
                        tb.Focus();
                    }
                };
                intellisenseListBox.KeyPress += (o, args) =>
                {
                    var x = args.KeyChar.ToString();
                    if (!string.IsNullOrEmpty(x) && x != "\r" && x != "\n" && x != "\u001b" && x != " ")
                    {
                        if (x == "{")
                        {
                            x = "{{}";
                        }
                        else if (x == "}")
                        {
                            x = "{}}";
                        }

                        tb.Focus();
                        SendKeys.SendWait(x);
                        args.Handled = true;
                        AssaTagHelper.AutoCompleteTextBox(tb, intellisenseListBox);
                        intellisenseListBox.Focus();
                    }
                };
                intellisenseListBox.LostFocus += (o, args) => intellisenseListBox.Hide();
            }

            if (AssaTagHelper.AutoCompleteTextBox(tb, intellisenseListBox))
            {
                var p = GetPositionInForm(tb);
                intellisenseListBox.Location = new Point(p.X + 10, p.Y + 30); //TODO: improve position
                intellisenseListBox.Height   = 185;
                intellisenseListBox.Show();
                intellisenseListBox.BringToFront();
                intellisenseListBox.Focus();
            }

            return(intellisenseListBox);
        }