hello,if the item in suggestion list is a function ,the "()" will add automaticlly.
explanation:
1.use the searchItem to store the the function type name in int CodeCompletion::CodeComplete() in codecompletion.cpp
2.hook the message wxEVT_SCI_AUTOCOMP_SELECTION,if we find the item which wil be completed in the serachItem,
then cancel the codecompletion.we do it by ourselves,and add the "()",if the function has arguement.the caret go to the
position beteen the "()".
here is the patch:
Index: src/plugins/codecompletion/codecompletion.cpp
===================================================================
--- src/plugins/codecompletion/codecompletion.cpp (revision 5813)
+++ src/plugins/codecompletion/codecompletion.cpp (working copy)
@@ -564,6 +564,7 @@
TokensTree* tokens = parser->GetTokens();
for (TokenIdxSet::iterator it = result.begin(); it != result.end(); ++it)
{
+ searchItem.clear();
Token* token = tokens->at(*it);
if (!token || token->m_Name.IsEmpty())
continue;
@@ -580,7 +581,10 @@
wxString tmp;
tmp << token->m_Name << wxString::Format(_T("?%d"), iidx);
items.Add(tmp);
-
+ if (token->m_TokenKind == tkFunction || token->m_TokenKind == tkConstructor || token->m_TokenKind == tkDestructor)
+ {
+ searchItem[token->m_Name] = token->m_Args.size();
+ }
if (token->m_TokenKind == tkNamespace && token->m_Aliases.size())
{
for (size_t i = 0; i < token->m_Aliases.size(); ++i)
@@ -1940,7 +1944,32 @@
if ((event.GetKey() == '.') && control->AutoCompActive())
control->AutoCompCancel();
+ if(event.GetEventType() == wxEVT_SCI_AUTOCOMP_SELECTION)
+ {
+ //for (map<wxString, int>::iterator it = searchItem.begin(); it != searchItem.end(); ++it)
+ //{
+ wxString itemText = event.GetText();
+ map<wxString, int>::iterator it = searchItem.find(itemText);
+ if (it != searchItem.end())
+ {
+ //Manager::Get()->GetLogManager()->DebugLog((*it).first);
+ control->AutoCompCancel();
+ int pos = control->GetCurrentPos();
+ int start = control->WordStartPosition(pos, true);
+ control->AddText(itemText.substr(pos - start)+_T("()"));
+ //Parser* parser = m_NativeParsers.FindParserFromEditor(editor);
+ //TokensTree* tokens = parser->GetTokens();
+ if ((*it).second)
+ {
+ pos = control->GetCurrentPos();
+ control->GotoPos(pos - 1);
+ }
+ //Manager::Get()->GetLogManager()->DebugLog((*it).first+_T("param"));
+ }
+ //}
+ //Manager::Get()->GetLogManager()->DebugLog((*it).first);
+ }
if (event.GetEventType() == wxEVT_SCI_CHARADDED)
{
// a character was just added in the editor
Index: src/plugins/codecompletion/codecompletion.h
===================================================================
--- src/plugins/codecompletion/codecompletion.h (revision 5813)
+++ src/plugins/codecompletion/codecompletion.h (working copy)
@@ -142,6 +142,7 @@
int StartIdxNameSpaceInScope;
int m_CurrentLine;
+ map<wxString, int> searchItem;
wxString m_LastFile;
wxTimer m_FunctionsParsingTimer;
Index: src/sdk/cbeditor.cpp
===================================================================
--- src/sdk/cbeditor.cpp (revision 5813)
+++ src/sdk/cbeditor.cpp (working copy)
@@ -1045,7 +1045,7 @@
wxEVT_SCI_HOTSPOT_CLICK,
wxEVT_SCI_HOTSPOT_DCLICK,
wxEVT_SCI_CALLTIP_CLICK,
-// wxEVT_SCI_AUTOCOMP_SELECTION,
+ wxEVT_SCI_AUTOCOMP_SELECTION,
// wxEVT_SCI_INDICATOR_CLICK,
// wxEVT_SCI_INDICATOR_RELEASE,
EDIT:this need to turn message wxEVT_SCI_AUTOCOMP_SELECTION on .
I asked the question before in this thread.
http://forums.codeblocks.org/index.php/topic,10873.msg75913.html#msg75913