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

Navigation between the calltips for overloaded functions

<< < (3/4) > >>

darmar:
There is no technical problems to make the call-tips wrap-around. It just depends on the taste of developers.

oBFusCATed:
Yes, I know, I've just tried it is way better and logical.

oBFusCATed:
Here is the patch I'm testing:


--- Code: ---commit ecd133cdf16bd7e493c9b59deb363036e67d75a5
Author: T Petrov <tpetrov@codeblocks.org>
Date:   Thu Jan 29 08:33:57 2015 +0200

    * ccmanager: Make the call tips wrap around
   
    > Introduce a helper function that advances to the previous or next call tip.
    > It goes to the first if the user wants to go to the next tip and it is at
      the last tip.
    > It goest to the last tip if at the first and going backwards.
    > Use it everywhere to do the advancing of tips (key handling, menu
      handling and call tip, button presses).
    > Always show both forward and backward buttons in the calltip, so the user
      will know that we support wraparound.

diff --git a/src/include/ccmanager.h b/src/include/ccmanager.h
index fd7a435..8cd89fa 100644
--- a/src/include/ccmanager.h
+++ b/src/include/ccmanager.h
@@ -76,6 +76,7 @@ class DLLIMPORT CCManager : public Mgr<CCManager>, wxEvtHandler
         void DoHidePopup();
         void DoShowDocumentation(cbEditor* ed);
         void DoUpdateCallTip(cbEditor* ed);
+        void AdvanceTip(bool next);
         /** format tips by breaking long lines at (hopefully) logical places */
         void DoShowTips(const wxStringVec& tips, cbStyledTextCtrl* stc, int pos, int argsPos, int hlStart, int hlEnd);
 
diff --git a/src/sdk/ccmanager.cpp b/src/sdk/ccmanager.cpp
index 6ac2f13..5e2ba7b 100644
--- a/src/sdk/ccmanager.cpp
+++ b/src/sdk/ccmanager.cpp
@@ -397,6 +397,28 @@ void CCManager::InjectAutoCompShow(int lenEntered, const wxString& itemList)
     }
 }
 
+// Change the current call tip to be the next or the previous.
+// Do wrapping if the end is reached in both directions.
+void CCManager::AdvanceTip(bool next)
+{
+    if (next)
+    {
+        ++m_CurCallTip;
+        if (m_CurCallTip == m_CallTips.end())
+            m_CurCallTip = m_CallTips.begin();
+    }
+    else
+    {
+        if (m_CurCallTip == m_CallTips.begin())
+        {
+            if (m_CallTips.size() > 1)
+                m_CurCallTip = m_CallTips.begin() + m_CallTips.size() - 1;
+        }
+        else
+            --m_CurCallTip;
+    }
+}
+
 bool CCManager::ProcessArrow(int key)
 {
     bool wasProcessed = false;
@@ -406,12 +428,13 @@ bool CCManager::ProcessArrow(int key)
     cbStyledTextCtrl* stc = ed->GetControl();
     if (stc->CallTipActive() && m_CallTipActive != wxSCI_INVALID_POSITION && m_CallTips.size() > 1)
     {
-        if (key == WXK_DOWN && (m_CurCallTip + 1) != m_CallTips.end())
-            ++m_CurCallTip;
-        else if (key == WXK_UP && m_CurCallTip != m_CallTips.begin())
-            --m_CurCallTip;
+        if (key == WXK_DOWN)
+            AdvanceTip(true);
+        else if (key == WXK_UP)
+            AdvanceTip(false);
         else
-            return wasProcessed; // moved off end, cancel tip
+            return wasProcessed;
+
         DoUpdateCallTip(ed);
         wasProcessed = true;
     }
@@ -814,12 +837,12 @@ void CCManager::OnEditorHook(cbEditor* ed, wxScintillaEvent& event)
         switch (event.GetPosition())
         {
             case 1: // up
-                --m_CurCallTip;
+                AdvanceTip(false);
                 DoUpdateCallTip(ed);
                 break;
 
             case 2: // down
-                ++m_CurCallTip;
+                AdvanceTip(true);
                 DoUpdateCallTip(ed);
                 break;
 
@@ -1073,16 +1096,12 @@ void CCManager::OnMenuSelect(wxCommandEvent& event)
         return;
     if (event.GetId() == idCallTipNext)
     {
-        if ((m_CurCallTip + 1) == m_CallTips.end())
-            return;
-        ++m_CurCallTip;
+        AdvanceTip(true);
         DoUpdateCallTip(ed);
     }
     else if (event.GetId() == idCallTipPrevious)
     {
-        if (m_CurCallTip == m_CallTips.begin())
-            return;
-        --m_CurCallTip;
+        AdvanceTip(false);
         DoUpdateCallTip(ed);
     }
 }
@@ -1184,16 +1203,9 @@ void CCManager::DoUpdateCallTip(cbEditor* ed)
     cbStyledTextCtrl* stc = ed->GetControl();
     if (m_CallTips.size() > 1)
     {
-        ++offset;
-        if (m_CurCallTip == m_CallTips.begin())
-            tips.front().Prepend(wxT('\002')); // down arrow
-        else if (m_CurCallTip + 1 == m_CallTips.end())
-            tips.front().Prepend(wxT('\001')); // up arrow
-        else
-        {
-            tips.front().Prepend(wxT("\001\002")); // up/down arrows
-            ++offset;
-        }
+        tips.front().Prepend(wxT("\001\002")); // up/down arrows
+        offset += 2;
+
         tips.push_back(wxString::Format(wxT("(%d/%u)"), m_CurCallTip - m_CallTips.begin() + 1, m_CallTips.size()));
         // store for better first choice later
         m_CallTipChoiceDict[CCManagerHelper::CallTipToInt(m_CallTips.front().tip, m_CallTips.size())] = m_CurCallTip - m_CallTips.begin();

--- End code ---

Any feedback is welcome. If there is none, I'll push it as is!  ;D

Alpha:

--- Quote from: oBFusCATed on January 29, 2015, 07:45:27 am ---Any feedback is welcome. If there is none, I'll push it as is!  ;D

--- End quote ---
I am fine with this.  The only thing I would mention is I do not like bool parameters since if one just reads AdvanceTip(false); it is not clear exactly what it does without looking up the definition.  An enum would be better (either create one, or use a wx one).

oBFusCATed:
OK, In svn...

Navigation

[0] Message Index

[#] Next page

[*] Previous page

Go to full version