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

auto add the "()"

<< < (2/2)

blueshake:
ok,here is the new patch.

--- Code: ---Index: src/plugins/codecompletion/codecompletion.cpp
===================================================================
--- src/plugins/codecompletion/codecompletion.cpp (revision 5816)
+++ 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,12 @@
                 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()-2;
+                    //Manager::Get()->GetLogManager()->DebugLog(token->m_Name);
+                    //Manager::Get()->GetLogManager()->DebugLog(token->m_Args);
+                }
                 if (token->m_TokenKind == tkNamespace && token->m_Aliases.size())
                 {
                     for (size_t i = 0; i < token->m_Aliases.size(); ++i)
@@ -594,7 +600,10 @@
                     }
                 }
             }
-
+//    for (unsigned int i = 0; i < items.GetCount(); ++i)
+//    {
+        //Manager::Get()->GetLogManager()()DebugLog(items[i]);
+//    }
             if (m_NativeParsers.LastAISearchWasGlobal())
             {
                 // empty or partial search phrase: add theme keywords in search list
@@ -1940,7 +1949,37 @@
 
     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->SetTargetStart(start);
+            control->SetTargetEnd(pos);
+            control->ReplaceTarget(itemText+_T("()"));
+            pos = control->GetCurrentPos();
+            control->GotoPos(pos + itemText.size()+2);
+            //control->AddText(itemText.substr(pos - start)+_T("()"));
+            //Parser* parser = m_NativeParsers.FindParserFromEditor(editor);
+            //TokensTree* tokens = parser->GetTokens();
+            if ((*it).second != 0)
+            {
+                //Manager::Get()->GetLogManager()->DebugLog(F(_T("count:%d"),(*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 5816)
+++ 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 5816)
+++ 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,
 

--- End code ---

blueshake:
Hello,Morton:
Does the patch above still work for you ,why it don't work for me now .what kind of joke it is. :shock:

thomas:
Mmmh... same comment from me like for turning "." into "->".

Navigation

[0] Message Index

[*] Previous page

Go to full version