wxString wxSTEditorShell::GetPromptText()
{
    int prompt_line = GetPromptLine();
    int start_pos   = PositionFromLine(prompt_line);
    int end_pos     = GetLength();
    wxString text(GetTextRange(start_pos, end_pos));
    return text;
}
void wxSTEditorShell::SetPromptText(const wxString& text)
{
    BeginWriteable();
    int length      = GetLength();
    int prompt_line = GetPromptLine();
    int start_pos   = PositionFromLine(prompt_line);
    SetTargetStart(start_pos);
    SetTargetEnd(length);
    ReplaceTarget(text);
    GotoPos(GetLength());
    EndWriteable();
}
Example #3
0
bool wxSTEditorShell::CheckReadOnly(bool set)
{
    bool make_ro = !CaretOnPromptLine(STE_CARET_MOVE_NONE);

    if (!make_ro)
    {
        // also check selection and make ro so they can't cut text not on last line
        int prompt_line = GetPromptLine();
        make_ro |= ((LineFromPosition(GetSelectionStart()) < prompt_line) ||
                    (LineFromPosition(GetSelectionEnd())   < prompt_line));
    }

    if (set && (make_ro != GetReadOnly()))
        SetReadOnly(make_ro);

    return make_ro;
}
Example #4
0
bool wxSTEditorShell::CaretOnPromptLine(STE_CaretPos_Type option)
{
    int prompt_line = GetPromptLine();
    bool on_last    = GetCurrentLine() >= prompt_line;

    //wxPrintf(wxT("Caret on last line total %d current %d onlast %d\n"), total_lines, GetCurrentLine(), (int)on_last);

    if (!on_last && (option != STE_CARET_MOVE_NONE))
    {
        if ((option & STE_CARET_MOVE_LASTLINE) != 0)
            GotoLine(prompt_line);
        else if ((option & STE_CARET_MOVE_ENDTEXT) != 0)
            GotoPos(GetLength());
    }

    return GetCurrentLine() >= prompt_line;
}
Example #5
0
wxString wxSTEditorShell::GetPromptText()
{
    int prompt_line = GetPromptLine();
    wxString text = GetTextRange(PositionFromLine(prompt_line), GetLength());
    return text;
}
Example #6
0
void wxSTEditorShell::OnKeyDown(wxKeyEvent &event)
{
    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(event.GetKeyCode() == WXK_DOWN, 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
            if ((int)GetHistoryIndex() < (int)GetHistoryCount()-1)
            {
                wxString promptText = GetPromptText();
                SetPromptText(GetNextHistoryLine(event.GetKeyCode() == WXK_DOWN, 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_PRIOR : case WXK_NUMPAD_PRIOR : //case WXK_NUMPAD_PAGEUP :
        case WXK_NEXT  : case WXK_NUMPAD_NEXT  : //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.IsEmpty())
                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
        {
            CaretOnPromptLine(STE_CARET_MOVE_ENDTEXT);
            break;
        }
    }

    event.Skip();
}