Developer forums (C::B DEVELOPMENT STRICTLY!) > CodeCompletion redesign

hook "tab" key

(1/6) > >>

blueshake:
dear all:


mybe you have the function of eclipse,in eclipse editor,when you type "tab",and if the next char is one of ")]}",it will skip it. see the screen shot.so if we want to implement this function,we need to hook getkey donw message,in codelite, it just simple handle it in this way.see the quote.

and in codeblock ,I can not figure out how to do this.can somebode tell me how to do this in codeblock,thanks.

--- Quote ---BEGIN_EVENT_TABLE(LEditor, wxScintilla)

    EVT_SCI_CHARADDED              (wxID_ANY, LEditor::OnCharAdded)
    EVT_SCI_MARGINCLICK            (wxID_ANY, LEditor::OnMarginClick)
    EVT_SCI_CALLTIP_CLICK          (wxID_ANY, LEditor::OnCallTipClick)
    EVT_SCI_DWELLEND               (wxID_ANY, LEditor::OnDwellEnd)
    EVT_SCI_UPDATEUI               (wxID_ANY, LEditor::OnSciUpdateUI)
    EVT_SCI_SAVEPOINTREACHED       (wxID_ANY, LEditor::OnSavePoint)
    EVT_SCI_SAVEPOINTLEFT          (wxID_ANY, LEditor::OnSavePoint)
    EVT_SCI_MODIFIED               (wxID_ANY, LEditor::OnChange)
    EVT_CONTEXT_MENU               (LEditor::OnContextMenu)
    EVT_KEY_DOWN                   (LEditor::OnKeyDown)
    EVT_LEFT_DOWN                  (LEditor::OnLeftDown)
    EVT_MIDDLE_DOWN                (LEditor::OnMiddleDown)
    EVT_MIDDLE_UP                  (LEditor::OnMiddleUp)
    EVT_LEFT_UP                    (LEditor::OnLeftUp)
    EVT_LEAVE_WINDOW               (LEditor::OnLeaveWindow)
    EVT_KILL_FOCUS                 (LEditor::OnFocusLost)
    EVT_SCI_DOUBLECLICK            (wxID_ANY, LEditor::OnLeftDClick)
    EVT_COMMAND                    (wxID_ANY, wxEVT_FRD_FIND_NEXT, LEditor::OnFindDialog)
    EVT_COMMAND                    (wxID_ANY, wxEVT_FRD_REPLACE, LEditor::OnFindDialog)
    EVT_COMMAND                    (wxID_ANY, wxEVT_FRD_REPLACEALL, LEditor::OnFindDialog)
    EVT_COMMAND                    (wxID_ANY, wxEVT_FRD_BOOKMARKALL, LEditor::OnFindDialog)
    EVT_COMMAND                    (wxID_ANY, wxEVT_FRD_CLOSE, LEditor::OnFindDialog)
    EVT_COMMAND                    (wxID_ANY, wxEVT_FRD_CLEARBOOKMARKS, LEditor::OnFindDialog)
    EVT_COMMAND                    (wxID_ANY, wxEVT_CMD_JOB_STATUS_VOID_PTR, LEditor::OnHighlightThread)
    EVT_COMMAND                    (wxID_ANY, wxCMD_EVENT_REMOVE_MATCH_INDICATOR, LEditor::OnRemoveMatchInidicator)
END_EVENT_TABLE()
--- End quote ---

[attachment deleted by admin]

