Example #1
0
        public void TestUndoRedoCommand()
        {
            // Arrange
            var project = new Project();
            var context = new BlockCommandContext(project);
            ProjectBlockCollection blocks = project.Blocks;
            Block block = blocks[0];

            using (block.AcquireBlockLock(RequestLock.Write))
            {
                block.SetText("abcd");
            }
            int      blockVersion = block.Version;
            BlockKey blockKey     = block.BlockKey;

            var command = new DeleteTextCommand(new BlockPosition(blockKey, 2), 3);

            project.Commands.Do(command, context);
            project.Commands.Undo(context);

            // Act
            project.Commands.Redo(context);

            // Assert
            Assert.AreEqual(1, blocks.Count);
            Assert.AreEqual(
                new BlockPosition(blocks[0], 2), project.Commands.LastPosition);

            const int index = 0;

            Assert.AreEqual("abd", blocks[index].Text);
            Assert.AreEqual(blockVersion + 3, blocks[index].Version);
        }
        public ProjectDeleteTextCommand(
            Project project,
            SingleLineTextRange range)
            : base(project)
        {
            // Create the project command wrapper.
            var command = new DeleteTextCommand(range);

            // Set the command into the adapter.
            Command = command;
        }
Example #3
0
        /// <summary>
        /// 删除与笔迹strokes相交的文本
        /// </summary>
        /// <param name="myGraphicStrokes"></param>
        public void removeHitTextBoxes(StrokeCollection myGraphicStrokes)
        {
            List <MyRichTextBox> myRichTextBoxs = new List <MyRichTextBox>();

            foreach (MyRichTextBox myRichTextBox in Sketch.MyRichTextBoxs)
            {
                Rect rectMyRichTextBox = new Rect(new Point(myRichTextBox.RichTextBox.Margin.Left, myRichTextBox.RichTextBox.Margin.Top),
                                                  new Point(myRichTextBox.RichTextBox.Margin.Left + myRichTextBox.RichTextBox.Width,
                                                            myRichTextBox.RichTextBox.Margin.Top + myRichTextBox.RichTextBox.Height));
                if (MathTool.getInstance().isHitRects(myGraphicStrokes.GetBounds(), rectMyRichTextBox) == true)
                {
                    myRichTextBoxs.Add(myRichTextBox);
                }
            }
            foreach (MyRichTextBox myRichTextBox in myRichTextBoxs)
            {
                Command dtc = new DeleteTextCommand(this, myRichTextBox);
                dtc.execute();
                CommandStack.Push(dtc);
            }
        }
Example #4
0
        /// <summary>
        /// 按下左键的时候
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        public override void _presenter_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
        {
            //创建一个richTextBox
            _inkCanvas.CaptureMouse();
            List <MyRichTextBox> emptyMyRichTextBoxs = new List <MyRichTextBox>();

            foreach (MyRichTextBox myRichTextBox in _inkCollector.Sketch.MyRichTextBoxs)
            {
                TextRange textRangeOld  = new TextRange(myRichTextBox.RichTextBox.Document.ContentStart, myRichTextBox.RichTextBox.Document.ContentEnd);
                string    textRangeStr1 = textRangeOld.Text.Replace(" ", "");
                string    textRangeStr2 = textRangeStr1.Replace("\r\n", "");
                if (textRangeStr2 == "")
                {
                    emptyMyRichTextBoxs.Add(myRichTextBox);
                }
            }
            foreach (MyRichTextBox myRichTextBox in emptyMyRichTextBoxs)
            {
                DeleteTextCommand dtc = new DeleteTextCommand(_inkCollector, myRichTextBox);
                dtc.execute();
            }
            _richTextBox                     = new RichTextBox();
            _startpoint                      = e.GetPosition(_inkCanvas);
            _richTextBox.Margin              = new Thickness(_startpoint.Value.X, _startpoint.Value.Y, 0, 0);
            _richTextBox.Background          = new SolidColorBrush(Colors.Transparent);
            _richTextBox.AcceptsReturn       = true;
            _richTextBox.BorderBrush         = new SolidColorBrush(Colors.Blue);
            _richTextBox.GotFocus           += new RoutedEventHandler(_richTextBox_GotFocus);
            _richTextBox.LostFocus          += new RoutedEventHandler(_richTextBox_LostFocus);
            _richTextBox.HorizontalAlignment = HorizontalAlignment.Left;
            _richTextBox.VerticalAlignment   = VerticalAlignment.Top;
            TextRange textRange = new TextRange(_richTextBox.Document.ContentStart, _richTextBox.Document.ContentEnd);

            textRange.ApplyPropertyValue(RichTextBox.FontFamilyProperty, _inkFrame.TextFontFamily);
            textRange.ApplyPropertyValue(RichTextBox.FontSizeProperty, "60");                               //_inkFrame.TextFontSize);
            textRange.ApplyPropertyValue(RichTextBox.ForegroundProperty, new SolidColorBrush(Colors.Blue)); //_inkFrame.TextFontColor);
            textRange.ApplyPropertyValue(RichTextBox.FontWeightProperty, _inkFrame.TextFontWeight);
            textRange.ApplyPropertyValue(RichTextBox.FontStyleProperty, _inkFrame.TextFontStyle);
        }