<table><tr><td style="">kossebau added a comment.
</td><a style="text-decoration: none; padding: 4px 8px; margin: 0 8px 8px; float: right; color: #464C5C; font-weight: bold; border-radius: 3px; background-color: #F7F7F9; background-image: linear-gradient(to bottom,#fff,#f1f0f1); display: inline-block; border: 1px solid rgba(71,87,120,.2);" href="https://phabricator.kde.org/D16882">View Revision</a></tr></table><br /><div><div><blockquote style="border-left: 3px solid #8C98B8;
          color: #6B748C;
          font-style: italic;
          margin: 4px 0 12px 0;
          padding: 8px 12px;
          background-color: #F8F9FC;">
<div style="font-style: normal;
          padding-bottom: 4px;">In <a href="https://phabricator.kde.org/D16882#360857" style="background-color: #e7e7e7;
          border-color: #e7e7e7;
          border-radius: 3px;
          padding: 0 4px;
          font-weight: bold;
          color: black;text-decoration: none;">D16882#360857</a>, <a href="https://phabricator.kde.org/p/rjvbb/" style="
              border-color: #f1f7ff;
              color: #19558d;
              background-color: #f1f7ff;
                border: 1px solid transparent;
                border-radius: 3px;
                font-weight: bold;
                padding: 0 4px;">@rjvbb</a> wrote:</div>
<div style="margin: 0;
          padding: 0;
          border: 0;
          color: rgb(107, 116, 140);"><p>Re-opening because I found an actual flaw in KDevelop after noticing that context menu duplication still occurred when only the active view receives the aboutToShowContextMenu signal.</p>

<p>The <tt style="background: #ebebeb; font-size: 13px;">addedContextMenu</tt> member exists because <tt style="background: #ebebeb; font-size: 13px;">"we want to remove the added stuff when the menu hides"</tt>. This should of course read "when the menu reopens in again, possibly in a different view".</p></div>
</blockquote>

<p>Good find, that seems indeed broken.</p>

<blockquote style="border-left: 3px solid #a7b5bf; color: #464c5c; font-style: italic; margin: 4px 0 12px 0; padding: 4px 12px; background-color: #f8f9fc;"><p>The flaw here is that the design forgets that the context menu instance is shared among views. It expects <tt style="background: #ebebeb; font-size: 13px;">d->addedContextMenu</tt> to exist and contain the QMenu added by a previous view, but this cannot be the case in the current implementation where the variable is only allocated when the menu is first opened in a given view.</p></blockquote>

<p>I would see the flaw also in that there is no specification in the KTextEditor API how the context menu is shared/reused. <tt style="background: #ebebeb; font-size: 13px;">KTextEditor::View::contextMenu()</tt> talks about "the xmlgui menu" or custom set "context menu object", but no hint/promise whether there is any instance sharing done, e.g. between views for the same document or even across all views in the same process(?).</p>

<blockquote style="border-left: 3px solid #a7b5bf; color: #464c5c; font-style: italic; margin: 4px 0 12px 0; padding: 4px 12px; background-color: #f8f9fc;"><p>If the <tt style="background: #ebebeb; font-size: 13px;">addedContextMenu</tt> is to be removed in JIT-fashion before reopening the context menu, it should be a static variable.</p></blockquote>

<p>That might be a way, yes.</p>

<p>Before though I would like to have it first sorted out with the KTextEditor people what to expect here and whether the API dox could resolve that undefinedness. Given the current implementation kdevelop-side I would not be surprised if KTextEditor changed implementation here, but needs to be explored. The proposed fix relies on the current implementation, which is a bit fragile.</p>

<p>Another option might be to link up to the menu being closed and clean up then, as the comment on the <tt style="background: #ebebeb; font-size: 13px;">addedContextMenu</tt> member claimed. (personally preferred to clean up right after use). <br />
Also needs to be explored if there once was such an implementation and why it has been removed. Might do in the next days.</p></div></div><br /><div><strong>REPOSITORY</strong><div><div>R32 KDevelop</div></div></div><br /><div><strong>REVISION DETAIL</strong><div><a href="https://phabricator.kde.org/D16882">https://phabricator.kde.org/D16882</a></div></div><br /><div><strong>To: </strong>rjvbb, KDevelop, kossebau<br /><strong>Cc: </strong>kossebau, kde-frameworks-devel, kdevelop-devel, glebaccon, antismap, iodelay, vbspam, geetamc, Pilzschaf, akshaydeo, surgenight, arrowd<br /></div>