예제 #1
0
 public new void keyDown(NSEvent evt)
 {
     if (evt.keyCode() == 36)
         doubleClicked(m_table);
     else
         Unused.Value = SuperCall(NSWindowController.Class, "keyDown:", evt);
 }
        public new void keyDown(NSEvent evt)
        {
            bool handled = false;

            ushort key = evt.keyCode();
            if (key == Constants.ReturnKey || key == Constants.EnterKey)
            {
                if (m_table.numberOfRows() > 0)
                {
                    doubleClicked(this);
                    handled = true;
                }
            }

            if (!handled)
                Unused.Value = SuperCall(NSWindowController.Class, "keyDown:", evt);
        }
예제 #3
0
        public new void keyDown(NSEvent evt)
        {
            do
            {
                TextController controller = (TextController) window().windowController();
                if (controller.Language != null && controller.Language.Name == "CsLanguage")
                {
                    // Handle auto-complete initiated with '.' or enter.
                    if (m_autoComplete.HandleKey(this, evt))
                        break;
                }

                if (DoTabKey(evt))
                    break;

                if (DoArrowKeys(evt))
                    break;

                if (DoDeleteKey(evt))
                    break;

                // Special case for deleting the new line at the start of a blank line
                // (users don't normally want the whitespace to be appended to the
                // previous line).
                NSRange range = selectedRange();
                if (range.location > 0 && range.length == 0)
                {
                    if (evt.keyCode() == Constants.DeleteKey && string_().characterAtIndex((uint) range.location - 1) == '\n')
                    {
                        int count = DoGetBlankCount(string_(), range.location);
                        if (count > 0)
                        {
                            setSelectedRange(new NSRange(range.location - 1, count + 1));
                            delete(this);
                            break;
                        }
                    }
                }

                // Default key processing.
                Unused.Value = SuperCall(NSTextView.Class, "keyDown:", evt);

                // For up and down arrow in the whitespace at the start of a line
                // we want to set the insertion point to the start of the line (this
                // makes it much nicer to do stuff like manually comment out lines).
                range = selectedRange();
                if (range.length == 0)
                {
                    if (evt.keyCode() == Constants.UpArrowKey || evt.keyCode() == Constants.DownArrowKey)
                    {
                        NSString text = string_();
                        int start = DoGetLineStartFromSpaceOrTab(text, range.location);
                        if (start >= 0)
                        {
                            setSelectedRange(new NSRange(start, 0));
                        }
                    }
                }
            }
            while (false);
        }
예제 #4
0
        private bool DoDeleteKey(NSEvent evt)
        {
            if (evt.keyCode() == Constants.DeleteKey)
            {
                var range = selectedRange();
                if ((evt.modifierFlags() & Enums.NSShiftKeyMask) == Enums.NSShiftKeyMask)
                {
                    if (range.length == 0)
                    {
                        // Shift-delete deletes the current line
                        DoDeleteLine(range.location);
                        return true;
                    }
                }
                else if (range.length == 0)
                {
                    TextController controller = (TextController) window().windowController();
                    if (controller.Language != null && !controller.UsesTabs && !NSObject.IsNullOrNil(controller.SpacesText))
                    {
                        // If we're inserting N spaces for tabs then delete should delete N spaces at a time.
                        int count = DoGetSpaceCount(string_(), range.location - 1);
                        int length = (int) controller.SpacesText.length();
                        if (count >= length)
                        {
                            setSelectedRange(new NSRange(range.location - length, length));
                            delete(this);
                            return true;
                        }
                    }
                }
            }

            return false;
        }
예제 #5
0
        private bool DoArrowKeys(NSEvent evt)
        {
            bool command = (evt.modifierFlags() & Enums.NSCommandKeyMask) == Enums.NSCommandKeyMask;
            bool option = (evt.modifierFlags() & Enums.NSAlternateKeyMask) == Enums.NSAlternateKeyMask;
            bool shift = (evt.modifierFlags() & Enums.NSShiftKeyMask) == Enums.NSShiftKeyMask;

            if (evt.keyCode() == Constants.LeftArrowKey)
            {
                if (command && option)
                {
                    // Cycle down through document windows.
                    DoActivateLowerWindow();
                    return true;
                }
                else if (option && shift)
                {
                    // Extend the selection to the left using the previous word (for some reason Cocoa
                    // does not call selectionRangeForProposedRange_granularity for this).
                    if (DoExtendSelectionLeft())
                        return true;
                }
                else if (option)
                {
                    // Move the insertion point to the start of the previous word.
                    if (DoMoveSelectionLeft())
                        return true;
                }
            }
            else if (evt.keyCode() == Constants.RightArrowKey)
            {
                if (command && option)
                {
                    // Cycle up through document windows.
                    DoActivateHigherWindow();
                    return true;
                }
                else if (option && shift)
                {
                    // Extend the selection to the right of the next word.
                    if (DoExtendSelectionRight())
                        return true;
                }
                else if (option)
                {
                    // Move the insertion point after the end of the next word.
                    if (DoMoveSelectionRight())
                        return true;
                }
            }
            else if (evt.keyCode() == Constants.UpArrowKey)
            {
                if (command && option)
                {
                    // Toggle between *.cpp/*.c/*.m and *.hpp/*.h files.
                    DoToggleHeader();
                    return true;
                }
            }

            return false;
        }
