Ejemplo n.º 1
0
        private void HandleKeyboardInput(EditInputType type, string detail)
        {
            if (NavigationTypeMap.ContainsKey(type))
            {
                this.pageCollection.NavigateCursor(NavigationTypeMap[type]);
                return;
            }

            if (type == EditInputType.Escape)
            {
                this.keyboardInput.Stop();
                return;
            }

            if (type == EditInputType.Input)
            {
                var buffer = new DocumentBuffer(this.elementFactory, this.textScoper);
                buffer.Append(detail, this.pageCollection.GetCurrentFlags());
                this.pageCollection.Insert(buffer, null);
                return;
            }


            throw new Exception("Unhandled input type: " + type);
        }
Ejemplo n.º 2
0
        public void AppendPeekAndGetTextWithSameFlags()
        {
            // Arrange
            var flags = new Flags()
            {
                FontSize = 12,
                Font     = "x"
            };
            var initialWidth = 30;
            var constraint   = new DimensionConstraint()
            {
                MaxHeight = 12, MaxWidth = initialWidth
            };
            var text = "A string";

            // The whole text can fit within the given width
            textScoperMock.Setup(ts => ts.GetFittingText(flags.Font, flags.FontSize, text, initialWidth)).Returns(text);

            // Act
            bufferUnderTest.Append(text, flags);

            var peekedText   = bufferUnderTest.Peek(constraint, flags);
            var takenText    = bufferUnderTest.Take(constraint, flags);
            var bufferEmpty1 = bufferUnderTest.EndOfBuffer();

            bufferUnderTest.Append(text, flags);
            var peekedObject = (FormattedTextMock)bufferUnderTest.Peek(constraint);
            var takenObject  = (FormattedTextMock)bufferUnderTest.Take(constraint);
            var bufferEmpty2 = bufferUnderTest.EndOfBuffer();

            // Assert
            Assert.AreEqual(text, peekedText);
            Assert.AreEqual(text, takenText);
            Assert.IsTrue(bufferEmpty1, "The buffer should be empty");

            Assert.AreEqual(text, peekedObject.Text);
            Assert.AreEqual(false, peekedObject.AllowZeroPosition);
            Assert.AreEqual(flags, peekedObject.Flags);
            Assert.AreEqual(text, takenObject.Text);
            Assert.AreEqual(false, takenObject.AllowZeroPosition);
            Assert.AreEqual(flags, takenObject.Flags);
            Assert.IsTrue(bufferEmpty2, "The buffer should be empty");
        }