Author Topic: Patch add event for editor split and unsplit  (Read 6352 times)

Offline arthurzmj

  • Multiple posting newcomer
  • *
  • Posts: 13
Patch add event for editor split and unsplit
« on: May 23, 2014, 02:36:14 pm »
I've create a ticket on https://sourceforge.net/p/codeblocks/tickets/2/
I think it's useful sometimes.
Declare here for developer's attention.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Patch add event for editor split and unsplit
« Reply #1 on: May 23, 2014, 11:55:44 pm »
Examples?
You've mentioned the KeyBinder plugin, but I don't see changes in it.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline arthurzmj

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: Patch add event for editor split and unsplit
« Reply #2 on: May 24, 2014, 05:41:24 am »
Examples?
You've mentioned the KeyBinder plugin, but I don't see changes in it.

I found such codes in KeyBinder
Code
// ----------------------------------------------------------------------------
void cbKeyBinder::OnWindowCreateEvent(wxEvent& event)
// ----------------------------------------------------------------------------
{
    // wxEVT_CREATE entry
    // Have to do this for split windows since CodeBlocks does not have
    // events when opening/closing split windows

    // Attach a split window (or any other window)
    if ( m_bBound )
    {
        wxWindow* pWindow = (wxWindow*)(event.GetEventObject());
        cbEditor* ed = 0;
        //cbStyledTextCtrl* p_cbStyledTextCtrl = 0;
        //cbStyledTextCtrl* pLeftSplitWin = 0;
        cbStyledTextCtrl* pRightSplitWin = 0;
        ed  = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor();
        if (ed)
        {   //p_cbStyledTextCtrl = ed->GetControl();
            //pLeftSplitWin = ed->GetLeftSplitViewControl();
            pRightSplitWin = ed->GetRightSplitViewControl();
            //Has this window been split?
            //**This is a temporary hack until some cbEvents are defined**
            if ( pWindow && (pRightSplitWin == 0) )
            {
                //-if (pRightSplitWin eq pWindow)
                //-{    Attach(pRightSplitWin);
                if (pWindow->GetParent() == ed)
                {   LOGIT( _T("OnWindowCreateEvent Attaching:%p"), pWindow );
                    AttachEditor(pWindow);
                }
            }
        }
    }//if m_bBound...

    event.Skip();
}//OnWindowCreateEvent

Although The plugin can find the split window in such way, the window relationship has not been built yet in such event.
That means the plugin can not find this window by Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor()->GetRightSplitViewControl()
What's more, the window's parent is going to be changed to a wxSplitterWindow after the window was created. In my cbVike plugin, It's important to get this wxSplitterWindow, but there is no way to do this without the split and unsplit event. You can refer to https://github.com/zmj64351508/cbvike . It's very similar to keyBinder in structure.

Edit: Another example is if the plugin want to do something like change the caret style in WindowCreateEvent, it may crash the app because the wxScintilla is not initialized when this event occurs.
« Last Edit: May 24, 2014, 10:00:54 am by arthurzmj »

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Patch add event for editor split and unsplit
« Reply #3 on: May 25, 2014, 12:50:52 pm »
Are you willing to provide a patch for keybinder, too?
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline arthurzmj

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: Patch add event for editor split and unsplit
« Reply #4 on: May 25, 2014, 06:18:43 pm »
OK. But the patch for keyBinder may come a few days later since I'm a little busy this week.

Offline arthurzmj

  • Multiple posting newcomer
  • *
  • Posts: 13
Re: Patch add event for editor split and unsplit
« Reply #5 on: May 26, 2014, 10:24:28 am »
Are you willing to provide a patch for keybinder, too?
This is the patch for keybinder and along with a little change of split event from previous patch. Please use this patch instead of the previous one.