Author Topic: Navigation between the calltips for overloaded functions  (Read 20769 times)

Offline darmar

  • Multiple posting newcomer
  • *
  • Posts: 68
Navigation between the calltips for overloaded functions
« on: January 10, 2015, 10:22:50 am »
Currently the calltips for overloaded functions are displayed on separate calltip pages. To navigate between the calltip pages the keyboard shortcuts "Ctrl+N" and "Ctrl+P"  are used.

I think the use of these shortcuts are not intuitive. In VisualStudio and MonoDevelop the simple "ArrowUp" and ArrowDown" are used instead. I find it is much more intuitive and corresponds to how the user navigates in the code-completion list.

I tried to implement the required changes into C::B. Now I have the working version. If developers have interest, I can prepare a patch.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Navigation between the calltips for overloaded functions
« Reply #1 on: January 10, 2015, 02:35:04 pm »
I have serious interest, I've raised this question long ago and it has not been addressed.
So you patch will be very welcome and I'll test it right away.
(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 darmar

  • Multiple posting newcomer
  • *
  • Posts: 68
Re: Navigation between the calltips for overloaded functions
« Reply #2 on: January 11, 2015, 04:17:20 pm »
Here is the patch.
This patch adds changes to the scintilla. I guess, this is not very desirable, but I haven't found another way.
Note: this patch doesn't delete Menu items "Next Call Tip" and "Previous Call Tip". I could prepare a patch for it if required.

I am ready to make adjustments in the patch if required.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Navigation between the calltips for overloaded functions
« Reply #3 on: January 11, 2015, 06:41:19 pm »
Thank you. Can you post the changes to Scintilla to the maintainers of Scintilla?
They can integrated them in the official release or they can tell you how to improve them or do it in a better way if needed.
(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 darmar

  • Multiple posting newcomer
  • *
  • Posts: 68
Re: Navigation between the calltips for overloaded functions
« Reply #4 on: January 13, 2015, 08:04:50 pm »
I have updated the patch. Now the change in Scintilla was avoided.

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: Navigation between the calltips for overloaded functions
« Reply #5 on: January 18, 2015, 09:13:33 pm »
I had been trying to achieve this for a while; I shall try to review your patch soon.

Offline Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: Navigation between the calltips for overloaded functions
« Reply #6 on: January 22, 2015, 03:29:03 am »
Committed, thank you.  I did change it slightly so that pressing down/up when there is no next/previous entry will instead cancel the tip, moving the caret to the next/previous line.

Offline teto

  • Almost regular
  • **
  • Posts: 127
Re: Navigation between the calltips for overloaded functions
« Reply #7 on: January 23, 2015, 11:23:35 am »
Great feature ! Much appreciated, thanks darmar :)

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Navigation between the calltips for overloaded functions
« Reply #8 on: January 26, 2015, 04:40:56 pm »
I've just tried it and I'm not sure I like it.
Is it possible to make it wrap-around?
(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 oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Navigation between the calltips for overloaded functions
« Reply #9 on: January 26, 2015, 06:13:03 pm »
FYI: The tooltips in VStudio 2010 are wrapping around, 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 darmar

  • Multiple posting newcomer
  • *
  • Posts: 68
Re: Navigation between the calltips for overloaded functions
« Reply #10 on: January 27, 2015, 06:13:27 pm »
There is no technical problems to make the call-tips wrap-around. It just depends on the taste of developers.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Navigation between the calltips for overloaded functions
« Reply #11 on: January 27, 2015, 08:59:38 pm »
Yes, I know, I've just tried it is way better and logical.
(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 oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Navigation between the calltips for overloaded functions
« Reply #12 on: January 29, 2015, 07:45:27 am »
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();

Any feedback is welcome. If there is none, I'll push it as is!  ;D
(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 Alpha

  • Developer
  • Lives here!
  • *****
  • Posts: 1513
Re: Navigation between the calltips for overloaded functions
« Reply #13 on: January 31, 2015, 12:02:58 am »
Any feedback is welcome. If there is none, I'll push it as is!  ;D
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).

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Navigation between the calltips for overloaded functions
« Reply #14 on: January 31, 2015, 12:41:32 am »
OK, In svn...
(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!]