예제 #6
0
        private bool DoTabKey(NSEvent evt)
        {
            if (evt.keyCode() == Constants.TabKey)
            {
                TextController controller = (TextController) window().windowController();
                if ((evt.modifierFlags() & Enums.NSAlternateKeyMask) != 0)
                {
                    if ((evt.modifierFlags() & Enums.NSShiftKeyMask) == 0)
                    {
                        // Option-tab selects the prev identifier.
                        if (DoSelectNextIdentifier(controller))
                            return true;
                    }
                    else
                    {
                        // Option-shift-tab selects the prev identifier.
                        if (DoSelectPreviousIdentifier(controller))
                            return true;
                    }
                }
                else if ((evt.modifierFlags() & Enums.NSCommandKeyMask) != 0)
                {
                }
                else if ((evt.modifierFlags() & Enums.NSControlKeyMask) != 0)
                {
                }
                else if ((evt.modifierFlags() & Enums.NSShiftKeyMask) != 0)
                {
                    // Shift-tab with at least one line selected unindents lines
                    var selRange = selectedRange();
                    if (DoSelectionCrossesLines(selRange))
                    {
                        controller.shiftLeft(this);
                        return true;
                    }
                }
                else
                {
                    var selRange = selectedRange();
                    if (selRange.location > 0 && selRange.length > 1)
                    {
                        // Tab with at least one line selected indents lines
                        if (DoSelectionCrossesLines(selRange))
                        {
                            controller.shiftRight(this);
                            return true;
                        }
                    }
                    else if (selRange.location > 0 && selRange.length == 0)
                    {
                        // Tab with no selection at the end of a blank line indents like the previous line.
                        if (DoMatchPriorLineTabs(selRange.location))
                            return true;
                    }

                    if (controller.Language != null && !controller.UsesTabs)
                    {
                        if (!NSObject.IsNullOrNil(controller.SpacesText))
                        {
                            this.insertText(controller.SpacesText);
                            return true;
                        }
                    }
                }
            }

            return false;
        }
예제 #7
-1
        public new void keyDown(NSEvent evt)
        {
            NSString chars = evt.characters();

            // TODO: Would be nice to also complete for '.' and ','. This should insert
            // the punctuation and, for '.', start a new completion.
            if (chars.Equals("\t") || chars.Equals("\r") || chars.Equals(" ") || chars.Equals("("))
            {
                DoComplete(false, selectedRow());
            }
            else if (evt.keyCode() == Constants.EnterKey)
            {
                DoComplete(true, selectedRow());
            }
            else if (chars.Equals(Constants.Escape))
            {
                m_text = null;
                window().windowController().Call("hide");
            }
            else if (chars.length() == 1 && (char.IsLetterOrDigit(chars[0]) || chars[0] == '_'))
            {
                m_completed += chars[0];
                int count = DoMatchName();
                if (count > 0)
                {
                    reloadData();
                }
                else if (m_completed.Length == 1)
                {
                    // It's rather confusing to have completed text without any indication
                    // that there is completed text so if the user's completed text is completely
                    // bogus we'll reset it.
                    m_completed = string.Empty;
                }
            }
            else if (chars.Equals(Constants.Delete))
            {
                if (m_completed.Length > 0)
                {
                    m_completed = m_completed.Remove(m_completed.Length - 1);
                    DoMatchName();
                    reloadData();
                }
                else
                    Functions.NSBeep();
            }
            else if (chars.length() == 1 && chars[0] == ' ')
            {
                DoMatchName();		// just select the best match
            }
            else
            {
                Unused.Value = SuperCall(NSTableView.Class, "keyDown:", evt);
            }
        }