예제 #1
0
        private void TouchpadOnGesture(object sender, GestureEventArgs gestureEventArgs)
        {
            if (gestureEventArgs.GestureType != RazerAPI.GestureType.Tap)
            {
                return;
            }

            var x = gestureEventArgs.X;
            var y = gestureEventArgs.Y;

            var titlePosition   = NoteTitleBox.TransformToAncestor(Application.Current.MainWindow).Transform(new Point(0, 0));
            var contentPosition = NoteContentBox.TransformToAncestor(Application.Current.MainWindow).Transform(new Point(0, 0));

            var capturing = SharpBladeHelper.Manager.KeyboardCapture;

            if (x >= titlePosition.X && x <= titlePosition.X + NoteTitleBox.Width &&
                y >= titlePosition.Y && y <= titlePosition.Y + NoteTitleBox.Height)
            {
                SharpBladeHelper.Manager.StartWPFControlKeyboardCapture(NoteTitleBox);
                if (_clearTitle)
                {
                    NoteTitleBox.Clear();
                    _clearTitle = false;
                }
                _caretManager = new CaretManager(NoteTitleBox, NoteTitleBox.Text.Length);
                HighlightInput(NoteTitleBox);
                UnhighlightInput(NoteContentBox);
            }
            else if (x >= contentPosition.X && x <= contentPosition.X + NoteContentBox.Width &&
                     y >= contentPosition.Y && y <= contentPosition.Y + NoteContentBox.Height)
            {
                SharpBladeHelper.Manager.StartWPFControlKeyboardCapture(NoteContentBox, false);
                if (_clearContent)
                {
                    NoteContentBox.Clear();
                    _clearContent = false;
                }
                _caretManager = new CaretManager(NoteContentBox, NoteContentBox.Text.Length);
                HighlightInput(NoteContentBox);
                UnhighlightInput(NoteTitleBox);
            }
            else if (capturing)
            {
                SharpBladeHelper.Manager.SetKeyboardCapture(false);
                DisposeCaretManager();
                UnhighlightInput(NoteContentBox);
                UnhighlightInput(NoteTitleBox);
            }
        }
예제 #2
0
        private void NoteContentBox_PreviewKeyDown(object sender, KeyEventArgs e)
        {
            if (Keyboard.IsKeyDown(Key.LeftCtrl) || Keyboard.IsKeyDown(Key.RightShift))
            {
                return;
            }
            int selectionStart = NoteContentBox.SelectionStart;
            int y = NoteContentBox.GetLineIndexFromCharacterIndex(selectionStart);
            int x = selectionStart - NoteContentBox.GetCharacterIndexFromLineIndex(y);

            if (e.Key == Key.Tab && bool.Parse(configuration.AppSettings.Settings["TabToSpace"].Value))
            {
                String tab           = new String(' ', tabsize - (x % tabsize));
                int    caretPosition = NoteContentBox.CaretIndex;
                NoteContentBox.Text       = NoteContentBox.Text.Insert(caretPosition, tab);
                NoteContentBox.CaretIndex = caretPosition + tabsize - (x % tabsize);
                e.Handled = true;
            }
            else if (e.Key == Key.Enter)
            {
                if (NoteContentBox.Text.Split(Environment.NewLine).Any())
                {
                    Match match = Regex.Match(NoteContentBox.Text.Split(Environment.NewLine)[y], @"^\s*[-*>+]\s");

                    if (match.Success && x >= match.Index + match.Length)
                    {
                        NoteContentBox.Text       = NoteContentBox.Text.Insert(NoteContentBox.CaretIndex, $"{Environment.NewLine}{match.Value}");
                        NoteContentBox.CaretIndex = selectionStart + match.Index + match.Length + Environment.NewLine.Length;
                        e.Handled = true;
                        return;
                    }
                    match = Regex.Match(NoteContentBox.Text.Split(Environment.NewLine)[y], @"^\s*([1-9][0-9]*)\.\s");
                    if (match.Success && x >= match.Index + match.Length)
                    {
                        int newValue = int.Parse(match.Groups[1].Value) + 1;
                        NoteContentBox.Text = NoteContentBox.Text.Insert(NoteContentBox.CaretIndex,
                                                                         $"{Environment.NewLine}{match.Value.Replace(match.Groups[1].Value, newValue.ToString())}");
                        NoteContentBox.CaretIndex = selectionStart + match.Index + match.Length
                                                    + Environment.NewLine.Length + (newValue.ToString().Length > (newValue - 1).ToString().Length ? 1 : 0);
                        e.Handled = true;
                        return;
                    }
                }
            }
        }