Code::Blocks Forums

Developer forums (C::B DEVELOPMENT STRICTLY!) => Plugins development => Topic started by: danselmi on July 23, 2014, 10:17:39 pm

Title: SmartIndent after CodeCompletion
Post by: danselmi on July 23, 2014, 10:17:39 pm
I'd like to improve the SmartIndentHDL plugin.

The following case:
Code
process begin
    ...
    end pro|
After typing "pro" CC pops up and I choose "process".
Normally the SmartIndent plugin chatches the wxEVT_SCI_CHARADDED event.
I tried additional with wxEVT_SCI_AUTOCOMP_SELECTION but at this time the completion is not done yet so the
line only contains "end pro" and the plugin can't decide how to unindent.

Any ideas?
Title: Re: SmartIndent after CodeCompletion
Post by: Alpha on July 24, 2014, 03:46:47 am
Hooking into the modified event should notify you at the right time (but it will also give many other notifications, so watch out for double handling events).
Code
if (evtType == wxEVT_SCI_MODIFIED && (event.GetModificationType() & wxSCI_MOD_INSERTTEXT))
{
    // handle changes...
    if (!didJustAutocomplete()) // might need to try a filter or something (wxSCI_PERFORMED_USER might help)
        return;  // ignore
}

Alternatively, you could add an API call into sdk/ccmanager.cpp line 742, so SmartIndent plugins get called at when necessary.
Title: Re: SmartIndent after CodeCompletion
Post by: danselmi on July 25, 2014, 02:59:33 pm
I tried alphas suggestion without success:
From Scintilla documentation:
"No modifications may be performed while in a SCN_MODIFIED event...".

I have a possible solution where i "take" the first wxEVT_SCI_UPDATEUI event after the wxEVT_SCI_AUTOCOMP_SELECTION event (Patch is attached).
Any better proposals?


regards danselmi
Title: Re: SmartIndent after CodeCompletion
Post by: Alpha on July 29, 2014, 03:46:09 am
Oops, sorry about that.  I guess I did not read the docs closely enough.

Reading through your patch, it seems like it relies too much on a specific order of events (which *might* be interrupted/altered someday in the future).  I think a cleaner way is to:
[...] add an API call into sdk/ccmanager.cpp line 742, so SmartIndent plugins get called at when necessary.
Have CCManager either broadcast a CC_Done event (which SmartIndent plugins could pick up), or iterate through all SmartIndent plugins and execute plugin->OnCCDone(ed).
Title: Re: SmartIndent after CodeCompletion
Post by: danselmi on July 30, 2014, 09:13:05 am
just commited rev9853

It implements the approach where CCManager calls SmartIndentPlugin->OnCCDone(ed).
Kudos to alpha for support and reviewing!

regards danselmi