示例#1
0
        /// <summary>
        /// Sets up the basic unit tests with set strings and controls.
        /// </summary>
        private void SetupTests(
            out EditorViewController controller,
            out Caret caret,
            out LineBuffer lineBuffer)
        {
            // Set up Gtk so we can create the view.
            Application.Init();

            // Set up an editor without a cached renderer and a memory buffer
            // we can easily verify.
            var view = new EditorView();

            caret      = view.Caret;
            lineBuffer = new MemoryLineBuffer();
            controller = view.Controller;
            var renderer = new LineBufferRenderer(view, lineBuffer);

            view.SetRenderer(renderer);

            // Create three lines of text.
            TextActions.InsertText(controller, DefaultLine);
            TextActions.InsertParagraph(controller);
            TextActions.InsertText(controller, DefaultLine);
            TextActions.InsertParagraph(controller);
            TextActions.InsertText(controller, DefaultLine);
        }
        /// <summary>
        /// Handles a key press and performs the appropriate action.
        /// </summary>
        /// <param name="key">The key.</param>
        /// <param name="unicodeKey">The Unicode key.</param>
        /// <param name="modifier">The modifier.</param>
        public bool HandleKeyPress(
            Key key,
            ModifierType modifier,
            uint unicodeKey)
        {
            // Normalize the key code and remove excessive modifiers.
            ModifierType filteredModifiers = modifier
                                             & (ModifierType.ShiftMask | ModifierType.Mod1Mask | ModifierType.ControlMask
                                                | ModifierType.MetaMask | ModifierType.SuperMask);
            int keyCode = GdkUtility.GetNormalizedKeyCode(key, filteredModifiers);

            // Check to see if we have an action for this.
            ModifierType isNormalOrShifted = filteredModifiers & ~ModifierType.ShiftMask;
            bool         isCharacter       = unicodeKey != 0 && isNormalOrShifted == ModifierType.None;
            bool         isAction          = keyBindings.ContainsKey(keyCode);

            if (isAction || isCharacter)
            {
                // Keep track of the original selection.
                TextRange previousSelection = displayContext.Caret.Selection;

                // Mark that we are starting a new action and fire events so
                // other listeners and handle it.
                InAction = true;

                // Perform the appropriate action.
                try
                {
                    if (isAction)
                    {
                        keyBindings[keyCode].Perform(this);
                    }
                    else
                    {
                        TextActions.InsertText(this, (char)unicodeKey);
                    }
                }
                finally
                {
                    InAction = false;
                }

                // Check to see if the selection changed.
                if (previousSelection != displayContext.Caret.Selection)
                {
                    displayContext.Renderer.UpdateSelection(displayContext, previousSelection);
                }

                // We did something, so return processed.
                return(true);
            }

            // No idea what to do, so don't do anything.
            return(false);
        }
        public void InsertTextUsingTextActionString()
        {
            // Setup

            // Operation
            TextActions.InsertText(controller, "Test");

            // Verification
            Assert.AreEqual(1, buffer.LineCount);
            Assert.AreEqual("Test", buffer.GetLineText(0));
        }
        /// <summary>
        /// Inserts patterned text into the buffer.
        /// </summary>
        private void InsertPatternIntoBuffer(int lines)
        {
            for (int i = 0;
                 i < lines;
                 i++)
            {
                if (i > 0)
                {
                    TextActions.InsertParagraph(controller);
                }

                TextActions.InsertText(controller, "Line " + (i + 1));
            }
        }
        public override int GetHashCode()
        {
            int hash = 1;

            hash ^= vectorActions_.GetHashCode();
            if (TextActions.Length != 0)
            {
                hash ^= TextActions.GetHashCode();
            }
            hash ^= memories_.GetHashCode();
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }
        public void PasteSingleInMiddle()
        {
            // Setup
            InsertPatternIntoBuffer(3);
            editor.Clipboard.Text = "Insert ";
            editor.Caret.Position = new TextPosition(1, 5);

            // Operation
            TextActions.Paste(controller);

            // Verification
            Assert.AreEqual(3, buffer.LineCount);
            Assert.AreEqual("Line 1", buffer.GetLineText(0));
            Assert.AreEqual("Line Insert 2", buffer.GetLineText(1));
            Assert.AreEqual("Line 3", buffer.GetLineText(2));
        }
        public void PasteSingleAtEnd()
        {
            // Setup
            InsertPatternIntoBuffer(3);
            editor.Clipboard.Text = " Inserted";
            editor.Caret.Position = new TextPosition(1, 0).ToEndOfLine(renderer);

            // Operation
            TextActions.Paste(controller);

            // Verification
            Assert.AreEqual(3, buffer.LineCount);
            Assert.AreEqual("Line 1", buffer.GetLineText(0));
            Assert.AreEqual("Line 2 Inserted", buffer.GetLineText(1));
            Assert.AreEqual("Line 3", buffer.GetLineText(2));
        }
        public void InsertMultipleParagraphs()
        {
            // Setup

            // Operation
            TextActions.InsertText(controller, "One");
            TextActions.InsertParagraph(controller);
            TextActions.InsertText(controller, "Two");
            TextActions.InsertParagraph(controller);
            TextActions.InsertText(controller, "Three");

            // Verification
            Assert.AreEqual(3, buffer.LineCount);
            Assert.AreEqual("One", buffer.GetLineText(0));
            Assert.AreEqual("Two", buffer.GetLineText(1));
            Assert.AreEqual("Three", buffer.GetLineText(2));
        }
        public void PasteMultipleAtBeginning()
        {
            // Setup
            InsertPatternIntoBuffer(3);
            editor.Clipboard.Text = "Insert\nNew ";
            editor.Caret.Position = new TextPosition(1, 0);

            // Operation
            TextActions.Paste(controller);

            // Verification
            Assert.AreEqual(4, buffer.LineCount);
            Assert.AreEqual("Line 1", buffer.GetLineText(0));
            Assert.AreEqual("Insert", buffer.GetLineText(1));
            Assert.AreEqual("New Line 2", buffer.GetLineText(2));
            Assert.AreEqual("Line 3", buffer.GetLineText(3));
        }
        public void PasteSingleSelectionSingleEolInMiddle()
        {
            // Setup
            InsertPatternIntoBuffer(3);
            editor.Clipboard.Text  = "Insert\n";
            editor.Caret.Selection = new TextRange(
                new TextPosition(1, 3), new TextPosition(1, 5));

            // Operation
            TextActions.Paste(controller);

            // Verification
            Assert.AreEqual(4, buffer.LineCount);
            Assert.AreEqual("Line 1", buffer.GetLineText(0));
            Assert.AreEqual("LinInsert", buffer.GetLineText(1));
            Assert.AreEqual("2", buffer.GetLineText(2));
            Assert.AreEqual("Line 3", buffer.GetLineText(3));
        }
        public void PasteSingleSelectionMultipleAtEnd()
        {
            // Setup
            InsertPatternIntoBuffer(3);
            editor.Clipboard.Text  = " Inserted\nNew";
            editor.Caret.Selection = new TextRange(
                new TextPosition(1, 3), new TextPosition(1, 6));

            // Operation
            TextActions.Paste(controller);

            // Verification
            Assert.AreEqual(4, buffer.LineCount);
            Assert.AreEqual("Line 1", buffer.GetLineText(0));
            Assert.AreEqual("Lin Inserted", buffer.GetLineText(1));
            Assert.AreEqual("New", buffer.GetLineText(2));
            Assert.AreEqual("Line 3", buffer.GetLineText(3));
        }
示例#12
0
        public override int GetHashCode()
        {
            int hash = 1;

            hash ^= vectorActions_.GetHashCode();
            if (TextActions.Length != 0)
            {
                hash ^= TextActions.GetHashCode();
            }
            hash ^= memories_.GetHashCode();
            if (Value != 0F)
            {
                hash ^= pbc::ProtobufEqualityComparers.BitwiseSingleEqualityComparer.GetHashCode(Value);
            }
            if (_unknownFields != null)
            {
                hash ^= _unknownFields.GetHashCode();
            }
            return(hash);
        }