ollydbg:
I have tried, but failed. :(

In the codelite editor, say LEditor class, it is just derived from wxScintilla class, so it can hook the EVT_KEY_DOWN message.

But in Codeblocks, cbEditor class use wxScintilla as its member, I don't know how to hook the Key_down event.

By the way, if we can handle the message SCI_TAB from scintilla (see: http://www.scintilla.org/ScintillaDoc.html#KeyboardCommands), we can do the same thing.

hope some one can help you.

MortenMacFly:

--- Quote from: blueshake on March 08, 2010, 08:47:42 am ---and in codeblock ,I can not figure out how to do this.can somebode tell me how to do this in codeblock,thanks.

--- End quote ---
Look into:

--- Code: ---void cbEditor::OnScintillaEvent(wxScintillaEvent& event)
--- End code ---

Notice that you should do any listening via an (the) editor hook. It can even be implemented as plugin btw!

blueshake:
@morten

thanks for your answer.I will check into it. :D

ollydbg:
I don't know we can do it in the OnScintillaEvent(), because we don't have a  wxEVT_SCI_TAB defined in wxscintilla.h

See the code snippet :


--- Code: ---cbStyledTextCtrl* cbEditor::CreateEditor()
{
    m_ID = wxNewId();

    // avoid gtk-critical because of sizes less than -1 (can happen with wxAuiNotebook/cbAuiNotebook)
    wxSize size = m_pControl ? wxDefaultSize : GetSize();
    size.x = std::max(size.x, -1);
    size.y = std::max(size.y, -1);

    cbStyledTextCtrl* control = new cbStyledTextCtrl(this, m_ID, wxDefaultPosition, size);
    control->UsePopUp(false);

    wxString enc_name = Manager::Get()->GetConfigManager(_T("editor"))->Read(_T("/default_encoding"), wxEmptyString);
    m_pData->m_encoding = wxFontMapper::GetEncodingFromName(enc_name);

    // dynamic events
    Connect( m_ID,  -1, wxEVT_SCI_MARGINCLICK,
                  (wxObjectEventFunction) (wxEventFunction) (wxScintillaEventFunction)
                  &cbEditor::OnMarginClick );
    Connect( m_ID,  -1, wxEVT_SCI_UPDATEUI,
                  (wxObjectEventFunction) (wxEventFunction) (wxScintillaEventFunction)
                  &cbEditor::OnEditorUpdateUI );
    Connect( m_ID,  -1, wxEVT_SCI_CHANGE,
                  (wxObjectEventFunction) (wxEventFunction) (wxScintillaEventFunction)
                  &cbEditor::OnEditorChange );
    Connect( m_ID,  -1, wxEVT_SCI_CHARADDED,
                  (wxObjectEventFunction) (wxEventFunction) (wxScintillaEventFunction)
                  &cbEditor::OnEditorCharAdded );
    Connect( m_ID,  -1, wxEVT_SCI_DWELLSTART,
                  (wxObjectEventFunction) (wxEventFunction) (wxScintillaEventFunction)
                  &cbEditor::OnEditorDwellStart );
    Connect( m_ID,  -1, wxEVT_SCI_DWELLEND,
                  (wxObjectEventFunction) (wxEventFunction) (wxScintillaEventFunction)
                  &cbEditor::OnEditorDwellEnd );
    Connect( m_ID,  -1, wxEVT_SCI_USERLISTSELECTION,
                  (wxObjectEventFunction) (wxEventFunction) (wxScintillaEventFunction)
                  &cbEditor::OnUserListSelection );
    Connect( m_ID,  -1, wxEVT_SCI_MODIFIED,
                  (wxObjectEventFunction) (wxEventFunction) (wxScintillaEventFunction)
                  &cbEditor::OnEditorModified );

    // Now bind all *other* scintilla events to a common function so that editor hooks
    // can be informed for them too.
    // If you implement one of these events using a different function, do the following:
    //  * comment it out here,
    //  * "connect" it in the above block
    //  * and make sure you call OnScintillaEvent() from your new handler function
    // This will make sure that all editor hooks will be called when needed.
    int scintilla_events[] =
    {
//        wxEVT_SCI_CHANGE,
        wxEVT_SCI_STYLENEEDED,
//        wxEVT_SCI_CHARADDED,
        wxEVT_SCI_SAVEPOINTREACHED,
        wxEVT_SCI_SAVEPOINTLEFT,
        wxEVT_SCI_ROMODIFYATTEMPT,
        wxEVT_SCI_KEY,
        wxEVT_SCI_DOUBLECLICK,
//        wxEVT_SCI_UPDATEUI,
//        wxEVT_SCI_MODIFIED,
        wxEVT_SCI_MACRORECORD,
//        wxEVT_SCI_MARGINCLICK,
        wxEVT_SCI_NEEDSHOWN,
        wxEVT_SCI_PAINTED,
//        wxEVT_SCI_USERLISTSELECTION,
        wxEVT_SCI_URIDROPPED,
//        wxEVT_SCI_DWELLSTART,
//        wxEVT_SCI_DWELLEND,
        wxEVT_SCI_START_DRAG,
        wxEVT_SCI_DRAG_OVER,
        wxEVT_SCI_DO_DROP,
        wxEVT_SCI_ZOOM,
        wxEVT_SCI_HOTSPOT_CLICK,
        wxEVT_SCI_HOTSPOT_DCLICK,
        wxEVT_SCI_CALLTIP_CLICK,
        wxEVT_SCI_AUTOCOMP_SELECTION,
//        wxEVT_SCI_INDICATOR_CLICK,
//        wxEVT_SCI_INDICATOR_RELEASE,

        -1 // to help enumeration of this array
    };
    int i = 0;
    while (scintilla_events[i] != -1)
    {
        Connect( m_ID,  -1, scintilla_events[i],
                      (wxObjectEventFunction) (wxEventFunction) (wxScintillaEventFunction)
                      &cbEditor::OnScintillaEvent );
        ++i;
    }

    return control;
}

--- End code ---


We can only handle all the events in the scintilla_events array, either commented events or uncommented events. But the "tab" event will never carried in the wxEVT_SCI_KEY, because from the docs:

http://www.scintilla.org/ScintillaDoc.html#SCN_KEY


--- Quote ---SCN_KEY
Reports all keys pressed but not consumed by Scintilla.
--- End quote ---

Since I think the "tab" event is already consumed by Scintilla internally, the only chance we can hook the tab event is the "SCI_TAB" stated in the
http://www.scintilla.org/ScintillaDoc.html#KeyboardCommands

which is not implemented in wxScintilla.

I'm not sure all my comments is right. :D

Navigation

[0] Message Index

[#] Next page

Go to full version