void cbStyledTextCtrl::OnKeyDown(wxKeyEvent& event)
{
    switch (event.GetKeyCode())
    {
        case WXK_TAB:
        {
            if (m_tabSmartJump && !(event.ControlDown() || event.ShiftDown() || event.AltDown()))
            {
                if (!AutoCompActive() && m_bracePosition != wxSCI_INVALID_POSITION)
                {
                    m_lastPosition = GetCurrentPos();
                    GotoPos(m_bracePosition);

                    // Need judge if it's the final brace
                    HighlightRightBrace();
                    if (!m_tabSmartJump && CallTipActive())
                        CallTipCancel();
                    return;
                }
            }
        }
        break;

        case WXK_BACK:
        {
            if (m_tabSmartJump)
            {
                if (!(event.ControlDown() || event.ShiftDown() || event.AltDown()))
                {
                    const int pos = GetCurrentPos();
                    const int index = s_leftBrace.Find((wxChar)GetCharAt(pos - 1));
                    if (index != wxNOT_FOUND && (wxChar)GetCharAt(pos) == s_rightBrace.GetChar(index))
                    {
                        CharRight();
                        DeleteBack();
                    }
                }
                else if (m_lastPosition != wxSCI_INVALID_POSITION && event.ControlDown())
                {
                    GotoPos(m_lastPosition);
                    m_lastPosition = wxSCI_INVALID_POSITION;
                    return;
                }
            }
        }
        break;

        case WXK_RETURN:
        case WXK_ESCAPE:
        {
            if (m_tabSmartJump)
                m_tabSmartJump = false;
        }
        break;
    }

    event.Skip();
}
Beispiel #2
0
void StyledTextCtrl::OnAutoComplete(wxStyledTextEvent& event)
{

    if (!AutoCompActive())
    {
        AutoCompShow(1, *autoCompWords);
    }
    //AutoCompStops(functionKeywords);
}
void cbStyledTextCtrl::OnKillFocus(wxFocusEvent& event)
{
    // cancel auto-completion list when losing focus
    if ( AutoCompActive() )
        AutoCompCancel();

    if ( CallTipActive() )
        CallTipCancel();

    event.Skip();
}
void DisassemblyTextCtrl::OnKillFocus(wxFocusEvent& event)
{
    // cancel auto-completion list when losing focus
    if (AutoCompActive())
    {
        AutoCompCancel();
    }
    if (CallTipActive())
    {
        CallTipCancel();
    }
    event.Skip();
} // end of OnKillFocus
void cbStyledTextCtrl::OnKeyDown(wxKeyEvent& event)
{
    m_lastSelectedText = GetSelectedText();
    bool emulateDwellStart = false;

    switch ( event.GetKeyCode() )
    {
        case _T('I'):
        {
            if (event.GetModifiers() == wxMOD_ALT)
                m_braceShortcutState = true;
            break;
        }

        case WXK_TAB:
        {
            if (m_tabSmartJump && event.GetModifiers() == wxMOD_NONE)
            {
                if (!AutoCompActive() && m_bracePosition != wxSCI_INVALID_POSITION)
                {
                    m_lastPosition = GetCurrentPos();
                    GotoPos(m_bracePosition);

                    // Need judge if it's the final brace
                    HighlightRightBrace();
                    if (!m_tabSmartJump && CallTipActive())
                        CallTipCancel();
                    return;
                }
            }
        }
        break;

        case WXK_BACK:
        {
            if (m_tabSmartJump)
            {
                if (!(event.ControlDown() || event.ShiftDown() || event.AltDown()))
                {
                    const int pos = GetCurrentPos();
                    const int index = s_leftBrace.Find((wxChar)GetCharAt(pos - 1));
                    if (index != wxNOT_FOUND && (wxChar)GetCharAt(pos) == s_rightBrace.GetChar(index))
                    {
                        CharRight();
                        DeleteBack();
                    }
                }
                else if (m_lastPosition != wxSCI_INVALID_POSITION && event.ControlDown())
                {
                    GotoPos(m_lastPosition);
                    m_lastPosition = wxSCI_INVALID_POSITION;
                    return;
                }
            }
        }
        break;

        case WXK_RETURN:
        case WXK_NUMPAD_ENTER:
        case WXK_ESCAPE:
        {
            if (m_tabSmartJump)
                m_tabSmartJump = false;
        }
        break;

        case WXK_CONTROL:
        {
            EmulateDwellStart();
            emulateDwellStart = true;
        }
        break;
        default: break;
    }

    if (event.ControlDown() && !emulateDwellStart)
        EmulateDwellStart();

    event.Skip();
}
void wxSTEditorShell::OnKeyDown(wxKeyEvent &event)
{
    // don't steal any keys from the autocomplete dropdown
    if (AutoCompActive())
    {
        event.Skip(true);
        return;
    }

    event.Skip(false);
    CheckReadOnly(true);

    switch (event.GetKeyCode())
    {
        case WXK_UP : case WXK_NUMPAD_UP :
        {
            // you can scroll up through multiline entry
            int current_line = GetCurrentLine();
            int prompt_line  = GetPromptLine();
            if ((current_line < prompt_line) || (current_line > prompt_line))
                break;

            // up/down arrows go through the history buffer
            wxString promptText = GetPromptText();
            SetPromptText(GetNextHistoryLine(false, promptText));
            return;
        }
        case WXK_DOWN : case WXK_NUMPAD_DOWN :
        {
            // you can scroll down through multiline entry
            int total_lines  = GetLineCount();
            total_lines      = wxMax(0, total_lines - 1);
            int current_line = GetCurrentLine();
            if (current_line < total_lines)
                break;

            // up/down arrows go through the history buffer
            wxString promptText = GetPromptText();
            SetPromptText(GetNextHistoryLine(true, promptText));
            return;
        }
        case WXK_LEFT : case WXK_NUMPAD_LEFT :
        {
            int current_line = GetCurrentLine();
            int prompt_line  = GetPromptLine();
            if (current_line >= prompt_line)
            {
                int caret_pos = 0;
                GetCurLine(&caret_pos);
                if (caret_pos < 1)
                    return;
            }
            break;
        }

        case WXK_PAGEUP   : case WXK_NUMPAD_PAGEUP   :
        case WXK_PAGEDOWN : case WXK_NUMPAD_PAGEDOWN :
        case WXK_END      : case WXK_NUMPAD_END   :
        case WXK_HOME     : case WXK_NUMPAD_HOME  :
        case WXK_RIGHT    : case WXK_NUMPAD_RIGHT :

        case WXK_SHIFT   :
        case WXK_CONTROL :
        case WXK_ALT     :
        {
            // default processing for these keys
            event.Skip();
            return;
        }

        case WXK_RETURN : case WXK_NUMPAD_ENTER :
        {
            // put cursor at end if not already on the last line
            if (!CaretOnPromptLine(STE_CARET_MOVE_NONE))
            {
                GotoPos(GetLength());
                return;
            }

            int current_line = GetCurrentLine();
            int prompt_line  = GetPromptLine();

            // allow multiline entry for shift+enter
            if ((current_line >= prompt_line) && event.ShiftDown())
            {
                event.Skip();
                return;
            }

            wxString promptText = GetPromptText();

            // goto the end of the line and store the line for the history
            LineEnd();
            if (promptText.Length())
                AddHistoryLine(promptText, true);

            // just send the event, the receiver can do what they like
            SendEvent(wxEVT_STESHELL_ENTER, 0, GetState(), promptText);
            return;
        }
        case WXK_BACK :
        {
            // go to the end of the last line if not on last line
            if (!CaretOnPromptLine(STE_CARET_MOVE_NONE))
            {
                GotoPos(GetLength());
                return;
            }
            // don't let them backspace into previous line
            int caret_pos = 0;
            GetCurLine(&caret_pos);
            if (caret_pos < 1)
                return;

            break;
        }
        default : // move cursor to end if not already there
        {
            // reset history to start at most recent again
            m_line_history_index = (int)(m_lineHistoryArray.GetCount() - 1);

            CaretOnPromptLine(STE_CARET_MOVE_ENDTEXT);
            break;
        }
    }

    event.Skip();
}
Beispiel #7
0
void CodeEdit::StartAutoCompletion(const wxString& token)
{

    wxASSERT(m_autoCompleteManager != NULL);

    wxString items;

    // Get the actual prefix of the thing we're trying to match for autocompletion.
    // If the token refers to a member, the prefix is the member name.

    wxString prefix;
    wxString newToken;
    bool member = false;
    bool function = false;

    if (GetLexer() == wxSTC_LEX_LUA)
    {

        int end1 = token.Find('.', true);

        if (end1 == wxNOT_FOUND)
        {
            end1 = 0;
        }
        else
        {
            // Skip the '.' character.
            ++end1;
            member = true;
        }

        int end2 = token.Find(':', true);

        if (end2 == wxNOT_FOUND)
        {
            end2 = 0;
        }
        else
        {
            // Skip the ':' character.
            ++end2;
            member = true;
        }

        int end = std::max(end1, end2);
        newToken = token.Right(token.Length() - end);
        prefix = token.Left(end - 1);

        if (end != 0 && token[end - 1] == ':')
          function = true;
    }
    else
    {
        // No autocompletion when using the default lexer.
        return;
    }

    if (!member && newToken.Length() < m_minAutoCompleteLength)
    {
        // Don't pop up the auto completion if the user hasn't typed in very
        // much yet.
        return;
    }

    wxVector<wxString> prefixes;

    m_autoCompleteManager->ParsePrefix(prefix, file, GetCurrentLine(), prefixes);
    m_autoCompleteManager->GetMatchingItems(newToken, prefixes, member, function, items);

    if (!AutoCompActive() || m_autoCompleteItems != items)
    {

        // Remember the items in the list so that we don't redisplay the list
        // with the same set of items (reduces flickering).
        m_autoCompleteItems = items;

        if (!items.IsEmpty())
        {
            // Show the autocomplete selection list.
          AutoCompShow(newToken.Length(), items);
        }
        else
        {
            // We have no matching items, so hide the autocompletion selection.
            AutoCompCancel();
        }

    }

}